1 /*
2 * Copyright (c) 2015, 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 __UART_IMX_H__
32 #define __UART_IMX_H__
33
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <assert.h>
37 #include "device_imx.h"
38
39 /*!
40 * @addtogroup uart_imx_driver
41 * @{
42 */
43
44 /*******************************************************************************
45 * Definitions
46 ******************************************************************************/
47
48 /*! @brief Uart module initialization structure. */
49 typedef struct _uart_init_config
50 {
51 uint32_t clockRate; /*!< Current UART module clock freq. */
52 uint32_t baudRate; /*!< Desired UART baud rate. */
53 uint32_t wordLength; /*!< Data bits in one frame. */
54 uint32_t stopBitNum; /*!< Number of stop bits in one frame. */
55 uint32_t parity; /*!< Parity error check mode of this module. */
56 uint32_t direction; /*!< Data transfer direction of this module. */
57 } uart_init_config_t;
58
59 /*! @brief UART number of data bits in a character. */
60 enum _uart_word_length
61 {
62 uartWordLength7Bits = 0x0, /*!< One character has 7 bits. */
63 uartWordLength8Bits = UART_UCR2_WS_MASK, /*!< One character has 8 bits. */
64 };
65
66 /*! @brief UART number of stop bits. */
67 enum _uart_stop_bit_num
68 {
69 uartStopBitNumOne = 0x0, /*!< One bit Stop. */
70 uartStopBitNumTwo = UART_UCR2_STPB_MASK, /*!< Two bits Stop. */
71 };
72
73 /*! @brief UART parity mode. */
74 enum _uart_partity_mode
75 {
76 uartParityDisable = 0x0, /*!< Parity error check disabled. */
77 uartParityEven = UART_UCR2_PREN_MASK, /*!< Even error check is selected. */
78 uartParityOdd = UART_UCR2_PREN_MASK | UART_UCR2_PROE_MASK, /*!< Odd error check is selected. */
79 };
80
81 /*! @brief Data transfer direction. */
82 enum _uart_direction_mode
83 {
84 uartDirectionDisable = 0x0, /*!< Both Tx and Rx are disabled. */
85 uartDirectionTx = UART_UCR2_TXEN_MASK, /*!< Tx is enabled. */
86 uartDirectionRx = UART_UCR2_RXEN_MASK, /*!< Rx is enabled. */
87 uartDirectionTxRx = UART_UCR2_TXEN_MASK | UART_UCR2_RXEN_MASK, /*!< Both Tx and Rx are enabled. */
88 };
89
90 /*! @brief This enumeration contains the settings for all of the UART interrupt configurations. */
91 enum _uart_interrupt
92 {
93 uartIntAutoBaud = 0x0080000F, /*!< Automatic baud rate detection Interrupt Enable. */
94 uartIntTxReady = 0x0080000D, /*!< transmitter ready Interrupt Enable. */
95 uartIntIdle = 0x0080000C, /*!< IDLE Interrupt Enable. */
96 uartIntRxReady = 0x00800009, /*!< Receiver Ready Interrupt Enable. */
97 uartIntTxEmpty = 0x00800006, /*!< Transmitter Empty Interrupt Enable. */
98 uartIntRtsDelta = 0x00800005, /*!< RTS Delta Interrupt Enable. */
99 uartIntEscape = 0x0084000F, /*!< Escape Sequence Interrupt Enable. */
100 uartIntRts = 0x00840004, /*!< Request to Send Interrupt Enable. */
101 uartIntAgingTimer = 0x00840003, /*!< Aging Timer Interrupt Enable. */
102 uartIntDtr = 0x0088000D, /*!< Data Terminal Ready Interrupt Enable. */
103 uartIntParityError = 0x0088000C, /*!< Parity Error Interrupt Enable. */
104 uartIntFrameError = 0x0088000B, /*!< Frame Error Interrupt Enable. */
105 uartIntDcd = 0x00880009, /*!< Data Carrier Detect Interrupt Enable. */
106 uartIntRi = 0x00880008, /*!< Ring Indicator Interrupt Enable. */
107 uartIntRxDs = 0x00880006, /*!< Receive Status Interrupt Enable. */
108 uartInttAirWake = 0x00880005, /*!< Asynchronous IR WAKE Interrupt Enable. */
109 uartIntAwake = 0x00880004, /*!< Asynchronous WAKE Interrupt Enable. */
110 uartIntDtrDelta = 0x00880003, /*!< Data Terminal Ready Delta Interrupt Enable. */
111 uartIntAutoBaudCnt = 0x00880000, /*!< Autobaud Counter Interrupt Enable. */
112 uartIntIr = 0x008C0008, /*!< Serial Infrared Interrupt Enable. */
113 uartIntWake = 0x008C0007, /*!< WAKE Interrupt Enable. */
114 uartIntTxComplete = 0x008C0003, /*!< TransmitComplete Interrupt Enable. */
115 uartIntBreakDetect = 0x008C0002, /*!< BREAK Condition Detected Interrupt Enable. */
116 uartIntRxOverrun = 0x008C0001, /*!< Receiver Overrun Interrupt Enable. */
117 uartIntRxDataReady = 0x008C0000, /*!< Receive Data Ready Interrupt Enable. */
118 uartIntRs485SlaveAddrMatch = 0x00B80003, /*!< RS-485 Slave Address Detected Interrupt Enable. */
119 };
120
121 /*! @brief Flag for UART interrupt/DMA status check or polling status. */
122 enum _uart_status_flag
123 {
124 uartStatusRxCharReady = 0x0000000F, /*!< Rx Character Ready Flag. */
125 uartStatusRxError = 0x0000000E, /*!< Rx Error Detect Flag. */
126 uartStatusRxOverrunError = 0x0000000D, /*!< Rx Overrun Flag. */
127 uartStatusRxFrameError = 0x0000000C, /*!< Rx Frame Error Flag. */
128 uartStatusRxBreakDetect = 0x0000000B, /*!< Rx Break Detect Flag. */
129 uartStatusRxParityError = 0x0000000A, /*!< Rx Parity Error Flag. */
130 uartStatusParityError = 0x0094000F, /*!< Parity Error Interrupt Flag. */
131 uartStatusRtsStatus = 0x0094000E, /*!< RTS_B Pin Status Flag. */
132 uartStatusTxReady = 0x0094000D, /*!< Transmitter Ready Interrupt/DMA Flag. */
133 uartStatusRtsDelta = 0x0094000C, /*!< RTS Delta Flag. */
134 uartStatusEscape = 0x0094000B, /*!< Escape Sequence Interrupt Flag. */
135 uartStatusFrameError = 0x0094000A, /*!< Frame Error Interrupt Flag. */
136 uartStatusRxReady = 0x00940009, /*!< Receiver Ready Interrupt/DMA Flag. */
137 uartStatusAgingTimer = 0x00940008, /*!< Ageing Timer Interrupt Flag. */
138 uartStatusDtrDelta = 0x00940007, /*!< DTR Delta Flag. */
139 uartStatusRxDs = 0x00940006, /*!< Receiver IDLE Interrupt Flag. */
140 uartStatustAirWake = 0x00940005, /*!< Asynchronous IR WAKE Interrupt Flag. */
141 uartStatusAwake = 0x00940004, /*!< Asynchronous WAKE Interrupt Flag. */
142 uartStatusRs485SlaveAddrMatch = 0x00940003, /*!< RS-485 Slave Address Detected Interrupt Flag. */
143 uartStatusAutoBaud = 0x0098000F, /*!< Automatic Baud Rate Detect Complete Flag. */
144 uartStatusTxEmpty = 0x0098000E, /*!< Transmit Buffer FIFO Empty. */
145 uartStatusDtr = 0x0098000D, /*!< DTR edge triggered interrupt flag. */
146 uartStatusIdle = 0x0098000C, /*!< Idle Condition Flag. */
147 uartStatusAutoBaudCntStop = 0x0098000B, /*!< Autobaud Counter Stopped Flag. */
148 uartStatusRiDelta = 0x0098000A, /*!< Ring Indicator Delta Flag. */
149 uartStatusRi = 0x00980009, /*!< Ring Indicator Input Flag. */
150 uartStatusIr = 0x00980008, /*!< Serial Infrared Interrupt Flag. */
151 uartStatusWake = 0x00980007, /*!< Wake Flag. */
152 uartStatusDcdDelta = 0x00980006, /*!< Data Carrier Detect Delta Flag. */
153 uartStatusDcd = 0x00980005, /*!< Data Carrier Detect Input Flag. */
154 uartStatusRts = 0x00980004, /*!< RTS Edge Triggered Interrupt Flag. */
155 uartStatusTxComplete = 0x00980003, /*!< Transmitter Complete Flag. */
156 uartStatusBreakDetect = 0x00980002, /*!< BREAK Condition Detected Flag. */
157 uartStatusRxOverrun = 0x00980001, /*!< Overrun Error Flag. */
158 uartStatusRxDataReady = 0x00980000, /*!< Receive Data Ready Flag. */
159 };
160
161 /*! @brief The events generate the DMA Request. */
162 enum _uart_dma
163 {
164 uartDmaRxReady = 0x00800008, /*!< Receive Ready DMA Enable. */
165 uartDmaTxReady = 0x00800003, /*!< Transmitter Ready DMA Enable. */
166 uartDmaAgingTimer = 0x00800002, /*!< Aging DMA Timer Enable. */
167 uartDmaIdle = 0x008C0006, /*!< DMA IDLE Condition Detected Interrupt Enable. */
168 };
169
170 /*! @brief RTS pin interrupt trigger edge. */
171 enum _uart_rts_int_trigger_edge
172 {
173 uartRtsTriggerEdgeRising = UART_UCR2_RTEC(0), /*!< RTS pin interrupt triggered on rising edge. */
174 uartRtsTriggerEdgeFalling = UART_UCR2_RTEC(1), /*!< RTS pin interrupt triggered on falling edge. */
175 uartRtsTriggerEdgeBoth = UART_UCR2_RTEC(2), /*!< RTS pin interrupt triggered on both edge. */
176 };
177
178 /*! @brief UART module modem role selections. */
179 enum _uart_modem_mode
180 {
181 uartModemModeDce = 0, /*!< UART module works as DCE. */
182 uartModemModeDte = UART_UFCR_DCEDTE_MASK, /*!< UART module works as DTE. */
183 };
184
185 /*! @brief DTR pin interrupt trigger edge. */
186 enum _uart_dtr_int_trigger_edge
187 {
188 uartDtrTriggerEdgeRising = UART_UCR3_DPEC(0), /*!< DTR pin interrupt triggered on rising edge. */
189 uartDtrTriggerEdgeFalling = UART_UCR3_DPEC(1), /*!< DTR pin interrupt triggered on falling edge. */
190 uartDtrTriggerEdgeBoth = UART_UCR3_DPEC(2), /*!< DTR pin interrupt triggered on both edge. */
191 };
192
193 /*! @brief IrDA vote clock selections. */
194 enum _uart_irda_vote_clock
195 {
196 uartIrdaVoteClockSampling = 0x0, /*!< The vote logic uses the sampling clock (16x baud rate) for normal operation. */
197 uartIrdaVoteClockReference = UART_UCR4_IRSC_MASK, /*!< The vote logic uses the UART reference clock. */
198 };
199
200 /*! @brief UART module Rx Idle condition selections. */
201 enum _uart_rx_idle_condition
202 {
203 uartRxIdleMoreThan4Frames = UART_UCR1_ICD(0), /*!< Idle for more than 4 frames. */
204 uartRxIdleMoreThan8Frames = UART_UCR1_ICD(1), /*!< Idle for more than 8 frames. */
205 uartRxIdleMoreThan16Frames = UART_UCR1_ICD(2), /*!< Idle for more than 16 frames. */
206 uartRxIdleMoreThan32Frames = UART_UCR1_ICD(3), /*!< Idle for more than 32 frames. */
207 };
208
209 /*******************************************************************************
210 * API
211 ******************************************************************************/
212
213 #if defined(__cplusplus)
214 extern "C" {
215 #endif
216
217 /*!
218 * @name UART Initialization and Configuration functions
219 * @{
220 */
221
222 /*!
223 * @brief Initialize UART module with given initialization structure.
224 *
225 * @param base UART base pointer.
226 * @param initConfig UART initialization structure (see @ref uart_init_config_t structure above).
227 */
228 void UART_Init(UART_Type* base, const uart_init_config_t* initConfig);
229
230 /*!
231 * @brief This function reset UART module register content to its default value.
232 *
233 * @param base UART base pointer.
234 */
235 void UART_Deinit(UART_Type* base);
236
237 /*!
238 * @brief This function is used to Enable the UART Module.
239 *
240 * @param base UART base pointer.
241 */
UART_Enable(UART_Type * base)242 static inline void UART_Enable(UART_Type* base)
243 {
244 UART_UCR1_REG(base) |= UART_UCR1_UARTEN_MASK;
245 }
246
247 /*!
248 * @brief This function is used to Disable the UART Module.
249 *
250 * @param base UART base pointer.
251 */
UART_Disable(UART_Type * base)252 static inline void UART_Disable(UART_Type* base)
253 {
254 UART_UCR1_REG(base) &= ~UART_UCR1_UARTEN_MASK;
255 }
256
257 /*!
258 * @brief This function is used to set the baud rate of UART Module.
259 *
260 * @param base UART base pointer.
261 * @param clockRate UART module clock frequency.
262 * @param baudRate Desired UART module baud rate.
263 */
264 void UART_SetBaudRate(UART_Type* base, uint32_t clockRate, uint32_t baudRate);
265
266 /*!
267 * @brief This function is used to set the transform direction of UART Module.
268 *
269 * @param base UART base pointer.
270 * @param direction UART transfer direction (see @ref _uart_direction_mode enumeration).
271 */
UART_SetDirMode(UART_Type * base,uint32_t direction)272 static inline void UART_SetDirMode(UART_Type* base, uint32_t direction)
273 {
274 assert((direction & uartDirectionTx) || (direction & uartDirectionRx));
275
276 UART_UCR2_REG(base) = (UART_UCR2_REG(base) & ~(UART_UCR2_RXEN_MASK | UART_UCR2_TXEN_MASK)) | direction;
277 }
278
279 /*!
280 * @brief This function is used to set the number of frames RXD is allowed to
281 * be idle before an idle condition is reported. The available condition
282 * can be select from @ref _uart_idle_condition enumeration.
283 *
284 * @param base UART base pointer.
285 * @param idleCondition The condition that an idle condition is reported
286 * (see @ref _uart_idle_condition enumeration).
287 */
UART_SetRxIdleCondition(UART_Type * base,uint32_t idleCondition)288 static inline void UART_SetRxIdleCondition(UART_Type* base, uint32_t idleCondition)
289 {
290 assert(idleCondition <= uartRxIdleMoreThan32Frames);
291
292 UART_UCR1_REG(base) = (UART_UCR1_REG(base) & ~UART_UCR1_ICD_MASK) | idleCondition;
293 }
294
295 /*!
296 * @brief This function is used to set the polarity of UART signal. The polarity
297 * of Tx and Rx can be set separately.
298 *
299 * @param base UART base pointer.
300 * @param direction UART transfer direction (see @ref _uart_direction_mode enumeration).
301 * @param invert Set true to invert the polarity of UART signal.
302 */
303 void UART_SetInvertCmd(UART_Type* base, uint32_t direction, bool invert);
304
305 /*@}*/
306
307 /*!
308 * @name Low Power Mode functions.
309 * @{
310 */
311
312 /*!
313 * @brief This function is used to set UART enable condition in the DOZE state.
314 *
315 * @param base UART base pointer.
316 * @param enable Enable/Disable UART module in doze mode.
317 * - true: Enable UART module in doze mode.
318 * - false: Disable UART module in doze mode.
319 */
320 void UART_SetDozeMode(UART_Type* base, bool enable);
321
322 /*!
323 * @brief This function is used to set UART enable condition of the UART low power feature.
324 *
325 * @param base UART base pointer.
326 * @param enable Enable/Disable UART module low power feature.
327 * - true: Enable UART module low power feature.
328 * - false: Disable UART module low power feature.
329 */
330 void UART_SetLowPowerMode(UART_Type* base, bool enable);
331
332 /*@}*/
333
334 /*!
335 * @name Data transfer functions.
336 * @{
337 */
338
339 /*!
340 * @brief This function is used to send data in RS-232 and IrDA Mode.
341 * A independent 9 Bits RS-485 send data function is provided.
342 *
343 * @param base UART base pointer.
344 * @param data Data to be set through UART module.
345 */
UART_Putchar(UART_Type * base,uint8_t data)346 static inline void UART_Putchar(UART_Type* base, uint8_t data)
347 {
348 UART_UTXD_REG(base) = (data & UART_UTXD_TX_DATA_MASK);
349 }
350
351 /*!
352 * @brief This function is used to receive data in RS-232 and IrDA Mode.
353 * A independent 9 Bits RS-485 receive data function is provided.
354 *
355 * @param base UART base pointer.
356 * @return The data received from UART module.
357 */
UART_Getchar(UART_Type * base)358 static inline uint8_t UART_Getchar(UART_Type* base)
359 {
360 return (uint8_t)(UART_URXD_REG(base) & UART_URXD_RX_DATA_MASK);
361 }
362
363 /*@}*/
364
365 /*!
366 * @name Interrupt and Flag control functions.
367 * @{
368 */
369
370 /*!
371 * @brief This function is used to set the enable condition of
372 * specific UART interrupt source. The available interrupt
373 * source can be select from @ref _uart_interrupt enumeration.
374 *
375 * @param base UART base pointer.
376 * @param intSource Available interrupt source for this module.
377 * @param enable Enable/Disable corresponding interrupt.
378 * - true: Enable corresponding interrupt.
379 * - false: Disable corresponding interrupt.
380 */
381 void UART_SetIntCmd(UART_Type* base, uint32_t intSource, bool enable);
382
383 /*!
384 * @brief This function is used to get the current status of specific
385 * UART status flag(including interrupt flag). The available
386 * status flag can be select from @ref _uart_status_flag enumeration.
387 *
388 * @param base UART base pointer.
389 * @param flag Status flag to check.
390 * @return current state of corresponding status flag.
391 */
UART_GetStatusFlag(UART_Type * base,uint32_t flag)392 static inline bool UART_GetStatusFlag(UART_Type* base, uint32_t flag){
393 volatile uint32_t* uart_reg = 0;
394
395 uart_reg = (uint32_t *)((uint32_t)base + (flag >> 16));
396 return (bool)((*uart_reg >> (flag & 0x0000FFFF)) & 0x1);
397 }
398
399 /*!
400 * @brief This function is used to get the current status
401 * of specific UART status flag. The available status
402 * flag can be select from @ref _uart_status_flag enumeration.
403 *
404 * @param base UART base pointer.
405 * @param flag Status flag to clear.
406 */
407 void UART_ClearStatusFlag(UART_Type* base, uint32_t flag);
408
409 /*@}*/
410
411 /*!
412 * @name DMA control functions.
413 * @{
414 */
415
416 /*!
417 * @brief This function is used to set the enable condition of
418 * specific UART DMA source. The available DMA source
419 * can be select from @ref _uart_dma enumeration.
420 *
421 * @param base UART base pointer.
422 * @param dmaSource The Event that can generate DMA request.
423 * @param enable Enable/Disable corresponding DMA source.
424 * - true: Enable corresponding DMA source.
425 * - false: Disable corresponding DMA source.
426 */
427 void UART_SetDmaCmd(UART_Type* base, uint32_t dmaSource, bool enable);
428
429 /*@}*/
430
431 /*!
432 * @name FIFO control functions.
433 * @{
434 */
435
436 /*!
437 * @brief This function is used to set the watermark of UART Tx FIFO.
438 * A maskable interrupt is generated whenever the data level in
439 * the TxFIFO falls below the Tx FIFO watermark.
440 *
441 * @param base UART base pointer.
442 * @param watermark The Tx FIFO watermark.
443 */
UART_SetTxFifoWatermark(UART_Type * base,uint8_t watermark)444 static inline void UART_SetTxFifoWatermark(UART_Type* base, uint8_t watermark)
445 {
446 assert((watermark >= 2) && (watermark <= 32));
447 UART_UFCR_REG(base) = (UART_UFCR_REG(base) & ~UART_UFCR_TXTL_MASK) | UART_UFCR_TXTL(watermark);
448 }
449
450 /*!
451 * @brief This function is used to set the watermark of UART Rx FIFO.
452 * A maskable interrupt is generated whenever the data level in
453 * the RxFIFO reaches the Rx FIFO watermark.
454 *
455 * @param base UART base pointer.
456 * @param watermark The Rx FIFO watermark.
457 */
UART_SetRxFifoWatermark(UART_Type * base,uint8_t watermark)458 static inline void UART_SetRxFifoWatermark(UART_Type* base, uint8_t watermark)
459 {
460 assert(watermark <= 32);
461 UART_UFCR_REG(base) = (UART_UFCR_REG(base) & ~UART_UFCR_RXTL_MASK) | UART_UFCR_RXTL(watermark);
462 }
463
464 /*@}*/
465
466 /*!
467 * @name Hardware Flow control and Modem Signal functions.
468 * @{
469 */
470
471 /*!
472 * @brief This function is used to set the enable condition of RTS
473 * Hardware flow control.
474 *
475 * @param base UART base pointer.
476 * @param enable Enable/Disbale RTS hardware flow control.
477 * - true: Enable RTS hardware flow control.
478 * - false: Disbale RTS hardware flow control.
479 */
480 void UART_SetRtsFlowCtrlCmd(UART_Type* base, bool enable);
481
482 /*!
483 * @brief This function is used to set the RTS interrupt trigger edge.
484 * The available trigger edge can be select from
485 * @ref _uart_rts_trigger_edge enumeration.
486 *
487 * @param base UART base pointer.
488 * @param triggerEdge Available RTS pin interrupt trigger edge.
489 */
UART_SetRtsIntTriggerEdge(UART_Type * base,uint32_t triggerEdge)490 static inline void UART_SetRtsIntTriggerEdge(UART_Type* base, uint32_t triggerEdge)
491 {
492 assert((triggerEdge == uartRtsTriggerEdgeRising) || \
493 (triggerEdge == uartRtsTriggerEdgeFalling) || \
494 (triggerEdge == uartRtsTriggerEdgeBoth));
495
496 UART_UCR2_REG(base) = (UART_UCR2_REG(base) & ~UART_UCR2_RTEC_MASK) | triggerEdge;
497 }
498
499
500 /*!
501 * @brief This function is used to set the enable condition of CTS
502 * auto control. if CTS control is enabled, the CTS_B pin
503 * is controlled by the receiver, otherwise the CTS_B pin is
504 * controlled by UART_CTSPinCtrl function.
505 *
506 * @param base UART base pointer.
507 * @param enable Enable/Disable CTS auto control.
508 * - true: Enable CTS auto control.
509 * - false: Disable CTS auto control.
510 */
511 void UART_SetCtsFlowCtrlCmd(UART_Type* base, bool enable);
512
513 /*!
514 * @brief This function is used to control the CTS_B pin state when
515 * auto CTS control is disabled.
516 * The CTS_B pin is low(active)
517 * The CTS_B pin is high(inactive)
518 *
519 * @param base UART base pointer.
520 * @param active The CTS_B pin state to set.
521 * - true: the CTS_B pin active;
522 * - false: the CTS_B pin inactive.
523 */
524 void UART_SetCtsPinLevel(UART_Type* base, bool active);
525
526 /*!
527 * @brief This function is used to set the auto CTS_B pin control
528 * trigger level. The CTS_B pin is de-asserted when
529 * Rx FIFO reach CTS trigger level.
530 *
531 * @param base UART base pointer.
532 * @param triggerLevel Auto CTS_B pin control trigger level.
533 */
UART_SetCtsTriggerLevel(UART_Type * base,uint8_t triggerLevel)534 static inline void UART_SetCtsTriggerLevel(UART_Type* base, uint8_t triggerLevel)
535 {
536 assert(triggerLevel <= 32);
537 UART_UCR4_REG(base) = (UART_UCR4_REG(base) & ~UART_UCR4_CTSTL_MASK) | UART_UCR4_CTSTL(triggerLevel);
538 }
539
540 /*!
541 * @brief This function is used to set the role (DTE/DCE) of UART module
542 * in RS-232 communication.
543 *
544 * @param base UART base pointer.
545 * @param mode The role(DTE/DCE) of UART module (see @ref _uart_modem_mode enumeration).
546 */
547 void UART_SetModemMode(UART_Type* base, uint32_t mode);
548
549 /*!
550 * @brief This function is used to set the edge of DTR_B (DCE) or
551 * DSR_B (DTE) on which an interrupt is generated.
552 *
553 * @param base UART base pointer.
554 * @param triggerEdge The trigger edge on which an interrupt is generated
555 * (see @ref _uart_dtr_trigger_edge enumeration above).
556 */
UART_SetDtrIntTriggerEdge(UART_Type * base,uint32_t triggerEdge)557 static inline void UART_SetDtrIntTriggerEdge(UART_Type* base, uint32_t triggerEdge)
558 {
559 assert((triggerEdge == uartDtrTriggerEdgeRising) || \
560 (triggerEdge == uartDtrTriggerEdgeFalling) || \
561 (triggerEdge == uartDtrTriggerEdgeBoth));
562
563 UART_UCR3_REG(base) = (UART_UCR3_REG(base) & ~UART_UCR3_DPEC_MASK) | triggerEdge;
564 }
565
566 /*!
567 * @brief This function is used to set the pin state of DSR pin(for DCE mode)
568 * or DTR pin(for DTE mode) for the modem interface.
569 *
570 * @param base UART base pointer.
571 * @param active The state of DSR pin.
572 * - true: DSR/DTR pin is logic one.
573 * - false: DSR/DTR pin is logic zero.
574 */
575 void UART_SetDtrPinLevel(UART_Type* base, bool active);
576
577 /*!
578 * @brief This function is used to set the pin state of
579 * DCD pin. THIS FUNCTION IS FOR DCE MODE ONLY.
580 *
581 * @param base UART base pointer.
582 * @param active The state of DCD pin.
583 * - true: DCD_B pin is logic one (DCE mode)
584 * - false: DCD_B pin is logic zero (DCE mode)
585 */
586 void UART_SetDcdPinLevel(UART_Type* base, bool active);
587
588 /*!
589 * @brief This function is used to set the pin state of
590 * RI pin. THIS FUNCTION IS FOR DCE MODE ONLY.
591 *
592 * @param base UART base pointer.
593 * @param active The state of RI pin.
594 * - true: RI_B pin is logic one (DCE mode)
595 * - false: RI_B pin is logic zero (DCE mode)
596 */
597 void UART_SetRiPinLevel(UART_Type* base, bool active);
598
599 /*@}*/
600
601 /*!
602 * @name Multiprocessor and RS-485 functions.
603 * @{
604 */
605
606 /*!
607 * @brief This function is used to send 9 Bits length data in
608 * RS-485 Multidrop mode.
609 *
610 * @param base UART base pointer.
611 * @param data Data(9 bits) to be set through UART module.
612 */
613 void UART_Putchar9(UART_Type* base, uint16_t data);
614
615 /*!
616 * @brief This functions is used to receive 9 Bits length data in
617 * RS-485 Multidrop mode.
618 *
619 * @param base UART base pointer.
620 * @return The data(9 bits) received from UART module.
621 */
622 uint16_t UART_Getchar9(UART_Type* base);
623
624 /*!
625 * @brief This function is used to set the enable condition of
626 * 9-Bits data or Multidrop mode.
627 *
628 * @param base UART base pointer.
629 * @param enable Enable/Disable Multidrop mode.
630 * - true: Enable Multidrop mode.
631 * - false: Disable Multidrop mode.
632 */
633 void UART_SetMultidropMode(UART_Type* base, bool enable);
634
635 /*!
636 * @brief This function is used to set the enable condition of
637 * Automatic Address Detect Mode.
638 *
639 * @param base UART base pointer.
640 * @param enable Enable/Disable Automatic Address Detect mode.
641 * - true: Enable Automatic Address Detect mode.
642 * - false: Disable Automatic Address Detect mode.
643 */
644 void UART_SetSlaveAddressDetectCmd(UART_Type* base, bool enable);
645
646 /*!
647 * @brief This function is used to set the slave address char
648 * that the receiver tries to detect.
649 *
650 * @param base UART base pointer.
651 * @param slaveAddress The slave to detect.
652 */
UART_SetSlaveAddress(UART_Type * base,uint8_t slaveAddress)653 static inline void UART_SetSlaveAddress(UART_Type* base, uint8_t slaveAddress)
654 {
655 UART_UMCR_REG(base) = (UART_UMCR_REG(base) & ~UART_UMCR_SLADDR_MASK) | \
656 UART_UMCR_SLADDR(slaveAddress);
657 }
658
659 /*@}*/
660
661 /*!
662 * @name IrDA control functions.
663 * @{
664 */
665
666 /*!
667 * @brief This function is used to set the enable condition of
668 * IrDA Mode.
669 *
670 * @param base UART base pointer.
671 * @param enable Enable/Disable IrDA mode.
672 * - true: Enable IrDA mode.
673 * - false: Disable IrDA mode.
674 */
675 void UART_SetIrDACmd(UART_Type* base, bool enable);
676
677 /*!
678 * @brief This function is used to set the clock for the IR pulsed
679 * vote logic. The available clock can be select from
680 * @ref _uart_irda_vote_clock enumeration.
681 *
682 * @param base UART base pointer.
683 * @param voteClock The available IrDA vote clock selection.
684 */
685 void UART_SetIrDAVoteClock(UART_Type* base, uint32_t voteClock);
686
687 /*@}*/
688
689 /*!
690 * @name Misc. functions.
691 * @{
692 */
693
694 /*!
695 * @brief This function is used to set the enable condition of
696 * Automatic Baud Rate Detection feature.
697 *
698 * @param base UART base pointer.
699 * @param enable Enable/Disable Automatic Baud Rate Detection feature.
700 * - true: Enable Automatic Baud Rate Detection feature.
701 * - false: Disable Automatic Baud Rate Detection feature.
702 */
703 void UART_SetAutoBaudRateCmd(UART_Type* base, bool enable);
704
705 /*!
706 * @brief This function is used to read the current value of Baud Rate
707 * Count Register value. this counter is used by Auto Baud Rate
708 * Detect feature.
709 *
710 * @param base UART base pointer.
711 * @return Current Baud Rate Count Register value.
712 */
UART_ReadBaudRateCount(UART_Type * base)713 static inline uint16_t UART_ReadBaudRateCount(UART_Type* base)
714 {
715 return (uint16_t)(UART_UBRC_REG(base) & UART_UBRC_BCNT_MASK);
716 }
717
718 /*!
719 * @brief This function is used to send BREAK character.It is
720 * important that SNDBRK is asserted high for a sufficient
721 * period of time to generate a valid BREAK.
722 *
723 * @param base UART base pointer.
724 * @param active Asserted high to generate BREAK.
725 * - true: Generate BREAK character.
726 * - false: Stop generate BREAK character.
727 */
728 void UART_SendBreakChar(UART_Type* base, bool active);
729
730 /*!
731 * @brief This function is used to Enable/Disable the Escape
732 * Sequence Decection feature.
733 *
734 * @param base UART base pointer.
735 * @param enable Enable/Disable Escape Sequence Decection.
736 * - true: Enable Escape Sequence Decection.
737 * - false: Disable Escape Sequence Decection.
738 */
739 void UART_SetEscapeDecectCmd(UART_Type* base, bool enable);
740
741 /*!
742 * @brief This function is used to set the enable condition of
743 * Escape Sequence Detection feature.
744 *
745 * @param base UART base pointer.
746 * @param escapeChar The Escape Character to detect.
747 */
UART_SetEscapeChar(UART_Type * base,uint8_t escapeChar)748 static inline void UART_SetEscapeChar(UART_Type* base, uint8_t escapeChar)
749 {
750 UART_UESC_REG(base) = (UART_UESC_REG(base) & ~UART_UESC_ESC_CHAR_MASK) | \
751 UART_UESC_ESC_CHAR(escapeChar);
752 }
753
754 /*!
755 * @brief This function is used to set the maximum time interval (in ms)
756 * allowed between escape characters.
757 *
758 * @param base UART base pointer.
759 * @param timerInterval Maximum time interval allowed between escape characters.
760 */
UART_SetEscapeTimerInterval(UART_Type * base,uint16_t timerInterval)761 static inline void UART_SetEscapeTimerInterval(UART_Type* base, uint16_t timerInterval)
762 {
763 assert(timerInterval <= 0xFFF);
764 UART_UTIM_REG(base) = (UART_UTIM_REG(base) & ~UART_UTIM_TIM_MASK) | \
765 UART_UTIM_TIM(timerInterval);
766 }
767
768 /*@}*/
769
770 #ifdef __cplusplus
771 }
772 #endif
773
774 /*! @}*/
775
776 #endif /* __UART_IMX_H__ */
777 /*******************************************************************************
778 * EOF
779 ******************************************************************************/
780