1 /**************************************************************************//**
2  * @file     lpuart.h
3  * @version  V3.00
4  * @brief    M2L31 series LPUART Interface Controller (LPUART) driver header file
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8  *****************************************************************************/
9 #ifndef __LPUART_H__
10 #define __LPUART_H__
11 
12 
13 #ifdef __cplusplus
14 extern "C"
15 {
16 #endif
17 
18 
19 /** @addtogroup Standard_Driver Standard Driver
20   @{
21 */
22 
23 /** @addtogroup LPUART_Driver LPUART Driver
24   @{
25 */
26 
27 /** @addtogroup LPUART_EXPORTED_CONSTANTS LPUART Exported Constants
28   @{
29 */
30 
31 /*---------------------------------------------------------------------------------------------------------*/
32 /* LPUART FIFO size constants definitions                                                                    */
33 /*---------------------------------------------------------------------------------------------------------*/
34 #define LPUART0_FIFO_SIZE 16UL /*!< LPUART0 supports separated receive/transmit 16/16 bytes entry FIFO */
35 
36 /*---------------------------------------------------------------------------------------------------------*/
37 /* LPUART_FIFO constants definitions                                                                         */
38 /*---------------------------------------------------------------------------------------------------------*/
39 #define LPUART_FIFO_RFITL_1BYTE      (0x0UL << LPUART_FIFO_RFITL_Pos)   /*!< LPUART_FIFO setting to set RX FIFO Trigger Level to 1 byte */
40 #define LPUART_FIFO_RFITL_4BYTES     (0x1UL << LPUART_FIFO_RFITL_Pos)   /*!< LPUART_FIFO setting to set RX FIFO Trigger Level to 4 bytes */
41 #define LPUART_FIFO_RFITL_8BYTES     (0x2UL << LPUART_FIFO_RFITL_Pos)   /*!< LPUART_FIFO setting to set RX FIFO Trigger Level to 8 bytes */
42 #define LPUART_FIFO_RFITL_14BYTES    (0x3UL << LPUART_FIFO_RFITL_Pos)   /*!< LPUART_FIFO setting to set RX FIFO Trigger Level to 14 bytes */
43 
44 #define LPUART_FIFO_RTSTRGLV_1BYTE      (0x0UL << LPUART_FIFO_RTSTRGLV_Pos)  /*!< LPUART_FIFO setting to set RTS Trigger Level to 1 byte */
45 #define LPUART_FIFO_RTSTRGLV_4BYTES     (0x1UL << LPUART_FIFO_RTSTRGLV_Pos)  /*!< LPUART_FIFO setting to set RTS Trigger Level to 4 bytes */
46 #define LPUART_FIFO_RTSTRGLV_8BYTES     (0x2UL << LPUART_FIFO_RTSTRGLV_Pos)  /*!< LPUART_FIFO setting to set RTS Trigger Level to 8 bytes */
47 #define LPUART_FIFO_RTSTRGLV_14BYTES    (0x3UL << LPUART_FIFO_RTSTRGLV_Pos)  /*!< LPUART_FIFO setting to set RTS Trigger Level to 14 bytes */
48 
49 /*---------------------------------------------------------------------------------------------------------*/
50 /* LPUART_LINE constants definitions                                                                         */
51 /*---------------------------------------------------------------------------------------------------------*/
52 #define LPUART_WORD_LEN_5     (0UL) /*!< LPUART_LINE setting to set LPUART word length to 5 bits */
53 #define LPUART_WORD_LEN_6     (1UL) /*!< LPUART_LINE setting to set LPUART word length to 6 bits */
54 #define LPUART_WORD_LEN_7     (2UL) /*!< LPUART_LINE setting to set LPUART word length to 7 bits */
55 #define LPUART_WORD_LEN_8     (3UL) /*!< LPUART_LINE setting to set LPUART word length to 8 bits */
56 
57 #define LPUART_PARITY_NONE    (0x0UL << LPUART_LINE_PBE_Pos) /*!< LPUART_LINE setting to set LPUART as no parity   */
58 #define LPUART_PARITY_ODD     (0x1UL << LPUART_LINE_PBE_Pos) /*!< LPUART_LINE setting to set LPUART as odd parity  */
59 #define LPUART_PARITY_EVEN    (0x3UL << LPUART_LINE_PBE_Pos) /*!< LPUART_LINE setting to set LPUART as even parity */
60 #define LPUART_PARITY_MARK    (0x5UL << LPUART_LINE_PBE_Pos) /*!< LPUART_LINE setting to keep parity bit as '1'  */
61 #define LPUART_PARITY_SPACE   (0x7UL << LPUART_LINE_PBE_Pos) /*!< LPUART_LINE setting to keep parity bit as '0'  */
62 
63 #define LPUART_STOP_BIT_1     (0x0UL << LPUART_LINE_NSB_Pos) /*!< LPUART_LINE setting for one stop bit */
64 #define LPUART_STOP_BIT_1_5   (0x1UL << LPUART_LINE_NSB_Pos) /*!< LPUART_LINE setting for 1.5 stop bit when 5-bit word length */
65 #define LPUART_STOP_BIT_2     (0x1UL << LPUART_LINE_NSB_Pos) /*!< LPUART_LINE setting for two stop bit when 6, 7, 8-bit word length */
66 
67 
68 /*---------------------------------------------------------------------------------------------------------*/
69 /* LPUART RTS ACTIVE LEVEL constants definitions                                                           */
70 /*---------------------------------------------------------------------------------------------------------*/
71 #define LPUART_RTS_IS_LOW_LEV_ACTIVE   (0x1UL << LPUART_MODEM_RTSACTLV_Pos) /*!< Set RTS is Low Level Active */
72 #define LPUART_RTS_IS_HIGH_LEV_ACTIVE  (0x0UL << LPUART_MODEM_RTSACTLV_Pos) /*!< Set RTS is High Level Active */
73 
74 /*---------------------------------------------------------------------------------------------------------*/
75 /* LPUART_FUNCSEL constants definitions                                                                    */
76 /*---------------------------------------------------------------------------------------------------------*/
77 #define LPUART_FUNCSEL_LPUART  (0x0UL << LPUART_FUNCSEL_FUNCSEL_Pos)       /*!< LPUART_FUNCSEL setting to set LPUART Function (Default) */
78 #define LPUART_FUNCSEL_RS485 (0x3UL << LPUART_FUNCSEL_FUNCSEL_Pos)       /*!< LPUART_FUNCSEL setting to set RS485 Function          */
79 #define LPUART_FUNCSEL_SINGLE_WIRE (0x4ul << LPUART_FUNCSEL_FUNCSEL_Pos) /*!< LPUART_FUNCSEL setting to set Single Wire Function   \hideinitializer */
80 
81 /*---------------------------------------------------------------------------------------------------------*/
82 /* LPUART BAUDRATE MODE constants definitions                                                              */
83 /*---------------------------------------------------------------------------------------------------------*/
84 #define LPUART_BAUD_MODE0     (0UL) /*!< Set LPUART Baudrate Mode is Mode0 */
85 #define LPUART_BAUD_MODE1     (LPUART_BAUD_BAUDM1_Msk)
86 #define LPUART_BAUD_MODE2     (LPUART_BAUD_BAUDM1_Msk | LPUART_BAUD_BAUDM0_Msk) /*!< Set LPUART Baudrate Mode is Mode2 */
87 
88 /*---------------------------------------------------------------------------------------------------------*/
89 /* LPUART AUTOCTL constants definitions                                                           */
90 /*---------------------------------------------------------------------------------------------------------*/
91 #define LPUART_AUTOCTL_TRIGSEL_LPTMR0   (0x0UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is LPTMR0 \hideinitializer */
92 #define LPUART_AUTOCTL_TRIGSEL_LPTMR1   (0x1UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is LPTMR1 \hideinitializer */
93 #define LPUART_AUTOCTL_TRIGSEL_TTMR0    (0x2UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is TTMR0 \hideinitializer */
94 #define LPUART_AUTOCTL_TRIGSEL_TTMR1    (0x3UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is TTMR1 \hideinitializer */
95 #define LPUART_AUTOCTL_TRIGSEL_WKIOA0   (0x4UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is WKIOA0 \hideinitializer */
96 #define LPUART_AUTOCTL_TRIGSEL_WKIOB0   (0x5UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is WKIOB0 \hideinitializer */
97 #define LPUART_AUTOCTL_TRIGSEL_WKIOC0   (0x6UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is WKIOC0 \hideinitializer */
98 #define LPUART_AUTOCTL_TRIGSEL_WKIOD0   (0x7UL << LPUART_AUTOCTL_TRIGSEL_Pos) /*!< LPUART Automatic Operation Trigger Source Select is WKIOD0 \hideinitializer */
99 
100 
101 /**@}*/ /* end of group LPUART_EXPORTED_CONSTANTS */
102 
103 
104 /** @addtogroup LPUART_EXPORTED_FUNCTIONS LPUART Exported Functions
105   @{
106 */
107 
108 
109 /**
110  *    @brief        Calculate LPUART baudrate mode0 divider
111  *
112  *    @param[in]    u32SrcFreq      LPUART clock frequency
113  *    @param[in]    u32BaudRate     Baudrate of LPUART module
114  *
115  *    @return       LPUART baudrate mode0 divider
116  *
117  *    @details      This macro calculate LPUART baudrate mode0 divider.
118  *    \hideinitializer
119  */
120 #define LPUART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate)    ((((u32SrcFreq) + ((u32BaudRate)*8ul)) / (u32BaudRate) >> 4ul)-2ul)
121 
122 
123 /**
124  *    @brief        Calculate LPUART baudrate mode2 divider
125  *
126  *    @param[in]    u32SrcFreq      LPUART clock frequency
127  *    @param[in]    u32BaudRate     Baudrate of LPUART module
128  *
129  *    @return       LPUART baudrate mode2 divider
130  *
131  *    @details      This macro calculate LPUART baudrate mode2 divider.
132  *    \hideinitializer
133  */
134 #define LPUART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate)    ((((u32SrcFreq) + ((u32BaudRate)/2ul)) / (u32BaudRate))-2ul)
135 
136 
137 /**
138  *    @brief        Write LPUART data
139  *
140  *    @param[in]    lpuart    The pointer of the specified LPUART module
141  *    @param[in]    u8Data  Data byte to transmit.
142  *
143  *    @return       None
144  *
145  *    @details      This macro write Data to Tx data register.
146  *    \hideinitializer
147  */
148 #define LPUART_WRITE(lpuart, u8Data)    ((lpuart)->DAT = (u8Data))
149 
150 
151 /**
152  *    @brief        Read LPUART data
153  *
154  *    @param[in]    lpuart    The pointer of the specified LPUART module
155  *
156  *    @return       The oldest data byte in RX FIFO.
157  *
158  *    @details      This macro read Rx data register.
159  *    \hideinitializer
160  */
161 #define LPUART_READ(lpuart)    ((lpuart)->DAT)
162 
163 
164 /**
165  *    @brief        Get Tx empty
166  *
167  *    @param[in]    lpuart    The pointer of the specified LPUART module
168  *
169  *    @retval       0   Tx FIFO is not empty
170  *    @retval       >=1 Tx FIFO is empty
171  *
172  *    @details      This macro get Transmitter FIFO empty register value.
173  *    \hideinitializer
174  */
175 #define LPUART_GET_TX_EMPTY(lpuart)    ((lpuart)->FIFOSTS & LPUART_FIFOSTS_TXEMPTY_Msk)
176 
177 
178 /**
179  *    @brief        Get Rx empty
180  *
181  *    @param[in]    lpuart    The pointer of the specified LPUART module
182  *
183  *    @retval       0   Rx FIFO is not empty
184  *    @retval       >=1 Rx FIFO is empty
185  *
186  *    @details      This macro get Receiver FIFO empty register value.
187  *    \hideinitializer
188  */
189 #define LPUART_GET_RX_EMPTY(lpuart)    ((lpuart)->FIFOSTS & LPUART_FIFOSTS_RXEMPTY_Msk)
190 
191 
192 /**
193  *    @brief        Check specified lpuart port transmission is over.
194  *
195  *    @param[in]    lpuart    The pointer of the specified LPUART module
196  *
197  *    @retval       0 Tx transmission is not over
198  *    @retval       1 Tx transmission is over
199  *
200  *    @details      This macro return Transmitter Empty Flag register bit value.
201  *                  It indicates if specified lpuart port transmission is over nor not.
202  *    \hideinitializer
203  */
204 #define LPUART_IS_TX_EMPTY(lpuart)    (((lpuart)->FIFOSTS & LPUART_FIFOSTS_TXEMPTYF_Msk) >> LPUART_FIFOSTS_TXEMPTYF_Pos)
205 
206 
207 /**
208  *    @brief        Wait specified lpuart port transmission is over
209  *
210  *    @param[in]    lpuart    The pointer of the specified LPUART module
211  *
212  *    @return       None
213  *
214  *    @details      This macro wait specified lpuart port transmission is over.
215  *    \hideinitializer
216  */
217 #define LPUART_WAIT_TX_EMPTY(lpuart)    while(!((((lpuart)->FIFOSTS) & LPUART_FIFOSTS_TXEMPTYF_Msk) >> LPUART_FIFOSTS_TXEMPTYF_Pos))
218 
219 
220 /**
221  *    @brief        Check RX is ready or not
222  *
223  *    @param[in]    lpuart    The pointer of the specified LPUART module
224  *
225  *    @retval       0 The number of bytes in the RX FIFO is less than the RFITL
226  *    @retval       1 The number of bytes in the RX FIFO equals or larger than RFITL
227  *
228  *    @details      This macro check receive data available interrupt flag is set or not.
229  *    \hideinitializer
230  */
231 #define LPUART_IS_RX_READY(lpuart)    (((lpuart)->INTSTS & LPUART_INTSTS_RDAIF_Msk)>>LPUART_INTSTS_RDAIF_Pos)
232 
233 
234 /**
235  *    @brief        Check TX FIFO is full or not
236  *
237  *    @param[in]    lpuart    The pointer of the specified LPUART module
238  *
239  *    @retval       1 TX FIFO is full
240  *    @retval       0 TX FIFO is not full
241  *
242  *    @details      This macro check TX FIFO is full or not.
243  *    \hideinitializer
244  */
245 #define LPUART_IS_TX_FULL(lpuart)    (((lpuart)->FIFOSTS & LPUART_FIFOSTS_TXFULL_Msk)>>LPUART_FIFOSTS_TXFULL_Pos)
246 
247 
248 /**
249  *    @brief        Check RX FIFO is full or not
250  *
251  *    @param[in]    lpuart    The pointer of the specified LPUART module
252  *
253  *    @retval       1 RX FIFO is full
254  *    @retval       0 RX FIFO is not full
255  *
256  *    @details      This macro check RX FIFO is full or not.
257  *    \hideinitializer
258  */
259 #define LPUART_IS_RX_FULL(lpuart)    (((lpuart)->FIFOSTS & LPUART_FIFOSTS_RXFULL_Msk)>>LPUART_FIFOSTS_RXFULL_Pos)
260 
261 
262 /**
263  *    @brief        Get Tx full register value
264  *
265  *    @param[in]    lpuart    The pointer of the specified LPUART module
266  *
267  *    @retval       0   Tx FIFO is not full.
268  *    @retval       >=1 Tx FIFO is full.
269  *
270  *    @details      This macro get Tx full register value.
271  *    \hideinitializer
272  */
273 #define LPUART_GET_TX_FULL(lpuart)    ((lpuart)->FIFOSTS & LPUART_FIFOSTS_TXFULL_Msk)
274 
275 
276 /**
277  *    @brief        Get Rx full register value
278  *
279  *    @param[in]    lpuart    The pointer of the specified LPUART module
280  *
281  *    @retval       0   Rx FIFO is not full.
282  *    @retval       >=1 Rx FIFO is full.
283  *
284  *    @details      This macro get Rx full register value.
285  *    \hideinitializer
286  */
287 #define LPUART_GET_RX_FULL(lpuart)    ((lpuart)->FIFOSTS & LPUART_FIFOSTS_RXFULL_Msk)
288 
289 /**
290  *    @brief        Rx Idle Status register value
291  *
292  *    @param[in]    lpuart    The pointer of the specified LPUART module
293  *
294  *    @retval       0 Rx is busy.
295  *    @retval       1 Rx is Idle(Default)
296  *
297  *    @details      This macro get Rx Idle Status register value.
298  *    \hideinitializer
299  */
300 #define LPUART_RX_IDLE(lpuart) (((lpuart)->FIFOSTS & LPUART_FIFOSTS_RXIDLE_Msk )>> LPUART_FIFOSTS_RXIDLE_Pos)
301 
302 
303 /**
304  *    @brief        Enable specified LPUART interrupt
305  *
306  *    @param[in]    lpuart        The pointer of the specified LPUART module
307  *    @param[in]    u32eIntSel  Interrupt type select
308  *                              - \ref LPUART_INTEN_TXENDIEN_Msk   : Transmitter empty interrupt
309  *                              - \ref LPUART_INTEN_ABRIEN_Msk     : Auto baud rate interrupt
310  *                              - \ref LPUART_INTEN_WKIEN_Msk      : Wake-up interrupt
311  *                              - \ref LPUART_INTEN_BUFERRIEN_Msk  : Buffer Error interrupt
312  *                              - \ref LPUART_INTEN_RXTOIEN_Msk    : Rx time-out interrupt
313  *                              - \ref LPUART_INTEN_MODEMIEN_Msk   : Modem interrupt
314  *                              - \ref LPUART_INTEN_RLSIEN_Msk     : Rx Line status interrupt
315  *                              - \ref LPUART_INTEN_THREIEN_Msk    : Tx empty interrupt
316  *                              - \ref LPUART_INTEN_RDAIEN_Msk     : Rx ready interrupt
317  *
318  *    @return       None
319  *
320  *    @details      This macro enable specified LPUART interrupt.
321  *    \hideinitializer
322  */
323 #define LPUART_ENABLE_INT(lpuart, u32eIntSel)    ((lpuart)->INTEN |= (u32eIntSel))
324 
325 
326 /**
327  *    @brief        Disable specified LPUART interrupt
328  *
329  *    @param[in]    lpuart        The pointer of the specified LPUART module
330  *    @param[in]    u32eIntSel  Interrupt type select
331  *                              - \ref LPUART_INTEN_TXENDIEN_Msk   : Transmitter Empty Interrupt
332  *                              - \ref LPUART_INTEN_ABRIEN_Msk     : Auto-baud Rate Interrupt
333  *                              - \ref LPUART_INTEN_WKIEN_Msk      : Wake-up interrupt
334  *                              - \ref LPUART_INTEN_BUFERRIEN_Msk  : Buffer Error interrupt
335  *                              - \ref LPUART_INTEN_RXTOIEN_Msk    : Rx Time-out Interrupt
336  *                              - \ref LPUART_INTEN_MODEMIEN_Msk   : MODEM Status Interrupt
337  *                              - \ref LPUART_INTEN_RLSIEN_Msk     : Receive Line Status Interrupt
338  *                              - \ref LPUART_INTEN_THREIEN_Msk    : Transmit Holding Register Empty Interrupt
339  *                              - \ref LPUART_INTEN_RDAIEN_Msk     : Receive Data Available Interrupt
340  *
341  *    @return       None
342  *
343  *    @details      This macro disable specified LPUART interrupt.
344  *    \hideinitializer
345  */
346 #define LPUART_DISABLE_INT(lpuart, u32eIntSel)    ((lpuart)->INTEN &= ~ (u32eIntSel))
347 
348 
349 /**
350  *    @brief        Get specified interrupt flag/status
351  *
352  *    @param[in]    lpuart            The pointer of the specified LPUART module
353  *    @param[in]    u32eIntTypeFlag Interrupt Type Flag, should be
354  *                                  - \ref LPUART_INTSTS_ABRINT_Msk    : Auto-baud Rate Interrupt Indicator
355  *                                  - \ref LPUART_INTSTS_TXENDINT_Msk  : Transmitter Empty Interrupt Indicator
356  *                                  - \ref LPUART_INTSTS_HWBUFEINT_Msk : PDMA Mode Buffer Error Interrupt Indicator
357  *                                  - \ref LPUART_INTSTS_HWTOINT_Msk   : PDMA Mode Rx Time-out Interrupt Indicator
358  *                                  - \ref LPUART_INTSTS_HWMODINT_Msk  : PDMA Mode MODEM Status Interrupt Indicator
359  *                                  - \ref LPUART_INTSTS_HWRLSINT_Msk  : PDMA Mode Receive Line Status Interrupt Indicator
360  *                                  - \ref LPUART_INTSTS_TXENDIF_Msk   : Transmitter Empty Interrupt Flag
361  *                                  - \ref LPUART_INTSTS_HWBUFEIF_Msk  : PDMA Mode Buffer Error Interrupt Flag
362  *                                  - \ref LPUART_INTSTS_HWTOIF_Msk    : PDMA Mode Time-out Interrupt Flag
363  *                                  - \ref LPUART_INTSTS_HWMODIF_Msk   : PDMA Mode MODEM Status Interrupt Flag
364  *                                  - \ref LPUART_INTSTS_HWRLSIF_Msk   : PDMA Mode Receive Line Status Flag
365  *                                  - \ref LPUART_INTSTS_WKINT_Msk     : Wake-up Interrupt Indicator
366  *                                  - \ref LPUART_INTSTS_BUFERRINT_Msk : Buffer Error Interrupt Indicator
367  *                                  - \ref LPUART_INTSTS_RXTOINT_Msk   : Rx Time-out Interrupt Indicator
368  *                                  - \ref LPUART_INTSTS_MODEMINT_Msk  : Modem Status Interrupt Indicator
369  *                                  - \ref LPUART_INTSTS_RLSINT_Msk    : Receive Line Status Interrupt Indicator
370  *                                  - \ref LPUART_INTSTS_THREINT_Msk   : Transmit Holding Register Empty Interrupt Indicator
371  *                                  - \ref LPUART_INTSTS_RDAINT_Msk    : Receive Data Available Interrupt Indicator
372  *                                  - \ref LPUART_INTSTS_WKIF_Msk      : Wake-up Interrupt Flag
373  *                                  - \ref LPUART_INTSTS_BUFERRIF_Msk  : Buffer Error Interrupt Flag
374  *                                  - \ref LPUART_INTSTS_RXTOIF_Msk    : Rx Time-out Interrupt Flag
375  *                                  - \ref LPUART_INTSTS_MODEMIF_Msk   : MODEM Status Interrupt Flag
376  *                                  - \ref LPUART_INTSTS_RLSIF_Msk     : Receive Line Status Interrupt Flag
377  *                                  - \ref LPUART_INTSTS_THREIF_Msk    : Transmit Holding Register Empty Interrupt Flag
378  *                                  - \ref LPUART_INTSTS_RDAIF_Msk     : Receive Data Available Interrupt Flag
379  *
380  *    @retval       0 The specified interrupt is not happened.
381  *                  1 The specified interrupt is happened.
382  *
383  *    @details      This macro get specified interrupt flag or interrupt indicator status.
384  *    \hideinitializer
385  */
386 #define LPUART_GET_INT_FLAG(lpuart,u32eIntTypeFlag)    (((lpuart)->INTSTS & (u32eIntTypeFlag))?1:0)
387 
388 /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */
389 static __INLINE void LPUART_CLEAR_RTS(LPUART_T* lpuart);
390 static __INLINE void LPUART_SET_RTS(LPUART_T* lpuart);
391 
392 
393 /**
394  *    @brief        Set RTS pin to low
395  *
396  *    @param[in]    lpuart    The pointer of the specified LPUART module
397  *
398  *    @return       None
399  *
400  *    @details      This macro set RTS pin to low.
401  *    \hideinitializer
402  */
LPUART_CLEAR_RTS(LPUART_T * lpuart)403 __STATIC_INLINE void LPUART_CLEAR_RTS(LPUART_T* lpuart)
404 {
405     lpuart->MODEM |= LPUART_MODEM_RTSACTLV_Msk;
406     lpuart->MODEM &= ~LPUART_MODEM_RTS_Msk;
407 }
408 
409 
410 /**
411  *    @brief        Set RTS pin to high
412  *
413  *    @param[in]    lpuart    The pointer of the specified LPUART module
414  *
415  *    @return       None
416  *
417  *    @details      This macro set RTS pin to high.
418  *    \hideinitializer
419  */
LPUART_SET_RTS(LPUART_T * lpuart)420 __STATIC_INLINE void LPUART_SET_RTS(LPUART_T* lpuart)
421 {
422     lpuart->MODEM |= LPUART_MODEM_RTSACTLV_Msk | LPUART_MODEM_RTS_Msk;
423 }
424 
425 
426 /**
427  *    @brief        Clear RS-485 Address Byte Detection Flag
428  *
429  *    @param[in]    lpuart    The pointer of the specified LPUART module
430  *
431  *    @return       None
432  *
433  *    @details      This macro clear RS-485 address byte detection flag.
434  */
435 #define LPUART_RS485_CLEAR_ADDR_FLAG(lpuart)    ((lpuart)->FIFOSTS = LPUART_FIFOSTS_ADDRDETF_Msk)
436 
437 
438 /**
439  *    @brief        Get RS-485 Address Byte Detection Flag
440  *
441  *    @param[in]    lpuart    The pointer of the specified LPUART module
442  *
443  *    @retval       0 Receiver detects a data that is not an address bit.
444  *    @retval       1 Receiver detects a data that is an address bit.
445  *
446  *    @details      This macro get RS-485 address byte detection flag.
447  */
448 #define LPUART_RS485_GET_ADDR_FLAG(lpuart)    (((lpuart)->FIFOSTS  & LPUART_FIFOSTS_ADDRDETF_Msk) >> LPUART_FIFOSTS_ADDRDETF_Pos)
449 
450 
451 /**
452  *    @brief        Enable specified LPUART PDMA function
453  *
454  *    @param[in]    lpuart        The pointer of the specified LPUART module
455  *    @param[in]    u32FuncSel  Combination of following functions
456  *                             - \ref LPUART_INTEN_TXPDMAEN_Msk
457  *                             - \ref LPUART_INTEN_RXPDMAEN_Msk
458  *
459  *    @return       None
460  *
461  *    @details      This macro enable specified LPUART PDMA function.
462  */
463 #define LPUART_PDMA_ENABLE(lpuart, u32FuncSel)    ((lpuart)->INTEN |= (u32FuncSel))
464 
465 
466 /**
467  *    @brief        Disable specified LPUART PDMA function
468  *
469  *    @param[in]    lpuart        The pointer of the specified LPUART module
470  *    @param[in]    u32FuncSel  Combination of following functions
471  *                             - \ref LPUART_INTEN_TXPDMAEN_Msk
472  *                             - \ref LPUART_INTEN_RXPDMAEN_Msk
473  *
474  *    @return       None
475  *
476  *    @details      This macro disable specified LPUART PDMA function.
477  */
478 #define LPUART_PDMA_DISABLE(lpuart, u32FuncSel)    ((lpuart)->INTEN &= ~(u32FuncSel))
479 
480 
481 void LPUART_ClearIntFlag(LPUART_T* lpuart, uint32_t u32InterruptFlag);
482 void LPUART_Close(LPUART_T* lpuart);
483 void LPUART_DisableFlowCtrl(LPUART_T* lpuart);
484 void LPUART_DisableInt(LPUART_T*  lpuart, uint32_t u32InterruptFlag);
485 void LPUART_EnableFlowCtrl(LPUART_T* lpuart);
486 void LPUART_EnableInt(LPUART_T*  lpuart, uint32_t u32InterruptFlag);
487 void LPUART_Open(LPUART_T* lpuart, uint32_t u32baudrate);
488 uint32_t LPUART_Read(LPUART_T* lpuart, uint8_t pu8RxBuf[], uint32_t u32ReadBytes);
489 void LPUART_SetLine_Config(LPUART_T* lpuart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t  u32stop_bits);
490 void LPUART_SetTimeoutCnt(LPUART_T* lpuart, uint32_t u32TOC);
491 void LPUART_SelectRS485Mode(LPUART_T* lpuart, uint32_t u32Mode, uint32_t u32Addr);
492 uint32_t LPUART_Write(LPUART_T* lpuart, uint8_t pu8TxBuf[], uint32_t u32WriteBytes);
493 void LPUART_SelectSingleWireMode(LPUART_T *lpuart);
494 
495 /**@}*/ /* end of group LPUART_EXPORTED_FUNCTIONS */
496 
497 /**@}*/ /* end of group LPUART_Driver */
498 
499 /**@}*/ /* end of group Standard_Driver */
500 
501 #ifdef __cplusplus
502 }
503 #endif
504 
505 #endif /* __LPUART_H__ */
506