2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __FSL_UART_HAL_H__
31 #define __FSL_UART_HAL_H__
36 #include "fsl_uart_features.h"
37 #include "fsl_device_registers.h"
40 * @addtogroup uart_hal
46 /*******************************************************************************
48 ******************************************************************************/
49 #define UART_SHIFT (8U)
51 /*! @brief Error codes for the UART driver. */
52 typedef enum _uart_status
54 kStatus_UART_Success
= 0x0U
,
55 kStatus_UART_BaudRateCalculationError
= 0x1U
,
56 kStatus_UART_RxStandbyModeError
= 0x2U
,
57 kStatus_UART_ClearStatusFlagError
= 0x3U
,
58 kStatus_UART_TxNotDisabled
= 0x4U
,
59 kStatus_UART_RxNotDisabled
= 0x5U
,
60 kStatus_UART_TxOrRxNotDisabled
= 0x6U
,
61 kStatus_UART_TxBusy
= 0x7U
,
62 kStatus_UART_RxBusy
= 0x8U
,
63 kStatus_UART_NoTransmitInProgress
= 0x9U
,
64 kStatus_UART_NoReceiveInProgress
= 0xAU
,
65 kStatus_UART_Timeout
= 0xBU
,
66 kStatus_UART_Initialized
= 0xCU
,
67 kStatus_UART_RxCallBackEnd
= 0xDU
71 * @brief UART number of stop bits.
73 * These constants define the number of allowable stop bits to configure in a UART baseAddr.
75 typedef enum _uart_stop_bit_count
{
76 kUartOneStopBit
= 0U, /*!< one stop bit */
77 kUartTwoStopBit
= 1U, /*!< two stop bits */
78 } uart_stop_bit_count_t
;
81 * @brief UART parity mode.
83 * These constants define the UART parity mode options: disabled or enabled of type even or odd.
85 typedef enum _uart_parity_mode
{
86 kUartParityDisabled
= 0x0U
, /*!< parity disabled */
87 kUartParityEven
= 0x2U
, /*!< parity enabled, type even, bit setting: PE|PT = 10 */
88 kUartParityOdd
= 0x3U
, /*!< parity enabled, type odd, bit setting: PE|PT = 11 */
92 * @brief UART number of bits in a character.
94 * These constants define the number of allowable data bits per UART character. Note, check the
95 * UART documentation to determine if the desired UART baseAddr supports the desired number
96 * of data bits per UART character.
98 typedef enum _uart_bit_count_per_char
{
99 kUart8BitsPerChar
= 0U, /*!< 8-bit data characters */
100 kUart9BitsPerChar
= 1U, /*!< 9-bit data characters */
101 } uart_bit_count_per_char_t
;
104 * @brief UART operation configuration constants.
106 * This provides constants for UART operational states: "operates normally"
107 * or "stops/ceases operation"
109 typedef enum _uart_operation_config
{
110 kUartOperates
= 0U, /*!< UART continues to operate normally */
111 kUartStops
= 1U, /*!< UART ceases operation */
112 } uart_operation_config_t
;
114 /*! @brief UART receiver source select mode. */
115 typedef enum _uart_receiver_source
{
116 kUartLoopBack
= 0U, /*!< Internal loop back mode. */
117 kUartSingleWire
= 1U,/*!< Single wire mode. */
118 } uart_receiver_source_t
;
121 * @brief UART wakeup from standby method constants.
123 * This provides constants for the two UART wakeup methods: idle-line or address-mark.
125 typedef enum _uart_wakeup_method
{
126 kUartIdleLineWake
= 0U, /*!< The idle-line wakes UART receiver from standby */
127 kUartAddrMarkWake
= 1U, /*!< The address-mark wakes UART receiver from standby */
128 } uart_wakeup_method_t
;
131 * @brief UART idle-line detect selection types.
133 * This provides constants for the UART idle character bit-count start: either after start or
136 typedef enum _uart_idle_line_select
{
137 kUartIdleLineAfterStartBit
= 0U, /*!< UART idle character bit count start after start bit */
138 kUartIdleLineAfterStopBit
= 1U, /*!< UART idle character bit count start after stop bit */
139 } uart_idle_line_select_t
;
142 * @brief UART break character length settings for transmit/detect.
144 * This provides constants for the UART break character length for both transmission and detection
145 * purposes. Note that the actual maximum bit times may vary depending on the UART baseAddr.
147 typedef enum _uart_break_char_length
{
148 kUartBreakChar10BitMinimum
= 0U, /*!< UART break char length 10 bit times (if M = 0, SBNS = 0) or
149 11 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 12 (if M = 1,
150 SBNS = 1 or M10 = 1, SNBS = 0) or 13 (if M10 = 1, SNBS = 1) */
151 kUartBreakChar13BitMinimum
= 1U, /*!< UART break char length 13 bit times (if M = 0, SBNS = 0) or
152 14 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 15 (if M = 1,
153 SBNS = 1 or M10 = 1, SNBS = 0) or 16 (if M10 = 1, SNBS = 1) */
154 } uart_break_char_length_t
;
157 * @brief UART single-wire mode transmit direction.
159 * This provides constants for the UART transmit direction when configured for single-wire mode.
160 * The transmit line TXDIR is either an input or output.
162 typedef enum _uart_singlewire_txdir
{
163 kUartSinglewireTxdirIn
= 0U, /*!< UART Single-Wire mode TXDIR input */
164 kUartSinglewireTxdirOut
= 1U, /*!< UART Single-Wire mode TXDIR output */
165 } uart_singlewire_txdir_t
;
168 * @brief UART infrared transmitter pulse width options.
170 * This provides constants for the UART infrared (IR) pulse widths. Options include 3/16, 1/16
171 * 1/32, and 1/4 pulse widths.
173 typedef enum _uart_ir_tx_pulsewidth
{
174 kUartIrThreeSixteenthsWidth
= 0U, /*!< 3/16 pulse */
175 kUartIrOneSixteenthWidth
= 1U, /*!< 1/16 pulse */
176 kUartIrOneThirtysecondsWidth
= 2U, /*!< 1/32 pulse */
177 kUartIrOneFourthWidth
= 3U, /*!< 1/4 pulse */
178 } uart_ir_tx_pulsewidth_t
;
181 * @brief UART status flags.
183 * This provides constants for the UART status flags for use in the UART functions.
185 typedef enum _uart_status_flag
{
186 kUartTxDataRegEmpty
= 0U << UART_SHIFT
| BP_UART_S1_TDRE
, /*!< Tx data register empty flag, sets when Tx buffer is empty */
187 kUartTxComplete
= 0U << UART_SHIFT
| BP_UART_S1_TC
, /*!< Transmission complete flag, sets when transmission activity complete */
188 kUartRxDataRegFull
= 0U << UART_SHIFT
| BP_UART_S1_RDRF
, /*!< Rx data register full flag, sets when the receive data buffer is full */
189 kUartIdleLineDetect
= 0U << UART_SHIFT
| BP_UART_S1_IDLE
, /*!< Idle line detect flag, sets when idle line detected */
190 kUartRxOverrun
= 0U << UART_SHIFT
| BP_UART_S1_OR
, /*!< Rxr Overrun, sets when new data is received before data is read from receive register */
191 kUartNoiseDetect
= 0U << UART_SHIFT
| BP_UART_S1_NF
, /*!< Rxr takes 3 samples of each received bit. If any of these samples differ, noise flag sets */
192 kUartFrameErr
= 0U << UART_SHIFT
| BP_UART_S1_FE
, /*!< Frame error flag, sets if logic 0 was detected where stop bit expected */
193 kUartParityErr
= 0U << UART_SHIFT
| BP_UART_S1_PF
, /*!< If parity enabled, sets upon parity error detection */
194 kUartLineBreakDetect
= 1U << UART_SHIFT
| BP_UART_S2_LBKDIF
, /*!< LIN break detect interrupt flag, sets when LIN break char detected and LIN circuit enabled */
195 kUartRxActiveEdgeDetect
= 1U << UART_SHIFT
| BP_UART_S2_RXEDGIF
, /*!< Rx pin active edge interrupt flag, sets when active edge detected */
196 kUartRxActive
= 1U << UART_SHIFT
| BP_UART_S2_RAF
, /*!< Receiver Active Flag (RAF), sets at beginning of valid start bit */
197 #if FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS
198 kUartNoiseInCurrentWord
= 2U << UART_SHIFT
| BP_UART_ED_NOISY
, /*!< NOISY bit, sets if noise detected in current data word */
199 kUartParityErrInCurrentWord
= 2U << UART_SHIFT
| BP_UART_ED_PARITYE
, /*!< PARITYE bit, sets if noise detected in current data word */
201 #if FSL_FEATURE_UART_HAS_FIFO
202 kUartTxBuffEmpty
= 3U << UART_SHIFT
| BP_UART_SFIFO_TXEMPT
, /*!< TXEMPT bit, sets if Tx buffer is empty */
203 kUartRxBuffEmpty
= 3U << UART_SHIFT
| BP_UART_SFIFO_RXEMPT
, /*!< RXEMPT bit, sets if Rx buffer is empty */
204 kUartTxBuffOverflow
= 3U << UART_SHIFT
| BP_UART_SFIFO_TXOF
, /*!< TXOF bit, sets if Tx buffer overflow occurred */
205 kUartRxBuffUnderflow
= 3U << UART_SHIFT
| BP_UART_SFIFO_RXUF
, /*!< RXUF bit, sets if receive buffer underflow occurred */
207 } uart_status_flag_t
;
210 * @brief UART interrupt configuration structure, default settings are 0 (disabled).
212 * This structure contains the settings for all of the UART interrupt configurations.
214 typedef enum _uart_interrupt
{
215 kUartIntLinBreakDetect
= 0U << UART_SHIFT
| BP_UART_BDH_LBKDIE
, /*!< LIN break detect. */
216 kUartIntRxActiveEdge
= 0U << UART_SHIFT
| BP_UART_BDH_RXEDGIE
, /*!< RX Active Edge. */
217 kUartIntTxDataRegEmpty
= 1U << UART_SHIFT
| BP_UART_C2_TIE
, /*!< Transmit data register empty. */
218 kUartIntTxComplete
= 1U << UART_SHIFT
| BP_UART_C2_TCIE
, /*!< Transmission complete. */
219 kUartIntRxDataRegFull
= 1U << UART_SHIFT
| BP_UART_C2_RIE
, /*!< Receiver data register full. */
220 kUartIntIdleLine
= 1U << UART_SHIFT
| BP_UART_C2_ILIE
, /*!< Idle line. */
221 kUartIntRxOverrun
= 2U << UART_SHIFT
| BP_UART_C3_ORIE
, /*!< Receiver Overrun. */
222 kUartIntNoiseErrFlag
= 2U << UART_SHIFT
| BP_UART_C3_NEIE
, /*!< Noise error flag. */
223 kUartIntFrameErrFlag
= 2U << UART_SHIFT
| BP_UART_C3_FEIE
, /*!< Framing error flag. */
224 kUartIntParityErrFlag
= 2U << UART_SHIFT
| BP_UART_C3_PEIE
, /*!< Parity error flag. */
225 #if FSL_FEATURE_UART_HAS_FIFO
226 kUartIntTxFifoOverflow
= 3U << UART_SHIFT
| BP_UART_CFIFO_TXOFE
, /*!< TX FIFO Overflow. */
227 kUartIntRxFifoUnderflow
= 3U << UART_SHIFT
| BP_UART_CFIFO_RXUFE
, /*!< RX FIFO Underflow. */
231 /*******************************************************************************
233 ******************************************************************************/
235 #if defined(__cplusplus)
240 * @name UART Common Configurations
245 * @brief Initializes the UART controller.
247 * This function initializes the module to a known state.
249 * @param baseAddr UART module base address.
251 void UART_HAL_Init(uint32_t baseAddr
);
254 * @brief Enables the UART transmitter.
256 * This function allows the user to enable the UART transmitter.
258 * @param baseAddr UART module base address.
260 static inline void UART_HAL_EnableTransmitter(uint32_t baseAddr
)
262 BW_UART_C2_TE(baseAddr
, 1U);
266 * @brief Disables the UART transmitter.
268 * This function allows the user to disable the UART transmitter.
270 * @param baseAddr UART module base address.
272 static inline void UART_HAL_DisableTransmitter(uint32_t baseAddr
)
274 BW_UART_C2_TE(baseAddr
, 0U);
278 * @brief Gets the UART transmitter enabled/disabled configuration setting.
280 * This function allows the user to get the setting of the UART transmitter.
282 * @param baseAddr UART module base address.
283 * @return The state of UART transmitter enable(true)/disable(false) setting.
285 static inline bool UART_HAL_IsTransmitterEnabled(uint32_t baseAddr
)
287 return (bool)BR_UART_C2_TE(baseAddr
);
291 * @brief Enables the UART receiver.
293 * This function allows the user to enable the UART receiver.
295 * @param baseAddr UART module base address.
297 static inline void UART_HAL_EnableReceiver(uint32_t baseAddr
)
299 BW_UART_C2_RE(baseAddr
, 1U);
303 * @brief Disables the UART receiver.
305 * This function allows the user to disable the UART receiver.
307 * @param baseAddr UART module base address.
309 static inline void UART_HAL_DisableReceiver(uint32_t baseAddr
)
311 BW_UART_C2_RE(baseAddr
, 0U);
315 * @brief Gets the UART receiver enabled/disabled configuration setting.
317 * This function allows the user to get the setting of the UART receiver.
319 * @param baseAddr UART module base address.
320 * @return The state of UART receiver enable(true)/disable(false) setting.
322 static inline bool UART_HAL_IsReceiverEnabled(uint32_t baseAddr
)
324 return (bool)BR_UART_C2_RE(baseAddr
);
328 * @brief Configures the UART baud rate.
330 * This function programs the UART baud rate to the desired value passed in by the user. The user
331 * must also pass in the module source clock so that the function can calculate the baud
332 * rate divisors to their appropriate values.
333 * In some UART baseAddrs it is required that the transmitter/receiver be disabled
334 * before calling this function.
335 * Generally this is applied to all UARTs to ensure safe operation.
337 * @param baseAddr UART module base address.
338 * @param sourceClockInHz UART source input clock in Hz.
339 * @param baudRate UART desired baud rate.
340 * @return An error code or kStatus_UART_Success
342 uart_status_t
UART_HAL_SetBaudRate(uint32_t baseAddr
, uint32_t sourceClockInHz
, uint32_t baudRate
);
345 * @brief Sets the UART baud rate modulo divisor value.
347 * This function allows the user to program the baud rate divisor directly in situations
348 * where the divisor value is known. In this case, the user may not want to call the
349 * UART_HAL_SetBaudRate() function, as the divisor is already known.
351 * @param baseAddr UART module base address.
352 * @param baudRateDivisor The baud rate modulo division "SBR" value.
354 void UART_HAL_SetBaudRateDivisor(uint32_t baseAddr
, uint16_t baudRateDivisor
);
356 #if FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
358 * @brief Sets the UART baud rate fine adjust. (Note: Feature available on select
359 * UART baseAddrs used in conjunction with baud rate programming)
361 * This function, which programs the baud rate fine adjust, is used together with
362 * programming the baud rate modulo divisor in situations where these divisors value are known.
363 * In this case, the user may not want to call the UART_HAL_SetBaudRate() function, as the
364 * divisors are already known.
366 * @param baseAddr UART module base address.
367 * @param baudFineAdjust Value of 5-bit field used to add more timing resolution to average
368 * baud rate frequency is 1/32 increments.
370 static inline void UART_HAL_SetBaudRateFineAdjust(uint32_t baseAddr
, uint8_t baudFineAdjust
)
372 assert(baudFineAdjust
< 0x1F);
373 BW_UART_C4_BRFA(baseAddr
, baudFineAdjust
);
378 * @brief Configures the number of bits per character in the UART controller.
380 * This function allows the user to configure the number of bits per character according to the
381 * typedef uart_bit_count_per_char_t.
383 * @param baseAddr UART module base address.
384 * @param bitCountPerChar Number of bits per char (8, 9, or 10, depending on the UART baseAddr).
386 static inline void UART_HAL_SetBitCountPerChar(uint32_t baseAddr
,
387 uart_bit_count_per_char_t bitCountPerChar
)
389 /* config 8- (M=0) or 9-bits (M=1) */
390 BW_UART_C1_M(baseAddr
, bitCountPerChar
);
394 * @brief Configures the parity mode in the UART controller.
396 * This function allows the user to configure the parity mode of the UART controller to disable
397 * it or enable it for even parity or for odd parity.
399 * @param baseAddr UART module base address.
400 * @param parityMode Parity mode setting (enabled, disable, odd, even - see
401 * parity_mode_t struct).
403 static inline void UART_HAL_SetParityMode(uint32_t baseAddr
, uart_parity_mode_t parityMode
)
405 HW_UART_C1_SET(baseAddr
, parityMode
);
408 #if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
410 * @brief Configures the number of stop bits in the UART controller.
412 * This function allows the user to configure the number of stop bits in the UART controller
413 * to be one or two stop bits.
415 * @param baseAddr UART module base address.
416 * @param stopBitCount Number of stop bits setting (1 or 2 - see uart_stop_bit_count_t struct).
417 * @return An error code (an unsupported setting in some UARTs) or kStatus_UART_Success.
419 static inline void UART_HAL_SetStopBitCount(uint32_t baseAddr
, uart_stop_bit_count_t stopBitCount
)
421 BW_UART_BDH_SBNS(baseAddr
, stopBitCount
);
426 * @brief Configures the transmit and receive inversion control in UART controller.
428 * This function allows the user to invert the transmit and receive signals, independently.
429 * This function should only be called when the UART is between transmit and receive packets.
431 * @param baseAddr UART module base address.
432 * @param rxInvert Enable (true) or disable (false) receive inversion.
433 * @param txInvert Enable (true) or disable (false) transmit inversion.
435 void UART_HAL_SetTxRxInversionCmd(uint32_t baseAddr
, bool rxInvertEnable
, bool txInvertEnable
);
440 * @name UART Interrupts and DMA
445 * @brief Configures the UART module interrupts to enable/disable various interrupt sources.
447 * @param baseAddr UART module base address.
448 * @param interrupt UART interrupt configuration data.
449 * @param enable true: enable, false: disable.
451 void UART_HAL_SetIntMode(uint32_t baseAddr
, uart_interrupt_t interrupt
, bool enable
);
454 * @brief Returns whether the UART module interrupts is enabled/disabled.
456 * @param baseAddr UART module base address.
457 * @param interrupt UART interrupt configuration data.
458 * @return true: enable, false: disable.
460 bool UART_HAL_GetIntMode(uint32_t baseAddr
, uart_interrupt_t interrupt
);
463 * @brief Enables or disables the tx_data_register_empty_interrupt.
465 * @param baseAddr UART module base address.
466 * @param enable true: enable, false: disable.
468 static inline void UART_HAL_SetTxDataRegEmptyIntCmd(uint32_t baseAddr
, bool enable
)
470 /* transmit interrupt enable for TDRE (transmit data register empty)*/
471 BW_UART_C2_TIE(baseAddr
, (uint8_t)enable
);
475 * @brief Gets the configuration of the tx_data_register_empty_interrupt enable setting.
477 * @param baseAddr UART module base address.
478 * @return setting of the interrupt enable bit.
480 static inline bool UART_HAL_GetTxDataRegEmptyIntCmd(uint32_t baseAddr
)
482 /* return interrupt enable condition of TIE */
483 return (bool)BR_UART_C2_TIE(baseAddr
);
487 * @brief Disables the rx_data_register_full_interrupt.
489 * @param baseAddr UART module base address.
490 * @param enable true: enable, false: disable.
492 static inline void UART_HAL_SetRxDataRegFullIntCmd(uint32_t baseAddr
, bool enable
)
494 /* receiver interrupt enable for receiver data register full (RDRF)*/
495 BW_UART_C2_RIE(baseAddr
, (uint8_t)enable
);
499 * @brief Gets the configuration of the rx_data_register_full_interrupt enable setting.
501 * @param baseAddr UART module base address.
502 * @return Bit setting of the interrupt enable bit.
504 static inline bool UART_HAL_GetRxDataRegFullIntCmd(uint32_t baseAddr
)
506 /* return interrupt enable condition of RIE */
507 return (bool)BR_UART_C2_RIE(baseAddr
);
511 * @brief Configures the UART DMA requests for the Transmitter and Receiver.
513 * This function allows the user to configure the transmit data register empty flag to
514 * generate an interrupt request (default) or a DMA request. Similarly, this function
515 * allows the user to configure the receive data register full flag to generate an interrupt
516 * request (default) or a DMA request.
518 * @param baseAddr UART module base address.
519 * @param txDmaConfig Transmit DMA request configuration setting (enable: true /disable: false).
520 * @param rxDmaConfig Receive DMA request configuration setting (enable: true/disable: false).
522 void UART_HAL_ConfigureDma(uint32_t baseAddr
, bool txDmaConfig
, bool rxDmaConfig
);
525 * @brief Gets the UART Transmit DMA request configuration setting.
527 * This function returns the configuration setting of the Transmit DMA request.
529 * @param baseAddr UART module base address.
530 * @return Transmit DMA request configuration setting (enable: true /disable: false).
532 bool UART_HAL_IsTxdmaEnabled(uint32_t baseAddr
);
535 * @brief Gets the UART Receive DMA request configuration setting.
537 * This function returns the configuration setting of the Receive DMA request.
539 * @param baseAddr UART module base address.
540 * @return Receive DMA request configuration setting (enable: true /disable: false).
542 bool UART_HAL_IsRxdmaEnabled(uint32_t baseAddr
);
545 * @brief Get UART tx/rx data register address.
547 * This function is used for DMA transfer.
549 * @return UART tx/rx data register address.
551 static inline uint32_t UART_HAL_GetDataRegAddr(uint32_t baseAddr
)
553 return (uint32_t)HW_UART_D_ADDR(baseAddr
);
559 * @name UART Transfer Functions
564 * @brief This function allows the user to send an 8-bit character from the UART data register.
566 * @param baseAddr UART module base address.
567 * @param data The data to send of size 8-bit.
569 void UART_HAL_Putchar(uint32_t baseAddr
, uint8_t data
);
572 * @brief This function allows the user to send a 9-bit character from the UART data register.
574 * @param baseAddr UART module base address.
575 * @param data The data to send of size 9-bit.
577 void UART_HAL_Putchar9(uint32_t baseAddr
, uint16_t data
);
580 * @brief This function gets a received 8-bit character from the UART data register.
582 * @param baseAddr UART module base address.
583 * @param readData The received data read from data register of size 8-bit.
585 void UART_HAL_Getchar(uint32_t baseAddr
, uint8_t *readData
);
588 * @brief This function gets a received 9-bit character from the UART data register.
590 * @param baseAddr UART module base address.
591 * @param readData The received data read from data register of size 9-bit.
593 void UART_HAL_Getchar9(uint32_t baseAddr
, uint16_t *readData
);
595 #if FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS
597 * @brief Configures the UART bit 10 (if enabled) or bit 9 (if disabled) as the parity bit in the
598 * serial transmission.
600 * This function configures bit 10 or bit 9 to be the parity bit. To configure bit 10 as the parity
601 * bit, the function sets UARTx_C4[M10]; it also sets UARTx_C1[M] and UARTx_C1[PE] as required.
603 * @param baseAddr UART module base address.
604 * @param enable The setting to enable (true), which configures bit 10 as the parity bit or to
605 * disable (false), which configures bit 9 as the parity bit in the serial
608 static inline void UART_HAL_SetBit10AsParitybit(uint32_t baseAddr
, bool enable
)
610 /* to enable the parity bit as the tenth data bit, along with enabling UARTx_C4[M10]
611 * need to also enable parity and set UARTx_C1[M] bit
612 * assumed that the user has already set the appropriate bits */
613 BW_UART_C4_M10(baseAddr
, enable
);
617 * @brief Gets the configuration of the UART bit 10 (if enabled) or bit 9 (if disabled) as the
618 * parity bit in the serial transmission.
620 * This function returns true if bit 10 is configured as the parity bit, otherwise it returns
621 * false if bit 9 is configured as the parity bit.
623 * @param baseAddr UART module base address.
624 * @return The configuration setting of bit 10 (true), or bit 9 (false) as the
625 * parity bit in the serial transmission.
627 static inline bool UART_HAL_IsBit10SetAsParitybit(uint32_t baseAddr
)
629 /* to see if the parity bit is set as the tenth data bit,
630 * return value of UARTx_C4[M10] */
631 return BR_UART_C4_M10(baseAddr
);
635 * @brief Determines whether the UART received data word was received with noise.
637 * This function returns true if the received data word was received with noise. Otherwise,
638 * it returns false indicating no noise was detected.
640 * @param baseAddr UART module base address.
641 * @return The status of the NOISY bit in the UART extended data register.
643 static inline bool UART_HAL_IsCurrentDatawordReceivedWithNoise(uint32_t baseAddr
)
645 /* to see if the current dataword was received with noise,
646 * return value of UARTx_ED[NOISY] */
647 return BR_UART_ED_NOISY(baseAddr
);
651 * @brief Determines whether the UART received data word was received with a parity error.
653 * This function returns true if the received data word was received with a parity error.
654 * Otherwise, it returns false indicating no parity error was detected.
656 * @param baseAddr UART module base address.
657 * @return The status of the PARITYE (parity error) bit in the UART extended data register.
659 static inline bool UART_HAL_IsCurrentDatawordReceivedWithParityerror(uint32_t baseAddr
)
661 /* to see if the current dataword was received with parity error,
662 * return value of UARTx_ED[PARITYE] */
663 return BR_UART_ED_PARITYE(baseAddr
);
666 #endif /* FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS*/
671 * @name UART Special Feature Configurations
676 * @brief Configures the UART to either operate or cease to operate in WAIT mode.
678 * The function configures the UART to either operate or cease to operate when WAIT mode is
681 * @param baseAddr UART module base address.
682 * @param mode The UART WAIT mode operation - operates or ceases to operate in WAIT mode.
684 static inline void UART_HAL_SetWaitModeOperation(uint32_t baseAddr
, uart_operation_config_t mode
)
686 /*In CPU wait mode: 0 - uart is enabled; 1 - uart is disabled */
687 BW_UART_C1_UARTSWAI(baseAddr
, mode
);
691 * @brief Determines if the UART operates or ceases to operate in WAIT mode.
693 * This function returns kUartOperates if the UART has been configured to operate in WAIT mode.
694 * Else it returns KUartStops if the UART has been configured to cease-to-operate in WAIT mode.
696 * @param baseAddr UART module base address.
697 * @return The UART WAIT mode operation configuration, returns either kUartOperates or KUartStops.
699 static inline uart_operation_config_t
UART_HAL_GetWaitModeOperation(uint32_t baseAddr
)
701 /*In CPU wait mode: 0 - uart is enabled; 1 - uart is disabled */
702 return (uart_operation_config_t
)BR_UART_C1_UARTSWAI(baseAddr
);
706 * @brief Configures the UART loopback operation.
708 * This function enables or disables the UART loopback operation.
710 * @param baseAddr UART module base address.
711 * @param enable The UART loopback mode configuration, either disabled (false) or enabled (true).
713 static inline void UART_HAL_SetLoopCmd(uint32_t baseAddr
, bool enable
)
715 BW_UART_C1_LOOPS(baseAddr
, enable
);
719 * @brief Configures the UART single-wire operation.
721 * This function enables or disables the UART single-wire operation.
722 * In some UART baseAddrs it is required that the transmitter/receiver be disabled
723 * before calling this function.
724 * This may be applied to all UARTs to ensure safe operation.
726 * @param baseAddr UART module base address.
727 * @param enable The UART single-wire mode configuration, either disabled (false) or enabled (true).
729 static inline void UART_HAL_SetReceiverSource(uint32_t baseAddr
, uart_receiver_source_t source
)
731 BW_UART_C1_RSRC(baseAddr
, source
);
734 * @brief Configures the UART transmit direction while in single-wire mode.
736 * This function configures the transmitter direction when the UART is configured for single-wire
739 * @param baseAddr UART module base address.
740 * @param direction The UART single-wire mode transmit direction configuration of type
741 * uart_singlewire_txdir_t (either kUartSinglewireTxdirIn or
742 * kUartSinglewireTxdirOut.
744 static inline void UART_HAL_SetTransmitterDir(uint32_t baseAddr
, uart_singlewire_txdir_t direction
)
746 /* configure UART transmit direction (input or output) when in single-wire mode
747 * it is assumed UART is in single-wire mode
749 BW_UART_C3_TXDIR(baseAddr
, direction
);
753 * @brief Places the UART receiver in standby mode.
755 * This function, when called, places the UART receiver into standby mode.
756 * In some UART baseAddrs, there are conditions that must be met before placing Rx in standby mode.
757 * Before placing UART in standby, determine if receiver is set to
758 * wake on idle, and if receiver is already in idle state.
759 * NOTE: RWU should only be set with C1[WAKE] = 0 (wakeup on idle) if the channel is currently
761 * This can be determined by the S2[RAF] flag. If set to wake up FROM an IDLE event and the channel
762 * is already idle, it is possible that the UART will discard data because data must be received
763 * (or a LIN break detect) after an IDLE is detected before IDLE is allowed to be reasserted.
765 * @param baseAddr UART module base address.
766 * @return Error code or kStatus_UART_Success.
768 uart_status_t
UART_HAL_PutReceiverInStandbyMode(uint32_t baseAddr
);
771 * @brief Places the UART receiver in normal mode (disable standby mode operation).
773 * This function, when called, places the UART receiver into normal mode and out of
776 * @param baseAddr UART module base address.
778 static inline void UART_HAL_PutReceiverInNormalMode(uint32_t baseAddr
)
780 /* clear the RWU bit to place receiver into normal mode (disable standby mode)*/
781 HW_UART_C2_CLR(baseAddr
, BM_UART_C2_RWU
);
785 * @brief Determines if the UART receiver is currently in standby mode.
787 * This function determines the state of the UART receiver. If it returns true, this means
788 * that the UART receiver is in standby mode; if it returns false, the UART receiver
791 * @param baseAddr UART module base address.
792 * @return The UART receiver is in normal mode (false) or standby mode (true).
794 static inline bool UART_HAL_IsReceiverInStandby(uint32_t baseAddr
)
796 /* return the RWU bit setting (0 - normal more, 1 - standby)*/
797 return BR_UART_C2_RWU(baseAddr
);
801 * @brief Selects the UART receiver wakeup method (idle-line or address-mark) from standby mode.
803 * This function configures the wakeup method of the UART receiver from standby mode. The options
804 * are idle-line wake or address-mark wake.
806 * @param baseAddr UART module base address.
807 * @param method The UART receiver wakeup method options: kUartIdleLineWake - Idle-line wake or
808 * kUartAddrMarkWake - address-mark wake.
810 static inline void UART_HAL_SetReceiverWakeupMethod(uint32_t baseAddr
, uart_wakeup_method_t method
)
812 /* configure the WAKE bit for idle line wake or address mark wake */
813 BW_UART_C1_WAKE(baseAddr
, method
);
817 * @brief Gets the UART receiver wakeup method (idle-line or address-mark) from standby mode.
819 * This function returns how the UART receiver is configured to wake from standby mode. The
820 * wake method options that can be returned are kUartIdleLineWake or kUartAddrMarkWake.
822 * @param baseAddr UART module base address.
823 * @return The UART receiver wakeup from standby method, false: kUartIdleLineWake (idle-line wake)
824 * or true: kUartAddrMarkWake (address-mark wake).
826 static inline uart_wakeup_method_t
UART_HAL_GetReceiverWakeupMethod(uint32_t baseAddr
)
828 /* get configuration of the WAKE bit for idle line wake or address mark wake */
829 return (uart_wakeup_method_t
)BR_UART_C1_WAKE(baseAddr
);
833 * @brief Configures the operation options of the UART idle line detect.
835 * This function allows the user to configure the UART idle-line detect operation. There are two
836 * separate operations for the user to configure, the idle line bit-count start and the receive
837 * wake up affect on IDLE status bit. The user will pass in a structure of type
838 * uart_idle_line_config_t.
840 * @param baseAddr UART module base address.
841 * @param idleLine Idle bit count start: 0 - after start bit (default), 1 - after stop bit
842 * @param rxWakeIdleDetect Receiver Wake Up Idle Detect. IDLE status bit operation during receive
843 * standby. Controls whether idle character that wakes up receiver will also set IDLE status
844 * bit. 0 - IDLE status bit doesn't get set (default), 1 - IDLE status bit gets set
846 void UART_HAL_ConfigIdleLineDetect(uint32_t baseAddr
, uint8_t idleLine
, uint8_t rxWakeIdleDetect
);
849 * @brief Configures the UART break character transmit length.
851 * This function allows the user to configure the UART break character transmit length. Refer to
852 * the typedef uart_break_char_length_t for setting options.
853 * In some UART baseAddrs it is required that the transmitter be disabled before calling
854 * this function. This may be applied to all UARTs to ensure safe operation.
856 * @param baseAddr UART module base address.
857 * @param length The UART break character length setting of type uart_break_char_length_t, either a
858 * minimum 10-bit times or a minimum 13-bit times.
860 static inline void UART_HAL_SetBreakCharTransmitLength(uint32_t baseAddr
,
861 uart_break_char_length_t length
)
863 /* Configure BRK13 - Break Character transmit length configuration
864 * UART break character length setting:
865 * 0 - minimum 10-bit times (default),
866 * 1 - minimum 13-bit times */
867 BW_UART_S2_BRK13(baseAddr
, length
);
871 * @brief Configures the UART break character detect length.
873 * This function allows the user to configure the UART break character detect length. Refer to
874 * the typedef uart_break_char_length_t for setting options.
876 * @param baseAddr UART module base address.
877 * @param length The UART break character length setting of type uart_break_char_length_t, either a
878 * minimum 10-bit times or a minimum 13-bit times.
880 static inline void UART_HAL_SetBreakCharDetectLength(uint32_t baseAddr
, uart_break_char_length_t length
)
882 /* Configure LBKDE - Break Character detect length configuration
883 * UART break character length setting:
884 * 0 - minimum 10-bit times (default),
885 * 1 - minimum 13-bit times */
886 BW_UART_S2_LBKDE(baseAddr
, length
);
890 * @brief Configures the UART transmit send break character operation.
892 * This function allows the user to queue a UART break character to send. If true is passed into
893 * the function, then a break character is queued for transmission. A break character will
894 * continuously be queued until this function is called again when a false is passed into this
897 * @param baseAddr UART module base address.
898 * @param enable If false, the UART normal/queue break character setting is disabled, which
899 * configures the UART for normal transmitter operation. If true, a break
900 * character is queued for transmission.
902 static inline void UART_HAL_SetBreakCharCmd(uint32_t baseAddr
, bool enable
)
904 BW_UART_C2_SBK(baseAddr
, enable
);
908 * @brief Configures the UART match address mode control operation. (Note: Feature available on
909 * select UART baseAddrs)
911 * The function allows the user to configure the UART match address control operation. The user
912 * has the option to enable the match address mode and to program the match address value. There
913 * are two match address modes, each with its own enable and programmable match address value.
915 * @param baseAddr UART module base address.
916 * @param matchAddrMode1 If true, this enables match address mode 1 (MAEN1), where false disables.
917 * @param matchAddrMode2 If true, this enables match address mode 2 (MAEN2), where false disables.
918 * @param matchAddrValue1 The match address value to program for match address mode 1.
919 * @param matchAddrValue2 The match address value to program for match address mode 2.
921 void UART_HAL_SetMatchAddress(uint32_t baseAddr
, bool matchAddrMode1
, bool matchAddrMode2
,
922 uint8_t matchAddrValue1
, uint8_t matchAddrValue2
);
924 #if FSL_FEATURE_UART_HAS_BIT_ORDER_SELECT
926 * @brief Configures the UART to send data MSB first
927 * (Note: Feature available on select UART baseAddrs)
929 * The function allows the user to configure the UART to send data MSB first or LSB first.
930 * In some UART baseAddrs it is required that the transmitter/receiver be disabled
931 * before calling this function.
932 * This may be applied to all UARTs to ensure safe operation.
934 * @param baseAddr UART module base address.
935 * @param enable This configures send MSB first mode configuration. If true, the data is sent MSB
936 * first; if false, it is sent LSB first.
938 static inline void UART_HAL_SetSendMsbFirstCmd(uint32_t baseAddr
, bool enable
)
940 BW_UART_S2_MSBF(baseAddr
, enable
);
944 #if FSL_FEATURE_UART_HAS_MODEM_SUPPORT
946 * @brief Enables the UART receiver request-to-send functionality.
948 * This function allows the user to enable the UART receiver request-to-send (RTS) functionality.
949 * By enabling, it allows the RTS output to control the CTS input of the transmitting device to
950 * prevent receiver overrun. RTS is deasserted if the number of characters in the receiver data
951 * register (FIFO) is equal to or greater than RWFIFO[RXWATER]. RTS is asserted when the
952 * number of characters in the receiver data register (FIFO) is less than RWFIFO[RXWATER].
953 * Do not set both RXRTSE and TXRTSE.
955 * @param baseAddr UART module base address.
956 * @param enable Enable or disable receiver rts.
958 static inline void UART_HAL_SetReceiverRtsCmd(uint32_t baseAddr
, bool enable
)
961 BW_UART_MODEM_RXRTSE(baseAddr
, enable
);
965 * @brief Enables the UART transmitter request-to-send functionality.
967 * This function allows the user to enable the UART transmitter request-to-send (RTS) functionality.
968 * When enabled, it allows the UART to control the RTS assertion before and after a transmission
969 * such that when a character is placed into an empty transmitter data buffer, RTS
970 * asserts one bit time before the start bit is transmitted. RTS deasserts one bit time after all
971 * characters in the transmitter data buffer and shift register are completely sent, including
974 * @param baseAddr UART module base address.
975 * @param enable Enable or disable transmitter RTS.
977 static inline void UART_HAL_SetTransmitterRtsCmd(uint32_t baseAddr
, bool enable
)
980 BW_UART_MODEM_TXRTSE(baseAddr
, enable
);
984 * @brief Configures the UART transmitter RTS polarity.
986 * This function allows the user configure the transmitter RTS polarity to be either active low
989 * @param baseAddr UART module base address.
990 * @param polarity The UART transmitter RTS polarity setting (false - active low,
991 * true - active high).
993 static inline void UART_HAL_SetTransmitterRtsPolarityMode(uint32_t baseAddr
, bool polarity
)
995 /* Configure the transmitter rts polarity: 0=active low, 1=active high */
996 BW_UART_MODEM_TXRTSPOL(baseAddr
, polarity
);
1000 * @brief Enables the UART transmitter clear-to-send functionality.
1002 * This function allows the user to enable the UART transmitter clear-to-send (CTS) functionality.
1003 * When enabled, the transmitter checks the state of CTS each time it is ready to send a character.
1004 * If CTS is asserted, the character is sent. If CTS is deasserted, the signal TXD remains in
1005 * the mark state and transmission is delayed until CTS is asserted. Changes in CTS as a
1006 * character is being sent do not affect its transmission.
1008 * @param baseAddr UART module base address.
1009 * @param enable Enable or disable transmitter CTS.
1011 static inline void UART_HAL_SetTransmitterCtsCmd(uint32_t baseAddr
, bool enable
)
1014 BW_UART_MODEM_TXCTSE(baseAddr
, enable
);
1017 #endif /* FSL_FEATURE_UART_HAS_MODEM_SUPPORT*/
1019 #if FSL_FEATURE_UART_HAS_IR_SUPPORT
1021 * @brief Configures the UART infrared operation.
1023 * The function allows the user to enable or disable the UART infrared (IR) operation
1024 * and to configure the IR pulse width.
1026 * @param baseAddr UART module base address.
1027 * @param enable Enable (true) or disable (false) the infrared operation.
1028 * @param pulseWidth The UART transmit narrow pulse width setting of type uart_ir_tx_pulsewidth_t.
1030 void UART_HAL_SetInfraredOperation(uint32_t baseAddr
, bool enable
,
1031 uart_ir_tx_pulsewidth_t pulseWidth
);
1032 #endif /* FSL_FEATURE_UART_HAS_IR_SUPPORT*/
1037 * @name UART Status Flags
1042 * @brief Gets all UART status flag states.
1044 * @param baseAddr UART module base address.
1045 * @param statusFlag Status flag name.
1047 bool UART_HAL_GetStatusFlag(uint32_t baseAddr
, uart_status_flag_t statusFlag
);
1050 * @brief Gets the UART Transmit data register empty flag.
1052 * This function returns the state of the UART Transmit data register empty flag.
1054 * @param baseAddr UART module base address.
1055 * @return The status of Transmit data register empty flag, which is set when transmit buffer
1058 static inline bool UART_HAL_IsTxDataRegEmpty(uint32_t baseAddr
)
1060 /* return status condition of TDRE flag */
1061 return BR_UART_S1_TDRE(baseAddr
);
1065 * @brief Gets the UART Transmission complete flag.
1067 * This function returns the state of the UART Transmission complete flag.
1069 * @param baseAddr UART module base address.
1070 * @return The status of Transmission complete flag, which is set when the transmitter is idle
1071 * (transmission activity complete).
1073 static inline bool UART_HAL_IsTxComplete(uint32_t baseAddr
)
1075 /* return status condition of TC flag */
1076 return BR_UART_S1_TC(baseAddr
);
1080 * @brief Gets the UART Receive data register full flag.
1082 * This function returns the state of the UART Receive data register full flag.
1084 * @param baseAddr UART module base address.
1085 * @return The status of Receive data register full flag, which is set when the receive data buffer
1088 static inline bool UART_HAL_IsRxDataRegFull(uint32_t baseAddr
)
1090 /* return status condition of RDRF flag */
1091 return BR_UART_S1_RDRF(baseAddr
);
1095 * @brief Clears an individual and specific UART status flag.
1097 * This function allows the user to clear an individual and specific UART status flag. Refer to
1098 * structure definition uart_status_flag_t for list of status bits.
1100 * @param baseAddr UART module base address.
1101 * @param statusFlag The desired UART status flag to clear.
1102 * @return An error code or kStatus_UART_Success.
1104 uart_status_t
UART_HAL_ClearStatusFlag(uint32_t baseAddr
, uart_status_flag_t statusFlag
);
1107 * @brief Clears all UART status flags.
1109 * This function tries to clear all of the UART status flags. In some cases, some of the status
1110 * flags may not get cleared because the condition that set the flag may still exist.
1112 * @param baseAddr UART module base address.
1114 void UART_HAL_ClearAllNonAutoclearStatusFlags(uint32_t baseAddr
);
1119 * @name UART FIFO Configurations
1123 #if FSL_FEATURE_UART_HAS_FIFO
1125 * @brief Enables or disable the UART transmit FIFO.
1127 * This function allows the user to enable or disable the UART transmit FIFO.
1128 * It is required that the transmitter/receiver be disabled before calling this function
1129 * when the FIFO is empty.
1130 * Additionally, TXFLUSH and RXFLUSH commands should be issued after calling this function.
1132 * @param baseAddr UART module base address.
1133 * @param enable Enable or disable Tx FIFO.
1134 * @return Error code if it is detected that the transmitter or receiver is enabled or
1135 * kStatus_UART_Success.
1137 uart_status_t
UART_HAL_SetTxFifoCmd(uint32_t baseAddr
, bool enable
);
1140 * @brief Enables or disable the UART receive FIFO.
1142 * This function allows the user to enable or disable the UART receive FIFO.
1143 * It is required that the transmitter/receiver be disabled before calling this function
1144 * when the FIFO is empty.
1145 * Additionally, TXFLUSH and RXFLUSH commands should be issued after calling this function.
1147 * @param baseAddr UART module base address.
1148 * @param enable Enable or disable Rx FIFO.
1149 * @return Error code if it is detected that the transmitter or receiver is enabled or
1150 * kStatus_UART_Success.
1152 uart_status_t
UART_HAL_SetRxFifoCmd(uint32_t baseAddr
, bool enable
);
1155 * @brief Gets the size of the UART transmit FIFO.
1157 * This function returns the size (number of entries) supported in the UART transmit FIFO for
1158 * a particular module baseAddr.
1160 * @param baseAddr UART module base address.
1161 * @return The UART transmit FIFO size as follows:
1162 * 0x0: 1 data word; 0x1: 4 data words; 0x2: 8 data words; 0x3: 16 data words
1163 * 0x4: 32 data words; 0x5: 64 data words; 0x6: 128 data words; 0x7: reserved
1165 static inline uint8_t UART_HAL_GetTxFifoSize(uint32_t baseAddr
)
1167 return BR_UART_PFIFO_TXFIFOSIZE(baseAddr
);
1171 * @brief Gets the size of the UART receive FIFO.
1173 * This function returns the size (number of entries) supported in the UART receive FIFO for
1174 * a particular module baseAddr.
1176 * @param baseAddr UART module base address.
1177 * @return The receive FIFO size as follows:
1178 * 0x0: 1 data word; 0x1: 4 data words; 0x2: 8 data words; 0x3: 16 data words
1179 * 0x4: 32 data words; 0x5: 64 data words; 0x6: 128 data words; 0x7: reserved
1181 static inline uint8_t UART_HAL_GetRxFifoSize(uint32_t baseAddr
)
1183 return BR_UART_PFIFO_RXFIFOSIZE(baseAddr
);
1187 * @brief Flushes the UART transmit FIFO.
1189 * This function allows the user to flush the UART transmit FIFO for a particular module baseAddr.
1190 * Flushing the FIFO may result in data loss.
1191 * It is recommended that the transmitter be disabled before calling this function.
1193 * @param baseAddr UART module base address.
1194 * @return Error code if it is detected that the transmitter or receiver is enabled or
1195 * kStatus_UART_Success.
1197 uart_status_t
UART_HAL_FlushTxFifo(uint32_t baseAddr
);
1200 * @brief Flushes the UART receive FIFO.
1202 * This function allows the user to flush the UART receive FIFO for a particular module baseAddr.
1203 * Flushing the FIFO may result in data loss.
1204 * It is recommended that the receiver be disabled before calling this function.
1206 * @param baseAddr UART module base address.
1207 * @return Error code if it is detected that the transmitter or receiver is enabled or
1208 * kStatus_UART_Success.
1210 uart_status_t
UART_HAL_FlushRxFifo(uint32_t baseAddr
);
1213 * @brief Gets the UART transmit FIFO empty status state.
1215 * The function returns the state of the transmit FIFO empty status state, but does not take into
1216 * account data in the shift register.
1218 * @param baseAddr UART module base address.
1219 * @return The UART transmit FIFO empty status: true=empty; false=not-empty.
1221 static inline bool UART_HAL_IsTxFifoEmpty(uint32_t baseAddr
)
1223 return BR_UART_SFIFO_TXEMPT(baseAddr
);
1227 * @brief Gets the UART receive FIFO empty status state.
1229 * The function returns the state of the receive FIFO empty status state, but does not take into
1230 * account data in the shift register.
1232 * @param baseAddr UART module base address.
1233 * @return The UART receive FIFO empty status: true=empty; false=not-empty.
1235 static inline bool UART_HAL_IsRxFifoEmpty(uint32_t baseAddr
)
1237 return BR_UART_SFIFO_RXEMPT(baseAddr
);
1241 * @brief Sets the UART transmit FIFO watermark value.
1243 * Programming the transmit watermark should be done when UART the transmitter is disabled
1244 * and the value must be set less than the size obtained from UART_HAL_GetTxFifoSize.
1246 * @param baseAddr UART module base address.
1247 * @param watermark The UART transmit watermark value to be programmed.
1248 * @return Error code if transmitter is enabled or kStatus_UART_Success.
1250 uart_status_t
UART_HAL_SetTxFifoWatermark(uint32_t baseAddr
, uint8_t watermark
);
1253 * @brief Gets the UART transmit FIFO watermark value.
1255 * @param baseAddr UART module base address.
1256 * @return The value currently programmed for the UART transmit watermark.
1258 static inline uint8_t UART_HAL_GetTxFifoWatermark(uint32_t baseAddr
)
1261 return HW_UART_TWFIFO_RD(baseAddr
);
1265 * @brief Gets the UART transmit FIFO data word count (number of words in the transmit FIFO).
1267 * The function UART_HAL_GetTxDatawordCountInFifo excludes any data that may
1268 * be in the UART transmit shift register
1270 * @param baseAddr UART module base address.
1271 * @return The number of data words currently in the UART transmit FIFO.
1273 static inline uint8_t UART_HAL_GetTxDatawordCountInFifo(uint32_t baseAddr
)
1275 /* get the current number of datawords in the FIFO*/
1276 return HW_UART_TCFIFO_RD(baseAddr
);
1280 * @brief Sets the UART receive FIFO watermark value.
1282 * Programming the receive watermark should be done when the receiver is disabled
1283 * and the value must be set less than the size obtained from UART_HAL_GetRxFifoSize and
1284 * greater than zero.
1286 * @param baseAddr UART module base address.
1287 * @param watermark The UART receive watermark value to be programmed.
1288 * @return Error code if receiver is enabled or kStatus_UART_Success.
1290 uart_status_t
UART_HAL_SetRxFifoWatermark(uint32_t baseAddr
, uint8_t watermark
);
1293 * @brief Gets the UART receive FIFO data word count (number of words in the receive FIFO).
1295 * The function UART_HAL_GetRxDatawordCountInFifo excludes any data that may be
1296 * in the receive shift register.
1298 * @param baseAddr UART module base address.
1299 * @return The number of data words currently in the UART receive FIFO.
1301 static inline uint8_t UART_HAL_GetRxDatawordCountInFifo(uint32_t baseAddr
)
1303 /* get the current number of datawords in the FIFO*/
1304 return HW_UART_RCFIFO_RD(baseAddr
);
1308 * @brief Gets the UART receive FIFO watermark value.
1310 * @param baseAddr UART module base address.
1311 * @return The value currently programmed for the UART receive watermark.
1313 static inline uint8_t UART_HAL_GetRxFifoWatermark(uint32_t baseAddr
)
1316 return HW_UART_RWFIFO_RD(baseAddr
);
1319 #endif /* FSL_FEATURE_UART_HAS_FIFO*/
1323 #if defined(__cplusplus)
1329 #endif /* __FSL_UART_HAL_H__*/
1330 /*******************************************************************************
1332 ******************************************************************************/