uart_driver.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: uart_driver.h
  4. Partner Filename: uart_driver.c
  5. Description: The header file of uart_driver.c
  6. Complier: IAR Embedded Workbench for ARM 8.40.2, IAR Systems.
  7. CPU TYPE : GD32F30x
  8. *************************************************************************
  9. Copyright (c) 2022 Welling Motor Technology(Shanghai) Co. Ltd.
  10. All rights reserved.
  11. *************************************************************************
  12. *************************************************************************
  13. Revising History (ECL of this file):
  14. ************************************************************************/
  15. /************************************************************************
  16. Beginning of File, do not put anything above here except notes
  17. Compiler Directives
  18. ************************************************************************/
  19. #ifndef UART_DRIVER_H
  20. #define UART_DRIVER_H
  21. /************************************************************************
  22. Compiler Directives (N/A)
  23. *************************************************************************/
  24. #ifdef _UART_DRIVER_C_
  25. #define _UART_DRIVER_EXT
  26. #else
  27. #define _UART_DRIVER_EXT extern
  28. #endif
  29. /************************************************************************
  30. Definitions & Macros
  31. *************************************************************************/
  32. #define UART_RX_BUFFER_SIZE 24 // max receive bufffer length
  33. #define UART_DRIVER_READ_DEFAULT \
  34. { \
  35. FALSE, 0, {NULL, 0}, NULL \
  36. }
  37. #define UART_DRIVER_WRITE_DEFAULT \
  38. { \
  39. FALSE, {NULL, 0}, NULL \
  40. }
  41. #define UART_MONITOR_ADDRESS_DEFAULT \
  42. { \
  43. NULL, NULL, NULL, NULL, NULL, NULL \
  44. } // default monitor address(ms)
  45. /************************************************************************
  46. TypeDefs & Structure defines (N/A)
  47. *************************************************************************/
  48. /* UART error type */
  49. typedef enum UART_ERR
  50. {
  51. UART_ERR_OK, // no error
  52. UART_ERR_BUSY, // Read or Write process is in busy.
  53. UART_ERR_NO_BUFFER, // no buffer room for data received
  54. UART_ERR_TIMEOUT, // timeout when read
  55. UART_ERR_UNKNOWN_CMD, // no define command
  56. UART_ERR_INVALID_CMD, // not in use
  57. UART_ERR_CANCEL, // not in use
  58. UART_ERR_PARA // provide function with invalid argument
  59. } UART_ERR_Type;
  60. /* callback function type definitions */
  61. typedef void (*UART_CB_ERR)(UART_ERR_Type);
  62. typedef void (*UART_CB_DONE_READ)(UART_ERR_Type, ULONG);
  63. typedef void (*UART_CB_DONE_WRITE)(UART_ERR_Type);
  64. typedef struct DataBuff
  65. {
  66. UBYTE *pBuf;
  67. ULONG NumBytes;
  68. } UART_DataBuff_Type;
  69. /* data structure used for Read */
  70. typedef struct READ
  71. {
  72. BOOL m_ReadBusy; // reading flag
  73. ULONG m_BuffSize; // max of RX buffer length
  74. UART_DataBuff_Type m_DataBuff;
  75. UART_CB_DONE_READ m_fpDone; // read callback function
  76. } UART_READ_Type;
  77. typedef struct WRITE
  78. {
  79. BOOL m_WriteBusy; // writing flag
  80. UART_DataBuff_Type m_DataBuff;
  81. UART_CB_DONE_WRITE m_fpDone; // read callback function
  82. } UART_WRITE_Type;
  83. /************************************************************************
  84. Exported Variables
  85. *************************************************************************/
  86. #ifdef _UART_DRIVER_C_
  87. _UART_DRIVER_EXT UART_READ_Type uart_stRead = UART_DRIVER_READ_DEFAULT;
  88. _UART_DRIVER_EXT UART_WRITE_Type uart_stWrite = UART_DRIVER_WRITE_DEFAULT;
  89. _UART_DRIVER_EXT UBYTE uart_ubReadBuffer2[UART_RX_BUFFER_SIZE];
  90. _UART_DRIVER_EXT UBYTE *uart_pReadBuffer2 = uart_ubReadBuffer2;
  91. _UART_DRIVER_EXT UWORD * uart_pMonAddr[6] = UART_MONITOR_ADDRESS_DEFAULT; // the address of the variable which user want to monitor.
  92. _UART_DRIVER_EXT volatile UART_CB_ERR uart_fpError = NULL;
  93. _UART_DRIVER_EXT volatile UWORD uart_uwDataNum2 = 0;
  94. _UART_DRIVER_EXT UWORD uart_uwDummy = 0;
  95. _UART_DRIVER_EXT BOOL uart_bFrameStartFlag = FALSE;
  96. _UART_DRIVER_EXT BOOL uart_blCommErrFlag = FALSE;
  97. _UART_DRIVER_EXT UBYTE uart_ubFrameType = 0x00;
  98. _UART_DRIVER_EXT UBYTE uart_ubFrameLength = 0;
  99. _UART_DRIVER_EXT UWORD uart_uwReceivedNum = 0;
  100. #else
  101. _UART_DRIVER_EXT UART_READ_Type uart_stRead;
  102. _UART_DRIVER_EXT UART_WRITE_Type uart_stWrite;
  103. _UART_DRIVER_EXT UBYTE uart_ubReadBuffer2[UART_RX_BUFFER_SIZE];
  104. _UART_DRIVER_EXT UBYTE *uart_pReadBuffer2;
  105. _UART_DRIVER_EXT UWORD * uart_pMonAddr[6]; // the address of the variable which user want to monitor.
  106. _UART_DRIVER_EXT volatile UART_CB_ERR uart_fpError;
  107. _UART_DRIVER_EXT volatile UWORD uart_uwDataNum2;
  108. _UART_DRIVER_EXT UWORD uart_uwDummy;
  109. _UART_DRIVER_EXT BOOL uart_bFrameStartFlag;
  110. _UART_DRIVER_EXT BOOL uart_blCommErrFlag;
  111. _UART_DRIVER_EXT UBYTE uart_ubFrameType;
  112. _UART_DRIVER_EXT UBYTE uart_ubFrameLength;
  113. _UART_DRIVER_EXT UWORD uart_uwReceivedNum;
  114. #endif
  115. /************************************************************************
  116. RAM ALLOCATION (N/A)
  117. *************************************************************************/
  118. /************************************************************************
  119. Exported Function Call Prototypes
  120. *************************************************************************/
  121. #ifdef _UART_DRIVER_C_
  122. _UART_DRIVER_EXT static void uart_voCBSwanError(UART_ERR_Type _err);
  123. _UART_DRIVER_EXT void uart_voApplInit(void);
  124. _UART_DRIVER_EXT void uart_voReadPoll2(ULONG _NumBytes, UBYTE *_Buffer, UART_CB_DONE_READ _fpCBDone);
  125. _UART_DRIVER_EXT void uart_voWritePoll2(ULONG _NumBytes, const UBYTE *_Buffer);
  126. _UART_DRIVER_EXT void uart_voApplMain(void);
  127. _UART_DRIVER_EXT void uart_voReadFramePoll2(void);
  128. _UART_DRIVER_EXT void uart_voWriteFramePoll2(void);
  129. _UART_DRIVER_EXT void uart_voCancelReadPoll2(void);
  130. _UART_DRIVER_EXT static void uart_voCBDoneRead2(UART_ERR_Type _err, ULONG _NumBytes);
  131. _UART_DRIVER_EXT void uart_voMonitorInit(void);
  132. #else
  133. _UART_DRIVER_EXT void uart_voCBSwanError(UART_ERR_Type _err);
  134. _UART_DRIVER_EXT void uart_voApplInit(void);
  135. _UART_DRIVER_EXT void uart_voReadPoll2(ULONG _NumBytes, UBYTE *_Buffer, UART_CB_DONE_READ _fpCBDone);
  136. _UART_DRIVER_EXT void uart_voApplMain(void);
  137. _UART_DRIVER_EXT void uart_voReadFramePoll2(void);
  138. _UART_DRIVER_EXT void uart_voWriteFramePoll2(void);
  139. _UART_DRIVER_EXT void uart_voCancelReadPoll2(void);
  140. _UART_DRIVER_EXT void uart_voWritePoll2(ULONG _NumBytes, const UBYTE *_Buffer);
  141. _UART_DRIVER_EXT void uart_voMonitorInit(void);
  142. #endif
  143. /************************************************************************
  144. Local Function Call Prototypes (N/A)
  145. *************************************************************************/
  146. /************************************************************************
  147. Flag Define (N/A)
  148. *************************************************************************/
  149. #endif
  150. /************************************************************************
  151. Copyright (c) 2022 Welling Motor Technology(Shanghai) Co. Ltd.
  152. All rights reserved.
  153. *************************************************************************
  154. End of this File (EOF)!
  155. Do not put anything after this part!
  156. *************************************************************************/