Well, I'll leave the details of my systems programming project (first systems prog. class for me) to the web page:
http://www.cs.rit.edu/~wrc/courses/sp1/projects/3/
In short, we have to communicate with a dummy terminal via a serial connection, using interrupts. This is all being run on a standalone framework WITHOUT an operating system running (for details, see the project page). Anyway, I wanted to get feedback on my serial ISR. This is the first one I ever wrote.
It is in C, and as many will likely point out, could be written better in assembly, but I have other classes to work/study for so time is limited.
Code: Select all
void serial_isr( int vector, int code ) {
char ch;
while( ((__inb(UA4_LSR) & UA4_LSR_RXDA) != 0) ||
((__inb(UA4_LSR) & UA4_LSR_TXRDY)!= 0) ) {
if( (__inb(UA4_LSR) & UA4_LSR_RXDA) != 0 ) {
/* data ready for read */
if( in_space ) {
/* read char and strip parity bit */
ch = __inb( UA4_RXD ) & 0x7f;
if((ch = '\r') && !READY) {
READY = 1;
break;
}
/* place char in input buffer */
input_buffer[ in_index++ ] = ch;
in_space--;
} else {
/* input buffer full */
}
} /* recieve data */
if( (__inb(UA4_LSR) & UA4_LSR_TXRDY) != 0) {
/* ready to transmit data */
if( out_index ) {
ch = get_next_out_char(); /* get oldest char in buffer (first in) */
__outb( UA4_TXD, ch ); /* output byte to port */
} else {
/* no data to transmit */
}
} /* transmit data */
}
__outb(PIC_MASTER_CMD_PORT,PIC_EOI); /* acknowledge irq */
} /* serial_isr() */
The get_next_out_char() function returns the oldest (first in) character in the user buffer, and moves all the characters to the left one space. Could have used a circular buffer, but oh well...