10 #define F_1_1000 (F1_0/1000) // 1/1000
12 struct portparam { int base,irq; };
13 struct portparam portparams[4] = {{0x3f8, 4}, {0x2f8, 3}, {0x3e8, 4}, {0x2e8, 3}};
15 /* return Data Carrier Detect status */
16 int comm_get_dcd(comm_port *port) {
17 return (inportb(port->MSR) & MSR_DCD) != 0;
20 void comm_printf(PORT *port, char *msg, ...) {
25 vsprintf(buf, msg, vp);
27 mprintf((0, "comm_printf: writing \"%s\"\n", buf));
28 WriteBuffer(port, buf, strlen(buf));
31 PORT * PortOpenGreenleafFast(int port, int baud, char parity, int databits, int stopbits)
34 static int did_init = 0;
41 if (!(com = comm_port_init(port))) {
42 mprintf((1,"comm_port_init: %s\n", szDZCommErr));
46 com->nPort = portparams[port].base;
47 com->nIRQ = portparams[port].irq;
49 case 'N': com->nParity = NO_PARITY; break;
50 case 'E': com->nParity = EVEN_PARITY; break;
51 case 'O': com->nParity = ODD_PARITY; break;
54 case 5: com->nData = BITS_5; break;
55 case 6: com->nData = BITS_6; break;
56 case 7: com->nData = BITS_7; break;
57 case 8: com->nData = BITS_8; break;
60 case 1: com->nStop = STOP_1; break;
61 case 2: com->nStop = STOP_2; break;
63 com->control_type = NO_CONTROL;
64 if (!comm_port_install_handler(com)) {
65 mprintf((1,"comm_port_install: %s\n", szDZCommErr));
66 comm_port_delete(com);
72 void SetDtr(PORT *port,int state)
77 void SetRts(PORT *port,int state)
82 void UseRtsCts(PORT *port,int state)
84 #if 0 /* disabled for now */
85 if (state && port->control_type != RTS_CTS) {
88 if (!queue_empty(port->OutBuf))
89 outportb(port->MCR,inportb(port->MCR)|0x02); //setting RTS
90 port->control_type = RTS_CTS;
91 } else if (!state && port->control_type == RTS_CTS) {
92 port->control_type = NO_CONTROL;
93 if (!queue_empty(port->OutBuf))
94 interrupt_on(port, THREINT);
100 void WriteChar(PORT *port, char ch)
102 //mprintf((0, "(%d,%d)", port->OutBuf->head, port->OutBuf->tail));
103 //mprintf((0, ">%02x ", (unsigned char)ch));
104 comm_port_out(port, ch);
108 void ClearRXBuffer(PORT *port)
110 queue_reset(port->InBuf);
113 int ReadBufferTimed(PORT *port, char *buf, int length, int timeout)
115 fix stop = timer_get_fixed_seconds() + timeout * F_1_1000;
120 while (stop >= timer_get_fixed_seconds()) {
121 if ((c = comm_port_test(port)) >= 0) {
122 mprintf((0, "<%02x ", c));
132 int Change8259Priority(int irq)
137 int FastSetPortHardware(int port, int IRQ, int baseaddr)
139 portparams[port].irq = IRQ;
140 portparams[port].base = baseaddr;
144 int FastGetPortHardware(int port, int *IRQ, int *baseaddr)
146 *IRQ = portparams[port].irq;
147 *baseaddr = portparams[port].base;
151 void FastSet16550TriggerLevel(int level)
155 void FastSet16550UseTXFifos(int on)
160 void FastSavePortParameters(int port)
164 int PortClose(PORT *port)
166 comm_port_delete(port);
170 void FastRestorePortParameters(int port)
174 int GetCd(PORT *port)
176 return comm_get_dcd(port);
179 int ReadCharTimed(PORT *port, int timeout)
181 fix stop = timer_get_fixed_seconds() + timeout * F_1_1000;
184 while (stop >= timer_get_fixed_seconds() && (c = comm_port_test(port)) < 0)
187 mprintf((0, "<%02x ", c));
191 int ReadChar(PORT *port)
193 int c = comm_port_test(port);
195 // mprintf((0, "<%02x ", c));
199 void ClearLineStatus(PORT *port)
203 void WriteBuffer(PORT *port, char *pbuff, int len)
205 mprintf((0, ">x%d ", len));
207 comm_port_out(port, *(pbuff++));
211 int HMInputLine(PORT *port, int timeout, char *buf, int bufsize)
213 fix stop = timer_get_fixed_seconds() + timeout * F_1_1000;
216 int bufleft = bufsize;
218 mprintf((1, "port->InBuf->head=%d, port->InBuf->tail=%d\n", port->InBuf->head,
220 while (stop >= timer_get_fixed_seconds()) {
221 if ((c = comm_port_test(port)) >= 0) {
222 mprintf((0,"got char %d (%c)", c, c >= 32 ? c : '.'));
223 if (c == '\n' && p > buf) {
225 mprintf((0,"got line \"%s\"", buf));
226 if (p - buf >= 2 && !strncmp(buf, "AT", 2)) { /* assume AT... response is echo */
234 if (c != '\r' && c != '\n') {
236 return -1; // buffer overflow
242 mprintf((0,"hminputline: timeout\n"));
246 void HMWaitForOK(int timeout, char *buf)
248 /* what is this supposed to do without a port handle? */
251 void HMSendStringNoWait(PORT *port, char *pbuf, int a)
253 comm_printf(port, "%s\r", pbuf);
256 int HMSendString(PORT *port, char *msg)
260 HMSendStringNoWait(port, msg, -2);
261 // HMInputLine(port, 5000, buf, sizeof(buf) - 1); /* 5 sec timeout */
262 // if (!strncmp(buf, "OK", 2))
264 // return -1; // Error
265 if(HMInputLine(port, 5000, msg, sizeof(msg) - 1) >= 0)
269 //added on 11/5/98 by Victor Rachels to wait less
270 int HMSendStringWait(PORT *port, char *msg, int wait)
272 HMSendStringNoWait(port, msg, -2);
273 if(HMInputLine(port, wait, msg, sizeof(msg) - 1) >= 0)
277 //end this section addition - VR
279 void HMReset(PORT *port)
283 void HMDial(PORT *port, char *pPhoneNum)
285 comm_printf(port, "ATD%s\r", pPhoneNum);
288 void HMAnswer(PORT *port)
290 comm_printf(port, "ATA\r");
293 void ClearTXBuffer(PORT *port)
295 queue_reset(port->OutBuf);
298 int GetLineStatus(PORT *port)