1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: 17: 18: 19: 20:
21:
22: #include "line_drv.h"
23: #include "svc/ifserialio.h"
24: #include <tm/tmonitor.h>
25:
26:
27: IMPORT ER con_def_subsys(W svc, W pri, void *svcent, void *brkent);
28:
29:
30: #include "portdef.h"
31:
32:
33: EXPORT LINE_INFO *LineInfo;
34: EXPORT W nPorts = N_PORTS;
35:
36: 37: 38:
39: LOCAL ER _serial_in(SERIAL_SERIAL_IN_PARA *p)
40: {
41:
42: if (p->port < 0 || p->port >= nPorts) return E_PAR;
43:
44: return (*(LineInfo[p->port].scdefs.fn->in))(
45: &LineInfo[p->port], (UB*)p->buf, p->len, p->alen,
46: (p->tmout < 0) ? TMO_FEVR : p->tmout);
47: }
48:
49: 50: 51:
52: LOCAL ER _serial_out(SERIAL_SERIAL_OUT_PARA *p)
53: {
54:
55: if (p->port < 0 || p->port >= nPorts) return E_PAR;
56: if (p->len <= 0) return E_OK;
57:
58: return (*(LineInfo[p->port].scdefs.fn->out))(
59: &LineInfo[p->port], (UB*)p->buf, p->len, p->alen,
60: (p->tmout < 0) ? TMO_FEVR : p->tmout);
61: }
62:
63: 64: 65:
66: LOCAL ER _serial_ctl(SERIAL_SERIAL_CTL_PARA *p)
67: {
68:
69: if (p->port < 0 || p->port >= nPorts) return E_PAR;
70:
71: return (*(LineInfo[p->port].scdefs.fn->ctl))
72: (&LineInfo[p->port], p->kind, p->arg);
73: }
74:
75: 76: 77:
78: LOCAL ER serial_io_entry(void *para, W fn)
79: {
80: switch(fn) {
81: case SERIAL_SERIAL_IN_FN: return _serial_in(para);
82: case SERIAL_SERIAL_OUT_FN: return _serial_out(para);
83: case SERIAL_SERIAL_CTL_FN: return _serial_ctl(para);
84: }
85: return E_RSFN;
86: }
87:
88: 89: 90:
91: LOCAL void serial_io_break(ID tskid)
92: {
93: tk_dis_wai(tskid, TTW_FLG);
94: }
95:
96: 97: 98:
99: EXPORT ER startup_serial_io(BOOL StartUp)
100: {
101: LINE_INFO *li;
102: W port, baud;
103: static union objname name = {{ "sio0" }};
104:
105:
106: if ((baud = tm_extsvc(0x00, 0, 0, 0)) < 19200) baud = 0;
107:
108:
109: INIT_AUXPORT(StartUp);
110:
111: if (!StartUp) {
112:
113: con_def_subsys(SERIAL_SVC, SERIAL_PRI, NULL, NULL);
114:
115:
116: START_AUXPORT(FALSE);
117:
118:
119: for (port = 0; port < nPorts; port++) {
120: li = &LineInfo[port];
121: li->scdefs = PortDefs[port];
122:
123:
124: (*(li->scdefs.fn->down))(li);
125:
126:
127: if (li->in_buf) Free(li->in_buf);
128:
129: 130:
131: if (li->flg > 0) consDeleteMLock(&li->lock);
132: }
133:
134:
135: if (LineInfo) Free(LineInfo);
136:
137: return E_OK;
138: }
139:
140:
141: START_AUXPORT(TRUE);
142:
143:
144: LineInfo = (LINE_INFO *)Malloc(sizeof(LINE_INFO) * nPorts);
145: if (! LineInfo) {nPorts = 0; return E_NOMEM;}
146: MEMSET(LineInfo, 0, sizeof(LINE_INFO) * nPorts);
147:
148:
149: for (port = 0; port < nPorts; port++) {
150: li = &LineInfo[port];
151: li->scdefs = PortDefs[port];
152:
153:
154: if (baud != 0) li->scdefs.mode.baud = baud;
155:
156: name.s[3] = '0' + port;
157:
158:
159: li->in_buf = Malloc(li->in_bufsz = DEF_INBUFSZ);
160: if (li->in_buf == NULL) return E_NOMEM;
161:
162: 163:
164: li->flg = consCreateMLock(&li->lock, name.s);
165:
166:
167: li->flow.csflow = 1;
168: li->flow.rsflow = 1;
169:
170:
171: (*(li->scdefs.fn->up))(li);
172: }
173:
174:
175: return con_def_subsys(SERIAL_SVC, SERIAL_PRI,
176: &serial_io_entry, &serial_io_break);
177: }