/*********************************************************************//** THE MAIN CAN BODY **********************************************************************/ int c_entry(void) { /* Main Program */ uint32_t i; uint32_t cnt; CAN_ERROR error; CAN_PinCFG_Type CAN1PinStruct, CAN2PinStruct; NVIC_DeInit(); NVIC_SCBDeInit(); /* Configure the NVIC Preemption Priority Bits: * two (2) bits of preemption priority, six (6) bits of sub-priority. * Since the Number of Bits used for Priority Levels is five (5), so the * actual bit number of sub-priority is three (3) */ NVIC_SetPriorityGrouping(0x06); // Set Vector table offset value #if (__RAM_MODE__==1) NVIC_SetVTOR(0x10000000); #else NVIC_SetVTOR(0x00000000); #endif debug_frmwrk_init(); print_menu(); /* Pin Configuration */ CAN1PinStruct.RD = CAN_RD1_P0_0; CAN1PinStruct.TD = CAN_TD1_P0_1; CAN2PinStruct.RD = CAN_RD2_P2_7; CAN2PinStruct.TD = CAN_TD2_P2_8; PINSEL_ConfigPin((PINSEL_CFG_Type *) (&can_rd1_pin[CAN1PinStruct.RD])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&can_td1_pin[CAN1PinStruct.TD])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&can_rd2_pin[CAN2PinStruct.RD])); PINSEL_ConfigPin((PINSEL_CFG_Type *) (&can_td2_pin[CAN2PinStruct.TD])); //Initialize CAN1 & CAN2 CAN_Init(LPC_CAN1, 125000); CAN_Init(LPC_CAN2, 125000); //Enable Receive Interrupt CAN_IRQCmd(LPC_CAN2, CANINT_FCE, ENABLE); CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE); CAN_IRQCmd(LPC_CAN2, CANINT_DOIE, ENABLE); CAN_SetupCBS(CANINT_FCE, CAN_Callback0); CAN_SetupCBS(CANINT_RIE, CAN_Callback1); CAN_SetupCBS(CANINT_DOIE, CAN_Callback2); //Enable CAN Interrupt NVIC_EnableIRQ(CAN_IRQn); /* First, we send 10 messages: * - message 0,2,4,6,8 have id in AFLUT >>> will be received * - message 1,3,5,7,9 don't have id in AFLUT >>> will be ignored * Then, we change AFLUT by load/remove entries in AFLUT and re-send messages * - message 1,3,5,7,9 have id in AFLUT >>> will be received * - message 0,2,4,6,8 don't have id in AFLUT >>> will be ignored * Note that: FullCAN Object must be read from FullCAN Object Section next to AFLUT */ /*-------------------------Init Message & AF Look-up Table------------------------*/ _DBG_("Test Acceptance Filter function..."); _DBG_("Press '1' to initialize message and AF Loop-up Table...");_DBG_(""); while(_DG !='1'); CAN_InitAFMessage(); /* initialize Transmit Message */ _DBG_("Init message finished!!!"); CAN_SetupAFTable(); /* initialize AF Look-up Table sections*/ error = CAN_SetupAFLUT(LPC_CANAF,&AFTable); /* install AF Look-up Table */ if (error != CAN_OK) { _DBG_("Setup AF: ERROR..."); while (1); // AF Table has error } else _DBG_("Setup AF: SUCCESSFUL!!!");_DBG_(""); /*-------------------------Send messages------------------------*/ _DBG_("Press '2' to start CAN transferring operation...");_DBG_(""); while(_DG !='2'); for (i = 0; i < CAN_TX_MSG_CNT; i++) { CAN_SendMsg(LPC_CAN1, &AFTxMsg[i]); PrintMessage(&AFTxMsg[i]);_DBG_(""); for(cnt=0;cnt<10000;cnt++); //transmit delay CANTxCount++; } _DBG_("Sending finished !!!"); /*-------------------------Display Received messages------------------------*/ _DBG_("Press '3' to display received messages...");_DBG_(""); while(_DG !='3'); for (i = 0; i < CAN_RX_MSG_CNT; i++) { PrintMessage(&AFRxMsg[i]);_DBG_(""); } /*-------------------------Change AFLUT Table --------------------*/ _DBG_("Press '4' to change AF look-up table...");_DBG_(""); while(_DG !='4'); CAN_ChangeAFTable(); _DBG_("Change AFLUT: FINISHED!!!"); CAN_SetAFMode(LPC_CANAF, CAN_eFCAN); CAN_InitAFMessage(); CANRxCount = CANTxCount = 0; /*-------------------------Re-Send messages------------------------*/ _DBG_("Press '5' to re-send messages...");_DBG_(""); while(_DG !='5'); for (i = 0; i < CAN_TX_MSG_CNT; i++) { CAN_SendMsg(LPC_CAN1, &AFTxMsg[i]); PrintMessage(&AFTxMsg[i]);_DBG_(""); for(cnt=0;cnt<10000;cnt++); //transmit delay CANTxCount++; } /*-------------------------Display received messages------------------------*/ _DBG_("Re-Sending finished !!!"); _DBG_("Press '6' to display received messages...");_DBG_(""); while(_DG !='6'); for (i = 0; i < CAN_RX_MSG_CNT; i++) { PrintMessage(&AFRxMsg[i]);_DBG_(""); } _DBG_("Demo terminal !!!"); CAN_DeInit(LPC_CAN1); CAN_DeInit(LPC_CAN2); while (1); return 0; }
/*********************************************************************//** * @brief c_entry: Main CAN program body * @param[in] none * @return int **********************************************************************/ int c_entry(void) { /* Main Program */ uint32_t i; uint32_t cnt; CAN_ERROR error; PINSEL_CFG_Type PinCfg; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* Pin configuration * CAN1: select P0.0 as RD1. P0.1 as TD1 * CAN2: select P2.7 as RD2, P2.8 as RD2 */ PinCfg.Funcnum = 1; PinCfg.OpenDrain = 0; PinCfg.Pinmode = 0; PinCfg.Pinnum = 0; PinCfg.Portnum = 0; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 1; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 7; PinCfg.Portnum = 2; PINSEL_ConfigPin(&PinCfg); PinCfg.Pinnum = 8; PINSEL_ConfigPin(&PinCfg); //Initialize CAN1 & CAN2 CAN_Init(LPC_CAN1, 125000); CAN_Init(LPC_CAN2, 125000); //Enable Receive Interrupt CAN_IRQCmd(LPC_CAN2, CANINT_FCE, ENABLE); CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE); //Enable CAN Interrupt NVIC_EnableIRQ(CAN_IRQn); /* First, we send 10 messages: * - message 0,2,4,6,8 have id in AFLUT >>> will be received * - message 1,3,5,7,9 don't have id in AFLUT >>> will be ignored * Then, we change AFLUT by load/remove entries in AFLUT and re-send messages * - message 1,3,5,7,9 have id in AFLUT >>> will be received * - message 0,2,4,6,8 don't have id in AFLUT >>> will be ignored * Note that: FullCAN Object must be read from FullCAN Object Section next to AFLUT */ /*-------------------------Init Message & AF Look-up Table------------------------*/ _DBG_("Test Acceptance Filter function..."); _DBG_("Press '1' to initialize message and AF Loop-up Table...");_DBG_(""); while(_DG !='1'); CAN_InitAFMessage(); /* initialize Transmit Message */ _DBG_("Init message finished!!!"); CAN_SetupAFTable(); /* initialize AF Look-up Table sections*/ error = CAN_SetupAFLUT(LPC_CANAF,&AFTable); /* install AF Look-up Table */ if (error != CAN_OK) { _DBG_("Setup AF: ERROR..."); while (1); // AF Table has error } else _DBG_("Setup AF: SUCCESSFUL!!!");_DBG_(""); /*-------------------------Send messages------------------------*/ _DBG_("Press '2' to start CAN transferring operation...");_DBG_(""); while(_DG !='2'); for (i = 0; i < CAN_TX_MSG_CNT; i++) { CAN_SendMsg(LPC_CAN1, &AFTxMsg[i]); PrintMessage(&AFTxMsg[i]);_DBG_(""); for(cnt=0;cnt<10000;cnt++); //transmit delay CANTxCount++; } _DBG_("Sending finished !!!"); /*-------------------------Display Received messages------------------------*/ _DBG_("Press '3' to display received messages...");_DBG_(""); while(_DG !='3'); for (i = 0; i < CAN_RX_MSG_CNT; i++) { PrintMessage(&AFRxMsg[i]);_DBG_(""); } /*-------------------------Change AFLUT Table --------------------*/ _DBG_("Press '4' to change AF look-up table...");_DBG_(""); while(_DG !='4'); CAN_ChangeAFTable(); _DBG_("Change AFLUT: FINISHED!!!"); CAN_SetAFMode(LPC_CANAF, CAN_eFCAN); CAN_InitAFMessage(); CANRxCount = CANTxCount = 0; /*-------------------------Re-Send messages------------------------*/ _DBG_("Press '5' to re-send messages...");_DBG_(""); while(_DG !='5'); for (i = 0; i < CAN_TX_MSG_CNT; i++) { CAN_SendMsg(LPC_CAN1, &AFTxMsg[i]); PrintMessage(&AFTxMsg[i]);_DBG_(""); for(cnt=0;cnt<10000;cnt++); //transmit delay CANTxCount++; } /*-------------------------Display received messages------------------------*/ _DBG_("Re-Sending finished !!!"); _DBG_("Press '6' to display received messages...");_DBG_(""); while(_DG !='6'); for (i = 0; i < CAN_RX_MSG_CNT; i++) { PrintMessage(&AFRxMsg[i]);_DBG_(""); } _DBG_("Demo terminal !!!"); CAN_DeInit(LPC_CAN1); CAN_DeInit(LPC_CAN2); while (1); return 0; }
/*********************************************************************//** * @brief c_entry: Main CAN program body * @param[in] none * @return none **********************************************************************/ void c_entry(void) { uint32_t i; volatile uint32_t cnt; CAN_ERROR error; CANRxCount = CANTxCount = 0; /* Initialize debug via UART0 * – 115200bps * – 8 data bit * – No parity * – 1 stop bit * – No flow control */ debug_frmwrk_init(); print_menu(); /* Pin configuration * CAN1: select P0.0 as RD1. P0.1 as TD1 * CAN2: select P0.4 as RD2, P0.5 as RD2 */ PINSEL_ConfigPin (0, 0, 1); PINSEL_ConfigPin (0, 1, 1); #if (RECVD_CAN_NO != CAN_1) PINSEL_ConfigPin (0, 4, 2); PINSEL_ConfigPin (0, 5, 2); #endif //Initialize CAN1 & CAN2 CAN_Init(CAN_1, 125000); #if (RECVD_CAN_NO != CAN_1) CAN_Init(RECVD_CAN_NO, 125000); #endif //Enable Receive Interrupt CAN_IRQCmd(RECVD_CAN_NO, CANINT_FCE, ENABLE); CAN_IRQCmd(RECVD_CAN_NO, CANINT_RIE, ENABLE); //Enable CAN Interrupt NVIC_EnableIRQ(CAN_IRQn); /* First, we send 10 messages: * - message 0,2,4,6,8 have id in AFLUT >>> will be received * - message 1,3,5,7,9 don't have id in AFLUT >>> will be ignored * Then, we change AFLUT by load/remove entries in AFLUT and re-send messages * - message 1,3,5,7,9 have id in AFLUT >>> will be received * - message 0,2,4,6,8 don't have id in AFLUT >>> will be ignored * Note that: FullCAN Object must be read from FullCAN Object Section next to AFLUT */ /*-------------------------Init Message & AF Look-up Table------------------------*/ _DBG_("Test Acceptance Filter function..."); _DBG_("Press '1' to initialize message and AF Loop-up Table...");_DBG_(""); while(_DG !='1'); /* initialize Transmit Message */ CAN_InitAFMessage(); _DBG_("Init message finished!!!"); /* initialize AF Look-up Table sections*/ CAN_SetupAFTable(); /* install AF Look-up Table */ error = CAN_SetupAFLUT(&AFTable); if (error != CAN_OK) { _DBG_("Setup AF: ERROR..."); while (1); // AF Table has error } else { _DBG_("Setup AF: SUCCESSFUL!!!");_DBG_(""); } /*-------------------------Send messages------------------------*/ _DBG_("Press '2' to start CAN transferring operation...");_DBG_(""); while(_DG !='2'); for (i = 0; i < CAN_TX_MSG_CNT; i++) { CAN_SendMsg(CAN_1, (CAN_MSG_Type *)&AFTxMsg[i]); PrintMessage((CAN_MSG_Type *)&AFTxMsg[i]);_DBG_(""); for(cnt=0;cnt<10000;cnt++); //transmit delay CANTxCount++; } _DBG_("Sending finished !!!");_DBG_(""); if(CANRxCount == 0) { _DBG_(">>> No message is recieved. Please check the connection between 2 CANs!!!");_DBG_(""); } /*-------------------------Display Received messages------------------------*/ _DBG_("Press '3' to display received messages...");_DBG_(""); while(_DG !='3'); for (i = 0; i < CAN_RX_MSG_CNT; i++) { PrintMessage((CAN_MSG_Type *)&AFRxMsg[i]);_DBG_(""); } /*-------------------------Change AFLUT Table --------------------*/ _DBG_("Press '4' to change AF look-up table...");_DBG_(""); while(_DG !='4'); CAN_ChangeAFTable(); _DBG_("Change AFLUT: FINISHED!!!"); //CAN_SetAFMode(LPC_CANAF, CAN_eFCAN); CAN_SetAFMode(CAN_EFCAN); CAN_InitAFMessage(); CANRxCount = CANTxCount = 0; /*-------------------------Re-Send messages------------------------*/ _DBG_("Press '5' to re-send messages...");_DBG_(""); while(_DG !='5'); for (i = 0; i < CAN_TX_MSG_CNT; i++) { CAN_SendMsg(CAN_1, (CAN_MSG_Type *)&AFTxMsg[i]); PrintMessage((CAN_MSG_Type *)&AFTxMsg[i]);_DBG_(""); for(cnt=0;cnt<10000;cnt++); //transmit delay CANTxCount++; } /*-------------------------Display received messages------------------------*/ _DBG_("Re-Sending finished !!!");_DBG_(""); if(CANRxCount == 0) { _DBG_(">>> No message is recieved. Please check the connection between 2 CANs!!!");_DBG_(""); } _DBG_("Press '6' to display received messages...");_DBG_(""); while(_DG !='6'); for (i = 0; i < CAN_RX_MSG_CNT; i++) { PrintMessage((CAN_MSG_Type *)&AFRxMsg[i]);_DBG_(""); } _DBG_("Demo terminal !!!"); CAN_DeInit(CAN_1); #if (RECVD_CAN_NO != CAN_1) CAN_DeInit(CAN_2); #endif while (1); }