embedded-software
reusable software modules for embedded systems
|
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 |
#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 void(* receiver_callback_t)(uint8_t) |
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.
channel | - channel the interrupt occurred on |
void UART_Init | ( | uint8_t | channel | ) |
Initialize UART module
Example usage:
channel | - The channel of UART to be used. Macros for these should be defined in the HAL of the specific device. |
uint8_t UART_IsTransmitting | ( | uint8_t | channel | ) |
Returns 0 or num bytes to indicate if the UART is transmitting.
channel | - UART channel to check |
void UART_ReconfigureBaud | ( | uint8_t | channel, |
uint32_t | baud | ||
) |
Change baud rate.
channel | - The channel of the UART to have its baud rate changed. |
baud | - The new baud rate. |
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.
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.
channel | - UART channel to register receiver with |
fn | - function pointer to receiver function: void ReceiverName(char c) |
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.
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.
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.
channel | - channel the interrupt occurred on |
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.
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.
channel | - channel the interrupt occurred on |
void UART_UnregisterReceiver | ( | uint8_t | channel, |
void(*)(uint8_t) | fn | ||
) |
Unregister a receiver added by UART_RegisterReceiver()
channel | - UART channel to unregister receiver on |
fn | - function pointer to receiver function: void ReceiverName(char c) |
int8_t UART_Write | ( | uint8_t | channel, |
uint8_t * | data, | ||
uint16_t | length | ||
) |
Write chunk of data to UART tx buffer.
channel | - the UART channel to send on |
data | - a pointer to the data to send |
length | - the amount of data to send |
void UART_WriteByte | ( | uint8_t | channel, |
uint8_t | c | ||
) |
Write a single byte to UART.
Transmit a single byte over the UART channel
channel | - The UART channel to send the byte over |
c | - the byte to send |
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] |