Screen Version
School of Computer Science & Engineering
University of New South Wales

 Advanced Operating Systems 
 COMP9242 2004/S2 

Serial Library

The serial library provides a very simple device driver for the serial port chipset found in the U4600 machine.

serial_init

struct serial * serial_init(bs_seq spaces)

serial_init initalises the state of the serial driver and returns a handle that must be passed to other serial functions. The spaces parameter defines where in physical memory the serial chips have been mapped. The provided code in hardware.c provides an example of how this is used.

serial_interrupt_handler

int serial_interrupt_handler(struct serial *serial);

serial_interrupt_handler should be called when ever and interrupt for the serial device occurs. The serial parameter should be a variable previously returned by serial_init. Again, hardware.c provides an example of how this function is used.

serial_send

int serial_send(struct serial *serial, char *data, int len);

serial_send will write len bytes of data to the serial line. This function returns the number of bytes written, which may be less than len. This occurs if the serial driver's internal buffer fills faster than it can actually output data. In this case it is up to the calling code to handle the situation, either by retrying or returning an error to the user.

It should be noted that the serial driver performs conversion of \n to \r\n.

serial_register_handler

int serial_register_handler(struct serial *serial, void (*handler) (char c));

To receive input from the serial line you must register a handler function, which will be called by the serial driver when input is available. The provided function simply takes the inputted character as it's only argument. This function will be called during the interrupt context so it should be reasonably light-weight.


Last modified: 23 Aug 2004.