Interrupt driven serial IO

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tja1618
Posts: 4
Joined: Fri Feb 16, 2007 8:50 pm

Interrupt driven serial IO

Post by tja1618 »

I already posted a more general topic in the General Programming forum, but I was hoping for more responses here.

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...
Currently working toward B.S in computer science

-> heading into systems programming sequence
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: Interrupt driven serial IO

Post by Alboin »

tja1618 wrote:I already posted a more general topic in the General Programming forum, but I was hoping for more responses here.
Tis a small forum. Personally, I check this forum, General Ramblings, and General Programming, and I think most other members here do something close to the same. So, I doubt you'll get better answers here. :wink:
C8H10N4O2 | #446691 | Trust the nodes.
Post Reply