123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /********************************************************************************
- * 常州易控汽车电子股份有限公司
- * (c) Copyright 2009-2015 ECTEK
- * 保留所有权利
- ********************************************************************************
- * 工程名称:整车管理
- * 文件名: CANNet.c
- * 功能描述 : CAN总线管理
- * 引用记录:
- * 备注:
- * 修订记录:
- * 日期 版本 作者 描述
- * 2011.07.14 00.01.00 李中 第一版
- *******************************************************************************/
- #include <CanProtocolFunc.h>
- #include <CanProtocolFunc.h>
- #include "HardwareLib.h"
- #include "CANNet.h"
- #include "AccPedCD.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];
- 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)
- {
- Can0Decode(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
- }
- // CAN1接收消息处理函数
- void CANNet_RecvMsgCAN1(MCANDrv_infoMsgS_TYPE infoMsgS)
- {
- Can1Decode(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
- }
- /*备注,CAN2接收报文时,需要配置接收报文的MO号,如果不配置,将进入不了CAN中断*/
- void CANNet_RecvMsgCAN2(MCANDrv_infoMsgS_TYPE infoMsgS)
- {
- }
- //发送消息管理
- void CAN0Net_Manage1ms(void)
- {
- }
- 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 % (Can1OutTable[BcuIDIdx][1]) == 0)
- {
- CANNet_infoMsgTxConfSA[1].infoMsgIDUI = Can1OutTable[BcuIDIdx][0];
- infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[1];
- memset(infoMsgS.datMsgUBA, 0x00, 8);
- Can1Encode(Can1OutTable[BcuIDIdx][0], &(infoMsgS.datMsgUBA[0]));
- MCANDrv_SendMsg(infoMsgS);
- }
- BcuIDIdx++;
- BcuChkFlg = FALSE;
- }
- if (BcuIDIdx >= (sizeof(Can1OutTable) / 8))
- {
- BcuIDIdx = 0;
- BcuChkFlg = TRUE;
- }
- if (BcuChkFlg)
- {
- Can1TimerCounter = Can1TimerCounter + 1;
- }
- }
- void CAN2Net_Manage1ms(void)
- {
- }
|