]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/lpuart/fsl_lpuart_hal.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / hal / lpuart / fsl_lpuart_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  
31 #ifndef __FSL_LPUART_HAL_H__
32 #define __FSL_LPUART_HAL_H__
33
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <assert.h>
37 #include "fsl_lpuart_features.h"
38 #include "fsl_device_registers.h"
39
40 #ifndef MBED_NO_LPUART
41
42 /*!
43  * @addtogroup lpuart_hal
44  * @{
45  */
46
47 /*******************************************************************************
48  * Definitions
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)
57
58 /*! @brief Error codes for the LPUART driver.*/
59 typedef enum _lpuart_status
60 {
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,
83 } lpuart_status_t;
84
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;
90
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;
97
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;
104
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;
110
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;
116
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;
122
123 /*!
124  * @brief LPUART break character length settings for transmit/detect.
125  *
126  * The actual maximum bit times may vary depending on the LPUART instance.
127  */
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;
136
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;
142
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;
150
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;
158
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;
170
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;
176
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;
182
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;
193
194 /*!
195  * @brief LPUART status flags.
196  *
197  * This provides constants for the LPUART status flags for use in the UART functions.
198  */
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 */
214 #endif
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 */
218 #endif
219 } lpuart_status_flag_t;
220
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. */
236 #endif
237 } lpuart_interrupt_t;
238
239
240 /*******************************************************************************
241  * API
242  ******************************************************************************/
243
244 #if defined(__cplusplus)
245 extern "C" {
246 #endif
247
248 /*!
249  * @name LPUART Common Configurations
250  * @{
251  */
252
253 /*!
254  * @brief Initializes the LPUART controller to known state.
255  *
256  * @param baseAddr LPUART base address.
257  */
258 void LPUART_HAL_Init(uint32_t baseAddr);
259
260 /*!
261  * @brief Enables the LPUART transmitter.
262  *
263  * @param baseAddr LPUART base address.
264  */
265 void LPUART_HAL_EnableTransmitter(uint32_t baseAddr);
266
267 /*!
268  * @brief Disables the LPUART transmitter.
269  *
270  * @param baseAddr LPUART base address
271  */
272 static inline void LPUART_HAL_DisableTransmitter(uint32_t baseAddr)
273 {
274     BW_LPUART_CTRL_TE(baseAddr, 0);
275 }
276
277 /*!
278  * @brief Gets the LPUART transmitter enabled/disabled configuration.
279  *
280  * @param baseAddr LPUART base address
281  * @return State of LPUART transmitter enable(1)/disable(0)
282  */
283 static inline bool LPUART_HAL_IsTransmitterEnabled(uint32_t baseAddr)
284 {
285     return BR_LPUART_CTRL_TE(baseAddr);
286 }
287
288 /*!
289  * @brief Enables the LPUART receiver.
290  *
291  * @param baseAddr LPUART base address
292  */
293 static inline void LPUART_HAL_EnableReceiver(uint32_t baseAddr)
294 {
295     BW_LPUART_CTRL_RE(baseAddr, 1);
296 }
297
298 /*!
299  * @brief Disables the LPUART receiver.
300  *
301  * @param baseAddr LPUART base address
302  */
303 static inline void LPUART_HAL_DisableReceiver(uint32_t baseAddr)
304 {
305     BW_LPUART_CTRL_RE(baseAddr, 0);
306 }
307
308 /*!
309  * @brief Gets the LPUART receiver enabled/disabled configuration.
310  *
311  * @param baseAddr LPUART base address
312  * @return State of LPUART receiver enable(1)/disable(0)
313  */
314 static inline bool LPUART_HAL_IsReceiverEnabled(uint32_t baseAddr)
315 {
316     return BR_LPUART_CTRL_RE(baseAddr);
317 }
318
319 /*!
320  * @brief Configures the LPUART baud rate.
321  *
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.
325  *
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
330  */
331 lpuart_status_t LPUART_HAL_SetBaudRate(uint32_t baseAddr, uint32_t sourceClockInHz,
332                                 uint32_t desiredBaudRate);
333
334 /*!
335  * @brief Sets the LPUART baud rate modulo divisor.
336  *
337  * @param baseAddr LPUART base address.
338  * @param   baudRateDivisor The baud rate modulo division "SBR"
339  */
340 static inline void LPUART_HAL_SetBaudRateDivisor(uint32_t baseAddr, uint32_t baudRateDivisor)
341 {
342     assert ((baudRateDivisor < 0x1FFF) && (baudRateDivisor > 1));
343     BW_LPUART_BAUD_SBR(baseAddr, baudRateDivisor);
344 }
345
346 #if FSL_FEATURE_LPUART_HAS_BAUD_RATE_OVER_SAMPLING_SUPPORT
347 /*!
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
354  *        this function.
355  *
356  * @param baseAddr LPUART base address.
357  * @param   overSamplingRatio The oversampling ratio "OSR"
358  */
359 static inline void LPUART_HAL_SetOversamplingRatio(uint32_t baseAddr, uint32_t overSamplingRatio)
360 {
361     assert(overSamplingRatio < 0x1F);
362     BW_LPUART_BAUD_OSR(baseAddr, overSamplingRatio);
363 }
364 #endif
365
366 #if FSL_FEATURE_LPUART_HAS_BOTH_EDGE_SAMPLING_SUPPORT
367 /*!
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.
373  *
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
377  */
378 static inline void LPUART_HAL_SetBothEdgeSamplingCmd(uint32_t baseAddr, bool enableBothEdgeSampling)
379 {
380     BW_LPUART_BAUD_BOTHEDGE(baseAddr, enableBothEdgeSampling);
381 }
382 #endif
383
384 /*!
385  * @brief Configures the number of bits per character in the LPUART controller.
386  *
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.
390  *
391  * @param baseAddr LPUART base address.
392  * @param   bitCountPerChar   Number of bits per char (8, 9, or
393  *                            10, depending on the LPUART instance)
394  */
395 void LPUART_HAL_SetBitCountPerChar(uint32_t baseAddr, lpuart_bit_count_per_char_t bitCountPerChar);
396
397
398 /*!
399  * @brief Configures parity mode in the LPUART controller.
400  * 
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.
404  *
405  * @param baseAddr LPUART base address.
406  * @param   parityModeType  Parity mode (enabled, disable, odd, even - see parity_mode_t struct)
407  */
408 void LPUART_HAL_SetParityMode(uint32_t baseAddr, lpuart_parity_mode_t parityModeType);
409
410 /*!
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.
415  *
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
419  */
420 static inline void LPUART_HAL_SetStopBitCount(uint32_t baseAddr, lpuart_stop_bit_count_t stopBitCount)
421 {
422     /* configure the number of stop bits */
423     BW_LPUART_BAUD_SBNS(baseAddr, stopBitCount);
424 }
425
426 /*!
427  * @brief Configures the transmit and receive inversion control in the LPUART controller.
428  *
429  * This function should only be called when the LPUART is between transmit and receive packets.
430  *
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
434  */
435 void LPUART_HAL_SetTxRxInversionCmd(uint32_t baseAddr, uint32_t rxInvert, uint32_t txInvert);
436
437 /*@}*/
438
439 /*!
440  * @name LPUART Interrupts and DMA
441  * @{
442  */
443
444 /*!
445  * @brief Configures the LPUART module interrupts to enable/disable various interrupt sources.
446  *
447  * @param   baseAddr LPUART module base address.
448  * @param   interrupt LPUART interrupt configuration data.
449  * @param   enable   true: enable, false: disable.
450  */
451 void LPUART_HAL_SetIntMode(uint32_t baseAddr, lpuart_interrupt_t interrupt, bool enable);
452
453 /*!
454  * @brief Returns whether the LPUART module interrupts is enabled/disabled.
455  *
456  * @param   baseAddr LPUART module base address.
457  * @param   interrupt LPUART interrupt configuration data.
458  * @return  true: enable, false: disable.
459  */
460 bool LPUART_HAL_GetIntMode(uint32_t baseAddr, lpuart_interrupt_t interrupt);
461
462 /*!
463  * @brief Enable/Disable the transmission_complete_interrupt.
464  *
465  * @param baseAddr LPUART base address
466  * @param   enable   true: enable, false: disable.
467  */
468 static inline void LPUART_HAL_SetTxDataRegEmptyIntCmd(uint32_t baseAddr, bool enable)
469 {
470     BW_LPUART_CTRL_TIE(baseAddr, enable);
471 }
472
473 /*!
474  * @brief Gets the configuration of the transmission_data_register_empty_interrupt enable setting.
475  *
476  * @param baseAddr LPUART base address
477  * @return  Bit setting of the interrupt enable bit
478  */
479 static inline bool LPUART_HAL_GetTxDataRegEmptyIntCmd(uint32_t baseAddr)
480 {
481     return BR_LPUART_CTRL_TIE(baseAddr);
482 }
483
484 /*!
485  * @brief Enables the rx_data_register_full_interrupt.
486  *
487  * @param baseAddr LPUART base address
488  * @param   enable   true: enable, false: disable.
489  */
490 static inline void LPUART_HAL_SetRxDataRegFullIntCmd(uint32_t baseAddr, bool enable)
491 {
492     BW_LPUART_CTRL_RIE(baseAddr, enable);
493 }
494
495 /*!
496  * @brief Gets the configuration of the rx_data_register_full_interrupt enable.
497  *
498  * @param baseAddr LPUART base address
499  * @return Bit setting of the interrupt enable bit
500  */
501 static inline bool LPUART_HAL_GetRxDataRegFullIntCmd(uint32_t baseAddr)
502 {
503     return BR_LPUART_CTRL_RIE(baseAddr);
504 }
505
506 #if FSL_FEATURE_LPUART_HAS_DMA_ENABLE 
507 /*!
508  * @brief  LPUART configures DMA requests for Transmitter and Receiver.
509  *
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)
513  */
514 void LPUART_HAL_ConfigureDma(uint32_t baseAddr, bool txDmaConfig, bool rxDmaConfig);
515
516 /*!
517  * @brief  Gets the LPUART Transmit DMA request configuration.
518  *
519  * @param baseAddr LPUART base address
520  * @return   Transmit DMA request configuration (enable: 1/disable: 0)
521  */
522 static inline bool LPUART_HAL_IsTxDmaEnabled(uint32_t baseAddr)
523 {
524     /* TDMAE configures the transmit data register empty flag, S1[TDRE], to */
525     /* generate a DMA request. */
526     return BR_LPUART_BAUD_TDMAE(baseAddr);
527 }
528
529 /*!
530  * @brief  Gets the LPUART receive DMA request configuration.
531  *
532  * @param baseAddr LPUART base address
533  * @return   Receives the DMA request configuration (enable: 1/disable: 0).
534  */
535 static inline bool LPUART_HAL_IsRxDmaEnabled(uint32_t baseAddr)
536 {
537     /* RDMAE configures the receive data register fell flag, S1[RDRF], to */
538     /* generate a DMA request. */
539     return BR_LPUART_BAUD_RDMAE(baseAddr);
540 }
541
542 #endif
543
544 /*@}*/
545
546 /*! 
547  * @name LPUART Transfer Functions
548  * @{
549  */
550
551 /*!
552  * @brief Sends the LPUART 8-bit character.
553  *
554  * @param baseAddr LPUART Instance
555  * @param data     data to send (8-bit)
556  */
557 static inline void LPUART_HAL_Putchar(uint32_t baseAddr, uint8_t data)
558 {
559     /* put 8-bit data into the lpuart data register */
560     HW_LPUART_DATA_WR(baseAddr, data);
561 }
562
563 /*!
564  * @brief Sends the LPUART 9-bit character.
565  *
566  * @param baseAddr LPUART Instance
567  * @param data     data to send (9-bit)
568  */
569 void LPUART_HAL_Putchar9(uint32_t baseAddr, uint16_t data);
570
571 /*!
572  * @brief Sends the LPUART 10-bit character (Note: Feature available on select LPUART instances).
573  *
574  * @param baseAddr LPUART Instance
575  * @param   data        data to send (10-bit)
576  * @return  An error code or kStatus_Success
577  */
578 lpuart_status_t LPUART_HAL_Putchar10(uint32_t baseAddr, uint16_t data);
579
580 /*!
581  * @brief Gets the LPUART 8-bit character.
582  *
583  * @param baseAddr LPUART base address
584  * @param   readData    data read from receive (8-bit)
585  */
586 void  LPUART_HAL_Getchar(uint32_t baseAddr, uint8_t *readData);
587
588 /*!
589  * @brief Gets the LPUART 9-bit character.
590  *
591  * @param baseAddr LPUART base address
592  * @param   readData    data read from receive (9-bit)
593  */
594 void  LPUART_HAL_Getchar9(uint32_t baseAddr, uint16_t *readData);
595
596 /*!
597  * @brief Gets the LPUART 10-bit character.
598  *
599  * @param baseAddr LPUART base address
600  * @param   readData    data read from receive (10-bit)
601  * @return  An error code or kStatus_Success
602  */
603 lpuart_status_t LPUART_HAL_Getchar10(uint32_t baseAddr, uint16_t *readData);
604
605 /*!
606  * @brief Configures the number of idle characters that must be received before the IDLE flag is set.
607  *
608  * @param baseAddr LPUART base address
609  * @param   idle_config    idle characters configuration
610  */
611 static inline void LPUART_HAL_IdleConfig(uint32_t baseAddr, lpuart_idle_config_t idleConfig)
612 {
613     BW_LPUART_CTRL_IDLECFG(baseAddr, idleConfig);
614 }
615
616 /*!
617  * @brief Gets the configuration of the number of idle characters that must be received before the IDLE flag is set.
618  *
619  * @param baseAddr LPUART base address
620  * @return  idle characters configuration
621  */
622 static inline lpuart_idle_config_t LPUART_HAL_GetIdleconfig(uint32_t baseAddr)
623 {
624     /* get the receiver idle character config based on the LPUART baseAddr */
625     return (lpuart_idle_config_t)BR_LPUART_CTRL_IDLECFG(baseAddr);
626 }
627
628 #if FSL_FEATURE_LPUART_HAS_EXTENDED_DATA_REGISTER_FLAGS
629 /*!
630  * @brief  Configures  bit10 (if enabled) or bit9 (if disabled) as the parity bit in the serial
631  *         transmission.
632  * This sets LPUARTx_C4[M10] - it is also required to set LPUARTx_C1[M] and LPUARTx_C1[PE]
633  *
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
637  */
638 static inline void LPUART_HAL_ConfigureBit10AsParityBitOperation(uint32_t baseAddr, bool enable)
639 {
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);
644 }
645
646 /*!
647  * @brief  Gets the configuration of bit10 (if enabled) or bit9 (if disabled) as the
648  *         parity bit in the serial transmission.
649  *
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
653  */
654 static inline bool LPUART_HAL_IsBit10SetAsParityBit(uint32_t baseAddr)
655 {
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);
659 }
660
661 /*!
662  * @brief  Checks whether the current data word was received with noise.
663  *
664  * @param baseAddr LPUART base address.
665  * @return  The status of the NOISY bit in the LPUART extended data register
666  */
667 static inline bool LPUART_HAL_IsCurrentDatawordReceivedWithNoise(uint32_t baseAddr)
668 {
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);
672 }
673
674 /*!
675  * @brief  Checks whether the receive buffer is empty.
676  *
677  * @param baseAddr LPUART base address
678  * @return   TRUE if the receive-buffer is empty.
679  */
680 static inline bool LPUART_HAL_IsReceiveBufferEmpty(uint32_t baseAddr)
681 {
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);
685 }
686
687 /*!
688  * @brief  Checks whether  the previous BUS state was idle before this byte is received.
689  *
690  * @param baseAddr LPUART base address
691  * @return   TRUE if the previous BUS state was IDLE.
692  */
693 static inline bool LPUART_HAL_ItWasPreviousBusStateIdle(uint32_t baseAddr)
694 {
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);
698 }
699
700 /*!
701  * @brief  Checks whether  the current data word was received with parity error.
702  *
703  * @param baseAddr LPUART base address
704  * @return  The status of the PARITYE bit in the LPUART extended data register
705  */
706 static inline bool LPUART_HAL_IsCurrentDatawordReceivedWithParityError(uint32_t baseAddr)
707 {
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);
711 }
712 #endif  /* FSL_FEATURE_LPUART_HAS_EXTENDED_DATA_REGISTER_FLAGS */
713
714 /*@}*/
715
716 /*! 
717  * @name LPUART Special Feature Configurations
718  * @{
719  */
720
721 /*!
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.
726  *
727  * @param baseAddr LPUART base address
728  * @param   mode        LPUART wait mode operation - operates or stops to operate in wait mode.
729  */
730 static inline void  LPUART_HAL_SetWaitModeOperation(uint32_t baseAddr, lpuart_operation_config_t mode)
731 {
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);
735 }
736
737 /*!
738  * @brief Gets the LPUART operation in wait mode (operates or stops operations in wait mode).
739  *
740  * @param baseAddr LPUART base address
741  * @return   LPUART wait mode operation configuration - kLpuartOperates or KLpuartStops in wait mode
742  */
743 lpuart_operation_config_t LPUART_HAL_GetWaitModeOperationConfig(uint32_t baseAddr);
744
745 /*!
746  * @brief Configures the LPUART loopback operation (enable/disable loopback operation)
747  *
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.
751  *
752  * @param baseAddr LPUART base address
753  * @param   enable        LPUART loopback mode - disabled (0) or enabled (1)
754  */
755 void LPUART_HAL_SedLoopbackCmd(uint32_t baseAddr, bool enable);
756
757 /*!
758  * @brief Configures the LPUART single-wire operation (enable/disable single-wire mode)
759  *
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.
763  *
764  * @param baseAddr LPUART base address
765  * @param   enable        LPUART loopback mode - disabled (0) or enabled (1)
766  */
767 void LPUART_HAL_SetSingleWireCmd(uint32_t baseAddr, bool enable);
768
769 /*!
770  * @brief Configures the LPUART transmit direction while in single-wire mode.
771  *
772  * @param baseAddr LPUART base address
773  * @param   direction   LPUART single-wire transmit direction - input or output
774  */
775 static inline void LPUART_HAL_ConfigureTxdirInSinglewireMode(uint32_t baseAddr,
776                                                  lpuart_singlewire_txdir_t direction)
777 {
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);
781 }
782
783 /*!
784  * @brief  Places the LPUART receiver in standby mode.
785  *
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
790  * not idle.
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.
794  *
795  * @param baseAddr LPUART base address
796  * @return Error code or kStatus_Success
797  */
798 lpuart_status_t LPUART_HAL_PutReceiverInStandbyMode(uint32_t baseAddr);
799
800 /*!
801  * @brief  Places the LPUART receiver in a normal mode (disable standby mode operation).
802  *
803  * @param baseAddr LPUART base address
804  */
805 static inline void LPUART_HAL_PutReceiverInNormalMode(uint32_t baseAddr)
806 {
807     /* clear the RWU bit to place receiver into normal mode (disable standby mode) */
808     BW_LPUART_CTRL_RWU(baseAddr, 0);
809 }
810
811 /*!
812  * @brief  Checks whether the LPUART receiver is in a standby mode.
813  *
814  * @param baseAddr LPUART base address
815  * @return LPUART in normal more (0) or standby (1)
816  */
817 static inline bool LPUART_HAL_IsReceiverInStandby(uint32_t baseAddr)
818 {
819     /* return the RWU bit setting (0 - normal more, 1 - standby) */
820     return BR_LPUART_CTRL_RWU(baseAddr);
821 }
822
823 /*!
824  * @brief  LPUART receiver wakeup method (idle line or addr-mark) from standby mode
825  *
826  * @param baseAddr LPUART base address
827  * @param   method        LPUART wakeup method: 0 - Idle-line wake (default), 1 - addr-mark wake
828  */
829 static inline void LPUART_HAL_SelectReceiverWakeupMethod(uint32_t baseAddr, lpuart_wakeup_method_t method)
830 {
831     /* configure the WAKE bit for idle line wake or address mark wake */
832     BW_LPUART_CTRL_WAKE(baseAddr, method);
833 }
834
835 /*!
836  * @brief  Gets the LPUART receiver wakeup method (idle line or addr-mark) from standby mode.
837  *
838  * @param baseAddr LPUART base address
839  * @return  LPUART wakeup method: kLpuartIdleLineWake: 0 - Idle-line wake (default),
840  *          kLpuartAddrMarkWake: 1 - addr-mark wake
841  */
842 lpuart_wakeup_method_t LPUART_HAL_GetReceiverWakeupMethod(uint32_t baseAddr);
843
844 /*!
845  * @brief  LPUART idle-line detect operation configuration (idle line bit-count start and wake
846  *         up affect on IDLE status bit).
847  *
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.
851  *
852  * @param baseAddr LPUART base address
853  * @param   config        LPUART configuration data for idle line detect operation
854  */
855 void LPUART_HAL_ConfigureIdleLineDetect(uint32_t baseAddr,
856                                          const lpuart_idle_line_config_t *config);
857
858 /*!
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.
862  *
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
866  */
867 static inline void LPUART_HAL_SetBreakCharTransmitLength(uint32_t baseAddr,
868                                              lpuart_break_char_length_t length)
869 {
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);
875 }
876
877 /*!
878  * @brief  LPUART break character detect length configuration
879  *
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
883  */
884 static inline void LPUART_HAL_SetBreakCharDetectLength(uint32_t baseAddr,
885                                            lpuart_break_char_length_t length)
886 {
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);
892 }
893
894 /*!
895  * @brief  LPUART transmit sends break character configuration.
896  *
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)
900  */
901 static inline void LPUART_HAL_QueueBreakCharToSend(uint32_t baseAddr, bool enable)
902 {
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 */
907
908     BW_LPUART_CTRL_SBK(baseAddr, enable);
909 }
910
911 /*!
912  * @brief  LPUART configures match address mode control (Note: Feature available on
913  *         select LPUART instances)
914  *
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
922  */
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);
927
928 /*!
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.
933  *
934  * @param baseAddr LPUART base address
935  * @param   enable  MSB first mode configuration, MSBF: 0 - LSB (default, feature disabled),
936  *                  1 - MSB (feature enabled)
937  */
938 static inline void LPUART_HAL_ConfigureSendMsbFirstOperation(uint32_t baseAddr, bool enable)
939 {
940     BW_LPUART_STAT_MSBF(baseAddr, enable);
941 }
942
943 /*!
944  * @brief  LPUART disables re-sync of received data configuration (Note: Feature available on
945  *         select LPUART instances).
946  *
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)
951  */
952 static inline void LPUART_HAL_ConfigureReceiveResyncDisableOperation(uint32_t baseAddr, bool enable)
953 {
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);
958 }
959
960 #if FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT
961 /*!
962  * @brief  Transmits the CTS source configuration.
963  *
964  * @param baseAddr LPUART base address
965  * @param   source    LPUART CTS source
966  */
967 static inline void LPUART_HAL_SelectSourceCts(uint32_t baseAddr, lpuart_cts_source_t source)
968 {
969     /* Set TXCTSSRC */
970     BW_LPUART_MODIR_TXCTSSRC(baseAddr, source);
971 }
972
973 /*!
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.
976  *
977  * @param baseAddr LPUART base address
978  * @param   config    LPUART CTS configuration
979  */
980 static inline void LPUART_HAL_ConfigureCts(uint32_t baseAddr, lpuart_cts_config_t config)
981 {
982     /* Set TXCTSC */
983     BW_LPUART_MODIR_TXCTSC(baseAddr, config);
984 }
985
986 /*!
987  * @brief  Enables  the receiver request-to-send.
988  * Note: do not enable both Receiver RTS (RXRTSE) and Transmit RTS (TXRTSE).
989  *
990  * @param baseAddr LPUART base address
991  * @param   enable  disable(0)/enable(1) receiver RTS.
992  */
993
994 static inline void LPUART_HAL_SetReceiverRts(uint32_t baseAddr, bool enable)
995 {
996     BW_LPUART_MODIR_RXRTSE(baseAddr, enable);
997 }
998
999 /*!
1000  * @brief  Enables the transmitter request-to-send.
1001  * Note: do not enable both Receiver RTS (RXRTSE) and Transmit RTS (TXRTSE).
1002  *
1003  * @param baseAddr LPUART base address
1004  * @param   enable  disable(0)/enable(1) transmitter RTS.
1005  */
1006 static inline void LPUART_HAL_SetTransmitterRtsCmd(uint32_t baseAddr, bool enable)
1007 {
1008     BW_LPUART_MODIR_TXRTSE(baseAddr, enable);
1009 }
1010
1011 /*!
1012  * @brief  Configures the transmitter RTS polarity: 0=active low, 1=active high.
1013  *
1014  * @param baseAddr LPUART base address
1015  * @param   polarity    Settings to choose RTS polarity.
1016  */
1017 static inline void LPUART_HAL_SetTransmitterRtsPolarityMode(uint32_t baseAddr, bool polarity)
1018 {
1019     /* Configure the transmitter rts polarity: 0=active low, 1=active high */
1020     BW_LPUART_MODIR_TXRTSPOL(baseAddr, polarity);
1021 }
1022
1023 /*!
1024  * @brief  Enables the transmitter clear-to-send.
1025  *
1026  * @param baseAddr LPUART base address
1027  * @param   enable  disable(0)/enable(1) transmitter CTS.
1028  */
1029 static inline void LPUART_HAL_SetTransmitterCtsCmd(uint32_t baseAddr, bool enable)
1030 {
1031     BW_LPUART_MODIR_TXCTSE(baseAddr, enable);
1032 }
1033
1034 #endif  /* FSL_FEATURE_LPUART_HAS_MODEM_SUPPORT */
1035
1036 #if FSL_FEATURE_LPUART_HAS_IR_SUPPORT
1037 /*!
1038  * @brief  Configures the LPUART infrared operation.
1039  *
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
1043  */
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 */
1047
1048 /*@}*/
1049
1050 /*!
1051  * @name LPUART Status Flags
1052  * @{
1053  */
1054
1055 /*!
1056  * @brief  LPUART get status flag
1057  *
1058  * @param baseAddr LPUART base address
1059  * @param   statusFlag  The status flag to query
1060  */
1061 bool LPUART_HAL_GetStatusFlag(uint32_t baseAddr, lpuart_status_flag_t statusFlag);
1062
1063 /*!
1064  * @brief  Gets the LPUART Transmit data register empty flag.
1065  *
1066  * This function returns the state of the LPUART Transmit data register empty flag.
1067  *
1068  * @param baseAddr LPUART module base address.
1069  * @return The status of Transmit data register empty flag, which is set when transmit buffer
1070  *          is empty.
1071  */
1072 static inline bool LPUART_HAL_IsTxDataRegEmpty(uint32_t baseAddr)
1073 {
1074     /* return status condition of TDRE flag  */
1075     return BR_LPUART_STAT_TDRE(baseAddr);
1076 }
1077
1078 /*!
1079  * @brief  Gets the LPUART receive data register full flag.
1080  *
1081  * @param baseAddr LPUART base address
1082  * @return  Status of the receive data register full flag, sets when the receive data buffer is full.
1083  */
1084 static inline bool LPUART_HAL_IsRxDataRegFull(uint32_t baseAddr)
1085 {
1086     /* return status condition of RDRF flag  */
1087     return BR_LPUART_STAT_RDRF(baseAddr);
1088 }
1089
1090 /*!
1091  * @brief  Gets the LPUART transmission complete flag.
1092  *
1093  * @param   baseAddr    LPUART base address
1094  * @return  Status of Transmission complete flag, sets when transmitter is idle
1095  *          (transmission activity complete)
1096  */
1097 static inline bool LPUART_HAL_IsTxComplete(uint32_t baseAddr)
1098 {
1099     /* return status condition of TC flag  */
1100     return BR_LPUART_STAT_TC(baseAddr);
1101 }
1102
1103 /*!
1104  * @brief  LPUART clears an individual status flag (see lpuart_status_flag_t for list of status bits).
1105  *
1106  * @param baseAddr LPUART base address
1107  * @param   statusFlag  Desired LPUART status flag to clear
1108  * @return  An error code or kStatus_Success
1109  */
1110 lpuart_status_t LPUART_HAL_ClearStatusFlag(uint32_t baseAddr, lpuart_status_flag_t statusFlag);
1111
1112 /*!
1113  * @brief  LPUART clears ALL status flags.
1114  *
1115  * @param baseAddr LPUART base address
1116  */
1117 void LPUART_HAL_ClearAllNonAutoclearStatusFlags(uint32_t baseAddr);
1118
1119 /*@}*/
1120
1121 #if defined(__cplusplus)
1122 }
1123 #endif
1124
1125 /*! @}*/
1126
1127 #endif /* MBED_NO_LPUART */
1128
1129 #endif /* __FSL_LPUART_HAL_H__ */
1130
1131 /*******************************************************************************
1132  * EOF
1133  ******************************************************************************/
1134