/* DRIVERS.C */ #include #include #include /* ANSI Standard only */ #include #include #include "serial.h" #include "protocol.h" #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif /* size of the buffer to use for string incoming characters */ // #define COM_BUF_SIZE (62 * 1024) #define COM_BUF_SIZE 2048 char *buffer_start; /* beginning of the buffer */ char *buffer_end; /* end of the buffer */ /* pointer to next place to put character in */ char *buffer_in; char *buffer_out; /* place to get next character from */ int count = 0; /* number of characters in buffer */ int max_count; /* max number of chars ever in buffer */ void init_buf(void) { count = 0; max_count = 0; buffer_start = (char *) malloc( COM_BUF_SIZE ); if( buffer_start == NULL ) { printf( "\n** Can't malloc in init_buf(%u) **\n", COM_BUF_SIZE); exit( 1 ); } buffer_in = buffer_start; buffer_out = buffer_start; buffer_end = buffer_start + COM_BUF_SIZE - 10; memset( buffer_start, '*', COM_BUF_SIZE ); } /* init -- initialize the port */ /* buf_getch -- get a character from the buffer Update buffer_out Returns the character or ? if none */ char buf_getch(void) { char ch; /* character we got */ if (count == 0) return ('?'); ch = *buffer_out; buffer_out++; if (buffer_out == buffer_end) buffer_out = buffer_start; disable(); count--; enable(); return(ch); } /* serial_interrupt -- interrupt handler for serial input Called in interrupt mode by the hardware when a character is received on the serial input */ //far void interrupt serial_interrupt() { int int_status; /* status during interrupt */ disable(); int_status = inportb((int)&COM->status); /* tell device we have read interrupt */ (void)inportb((int)&COM->interrupt_enable); (void)inportb((int)&COM->interrupt_id); if ((int_status & S_RxRDY) == 0) { enable(); return; } *buffer_in = inportb((int)&COM->data) & 0x7F; buffer_in++; if (buffer_in == buffer_end) buffer_in = buffer_start; count++; if( count > max_count ) max_count = count; outportb(0x20, 0x20); enable(); }