123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /**
- ******************************************************************************
- * @file usart.h
- * @author
- * @version V1.0.0
- * @date 23-12-2015
- * @brief usart function.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Define to prevent recursive inclusion -------------------------------------*/
- #ifndef __USART_H
- #define __USART_H
- /* Includes ------------------------------------------------------------------*/
- //#include "at32f421.h"
- #include <stdbool.h>
- #include "typedefine.h"
- #include "bikethrottle.h"
- #include "typedefine.h"
- /* Public Function declare---------------------------------------------------*/
- typedef _Bool BOOL;
- // 天腾
- #define ID_MC_BC 0x710
- #define ID_MC_TO_BMS 0x712
- #define ID_MC_TO_PBU 0x713
- #define ID_MC_TO_HMI 0x714
- #define ID_MC_TO_CDL 0x715
- #define ID_BMS_BC 0x720
- #define ID_BMS_TO_MC 0x721
- #define ID_BMS_TO_PBU 0x723
- #define ID_BMS_TO_HMI 0x724
- #define ID_BMS_TO_CDL 0x725
- #define ID_PBU_BC 0x730
- #define ID_PBU_TO_MC 0x731
- #define ID_PBU_TO_BMS 0x732
- #define ID_PBU_TO_CDL 0x735
- #define ID_HMI_BC 0x740
- #define ID_HMI_TO_MC 0x741
- #define ID_HMI_TO_BMS 0x742
- #define ID_HMI_TO_PBU 0x743
- #define ID_HMI_TO_CDL 0x745
- #define ID_CDL_BC 0x750
- #define ID_CDL_TO_MC 0x751
- #define ID_CDL_TO_BMS 0x752
- #define ID_CDL_TO_PBU 0x753
- #define ID_CDL_TO_HMI 0x754
- #define MODE_READ 0x11
- #define MODE_WRITE 0x16
- #define MODE_REPORT 0x0C
- #define UART_BUFF_SIZE 512//256
- #define FRAME_SIZE 8
- #define FRAMETIMEOUT_Count 10//20 //ms
-
- #define UARTFRAME_BEGIN (UBYTE)0x3A
- #define UARTFRAME_END1 (UBYTE)0x0D
- #define UARTFRAME_END2 (UBYTE)0x0A
- #define UARTADDR_CDL (UBYTE)0xFA
- #define UARTADDR_BMS (UBYTE)0x16
- #define UARTADDR_OBC (UBYTE)0x1A
- #define UARTMODE_READ (UBYTE)0x11
- #define UARTMODE_WRITE (UBYTE)0x16
- #define UARTMODE_REPORT (UBYTE)0x0C
- /* Define to variables declare---------------------------------------------------*/
- //低字节在前, 高字节在后
- typedef struct
- {
- UWORD ucBufSize;
- UWORD ucBufWrInde;
- UWORD ucBufRdInde;
- UWORD ucBufCnt;
- UBYTE ucBufOvf;
- UBYTE * pcBufAddr;
- // usart_type* usart_periph;
- ULONG DelayTimeCnt; //超时计时
- BOOL IsWaitRX_Flag; //超时等待数据标志
- ULONG ul_UartComTimeOutCount;
- } USART_Buf_TypeDef;
- typedef struct
- {
- UWORD uwFramecount;
- UBYTE ucBufWrIndex;
- UBYTE ucBufRdIndex;
- UWORD uwDataCount[FRAME_SIZE];
- } USART_FrameBuf_TypeDef;
- typedef enum
- {
- Assist_Forward = 0x00,
- Assist_Backward = 0x01,
- } AssistDir_Struct_t;
- typedef struct
- {
- UBYTE ucPWM;
- UBYTE ucLightSwitch;
- UBYTE ucLowPower;
- UBYTE ucWalk;
- UBYTE ucCruise;
- UBYTE ucOverSpeed;
- } OBC_RunInfo_Struct_t;
- typedef struct
- {
- AssistDir_Struct_t AssistDir;
- UBYTE ucAssistedMagnetSteel;
- UBYTE ucAssistRatio;
- UBYTE ucThrottleGt;
- UBYTE ucThrottleLimited;
- UBYTE ucSlowStartMode;
- UBYTE ucSpeedSensorPulses;
- SWORD swUnderVoltageBias;//0.1V
- UWORD uwUnderVoltageBase;
- UBYTE ucCurrentLimiation;//0.5A
- UBYTE ucShakingCode;
- UBYTE ucSpeedLimiation;
- UBYTE ucWheelDiameterCode;
- } OBC_SetInfo_Struct_t;
- typedef struct
- {
- UBYTE Stage;
- UBYTE Current;
- UWORD Speed;
- UBYTE ErrorCode;
- } MC2OBC_RunInfo_Struct_t;
- /* Public variables declare---------------------------------------------------*/
- extern UBYTE UART_RxBuff_OBC[UART_BUFF_SIZE];
- extern USART_Buf_TypeDef UART_RxBuff_Struct_OBC;
- extern UBYTE UART_TxBuff_OBC[UART_BUFF_SIZE];
- extern USART_Buf_TypeDef UART_TxBuff_Struct_OBC;
- extern UBYTE UART_RxBuff_BMS[UART_BUFF_SIZE];
- extern USART_Buf_TypeDef UART_RxBuff_Struct_BMS ;
- extern UBYTE UART_TxBuff_BMS[UART_BUFF_SIZE];
- extern USART_Buf_TypeDef UART_TxBuff_Struct_BMS;
- extern USART_FrameBuf_TypeDef stUSART_FrameBuf_OBC;
- extern USART_FrameBuf_TypeDef stUSART_FrameBuf_BMS;
- extern OBC_RunInfo_Struct_t stOBC_RunInfo;
- //extern OBC_SetInfo_Struct_t stOBC_SetInfo;
- //extern MC2OBC_RunInfo_Struct_t stMC2OBC_RRunInfo;
- extern UBYTE ucUartAnalyseID;
- extern UBYTE ucCommType;
- extern BIKECRUISE_COF bikeCruise;
- /*Private function declare---------------------------------------------------*/
- UBYTE UART_ReadChar(USART_Buf_TypeDef * ptRx, UBYTE ucNum);
- void UART_DelChar(USART_Buf_TypeDef * ptRx, UBYTE ucNum);
- void UART_PutChar(USART_Buf_TypeDef * ptTx, UBYTE ucData);
- void UsartRx_Process(USART_Buf_TypeDef *USARTx_RxBuf_Struct, USART_Buf_TypeDef *USARTx_TxBuf_Struct, USART_FrameBuf_TypeDef *USART_RxFrameBuf_Struct);
- void SendData(USART_Buf_TypeDef* ptUartTx, UWORD ID, UBYTE Mode, UWORD Command, UBYTE *Data);
- void KM5S_USART_RxData_Process(USART_Buf_TypeDef* ptUartTx, UBYTE* buf, UWORD dataCount);
- void KM5S_USART_DataProcess(USART_Buf_TypeDef* ptUartTx, UWORD Addr, UBYTE Mode, UBYTE Length, UBYTE* Data);
- void DataProcess(USART_Buf_TypeDef* ptUartTx, UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE *Data);
- void KM5S_SendData_OBC(USART_Buf_TypeDef* ptUartTx, UBYTE Mode, UBYTE Length, UBYTE checknum);
- void USARTx_Rx_IRQ(USART_Buf_TypeDef *USARTx_RxBuf_Struct, USART_FrameBuf_TypeDef *USART_RxFrameBuf_Struct);
- void USARTx_Tx_IRQ(USART_Buf_TypeDef *USARTx_TxBuf_Struct);
- void KM5S_OBCSetPara(UBYTE* buf);
- void USARTx_RxTX_IRQ(USART_Buf_TypeDef *USARTx_RxBuf_Struct,USART_Buf_TypeDef *USARTx_TxBuf_Struct,USART_FrameBuf_TypeDef *USART_RxFrameBuf_Struct);
- #endif /*__USART_H */
- /*---------------------------- file end -------------------------------------*/
|