tao_z
2022-06-01 73bf3cdb517b55f662ed5fa513cdaaf55c1fd0c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/**
  ******************************************************************************
  * @file     xl_uart.h
  * @author   software group
  * @brief    This file contains all the functions prototypes for the USART 
  *           firmware library.
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
    
/* Define to prevent recursive inclusion -------------------------------------*/      
#ifndef __XL_UART_H
#define __XL_UART_H
 
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ---------------------------------------------------------------*/
#include "xl6600.h"
#pragma anon_unions /* added by neo, to support union function */
    
/* Register define ------------------------------------------------------------*/
 
/* RBR Bit Fields */                                
#define UART_RBR_RDB_MASK                       0xFFu
#define UART_RBR_RDB_SHIFT                      0
 
/* THR Bit Fields */                                     
#define UART_THR_TDH_MASK                       0xFFu
#define UART_THR_TDH_SHIFT                      0
 
/* DLH Bit Fields */                                                    
#define UART_DLH_BRD_MASK                       0xFFu
#define UART_DLH_BRD_SHIFT                      0
 
/* DLL Bit Fields */                                                    
#define UART_DLL_BRD_MASK                       0xFFu
#define UART_DLL_BRD_SHIFT                      0
 
/* IER Bit Fields */
#define UART_IER_ERBFI_MASK                     0x1u
#define UART_IER_ERBFI_SHIFT                    0
 
#define UART_IER_ETBEI_MASK                     0x2u
#define UART_IER_ETBEI_SHIFT                    1
 
#define UART_IER_ELSI_MASK                      0x4u
#define UART_IER_ELSI_SHIFT                     1
 
#define UART_IER_EDSSI_MASK                      0x8u
#define UART_IER_EDSSI_SHIFT                     1
 
#define UART_IER_PTIME_MASK                     0x80u
#define UART_IER_PTIME_SHIFT                    7
 
/* IIR Bit Fields */                                                    
#define UART_IIR_IID_MASK                       0xFu
#define UART_IIR_IID_SHIFT                      0
 
#define UART_IIR_FIFOSE_MASK                    0xC0u
#define UART_IIR_FIFOSE_SHIFT                   6
 
/* FCR Bit Fields */
#define UART_FCR_FIFOE_MASK                     0x1u
#define UART_FCR_FIFOE_SHIFT                    0
 
#define UART_FCR_TET_MASK                       0x30u
#define UART_FCR_TET_SHIFT                      4
 
#define UART_FCR_RT_MASK                        0xC0u
#define UART_FCR_RT_SHIFT                       6
 
/* LCR Bit Fields */                
#define UART_LCR_DLS_MASK                       0x3u
#define UART_LCR_DLS_SHIFT                      0
 
#define UART_LCR_STOP_MASK                      0x4u
#define UART_LCR_STOP_SHIFT                     2
 
#define UART_LCR_PEN_MASK                       0x8u
#define UART_LCR_PEN_SHIFT                      3
 
#define UART_LCR_EPS_MASK                       0x10u
#define UART_LCR_EPS_SHIFT                      4
 
#define UART_LCR_SP_MASK                        0x20u
#define UART_LCR_SP_SHIFT                       5
 
#define UART_LCR_BRK13_MASK                        0x40u
#define UART_LCR_BRK13_SHIFT                       6
 
#define UART_LCR_DLAB_MASK                      0x80u
#define UART_LCR_DLAB_SHIFT                     7
 
/* LSR Bit Fields */                
#define UART_LSR_DR_MASK                        0x1u
#define UART_LSR_DR_SHIFT                       0
 
#define UART_LSR_OE_MASK                        0x2u
#define UART_LSR_OE_SHIFT                       1
 
#define UART_LSR_PE_MASK                        0x4u
#define UART_LSR_PE_SHIFT                       2
 
#define UART_LSR_FE_MASK                        0x8u
#define UART_LSR_FE_SHIFT                       3
 
#define UART_LSR_BI_MASK                        0x10u
#define UART_LSR_BI_SHIFT                       4
 
#define UART_LSR_THRE_MASK                      0x20u
#define UART_LSR_THRE_SHIFT                     5
 
#define UART_LSR_TEMT_MASK                      0x40u
#define UART_LSR_TEMT_SHIFT                     6
 
#define UART_LSR_RFE_MASK                       0x80u
#define UART_LSR_RFE_SHIFT                      7
 
/* PATTERN Bit Fields */      
#define UART_PATTERN_BC_MASK                 0x80u
#define UART_PATTERN_BC_SHIFT                7
 
/* USR Bit Fields */        
#define UART_USR_BUSY_MASK                      0x1u
#define UART_USR_BUSY_SHIFT                     0
 
#define UART_USR_TFNF_MASK                      0x2u
#define UART_USR_TFNF_SHIFT                     1
 
#define UART_USR_TFE_MASK                       0x4u
#define UART_USR_TFE_SHIFT                      2
 
#define UART_USR_RFNE_MASK                      0x8u
#define UART_USR_RFNE_SHIFT                     3
 
#define UART_USR_RFF_MASK                       0x10u
#define UART_USR_RFF_SHIFT                      4
 
#define UART_USR_IDLE_MASK                       0x80u
#define UART_USR_IDLE_SHIFT                      7
 
/* TFL Bit Fields */                                                    
#define UART_TFL_TFIFOL_MASK                    0x7Fu
#define UART_TFL_TFIFOL_SHIFT                   0
 
/* RFL Bit Fields */                                                    
#define UART_RFL_RFIFOL_MASK                    0x7Fu
#define UART_RFL_RFIFOL_SHIFT                   0
 
/* HTX Bit Fields */                                                    
#define UART_HTX_HTX_MASK                       0x1u
#define UART_HTX_HTX_SHIFT                      0
 
/* DMASA Bit Fields */                                                    
#define UART_DMASA_DMASA_MASK                   0x1u
#define UART_DMASA_DMASA_SHIFT                  0
 
/* SGW Bit Fields */
#define UART_SGW_TXDIR_MASK                     0x1u
#define UART_SGW_TXDIR_SHIFT                    0
 
#define UART_SGW_EN_MASK                                                0x02u
#define UART_SGW_EN_SHIFT                       1
 
#define UART_SGW_RSRC_MASK                      0x4u
#define UART_SGW_RSRC_SHIFT                     2
 
#define UART_SGW_LOOPS_MASK                     0x8u
#define UART_SGW_LOOPS_SHIFT                    3
 
/** UART - Register Layout Typedef */
typedef struct {
    union {
     __I  uint32_t       RBR;                      /*!< ½ÓÊÕ»º´æ¼Ä´æÆ÷, offset:0x00*/
     __O  uint32_t       THR;                      /*!< ·¢Ëͱ£³Ö¼Ä´æÆ÷, offset:0x00*/
     __IO uint32_t       DLL;                      /*!< ²¨ÌØÂʼĴæÆ÷µÍλ, offset:0x00*/
    };
    union {
     __IO uint32_t       DLH;                      /*!< ²¨ÌØÂʼĴæÆ÷¸ßλ, offset:0x04*/
     __IO uint32_t       IER;                      /*!< ÖжÏʹÄܼĴæÆ÷, offset:0x04*/
    };
    union {
     __I  uint32_t       IIR;                      /*!< Öжϱêʶ¼Ä´æÆ÷, offset:0x08*/
     __O  uint32_t       FCR;                      /*!< FIFO¿ØÖƼĴæÆ÷, offset:0x08*/
    };
    __IO uint32_t        LCR;                      /*!< Ïß·¿ØÖƼĴæÆ÷, offset:0x0C*/
       uint32_t RESERVED_0[1];
    __I  uint32_t        LSR;                      /*!< Ïß·״̬¼Ä´æÆ÷, offset:0x14*/
       uint32_t RESERVED_1[10];
    __IO uint32_t        PATTERN;                         /*!< UART/LINģʽѡÔñ¼Ä´æÆ÷, offset:0x40*/
             uint32_t RESERVED_2[14];
    __I  uint32_t        USR;                      /*!< UART״̬¼Ä´æÆ÷, offset:0x7C*/
    __I  uint32_t        TFL;                      /*!< ·¢ËÍFIFO¼ÆÊý¼Ä´æÆ÷, offset:0x80*/
    __I  uint32_t        RFL;                      /*!< ½ÓÊÕFIFO¼ÆÊý¼Ä´æÆ÷, offset:0x84*/
       uint32_t RESERVED_3[7];        
    __IO uint32_t        HTX;                      /*!< ÔÝÍ£TX, offset:0xA4*/
    __O  uint32_t        DMASA;                    /*!< DMAÈí¼þÈ·ÈϼĴæÆ÷, offset:0xA8*/
    uint32_t RESERVED_4[5];    
    __O uint32_t DLF;                              /*!< Ð¡Êý²¨ÌØÂʼĴæÆ÷, offset:0xA8*/
    uint32_t RESERVED_5[15];    
    __IO uint32_t        SGW;                      /*!< µ¥ÏßģʽºÍ»·»ØÄ£Ê½, offset:0x100*/
    
}UART_Type;
 
extern UART_Type*          UART0;
extern UART_Type*          UART1;
extern UART_Type*          UART2;    
 
 
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @addtogroup UART 
  * @{
  */
 
/* Exported types ------------------------------------------------------------*/ 
/** 
  * @brief UART³õʼ»¯½á¹¹Ì嶨Òå
  */
typedef struct
{
    uint32_t UART_SourceClk;          /*!< uartʱÖÓÆµÂÊ */
    uint32_t UART_BaudRate;           /*!<  Í¨Ñ¶²¨ÌØÂÊ */
    uint8_t  UART_DataLength;         /*!< uartÊý¾Ý³¤¶È */  
    uint8_t  UART_StopBits;           /*!< uartֹͣλ    */
    uint8_t  UART_Parity;             /*!< uartУÑéλ */
    uint8_t  UART_TET;                  /*!< TX¿Õ´¥·¢¡£ÕâÓÃÓÚÑ¡Ôñ²úÉúTHREÖжϵĿÕãÐÖµµçƽ */
    uint8_t  UART_RT;                 /*!< RCVR´¥·¢¡£ÓÃÓÚÑ¡ÔñÉú³É½ÓÊÕÊý¾Ý×¼±¸ºÃÖжϵĽÓÊÕFIFO´¥·¢Ë®Æ½ */
} UART_InitTypeDef;
 
/** 
  * @brief UART FIFO³õʼ»¯½á¹¹Ì嶨Òå
  */
typedef struct
{
    uint8_t  UART_TET;                  /*!< select the empty threshold level at which the THRE Interrupts aregenerated when the mode is active */
    uint8_t  UART_RT;                 /*!< select the trigger level in the receiver FIFO at which the Received Data Available Interrupt is generated. In */
    uint8_t  UART_FIFO_Enable;
}UART_FIFOInitTypeDef;
/* Exported constants --------------------------------------------------------*/
/** @defgroup UART_Exported_Constants UARTÄ£¿éʹÓòÎÊý¶¨Òå
  * @{
  */
 
/**
    * @defgroup Data_Length_Select UARTÊý¾Ý붨Òå
    * @{
    */
#define UART_DataLength_5b                               ((uint8_t)0x00)   /*!< 5λ */
#define UART_DataLength_6b                               ((uint8_t)0x01)   /*!< 6λ */
#define UART_DataLength_7b                               ((uint8_t)0x02)   /*!< 7λ */
#define UART_DataLength_8b                               ((uint8_t)0x03)   /*!< 8λ */
/**
  * @}
  */ 
  
/**
    * @defgroup Stop_Bits_Select UARTֹͣ붨Òå
    * @{
    */
#define UART_StopBits_1                                  ((uint8_t)0x00)   /*!< 1¸öֹͣλ */
#define UART_StopBits_2                                  ((uint8_t)0x04)   /*!< µ±DLS£¨LCR [1£º0]£©Îª0ʱΪ1¨D1.5¸öֹͣ룬·ñÔòΪ2¸öֹͣλ */
/**
  * @}
  */    
 
    
/**
    * @defgroup Parity_Bits_Select UARTУÑé붨Òå
    * @{
    */    
#define UART_Parity_No                                   ((uint8_t)0x00)   /*!< Ð£ÑéλʧÄÜ */
#define UART_Parity_Odd                                  ((uint8_t)0x08)   /*!< ÆæÐ£Ñé */
#define UART_Parity_Even                                 ((uint8_t)0x18)   /*!< Å¼Ð£Ñé */
#define UART_StickParity_Odd                             ((uint8_t)0x28)   /*!< ·¢ËÍ»ò¼ì²éÆæÊý¸öÊý */
#define UART_StickParity_Even                            ((uint8_t)0x38)   /*!< ·¢ËÍ»ò¼ì²éżÊý¸öÊý  */
/**
  * @}
  */
 
/**
    * @defgroup RX_FIFO_LEV UART½ÓÊÕFIFOÉî¶È¶¨Òå
    * @{
    */    
#define UART_RxFIFO_1Char                              ((uint8_t)0x00)   /*!< ½ÓÊÕFIFOÉî¶ÈΪ1×Ö½Ú */
#define UART_RxFIFO_4Char                              ((uint8_t)0x40)   /*!< ½ÓÊÕFIFOÉî¶ÈΪ4×Ö½Ú */
#define UART_RxFIFO_8Char                              ((uint8_t)0x80)   /*!< ½ÓÊÕFIFOÉî¶ÈΪ8×Ö½Ú */
#define UART_RxFIFO_14Char                          ((uint8_t)0xC0)   /*!< ½ÓÊÕFIFOÉî¶ÈΪ14×Ö½Ú */
/**
  * @}
  */ 
    
/**
    * @defgroup TX_FIFO_LEV UART·¢ËÍFIFOÉî¶È¶¨Òå
    * @{
    */    
#define UART_TxFIFO_0Char                              ((uint8_t)0x00)   /*!< ·¢ËÍFIFOÉî¶ÈΪ0×Ö½Ú */
#define UART_TxFIFO_2Char                              ((uint8_t)0x10)   /*!< ·¢ËÍFIFOÉî¶ÈΪ2×Ö½Ú */
#define UART_TxFIFO_4Char                              ((uint8_t)0x20)   /*!< ·¢ËÍFIFOÉî¶ÈΪ4×Ö½Ú */
#define UART_TxFIFO_8Char                              ((uint8_t)0x30)   /*!< ·¢ËÍFIFOÉî¶ÈΪ8×Ö½Ú */
/**
  * @}
  */ 
        
/**
    * @defgroup LIN_BreakLenght_Select LINͬ²½¼ä¸ô¶Î³¤¶ÈÑ¡Ôñ
    * @{
    */    
#define UART_LINBreakLength_10b              ((uint8_t)0x00)   /* ÖÁÉÙÉú³É10bitͬ²½¼ä¸ô¶Î³¤¶È */
#define UART_LINBreakLength_13b              ((uint8_t)0x40)   /* ÖÁÉÙÉú³É13bitͬ²½¼ä¸ô¶Î³¤¶È */
/**
 .. * @}
  */ 
 
 
/**
    * @defgroup UART_Interrupt_Select UARTʹÄÜÖжÏÀàÐͶ¨Òå
    * @{
    */
#define UART_RDataAvailableIntEN                            ((uint8_t)0x01)   /* ½ÓÊÕÊý¾Ý¿ÉÓÃÖжϠ*/
#define UART_THoldingEmptyIntEN                                ((uint8_t)0x02)   /* ·¢Ëͱ£³Ö¼Ä´æÆ÷¿ÕÖжϠ*/
#define UART_RLineStatusIntEN                                ((uint8_t)0x04)     /* ½ÓÊÕÏß·״̬ÖжϠ*/
#define UART_ModenStatusIntEN                                ((uint8_t)0x08)     /* µ÷ÖÆ½âµ÷Æ÷״̬ÖжϠ*/
#define UART_THREIntEN                                        ((uint8_t)0x80)       /* THREÖжϠ*/
/**
  * @}
  */ 
      
/**
    * @defgroup UART_Interrupt_ID UARTײ¶ÏÀàÐͶ¨Òå
    * @{
    */
#define UART_IID_NONE                                                    ((uint8_t)0x01)   /* ÎÞÖжϵȴý */
#define UART_IID_TxHoldingEmpty                                ((uint8_t)0x02)   /* THRΪ¿Õ */
#define UART_IID_RxDataAvailable                            ((uint8_t)0x04)   /* ½ÓÊÕµÄÊý¾Ý¿ÉÓà*/
#define UART_IID_RxLineStatus                                    ((uint8_t)0x06)   /* ½ÓÊÕÏß·״̬ */
#define UART_IID_Busy                                                    ((uint8_t)0x07)   /* Ã¦ÖжϠ*/
#define UART_IID_Overtime                                            ((uint8_t)0x0C)   /* ×Ö·û³¬Ê± */
/**
  * @}
  */  
    
/**
    * @defgroup UART_Status_Select UART״̬ÀàÐͶ¨Òå
    * @{
    */
#define UART_Busy                                                            ((uint8_t)0x00)   /* UARTæ */
#define UART_TransmitFIFONotFull                            ((uint8_t)0x01)   /* ·¢ËÍFIFOδÂú */
#define UART_TransmitFIFOEmpty                                ((uint8_t)0x02)   /* ·¢ËÍFIFOΪ¿Õ */
#define UART_ReceiveFIFONotEmpty                            ((uint8_t)0x03)   /* ½ÓÊÕFIFO²»Îª¿Õ */
#define UART_ReceiveFIFOFull                                    ((uint8_t)0x04)   /* ½ÓÊÕFIFOÂú */
#define UART_BusIdle                                                    ((uint8_t)0x07)   /* UART×ÜÏß´¦ÓÚIDLE״̬ */
/**
  * @}
  */ 
 
/**
    * @defgroup UART_LineStatus_Select  UARTÏß·״̬ÀàÐͶ¨Òå
    * @{
    */    
#define UART_LSRDataReady                                            ((uint8_t)0x00)   /* Êý¾Ý×¼±¸ºÃ */
#define UART_LSROverrunErr                                        ((uint8_t)0x01)   /* Òç³ö´íÎó */
#define UART_LSRParityErr                                            ((uint8_t)0x02)   /* ÆæÅ¼Ð£Ñé´íÎó */
#define UART_LSRFrameErr                                            ((uint8_t)0x03)   /* Ö¡´íÎó */
#define UART_LSRBreakIntr                                            ((uint8_t)0x04)   /* ¼ä¸ô·û¼ì²âÖжϠ*/
#define UART_LSRTHREmpty                                            ((uint8_t)0x05)   /* ·¢Ëͱ£³Ö¼Ä´æÆ÷Ϊ¿Õλ */
#define UART_LSRTransmitterEmpty                            ((uint8_t)0x06)   /* ·¢ËÍÆ÷¿Õ */
#define UART_LSRReceiverFIFOErr                                ((uint8_t)0x07)   /* ½ÓÊÕÆ÷FIFO´íÎó */
/**
  * @}
  */ 
  
/**
    * @defgroup UART_SingleLineDir_Seclect UARTµ¥ÏßģʽÏÂÉèÖÃUARTxÍâÉèTxDÒý½Å·½Ïò  
  * @{
    */        
#define UART_SingleLineDirection_Input                ((uint8_t)0x00)   /* Êý¾Ý×¼±¸ºÃ */
#define UART_SingleLineDirection_Output                ((uint8_t)0x01)   /* Òç³ö´íÎó */
/**
  * @}
  */ 
 
/**
    * @defgroup UART_Mode_Seclect ÉèÖÃUARTxÍâÉèģʽ 
    * @{
    */    
#define UART_Mode_Normal                                            ((uint8_t)0x00)   /* Êý¾Ý×¼±¸ºÃ */
#define UART_Mode_SingleLine                                    ((uint8_t)0x01)   /* Òç³ö´íÎó */
#define UART_Mode_Loop                                                ((uint8_t)0x02)   /* Òç³ö´íÎó */
/**
  * @}
  */ 
 
/**
  * @}
  */
    
 
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void UART_DeInit(UART_Type* UARTx);
void UART_Init(UART_Type* UARTx, const UART_InitTypeDef* UART_InitStruct);
void UART_FIFOInit(UART_Type* UARTx, const UART_FIFOInitTypeDef* UART_FIFOInitStruct);
FunctionalState UART_GetFIFOEnableStatus(const UART_Type* UARTx);
void UART_EnableCmd(UART_Type* UARTx, FunctionalState State);
void UART_SendLinBreak(UART_Type* UARTx);
void UART_LINBreakLengthConfig(UART_Type *UARTx, uint8_t UART_BreakLength);
void UART_SendData(UART_Type *UARTx,uint8_t Data);
uint8_t UART_ReceiveData(const UART_Type *UARTx);
void UART_EnableInterruptCmd(UART_Type *UARTx, uint8_t UART_Interrupt, FunctionalState State);
FlagStatus UART_GetInterruptCmd(const UART_Type *UARTx, uint8_t UART_Interrupt);
uint8_t UART_GetInterruptStatus (const UART_Type *UARTx);
void UART_EnableHaltTransmitCmd(UART_Type *UARTx, FunctionalState State);
uint8_t UART_GetTxFIFOLevel(const UART_Type *UARTx);
uint8_t UART_GetRxFIFOLevel(const UART_Type *UARTx);
FlagStatus UART_GetStatus(const UART_Type *UARTx, uint8_t UART_StatusType);
FlagStatus UART_GetLineStatus(const UART_Type *UARTx,uint8_t UART_LineStatusType);
void UART_SingleLineDirectionConfig(UART_Type *UARTx, bool_t UART_SingleLineDirection);
void UART_SetMode(UART_Type *UARTx , uint8_t UART_ModeType);
void UART_DMASoftwareAckEnableCmd(UART_Type *UARTx, FunctionalState State);
#ifdef __cplusplus
}
#endif
    
#endif /*__XL_UART_H */
/**
  * @}
  */
 
/**
  * @}
  */
 
 
 
 
/************************ (C) COPYRIGHT Chipways *****END OF FILE****/