//reserve CAN ROM-RAM 0x1000 0050 - 0x1000 00B9 __BSS(RESERVED) char CAN_driver_memory[0xC0]; |
ROM **rom = (ROM **)0x1fff1ff8; CAN_MSG_OBJ msg_obj; static uint32_t noAnswerErrorCount = 0; /* Initialize CAN Controller */ uint32_t ClkInitTable[2] = { 0x00000005UL, // CANCLKDIV 0x00000501UL // CAN_BTR 500kbps }; /* Callback function prototypes */ void CAN_rx(uint8_t msg_obj_num); void CAN_tx(uint8_t msg_obj_num); void CAN_error(uint32_t error_info); /* Publish CAN Callback Functions */ CAN_CALLBACKS callbacks = { CAN_rx, CAN_tx, CAN_error, NULL, NULL, NULL, NULL, NULL, }; /*CAN receive callback */ /*Function is executed by the Callback handler after a CAN message has been received */ void CAN_rx(uint8_t msg_obj_num){ noAnswerErrorCount = 0; /* Determine which CAN message has been received */ msg_obj.msgobj = msg_obj_num; /* Now load up the msg_obj structure with the CAN message */ (*rom)->pCAND->can_receive(&msg_obj); return; } /*CAN transmit callback */ /*Function is executed by the Callback handler after a CAN message has been transmitted */ void CAN_tx(uint8_t msg_obj_num) { return; } /*CAN error callback */ /*Function is executed by the Callback handler after an error has occured on the CAN bus */ void CAN_error(uint32_t error_info) { noAnswerErrorCount++; return; } /*CAN interrupt handler */ /*The CAN interrupt handler must be provided by the user application. It's function is to call the isr() API located in the ROM */ void CAN_IRQHandler (void){ (*rom)->pCAND->isr(); } void initCan(void) { bool result = true; /* Initialize the CAN controller */ (*rom)->pCAND->init_can(&ClkInitTable[0], 1); /* Configure the CAN callback functions */ (*rom)->pCAND->config_calb(&callbacks); /* Disable automatic repetition */ LPC_CAN->CNTL |= CTRL_DAR; /* Enable the CAN Interrupt */ NVIC_EnableIRQ(CAN_IRQn); noAnswerErrorCount = 0; } void speedCanRequest(void) { msg_obj.msgobj = 0; msg_obj.mode_id = 0x7DF; msg_obj.mask = 0x0; msg_obj.dlc = 8; msg_obj.data[0] = 0x02; msg_obj.data[1] = 0x01; msg_obj.data[2] = 0x0D; msg_obj.data[3] = 0x55; msg_obj.data[4] = 0x55; msg_obj.data[5] = 0x55; msg_obj.data[6] = 0x55; msg_obj.data[7] = 0x55; (*rom)->pCAND->can_transmit(&msg_obj); msg_obj.msgobj = 1; msg_obj.mode_id = 0x7E8; msg_obj.mask = 0x7E0; (*rom)->pCAND->config_rxmsgobj(&msg_obj); } |