ChibiOS
21.6.0
|
Generic SIO Driver. More...
Generic SIO Driver.
This driver abstracts a generic serial communication channel, usually an UART, this driver is similar to Serial and UART drivers but follows a different concept:
HAL_USE_SIO
option must be enabled in halconf.h
.The driver implements a state machine internally, not all the driver functionalities can be used in any moment, any transition not explicitly shown in the following diagram has to be considered an error and shall be captured by an assertion (if enabled).
Macros | |
#define | _sio_driver_methods _base_channel_methods |
SIODriver specific methods. More... | |
#define | sioGetFlagsX(siop) sio_lld_get_flags(siop) |
Returns the current set of flags and clears it. More... | |
#define | sioIsRXEmptyX(siop) sio_lld_is_rx_empty(siop) |
Determines the state of the RX FIFO. More... | |
#define | sioIsTXFullX(siop) sio_lld_is_tx_full(siop) |
Determines the state of the TX FIFO. More... | |
#define | sioGetAndClearEventsI(siop) sio_lld_get_and_clear_events(siop) |
Return the pending SIO events flags. More... | |
#define | sioGetX(siop) sio_lld_get(siop) |
Returns one frame from the RX FIFO. More... | |
#define | sioPutX(siop, data) sio_lld_put(siop, data) |
Pushes one frame into the TX FIFO. More... | |
#define | sioAsyncReadI(siop, size, buffer) sio_lld_read(siop, size, buffer) |
Reads data from the RX FIFO. More... | |
#define | sioAsyncWriteI(siop, size, buffer) sio_lld_write(siop, size, buffer) |
Writes data into the TX FIFO. More... | |
#define | sioControlX(siop, operation, arg) sio_lld_control(siop, operation, arg) |
Control operation on a serial port. More... | |
#define | sio_lld_driver_fields uint32_t dummy |
Low level fields of the SIO driver structure. More... | |
#define | sio_lld_config_fields uint32_t dummy |
Low level fields of the SIO configuration structure. More... | |
#define | sio_lld_is_rx_empty(siop) false |
Determines the state of the RX FIFO. More... | |
#define | sio_lld_is_tx_full(siop) false |
Determines the state of the TX FIFO. More... | |
#define | sio_lld_is_tx_ongoing(siop) false |
Determines the transmission state. More... | |
SIO status flags | |
#define | SIO_NO_ERROR 0 |
No pending conditions. More... | |
#define | SIO_PARITY_ERROR 4 |
Parity error happened. More... | |
#define | SIO_FRAMING_ERROR 8 |
Framing error happened. More... | |
#define | SIO_OVERRUN_ERROR 16 |
Overflow happened. More... | |
#define | SIO_NOISE_ERROR 32 |
Noise on the line. More... | |
#define | SIO_BREAK_DETECTED 64 |
Break detected. More... | |
SIO additional messages | |
#define | SIO_MSG_IDLE 1 |
#define | SIO_MSG_ERRORS 2 |
SIO configuration options | |
#define | SIO_DEFAULT_BITRATE 38400 |
Default bit rate. More... | |
#define | SIO_USE_SYNCHRONIZATION TRUE |
Support for thread synchronization API. More... | |
Low level driver helper macros | |
#define | __sio_callback_rx(siop) |
RX callback. More... | |
#define | __sio_callback_rx_idle(siop) |
RX idle callback. More... | |
#define | __sio_callback_tx(siop) |
TX callback. More... | |
#define | __sio_callback_tx_end(siop) |
TX end callback. More... | |
#define | __sio_callback_rx_evt(siop) |
RX event callback. More... | |
#define | __sio_wakeup_rx(siop, msg) |
Wakes up the RX-waiting thread. More... | |
#define | __sio_wakeup_tx(siop, msg) |
Wakes up the TX-waiting thread. More... | |
#define | __sio_wakeup_txend(siop, msg) |
Wakes up the TXend-waiting thread. More... | |
PLATFORM configuration options | |
#define | PLATFORM_SIO_USE_SIO1 FALSE |
SIO driver enable switch. More... | |
Typedefs | |
typedef uint_fast8_t | sioflags_t |
SIO driver condition flags type. More... | |
typedef struct hal_sio_driver | SIODriver |
Type of structure representing a SIO driver. More... | |
typedef struct hal_sio_config | SIOConfig |
Type of structure representing a SIO configuration. More... | |
typedef struct hal_sio_operation | SIOOperation |
Type of structure representing a SIO operation. More... | |
typedef void(* | siocb_t) (SIODriver *siop) |
Generic SIO notification callback type. More... | |
typedef uint32_t | sio_events_mask_t |
Type of a SIO events mask. More... | |
Data Structures | |
struct | hal_sio_config |
Driver configuration structure. More... | |
struct | sio_driver_vmt |
SIODriver virtual methods table. More... | |
struct | hal_sio_driver |
Structure representing a SIO driver. More... | |
struct | hal_sio_operation |
Structure representing a SIO operation. More... | |
Functions | |
void | sioInit (void) |
SIO Driver initialization. More... | |
void | sioObjectInit (SIODriver *siop) |
Initializes the standard part of a SIODriver structure. More... | |
bool | sioStart (SIODriver *siop, const SIOConfig *config) |
Configures and activates the SIO peripheral. More... | |
void | sioStop (SIODriver *siop) |
Deactivates the SIO peripheral. More... | |
void | sioStartOperation (SIODriver *siop, const SIOOperation *operation) |
Starts a SIO operation. More... | |
void | sioStopOperation (SIODriver *siop) |
Stops an ongoing SIO operation, if any. More... | |
sio_events_mask_t | sioGetAndClearEvents (SIODriver *siop) |
Return the pending SIO events flags. More... | |
size_t | sioAsyncRead (SIODriver *siop, uint8_t *buffer, size_t n) |
Reads data from the RX FIFO. More... | |
size_t | sioAsyncWrite (SIODriver *siop, const uint8_t *buffer, size_t n) |
Writes data into the TX FIFO. More... | |
msg_t | sioSynchronizeRX (SIODriver *siop, sysinterval_t timeout) |
Synchronizes with RX FIFO data availability. More... | |
msg_t | sioSynchronizeTX (SIODriver *siop, sysinterval_t timeout) |
Synchronizes with TX FIFO space availability. More... | |
msg_t | sioSynchronizeTXEnd (SIODriver *siop, sysinterval_t timeout) |
Synchronizes with TX completion. More... | |
void | sio_lld_init (void) |
Low level SIO driver initialization. More... | |
bool | sio_lld_start (SIODriver *siop) |
Configures and activates the SIO peripheral. More... | |
void | sio_lld_stop (SIODriver *siop) |
Deactivates the SIO peripheral. More... | |
void | sio_lld_start_operation (SIODriver *siop) |
Starts a SIO operation. More... | |
void | sio_lld_stop_operation (SIODriver *siop) |
Stops an ongoing SIO operation, if any. More... | |
sio_events_mask_t | sio_lld_get_and_clear_events (SIODriver *siop) |
Return the pending SIO events flags. More... | |
size_t | sio_lld_read (SIODriver *siop, uint8_t *buffer, size_t n) |
Reads data from the RX FIFO. More... | |
size_t | sio_lld_write (SIODriver *siop, const uint8_t *buffer, size_t n) |
Writes data into the TX FIFO. More... | |
msg_t | sio_lld_get (SIODriver *siop) |
Returns one frame from the RX FIFO. More... | |
void | sio_lld_put (SIODriver *siop, uint_fast16_t data) |
Pushes one frame into the TX FIFO. More... | |
msg_t | sio_lld_control (SIODriver *siop, unsigned int operation, void *arg) |
Control operation on a serial port. More... | |
Enumerations | |
enum | siostate_t { SIO_UNINIT = 0, SIO_STOP = 1, SIO_READY = 2, SIO_ACTIVE = 3 } |
Driver state machine possible states. More... | |
Variables | |
SIODriver | SIOD1 |
SIO1 driver identifier. More... | |
#define SIO_DEFAULT_BITRATE 38400 |
#define SIO_USE_SYNCHRONIZATION TRUE |
#define _sio_driver_methods _base_channel_methods |
#define sioGetFlagsX | ( | siop | ) | sio_lld_get_flags(siop) |
#define sioIsRXEmptyX | ( | siop | ) | sio_lld_is_rx_empty(siop) |
Determines the state of the RX FIFO.
[in] | siop | pointer to the SIODriver object |
false | if RX FIFO is not empty |
true | if RX FIFO is empty |
#define sioIsTXFullX | ( | siop | ) | sio_lld_is_tx_full(siop) |
Determines the state of the TX FIFO.
[in] | siop | pointer to the SIODriver object |
false | if TX FIFO is not full |
true | if TX FIFO is full |
#define sioGetAndClearEventsI | ( | siop | ) | sio_lld_get_and_clear_events(siop) |
Return the pending SIO events flags.
[in] | siop | pointer to the SIODriver object |
#define sioGetX | ( | siop | ) | sio_lld_get(siop) |
Returns one frame from the RX FIFO.
[in] | siop | pointer to the SIODriver object |
#define sioPutX | ( | siop, | |
data | |||
) | sio_lld_put(siop, data) |
Pushes one frame into the TX FIFO.
[in] | siop | pointer to the SIODriver object |
[in] | data | frame to be written |
#define sioAsyncReadI | ( | siop, | |
size, | |||
buffer | |||
) | sio_lld_read(siop, size, buffer) |
Reads data from the RX FIFO.
This function is non-blocking, data is read if present and the effective amount is returned.
rxne_cb
callback handler.[in] | siop | pointer to the SIODriver object |
[in] | size | maximum number of frames to read |
[in] | buffer | buffer for the received data |
#define sioAsyncWriteI | ( | siop, | |
size, | |||
buffer | |||
) | sio_lld_write(siop, size, buffer) |
Writes data into the TX FIFO.
This function is non-blocking, data is written if there is space in the FIFO and the effective amount is returned.
txnf_cb
callback handler.[in] | siop | pointer to the SIODriver object |
[in] | size | maximum number of frames to read |
[out] | buffer | buffer containing the data to be transmitted |
#define sioControlX | ( | siop, | |
operation, | |||
arg | |||
) | sio_lld_control(siop, operation, arg) |
Control operation on a serial port.
[in] | siop | pointer to the SIODriver object |
[in] | operation | control operation code |
[in,out] | arg | operation argument |
MSG_OK | in case of success. |
MSG_TIMEOUT | in case of operation timeout. |
MSG_RESET | in case of operation reset. |
#define __sio_callback_rx | ( | siop | ) |
#define __sio_callback_rx_idle | ( | siop | ) |
#define __sio_callback_tx | ( | siop | ) |
#define __sio_callback_tx_end | ( | siop | ) |
#define __sio_callback_rx_evt | ( | siop | ) |
#define __sio_wakeup_rx | ( | siop, | |
msg | |||
) |
Wakes up the RX-waiting thread.
[in] | siop | pointer to the SIODriver object |
[in] | msg | the wake up message |
#define __sio_wakeup_tx | ( | siop, | |
msg | |||
) |
Wakes up the TX-waiting thread.
[in] | siop | pointer to the SIODriver object |
[in] | msg | the wake up message |
#define __sio_wakeup_txend | ( | siop, | |
msg | |||
) |
Wakes up the TXend-waiting thread.
[in] | siop | pointer to the SIODriver object |
[in] | msg | the wake up message |
#define PLATFORM_SIO_USE_SIO1 FALSE |
SIO driver enable switch.
If set to TRUE
the support for SIO1 is included.
FALSE
. Definition at line 48 of file hal_sio_lld.h.
#define sio_lld_driver_fields uint32_t dummy |
Low level fields of the SIO driver structure.
Definition at line 72 of file hal_sio_lld.h.
#define sio_lld_config_fields uint32_t dummy |
Low level fields of the SIO configuration structure.
Definition at line 78 of file hal_sio_lld.h.
#define sio_lld_is_rx_empty | ( | siop | ) | false |
Determines the state of the RX FIFO.
[in] | siop | pointer to the SIODriver object |
false | if RX FIFO is not empty |
true | if RX FIFO is empty |
Definition at line 91 of file hal_sio_lld.h.
#define sio_lld_is_tx_full | ( | siop | ) | false |
Determines the state of the TX FIFO.
[in] | siop | pointer to the SIODriver object |
false | if TX FIFO is not full |
true | if TX FIFO is full |
Definition at line 103 of file hal_sio_lld.h.
#define sio_lld_is_tx_ongoing | ( | siop | ) | false |
Determines the transmission state.
[in] | siop | pointer to the SIODriver object |
false | if transmission is idle |
true | if transmission is ongoing |
Definition at line 115 of file hal_sio_lld.h.
typedef uint_fast8_t sioflags_t |
typedef struct hal_sio_driver SIODriver |
typedef struct hal_sio_config SIOConfig |
typedef struct hal_sio_operation SIOOperation |
typedef void(* siocb_t) (SIODriver *siop) |
typedef uint32_t sio_events_mask_t |
Type of a SIO events mask.
Definition at line 63 of file hal_sio_lld.h.
enum siostate_t |
void sioInit | ( | void | ) |
SIO Driver initialization.
halInit()
, there is no need to explicitly initialize the driver.Definition at line 213 of file hal_sio.c.
References sio_lld_init().
Referenced by halInit().
void sioObjectInit | ( | SIODriver * | siop | ) |
Initializes the standard part of a SIODriver
structure.
[out] | siop | pointer to the SIODriver object |
Definition at line 225 of file hal_sio.c.
References hal_sio_driver::vmt.
Referenced by sio_lld_init().
Configures and activates the SIO peripheral.
[in] | siop | pointer to the SIODriver object |
[in] | config | pointer to the SIOConfig object, can be NULL if the default configuration is desired |
false | if the driver has been correctly started. |
true | if an error occurred. |
Definition at line 251 of file hal_sio.c.
References hal_sio_driver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), sio_lld_start(), SIO_READY, SIO_STOP, and hal_sio_driver::state.
void sioStop | ( | SIODriver * | siop | ) |
Deactivates the SIO peripheral.
[in] | siop | pointer to the SIODriver object |
Definition at line 277 of file hal_sio.c.
References hal_sio_driver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), sio_lld_stop(), SIO_READY, SIO_STOP, and hal_sio_driver::state.
void sioStartOperation | ( | SIODriver * | siop, |
const SIOOperation * | operation | ||
) |
Starts a SIO operation.
[in] | siop | pointer to an SIODriver structure |
[in] | operation | pointer to an SIOOperation structure, can be NULL if callbacks are not required encoding the operation to be performed |
Definition at line 303 of file hal_sio.c.
References hal_sio_driver::operation, osalDbgAssert, osalDbgCheck, osalSysLock(), SIO_READY, and hal_sio_driver::state.
void sioStopOperation | ( | SIODriver * | siop | ) |
Stops an ongoing SIO operation, if any.
[in] | siop | pointer to an SIODriver structure |
Definition at line 333 of file hal_sio.c.
References MSG_RESET, hal_sio_driver::operation, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadResumeI(), SIO_ACTIVE, sio_lld_stop_operation(), SIO_READY, hal_sio_driver::state, hal_sio_driver::sync_rx, hal_sio_driver::sync_tx, and hal_sio_driver::sync_txend.
sio_events_mask_t sioGetAndClearEvents | ( | SIODriver * | siop | ) |
Return the pending SIO events flags.
[in] | siop | pointer to the SIODriver object |
Definition at line 364 of file hal_sio.c.
References osalDbgCheck, osalSysLock(), osalSysUnlock(), and sioGetAndClearEventsI.
size_t sioAsyncRead | ( | SIODriver * | siop, |
uint8_t * | buffer, | ||
size_t | n | ||
) |
Reads data from the RX FIFO.
This function is non-blocking, data is read if present and the effective amount is returned.
rxne_cb
callback handler.[in] | siop | pointer to the SIODriver object |
[in] | buffer | buffer for the received data |
[in] | n | maximum number of frames to read |
Definition at line 392 of file hal_sio.c.
References osalDbgCheck, osalSysLock(), osalSysUnlock(), and sioAsyncReadI.
size_t sioAsyncWrite | ( | SIODriver * | siop, |
const uint8_t * | buffer, | ||
size_t | n | ||
) |
Writes data into the TX FIFO.
This function is non-blocking, data is written if there is space in the FIFO and the effective amount is returned.
txnf_cb
callback handler.[in] | siop | pointer to the SIODriver object |
[out] | buffer | buffer containing the data to be transmitted |
[in] | n | maximum number of frames to read |
Definition at line 419 of file hal_sio.c.
References osalDbgCheck, osalSysLock(), osalSysUnlock(), and sioAsyncWriteI.
msg_t sioSynchronizeRX | ( | SIODriver * | siop, |
sysinterval_t | timeout | ||
) |
Synchronizes with RX FIFO data availability.
[in] | siop | pointer to an SIODriver structure |
[in] | timeout | synchronization timeout |
MSG_OK | if there is data in the RX FIFO. |
MSG_TIMEOUT | if synchronization timed out. |
MSG_RESET | operation has been stopped while waiting. |
SIO_MSG_IDLE | if RX line went idle. |
SIO_MSG_ERRORS | if RX errors occurred during wait. |
Definition at line 448 of file hal_sio.c.
References MSG_OK, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendTimeoutS(), SIO_ACTIVE, sio_lld_is_rx_empty, hal_sio_driver::state, and hal_sio_driver::sync_rx.
msg_t sioSynchronizeTX | ( | SIODriver * | siop, |
sysinterval_t | timeout | ||
) |
Synchronizes with TX FIFO space availability.
[in] | siop | pointer to an SIODriver structure |
[in] | timeout | synchronization timeout |
MSG_OK | if there is space in the TX FIFO. |
MSG_TIMEOUT | if synchronization timed out. |
MSG_RESET | operation has been stopped while waiting. |
Definition at line 483 of file hal_sio.c.
References MSG_OK, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendTimeoutS(), SIO_ACTIVE, sio_lld_is_tx_full, hal_sio_driver::state, and hal_sio_driver::sync_tx.
msg_t sioSynchronizeTXEnd | ( | SIODriver * | siop, |
sysinterval_t | timeout | ||
) |
Synchronizes with TX completion.
[in] | siop | pointer to an SIODriver structure |
[in] | timeout | synchronization timeout |
MSG_OK | if TX operation finished. |
MSG_TIMEOUT | if synchronization timed out. |
Definition at line 515 of file hal_sio.c.
References MSG_OK, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), osalThreadSuspendTimeoutS(), SIO_ACTIVE, sio_lld_is_tx_ongoing, hal_sio_driver::state, and hal_sio_driver::sync_txend.
void sio_lld_init | ( | void | ) |
Low level SIO driver initialization.
Definition at line 65 of file hal_sio_lld.c.
References SIOD1, and sioObjectInit().
Referenced by sioInit().
bool sio_lld_start | ( | SIODriver * | siop | ) |
Configures and activates the SIO peripheral.
[in] | siop | pointer to the SIODriver object |
false | if the driver has been correctly started. |
true | if an error occurred. |
Definition at line 83 of file hal_sio_lld.c.
References SIO_STOP, SIOD1, and hal_sio_driver::state.
Referenced by sioStart().
void sio_lld_stop | ( | SIODriver * | siop | ) |
Deactivates the SIO peripheral.
[in] | siop | pointer to the SIODriver object |
Definition at line 105 of file hal_sio_lld.c.
References SIO_READY, SIOD1, and hal_sio_driver::state.
Referenced by sioStop().
void sio_lld_start_operation | ( | SIODriver * | siop | ) |
Starts a SIO operation.
[in] | siop | pointer to an SIODriver structure |
Definition at line 126 of file hal_sio_lld.c.
void sio_lld_stop_operation | ( | SIODriver * | siop | ) |
Stops an ongoing SIO operation, if any.
[in] | siop | pointer to an SIODriver structure |
Definition at line 138 of file hal_sio_lld.c.
Referenced by sioStopOperation().
sio_events_mask_t sio_lld_get_and_clear_events | ( | SIODriver * | siop | ) |
Return the pending SIO events flags.
[in] | siop | pointer to the SIODriver object |
Definition at line 151 of file hal_sio_lld.c.
size_t sio_lld_read | ( | SIODriver * | siop, |
uint8_t * | buffer, | ||
size_t | n | ||
) |
Reads data from the RX FIFO.
The function is not blocking, it writes frames until there is space available without waiting.
[in] | siop | pointer to an SIODriver structure |
[in] | buffer | pointer to the buffer for read frames |
[in] | n | maximum number of frames to be read |
0 | if the TX FIFO is full. |
Definition at line 170 of file hal_sio_lld.c.
size_t sio_lld_write | ( | SIODriver * | siop, |
const uint8_t * | buffer, | ||
size_t | n | ||
) |
Writes data into the TX FIFO.
The function is not blocking, it writes frames until there is space available without waiting.
[in] | siop | pointer to an SIODriver structure |
[in] | buffer | pointer to the buffer for read frames |
[in] | n | maximum number of frames to be written |
0 | if the TX FIFO is full. |
Definition at line 189 of file hal_sio_lld.c.
Returns one frame from the RX FIFO.
[in] | siop | pointer to the SIODriver object |
Definition at line 206 of file hal_sio_lld.c.
void sio_lld_put | ( | SIODriver * | siop, |
uint_fast16_t | data | ||
) |
Pushes one frame into the TX FIFO.
[in] | siop | pointer to the SIODriver object |
[in] | data | frame to be written |
Definition at line 223 of file hal_sio_lld.c.
Control operation on a serial port.
[in] | siop | pointer to the SIODriver object |
[in] | operation | control operation code |
[in,out] | arg | operation argument |
MSG_OK | in case of success. |
MSG_TIMEOUT | in case of operation timeout. |
MSG_RESET | in case of operation reset. |
Definition at line 243 of file hal_sio_lld.c.
References MSG_OK.
SIODriver SIOD1 |
SIO1 driver identifier.
Definition at line 41 of file hal_sio_lld.c.
Referenced by sio_lld_init(), sio_lld_start(), and sio_lld_stop().