yc_uart.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c); 2006-2020, YICHIP Development Team
  3. * @file yc_uart.h
  4. * @brief source file for setting uart
  5. *
  6. * Change Logs:
  7. * Date Author Version Notes
  8. * 2020-11-06 wushengyan V1.0.0 the first version
  9. */
  10. #ifndef __YC_UART_H__
  11. #define __YC_UART_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "yc3122.h"
  16. #include "system.h"
  17. /**
  18. * @defgroup UARTx
  19. */
  20. #define IS_UART(UARTx) (((UARTx) == MUART0) ||\
  21. ((UARTx) == MUART1) ||\
  22. ((UARTx) == MUART2) ||\
  23. ((UARTx) == MUART3))
  24. /**
  25. * @defgroup UART_RxMode
  26. */
  27. #define MODE_RX_ENABLE 1
  28. #define MODE_RX_DISABLE 0
  29. #define IS_UART_RX_MODE(MODE) (((MODE) == MODE_RX_ENABLE) ||\
  30. ((MODE) == MODE_RX_DISABLE))
  31. /**
  32. * @defgroup USART_Parity
  33. */
  34. #define YC_PARITY_NONE 0
  35. #define YC_PARITY_EVEN 0
  36. #define YC_PARITY_ODD 1
  37. #define IS_UART_PARITY(PARITY) (((PARITY) == YC_PARITY_NONE) ||\
  38. ((PARITY) == YC_PARITY_EVEN) ||\
  39. ((PARITY) == YC_PARITY_ODD))
  40. /**
  41. * @defgroup UART_DataBits
  42. */
  43. #define DATABITS_8B 0
  44. #define DATABITS_9B 1
  45. #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == DATABITS_8B) || \
  46. ((LENGTH) == DATABITS_9B))
  47. /**
  48. * @defgroup UART_Stop_Bits
  49. */
  50. #define STOPBITS_1 0
  51. #define STOPBITS_2 1
  52. #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == STOPBITS_1) || \
  53. ((STOPBITS) == STOPBITS_2) )
  54. /**
  55. * @defgroup UART_Hardware_Flow_Control
  56. */
  57. #define FLOWCTRL_NONE 0
  58. #define FLOWCTRL_ENABLE 1
  59. #define IS_UART_FLOW_CTRL(CTRL) (((CTRL) == FLOWCTRL_NONE) || \
  60. ((CTRL) == FLOWCTRL_ENABLE))
  61. /**
  62. * @defgroup UART_Smart_Card_Control
  63. */
  64. #define SMARTCARD_ENABLE 1
  65. #define SMARTCARD_DISABLE 0
  66. #define IS_UART_SMART_CARD(CTRL) (((CTRL) == SMARTCARD_ENABLE) || \
  67. ((CTRL) == SMARTCARD_DISABLE))
  68. /**
  69. * @defgroup UART_CommMode
  70. */
  71. #define MODE_SINGLE_LINE 1
  72. #define MODE_DUPLEX 0
  73. #define IS_UART_COMM_MODE(MODE) (((MODE) == MODE_SINGLE_LINE) ||\
  74. ((MODE) == MODE_DUPLEX))
  75. /**
  76. * @defgroup USART_BaudRate
  77. */
  78. #define IS_UART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0x5B8) &&\
  79. ((BAUDRATE) < 0x0044AA21))
  80. /**
  81. * @defgroup UART_Interrupt_Type_definition
  82. */
  83. #define UART_IT_TX 0x01
  84. #define UART_IT_RX 0x02
  85. #define IS_UART_IT(ITx) (((ITx) == UART_IT_TX) || ((ITx) == UART_IT_RX))
  86. typedef struct
  87. {
  88. uint8_t RxMode; /*!< Specifies wether the Receive or Transmit mode
  89. is enabled or disabled. This parameter can be
  90. a value of @ref UART_Mode */
  91. uint8_t Parity; /*!< Specifies the parity mode.
  92. This parameter can be a value of
  93. @ref UART_Parity @note When parity is enabled,
  94. the computed parity is inserted at
  95. the MSB position of the transmitted data
  96. (9th bit when the word length is set to
  97. 9 data bits; 8th bit when the word length is
  98. set to 8 data bits);. */
  99. uint8_t DataBits; /*!< Specifies the number of data bits transmitted
  100. or received in a frame. This parameter can be
  101. a value of @ref UART_DataBits */
  102. uint8_t StopBits; /*!< Specifies the number of stop bits transmitted.
  103. parameter can be a value of @ref UART_Stop_Bits */
  104. uint8_t FlowCtrl; /*!< Specifies wether the hardware flow control mode
  105. is enabled or disabled. This parameter can be
  106. a value of @ref UART_Hardware_Flow_Control */
  107. uint8_t SmartCard;
  108. uint8_t CommMode;
  109. uint32_t BaudRate; /*!< This member configures the USART
  110. communication baud rate. */
  111. } UART_InitTypeDef;
  112. void UART_DeInit(UART_TypeDef *UARTx);
  113. void UART_Init(UART_TypeDef *UARTx, UART_InitTypeDef *UART_InitStruct);
  114. void UART_StructInit(UART_InitTypeDef *UART_InitStruct);
  115. void UART_ITConfig(UART_TypeDef *UARTx, uint32_t UART_IT, FunctionalState NewState);
  116. void UART_SendData(UART_TypeDef *UARTx, uint8_t Data);
  117. void UART_SendBuf(UART_TypeDef *UARTx, uint8_t *buf, uint32_t len);
  118. uint8_t UART_ReceiveData(UART_TypeDef *UARTx);
  119. uint32_t UART_ReceiveBuf(UART_TypeDef *UARTx, uint8_t *buf, uint32_t len);
  120. void UART_AutoFlowCtrlCmd(UART_TypeDef *UARTx, FunctionalState NewState);
  121. uint8_t UART_GetITIdentity(UART_TypeDef *UARTx);
  122. Boolean UART_IsRXFIFOFull(UART_TypeDef *UARTx);
  123. Boolean UART_IsRXFIFONotEmpty(UART_TypeDef *UARTx);
  124. Boolean UART_IsBusy(UART_TypeDef *UARTx);
  125. void UART_SetITTimeout(UART_TypeDef *UARTx, uint16_t timeout);
  126. void UART_SetRxITNum(UART_TypeDef *UARTx, uint8_t Bcnt);
  127. uint32_t UART_ReceiveDataLen(UART_TypeDef *UARTx);
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif
  132. /************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/