uart.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2020 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __HAL_UART_ADAPTER_H__
10 #define __HAL_UART_ADAPTER_H__
11 
12 #if defined(FSL_RTOS_FREE_RTOS)
13 #include "FreeRTOS.h"
14 #endif
15 
21 /*******************************************************************************
22  * Definitions
23  ******************************************************************************/
24 
33 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
34 #define UART_ADAPTER_NON_BLOCKING_MODE (1U)
35 #else
36 #ifndef SERIAL_MANAGER_NON_BLOCKING_MODE
37 #define UART_ADAPTER_NON_BLOCKING_MODE (0U)
38 #else
39 #define UART_ADAPTER_NON_BLOCKING_MODE SERIAL_MANAGER_NON_BLOCKING_MODE
40 #endif
41 #endif
42 
43 #if defined(__GIC_PRIO_BITS)
44 #ifndef HAL_UART_ISR_PRIORITY
45 #define HAL_UART_ISR_PRIORITY (25U)
46 #endif
47 #else
48 #if defined(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY)
49 #ifndef HAL_UART_ISR_PRIORITY
50 #define HAL_UART_ISR_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY)
51 #endif
52 #else
53 /* The default value 3 is used to support different ARM Core, such as CM0P, CM4, CM7, and CM33, etc.
54  * The minimum number of priority bits implemented in the NVIC is 2 on these SOCs. The value of mininum
55  * priority is 3 (2^2 - 1). So, the default value is 3.
56  */
57 #ifndef HAL_UART_ISR_PRIORITY
58 #define HAL_UART_ISR_PRIORITY (3U)
59 #endif
60 #endif
61 #endif
62 
63 #ifndef HAL_UART_ADAPTER_LOWPOWER
64 #define HAL_UART_ADAPTER_LOWPOWER (0U)
65 #endif /* HAL_UART_ADAPTER_LOWPOWER */
66 
68 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
69 #define HAL_UART_HANDLE_SIZE (90U + HAL_UART_ADAPTER_LOWPOWER * 16U)
70 #else
71 #define HAL_UART_HANDLE_SIZE (4U + HAL_UART_ADAPTER_LOWPOWER * 16U)
72 #endif
73 
89 #define UART_HANDLE_DEFINE(name) uint32_t name[((HAL_UART_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
90 
92 #ifndef HAL_UART_TRANSFER_MODE
93 #define HAL_UART_TRANSFER_MODE (0U)
94 #endif
95 
97 typedef void *hal_uart_handle_t;
98 
100 typedef enum _hal_uart_status
101 {
111  6),
115 
118 {
123 
126 {
130 
132 typedef struct _hal_uart_config
133 {
134  uint32_t srcClock_Hz;
135  uint32_t baudRate_Bps;
138  uint8_t enableRx;
139  uint8_t enableTx;
140  uint8_t instance;
144 
146 typedef void (*hal_uart_transfer_callback_t)(hal_uart_handle_t handle, hal_uart_status_t status, void *callbackParam);
147 
149 typedef struct _hal_uart_transfer
150 {
151  uint8_t *data;
152  size_t dataSize;
154 
155 /*******************************************************************************
156  * API
157  ******************************************************************************/
158 
159 #if defined(__cplusplus)
160 extern "C" {
161 #endif /* _cplusplus */
162 
198 
208 
233 hal_uart_status_t HAL_UartReceiveBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length);
234 
250 hal_uart_status_t HAL_UartSendBlocking(hal_uart_handle_t handle, const uint8_t *data, size_t length);
251 
254 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
255 #if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
256 
277 hal_uart_status_t HAL_UartTransferInstallCallback(hal_uart_handle_t handle,
279  void *callbackParam);
280 
300 hal_uart_status_t HAL_UartTransferReceiveNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer);
301 
319 hal_uart_status_t HAL_UartTransferSendNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer);
320 
331 hal_uart_status_t HAL_UartTransferGetReceiveCount(hal_uart_handle_t handle, uint32_t *count);
332 
344 hal_uart_status_t HAL_UartTransferGetSendCount(hal_uart_handle_t handle, uint32_t *count);
345 
358 hal_uart_status_t HAL_UartTransferAbortReceive(hal_uart_handle_t handle);
359 
372 hal_uart_status_t HAL_UartTransferAbortSend(hal_uart_handle_t handle);
373 
376 #else
377 
398 hal_uart_status_t HAL_UartInstallCallback(hal_uart_handle_t handle,
400  void *callbackParam);
401 
422 hal_uart_status_t HAL_UartReceiveNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length);
423 
442 hal_uart_status_t HAL_UartSendNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length);
443 
454 hal_uart_status_t HAL_UartGetReceiveCount(hal_uart_handle_t handle, uint32_t *reCount);
455 
467 hal_uart_status_t HAL_UartGetSendCount(hal_uart_handle_t handle, uint32_t *seCount);
468 
481 hal_uart_status_t HAL_UartAbortReceive(hal_uart_handle_t handle);
482 
495 hal_uart_status_t HAL_UartAbortSend(hal_uart_handle_t handle);
496 
499 #endif
500 #endif
501 
512 
523 
524 #if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
525 
532 void HAL_UartIsrFunction(hal_uart_handle_t handle);
533 #endif
534 
535 #if defined(__cplusplus)
536 }
537 #endif
538 
539 #endif /* __HAL_UART_ADAPTER_H__ */
HAL_UartInit
hal_uart_status_t HAL_UartInit(hal_uart_handle_t handle, hal_uart_config_t *config)
Initializes a UART instance with the UART handle and the user configuration structure.
Definition: lpuart_adapter.c:226
_hal_uart_config::enableTx
uint8_t enableTx
Definition: uart.h:139
kStatus_HAL_UartBaudrateNotSupport
@ kStatus_HAL_UartBaudrateNotSupport
Definition: uart.h:107
kHAL_UartTwoStopBit
@ kHAL_UartTwoStopBit
Definition: uart.h:128
_hal_uart_config::baudRate_Bps
uint32_t baudRate_Bps
Definition: uart.h:135
hal_uart_handle_t
void * hal_uart_handle_t
The handle of uart adapter.
Definition: uart.h:97
_hal_uart_config
UART configuration structure.
Definition: uart.h:132
_hal_uart_status
_hal_uart_status
UART status.
Definition: uart.h:100
kStatus_HAL_UartTxBusy
@ kStatus_HAL_UartTxBusy
Definition: uart.h:103
HAL_UartDeinit
hal_uart_status_t HAL_UartDeinit(hal_uart_handle_t handle)
Deinitializes a UART instance.
Definition: lpuart_adapter.c:310
_hal_uart_config::instance
uint8_t instance
Definition: uart.h:140
kHAL_UartParityOdd
@ kHAL_UartParityOdd
Definition: uart.h:121
_hal_uart_parity_mode
_hal_uart_parity_mode
UART parity mode.
Definition: uart.h:117
_hal_uart_config::parityMode
hal_uart_parity_mode_t parityMode
Definition: uart.h:136
hal_uart_transfer_callback_t
void(* hal_uart_transfer_callback_t)(hal_uart_handle_t handle, hal_uart_status_t status, void *callbackParam)
UART transfer callback function.
Definition: uart.h:146
HAL_UartSendBlocking
hal_uart_status_t HAL_UartSendBlocking(hal_uart_handle_t handle, const uint8_t *data, size_t length)
Writes to the TX register using a blocking method.
Definition: lpuart_adapter.c:353
hal_uart_transfer_t
struct _hal_uart_transfer hal_uart_transfer_t
UART transfer structure.
MAKE_STATUS
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:43
kHAL_UartParityDisabled
@ kHAL_UartParityDisabled
Definition: uart.h:119
_hal_uart_transfer
UART transfer structure.
Definition: uart.h:149
kStatus_HAL_UartTxIdle
@ kStatus_HAL_UartTxIdle
Definition: uart.h:105
HAL_UartEnterLowpower
hal_uart_status_t HAL_UartEnterLowpower(hal_uart_handle_t handle)
Prepares to enter low power consumption.
Definition: lpuart_adapter.c:374
count
size_t count
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/tests/test_common/ma_test_common.c:31
_hal_uart_transfer::data
uint8_t * data
Definition: uart.h:151
kStatus_HAL_UartError
@ kStatus_HAL_UartError
Definition: uart.h:113
_hal_uart_transfer::dataSize
size_t dataSize
Definition: uart.h:152
kHAL_UartOneStopBit
@ kHAL_UartOneStopBit
Definition: uart.h:127
hal_uart_config_t
struct _hal_uart_config hal_uart_config_t
UART configuration structure.
hal_uart_parity_mode_t
enum _hal_uart_parity_mode hal_uart_parity_mode_t
UART parity mode.
HAL_UartReceiveBlocking
hal_uart_status_t HAL_UartReceiveBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
Reads RX data register using a blocking method.
Definition: lpuart_adapter.c:331
kStatusGroup_HAL_UART
@ kStatusGroup_HAL_UART
Definition: fsl_common.h:147
HAL_UartExitLowpower
hal_uart_status_t HAL_UartExitLowpower(hal_uart_handle_t handle)
Restores from low power consumption.
Definition: lpuart_adapter.c:381
kStatus_HAL_UartRxBusy
@ kStatus_HAL_UartRxBusy
Definition: uart.h:104
kStatus_HAL_UartSuccess
@ kStatus_HAL_UartSuccess
Definition: uart.h:102
_hal_uart_config::stopBitCount
hal_uart_stop_bit_count_t stopBitCount
Definition: uart.h:137
_hal_uart_stop_bit_count
_hal_uart_stop_bit_count
UART stop bit count.
Definition: uart.h:125
kHAL_UartParityEven
@ kHAL_UartParityEven
Definition: uart.h:120
_hal_uart_config::enableRx
uint8_t enableRx
Definition: uart.h:138
_hal_uart_config::srcClock_Hz
uint32_t srcClock_Hz
Definition: uart.h:134
config
static sai_transceiver_t config
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:75
kStatus_HAL_UartProtocolError
@ kStatus_HAL_UartProtocolError
Definition: uart.h:109
kStatus_Success
@ kStatus_Success
Definition: fsl_common.h:179
hal_uart_status_t
enum _hal_uart_status hal_uart_status_t
UART status.
kStatus_HAL_UartRxIdle
@ kStatus_HAL_UartRxIdle
Definition: uart.h:106
hal_uart_stop_bit_count_t
enum _hal_uart_stop_bit_count hal_uart_stop_bit_count_t
UART stop bit count.


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:55