daisy::UartHandler¶
Module: LIBDAISY / PERIPHERAL / SERIAL
#include <uart.h>
Public Classes¶
Name | |
---|---|
struct | Config |
Public Types¶
Name | |
---|---|
enum class | Result |
enum class | DmaDirection |
typedef void(*)(void *context) | StartCallbackFunctionPtr |
typedef void(*)(void *context, Result result) | EndCallbackFunctionPtr |
typedef void(*)(uint8_t *data, size_t size, void *context, Result result) | CircularRxCallbackFunctionPtr |
Public Functions¶
Name | |
---|---|
UartHandler() | |
UartHandler(const UartHandler & other) =default | |
UartHandler & | operator=(const UartHandler & other) =default |
Result | Init(const Config & config) |
const Config & | GetConfig() const |
Result | BlockingTransmit(uint8_t * buff, size_t size, uint32_t timeout =100) |
Result | BlockingReceive(uint8_t * buffer, uint16_t size, uint32_t timeout =100) |
Result | DmaTransmit(uint8_t * buff, size_t size, UartHandler::StartCallbackFunctionPtr start_callback, UartHandler::EndCallbackFunctionPtr end_callback, void * callback_context) |
Result | DmaReceive(uint8_t * buff, size_t size, UartHandler::StartCallbackFunctionPtr start_callback, UartHandler::EndCallbackFunctionPtr end_callback, void * callback_context) |
Result | DmaListenStart(uint8_t * buff, size_t size, CircularRxCallbackFunctionPtr cb, void * callback_context) |
Result | DmaListenStop() |
bool | IsListening() const |
int | CheckError() |
int | PollReceive(uint8_t * buff, size_t size, uint32_t timeout) |
Result | PollTx(uint8_t * buff, size_t size) |
Detailed Description¶
Author: shensley
Date: March 2020
Uart Peripheral
Public Types Documentation¶
enum Result¶
Enumerator | Value | Description |
---|---|---|
OK | & | |
ERR | & |
Return values for Uart functions.
enum DmaDirection¶
Enumerator | Value | Description |
---|---|---|
RX | & | |
TX | & |
typedef StartCallbackFunctionPtr¶
A callback to be executed right before a standard dma transfer is started.
typedef EndCallbackFunctionPtr¶
A callback to be executed after a standard dma transfer is completed.
typedef CircularRxCallbackFunctionPtr¶
typedef void(* daisy::UartHandler::CircularRxCallbackFunctionPtr) (uint8_t *data, size_t size, void *context, Result result);
Parameters:
- data byte-buffer to fill with data
- size size of the "data" byte buffer
- context user-defined context variable to pass state to the callback
- result state of the UART Handler result, should be OK if things are OK.
A callback to be executed when using circular/listening mode includes a callback context, as well as the data to be handled This fires either after half of the size of the user-defined buffer has been transferred from peripheral to memory, or after an IDLE frame is detected.
Public Functions Documentation¶
function UartHandler¶
function UartHandler¶
function operator=¶
function Init¶
Initializes the UART Peripheral
function GetConfig¶
Returns the current config.
function BlockingTransmit¶
Parameters:
- buff input buffer
- size buffer size
- timeout how long in milliseconds the function will wait before returning without successful communication
Blocking transmit
function BlockingReceive¶
Parameters:
- buffer input buffer
- size buffer size
- timeout How long to timeout for in milliseconds
Return: Whether the receive was successful or not
Polling Receive
function DmaTransmit¶
Result DmaTransmit(
uint8_t * buff,
size_t size,
UartHandler::StartCallbackFunctionPtr start_callback,
UartHandler::EndCallbackFunctionPtr end_callback,
void * callback_context
)
Parameters:
- ***buff** input buffer
- size buffer size
- start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
- end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
- callback_context A pointer that will be passed back to you in the callbacks.
Return: Whether the transmit was successful or not
DMA-based transmit
function DmaReceive¶
Result DmaReceive(
uint8_t * buff,
size_t size,
UartHandler::StartCallbackFunctionPtr start_callback,
UartHandler::EndCallbackFunctionPtr end_callback,
void * callback_context
)
Parameters:
- ***buff** input buffer
- size buffer size
- start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
- end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
- callback_context A pointer that will be passed back to you in the callbacks.
Return: Whether the receive was successful or not
DMA-based receive
function DmaListenStart¶
Result DmaListenStart(
uint8_t * buff,
size_t size,
CircularRxCallbackFunctionPtr cb,
void * callback_context
)
Parameters:
- buff buffer of data accessible by DMA.
- size size of buffer
- cb callback that happens containing new bytes to process in software
- callback_context pointer to user-defined data accessible from callback
Starts the DMA Reception in "Listen" mode. In this mode the DMA is configured for circular behavior, and the IDLE interrupt is enabled.
At TC, HT, and IDLE interrupts data must be processed.
Size must be set so that at maximum bandwidth, the software has time to process N bytes before the next circular IRQ is fired
function DmaListenStop¶
Stops the DMA Reception during listen mode
function IsListening¶
Returns whether listen the DmaListen mode is active or not
function CheckError¶
Return: the result of HAL_UART_GetError() to the user.
function PollReceive¶
Will be deprecated soon! Wrapper for BlockingTransmit
function PollTx¶
Will be deprecated soon! Wrapper for BlockingTransmit
---¶
Updated on 2024-01-03 at 19:41:01 +0000