1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: 17: 18: 19: 20:
21:
22: #include <basic.h>
23: #include <device/serialio.h>
24: #include <device/rs.h>
25: #include <tk/tkernel.h>
26: #include <tk/util.h>
27: #include <sys/imalloc.h>
28: #include <sys/util.h>
29: #include <libstr.h>
30:
31: #define DEF_INBUFSZ 2048
32: #define MIN_INBUFSZ 256
33: #define OUBUFSZ 512
34:
35:
36: typedef union {
37: RsError c;
38: RsStat s;
39: ER w;
40: } RsErr;
41:
42:
43: typedef struct {
44: UB reqchar:8;
45: UW rsoff:1;
46: UW sndxoff:1;
47: } FlowState;
48:
49:
50: struct _L_INFO;
51: typedef struct {
52: ER (*in)(struct _L_INFO *li, UB *buf, W len, W *alen, W tmout);
53: ER (*out)(struct _L_INFO *li, UB *buf, W len, W *alen, W tmout);
54: ER (*ctl)(struct _L_INFO *li, W kind, UW *arg);
55: void (*up)(struct _L_INFO *li);
56: void (*down)(struct _L_INFO *li);
57: } SC_FUNC;
58:
59:
60: typedef struct {
61: SC_FUNC *fn;
62: RsHwConf_16450 c;
63: UB fctl;
64: UB dt[3];
65: RsMode mode;
66: RsFlow flow;
67: FlowState flowsts;
68: } SC_DEFS;
69:
70:
71: typedef struct _L_INFO {
72: SC_DEFS scdefs;
73: UW suspend:1;
74: UW enbint:1;
75:
76: FastMLock lock;
77: ID flg;
78:
79: RsMode mode;
80: RsFlow flow;
81: FlowState flowsts;
82:
83: FUNCP extfn;
84: UW extpar;
85: UB lsts;
86: UB lstshist;
87: UB msts;
88:
89: UW in_rptr;
90: UW in_wptr;
91: UW in_bufsz;
92: UB *in_buf;
93:
94: UW ou_rptr;
95: UW ou_wptr;
96:
97: UW ou_cnt;
98: UW ou_len;
99: UB ou_buf[OUBUFSZ];
100: } LINE_INFO;
101:
102: #define XOFF_MARGIN 64
103: #define XON_MARGIN 128
104:
105:
106: #define OU_PTRMASK(p, ptr) ((ptr) % OUBUFSZ)
107:
108:
109: #define PTRMASK(p, ptr) ((ptr) % ((p)->in_bufsz))
110:
111:
112: #define IN_BUF_REMAIN(p) ((p->in_rptr >= p->in_wptr) ? \
113: (p->in_rptr - p->in_wptr) : \
114: (p->in_rptr + p->in_bufsz - p->in_wptr))
115:
116:
117: #define IN_BUF_SIZE(p) ((p->in_wptr >= p->in_rptr) ? \
118: (p->in_wptr - p->in_rptr) : \
119: (p->in_wptr + p->in_bufsz - p->in_rptr))
120:
121:
122: #define XOFF ('S'-'@')
123: #define XON ('Q'-'@')
124:
125:
126: typedef enum {
127: RTN_OK = 0,
128: RTN_NONE = -1,
129: RTN_TMOUT = -2,
130: RTN_ABORT = -3,
131: RTN_ERR = -4
132: } RTN;
133: typedef W WRTN;
134:
135:
136: #define OU_LOCK 17
137: #define IN_LOCK 16
138: #define FLG_OU_ABORT (1 << 3)
139: #define FLG_OU_NORM (1 << 2)
140: #define FLG_IN_ABORT (1 << 1)
141: #define FLG_IN_NORM (1 << 0)
142: #define FLG_OU_WAIPTN (FLG_OU_NORM | FLG_OU_ABORT)
143: #define FLG_IN_WAIPTN (FLG_IN_NORM | FLG_IN_ABORT)
144:
145:
146: #define Malloc(len) (void*)Imalloc(len)
147: #define Free(ptr) Ifree((void*)(ptr))
148:
149:
150: IMPORT W nPorts;
151: IMPORT LINE_INFO *LineInfo;
152: IMPORT W DebugPort;
153:
154:
155: #define isDebugPort(li) ( (li) == &LineInfo[DebugPort] )
156:
157:
158: IMPORT ER consMLock(FastMLock *lock, INT no);
159: IMPORT ER consMUnlock(FastMLock *lock, INT no);
160: IMPORT ER consCreateMLock(FastMLock *lock, UB *name);
161: IMPORT ER consDeleteMLock(FastMLock *lock);