123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /************************************************************************
- Project: Welling Motor Control Paltform
- Filename: uart_driver.h
- Partner Filename: uart_driver.c
- Description: The header file of uart_driver.c
- Complier: IAR Embedded Workbench for ARM 8.40.2, IAR Systems.
- CPU TYPE : GD32F30x
- *************************************************************************
- Copyright (c) 2022 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- *************************************************************************
- Revising History (ECL of this file):
- ************************************************************************/
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives
- ************************************************************************/
- #ifndef UART_DRIVER_H
- #define UART_DRIVER_H
- /************************************************************************
- Compiler Directives (N/A)
- *************************************************************************/
- #ifdef _UART_DRIVER_C_
- #define _UART_DRIVER_EXT
- #else
- #define _UART_DRIVER_EXT extern
- #endif
- /************************************************************************
- Definitions & Macros
- *************************************************************************/
- #define UART_RX_BUFFER_SIZE 24 // max receive bufffer length
- #define UART_DRIVER_READ_DEFAULT \
- { \
- FALSE, 0, {NULL, 0}, NULL \
- }
- #define UART_DRIVER_WRITE_DEFAULT \
- { \
- FALSE, {NULL, 0}, NULL \
- }
- #define UART_MONITOR_ADDRESS_DEFAULT \
- { \
- NULL, NULL, NULL, NULL, NULL, NULL \
- } // default monitor address(ms)
- /************************************************************************
- TypeDefs & Structure defines (N/A)
- *************************************************************************/
- /* UART error type */
- typedef enum UART_ERR
- {
- UART_ERR_OK, // no error
- UART_ERR_BUSY, // Read or Write process is in busy.
- UART_ERR_NO_BUFFER, // no buffer room for data received
- UART_ERR_TIMEOUT, // timeout when read
- UART_ERR_UNKNOWN_CMD, // no define command
- UART_ERR_INVALID_CMD, // not in use
- UART_ERR_CANCEL, // not in use
- UART_ERR_PARA // provide function with invalid argument
- } UART_ERR_Type;
- /* callback function type definitions */
- typedef void (*UART_CB_ERR)(UART_ERR_Type);
- typedef void (*UART_CB_DONE_READ)(UART_ERR_Type, ULONG);
- typedef void (*UART_CB_DONE_WRITE)(UART_ERR_Type);
- typedef struct DataBuff
- {
- UBYTE *pBuf;
- ULONG NumBytes;
- } UART_DataBuff_Type;
- /* data structure used for Read */
- typedef struct READ
- {
- BOOL m_ReadBusy; // reading flag
- ULONG m_BuffSize; // max of RX buffer length
- UART_DataBuff_Type m_DataBuff;
- UART_CB_DONE_READ m_fpDone; // read callback function
- } UART_READ_Type;
- typedef struct WRITE
- {
- BOOL m_WriteBusy; // writing flag
- UART_DataBuff_Type m_DataBuff;
- UART_CB_DONE_WRITE m_fpDone; // read callback function
- } UART_WRITE_Type;
- /************************************************************************
- Exported Variables
- *************************************************************************/
- #ifdef _UART_DRIVER_C_
- _UART_DRIVER_EXT UART_READ_Type uart_stRead = UART_DRIVER_READ_DEFAULT;
- _UART_DRIVER_EXT UART_WRITE_Type uart_stWrite = UART_DRIVER_WRITE_DEFAULT;
- _UART_DRIVER_EXT UBYTE uart_ubReadBuffer2[UART_RX_BUFFER_SIZE];
- _UART_DRIVER_EXT UBYTE *uart_pReadBuffer2 = uart_ubReadBuffer2;
- _UART_DRIVER_EXT UWORD * uart_pMonAddr[6] = UART_MONITOR_ADDRESS_DEFAULT; // the address of the variable which user want to monitor.
- _UART_DRIVER_EXT volatile UART_CB_ERR uart_fpError = NULL;
- _UART_DRIVER_EXT volatile UWORD uart_uwDataNum2 = 0;
- _UART_DRIVER_EXT UWORD uart_uwDummy = 0;
- _UART_DRIVER_EXT BOOL uart_bFrameStartFlag = FALSE;
- _UART_DRIVER_EXT BOOL uart_blCommErrFlag = FALSE;
- _UART_DRIVER_EXT UBYTE uart_ubFrameType = 0x00;
- _UART_DRIVER_EXT UBYTE uart_ubFrameLength = 0;
- _UART_DRIVER_EXT UWORD uart_uwReceivedNum = 0;
- #else
- _UART_DRIVER_EXT UART_READ_Type uart_stRead;
- _UART_DRIVER_EXT UART_WRITE_Type uart_stWrite;
- _UART_DRIVER_EXT UBYTE uart_ubReadBuffer2[UART_RX_BUFFER_SIZE];
- _UART_DRIVER_EXT UBYTE *uart_pReadBuffer2;
- _UART_DRIVER_EXT UWORD * uart_pMonAddr[6]; // the address of the variable which user want to monitor.
- _UART_DRIVER_EXT volatile UART_CB_ERR uart_fpError;
- _UART_DRIVER_EXT volatile UWORD uart_uwDataNum2;
- _UART_DRIVER_EXT UWORD uart_uwDummy;
- _UART_DRIVER_EXT BOOL uart_bFrameStartFlag;
- _UART_DRIVER_EXT BOOL uart_blCommErrFlag;
- _UART_DRIVER_EXT UBYTE uart_ubFrameType;
- _UART_DRIVER_EXT UBYTE uart_ubFrameLength;
- _UART_DRIVER_EXT UWORD uart_uwReceivedNum;
- #endif
- /************************************************************************
- RAM ALLOCATION (N/A)
- *************************************************************************/
- /************************************************************************
- Exported Function Call Prototypes
- *************************************************************************/
- #ifdef _UART_DRIVER_C_
- _UART_DRIVER_EXT static void uart_voCBSwanError(UART_ERR_Type _err);
- _UART_DRIVER_EXT void uart_voApplInit(void);
- _UART_DRIVER_EXT void uart_voReadPoll2(ULONG _NumBytes, UBYTE *_Buffer, UART_CB_DONE_READ _fpCBDone);
- _UART_DRIVER_EXT void uart_voWritePoll2(ULONG _NumBytes, const UBYTE *_Buffer);
- _UART_DRIVER_EXT void uart_voApplMain(void);
- _UART_DRIVER_EXT void uart_voReadFramePoll2(void);
- _UART_DRIVER_EXT void uart_voWriteFramePoll2(void);
- _UART_DRIVER_EXT void uart_voCancelReadPoll2(void);
- _UART_DRIVER_EXT static void uart_voCBDoneRead2(UART_ERR_Type _err, ULONG _NumBytes);
- _UART_DRIVER_EXT void uart_voMonitorInit(void);
- #else
- _UART_DRIVER_EXT void uart_voCBSwanError(UART_ERR_Type _err);
- _UART_DRIVER_EXT void uart_voApplInit(void);
- _UART_DRIVER_EXT void uart_voReadPoll2(ULONG _NumBytes, UBYTE *_Buffer, UART_CB_DONE_READ _fpCBDone);
- _UART_DRIVER_EXT void uart_voApplMain(void);
- _UART_DRIVER_EXT void uart_voReadFramePoll2(void);
- _UART_DRIVER_EXT void uart_voWriteFramePoll2(void);
- _UART_DRIVER_EXT void uart_voCancelReadPoll2(void);
- _UART_DRIVER_EXT void uart_voWritePoll2(ULONG _NumBytes, const UBYTE *_Buffer);
- _UART_DRIVER_EXT void uart_voMonitorInit(void);
- #endif
- /************************************************************************
- Local Function Call Prototypes (N/A)
- *************************************************************************/
- /************************************************************************
- Flag Define (N/A)
- *************************************************************************/
- #endif
- /************************************************************************
- Copyright (c) 2022 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|