123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- /************************************************************************
- Project:
- Filename: uart_appl.h
- Partner Filename: N/A
- Description:
- 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):
- M0_20170410, by liyue, create this file;
- ************************************************************************/
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives
- ************************************************************************/
- #ifndef UART_MONITOR_APPL_H
- #define UART_MONITOR_APPL_H
- #include "typedefine.h"
- #include "uart_driver.h"
- /************************************************************************
- Compiler Directives (N/A)
- *************************************************************************/
- #ifdef _UART_MONITOR_APPL_C_
- #define _UART_MONITOR_APPL_EXT
- #else
- #define _UART_MONITOR_APPL_EXT extern
- #endif
- /************************************************************************
- Definitions & Macros
- *************************************************************************/
- #define INSERT_BUFFER_SIZE 16
- #define INSERT_BUFFER_HEADER_LEN 7
- #define ONE_SECOND_COUNT 1000
- #define CMD_LENGTH 22
- #define TX_BUFFER_SIZE 150
- #define RX_BUFFER_SIZE 24
- #define MSG_QUEUE_SIZE 10
- #define PARA_TABLE_SIZE 22
- #define PARA_BUFFER_SIZE 40
- #define LOW_WORD(var) ((UWORD *)(&(var))) // little-endian
- #define HIGH_WORD(var) ((UWORD *)(&(var)) + 1)
- /************** data monitor application ***************/
- /*******************************************************/
- /* Channel Number Time(sample+DMA/sample)(us) */
- /* 3 6.4/4.8 */
- /* 4 7.6/5.9 */
- /* 5 8.9/7.3 */
- /* 6 10.1/8.6 */
- /*******************************************************/
- /* TBC Channels Selection */
- /* 5.3k 3/4/5/6 */
- /* 8k 3/4/5/6 */
- /* 12k 3/4 */
- /*******************************************************/
- #define CHANNEL_NUM 6 // channel number
- #define CHANNEL_1 2 // 1 channel correspond to 2 bytes
- #define CHANNEL_2 4
- #define CHANNEL_3 6
- #define CHANNEL_4 8
- #define CHANNEL_5 10
- #define CHANNEL_6 12
- #define TEMP_BUFFER_LEN CHANNEL_5 // temp buffer length is based on the choice of channel number.
- #if TEMP_BUFFER_LEN == CHANNEL_6
- #define S_FRAME_SIZE 124
- #elif TEMP_BUFFER_LEN == CHANNEL_5
- #define S_FRAME_SIZE 104
- #elif TEMP_BUFFER_LEN == CHANNEL_4
- #define S_FRAME_SIZE 84
- #elif TEMP_BUFFER_LEN == CHANNEL_3
- #define S_FRAME_SIZE 64
- #else
- // do nothing!
- #endif
- #define UART_DEF_TIMEOUT_MS 1000 // default timeout const(ms)
- #define UART_DEF_CMD_LEN 0 // default command frame length
- //*** define USART Driver configuration objects ***
- // **length-mode configuration object**
- #define UART_APPL_CONFIG_DEFAULT \
- { \
- UART_MODE_LEN, UART_DEF_TIMEOUT_MS, CMD_LENGTH, NULL \
- }
- #define UART_MsgQ_CONFIG_DEFAULT \
- { \
- UART_stMsgQueue, UART_stMsgQueue, FALSE, FALSE \
- }
- /************************************************************************
- TypeDefs & Structure defines (N/A)
- *************************************************************************/
- /* USART work mode type */
- typedef enum UART_WorkMode
- {
- UART_MODE_TIME, // time interval framing mode
- UART_MODE_LEN, // fixed length framing mode
- UART_MODE_CHAR // fixed chars framing mode
- } UART_WorkMode_Type;
- typedef struct UART_CONFIG
- {
- UART_WorkMode_Type enWorkMode;
- UWORD uwTimeout; // unit:count
- UBYTE ubLength; // unit:bytes
- UBYTE * pChar;
- } UART_CONFIG_Type;
- typedef enum MsgType
- {
- UART_NULL = 0, // NULL message will not be processed
- UART_SEND_STATUS = 1, // send out Application status
- UART_SEND_PARA = 2 // send out Parameter value
- } UART_MsgType;
- typedef struct MSG
- {
- UART_MsgType enType;
- UBYTE * pBuf;
- UWORD uwNumBytes;
- } UART_MSG;
- typedef struct MsgQNode
- {
- UART_MSG stMsg;
- struct MsgQNode *pNext;
- } UART_MsgQNodeType;
- typedef struct MsgQType
- {
- UART_MsgQNodeType *pSave;
- UART_MsgQNodeType *pUse;
- BOOL bValid;
- BOOL bHandling;
- } UART_MsgQType;
- typedef struct ParaData
- {
- BOOL bParaStart;
- BOOL bWriteBusy;
- } UART_ParaData_Flag;
- /************************************************************************
- Exported Variables
- *************************************************************************/
- #ifdef _UART_MONITOR_APPL_C_
- _UART_MONITOR_APPL_EXT UWORD placeholder[4] = {0xFFFF};
- _UART_MONITOR_APPL_EXT ULONG dummy32 = 0x00000000;
- _UART_MONITOR_APPL_EXT UWORD dummy16 = 0x0000;
- /* parabuffer contains parameter response frame payload */
- _UART_MONITOR_APPL_EXT UBYTE UART_ubParaBuffer[PARA_BUFFER_SIZE] = {0};
- /* define Read Buffer and its pointer */
- _UART_MONITOR_APPL_EXT UBYTE UART_ubReadBuffer[RX_BUFFER_SIZE];
- /* define Write dual Buffer and its pointers */
- _UART_MONITOR_APPL_EXT UBYTE UART_ubWriteBuffer1[TX_BUFFER_SIZE] = {0x55, 0xAA, 0x55, 0xAA};
- _UART_MONITOR_APPL_EXT UBYTE UART_ubWriteBuffer2[TX_BUFFER_SIZE] = {0x55, 0xAA, 0x55, 0xAA};
- _UART_MONITOR_APPL_EXT UBYTE *UART_pWriteBuffer = UART_ubWriteBuffer1;
- _UART_MONITOR_APPL_EXT UWORD UART_uwWriteIndex = 4;
- /* data bytes recieved in a Read */
- _UART_MONITOR_APPL_EXT UWORD volatile UART_uwRxNum = 0;
- _UART_MONITOR_APPL_EXT UWORD writeDenyCount = 0; // HAL_Write request deny count(because of S_ERR_BUSY), this value mainly used for debug.
- _UART_MONITOR_APPL_EXT UART_CONFIG_Type UART_stConfigLEN = UART_APPL_CONFIG_DEFAULT;
- _UART_MONITOR_APPL_EXT BOOL UART_bMonSwitch = FALSE; // control monitor function whether of not write data out.
- _UART_MONITOR_APPL_EXT UWORD *UART_pMonAddr[6]; // the address of the variable which user want to monitor.
- //*** define insert buffer ***
- _UART_MONITOR_APPL_EXT UBYTE UART_ubInsertBuf[100] = {0x55, 0xAA, 0x55,
- 0xFF}; // the data in insertBuffer will be inserted into writeBuffer when enabled
- _UART_MONITOR_APPL_EXT volatile BOOL UART_bInsertPendTx = FALSE; // flag indicate whether insert buffer is pending to be transmitted.
- _UART_MONITOR_APPL_EXT UART_ParaData_Flag UART_stParaStatus = {FALSE};
- _UART_MONITOR_APPL_EXT UART_MsgQNodeType UART_stMsgQueue[MSG_QUEUE_SIZE]; // message queue
- _UART_MONITOR_APPL_EXT UART_MsgQType UART_stMsgQ = UART_MsgQ_CONFIG_DEFAULT;
- #else
- _UART_MONITOR_APPL_EXT UWORD placeholder[4];
- _UART_MONITOR_APPL_EXT ULONG dummy32;
- _UART_MONITOR_APPL_EXT UWORD dummy16;
- _UART_MONITOR_APPL_EXT UBYTE UART_ubParaBuffer[PARA_BUFFER_SIZE];
- _UART_MONITOR_APPL_EXT UBYTE UART_ubReadBuffer[RX_BUFFER_SIZE];
- /* define Write dual Buffer and its pointers */
- _UART_MONITOR_APPL_EXT UBYTE UART_ubWriteBuffer1[TX_BUFFER_SIZE];
- _UART_MONITOR_APPL_EXT UBYTE UART_ubWriteBuffer2[TX_BUFFER_SIZE];
- _UART_MONITOR_APPL_EXT UBYTE *UART_pWriteBuffer;
- _UART_MONITOR_APPL_EXT UWORD UART_uwWriteIndex;
- /* data bytes recieved in a Read */
- _UART_MONITOR_APPL_EXT UWORD volatile UART_uwRxNum;
- _UART_MONITOR_APPL_EXT UWORD writeDenyCount; // HAL_Write request deny count(because of S_ERR_BUSY), this value mainly used for debug.
- _UART_MONITOR_APPL_EXT UART_CONFIG_Type UART_stConfigLEN;
- _UART_MONITOR_APPL_EXT BOOL UART_bMonSwitch; // control monitor function whether of not write data out.
- _UART_MONITOR_APPL_EXT UWORD *UART_pMonAddr[6]; // the address of the variable which user want to monitor.
- //*** define insert buffer ***
- _UART_MONITOR_APPL_EXT UBYTE UART_ubInsertBuf[100]; // the data in insertBuffer will be inserted into writeBuffer when enabled
- _UART_MONITOR_APPL_EXT volatile BOOL UART_bInsertPendTx;
- _UART_MONITOR_APPL_EXT UART_ParaData_Flag UART_stParaStatus;
- _UART_MONITOR_APPL_EXT UART_MsgQNodeType UART_stMsgQueue[MSG_QUEUE_SIZE];
- #endif
- /************************************************************************
- RAM ALLOCATION (N/A)
- *************************************************************************/
- /************************************************************************
- Exported Function Call Prototypes
- *************************************************************************/
- #ifdef _UART_MONITOR_APPL_C_
- _UART_MONITOR_APPL_EXT void uart_voMainDec(void); // used in main.c for checking RxData and insertQueue
- _UART_MONITOR_APPL_EXT void UART_voAppMonitor(void); // used to send monitor data out
- _UART_MONITOR_APPL_EXT void UART_voApplTimer(void);
- _UART_MONITOR_APPL_EXT static void CBError_monitor(UART_ERR_Type _err);
- /* handle parameter related command*/
- _UART_MONITOR_APPL_EXT static void UART_voHandleParaCmd(void);
- //*** command decoder function ***
- _UART_MONITOR_APPL_EXT static void UART_voDecode(void);
- //*** Callback called when error occurs. ***
- _UART_MONITOR_APPL_EXT void CBError(UART_ERR_Type _err);
- //*** Callback called when some data received. ***
- _UART_MONITOR_APPL_EXT void UART_voCBDoneRead(UART_ERR_Type _err, ULONG _NumBytes);
- _UART_MONITOR_APPL_EXT static UBYTE UART_ubCheckXOR(const UBYTE Buf[], UBYTE CNT);
- _UART_MONITOR_APPL_EXT UART_MSG UART_stMsgFetched; // message fetched from msgQueue
- _UART_MONITOR_APPL_EXT void UART_voInitMsgQueue(void); // MsgQueue initialization
- _UART_MONITOR_APPL_EXT static void UART_voPostMsg(UART_MSG _msg); // post message
- _UART_MONITOR_APPL_EXT static void UART_voHandleMsg(void); // handle msg according to msg type
- #else
- _UART_MONITOR_APPL_EXT void uart_voMainDec(void); // used in main.c for checking RxData and insertQueue
- _UART_MONITOR_APPL_EXT void UART_voAppMonitor(void); // used to send monitor data out
- _UART_MONITOR_APPL_EXT void UART_voApplTimer(void);
- //*** Callback called when error occurs. ***
- _UART_MONITOR_APPL_EXT void CBError(UART_ERR_Type _err);
- //*** Callback called when some data received. ***
- _UART_MONITOR_APPL_EXT void UART_voCBDoneRead(UART_ERR_Type _err, ULONG _NumBytes);
- _UART_MONITOR_APPL_EXT UART_MSG UART_stMsgFetched; // message fetched from msgQueue
- _UART_MONITOR_APPL_EXT void UART_voInitMsgQueue(void); // MsgQueue initialization
- #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!
- *************************************************************************/
|