|
caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
|
Universal Asynchronous Receiver-Transmitter (UART) HAL API. More...
Go to the source code of this file.
Data Structures | |
| struct | cfn_hal_uart_phy_t |
| UART hardware physical mapping. More... | |
| struct | cfn_hal_uart_config_t |
| UART configuration structure. More... | |
| struct | cfn_hal_uart_api_s |
| UART Virtual Method Table (VMT). More... | |
Macros | |
| #define | CFN_HAL_UART_FLAG_CONTINUOUS_RX CFN_HAL_BIT(0) |
| UART continuous RX flag for tracking state in the base driver. | |
Typedefs | |
| typedef struct cfn_hal_uart_s | cfn_hal_uart_t |
| typedef struct cfn_hal_uart_api_s | cfn_hal_uart_api_t |
| typedef void(* | cfn_hal_uart_callback_t) (cfn_hal_uart_t *driver, uint32_t event_mask, uint32_t error_mask, uint8_t *data, size_t nbr_of_bytes, void *user_arg) |
| UART callback signature. | |
Functions | |
| CFN_HAL_VMT_CHECK (struct cfn_hal_uart_api_s) | |
| CFN_HAL_CREATE_DRIVER_TYPE (uart, cfn_hal_uart_config_t, cfn_hal_uart_api_t, cfn_hal_uart_phy_t, cfn_hal_uart_callback_t) | |
| CFN_HAL_INLINE void | cfn_hal_uart_populate (cfn_hal_uart_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_uart_api_t *api, const cfn_hal_uart_phy_t *phy, const cfn_hal_uart_config_t *config, cfn_hal_uart_callback_t callback, void *user_arg) |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_config_validate (const cfn_hal_uart_t *driver, const cfn_hal_uart_config_t *config) |
| Validates the UART configuration. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_init (cfn_hal_uart_t *driver) |
| Initializes the UART driver. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_deinit (cfn_hal_uart_t *driver) |
| Deinitializes the UART driver. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_config_set (cfn_hal_uart_t *driver, const cfn_hal_uart_config_t *config) |
| Sets the UART configuration. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_config_get (cfn_hal_uart_t *driver, cfn_hal_uart_config_t *config) |
| Gets the current UART configuration. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_callback_register (cfn_hal_uart_t *driver, const cfn_hal_uart_callback_t callback, void *user_arg) |
| Registers a callback for UART events and errors. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_power_state_set (cfn_hal_uart_t *driver, cfn_hal_power_state_t state) |
| Sets the UART power state. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_event_enable (cfn_hal_uart_t *driver, uint32_t event_mask) |
| Enables one or more UART nominal events. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_event_disable (cfn_hal_uart_t *driver, uint32_t event_mask) |
| Disables one or more UART nominal events. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_event_get (cfn_hal_uart_t *driver, uint32_t *event_mask) |
| Retrieves the current UART nominal event status. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_error_enable (cfn_hal_uart_t *driver, uint32_t error_mask) |
| Enables one or more UART exception errors. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_error_disable (cfn_hal_uart_t *driver, uint32_t error_mask) |
| Disables one or more UART exception errors. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_error_get (cfn_hal_uart_t *driver, uint32_t *error_mask) |
| Retrieves the current UART exception error status. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_tx_irq (cfn_hal_uart_t *driver, const uint8_t *data, size_t nbr_of_bytes) |
| Starts UART data transmission using interrupts (non-blocking). | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_tx_irq_abort (cfn_hal_uart_t *driver) |
| Aborts an ongoing interrupt-based transmission. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_rx_n_irq (cfn_hal_uart_t *driver, uint8_t *data, size_t nbr_of_bytes) |
| Starts UART data reception using interrupts to receive exactly N bytes. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_rx_irq (cfn_hal_uart_t *driver) |
| Starts UART data reception in continuous interrupt mode. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_rx_irq_abort (cfn_hal_uart_t *driver) |
| Aborts an ongoing interrupt-based reception. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_tx_polling (cfn_hal_uart_t *driver, const uint8_t *data, size_t nbr_of_bytes, uint32_t timeout) |
| Transmits data using polling (blocking). | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_rx_polling (cfn_hal_uart_t *driver, uint8_t *data, size_t nbr_of_bytes, uint32_t timeout) |
| Receives data using polling (blocking). | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_rx_to_idle (cfn_hal_uart_t *driver, uint8_t *data, size_t max_bytes, size_t *received_bytes, uint32_t timeout) |
| Receives data until an idle condition or max bytes reached. | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_tx_dma (cfn_hal_uart_t *driver, const uint8_t *data, size_t nbr_of_bytes) |
| Transmits data using DMA (non-blocking). | |
| CFN_HAL_INLINE cfn_hal_error_code_t | cfn_hal_uart_rx_dma (cfn_hal_uart_t *driver, uint8_t *data, size_t nbr_of_bytes) |
| Receives data using DMA (non-blocking). | |
| cfn_hal_error_code_t | cfn_hal_uart_construct (cfn_hal_uart_t *driver, const cfn_hal_uart_config_t *config, const cfn_hal_uart_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_uart_callback_t callback, void *user_arg) |
| cfn_hal_error_code_t | cfn_hal_uart_destruct (cfn_hal_uart_t *driver) |
Universal Asynchronous Receiver-Transmitter (UART) HAL API.
Copyright (c) 2026 Hisham Moussa Daou https://www.whileone.me
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| #define CFN_HAL_UART_FLAG_CONTINUOUS_RX CFN_HAL_BIT(0) |
UART continuous RX flag for tracking state in the base driver.
| typedef struct cfn_hal_uart_api_s cfn_hal_uart_api_t |
| typedef void(* cfn_hal_uart_callback_t) (cfn_hal_uart_t *driver, uint32_t event_mask, uint32_t error_mask, uint8_t *data, size_t nbr_of_bytes, void *user_arg) |
UART callback signature.
| driver | Pointer to the UART driver instance. |
| event_mask | Mask of triggered nominal events. |
| error_mask | Mask of triggered exception errors. |
| data | Pointer to the transaction buffer (if applicable). |
| nbr_of_bytes | Number of bytes transferred. |
| user_arg | User-defined argument passed during registration. |
| typedef struct cfn_hal_uart_s cfn_hal_uart_t |
UART data length configuration.
| enum cfn_hal_uart_error_t |
UART exception error flags.
| enum cfn_hal_uart_event_t |
| CFN_HAL_CREATE_DRIVER_TYPE | ( | uart | , |
| cfn_hal_uart_config_t | , | ||
| cfn_hal_uart_api_t | , | ||
| cfn_hal_uart_phy_t | , | ||
| cfn_hal_uart_callback_t | |||
| ) |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_callback_register | ( | cfn_hal_uart_t * | driver, |
| const cfn_hal_uart_callback_t | callback, | ||
| void * | user_arg | ||
| ) |
Registers a callback for UART events and errors.
| driver | Pointer to the UART driver instance. |
| callback | The callback function to register. |
| user_arg | User-defined argument passed to the callback. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_config_get | ( | cfn_hal_uart_t * | driver, |
| cfn_hal_uart_config_t * | config | ||
| ) |
Gets the current UART configuration.
| driver | Pointer to the UART driver instance. |
| config | [out] Pointer to store the configuration. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_config_set | ( | cfn_hal_uart_t * | driver, |
| const cfn_hal_uart_config_t * | config | ||
| ) |
Sets the UART configuration.
| driver | Pointer to the UART driver instance. |
| config | Pointer to the configuration structure. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_config_validate | ( | const cfn_hal_uart_t * | driver, |
| const cfn_hal_uart_config_t * | config | ||
| ) |
Validates the UART configuration.
| driver | Pointer to the UART driver instance. |
| config | Pointer to the configuration structure. |
| cfn_hal_error_code_t cfn_hal_uart_construct | ( | cfn_hal_uart_t * | driver, |
| const cfn_hal_uart_config_t * | config, | ||
| const cfn_hal_uart_phy_t * | phy, | ||
| struct cfn_hal_clock_s * | clock, | ||
| void * | dependency, | ||
| cfn_hal_uart_callback_t | callback, | ||
| void * | user_arg | ||
| ) |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_deinit | ( | cfn_hal_uart_t * | driver | ) |
Deinitializes the UART driver.
| driver | Pointer to the UART driver instance. |
| cfn_hal_error_code_t cfn_hal_uart_destruct | ( | cfn_hal_uart_t * | driver | ) |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_error_disable | ( | cfn_hal_uart_t * | driver, |
| uint32_t | error_mask | ||
| ) |
Disables one or more UART exception errors.
| driver | Pointer to the UART driver instance. |
| error_mask | Mask of errors to disable. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_error_enable | ( | cfn_hal_uart_t * | driver, |
| uint32_t | error_mask | ||
| ) |
Enables one or more UART exception errors.
| driver | Pointer to the UART driver instance. |
| error_mask | Mask of errors to enable. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_error_get | ( | cfn_hal_uart_t * | driver, |
| uint32_t * | error_mask | ||
| ) |
Retrieves the current UART exception error status.
| driver | Pointer to the UART driver instance. |
| error_mask | [out] Pointer to store the error mask. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_event_disable | ( | cfn_hal_uart_t * | driver, |
| uint32_t | event_mask | ||
| ) |
Disables one or more UART nominal events.
| driver | Pointer to the UART driver instance. |
| event_mask | Mask of events to disable. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_event_enable | ( | cfn_hal_uart_t * | driver, |
| uint32_t | event_mask | ||
| ) |
Enables one or more UART nominal events.
| driver | Pointer to the UART driver instance. |
| event_mask | Mask of events to enable. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_event_get | ( | cfn_hal_uart_t * | driver, |
| uint32_t * | event_mask | ||
| ) |
Retrieves the current UART nominal event status.
| driver | Pointer to the UART driver instance. |
| event_mask | [out] Pointer to store the event mask. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_init | ( | cfn_hal_uart_t * | driver | ) |
Initializes the UART driver.
| driver | Pointer to the UART driver instance. |
| CFN_HAL_INLINE void cfn_hal_uart_populate | ( | cfn_hal_uart_t * | driver, |
| uint32_t | peripheral_id, | ||
| struct cfn_hal_clock_s * | clock, | ||
| void * | dependency, | ||
| const cfn_hal_uart_api_t * | api, | ||
| const cfn_hal_uart_phy_t * | phy, | ||
| const cfn_hal_uart_config_t * | config, | ||
| cfn_hal_uart_callback_t | callback, | ||
| void * | user_arg | ||
| ) |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_power_state_set | ( | cfn_hal_uart_t * | driver, |
| cfn_hal_power_state_t | state | ||
| ) |
Sets the UART power state.
| driver | Pointer to the UART driver instance. |
| state | Target power state. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_rx_dma | ( | cfn_hal_uart_t * | driver, |
| uint8_t * | data, | ||
| size_t | nbr_of_bytes | ||
| ) |
Receives data using DMA (non-blocking).
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer to store received data. |
| nbr_of_bytes | Number of bytes to receive. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_rx_irq | ( | cfn_hal_uart_t * | driver | ) |
Starts UART data reception in continuous interrupt mode.
| driver | Pointer to the UART driver instance. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_rx_irq_abort | ( | cfn_hal_uart_t * | driver | ) |
Aborts an ongoing interrupt-based reception.
| driver | Pointer to the UART driver instance. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_rx_n_irq | ( | cfn_hal_uart_t * | driver, |
| uint8_t * | data, | ||
| size_t | nbr_of_bytes | ||
| ) |
Starts UART data reception using interrupts to receive exactly N bytes.
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer to store received data. |
| nbr_of_bytes | Number of bytes to receive. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_rx_polling | ( | cfn_hal_uart_t * | driver, |
| uint8_t * | data, | ||
| size_t | nbr_of_bytes, | ||
| uint32_t | timeout | ||
| ) |
Receives data using polling (blocking).
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer to store received data. |
| nbr_of_bytes | Number of bytes to receive. |
| timeout | Timeout duration in milliseconds. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_rx_to_idle | ( | cfn_hal_uart_t * | driver, |
| uint8_t * | data, | ||
| size_t | max_bytes, | ||
| size_t * | received_bytes, | ||
| uint32_t | timeout | ||
| ) |
Receives data until an idle condition or max bytes reached.
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer to store received data. |
| max_bytes | Maximum capacity of the data buffer. |
| received_bytes | [out] Actual number of bytes received. |
| timeout | Timeout duration in milliseconds. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_tx_dma | ( | cfn_hal_uart_t * | driver, |
| const uint8_t * | data, | ||
| size_t | nbr_of_bytes | ||
| ) |
Transmits data using DMA (non-blocking).
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer containing data to transmit. |
| nbr_of_bytes | Number of bytes to transmit. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_tx_irq | ( | cfn_hal_uart_t * | driver, |
| const uint8_t * | data, | ||
| size_t | nbr_of_bytes | ||
| ) |
Starts UART data transmission using interrupts (non-blocking).
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer containing data to transmit. |
| nbr_of_bytes | Number of bytes to transmit. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_tx_irq_abort | ( | cfn_hal_uart_t * | driver | ) |
Aborts an ongoing interrupt-based transmission.
| driver | Pointer to the UART driver instance. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_uart_tx_polling | ( | cfn_hal_uart_t * | driver, |
| const uint8_t * | data, | ||
| size_t | nbr_of_bytes, | ||
| uint32_t | timeout | ||
| ) |
Transmits data using polling (blocking).
| driver | Pointer to the UART driver instance. |
| data | Pointer to the buffer containing data to transmit. |
| nbr_of_bytes | Number of bytes to transmit. |
| timeout | Timeout duration in milliseconds. |
| CFN_HAL_VMT_CHECK | ( | struct cfn_hal_uart_api_s | ) |