dw_usart.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file dw_usart.h
  18. * @brief header file for usart driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef __DW_USART_H
  23. #define __DW_USART_H
  24. #include <stdio.h>
  25. #include "errno.h"
  26. #include "soc.h"
  27. #define BAUDRATE_DEFAULT 19200
  28. #define UART_BUSY_TIMEOUT 1000000
  29. #define UART_RECEIVE_TIMEOUT 1000
  30. #define UART_TRANSMIT_TIMEOUT 1000
  31. #define UART_MAX_FIFO 0x10
  32. /* UART register bit definitions */
  33. #define USR_UART_BUSY 0x01
  34. #define USR_UART_TFE 0x04
  35. #define USR_UART_RFNE 0x08
  36. #define LSR_DATA_READY 0x01
  37. #define LSR_THR_EMPTY 0x20
  38. #define IER_RDA_INT_ENABLE 0x01
  39. #define IER_THRE_INT_ENABLE 0x02
  40. #define IIR_NO_ISQ_PEND 0x01
  41. #define LCR_SET_DLAB 0x80 /* enable r/w DLR to set the baud rate */
  42. #define LCR_PARITY_ENABLE 0x08 /* parity enabled */
  43. #define LCR_PARITY_EVEN 0x10 /* Even parity enabled */
  44. #define LCR_PARITY_ODD 0xef /* Odd parity enabled */
  45. #define LCR_WORD_SIZE_5 0xfc /* the data length is 5 bits */
  46. #define LCR_WORD_SIZE_6 0x01 /* the data length is 6 bits */
  47. #define LCR_WORD_SIZE_7 0x02 /* the data length is 7 bits */
  48. #define LCR_WORD_SIZE_8 0x03 /* the data length is 8 bits */
  49. #define LCR_STOP_BIT1 0xfb /* 1 stop bit */
  50. #define LCR_STOP_BIT2 0x04 /* 1.5 stop bit */
  51. #define DW_LSR_PFE 0x80
  52. #define DW_LSR_TEMT 0x40
  53. #define DW_LSR_THRE 0x40
  54. #define DW_LSR_BI 0x10
  55. #define DW_LSR_FE 0x08
  56. #define DW_LSR_PE 0x04
  57. #define DW_LSR_OE 0x02
  58. #define DW_LSR_DR 0x01
  59. #define DW_LSR_TRANS_EMPTY 0x20
  60. #define DW_FCR_FIFOE 0x01
  61. #define DW_FCR_RFIFOR 0x02
  62. #define DW_FCR_XFIFOR 0x04
  63. #define DW_FCR_RT_FIFO_SINGLE 0x00 /* rcvr trigger 1 character in the FIFO */
  64. #define DW_FCR_RT_FIFO_QUARTER 0x01 /* rcvr trigger FIFO 1/4 full */
  65. #define DW_FCR_RT_FIFO_HALF 0x10 /* rcvr trigger FIFO 1/2 full */
  66. #define DW_FCR_RT_FIFO_LESSTWO 0x11 /* rcvr trigger FIFO 2 less than full */
  67. #define DW_FCR_TET_FIFO_EMPTY 0x00 /* tx empty trigger FIFO empty */
  68. #define DW_FCR_TET_FIFO_TWO 0x01 /* tx empty trigger 2 characters in the FIFO */
  69. #define DW_FCR_TET_FIFO_QUARTER 0x10 /* tx empty trigger FIFO 1/4 full */
  70. #define DW_FCR_TET_FIFO_HALF 0x11 /* tx empty trigger FIFO 1/2 full*/
  71. #define DW_IIR_THR_EMPTY 0x02 /* threshold empty */
  72. #define DW_IIR_RECV_DATA 0x04 /* received data available */
  73. typedef struct {
  74. union {
  75. __IM uint32_t RBR; /* Offset: 0x000 (R/ ) Receive buffer register */
  76. __OM uint32_t THR; /* Offset: 0x000 ( /W) Transmission hold register */
  77. __IOM uint32_t DLL; /* Offset: 0x000 (R/W) Clock frequency division low section register */
  78. };
  79. union {
  80. __IOM uint32_t DLH; /* Offset: 0x004 (R/W) Clock frequency division high section register */
  81. __IOM uint32_t IER; /* Offset: 0x004 (R/W) Interrupt enable register */
  82. };
  83. union {
  84. __IM uint32_t IIR; /* Offset: 0x008 (R/ ) Interrupt indicia register */
  85. __OM uint32_t FCR; /* Offset: 0x008 ( /W) FIFO control register */
  86. };
  87. __IOM uint32_t LCR; /* Offset: 0x00C (R/W) Transmission control register */
  88. __IOM uint32_t MCR; /* Offset: 0x010 (R/W) Modem control register */
  89. __IM uint32_t LSR; /* Offset: 0x014 (R/ ) Transmission state register */
  90. __IM uint32_t MSR; /* Offset: 0x018 (R/ ) Modem state register */
  91. uint32_t RESERVED1[21];
  92. __IOM uint32_t FAR; /* Offset: 0x070 (R/W) FIFO accesss register */
  93. __IM uint32_t TFR; /* Offset: 0x074 (R/ ) transmit FIFO read */
  94. __OM uint32_t RFW; /* Offset: 0x078 ( /W) receive FIFO write */
  95. __IM uint32_t USR; /* Offset: 0x07c (R/ ) UART state register */
  96. __IM uint32_t TFL; /* Offset: 0x080 (R/ ) transmit FIFO level */
  97. __IM uint32_t RFL; /* Offset: 0x084 (R/ ) receive FIFO level */
  98. } dw_usart_reg_t;
  99. #endif /* __DW_USART_H */