



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Introduction:
In this lab, you will write an assembly-language program that implements a simple com- mand-line interface using a set of generic serial communications functions (a serial “device driver” interface). You will also implement a device driver for a simple simulated serial communications device. You will run your program on the simulator, using your device driver, and on the target boards in the lab, using our device driver for the more complex serial communications device found there.
Goals:
Prelab Questions:
Program Specification:
Your program will have two parts:
The purpose of a device driver is to provide a generic function-call interface for a particu- lar type or class of device, hiding the details of the specific device from the rest of the sys- tem. The logical separation provided by the device-driver interface lets you use the same application on different systems with different devices, as long as each different device has a compatible device driver. Similarly, if you have a new device, writing a single device driver will allow all of the applications that use that driver interface to work with the new device.
A serial communications device is simply a device that communicates data one bit at a time over a single data wire. (Most serial interfaces have a handful of wires, including perhaps one data wire in each direction, a ground wire, and some wires for control or clock signals.) We will discuss serial communications concepts in detail later in this term. The most common serial interface device is called a UART, for Universal Asynchronous Receiver/Transmitter. This device converts data to and from the serial format one byte at a time.
The device-driver interface. This interface is very simple and would work for any charac- ter-at-a-time device (such as a printer). The ser_init function should be called exactly once at the beginning of the program. This function initializes the serial port to a default state. The other functions, ser_putchar and ser_getchar, send and receive individual char- acters (bytes) via the serial port. These are blocking calls, i.e., if they can’t immediately perform their function they will wait inside the function until they can. For example, if there’s no character to receive because the user hasn’t typed one yet, ser_getchar will wait until one is typed.
The terminal interface program. This program communicates with a user typing at a ter- minal. The terminal sends each character, as it is typed, to the system via the serial port. Your program will read characters from the serial port as they arrive and store them in a buffer array. The following characters must be treated specially:
Function Name
Parameters Return Value Function
ser_init None None Initializes serial port.
ser_putchar ASCII code of character to output
None Writes a character to the serial port.
ser_getchar None ASCII code of input character
Reads a character from the serial port. Waits until a character is ready.
ENABLE (register #0)
This register contains the receiver and transmitter enable control bits as well as the clear overrun error bit. Setting RE (bit #7) enables the receiver. Setting TE (bit #6) enables the transmitter. Writing a 1 to ER (bit #0) clears the transmitter and receiver overrun error flags. ER is a write-only bit which always reads as 0. RSTAT (register #3)
This read-only register contains the receiver’s status. If RF (bit #7) is set, the receiver’s data buffer is full. You may obtain the character the receiver just received by reading the RDATA register (which clears this bit). If RO (bit #0) is set, a receiver-overrun error has occurred, indicating that the receiver has dropped at least one incoming character. You may clear the RO status bit by writing a 1 to the ER bit in the CONTROL reg- ister. RDATA (register #4) This read-only register is the receiver’s data buffer. If the receiver is full, this register contains the last char- acter received by the receiver. Reading RDATA always clears the RSTAT register’s receiver-full status bit. TSTAT (register #5)
This read-only register contains the transmitter’s status. If TE (bit #7) is set, the transmitter data buffer is empty and the transmitter is ready to transmit another char- acter (assuming that the transmitter is enabled). If TO (bit #0) is set, a transmitter-overrun error has occurred, indicating that the transmitter has dropped at least one outgoing character. You may clear the TO status bit by writing a 1 to the ER bit in the CONTROL register. TDATA (register #6) This write-only register is the transmitter’s data buffer. If the transmitter is ready to transmit, the uart trans- mits any character written to this register. Writing to TDATA always clears the transmitter-empty status bit (TE) in the TSTAT register.
MSB 7 6 5 4 3 2 1
LSB 0
RE TE - - - - - ER
MSB 7 6 5 4 3 2 1
LSB 0
RF - - - - - - RO
MSB 7 6 5 4 3 2 1
LSB 0
TE - - - - - - TO
Notes and Hints:
Procedure (in the lab):