embedded-software
reusable software modules for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uart.c File Reference
#include "uart.h"
#include "hal_general.h"
Include dependency graph for uart.c:

Data Structures

struct  receiver_list_t
 

Macros

#define UART_BAUD   115200
 
#define NUM_RECEIVERS   2
 
#define UART_TX_BUFFER_LENGTH   128
 
#define UART_RX_BUFFER_LENGTH   32
 
#define UART_MAX_CHARS_PER_CALL   20
 

Typedefs

typedef void(* receiver_callback_t )(uint8_t)
 

Functions

void UART_Init (uint8_t channel)
 
void UART_Tick (void)
 Main UART routine which calls subscribers and handles errors. More...
 
void UART_ReconfigureBaud (uint8_t channel, uint32_t baud)
 Change baud rate. More...
 
void UART_WriteByte (uint8_t channel, uint8_t data)
 Write a single byte to UART. More...
 
int8_t UART_Write (uint8_t channel, uint8_t *data, uint16_t length)
 Write chunk of data to UART tx buffer. More...
 
int8_t UART_RegisterReceiver (uint8_t channel, receiver_callback_t fn)
 register a character receiver for a UART channel to receive data More...
 
void UART_UnregisterReceiver (uint8_t channel, receiver_callback_t fn)
 Unregister a receiver added by UART_RegisterReceiver() More...
 
uint8_t UART_IsTransmitting (uint8_t channel)
 Returns 0 or num bytes to indicate if the UART is transmitting. More...
 
void UART_Tx_Handler (uint8_t channel)
 UART transmit interrupt handler. More...
 
void UART_Rx_Handler (uint8_t channel)
 UART receive interrupt handler. More...
 
void UART_Error_Handler (uint8_t channel, enum uart_errors error)
 UART error (interrupt) handler. More...
 
void UART_RegisterErrorCallback (uint8_t channel, void(*callback)(enum uart_errors))
 Register callback function to handle UART errors. More...
 
void UART_RegisterTxOverwriteCallback (uint8_t channel, void(*overwriteCallback)(void))
 Register callback function to be called when/if the UART Tx buffer overflows. More...
 
void UART_RegisterRxOverwriteCallback (uint8_t channel, void(*overwriteCallback)(void))
 Register callback function to be called when/if the UART Rx buffer overflows. More...
 

Variables

struct {
   buffer_t *   rx
 
   buffer_t *   tx
 
   receiver_list_t *   receiverList
 
   uint8_t   errorStatus
 
   void(*   errorNotificationCallback )(enum uart_errors)
 
uart [NUM_UARTS]
 
uint8_t rx_flags
 
uint8_t error_flags
 

Macro Definition Documentation

#define NUM_RECEIVERS   2
#define UART_BAUD   115200
#define UART_MAX_CHARS_PER_CALL   20
#define UART_RX_BUFFER_LENGTH   32
#define UART_TX_BUFFER_LENGTH   128

Typedef Documentation

typedef void(* receiver_callback_t)(uint8_t)

Function Documentation

void UART_Error_Handler ( uint8_t  channel,
enum uart_errors  error 
)

UART error (interrupt) handler.

This function is implemented by the UART module (uart.c) but should be called by the error ISR for the given UART channel or when an error condition is detected by the HAL.

Parameters
channel- channel the interrupt occurred on

Here is the caller graph for this function:

void UART_Init ( uint8_t  channel)

Initialize UART module

Example usage:

UART_Init(UART0_CHANNEL);
Parameters
channel- The channel of UART to be used. Macros for these should be defined in the HAL of the specific device.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t UART_IsTransmitting ( uint8_t  channel)

Returns 0 or num bytes to indicate if the UART is transmitting.

Parameters
channel- UART channel to check
Returns
0 if not transmitting, number of bytes in buffer otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

void UART_ReconfigureBaud ( uint8_t  channel,
uint32_t  baud 
)

Change baud rate.

Parameters
channel- The channel of the UART to have its baud rate changed.
baud- The new baud rate.

Here is the call graph for this function:

Here is the caller graph for this function:

void UART_RegisterErrorCallback ( uint8_t  channel,
void(*)(enum uart_errors callback 
)

Register callback function to handle UART errors.

Will call the callback function when a UART error occurs. The callback should have no return value and a enum uart_errors input.

Parameters
channel- UART channel to tie the error callback function to
callback- function pointer to callback function: void CallbackName(enum uart_errors error)
int8_t UART_RegisterReceiver ( uint8_t  channel,
void(*)(uint8_t)  fn 
)

register a character receiver for a UART channel to receive data

The receiver function registered will be called by UART_Tick whenever a byte is received. The receiver function should have no return value and a char input.

Parameters
channel- UART channel to register receiver with
fn- function pointer to receiver function: void ReceiverName(char c)
Returns
-1 if channel is out of range, -2 if receiver list is full, 0 if successful

Here is the caller graph for this function:

void UART_RegisterRxOverwriteCallback ( uint8_t  channel,
void(*)(void)  overwriteCallback 
)

Register callback function to be called when/if the UART Rx buffer overflows.

Will be called when trying to transmit data and the Rx buffer is full. The callback should have no return value and no input.

Parameters
channel- UART channel to tie the Rx overwrite callback to
overwriteCallback- function pointer to callback function: void CallbackName(void)
void UART_RegisterTxOverwriteCallback ( uint8_t  channel,
void(*)(void)  overwriteCallback 
)

Register callback function to be called when/if the UART Tx buffer overflows.

Will be called when trying to transmit data and the Tx buffer is full. The callback should have no return value and no input.

Parameters
channel- UART channel to tie the tx overwrite callback to
overwriteCallback- function pointer to callback function: void CallbackName(void)
void UART_Rx_Handler ( uint8_t  channel)

UART receive interrupt handler.

REQUIRED to be called by HAL

This function is implemented by the UART module (uart.c) but should be called by the ISR for the given UART channel.

Parameters
channel- channel the interrupt occurred on

Here is the call graph for this function:

Here is the caller graph for this function:

void UART_Tick ( void  )

Main UART routine which calls subscribers and handles errors.

If the task management module is used and USE_MODULE_TASK is defined then this function will automatically run via the task management system. Otherwise the user should call UART_Tick() frequently to handle incoming data.

Here is the call graph for this function:

Here is the caller graph for this function:

void UART_Tx_Handler ( uint8_t  channel)

UART transmit interrupt handler.

REQUIRED to be called by HAL

This function is implemented by the UART module (uart.c) but should be called by the ISR for the given UART channel.

Parameters
channel- channel the interrupt occurred on

Here is the call graph for this function:

Here is the caller graph for this function:

void UART_UnregisterReceiver ( uint8_t  channel,
void(*)(uint8_t)  fn 
)

Unregister a receiver added by UART_RegisterReceiver()

Parameters
channel- UART channel to unregister receiver on
fn- function pointer to receiver function: void ReceiverName(char c)

Here is the caller graph for this function:

int8_t UART_Write ( uint8_t  channel,
uint8_t *  data,
uint16_t  length 
)

Write chunk of data to UART tx buffer.

Parameters
channel- the UART channel to send on
data- a pointer to the data to send
length- the amount of data to send
Returns
0 = success, -1 = not enough room in buffer, -2 = Invalid channel

Here is the call graph for this function:

Here is the caller graph for this function:

void UART_WriteByte ( uint8_t  channel,
uint8_t  c 
)

Write a single byte to UART.

Transmit a single byte over the UART channel

Parameters
channel- The UART channel to send the byte over
c- the byte to send

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

uint8_t error_flags
void(* errorNotificationCallback)(enum uart_errors)
uint8_t errorStatus
receiver_list_t* receiverList
buffer_t* rx
uint8_t rx_flags
buffer_t* tx
struct { ... } uart[NUM_UARTS]