COrnell Miniature ATmel Operating System (COMATOS)

C Version UART Facilities

The C version of COMATOS includes UART transmit and receive function calls. These calls are based upon the Atmel application note referring to UART programming in C.


The C calls are primarily interrupt driven. Two ring buffers are allocated, one for transmit and another for receive. Their sizes must be powers of 2 bytes and can be modified via the UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants in the comatos8515.h header file.

Initializing the UART

The OSInitUART function activates UART functionality. It takes one parameter, a value to be loaded into the UBRR register to set the baud rate. See the Atmel documentation for details on how to use the UBRR register.

Transmitting Data

Two calls are available for transmitting data: OSUARTTransmitByte (for sending one character) and OSUARTTransmitBytes (for sending multiple characters). These functions place the data intended for transmission into the transmit buffer. Once the data is in the buffer, the interrupts take care of transmission and control is returned to the task which requested the transmission. Thus, these calls are non-blocking. However, if space is not available in the transmit buffer because another transmission is in progress, these calls will wait for space to become available. Note that it is possible for a task to time-out waiting for buffer space to become available. Be sure to set the maximum timeout value for enough time to allow for buffer space to become available.

Receiving Data

Two calls are available for transmitting data: OSUARTReceiveByte (for receiving one character) and OSUARTReceiveBytes (for receiving multiple characters). Reception of data is interrupt driven. The receive ISR places received characters into the receive buffer. The receive calls remove data from the buffer and return it to the calling task. If a character is not available in the buffer when OSUARTReceiveByte is called, it will wait for one to become available. Note that a task can time-out waiting for a character to arrive. A more robust technique involves using OSUARTReceiveBytes. The number of bytes to receive is passed to this function. If that number is not available, whatever bytes are in the buffer are returned to the calling task. In addition, the function returns the number of bytes read.

Questions? Contact Ben Greenblatt