embedded-software
reusable software modules for embedded systems
|
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include "project_settings.h"
#include "buffer.h"
#include "hal_uart.h"
Go to the source code of this file.
enum | uart_errors { BREAK_ERROR = 0, PARITY_ERROR, FRAMING_ERROR, OVERRUN_ERROR, NUM_UART_ERRORS } |
void | UART_Init (uint8_t channel) |
void | UART_ReconfigureBaud (uint8_t channel, uint32_t baud) |
Change baud rate. More... | |
void | UART_WriteByte (uint8_t channel, uint8_t c) |
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... | |
uint8_t | UART_IsTransmitting (uint8_t channel) |
Returns 0 or num bytes to indicate if the UART is transmitting. More... | |
void | UART_Tick (void) |
Main UART routine which calls subscribers and handles errors. More... | |
int8_t | UART_RegisterReceiver (uint8_t channel, void(*fn)(uint8_t)) |
register a character receiver for a UART channel to receive data More... | |
void | UART_UnregisterReceiver (uint8_t channel, void(*fn)(uint8_t)) |
Unregister a receiver added by UART_RegisterReceiver() 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... | |
void | hal_UART_Init (uint8_t channel, uint32_t baud) |
initialize UART channel at specified baud rate More... | |
void | hal_UART_ReconfigureBaud (uint8_t channel, uint32_t baud) |
change the baud rate for the UART channel 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 | hal_UART_Enable (uint8_t channel) |
Enable UART peripheral for given channel. More... | |
void | hal_UART_Disable (uint8_t channel) |
Disable UART peripheral for given channel. More... | |
uint8_t | hal_UART_SpaceAvailable (uint8_t channel) |
return 0 if no space is available in the hardware UART tx buffer More... | |
uint8_t | hal_UART_DataAvailable (uint8_t channel) |
return 0 if no data is available in the hardware UART rx buffer More... | |
void | hal_UART_ClearRxIF (uint8_t channel) |
clear the UART rx interrupt flags More... | |
void | hal_UART_ClearTxIF (uint8_t channel) |
clear the UART tx interrupt flags More... | |
void | hal_UART_EnableRxInterrupt (uint8_t channel) |
enable the UART rx interrupt More... | |
void | hal_UART_EnableTxInterrupt (uint8_t channel) |
enable the UART tx interrupt More... | |
void | hal_UART_DisableRxInterrupt (uint8_t channel) |
disable the UART rx interrupt More... | |
void | hal_UART_DisableTxInterrupt (uint8_t channel) |
disable the UART tx interrupt More... | |
uint8_t | hal_UART_RxInterruptEnabled (uint8_t channel) |
Is UART rx interrupt enabled. More... | |
uint8_t | hal_UART_TxInterruptEnabled (uint8_t channel) |
Is UART tx interrupt enabled. More... | |
uint8_t | hal_UART_RxByte (uint8_t channel) |
Get character from UART hardware rx register. More... | |
void | hal_UART_TxByte (uint8_t channel, uint8_t data) |
send character to UART hardware tx register More... | |
Created on: Mar 12, 2014
Use this module for basic UART communications. Completely interrupt driven and buffered.
Normal usage is:
enum uart_errors |
NOTE: This enumeration has to occur BEFORE the include for the hal_uart.h because hal_uart.h includes this uart.h file so that it can see this error enumeration.
Enumerator | |
---|---|
BREAK_ERROR | |
PARITY_ERROR | |
FRAMING_ERROR | |
OVERRUN_ERROR | |
NUM_UART_ERRORS |
void hal_UART_ClearRxIF | ( | uint8_t | channel | ) |
clear the UART rx interrupt flags
void hal_UART_ClearTxIF | ( | uint8_t | channel | ) |
clear the UART tx interrupt flags
uint8_t hal_UART_DataAvailable | ( | uint8_t | channel | ) |
return 0 if no data is available in the hardware UART rx buffer
REQUIRED
void hal_UART_Disable | ( | uint8_t | channel | ) |
Disable UART peripheral for given channel.
void hal_UART_DisableRxInterrupt | ( | uint8_t | channel | ) |
disable the UART rx interrupt
void hal_UART_DisableTxInterrupt | ( | uint8_t | channel | ) |
disable the UART tx interrupt
REQUIRED
void hal_UART_Enable | ( | uint8_t | channel | ) |
Enable UART peripheral for given channel.
void hal_UART_EnableRxInterrupt | ( | uint8_t | channel | ) |
enable the UART rx interrupt
void hal_UART_EnableTxInterrupt | ( | uint8_t | channel | ) |
enable the UART tx interrupt
REQUIRED
void hal_UART_Init | ( | uint8_t | channel, |
uint32_t | baud | ||
) |
initialize UART channel at specified baud rate
REQUIRED
This function should:
channel | - UART channel to initialize |
baud | - integer baud rate (bits/s) to configure UART for |
there is some issue with the PIO_WPMR write protect register that is preventing the USART from being configured when this happens. For now the workaround is to set-up the USART first. Commenting the following line of code out will leave the write protect in a disabled state. This is how I (JE?) initially discovered the workaround.
there is some issue with the PIO_WPMR write protect register that is preventing the USART from being configured when this happens. For now the workaround is to set-up the USART first. Commenting the following line of code out will leave the write protect in a disabled state. This is how I (JE?) initially discovered the workaround.
there is some issue with the PIO_WPMR write protect register that is preventing the USART from being configured when this happens. For now the workaround is to set-up the USART first. Commenting the following line of code out will leave the write protect in a disabled state. This is how I (JE?) initially discovered the workaround.
there is some issue with the PIO_WPMR write protect register that is preventing the USART from being configured when this happens. For now the workaround is to set-up the USART first. Commenting the following line of code out will leave the write protect in a disabled state. This is how I (JE?) initially discovered the workaround.
there is some issue with the PIO_WPMR write protect register that is preventing the USART from being configured when this happens. For now the workaround is to set-up the USART first. Commenting the following line of code out will leave the write protect in a disabled state. This is how I (JE?) initially discovered the workaround.
there is some issue with the PIO_WPMR write protect register that is preventing the USART from being configured when this happens. For now the workaround is to set-up the USART first. Commenting the following line of code out will leave the write protect in a disabled state. This is how I (JE?) initially discovered the workaround.
void hal_UART_ReconfigureBaud | ( | uint8_t | channel, |
uint32_t | baud | ||
) |
change the baud rate for the UART channel
channel | - UART channel |
baud | - integer baud rate (bits/s) to configure UART for |
uint8_t hal_UART_RxByte | ( | uint8_t | channel | ) |
Get character from UART hardware rx register.
REQUIRED
uint8_t hal_UART_RxInterruptEnabled | ( | uint8_t | channel | ) |
Is UART rx interrupt enabled.
uint8_t hal_UART_SpaceAvailable | ( | uint8_t | channel | ) |
return 0 if no space is available in the hardware UART tx buffer
REQUIRED
void hal_UART_TxByte | ( | uint8_t | channel, |
uint8_t | data | ||
) |
send character to UART hardware tx register
REQUIRED
uint8_t hal_UART_TxInterruptEnabled | ( | uint8_t | channel | ) |
Is UART tx interrupt enabled.
REQUIRED
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 |