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.
31 #ifndef __FSL_LPUART_HAL_H__
32 #define __FSL_LPUART_HAL_H__
37 #include "fsl_lpuart_features.h"
38 #include "fsl_device_registers.h"
40 #ifndef MBED_NO_LPUART
43 * @addtogroup lpuart_hal
47 /*******************************************************************************
49 ******************************************************************************/
50 #define LPUART_SHIFT (16U)
51 #define LPUART_BAUD_REG_ID (0U)
52 #define LPUART_STAT_REG_ID (1U)
53 #define LPUART_CTRL_REG_ID (2U)
54 #define LPUART_DATA_REG_ID (3U)
55 #define LPUART_MATCH_REG_ID (4U)
56 #define LPUART_MODIR_REG_ID (5U)
58 /*! @brief Error codes for the LPUART driver.*/
59 typedef enum _lpuart_status
61 kStatus_LPUART_Success,
62 kStatus_LPUART_BaudRateCalculationError , /*!< LPUART Baud Rate calculation error out of range. */
63 kStatus_LPUART_BaudRatePercentDiffExceeded, /*!< LPUART Baud Rate exceeds percentage difference*/
64 kStatus_LPUART_BitCountNotSupported, /*!< LPUART bit count configuration not supported.*/
65 kStatus_LPUART_StopBitCountNotSupported, /*!< LPUART stop bit count configuration not supported.*/
66 kStatus_LPUART_RxStandbyModeError, /*!< LPUART unable to place receiver in standby mode.*/
67 kStatus_LPUART_ClearStatusFlagError, /*!< LPUART clear status flag error.*/
68 kStatus_LPUART_MSBFirstNotSupported, /*!< LPUART MSB first feature not supported.*/
69 kStatus_LPUART_Resync_NotSupported, /*!< LPUART resync disable operation not supported.*/
70 kStatus_LPUART_TxNotDisabled, /*!< LPUART Transmitter not disabled before enabling feature*/
71 kStatus_LPUART_RxNotDisabled, /*!< LPUART Receiver not disabled before enabling feature*/
72 kStatus_LPUART_TxOrRxNotDisabled, /*!< LPUART Transmitter or Receiver not disabled*/
73 kStatus_LPUART_TxBusy, /*!< LPUART transmit still in progress.*/
74 kStatus_LPUART_RxBusy, /*!< LPUART receive still in progress.*/
75 kStatus_LPUART_NoTransmitInProgress, /*!< LPUART no transmit in progress.*/
76 kStatus_LPUART_NoReceiveInProgress, /*!< LPUART no receive in progress.*/
77 kStatus_LPUART_InvalidInstanceNumber, /*!< Invalid LPUART base address */
78 kStatus_LPUART_InvalidBitSetting, /*!< Invalid setting for desired LPUART register bit field */
79 kStatus_LPUART_OverSamplingNotSupported, /*!< LPUART oversampling not supported.*/
80 kStatus_LPUART_BothEdgeNotSupported, /*!< LPUART both edge sampling not supported. */
81 kStatus_LPUART_Timeout, /*!< LPUART transfer timed out.*/
82 kStatus_LPUART_Initialized,
85 /*! @brief LPUART number of stop bits*/
86 typedef enum _lpuart_stop_bit_count {
87 kLpuartOneStopBit = 0, /*!< one stop bit*/
88 kLpuartTwoStopBit = 1, /*!< two stop bits*/
89 } lpuart_stop_bit_count_t;
91 /*! @brief LPUART parity mode*/
92 typedef enum _lpuart_parity_mode {
93 kLpuartParityDisabled = 0x0, /*!< parity disabled*/
94 kLpuartParityEven = 0x2, /*!< parity enabled, type even, bit setting: PE|PT = 10*/
95 kLpuartParityOdd = 0x3, /*!< parity enabled, type odd, bit setting: PE|PT = 11*/
96 } lpuart_parity_mode_t;
98 /*! @brief LPUART number of bits in a character*/
99 typedef enum _lpuart_bit_count_per_char {
100 kLpuart8BitsPerChar = 0, /*!< 8-bit data characters*/
101 kLpuart9BitsPerChar = 1, /*!< 9-bit data characters*/
102 kLpuart10BitsPerChar = 2, /*!< 10-bit data characters*/
103 } lpuart_bit_count_per_char_t;
105 /*! @brief LPUART operation configuration constants*/
106 typedef enum _lpuart_operation_config {
107 kLpuartOperates = 0,/*!< LPUART continues to operate normally.*/
108 kLpuartStops = 1, /*!< LPUART stops operation. */
109 } lpuart_operation_config_t;
111 /*! @brief LPUART wakeup from standby method constants*/
112 typedef enum _lpuart_wakeup_method {
113 kLpuartIdleLineWake = 0, /*!< Idle-line wakes the LPUART receiver from standby. */
114 kLpuartAddrMarkWake = 1, /*!< Addr-mark wakes LPUART receiver from standby.*/
115 } lpuart_wakeup_method_t;
117 /*! @brief LPUART idle line detect selection types*/
118 typedef enum _lpuart_idle_line_select {
119 kLpuartIdleLineAfterStartBit = 0, /*!< LPUART idle character bit count start after start bit */
120 kLpuartIdleLineAfterStopBit = 1, /*!< LPUART idle character bit count start after stop bit */
121 } lpuart_idle_line_select_t;
124 * @brief LPUART break character length settings for transmit/detect.
126 * The actual maximum bit times may vary depending on the LPUART instance.
128 typedef enum _lpuart_break_char_length {
129 kLpuartBreakChar10BitMinimum = 0, /*!< LPUART break char length 10 bit times (if M = 0, SBNS = 0)
130 or 11 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 12 (if M = 1,
131 SBNS = 1 or M10 = 1, SNBS = 0) or 13 (if M10 = 1, SNBS = 1 .*/
132 kLpuartBreakChar13BitMinimum = 1, /*!< LPUART break char length 13 bit times (if M = 0, SBNS = 0)
133 or 14 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 15 (if M = 1,
134 SBNS = 1 or M10 = 1, SNBS = 0) or 16 (if M10 = 1, SNBS = 1)*/
135 } lpuart_break_char_length_t;
137 /*! @brief LPUART single-wire mode TX direction*/
138 typedef enum _lpuart_singlewire_txdir {
139 kLpuartSinglewireTxdirIn = 0, /*!< LPUART Single Wire mode TXDIR input*/
140 kLpuartSinglewireTxdirOut = 1, /*!< LPUART Single Wire mode TXDIR output*/
141 } lpuart_singlewire_txdir_t;
143 /*! @brief LPUART Configures the match addressing mode used.*/
144 typedef enum _lpuart_match_config {
145 kLpuartAddressMatchWakeup = 0, /*!< LPUART Address Match Wakeup*/
146 kLpuartIdleMatchWakeup = 1, /*!< LPUART Idle Match Wakeup*/
147 kLpuartMatchOnAndMatchOff = 2, /*!< LPUART Match On and Match Off*/
148 kLpuartEnablesRwuOnDataMatch = 3, /*!< LPUART Enables RWU on Data Match and Match On/Off for transmitter CTS input*/
149 } lpuart_match_config_t;
151 /*! @brief LPUART infra-red transmitter pulse width options*/
152 typedef enum _lpuart_ir_tx_pulsewidth {
153 kLpuartIrThreeSixteenthsWidth = 0, /*!< 3/16 pulse*/
154 kLpuartIrOneSixteenthWidth = 1, /*!< 1/16 pulse*/
155 kLpuartIrOneThirtysecondsWidth = 2, /*!< 1/32 pulse*/
156 kLpuartIrOneFourthWidth = 3, /*!< 1/4 pulse*/
157 } lpuart_ir_tx_pulsewidth_t;
159 /*! @brief LPUART Configures the number of idle characters that must be received before the IDLE flag is set. */
160 typedef enum _lpuart_idle_config {
161 kLpuart_1_IdleChar = 0, /*!< 1 idle character*/
162 kLpuart_2_IdleChar = 1, /*!< 2 idle character*/
163 kLpuart_4_IdleChar = 2, /*!< 4 idle character*/
164 kLpuart_8_IdleChar = 3, /*!< 8 idle character*/
165 kLpuart_16_IdleChar = 4, /*!< 16 idle character*/
166 kLpuart_32_IdleChar = 5, /*!< 32 idle character*/
167 kLpuart_64_IdleChar = 6, /*!< 64 idle character*/
168 kLpuart_128_IdleChar = 7, /*!< 128 idle character*/
169 } lpuart_idle_config_t;
171 /*! @brief LPUART Transmits the CTS Configuration. Configures the source of the CTS input.*/
172 typedef enum _lpuart_cts_source {
173 kLpuartCtsSourcePin = 0, /*!< LPUART CTS input is the LPUART_CTS pin.*/
174 kLpuartCtsSourceInvertedReceiverMatch = 1, /*!< LPUART CTS input is the inverted Receiver Match result.*/
175 } lpuart_cts_source_t;
177 /*! @brief LPUART Transmits CTS Source.Configures if the CTS state is checked at the start of each character or only when the transmitter is idle.*/
178 typedef enum _lpuart_cts_config {
179 kLpuartCtsSampledOnEachCharacter = 0, /*!< LPUART CTS input is sampled at the start of each character.*/
180 kLpuartCtsSampledOnIdle = 1, /*!< LPUART CTS input is sampled when the transmitter is idle.*/
181 } lpuart_cts_config_t;
183 /*! @brief Structure for idle line configuration settings*/
184 typedef struct LpuartIdleLineConfig {
185 unsigned idleLineType : 1; /*!< ILT, Idle bit count start: 0 - after start bit (default),*/
186 /*! 1 - after stop bit */
187 unsigned rxWakeIdleDetect : 1; /*!< RWUID, Receiver Wake Up Idle Detect. IDLE status bit */
188 /*! operation during receive standbyControls whether idle */
189 /*! character that wakes up receiver will also set */
190 /*! IDLE status bit 0 - IDLE status bit doesn't */
191 /*! get set (default), 1 - IDLE status bit gets set*/
192 } lpuart_idle_line_config_t;
195 * @brief LPUART status flags.
197 * This provides constants for the LPUART status flags for use in the UART functions.
199 typedef enum _lpuart_status_flag {
200 kLpuartTxDataRegEmpty = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_TDRE, /*!< Tx data register empty flag, sets when Tx buffer is empty */
201 kLpuartTxComplete = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_TC, /*!< Transmission complete flag, sets when transmission activity complete */
202 kLpuartRxDataRegFull = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_RDRF, /*!< Rx data register full flag, sets when the receive data buffer is full */
203 kLpuartIdleLineDetect = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_IDLE, /*!< Idle line detect flag, sets when idle line detected */
204 kLpuartRxOverrun = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_OR, /*!< Rxr Overrun, sets when new data is received before data is read from receive register */
205 kLpuartNoiseDetect = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_NF, /*!< Rxr takes 3 samples of each received bit. If any of these samples differ, noise flag sets */
206 kLpuartFrameErr = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_FE, /*!< Frame error flag, sets if logic 0 was detected where stop bit expected */
207 kLpuartParityErr = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_PF, /*!< If parity enabled, sets upon parity error detection */
208 kLpuartLineBreakDetect = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_LBKDE, /*!< LIN break detect interrupt flag, sets when LIN break char detected and LIN circuit enabled */
209 kLpuartRxActiveEdgeDetect = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_RXEDGIF, /*!< Rx pin active edge interrupt flag, sets when active edge detected */
210 kLpuartRxActive = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_RAF, /*!< Receiver Active Flag (RAF), sets at beginning of valid start bit */
211 #if FSL_FEATURE_LPUART_HAS_EXTENDED_DATA_REGISTER_FLAGS
212 kLpuartNoiseInCurrentWord = LPUART_DATA_REG_ID << LPUART_SHIFT | BP_LPUART_DATA_NOISY, /*!< NOISY bit, sets if noise detected in current data word */
213 kLpuartParityErrInCurrentWord = LPUART_DATA_REG_ID << LPUART_SHIFT | BP_LPUART_DATA_PARITYE, /*!< PARITYE bit, sets if noise detected in current data word */
215 #if FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
216 kLpuartMatchAddrOne = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_MA1F, /*!< Address one match flag */
217 kLpuartMatchAddrTwo = LPUART_STAT_REG_ID << LPUART_SHIFT | BP_LPUART_STAT_MA2F, /*!< Address two match flag */
219 } lpuart_status_flag_t;
221 /*! @brief LPUART interrupt configuration structure, default settings are 0 (disabled)*/
222 typedef enum _lpuart_interrupt {
223 kLpuartIntLinBreakDetect = LPUART_BAUD_REG_ID << LPUART_SHIFT | BP_LPUART_BAUD_LBKDIE, /*!< LIN break detect. */
224 kLpuartIntRxActiveEdge = LPUART_BAUD_REG_ID << LPUART_SHIFT | BP_LPUART_BAUD_RXEDGIE, /*!< RX Active Edge. */
225 kLpuartIntTxDataRegEmpty = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_TIE, /*!< Transmit data register empty. */
226 kLpuartIntTxComplete = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_TCIE, /*!< Transmission complete. */
227 kLpuartIntRxDataRegFull = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_RIE, /*!< Receiver data register full. */
228 kLpuartIntIdleLine = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_ILIE, /*!< Idle line. */
229 kLpuartIntRxOverrun = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_ORIE, /*!< Receiver Overrun. */
230 kLpuartIntNoiseErrFlag = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_NEIE, /*!< Noise error flag. */
231 kLpuartIntFrameErrFlag = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_FEIE, /*!< Framing error flag. */
232 kLpuartIntParityErrFlag = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_PEIE, /*!< Parity error flag. */
233 #if FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
234 kLpuartIntMatchAddrOne = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_MA1IE, /*!< Match address one flag. */
235 kLpuartIntMatchAddrTwo = LPUART_CTRL_REG_ID << LPUART_SHIFT | BP_LPUART_CTRL_MA2IE, /*!< Match address two flag. */
237 } lpuart_interrupt_t;
240 /*******************************************************************************
242 ******************************************************************************/
244 #if defined(__cplusplus)
249 * @name LPUART Common Configurations
254 * @brief Initializes the LPUART controller to known state.
256 * @param baseAddr LPUART base address.
258 void LPUART_HAL_Init(uint32_t baseAddr);
261 * @brief Enables the LPUART transmitter.
263 * @param baseAddr LPUART base address.
265 void LPUART_HAL_EnableTransmitter(uint32_t baseAddr);
268 * @brief Disables the LPUART transmitter.
270 * @param baseAddr LPUART base address
272 static inline void LPUART_HAL_DisableTransmitter(uint32_t baseAddr)
274 BW_LPUART_CTRL_TE(baseAddr, 0);
278 * @brief Gets the LPUART transmitter enabled/disabled configuration.
280 * @param baseAddr LPUART base address
281 * @return State of LPUART transmitter enable(1)/disable(0)
283 static inline bool LPUART_HAL_IsTransmitterEnabled(uint32_t baseAddr)
285 return BR_LPUART_CTRL_TE(baseAddr);
289 * @brief Enables the LPUART receiver.
291 * @param baseAddr LPUART base address
293 static inline void LPUART_HAL_EnableReceiver(uint32_t baseAddr)
295 BW_LPUART_CTRL_RE(baseAddr, 1);
299 * @brief Disables the LPUART receiver.
301 * @param baseAddr LPUART base address
303 static inline void LPUART_HAL_DisableReceiver(uint32_t baseAddr)
305 BW_LPUART_CTRL_RE(baseAddr, 0);
309 * @brief Gets the LPUART receiver enabled/disabled configuration.
311 * @param baseAddr LPUART base address
312 * @return State of LPUART receiver enable(1)/disable(0)
314 static inline bool LPUART_HAL_IsReceiverEnabled(uint32_t baseAddr)
316 return BR_LPUART_CTRL_RE(baseAddr);
320 * @brief Configures the LPUART baud rate.
322 * In some LPUART instances the user must disable the transmitter/receiver
323 * before calling this function.
324 * Generally, this may be applied to all LPUARTs to ensure safe operation.
326 * @param baseAddr LPUART base address.
327 * @param sourceClockInHz LPUART source input clock in Hz.
328 * @param desiredBaudRate LPUART desired baud rate.
329 * @return An error code or kStatus_Success
331 lpuart_status_t LPUART_HAL_SetBaudRate(uint32_t baseAddr, uint32_t sourceClockInHz,
332 uint32_t desiredBaudRate);
335 * @brief Sets the LPUART baud rate modulo divisor.
337 * @param baseAddr LPUART base address.
338 * @param baudRateDivisor The baud rate modulo division "SBR"
340 static inline void LPUART_HAL_SetBaudRateDivisor(uint32_t baseAddr, uint32_t baudRateDivisor)
342 assert ((baudRateDivisor < 0x1FFF) && (baudRateDivisor > 1));
343 BW_LPUART_BAUD_SBR(baseAddr, baudRateDivisor);
346 #if FSL_FEATURE_LPUART_HAS_BAUD_RATE_OVER_SAMPLING_SUPPORT
348 * @brief Sets the LPUART baud rate oversampling ratio (Note: Feature available on select
349 * LPUART instances used together with baud rate programming)
350 * The oversampling ratio should be set between 4x (00011) and 32x (11111). Writing
351 * an invalid oversampling ratio results in an error and is set to a default
352 * 16x (01111) oversampling ratio.
353 * IDisable the transmitter/receiver before calling
356 * @param baseAddr LPUART base address.
357 * @param overSamplingRatio The oversampling ratio "OSR"
359 static inline void LPUART_HAL_SetOversamplingRatio(uint32_t baseAddr, uint32_t overSamplingRatio)
361 assert(overSamplingRatio < 0x1F);
362 BW_LPUART_BAUD_OSR(baseAddr, overSamplingRatio);
366 #if FSL_FEATURE_LPUART_HAS_BOTH_EDGE_SAMPLING_SUPPORT
368 * @brief Configures the LPUART baud rate both edge sampling (Note: Feature available on select
369 * LPUART instances used with baud rate programming)
370 * When enabled, the received data is sampled on both edges of the baud rate clock.
371 * This must be set when the oversampling ratio is between 4x and 7x.
372 * This function should only be called when the receiver is disabled.
374 * @param baseAddr LPUART base address.
375 * @param enableBothEdgeSampling Enable (1) or Disable (0) Both Edge Sampling
376 * @return An error code or kStatus_Success
378 static inline void LPUART_HAL_SetBothEdgeSamplingCmd(uint32_t baseAddr, bool enableBothEdgeSampling)
380 BW_LPUART_BAUD_BOTHEDGE(baseAddr, enableBothEdgeSampling);
385 * @brief Configures the number of bits per character in the LPUART controller.
387 * In some LPUART instances, the user should disable the transmitter/receiver
388 * before calling this function.
389 * Generally, this may be applied to all LPUARTs to ensure safe operation.
391 * @param baseAddr LPUART base address.
392 * @param bitCountPerChar Number of bits per char (8, 9, or
393 * 10, depending on the LPUART instance)
395 void LPUART_HAL_SetBitCountPerChar(uint32_t baseAddr, lpuart_bit_count_per_char_t bitCountPerChar);
399 * @brief Configures parity mode in the LPUART controller.
401 * In some LPUART instances, the user should disable the transmitter/receiver
402 * before calling this function.
403 * Generally, this may be applied to all LPUARTs to ensure safe operation.
405 * @param baseAddr LPUART base address.
406 * @param parityModeType Parity mode (enabled, disable, odd, even - see parity_mode_t struct)
408 void LPUART_HAL_SetParityMode(uint32_t baseAddr, lpuart_parity_mode_t parityModeType);
411 * @brief Configures the number of stop bits in the LPUART controller.
412 * In some LPUART instances, the user should disable the transmitter/receiver
413 * before calling this function.
414 * Generally, this may be applied to all LPUARTs to ensure safe operation.
416 * @param baseAddr LPUART base address.
417 * @param stopBitCount Number of stop bits (1 or 2 - see lpuart_stop_bit_count_t struct)
418 * @return An error code (an unsupported setting in some LPUARTs) or kStatus_Success
420 static inline void LPUART_HAL_SetStopBitCount(uint32_t baseAddr, lpuart_stop_bit_count_t stopBitCount)
422 /* configure the number of stop bits */
423 BW_LPUART_BAUD_SBNS(baseAddr, stopBitCount);
427 * @brief Configures the transmit and receive inversion control in the LPUART controller.
429 * This function should only be called when the LPUART is between transmit and receive packets.
431 * @param baseAddr LPUART base address.
432 * @param rxInvert Enable (1) or disable (0) receive inversion
433 * @param txInvert Enable (1) or disable (0) transmit inversion
435 void LPUART_HAL_SetTxRxInversionCmd(uint32_t baseAddr, uint32_t rxInvert, uint32_t txInvert);
440 * @name LPUART Interrupts and DMA
445 * @brief Configures the LPUART module interrupts to enable/disable various interrupt sources.
447 * @param baseAddr LPUART module base address.
448 * @param interrupt LPUART interrupt configuration data.
449 * @param enable true: enable, false: disable.
451 void LPUART_HAL_SetIntMode(uint32_t baseAddr, lpuart_interrupt_t interrupt, bool enable);
454 * @brief Returns whether the LPUART module interrupts is enabled/disabled.
456 * @param baseAddr LPUART module base address.
457 * @param interrupt LPUART interrupt configuration data.
458 * @return true: enable, false: disable.
460 bool LPUART_HAL_GetIntMode(uint32_t baseAddr, lpuart_interrupt_t interrupt);
463 * @brief Enable/Disable the transmission_complete_interrupt.
465 * @param baseAddr LPUART base address
466 * @param enable true: enable, false: disable.
468 static inline void LPUART_HAL_SetTxDataRegEmptyIntCmd(uint32_t baseAddr, bool enable)
470 BW_LPUART_CTRL_TIE(baseAddr, enable);
474 * @brief Gets the configuration of the transmission_data_register_empty_interrupt enable setting.
476 * @param baseAddr LPUART base address
477 * @return Bit setting of the interrupt enable bit
479 static inline bool LPUART_HAL_GetTxDataRegEmptyIntCmd(uint32_t baseAddr)
481 return BR_LPUART_CTRL_TIE(baseAddr);
485 * @brief Enables the rx_data_register_full_interrupt.
487 * @param baseAddr LPUART base address
488 * @param enable true: enable, false: disable.
490 static inline void LPUART_HAL_SetRxDataRegFullIntCmd(uint32_t baseAddr, bool enable)
492 BW_LPUART_CTRL_RIE(baseAddr, enable);
496 * @brief Gets the configuration of the rx_data_register_full_interrupt enable.
498 * @param baseAddr LPUART base address
499 * @return Bit setting of the interrupt enable bit
501 static inline bool LPUART_HAL_GetRxDataRegFullIntCmd(uint32_t baseAddr)
503 return BR_LPUART_CTRL_RIE(baseAddr);
506 #if FSL_FEATURE_LPUART_HAS_DMA_ENABLE
508 * @brief LPUART configures DMA requests for Transmitter and Receiver.
510 * @param baseAddr LPUART base address
511 * @param txDmaConfig Transmit DMA request configuration (enable:1 /disable: 0)
512 * @param rxDmaConfig Receive DMA request configuration (enable: 1/disable: 0)
514 void LPUART_HAL_ConfigureDma(uint32_t baseAddr, bool txDmaConfig, bool rxDmaConfig);
517 * @brief Gets the LPUART Transmit DMA request configuration.
519 * @param baseAddr LPUART base address
520 * @return Transmit DMA request configuration (enable: 1/disable: 0)
522 static inline bool LPUART_HAL_IsTxDmaEnabled(uint32_t baseAddr)
524 /* TDMAE configures the transmit data register empty flag, S1[TDRE], to */
525 /* generate a DMA request. */
526 return BR_LPUART_BAUD_TDMAE(baseAddr);
530 * @brief Gets the LPUART receive DMA request configuration.
532 * @param baseAddr LPUART base address
533 * @return Receives the DMA request configuration (enable: 1/disable: 0).
535 static inline bool LPUART_HAL_IsRxDmaEnabled(uint32_t baseAddr)
537 /* RDMAE configures the receive data register fell flag, S1[RDRF], to */
538 /* generate a DMA request. */
539 return BR_LPUART_BAUD_RDMAE(baseAddr);
547 * @name LPUART Transfer Functions
552 * @brief Sends the LPUART 8-bit character.
554 * @param baseAddr LPUART Instance
555 * @param data data to send (8-bit)
557 static inline void LPUART_HAL_Putchar(uint32_t baseAddr, uint8_t data)
559 /* put 8-bit data into the lpuart data register */
560 HW_LPUART_DATA_WR(baseAddr, data);
564 * @brief Sends the LPUART 9-bit character.
566 * @param baseAddr LPUART Instance
567 * @param data data to send (9-bit)
569 void LPUART_HAL_Putchar9(uint32_t baseAddr, uint16_t data);
572 * @brief Sends the LPUART 10-bit character (Note: Feature available on select LPUART instances).
574 * @param baseAddr LPUART Instance
575 * @param data data to send (10-bit)
576 * @return An error code or kStatus_Success
578 lpuart_status_t LPUART_HAL_Putchar10(uint32_t baseAddr, uint16_t data);
581 * @brief Gets the LPUART 8-bit character.
583 * @param baseAddr LPUART base address
584 * @param readData data read from receive (8-bit)
586 void LPUART_HAL_Getchar(uint32_t baseAddr, uint8_t *readData);
589 * @brief Gets the LPUART 9-bit character.
591 * @param baseAddr LPUART base address
592 * @param readData data read from receive (9-bit)
594 void LPUART_HAL_Getchar9(uint32_t baseAddr, uint16_t *readData);
597 * @brief Gets the LPUART 10-bit character.
599 * @param baseAddr LPUART base address
600 * @param readData data read from receive (10-bit)
601 * @return An error code or kStatus_Success
603 lpuart_status_t LPUART_HAL_Getchar10(uint32_t baseAddr, uint16_t *readData);
606 * @brief Configures the number of idle characters that must be received before the IDLE flag is set.
608 * @param baseAddr LPUART base address
609 * @param idle_config idle characters configuration
611 static inline void LPUART_HAL_IdleConfig(uint32_t baseAddr, lpuart_idle_config_t idleConfig)
613 BW_LPUART_CTRL_IDLECFG(baseAddr, idleConfig);
617 * @brief Gets the configuration of the number of idle characters that must be received before the IDLE flag is set.
619 * @param baseAddr LPUART base address
620 * @return idle characters configuration
622 static inline lpuart_idle_config_t LPUART_HAL_GetIdleconfig(uint32_t baseAddr)
624 /* get the receiver idle character config based on the LPUART baseAddr */
625 return (lpuart_idle_config_t)BR_LPUART_CTRL_IDLECFG(baseAddr);
628 #if FSL_FEATURE_LPUART_HAS_EXTENDED_DATA_REGISTER_FLAGS
630 * @brief Configures bit10 (if enabled) or bit9 (if disabled) as the parity bit in the serial
632 * This sets LPUARTx_C4[M10] - it is also required to set LPUARTx_C1[M] and LPUARTx_C1[PE]
634 * @param baseAddr LPUART base address
635 * @param enable Enable (1) to configure bit10 as the parity bit, disable (0) to
636 * configure bit 9 as the parity bit in the serial transmission
638 static inline void LPUART_HAL_ConfigureBit10AsParityBitOperation(uint32_t baseAddr, bool enable)
640 /* to enable the parity bit as the tenth data bit, along with enabling LPUARTx_C4[M10] */
641 /* need to also enable parity and set LPUARTx_CTRL[M] bit */
642 /* assumed that the user has already set the appropriate bits */
643 BW_LPUART_BAUD_M10(baseAddr, enable);
647 * @brief Gets the configuration of bit10 (if enabled) or bit9 (if disabled) as the
648 * parity bit in the serial transmission.
650 * @param baseAddr LPUART base address
651 * @return Configuration of bit10 (enabled (1)), or bit 9 (disabled (0)) as the
652 * parity bit in the serial transmission
654 static inline bool LPUART_HAL_IsBit10SetAsParityBit(uint32_t baseAddr)
656 /* to see if the parity bit is set as the tenth data bit, */
657 /* return value of LPUARTx_BAUD[M10] */
658 return BR_LPUART_BAUD_M10(baseAddr);
662 * @brief Checks whether the current data word was received with noise.
664 * @param baseAddr LPUART base address.
665 * @return The status of the NOISY bit in the LPUART extended data register
667 static inline bool LPUART_HAL_IsCurrentDatawordReceivedWithNoise(uint32_t baseAddr)
669 /* to see if the current dataword was received with noise, */
670 /* return value of LPUARTx_DATA[NOISY] */
671 return BR_LPUART_DATA_NOISY(baseAddr);
675 * @brief Checks whether the receive buffer is empty.
677 * @param baseAddr LPUART base address
678 * @return TRUE if the receive-buffer is empty.
680 static inline bool LPUART_HAL_IsReceiveBufferEmpty(uint32_t baseAddr)
682 /* to see if the current state of data buffer is empty, */
683 /* return value of LPUARTx_DATA[RXEMPT] */
684 return BR_LPUART_DATA_RXEMPT(baseAddr);
688 * @brief Checks whether the previous BUS state was idle before this byte is received.
690 * @param baseAddr LPUART base address
691 * @return TRUE if the previous BUS state was IDLE.
693 static inline bool LPUART_HAL_ItWasPreviousBusStateIdle(uint32_t baseAddr)
695 /* to see if the current dataword was received with parity error, */
696 /* return value of LPUARTx_DATA[PARITYE] */
697 return BR_LPUART_DATA_IDLINE(baseAddr);
701 * @brief Checks whether the current data word was received with parity error.
703 * @param baseAddr LPUART base address
704 * @return The status of the PARITYE bit in the LPUART extended data register
706 static inline bool LPUART_HAL_IsCurrentDatawordReceivedWithParityError(uint32_t baseAddr)
708 /* to see if the current dataword was received with parity error, */
709 /* return value of LPUARTx_DATA[PARITYE] */
710 return BR_LPUART_DATA_PARITYE(baseAddr);
712 #endif /* FSL_FEATURE_LPUART_HAS_EXTENDED_DATA_REGISTER_FLAGS */
717 * @name LPUART Special Feature Configurations
722 * @brief Configures the LPUART operation in wait mode (operates or stops operations in wait mode).
723 * In some LPUART instances, the user should disable the transmitter/receiver
724 * before calling this function.
725 * Generally, this may be applied to all LPUARTs to ensure safe operation.
727 * @param baseAddr LPUART base address
728 * @param mode LPUART wait mode operation - operates or stops to operate in wait mode.
730 static inline void LPUART_HAL_SetWaitModeOperation(uint32_t baseAddr, lpuart_operation_config_t mode)
732 /* configure lpuart operation in wait mode */
733 /* In CPU wait mode: 0 - lpuart clocks continue to run; 1 - lpuart clocks freeze */
734 BW_LPUART_CTRL_DOZEEN(baseAddr, mode);
738 * @brief Gets the LPUART operation in wait mode (operates or stops operations in wait mode).
740 * @param baseAddr LPUART base address
741 * @return LPUART wait mode operation configuration - kLpuartOperates or KLpuartStops in wait mode
743 lpuart_operation_config_t LPUART_HAL_GetWaitModeOperationConfig(uint32_t baseAddr);
746 * @brief Configures the LPUART loopback operation (enable/disable loopback operation)
748 * In some LPUART instances, the user should disable the transmitter/receiver
749 * before calling this function.
750 * Generally, this may be applied to all LPUARTs to ensure safe operation.
752 * @param baseAddr LPUART base address
753 * @param enable LPUART loopback mode - disabled (0) or enabled (1)
755 void LPUART_HAL_SedLoopbackCmd(uint32_t baseAddr, bool enable);
758 * @brief Configures the LPUART single-wire operation (enable/disable single-wire mode)
760 * In some LPUART instances, the user should disable the transmitter/receiver
761 * before calling this function.
762 * Generally, this may be applied to all LPUARTs to ensure safe operation.
764 * @param baseAddr LPUART base address
765 * @param enable LPUART loopback mode - disabled (0) or enabled (1)
767 void LPUART_HAL_SetSingleWireCmd(uint32_t baseAddr, bool enable);
770 * @brief Configures the LPUART transmit direction while in single-wire mode.
772 * @param baseAddr LPUART base address
773 * @param direction LPUART single-wire transmit direction - input or output
775 static inline void LPUART_HAL_ConfigureTxdirInSinglewireMode(uint32_t baseAddr,
776 lpuart_singlewire_txdir_t direction)
778 /* configure LPUART transmit direction (input or output) when in single-wire mode */
779 /* it is assumed LPUART is in single-wire mode */
780 BW_LPUART_CTRL_TXDIR(baseAddr, direction);
784 * @brief Places the LPUART receiver in standby mode.
786 * In some LPUART instances,
787 * before placing LPUART in standby mode, first determine whether the receiver is set to
788 * wake on idle or whether it is already in idle state.
789 * NOTE that the RWU should only be set with C1[WAKE] = 0 (wakeup on idle) if the channel is currently
791 * This can be determined by the S2[RAF] flag. If it is set to wake up an IDLE event and the channel is
792 * already idle, it is possible that the LPUART will discard data since data must be received
793 * (or a LIN break detect) after an IDLE is detected and before IDLE is allowed to reasserted.
795 * @param baseAddr LPUART base address
796 * @return Error code or kStatus_Success
798 lpuart_status_t LPUART_HAL_PutReceiverInStandbyMode(uint32_t baseAddr);
801 * @brief Places the LPUART receiver in a normal mode (disable standby mode operation).
803 * @param baseAddr LPUART base address
805 static inline void LPUART_HAL_PutReceiverInNormalMode(uint32_t baseAddr)
807 /* clear the RWU bit to place receiver into normal mode (disable standby mode) */
808 BW_LPUART_CTRL_RWU(baseAddr, 0);
812 * @brief Checks whether the LPUART receiver is in a standby mode.
814 * @param baseAddr LPUART base address
815 * @return LPUART in normal more (0) or standby (1)
817 static inline bool LPUART_HAL_IsReceiverInStandby(uint32_t baseAddr)
819 /* return the RWU bit setting (0 - normal more, 1 - standby) */
820 return BR_LPUART_CTRL_RWU(baseAddr);
824 * @brief LPUART receiver wakeup method (idle line or addr-mark) from standby mode
826 * @param baseAddr LPUART base address
827 * @param method LPUART wakeup method: 0 - Idle-line wake (default), 1 - addr-mark wake
829 static inline void LPUART_HAL_SelectReceiverWakeupMethod(uint32_t baseAddr, lpuart_wakeup_method_t method)
831 /* configure the WAKE bit for idle line wake or address mark wake */
832 BW_LPUART_CTRL_WAKE(baseAddr, method);
836 * @brief Gets the LPUART receiver wakeup method (idle line or addr-mark) from standby mode.
838 * @param baseAddr LPUART base address
839 * @return LPUART wakeup method: kLpuartIdleLineWake: 0 - Idle-line wake (default),
840 * kLpuartAddrMarkWake: 1 - addr-mark wake
842 lpuart_wakeup_method_t LPUART_HAL_GetReceiverWakeupMethod(uint32_t baseAddr);
845 * @brief LPUART idle-line detect operation configuration (idle line bit-count start and wake
846 * up affect on IDLE status bit).
848 * In some LPUART instances, the user should disable the transmitter/receiver
849 * before calling this function.
850 * Generally, this may be applied to all LPUARTs to ensure safe operation.
852 * @param baseAddr LPUART base address
853 * @param config LPUART configuration data for idle line detect operation
855 void LPUART_HAL_ConfigureIdleLineDetect(uint32_t baseAddr,
856 const lpuart_idle_line_config_t *config);
859 * @brief LPUART break character transmit length configuration
860 * In some LPUART instances, the user should disable the transmitter before calling
861 * this function. Generally, this may be applied to all LPUARTs to ensure safe operation.
863 * @param baseAddr LPUART base address
864 * @param length LPUART break character length setting: 0 - minimum 10-bit times (default),
865 * 1 - minimum 13-bit times
867 static inline void LPUART_HAL_SetBreakCharTransmitLength(uint32_t baseAddr,
868 lpuart_break_char_length_t length)
870 /* Configure BRK13 - Break Character transmit length configuration */
871 /* LPUART break character length setting: */
872 /* 0 - minimum 10-bit times (default), */
873 /* 1 - minimum 13-bit times */
874 BW_LPUART_STAT_BRK13(baseAddr, length);
878 * @brief LPUART break character detect length configuration
880 * @param baseAddr LPUART base address
881 * @param length LPUART break character length setting: 0 - minimum 10-bit times (default),
882 * 1 - minimum 13-bit times
884 static inline void LPUART_HAL_SetBreakCharDetectLength(uint32_t baseAddr,
885 lpuart_break_char_length_t length)
887 /* Configure LBKDE - Break Character detect length configuration */
888 /* LPUART break character length setting: */
889 /* 0 - minimum 10-bit times (default), */
890 /* 1 - minimum 13-bit times */
891 BW_LPUART_STAT_LBKDE(baseAddr, length);
895 * @brief LPUART transmit sends break character configuration.
897 * @param baseAddr LPUART base address
898 * @param enable LPUART normal/queue break char - disabled (normal mode, default: 0) or
899 * enabled (queue break char: 1)
901 static inline void LPUART_HAL_QueueBreakCharToSend(uint32_t baseAddr, bool enable)
903 /* Configure SBK - Send Break */
904 /* LPUART send break character setting: */
905 /* 0 - normal transmitter operation, */
906 /* 1 - Queue break character(s) to be sent */
908 BW_LPUART_CTRL_SBK(baseAddr, enable);
912 * @brief LPUART configures match address mode control (Note: Feature available on
913 * select LPUART instances)
915 * @param baseAddr LPUART base address
916 * @param matchAddrMode1 MAEN1: match address mode1 enable (1)/disable (0)
917 * @param matchAddrMode2 MAEN2: match address mode2 enable (1)/disable (0)
918 * @param matchAddrValue1 MA: match address value to program into match address register 1
919 * @param matchAddrValue2 MA: match address value to program into match address register 2
920 * @param config MATCFG: Configures the match addressing mode used.
921 * @return An error code or kStatus_Success
923 lpuart_status_t LPUART_HAL_SetMatchAddressOperation(uint32_t baseAddr,
924 bool matchAddrMode1, bool matchAddrMode2,
925 uint8_t matchAddrValue1, uint8_t matchAddrValue2,
926 lpuart_match_config_t config);
929 * @brief LPUART sends the MSB first configuration (Note: Feature available on select LPUART instances)
930 * In some LPUART instances, the user should disable the transmitter/receiver
931 * before calling this function.
932 * Generally, this may be applied to all LPUARTs to ensure safe operation.
934 * @param baseAddr LPUART base address
935 * @param enable MSB first mode configuration, MSBF: 0 - LSB (default, feature disabled),
936 * 1 - MSB (feature enabled)
938 static inline void LPUART_HAL_ConfigureSendMsbFirstOperation(uint32_t baseAddr, bool enable)
940 BW_LPUART_STAT_MSBF(baseAddr, enable);
944 * @brief LPUART disables re-sync of received data configuration (Note: Feature available on
945 * select LPUART instances).
947 * @param baseAddr LPUART base address
948 * @param enable disable re-sync of received data word configuration, RESYNCDIS:
949 * 0 - re-sync of received data word (default, feature disabled),
950 * 1 - disable the re-sync (feature enabled)
952 static inline void LPUART_HAL_ConfigureReceiveResyncDisableOperation(uint32_t baseAddr, bool enable)
954 /* When set, disables the resynchronization of the received data word when a data */
955 /* one followed by data zero transition is detected. This bit should only be changed */
956 /* when the receiver is disabled. */
957 BW_LPUART_BAUD_RESYNCDIS(baseAddr, enable);
960 #if FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
962 * @brief Transmits the CTS source configuration.
964 * @param baseAddr LPUART base address
965 * @param source LPUART CTS source
967 static inline void LPUART_HAL_SelectSourceCts(uint32_t baseAddr, lpuart_cts_source_t source)
970 BW_LPUART_MODIR_TXCTSSRC(baseAddr, source);
974 * @brief Transmits the CTS configuration.
975 * Note: configures if the CTS state is checked at the start of each character or only when the transmitter is idle.
977 * @param baseAddr LPUART base address
978 * @param config LPUART CTS configuration
980 static inline void LPUART_HAL_ConfigureCts(uint32_t baseAddr, lpuart_cts_config_t config)
983 BW_LPUART_MODIR_TXCTSC(baseAddr, config);
987 * @brief Enables the receiver request-to-send.
988 * Note: do not enable both Receiver RTS (RXRTSE) and Transmit RTS (TXRTSE).
990 * @param baseAddr LPUART base address
991 * @param enable disable(0)/enable(1) receiver RTS.
994 static inline void LPUART_HAL_SetReceiverRts(uint32_t baseAddr, bool enable)
996 BW_LPUART_MODIR_RXRTSE(baseAddr, enable);
1000 * @brief Enables the transmitter request-to-send.
1001 * Note: do not enable both Receiver RTS (RXRTSE) and Transmit RTS (TXRTSE).
1003 * @param baseAddr LPUART base address
1004 * @param enable disable(0)/enable(1) transmitter RTS.
1006 static inline void LPUART_HAL_SetTransmitterRtsCmd(uint32_t baseAddr, bool enable)
1008 BW_LPUART_MODIR_TXRTSE(baseAddr, enable);
1012 * @brief Configures the transmitter RTS polarity: 0=active low, 1=active high.
1014 * @param baseAddr LPUART base address
1015 * @param polarity Settings to choose RTS polarity.
1017 static inline void LPUART_HAL_SetTransmitterRtsPolarityMode(uint32_t baseAddr, bool polarity)
1019 /* Configure the transmitter rts polarity: 0=active low, 1=active high */
1020 BW_LPUART_MODIR_TXRTSPOL(baseAddr, polarity);
1024 * @brief Enables the transmitter clear-to-send.
1026 * @param baseAddr LPUART base address
1027 * @param enable disable(0)/enable(1) transmitter CTS.
1029 static inline void LPUART_HAL_SetTransmitterCtsCmd(uint32_t baseAddr, bool enable)
1031 BW_LPUART_MODIR_TXCTSE(baseAddr, enable);
1034 #endif /* FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT */
1036 #if FSL_FEATURE_LPUART_HAS_IR_SUPPORT
1038 * @brief Configures the LPUART infrared operation.
1040 * @param baseAddr LPUART base address
1041 * @param enable Enable (1) or disable (0) the infrared operation
1042 * @param pulseWidth The transmit narrow pulse width of type lpuart_ir_tx_pulsewidth_t
1044 void LPUART_HAL_SetInfraredOperation(uint32_t baseAddr, bool enable,
1045 lpuart_ir_tx_pulsewidth_t pulseWidth);
1046 #endif /* FSL_FEATURE_LPUART_HAS_IR_SUPPORT */
1051 * @name LPUART Status Flags
1056 * @brief LPUART get status flag
1058 * @param baseAddr LPUART base address
1059 * @param statusFlag The status flag to query
1061 bool LPUART_HAL_GetStatusFlag(uint32_t baseAddr, lpuart_status_flag_t statusFlag);
1064 * @brief Gets the LPUART Transmit data register empty flag.
1066 * This function returns the state of the LPUART Transmit data register empty flag.
1068 * @param baseAddr LPUART module base address.
1069 * @return The status of Transmit data register empty flag, which is set when transmit buffer
1072 static inline bool LPUART_HAL_IsTxDataRegEmpty(uint32_t baseAddr)
1074 /* return status condition of TDRE flag */
1075 return BR_LPUART_STAT_TDRE(baseAddr);
1079 * @brief Gets the LPUART receive data register full flag.
1081 * @param baseAddr LPUART base address
1082 * @return Status of the receive data register full flag, sets when the receive data buffer is full.
1084 static inline bool LPUART_HAL_IsRxDataRegFull(uint32_t baseAddr)
1086 /* return status condition of RDRF flag */
1087 return BR_LPUART_STAT_RDRF(baseAddr);
1091 * @brief Gets the LPUART transmission complete flag.
1093 * @param baseAddr LPUART base address
1094 * @return Status of Transmission complete flag, sets when transmitter is idle
1095 * (transmission activity complete)
1097 static inline bool LPUART_HAL_IsTxComplete(uint32_t baseAddr)
1099 /* return status condition of TC flag */
1100 return BR_LPUART_STAT_TC(baseAddr);
1104 * @brief LPUART clears an individual status flag (see lpuart_status_flag_t for list of status bits).
1106 * @param baseAddr LPUART base address
1107 * @param statusFlag Desired LPUART status flag to clear
1108 * @return An error code or kStatus_Success
1110 lpuart_status_t LPUART_HAL_ClearStatusFlag(uint32_t baseAddr, lpuart_status_flag_t statusFlag);
1113 * @brief LPUART clears ALL status flags.
1115 * @param baseAddr LPUART base address
1117 void LPUART_HAL_ClearAllNonAutoclearStatusFlags(uint32_t baseAddr);
1121 #if defined(__cplusplus)
1127 #endif /* MBED_NO_LPUART */
1129 #endif /* __FSL_LPUART_HAL_H__ */
1131 /*******************************************************************************
1133 ******************************************************************************/