#include #include #include "COMMDRV.H" const unsigned INT = 5; const unsigned RECEIVE = 0; const unsigned TRANSMIT = 0; const unsigned L_DIVISOR = 0; const unsigned U_DIVISOR = 1; const unsigned INT_ENB = 1; const unsigned INT_ID = 2; const unsigned LINE_CTRL = 3; const unsigned MODEM_CTRL = 4; const unsigned LINE_STAT = 5; const unsigned MODEM_STAT = 6; static void near dummy (void) {} // returns negation of contents of on-board 8253 counter static unsigned near readtimer (void) { asm pushf asm cli asm mov al,0h asm out 43h,al dummy(); asm in al,40h asm mov bl,al dummy(); asm in al,40h asm mov bh,al asm not bx asm popf return( _BX ); } // computer independent delay used for timout purposes. void comdelay( unsigned timer_ticks ) { unsigned long stop; unsigned cur, prev; stop = (prev = readtimer()) + (timer_ticks); while ((cur = readtimer()) < stop) { if (cur < prev) { if (stop < 0x10000L) break; stop -= 0x10000L; } prev = cur; } } void initCommCard(unsigned baseAddr, unsigned baudRate) { unsigned divisor; // Oscillator frequency is 1.8432MHz, or 1,843,200 Hz // The divisor is calculated by dividing the frequency by 16, then dividing // again by the baudrate, or --- divisor = (f / 16) / baudrate // 1,843,200 / 16 is 115200, so - divisor = 115200 / baudRate; // tell card, we are about to set options outportb(baseAddr + LINE_CTRL, 0x80); // assign 16 bit AX register to our divisor, so we can load the // card with the low and high bytes of the divisor. _AX = divisor; outportb(baseAddr + L_DIVISOR, _AL); outportb(baseAddr + U_DIVISOR, _AH); // set the card the 7 bits of data, even parity and 1 stop bit outportb(baseAddr + LINE_CTRL, 0x1A); outportb(baseAddr + MODEM_CTRL, 0x00); // clear the receive buffer delay(50); inportb(baseAddr + RECEIVE); delay(50); inportb(baseAddr + RECEIVE); } void writePod(unsigned baseAddr, char message[255]) { unsigned char x, times; // get length of the string to send x = strlen(message); // set the card into transmit mode outportb(baseAddr + MODEM_CTRL, 0x0F); for (times = 0; times < x; times++) { // wait until the card is ready to transmit a character while ((inportb(baseAddr+LINE_STAT) & 0x20) == 0); // transmit the character outportb(baseAddr+TRANSMIT, message[times]); } // wait until the character is transmitted while ((inportb(baseAddr+LINE_STAT) & 0x20) == 0); // transmit a Carriage Return outportb(baseAddr+TRANSMIT, 0x0D); // wait until CR is transmitted while ((inportb(baseAddr+LINE_STAT) & 0x20) == 0); // wait for the card to come back while ((inportb(baseAddr+LINE_STAT) & 0x40) == 0); // place the card into receive mode outportb(baseAddr+MODEM_CTRL, 0x0D); } void readPod(unsigned baseAddr, char message[255]) { unsigned char x = 255, ch; char retstring[255] = ""; unsigned int timeout; do { // character location in string is incremented x++; // timeout initialized timeout = 200; do { // decrement our timeout counter timeout--; // wait for 200 counter ticks comdelay(200); // wait until the card sees a character or until our counter has // timed out. } while ((timeout) && ((inportb(baseAddr+LINE_STAT) & 0x01) == 0x00)); // if it has not timed out, store the character if (timeout != 0x00) retstring[x] = inportb(baseAddr + RECEIVE); // otherwise, return with an error message else { strcpy(message, "??ERROR!"); return; } // repeat for fifty characters } while ((retstring[x] != 0x0D) && (x-1 != 250)); // null terminate the return string retstring[x] = 0x00; // copy it to the string pointer strcpy(message, retstring); // and clear the receive buffers delay(50); inportb(baseAddr + RECEIVE); delay(50); inportb(baseAddr + RECEIVE); }