123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- /********************************************************************************
- * 常州易控汽车电子股份有限公司
- * (c) Copyright 2009-2015 ECTEK
- * 保留所有权利
- ********************************************************************************
- * 工程名称:整车管理
- * 文件名: CANNet.c
- * 功能描述 : CAN总线管理
- * 引用记录:
- * 备注:
- * 修订记录:
- * 日期 版本 作者 描述
- * 2011.07.14 00.01.00 李中 第一版
- *******************************************************************************/
- #include "HardwareLib.h"
- #include "CANNet.h"
- #include "AccPedCD.h"
- #include "BleCanProtocolFunc.h"
- #include "BcuCanProtocolFunc.h"
- #include "VcuCanProtocolFunc.h"
- MCANDrv_infoMsgConfS_TYPE CANNet_infoMsgTxConfSA[3];
- MCAN_stRetE_TYPE CAN1Result;
- uint16 CANNet_idxSchedUB;
- MCANDrv_infoMsgConfS_TYPE CANNet_InfoRxMsgConfSA[128];
- uint8 CANNet_datRxMsgBufM[128][9];
- CanMsgInfo infoVcuSendMsg;
- CanMsgInfo infoBmsSendMsg;
- volatile BOOL VcuSendFlg = FALSE;
- volatile BOOL BmsSendFlg = FALSE;
- void CANNet_Init(void)
- {
- /*示例代码*/
- /*各个CAN节点初始化*/
- MCANDrv_SetBaudrate(_CAN_INDEX_CAN0, 250000);
- MCANDrv_SetCANMode(_CAN_INDEX_CAN0, MCAN_NODEMODE_BUF);
- MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN0, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN0, NULL_PTR);
- MCANDrv_SetBaudrate(_CAN_INDEX_CAN1, 250000);
- MCANDrv_SetCANMode(_CAN_INDEX_CAN1, MCAN_NODEMODE_BUF);
- MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN1, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN1, NULL_PTR);
- /*第2路CAN用于CCP、UDS协议,由底层配置*/
- // MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN2, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN2, NULL_PTR);
- /*接收报文初始化,主要配置CAN2*/
- CANNet_InfoRxMsgConfSA[0].infoMsgIDUI = 0x1CEF0000UL;
- CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.CAN = 2;
- CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.MO = 3;
- CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DIR = _MCAN_DIR_RX;
- CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DLC = 8;
- CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[0], CANNet_RecvMsgCAN2);
- CANNet_InfoRxMsgConfSA[1].infoMsgIDUI = 0x1C00ECEAUL;
- CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.CAN = 2;
- CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.MO = 4;
- CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.DIR = _MCAN_DIR_RX;
- CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.DLC = 8;
- CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[1], CANNet_RecvMsgCAN2);
- /*发送报文初始化*/
- CANNet_infoMsgTxConfSA[0].infoMsgIDUI = 0x1F000024UL;
- CANNet_infoMsgTxConfSA[0].infoMsgParU.B.CAN = 0;
- CANNet_infoMsgTxConfSA[0].infoMsgParU.B.MO = 0;
- CANNet_infoMsgTxConfSA[0].infoMsgParU.B.DIR = _MCAN_DIR_TX;
- CANNet_infoMsgTxConfSA[0].infoMsgParU.B.DLC = 8;
- CANNet_infoMsgTxConfSA[0].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- // MCANDrv_SetMsgObj(CANNet_infoMsgTxConfSA[0], NULL_PTR);
- CANNet_infoMsgTxConfSA[1].infoMsgIDUI = 0x1F000025UL;
- CANNet_infoMsgTxConfSA[1].infoMsgParU.B.CAN = 1;
- CANNet_infoMsgTxConfSA[1].infoMsgParU.B.MO = 1;
- CANNet_infoMsgTxConfSA[1].infoMsgParU.B.DIR = _MCAN_DIR_TX;
- CANNet_infoMsgTxConfSA[1].infoMsgParU.B.DLC = 8;
- CANNet_infoMsgTxConfSA[1].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- // MCANDrv_SetMsgObj(CANNet_infoMsgTxConfSA[1], NULL_PTR);
- CANNet_infoMsgTxConfSA[2].infoMsgIDUI = 0x1F000026UL;
- CANNet_infoMsgTxConfSA[2].infoMsgParU.B.CAN = 2;
- CANNet_infoMsgTxConfSA[2].infoMsgParU.B.MO = 2;
- CANNet_infoMsgTxConfSA[2].infoMsgParU.B.DIR = _MCAN_DIR_TX;
- CANNet_infoMsgTxConfSA[2].infoMsgParU.B.DLC = 8;
- CANNet_infoMsgTxConfSA[2].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- }
- // CAN0接收消息处理函数 VCU
- void CANNet_RecvMsgCAN0(MCANDrv_infoMsgS_TYPE infoMsgS)
- {
- //直连状态下,CAN0空置,连接CAN1
- //非直连状态下,CAN0接收VCU消息
- VcuDecodeFunction(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
- infoVcuSendMsg.CanID = infoMsgS.infoConfS.infoMsgIDUI;
- memcpy(infoVcuSendMsg.CanData,infoMsgS.datMsgUBA,8);
- VcuSendFlg = TRUE;
- if((infoVcuSendMsg.CanID&0x0000FFFF)==0x0000F3D0||(infoVcuSendMsg.CanID&0x0000FFFF)==0x000015F6||(infoVcuSendMsg.CanID&0x0000FFFF)==0x000051ED||(infoVcuSendMsg.CanID&0x0000FFFF)==0x1C00EDEA)
- {
- CANNet_infoMsgTxConfSA[1].infoMsgIDUI = infoVcuSendMsg.CanID;
- infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[1];
- memset(infoMsgS.datMsgUBA, 0x00, 8);
- if((infoVcuSendMsg.CanID==0x1802F3D0)&& 0)
- {
- static uint8 VcuLife = 0;
- uint8 chk = 0;
- VcuLife = (VcuLife+1)>14?0:(VcuLife+1);
- infoVcuSendMsg.CanData[1] = (BattHvCtl<<4)|(VcuLife&0x0F);
- for(uint8 i=1;i<8;i++)
- {
- chk = chk^infoVcuSendMsg.CanData[i];
- }
- infoVcuSendMsg.CanData[0] = chk;
- }
- memcpy(infoMsgS.datMsgUBA,infoVcuSendMsg.CanData,8);
- MCANDrv_SendMsg(infoMsgS);
- }
- }
- // CAN1接收消息处理函数
- void CANNet_RecvMsgCAN1(MCANDrv_infoMsgS_TYPE infoMsgS)
- {
- BcuDecodeFunction(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
- infoBmsSendMsg.CanID = infoMsgS.infoConfS.infoMsgIDUI;
- memcpy(infoBmsSendMsg.CanData,infoMsgS.datMsgUBA,8);
- BmsSendFlg = TRUE;
- CANNet_infoMsgTxConfSA[0].infoMsgIDUI = infoBmsSendMsg.CanID;
- static uint8 TmsErrorFltTemp = 0;
- if((infoBmsSendMsg.CanID==0x1880D0F3)&& 0)//主负继电器状态和主正一起发出 加TMS故障屏蔽
- {
- uint8 DataTemp = 0x00;
- if(((infoBmsSendMsg.CanData[1]>>4)&0x03)==0x02)//主负继电器状态和主正一起发出
- {
- DataTemp = infoBmsSendMsg.CanData[1]&0x3F;
- DataTemp = DataTemp|((0x02)<<6);
- infoBmsSendMsg.CanData[1] = DataTemp;
- }
- else
- {
- DataTemp = infoBmsSendMsg.CanData[1]&0x3F;
- DataTemp = DataTemp|((0x01)<<6);
- infoBmsSendMsg.CanData[1] = DataTemp;
- }
- if(infoBmsSendMsg.CanData[7]==93)//TMS故障屏蔽
- {
- TmsErrorFltTemp = 1;
- clrbit(infoBmsSendMsg.CanData[4],6);
- infoBmsSendMsg.CanData[7] = 0;
- }
- }
- if((infoBmsSendMsg.CanID==0x1881D0F3)&& TmsErrorFltTemp)//屏蔽Tms出现的故障等级
- {
- uint8 chk = 0;
- uint8 ErrNum = 0;
- clrbit(infoBmsSendMsg.CanData[2],5);
- clrbit(infoBmsSendMsg.CanData[2],6);
- ErrNum = (infoBmsSendMsg.CanData[7]>>3);
- ErrNum = (ErrNum-1)<=0?0:(ErrNum-1);
- infoBmsSendMsg.CanData[7] = (infoBmsSendMsg.CanData[7]&0x03)|(ErrNum<<3);
- for(uint8 i=1;i<8;i++)
- {
- chk = chk^infoBmsSendMsg.CanData[i];
- }
- infoVcuSendMsg.CanData[0] = chk;
- }
- infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[0];
- memset(infoMsgS.datMsgUBA, 0x00, 8);
- memcpy(infoMsgS.datMsgUBA,infoBmsSendMsg.CanData,8);
- MCANDrv_SendMsg(infoMsgS);
- }
- /*备注,CAN2接收报文时,需要配置接收报文的MO号,如果不配置,将进入不了CAN中断*/
- void CANNet_RecvMsgCAN2(MCANDrv_infoMsgS_TYPE infoMsgS)
- {
- Can2ProtocolDecode(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
- }
- //发送消息管理
- void CAN0Net_Manage1ms(void)
- {
- MCANDrv_infoMsgS_TYPE infoMsgS;
- if(BmsSendFlg){
- //BmsSendFlg = FALSE;
- }
- }
- void CAN1Net_Manage1ms(void)
- {
- static UINT32 Can1TimerCounter = 0;
- static UINT8 BcuIDIdx = 0;
- static BOOL BcuChkFlg = FALSE;
- MCANDrv_infoMsgS_TYPE infoMsgS;
- if (Can1TimerCounter % 100 == 0)
- {
- if (Can1TimerCounter % (EbcOutTable[BcuIDIdx][1]) == 0)
- {
- CANNet_infoMsgTxConfSA[1].infoMsgIDUI = EbcOutTable[BcuIDIdx][0];
- infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[1];
- memset(infoMsgS.datMsgUBA, 0x00, 8);
- BcuEncodeFunction(EbcOutTable[BcuIDIdx][0], &(infoMsgS.datMsgUBA[0]));
- MCANDrv_SendMsg(infoMsgS);
- }
- BcuIDIdx++;
- BcuChkFlg = FALSE;
- }
- else if(VcuSendFlg){
- //VcuSendFlg = FALSE;
- }
- if (BcuIDIdx >= (sizeof(EbcOutTable) / 8))
- {
- BcuIDIdx = 0;
- BcuChkFlg = TRUE;
- }
- if (BcuChkFlg)
- {
- Can1TimerCounter = Can1TimerCounter + 1;
- }
- }
- void CAN2Net_Manage1ms(void)
- {
- MCANDrv_infoMsgS_TYPE infoMsgS;
- static UINT32 Can2TimerCounter = 0;
- static uint8 Can2SendIdx = 0;
- BOOL Can2SendChkFlg = 0;
- if (Can2TimerCounter % 100 == 0)
- {
- if (Can2TimerCounter % (Can2OutTable[Can2SendIdx][1]) == 0)
- {
- CANNet_infoMsgTxConfSA[2].infoMsgIDUI = Can2OutTable[Can2SendIdx][0];
- infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[2];
- memset(infoMsgS.datMsgUBA, 0x00, 8);
- Can2EncodeFunction(Can2OutTable[Can2SendIdx][0], &(infoMsgS.datMsgUBA[0]));
- MCANDrv_SendMsg(infoMsgS);
- }
- Can2SendIdx++;
- Can2SendChkFlg = FALSE;
- }
- if (Can2SendIdx >= (sizeof(Can2OutTable) / 8))
- {
- Can2SendIdx = 0;
- Can2SendChkFlg = TRUE;
- }
- if (Can2SendChkFlg)
- {
- Can2TimerCounter = Can2TimerCounter + 1;
- }
- }
|