Home Teaching Research Publications

Advanced Operating Systems (LV 7680)

Serial Library

The serial library provides a very simple virtual device driver that uses UDP/IP to send data, without error correction or packet loss detection, to the AOS21 port (UDP 26721) on your development machine. The port number was chosen to be easy to remember; Imagine you are dialing 'AOS21', the port number is the series of digits you dialled.

IP addresses

The IP addresses used by SOS are configured using cmake, and referred to as SosIP and SosGateway. See the framework documentation for configuring variables with CMake. However, both IP addresses have been set by default to the IPs expected by U-Boot on the odroid-c2.

Libserial interface

serial_init

struct serial * serial_init()

serial_init initialises the state of the serial driver and returns a handle that must be passed to other serial functions.

serial_send

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

serial_send will write len bytes of data to the AOS20 port (UDP 26721) on your development machine. 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.

You can see this output by running netcat: nc -up 26721 192.168.168.2 26721 in a terminal window, assuming SosIP is set to 192.168.168.2.

serial_register_handler

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

To receive input from the netcat terminal you must register a handler function, which will be called by the serial driver when the network makes data available. The provided function simply takes the inputted character as its only argument. This function will be called during an interrupt context so it should be reasonably light-weight.

What's really happening here

Due to historical reasons we call this driver a serial driver, even though it has nothing to do with serial ports anymore. In reality it is a virtual serial driver over ethernet, using UDP. The serial_send() function, in the driver, takes a block of data, and uses the picotcp library to package the message up into UDP frames, which are sent to the SosGateway (your machine).

netcat(nc) is a pretty cool program, once it has received data from a particular machine it will connect() to the machine and send all input data onto your service.