9 #define F_1_1000 (F1_0/1000) // 1/1000
11 struct portparam { int base,irq; };
12 struct portparam portparams[4] = {{0x3f8, 4}, {0x2f8, 3}, {0x3e8, 4}, {0x2e8, 3}};
14 /* return Data Carrier Detect status */
15 int comm_get_dcd(comm_port *port) {
16 return (inportb(port->MSR) & MSR_DCD) != 0;
19 void comm_printf(PORT *port, char *msg, ...) {
24 vsprintf(buf, msg, vp);
26 mprintf((0, "comm_printf: writing \"%s\"\n", buf));
27 WriteBuffer(port, buf, strlen(buf));
30 PORT * PortOpenGreenleafFast(int port, int baud, char parity, int databits, int stopbits)
33 static int did_init = 0;
40 if (!(com = comm_port_init(port))) {
41 mprintf((1,"comm_port_init: %s\n", szDZCommErr));
45 com->nPort = portparams[port].base;
46 com->nIRQ = portparams[port].irq;
48 case 'N': com->nParity = NO_PARITY; break;
49 case 'E': com->nParity = EVEN_PARITY; break;
50 case 'O': com->nParity = ODD_PARITY; break;
53 case 5: com->nData = BITS_5; break;
54 case 6: com->nData = BITS_6; break;
55 case 7: com->nData = BITS_7; break;
56 case 8: com->nData = BITS_8; break;
59 case 1: com->nStop = STOP_1; break;
60 case 2: com->nStop = STOP_2; break;
62 com->control_type = NO_CONTROL;
63 if (!comm_port_install_handler(com)) {
64 mprintf((1,"comm_port_install: %s\n", szDZCommErr));
65 comm_port_delete(com);
71 void SetDtr(PORT *port,int state)
76 void SetRts(PORT *port,int state)
81 void UseRtsCts(PORT *port,int state)
83 #if 0 /* disabled for now */
84 if (state && port->control_type != RTS_CTS) {
87 if (!queue_empty(port->OutBuf))
88 outportb(port->MCR,inportb(port->MCR)|0x02); //setting RTS
89 port->control_type = RTS_CTS;
90 } else if (!state && port->control_type == RTS_CTS) {
91 port->control_type = NO_CONTROL;
92 if (!queue_empty(port->OutBuf))
93 interrupt_on(port, THREINT);
99 void WriteChar(PORT *port, char ch)
101 //mprintf((0, "(%d,%d)", port->OutBuf->head, port->OutBuf->tail));
102 //mprintf((0, ">%02x ", (unsigned char)ch));
103 comm_port_out(port, ch);
107 void ClearRXBuffer(PORT *port)
109 queue_reset(port->InBuf);
112 int ReadBufferTimed(PORT *port, char *buf, int length, int timeout)
114 fix stop = timer_get_fixed_seconds() + timeout * F_1_1000;
119 while (stop >= timer_get_fixed_seconds()) {
120 if ((c = comm_port_test(port)) >= 0) {
121 mprintf((0, "<%02x ", c));
131 int Change8259Priority(int irq)
136 int FastSetPortHardware(int port, int IRQ, int baseaddr)
138 portparams[port].irq = IRQ;
139 portparams[port].base = baseaddr;
143 int FastGetPortHardware(int port, int *IRQ, int *baseaddr)
145 *IRQ = portparams[port].irq;
146 *baseaddr = portparams[port].base;
150 void FastSet16550TriggerLevel(int level)
154 void FastSet16550UseTXFifos(int on)
159 void FastSavePortParameters(int port)
163 int PortClose(PORT *port)
165 comm_port_delete(port);
169 void FastRestorePortParameters(int port)
173 int GetCd(PORT *port)
175 return comm_get_dcd(port);
178 int ReadCharTimed(PORT *port, int timeout)
180 fix stop = timer_get_fixed_seconds() + timeout * F_1_1000;
183 while (stop >= timer_get_fixed_seconds() && (c = comm_port_test(port)) < 0)
186 mprintf((0, "<%02x ", c));
190 int ReadChar(PORT *port)
192 int c = comm_port_test(port);
194 // mprintf((0, "<%02x ", c));
198 void ClearLineStatus(PORT *port)
202 void WriteBuffer(PORT *port, char *pbuff, int len)
204 mprintf((0, ">x%d ", len));
206 comm_port_out(port, *(pbuff++));
210 int HMInputLine(PORT *port, int timeout, char *buf, int bufsize)
212 fix stop = timer_get_fixed_seconds() + timeout * F_1_1000;
215 int bufleft = bufsize;
217 mprintf((1, "port->InBuf->head=%d, port->InBuf->tail=%d\n", port->InBuf->head,
219 while (stop >= timer_get_fixed_seconds()) {
220 if ((c = comm_port_test(port)) >= 0) {
221 mprintf((0,"got char %d (%c)", c, c >= 32 ? c : '.'));
222 if (c == '\n' && p > buf) {
224 mprintf((0,"got line \"%s\"", buf));
225 if (p - buf >= 2 && !strncmp(buf, "AT", 2)) { /* assume AT... response is echo */
233 if (c != '\r' && c != '\n') {
235 return -1; // buffer overflow
241 mprintf((0,"hminputline: timeout\n"));
245 void HMWaitForOK(int timeout, char *buf)
247 /* what is this supposed to do without a port handle? */
250 void HMSendStringNoWait(PORT *port, char *pbuf, int a)
252 comm_printf(port, "%s\r", pbuf);
255 int HMSendString(PORT *port, char *msg)
259 HMSendStringNoWait(port, msg, -2);
260 // HMInputLine(port, 5000, buf, sizeof(buf) - 1); /* 5 sec timeout */
261 // if (!strncmp(buf, "OK", 2))
263 // return -1; // Error
264 if(HMInputLine(port, 5000, msg, sizeof(msg) - 1) >= 0)
268 //added on 11/5/98 by Victor Rachels to wait less
269 int HMSendStringWait(PORT *port, char *msg, int wait)
271 HMSendStringNoWait(port, msg, -2);
272 if(HMInputLine(port, wait, msg, sizeof(msg) - 1) >= 0)
276 //end this section addition - VR
278 void HMReset(PORT *port)
282 void HMDial(PORT *port, char *pPhoneNum)
284 comm_printf(port, "ATD%s\r", pPhoneNum);
287 void HMAnswer(PORT *port)
289 comm_printf(port, "ATA\r");
292 void ClearTXBuffer(PORT *port)
294 queue_reset(port->OutBuf);
297 int GetLineStatus(PORT *port)