/* SPC5 RLA - Copyright (C) 2015 STMicroelectronics Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Inclusion of the main header files of all the imported components in the order specified in the application wizard. The file is generated automatically.*/ #include "components.h" #include "can_lld_cfg.h" /* * Application entry point. */ CANTxFrame txmsg; CANRxFrame xCANrxBuf; uint32_t ulTxData_CAN1 = 0; uint32_t ulTxData_CAN2 = 0; /********************************************************************************** * brief: Call this function when receive CAN message. * paras: * return none *********************************************************************************/ void configuration_CAN1_DEL_CTRL_Fifo_RX_CTRL_CMD(CANDriver *canp, CANRxFrame crfp) { /*Receive 0x112 with CAN1*/ if (crfp.IDE==CAN_IDE_STD && crfp.SID==0x112) { ulTxData_CAN1 = (uint32_t)crfp.data32[0]; } } void configuration_CAN2_A3_CTRL_Fifo_RX(CANDriver *canp, CANRxFrame crfp) { /*Receive 0x112 with CAN1*/ if ( crfp.IDE==CAN_IDE_EXT && ( (crfp.EID==0x08ff1081) || (crfp.EID==0x18ff0a81) ) ) { ulTxData_CAN2 = (uint32_t)crfp.data32[0]; } } int main(void) { uint32_t ulBreakCnt = 0; uint32_t ulDelayIndex; /* Initialization of all the imported components in the order specified in the application wizard. The function is generated automatically.*/ componentsInit(); /* Enable Interrupts */ irqIsrEnable(); can_lld_start(&CAND1, &can_config_configuration_CAN1_DEL_CTRL); /*MCAN SUB 0 CAN 0*/ can_lld_start(&CAND2, &can_config_configuration_CAN2_A3_CTRL); /*MCAN SUB 0 CAN 0*/ /* Application main loop.*/ for ( ; ; ) { /*transmit 0x113 with CAN1*/ txmsg.IDE = CAN_IDE_STD; txmsg.SID = 0x113; txmsg.LENGTH = 8; txmsg.RTR = CAN_RTR_DATA; txmsg.data32[0] = (uint32_t)ulTxData_CAN1; txmsg.data32[1] = (uint32_t)ulTxData_CAN1; while ( can_lld_transmit(&CAND1, 1, &txmsg) == CAN_MSG_WAIT) { ulBreakCnt++; if (ulBreakCnt >= 100) { ulBreakCnt = 0; break; } } txmsg.IDE = CAN_IDE_EXT; txmsg.EID = 0x08FF1080; txmsg.LENGTH = 8; txmsg.RTR = CAN_RTR_DATA; txmsg.data32[0] = (uint32_t)ulTxData_CAN2; txmsg.data32[1] = (uint32_t)ulTxData_CAN2; while ( can_lld_transmit(&CAND2, 2, &txmsg) == CAN_MSG_WAIT) { ulBreakCnt++; if (ulBreakCnt >= 100) { ulBreakCnt = 0; break; } } for (ulDelayIndex=0; ulDelayIndex<10000; ulDelayIndex++) ; ulDelayIndex = 0; } }