This laboratory will focus in I/O programming with interrupts. The interrupt programming will also be part of the homework assignment. Labs checked off after the start of lab on Friday, February 28, will receive a minimum 3-point (of 10 possible) late penalty.
Thus, there are four routines: a read interrupt service routine, a write interrupt service routine, a read request routine, and a write request routine. Additionally, you will write a main program that writes a preprogrammed string to the terminal (using the write request routine) and then executes an infinite loop of calls to the read and write request routines to test keyboard echo. Ideally, implement two versions of the write request routine: one for single characters, and the other for null-terminated strings.
The write queue will need two pointers: the front and the back. When a character is added to the queue, it is added to the front (which is then incremented). When a character is transferred across the serial line, it is removed from the back after the transfer is complete, as indicated by an interrupt. In the write request routine (called by the main program), if the queue is full, enter a busy loop until it is not, and write a character to the front of the queue. If the write queue now has more than one character (the one you just added plus at least one more), a write is in progress, and the new character will be appended to the previous write request. If the write queue now has exactly one character (the one you just added), initiate a new transfer by copying the data to the UART. In the write interrupt service routine, update the write queue to remove the character just transmitted and, if present, transmit the next character.
The read queue acts much the same way as the write queue: characters are added to the front of the queue by the read interrupt service routine and read from the back by the read request routine. If the read queue is empty, the read request routine should enter a loop until a character is available.
Be sure to mask out interrupts while changing the queue pointers. If the read queue becomes full, discard additional characters. The queues must be circular, and should be small enough to verify their function (20 or fewer characters).