]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/uart/fsl_uart_hal.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / hal / uart / fsl_uart_hal.h
1 /*
2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
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.
14 *
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.
18 *
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.
29 */
30 #ifndef __FSL_UART_HAL_H__
31 #define __FSL_UART_HAL_H__
32
33 #include <assert.h>
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include "fsl_uart_features.h"
37 #include "fsl_device_registers.h"
38
39 /*!
40 * @addtogroup uart_hal
41 * @{
42 */
43
44 /*! @file*/
45
46 /*******************************************************************************
47 * Definitions
48 ******************************************************************************/
49 #define UART_SHIFT (8U)
50
51 /*! @brief Error codes for the UART driver. */
52 typedef enum _uart_status
53 {
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
68 } uart_status_t;
69
70 /*!
71 * @brief UART number of stop bits.
72 *
73 * These constants define the number of allowable stop bits to configure in a UART baseAddr.
74 */
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;
79
80 /*!
81 * @brief UART parity mode.
82 *
83 * These constants define the UART parity mode options: disabled or enabled of type even or odd.
84 */
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 */
89 } uart_parity_mode_t;
90
91 /*!
92 * @brief UART number of bits in a character.
93 *
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.
97 */
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;
102
103 /*!
104 * @brief UART operation configuration constants.
105 *
106 * This provides constants for UART operational states: "operates normally"
107 * or "stops/ceases operation"
108 */
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;
113
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 ;
119
120 /*!
121 * @brief UART wakeup from standby method constants.
122 *
123 * This provides constants for the two UART wakeup methods: idle-line or address-mark.
124 */
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;
129
130 /*!
131 * @brief UART idle-line detect selection types.
132 *
133 * This provides constants for the UART idle character bit-count start: either after start or
134 * stop bit.
135 */
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;
140
141 /*!
142 * @brief UART break character length settings for transmit/detect.
143 *
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.
146 */
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;
155
156 /*!
157 * @brief UART single-wire mode transmit direction.
158 *
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.
161 */
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;
166
167 /*!
168 * @brief UART infrared transmitter pulse width options.
169 *
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.
172 */
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;
179
180 /*!
181 * @brief UART status flags.
182 *
183 * This provides constants for the UART status flags for use in the UART functions.
184 */
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 */
200 #endif
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 */
206 #endif
207 } uart_status_flag_t;
208
209 /*!
210 * @brief UART interrupt configuration structure, default settings are 0 (disabled).
211 *
212 * This structure contains the settings for all of the UART interrupt configurations.
213 */
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. */
228 #endif
229 } uart_interrupt_t;
230
231 /*******************************************************************************
232 * API
233 ******************************************************************************/
234
235 #if defined(__cplusplus)
236 extern "C" {
237 #endif
238
239 /*!
240 * @name UART Common Configurations
241 * @{
242 */
243
244 /*!
245 * @brief Initializes the UART controller.
246 *
247 * This function initializes the module to a known state.
248 *
249 * @param baseAddr UART module base address.
250 */
251 void UART_HAL_Init(uint32_t baseAddr);
252
253 /*!
254 * @brief Enables the UART transmitter.
255 *
256 * This function allows the user to enable the UART transmitter.
257 *
258 * @param baseAddr UART module base address.
259 */
260 static inline void UART_HAL_EnableTransmitter(uint32_t baseAddr)
261 {
262 BW_UART_C2_TE(baseAddr, 1U);
263 }
264
265 /*!
266 * @brief Disables the UART transmitter.
267 *
268 * This function allows the user to disable the UART transmitter.
269 *
270 * @param baseAddr UART module base address.
271 */
272 static inline void UART_HAL_DisableTransmitter(uint32_t baseAddr)
273 {
274 BW_UART_C2_TE(baseAddr, 0U);
275 }
276
277 /*!
278 * @brief Gets the UART transmitter enabled/disabled configuration setting.
279 *
280 * This function allows the user to get the setting of the UART transmitter.
281 *
282 * @param baseAddr UART module base address.
283 * @return The state of UART transmitter enable(true)/disable(false) setting.
284 */
285 static inline bool UART_HAL_IsTransmitterEnabled(uint32_t baseAddr)
286 {
287 return (bool)BR_UART_C2_TE(baseAddr);
288 }
289
290 /*!
291 * @brief Enables the UART receiver.
292 *
293 * This function allows the user to enable the UART receiver.
294 *
295 * @param baseAddr UART module base address.
296 */
297 static inline void UART_HAL_EnableReceiver(uint32_t baseAddr)
298 {
299 BW_UART_C2_RE(baseAddr, 1U);
300 }
301
302 /*!
303 * @brief Disables the UART receiver.
304 *
305 * This function allows the user to disable the UART receiver.
306 *
307 * @param baseAddr UART module base address.
308 */
309 static inline void UART_HAL_DisableReceiver(uint32_t baseAddr)
310 {
311 BW_UART_C2_RE(baseAddr, 0U);
312 }
313
314 /*!
315 * @brief Gets the UART receiver enabled/disabled configuration setting.
316 *
317 * This function allows the user to get the setting of the UART receiver.
318 *
319 * @param baseAddr UART module base address.
320 * @return The state of UART receiver enable(true)/disable(false) setting.
321 */
322 static inline bool UART_HAL_IsReceiverEnabled(uint32_t baseAddr)
323 {
324 return (bool)BR_UART_C2_RE(baseAddr);
325 }
326
327 /*!
328 * @brief Configures the UART baud rate.
329 *
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.
336 *
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
341 */
342 uart_status_t UART_HAL_SetBaudRate(uint32_t baseAddr, uint32_t sourceClockInHz, uint32_t baudRate);
343
344 /*!
345 * @brief Sets the UART baud rate modulo divisor value.
346 *
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.
350 *
351 * @param baseAddr UART module base address.
352 * @param baudRateDivisor The baud rate modulo division "SBR" value.
353 */
354 void UART_HAL_SetBaudRateDivisor(uint32_t baseAddr, uint16_t baudRateDivisor);
355
356 #if FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
357 /*!
358 * @brief Sets the UART baud rate fine adjust. (Note: Feature available on select
359 * UART baseAddrs used in conjunction with baud rate programming)
360 *
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.
365 *
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.
369 */
370 static inline void UART_HAL_SetBaudRateFineAdjust(uint32_t baseAddr, uint8_t baudFineAdjust)
371 {
372 assert(baudFineAdjust < 0x1F);
373 BW_UART_C4_BRFA(baseAddr, baudFineAdjust);
374 }
375 #endif
376
377 /*!
378 * @brief Configures the number of bits per character in the UART controller.
379 *
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.
382 *
383 * @param baseAddr UART module base address.
384 * @param bitCountPerChar Number of bits per char (8, 9, or 10, depending on the UART baseAddr).
385 */
386 static inline void UART_HAL_SetBitCountPerChar(uint32_t baseAddr,
387 uart_bit_count_per_char_t bitCountPerChar)
388 {
389 /* config 8- (M=0) or 9-bits (M=1) */
390 BW_UART_C1_M(baseAddr, bitCountPerChar);
391 }
392
393 /*!
394 * @brief Configures the parity mode in the UART controller.
395 *
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.
398 *
399 * @param baseAddr UART module base address.
400 * @param parityMode Parity mode setting (enabled, disable, odd, even - see
401 * parity_mode_t struct).
402 */
403 static inline void UART_HAL_SetParityMode(uint32_t baseAddr, uart_parity_mode_t parityMode)
404 {
405 HW_UART_C1_SET(baseAddr, parityMode);
406 }
407
408 #if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
409 /*!
410 * @brief Configures the number of stop bits in the UART controller.
411 *
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.
414 *
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.
418 */
419 static inline void UART_HAL_SetStopBitCount(uint32_t baseAddr, uart_stop_bit_count_t stopBitCount)
420 {
421 BW_UART_BDH_SBNS(baseAddr, stopBitCount);
422 }
423 #endif
424
425 /*!
426 * @brief Configures the transmit and receive inversion control in UART controller.
427 *
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.
430 *
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.
434 */
435 void UART_HAL_SetTxRxInversionCmd(uint32_t baseAddr, bool rxInvertEnable, bool txInvertEnable);
436
437 /*@}*/
438
439 /*!
440 * @name UART Interrupts and DMA
441 * @{
442 */
443
444 /*!
445 * @brief Configures the UART module interrupts to enable/disable various interrupt sources.
446 *
447 * @param baseAddr UART module base address.
448 * @param interrupt UART interrupt configuration data.
449 * @param enable true: enable, false: disable.
450 */
451 void UART_HAL_SetIntMode(uint32_t baseAddr, uart_interrupt_t interrupt, bool enable);
452
453 /*!
454 * @brief Returns whether the UART module interrupts is enabled/disabled.
455 *
456 * @param baseAddr UART module base address.
457 * @param interrupt UART interrupt configuration data.
458 * @return true: enable, false: disable.
459 */
460 bool UART_HAL_GetIntMode(uint32_t baseAddr, uart_interrupt_t interrupt);
461
462 /*!
463 * @brief Enables or disables the tx_data_register_empty_interrupt.
464 *
465 * @param baseAddr UART module base address.
466 * @param enable true: enable, false: disable.
467 */
468 static inline void UART_HAL_SetTxDataRegEmptyIntCmd(uint32_t baseAddr, bool enable)
469 {
470 /* transmit interrupt enable for TDRE (transmit data register empty)*/
471 BW_UART_C2_TIE(baseAddr, (uint8_t)enable);
472 }
473
474 /*!
475 * @brief Gets the configuration of the tx_data_register_empty_interrupt enable setting.
476 *
477 * @param baseAddr UART module base address.
478 * @return setting of the interrupt enable bit.
479 */
480 static inline bool UART_HAL_GetTxDataRegEmptyIntCmd(uint32_t baseAddr)
481 {
482 /* return interrupt enable condition of TIE */
483 return (bool)BR_UART_C2_TIE(baseAddr);
484 }
485
486 /*!
487 * @brief Disables the rx_data_register_full_interrupt.
488 *
489 * @param baseAddr UART module base address.
490 * @param enable true: enable, false: disable.
491 */
492 static inline void UART_HAL_SetRxDataRegFullIntCmd(uint32_t baseAddr, bool enable)
493 {
494 /* receiver interrupt enable for receiver data register full (RDRF)*/
495 BW_UART_C2_RIE(baseAddr, (uint8_t)enable);
496 }
497
498 /*!
499 * @brief Gets the configuration of the rx_data_register_full_interrupt enable setting.
500 *
501 * @param baseAddr UART module base address.
502 * @return Bit setting of the interrupt enable bit.
503 */
504 static inline bool UART_HAL_GetRxDataRegFullIntCmd(uint32_t baseAddr)
505 {
506 /* return interrupt enable condition of RIE */
507 return (bool)BR_UART_C2_RIE(baseAddr);
508 }
509
510 /*!
511 * @brief Configures the UART DMA requests for the Transmitter and Receiver.
512 *
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.
517 *
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).
521 */
522 void UART_HAL_ConfigureDma(uint32_t baseAddr, bool txDmaConfig, bool rxDmaConfig);
523
524 /*!
525 * @brief Gets the UART Transmit DMA request configuration setting.
526 *
527 * This function returns the configuration setting of the Transmit DMA request.
528 *
529 * @param baseAddr UART module base address.
530 * @return Transmit DMA request configuration setting (enable: true /disable: false).
531 */
532 bool UART_HAL_IsTxdmaEnabled(uint32_t baseAddr);
533
534 /*!
535 * @brief Gets the UART Receive DMA request configuration setting.
536 *
537 * This function returns the configuration setting of the Receive DMA request.
538 *
539 * @param baseAddr UART module base address.
540 * @return Receive DMA request configuration setting (enable: true /disable: false).
541 */
542 bool UART_HAL_IsRxdmaEnabled(uint32_t baseAddr);
543
544 /*!
545 * @brief Get UART tx/rx data register address.
546 *
547 * This function is used for DMA transfer.
548 *
549 * @return UART tx/rx data register address.
550 */
551 static inline uint32_t UART_HAL_GetDataRegAddr(uint32_t baseAddr)
552 {
553 return (uint32_t)HW_UART_D_ADDR(baseAddr);
554 }
555
556 /*@}*/
557
558 /*!
559 * @name UART Transfer Functions
560 * @{
561 */
562
563 /*!
564 * @brief This function allows the user to send an 8-bit character from the UART data register.
565 *
566 * @param baseAddr UART module base address.
567 * @param data The data to send of size 8-bit.
568 */
569 void UART_HAL_Putchar(uint32_t baseAddr, uint8_t data);
570
571 /*!
572 * @brief This function allows the user to send a 9-bit character from the UART data register.
573 *
574 * @param baseAddr UART module base address.
575 * @param data The data to send of size 9-bit.
576 */
577 void UART_HAL_Putchar9(uint32_t baseAddr, uint16_t data);
578
579 /*!
580 * @brief This function gets a received 8-bit character from the UART data register.
581 *
582 * @param baseAddr UART module base address.
583 * @param readData The received data read from data register of size 8-bit.
584 */
585 void UART_HAL_Getchar(uint32_t baseAddr, uint8_t *readData);
586
587 /*!
588 * @brief This function gets a received 9-bit character from the UART data register.
589 *
590 * @param baseAddr UART module base address.
591 * @param readData The received data read from data register of size 9-bit.
592 */
593 void UART_HAL_Getchar9(uint32_t baseAddr, uint16_t *readData);
594
595 #if FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS
596 /*!
597 * @brief Configures the UART bit 10 (if enabled) or bit 9 (if disabled) as the parity bit in the
598 * serial transmission.
599 *
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.
602 *
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
606 * transmission.
607 */
608 static inline void UART_HAL_SetBit10AsParitybit(uint32_t baseAddr, bool enable)
609 {
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);
614 }
615
616 /*!
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.
619 *
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.
622 *
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.
626 */
627 static inline bool UART_HAL_IsBit10SetAsParitybit(uint32_t baseAddr)
628 {
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);
632 }
633
634 /*!
635 * @brief Determines whether the UART received data word was received with noise.
636 *
637 * This function returns true if the received data word was received with noise. Otherwise,
638 * it returns false indicating no noise was detected.
639 *
640 * @param baseAddr UART module base address.
641 * @return The status of the NOISY bit in the UART extended data register.
642 */
643 static inline bool UART_HAL_IsCurrentDatawordReceivedWithNoise(uint32_t baseAddr)
644 {
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);
648 }
649
650 /*!
651 * @brief Determines whether the UART received data word was received with a parity error.
652 *
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.
655 *
656 * @param baseAddr UART module base address.
657 * @return The status of the PARITYE (parity error) bit in the UART extended data register.
658 */
659 static inline bool UART_HAL_IsCurrentDatawordReceivedWithParityerror(uint32_t baseAddr)
660 {
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);
664 }
665
666 #endif /* FSL_FEATURE_UART_HAS_EXTENDED_DATA_REGISTER_FLAGS*/
667
668 /*@}*/
669
670 /*!
671 * @name UART Special Feature Configurations
672 * @{
673 */
674
675 /*!
676 * @brief Configures the UART to either operate or cease to operate in WAIT mode.
677 *
678 * The function configures the UART to either operate or cease to operate when WAIT mode is
679 * entered.
680 *
681 * @param baseAddr UART module base address.
682 * @param mode The UART WAIT mode operation - operates or ceases to operate in WAIT mode.
683 */
684 static inline void UART_HAL_SetWaitModeOperation(uint32_t baseAddr, uart_operation_config_t mode)
685 {
686 /*In CPU wait mode: 0 - uart is enabled; 1 - uart is disabled */
687 BW_UART_C1_UARTSWAI(baseAddr, mode);
688 }
689
690 /*!
691 * @brief Determines if the UART operates or ceases to operate in WAIT mode.
692 *
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.
695 *
696 * @param baseAddr UART module base address.
697 * @return The UART WAIT mode operation configuration, returns either kUartOperates or KUartStops.
698 */
699 static inline uart_operation_config_t UART_HAL_GetWaitModeOperation(uint32_t baseAddr)
700 {
701 /*In CPU wait mode: 0 - uart is enabled; 1 - uart is disabled */
702 return (uart_operation_config_t)BR_UART_C1_UARTSWAI(baseAddr);
703 }
704
705 /*!
706 * @brief Configures the UART loopback operation.
707 *
708 * This function enables or disables the UART loopback operation.
709 *
710 * @param baseAddr UART module base address.
711 * @param enable The UART loopback mode configuration, either disabled (false) or enabled (true).
712 */
713 static inline void UART_HAL_SetLoopCmd(uint32_t baseAddr, bool enable)
714 {
715 BW_UART_C1_LOOPS(baseAddr, enable);
716 }
717
718 /*!
719 * @brief Configures the UART single-wire operation.
720 *
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.
725 *
726 * @param baseAddr UART module base address.
727 * @param enable The UART single-wire mode configuration, either disabled (false) or enabled (true).
728 */
729 static inline void UART_HAL_SetReceiverSource(uint32_t baseAddr, uart_receiver_source_t source)
730 {
731 BW_UART_C1_RSRC(baseAddr, source);
732 }
733 /*!
734 * @brief Configures the UART transmit direction while in single-wire mode.
735 *
736 * This function configures the transmitter direction when the UART is configured for single-wire
737 * operation.
738 *
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.
743 */
744 static inline void UART_HAL_SetTransmitterDir(uint32_t baseAddr, uart_singlewire_txdir_t direction)
745 {
746 /* configure UART transmit direction (input or output) when in single-wire mode
747 * it is assumed UART is in single-wire mode
748 */
749 BW_UART_C3_TXDIR(baseAddr, direction);
750 }
751
752 /*!
753 * @brief Places the UART receiver in standby mode.
754 *
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
760 * not idle.
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.
764 *
765 * @param baseAddr UART module base address.
766 * @return Error code or kStatus_UART_Success.
767 */
768 uart_status_t UART_HAL_PutReceiverInStandbyMode(uint32_t baseAddr);
769
770 /*!
771 * @brief Places the UART receiver in normal mode (disable standby mode operation).
772 *
773 * This function, when called, places the UART receiver into normal mode and out of
774 * standby mode.
775 *
776 * @param baseAddr UART module base address.
777 */
778 static inline void UART_HAL_PutReceiverInNormalMode(uint32_t baseAddr)
779 {
780 /* clear the RWU bit to place receiver into normal mode (disable standby mode)*/
781 HW_UART_C2_CLR(baseAddr, BM_UART_C2_RWU);
782 }
783
784 /*!
785 * @brief Determines if the UART receiver is currently in standby mode.
786 *
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
789 * is in normal mode.
790 *
791 * @param baseAddr UART module base address.
792 * @return The UART receiver is in normal mode (false) or standby mode (true).
793 */
794 static inline bool UART_HAL_IsReceiverInStandby(uint32_t baseAddr)
795 {
796 /* return the RWU bit setting (0 - normal more, 1 - standby)*/
797 return BR_UART_C2_RWU(baseAddr);
798 }
799
800 /*!
801 * @brief Selects the UART receiver wakeup method (idle-line or address-mark) from standby mode.
802 *
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.
805 *
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.
809 */
810 static inline void UART_HAL_SetReceiverWakeupMethod(uint32_t baseAddr, uart_wakeup_method_t method)
811 {
812 /* configure the WAKE bit for idle line wake or address mark wake */
813 BW_UART_C1_WAKE(baseAddr, method);
814 }
815
816 /*!
817 * @brief Gets the UART receiver wakeup method (idle-line or address-mark) from standby mode.
818 *
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.
821 *
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).
825 */
826 static inline uart_wakeup_method_t UART_HAL_GetReceiverWakeupMethod(uint32_t baseAddr)
827 {
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);
830 }
831
832 /*!
833 * @brief Configures the operation options of the UART idle line detect.
834 *
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.
839 *
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
845 */
846 void UART_HAL_ConfigIdleLineDetect(uint32_t baseAddr, uint8_t idleLine, uint8_t rxWakeIdleDetect);
847
848 /*!
849 * @brief Configures the UART break character transmit length.
850 *
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.
855 *
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.
859 */
860 static inline void UART_HAL_SetBreakCharTransmitLength(uint32_t baseAddr,
861 uart_break_char_length_t length)
862 {
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);
868 }
869
870 /*!
871 * @brief Configures the UART break character detect length.
872 *
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.
875 *
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.
879 */
880 static inline void UART_HAL_SetBreakCharDetectLength(uint32_t baseAddr, uart_break_char_length_t length)
881 {
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);
887 }
888
889 /*!
890 * @brief Configures the UART transmit send break character operation.
891 *
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
895 * function.
896 *
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.
901 */
902 static inline void UART_HAL_SetBreakCharCmd(uint32_t baseAddr, bool enable)
903 {
904 BW_UART_C2_SBK(baseAddr, enable);
905 }
906
907 /*!
908 * @brief Configures the UART match address mode control operation. (Note: Feature available on
909 * select UART baseAddrs)
910 *
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.
914 *
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.
920 */
921 void UART_HAL_SetMatchAddress(uint32_t baseAddr, bool matchAddrMode1, bool matchAddrMode2,
922 uint8_t matchAddrValue1, uint8_t matchAddrValue2);
923
924 #if FSL_FEATURE_UART_HAS_BIT_ORDER_SELECT
925 /*!
926 * @brief Configures the UART to send data MSB first
927 * (Note: Feature available on select UART baseAddrs)
928 *
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.
933 *
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.
937 */
938 static inline void UART_HAL_SetSendMsbFirstCmd(uint32_t baseAddr, bool enable)
939 {
940 BW_UART_S2_MSBF(baseAddr, enable);
941 }
942 #endif
943
944 #if FSL_FEATURE_UART_HAS_MODEM_SUPPORT
945 /*!
946 * @brief Enables the UART receiver request-to-send functionality.
947 *
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.
954 *
955 * @param baseAddr UART module base address.
956 * @param enable Enable or disable receiver rts.
957 */
958 static inline void UART_HAL_SetReceiverRtsCmd(uint32_t baseAddr, bool enable)
959 {
960 /* Set RXRTSE */
961 BW_UART_MODEM_RXRTSE(baseAddr, enable);
962 }
963
964 /*!
965 * @brief Enables the UART transmitter request-to-send functionality.
966 *
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
972 * the last stop bit.
973 *
974 * @param baseAddr UART module base address.
975 * @param enable Enable or disable transmitter RTS.
976 */
977 static inline void UART_HAL_SetTransmitterRtsCmd(uint32_t baseAddr, bool enable)
978 {
979 /* Set TXRTSE */
980 BW_UART_MODEM_TXRTSE(baseAddr, enable);
981 }
982
983 /*!
984 * @brief Configures the UART transmitter RTS polarity.
985 *
986 * This function allows the user configure the transmitter RTS polarity to be either active low
987 * or active high.
988 *
989 * @param baseAddr UART module base address.
990 * @param polarity The UART transmitter RTS polarity setting (false - active low,
991 * true - active high).
992 */
993 static inline void UART_HAL_SetTransmitterRtsPolarityMode(uint32_t baseAddr, bool polarity)
994 {
995 /* Configure the transmitter rts polarity: 0=active low, 1=active high */
996 BW_UART_MODEM_TXRTSPOL(baseAddr, polarity);
997 }
998
999 /*!
1000 * @brief Enables the UART transmitter clear-to-send functionality.
1001 *
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.
1007 *
1008 * @param baseAddr UART module base address.
1009 * @param enable Enable or disable transmitter CTS.
1010 */
1011 static inline void UART_HAL_SetTransmitterCtsCmd(uint32_t baseAddr, bool enable)
1012 {
1013 /* Set TXCTSE */
1014 BW_UART_MODEM_TXCTSE(baseAddr, enable);
1015 }
1016
1017 #endif /* FSL_FEATURE_UART_HAS_MODEM_SUPPORT*/
1018
1019 #if FSL_FEATURE_UART_HAS_IR_SUPPORT
1020 /*!
1021 * @brief Configures the UART infrared operation.
1022 *
1023 * The function allows the user to enable or disable the UART infrared (IR) operation
1024 * and to configure the IR pulse width.
1025 *
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.
1029 */
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*/
1033
1034 /*@}*/
1035
1036 /*!
1037 * @name UART Status Flags
1038 * @{
1039 */
1040
1041 /*!
1042 * @brief Gets all UART status flag states.
1043 *
1044 * @param baseAddr UART module base address.
1045 * @param statusFlag Status flag name.
1046 */
1047 bool UART_HAL_GetStatusFlag(uint32_t baseAddr, uart_status_flag_t statusFlag);
1048
1049 /*!
1050 * @brief Gets the UART Transmit data register empty flag.
1051 *
1052 * This function returns the state of the UART Transmit data register empty flag.
1053 *
1054 * @param baseAddr UART module base address.
1055 * @return The status of Transmit data register empty flag, which is set when transmit buffer
1056 * is empty.
1057 */
1058 static inline bool UART_HAL_IsTxDataRegEmpty(uint32_t baseAddr)
1059 {
1060 /* return status condition of TDRE flag */
1061 return BR_UART_S1_TDRE(baseAddr);
1062 }
1063
1064 /*!
1065 * @brief Gets the UART Transmission complete flag.
1066 *
1067 * This function returns the state of the UART Transmission complete flag.
1068 *
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).
1072 */
1073 static inline bool UART_HAL_IsTxComplete(uint32_t baseAddr)
1074 {
1075 /* return status condition of TC flag */
1076 return BR_UART_S1_TC(baseAddr);
1077 }
1078
1079 /*!
1080 * @brief Gets the UART Receive data register full flag.
1081 *
1082 * This function returns the state of the UART Receive data register full flag.
1083 *
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
1086 * is full.
1087 */
1088 static inline bool UART_HAL_IsRxDataRegFull(uint32_t baseAddr)
1089 {
1090 /* return status condition of RDRF flag */
1091 return BR_UART_S1_RDRF(baseAddr);
1092 }
1093
1094 /*!
1095 * @brief Clears an individual and specific UART status flag.
1096 *
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.
1099 *
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.
1103 */
1104 uart_status_t UART_HAL_ClearStatusFlag(uint32_t baseAddr, uart_status_flag_t statusFlag);
1105
1106 /*!
1107 * @brief Clears all UART status flags.
1108 *
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.
1111 *
1112 * @param baseAddr UART module base address.
1113 */
1114 void UART_HAL_ClearAllNonAutoclearStatusFlags(uint32_t baseAddr);
1115
1116 /*@}*/
1117
1118 /*!
1119 * @name UART FIFO Configurations
1120 * @{
1121 */
1122
1123 #if FSL_FEATURE_UART_HAS_FIFO
1124 /*!
1125 * @brief Enables or disable the UART transmit FIFO.
1126 *
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.
1131 *
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.
1136 */
1137 uart_status_t UART_HAL_SetTxFifoCmd(uint32_t baseAddr, bool enable);
1138
1139 /*!
1140 * @brief Enables or disable the UART receive FIFO.
1141 *
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.
1146 *
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.
1151 */
1152 uart_status_t UART_HAL_SetRxFifoCmd(uint32_t baseAddr, bool enable);
1153
1154 /*!
1155 * @brief Gets the size of the UART transmit FIFO.
1156 *
1157 * This function returns the size (number of entries) supported in the UART transmit FIFO for
1158 * a particular module baseAddr.
1159 *
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
1164 */
1165 static inline uint8_t UART_HAL_GetTxFifoSize(uint32_t baseAddr)
1166 {
1167 return BR_UART_PFIFO_TXFIFOSIZE(baseAddr);
1168 }
1169
1170 /*!
1171 * @brief Gets the size of the UART receive FIFO.
1172 *
1173 * This function returns the size (number of entries) supported in the UART receive FIFO for
1174 * a particular module baseAddr.
1175 *
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
1180 */
1181 static inline uint8_t UART_HAL_GetRxFifoSize(uint32_t baseAddr)
1182 {
1183 return BR_UART_PFIFO_RXFIFOSIZE(baseAddr);
1184 }
1185
1186 /*!
1187 * @brief Flushes the UART transmit FIFO.
1188 *
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.
1192 *
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.
1196 */
1197 uart_status_t UART_HAL_FlushTxFifo(uint32_t baseAddr);
1198
1199 /*!
1200 * @brief Flushes the UART receive FIFO.
1201 *
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.
1205 *
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.
1209 */
1210 uart_status_t UART_HAL_FlushRxFifo(uint32_t baseAddr);
1211
1212 /*!
1213 * @brief Gets the UART transmit FIFO empty status state.
1214 *
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.
1217 *
1218 * @param baseAddr UART module base address.
1219 * @return The UART transmit FIFO empty status: true=empty; false=not-empty.
1220 */
1221 static inline bool UART_HAL_IsTxFifoEmpty(uint32_t baseAddr)
1222 {
1223 return BR_UART_SFIFO_TXEMPT(baseAddr);
1224 }
1225
1226 /*!
1227 * @brief Gets the UART receive FIFO empty status state.
1228 *
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.
1231 *
1232 * @param baseAddr UART module base address.
1233 * @return The UART receive FIFO empty status: true=empty; false=not-empty.
1234 */
1235 static inline bool UART_HAL_IsRxFifoEmpty(uint32_t baseAddr)
1236 {
1237 return BR_UART_SFIFO_RXEMPT(baseAddr);
1238 }
1239
1240 /*!
1241 * @brief Sets the UART transmit FIFO watermark value.
1242 *
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.
1245 *
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.
1249 */
1250 uart_status_t UART_HAL_SetTxFifoWatermark(uint32_t baseAddr, uint8_t watermark);
1251
1252 /*!
1253 * @brief Gets the UART transmit FIFO watermark value.
1254 *
1255 * @param baseAddr UART module base address.
1256 * @return The value currently programmed for the UART transmit watermark.
1257 */
1258 static inline uint8_t UART_HAL_GetTxFifoWatermark(uint32_t baseAddr)
1259 {
1260 /* get watermark*/
1261 return HW_UART_TWFIFO_RD(baseAddr);
1262 }
1263
1264 /*!
1265 * @brief Gets the UART transmit FIFO data word count (number of words in the transmit FIFO).
1266 *
1267 * The function UART_HAL_GetTxDatawordCountInFifo excludes any data that may
1268 * be in the UART transmit shift register
1269 *
1270 * @param baseAddr UART module base address.
1271 * @return The number of data words currently in the UART transmit FIFO.
1272 */
1273 static inline uint8_t UART_HAL_GetTxDatawordCountInFifo(uint32_t baseAddr)
1274 {
1275 /* get the current number of datawords in the FIFO*/
1276 return HW_UART_TCFIFO_RD(baseAddr);
1277 }
1278
1279 /*!
1280 * @brief Sets the UART receive FIFO watermark value.
1281 *
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.
1285 *
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.
1289 */
1290 uart_status_t UART_HAL_SetRxFifoWatermark(uint32_t baseAddr, uint8_t watermark);
1291
1292 /*!
1293 * @brief Gets the UART receive FIFO data word count (number of words in the receive FIFO).
1294 *
1295 * The function UART_HAL_GetRxDatawordCountInFifo excludes any data that may be
1296 * in the receive shift register.
1297 *
1298 * @param baseAddr UART module base address.
1299 * @return The number of data words currently in the UART receive FIFO.
1300 */
1301 static inline uint8_t UART_HAL_GetRxDatawordCountInFifo(uint32_t baseAddr)
1302 {
1303 /* get the current number of datawords in the FIFO*/
1304 return HW_UART_RCFIFO_RD(baseAddr);
1305 }
1306
1307 /*!
1308 * @brief Gets the UART receive FIFO watermark value.
1309 *
1310 * @param baseAddr UART module base address.
1311 * @return The value currently programmed for the UART receive watermark.
1312 */
1313 static inline uint8_t UART_HAL_GetRxFifoWatermark(uint32_t baseAddr)
1314 {
1315 /* get watermark*/
1316 return HW_UART_RWFIFO_RD(baseAddr);
1317 }
1318
1319 #endif /* FSL_FEATURE_UART_HAS_FIFO*/
1320
1321 /*@}*/
1322
1323 #if defined(__cplusplus)
1324 }
1325 #endif
1326
1327 /*! @}*/
1328
1329 #endif /* __FSL_UART_HAL_H__*/
1330 /*******************************************************************************
1331 * EOF
1332 ******************************************************************************/
1333
Imprint / Impressum