Docsity

EECS 373 Lab 3: Serial Communications - Fall 1998, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
EECS 373 Fall 1998
Lab 3: Simple Serial Communication
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:
1. To develop and debug a modular assembly-language program to meet a given specifi-
cation.
2. To gain experience with assembly-language functions and procedures.
3. To understand the utility of generic programming interfaces (and specifically device
drivers).
4. To provide basic experience interfacing a serial communications device (UART).
Prelab Questions:
1. Write a function that takes a string pointer (i.e., the starting address of a null-termi-
nated array of characters) containing ASCII digits and returns the integer represented
by the string.
2. Write a function that takes an integer value and generates a string of ASCII digits (the
reverse of the previous function). The function should take two parameters, an integer
value and the address of a character array in which to put the string. There is no return
value.
3. Write a function that takes two string pointers and returns 1 if the strings are the same
and 0 if they are different.
4. Write out a high-level description of how your terminal interface program will work.
Decompose your program into functions, possibly including—but definitely not lim-
ited to—the functions from the previous three questions.
5. Write the ser_putchar and ser_getchar driver functions for the simulated UART.
Program Specification:
Your program will have two parts:
1. A command-line terminal interface, that accepts and processes lines of text input via a
serial port
pf3
pf4
pf5

Partial preview of the text

Download EECS 373 Lab 3: Serial Communications - Fall 1998 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

EECS 373 Fall 1998

Lab 3: Simple Serial Communication

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:

  1. To develop and debug a modular assembly-language program to meet a given specifi- cation.
  2. To gain experience with assembly-language functions and procedures.
  3. To understand the utility of generic programming interfaces (and specifically device drivers).
  4. To provide basic experience interfacing a serial communications device (UART).

Prelab Questions:

  1. Write a function that takes a string pointer (i.e., the starting address of a null-termi- nated array of characters) containing ASCII digits and returns the integer represented by the string.
  2. Write a function that takes an integer value and generates a string of ASCII digits (the reverse of the previous function). The function should take two parameters, an integer value and the address of a character array in which to put the string. There is no return value.
  3. Write a function that takes two string pointers and returns 1 if the strings are the same and 0 if they are different.
  4. Write out a high-level description of how your terminal interface program will work. Decompose your program into functions, possibly including— but definitely not lim- ited to— the functions from the previous three questions.
  5. Write the ser_putchar and ser_getchar driver functions for the simulated UART.

Program Specification:

Your program will have two parts:

  1. A command-line terminal interface, that accepts and processes lines of text input via a serial port
  1. A “device driver” for the simple simulated serial device provided with the SingleStep simulator

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:

  1. Backspace (ASCII code 0x8): If at the beginning of an input line, do nothing. Other- wise, back up the buffer pointer instead of storing the backspace character in the buffer. (That is, make it do the right thing.)

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:

  1. The device driver routines and the terminal program should be in separate .s files. Run each file through the assembler independently to generate two .o files. To get a complete executable, you will link the two files together by specifying both on the linker command line. For example, if you start with the files terminal.s and sim- driver.s, and assemble these to terminal.o and simdriver.o, you could link them like this: ldppcl -dn -A lab3-lnk.txt -o lab3.elf terminal.o simdriver.o
  2. To run your program on the simulator, you will need to tell the simulator to configure the simulated UART. You will do this using the mem command, which manages the simulated memory space. First, you need to open a SingleStep command window by clicking the command-window button or selecting Command from the Window pull- down menu. Then type the command mem with no arguments. This will display all of the current memory regions and their attributes. Verify that there are no memory regions that contain the address 0xFE000000. If there is a region at that address, delete it by typing mem -d 0xfe000000. Finally, type the command mem 0xfe000000 periph=xuart.dll nooverrun to load the simulated UART and map its registers starting at 0xFE000000. (The nooverrun option tells it not to generate overrun errors.)
  3. Every function should start with a comment stating the input parameters, return value, and what the function does. Include a C++-style function prototype in the comment.
  4. The .skip n assembler directive reserves n bytes of memory and initializes them to zero. Use this directive to allocate space for your input line buffer. For example, buffer: .skip 100 will allocate 100 bytes and set the symbol buffer to the address of the first byte.

Procedure (in the lab):

  1. Run and debug your code using your serial driver on the simulator.
  2. Once it is running, demonstrate it for your TA.
  3. Copy adsinit.o from K:\F98\EECS373\LAB3 to your working directory. This file is the device driver for the target board’s serial port device.
  4. Relink your program, linking in adsinit.o in place of your serial driver file.
  5. Run HyperTerminal on the PC. HyperTerminal is a terminal emulator that talks to one of the PC’s serial ports, sending characters you type and displaying characters that are received. There is a cable connecting the PC’s COM2: serial port to the serial port on the target board. Detailed instructions for configuring and running HyperTerminal for this lab will be available in the lab.
  6. Run the SingleStep On-Chip debugger and download your program to the target board.