Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CANIntHandler(void)
- {
- uint32_t ui32Status;
- tCANMsgObject sMsgObjectRx;
- uint8_t msg_data[8];
- sMsgObjectRx.pui8MsgData = msg_data;
- //
- // Read the CAN interrupt status to find the cause of the interrupt
- //
- ui32Status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE);
- //
- // If the cause is a controller status interrupt, then get the status
- //
- if(ui32Status == CAN_INT_INTID_STATUS)
- {
- ui32Status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
- if(ui32Status & CAN_STATUS_TXOK)
- {
- ++can_tx_ok_counter;
- }
- else if(ui32Status == CAN_STATUS_RXOK)
- {
- ++can_rx_ok_counter;
- }
- else
- {
- can_err_flag = 1U;
- ++can_err_counter;
- }
- }
- else
- { // Service interrupts due to the various configured CAN message objects...
- switch(ui32Status)
- {
- case 1:
- CANMessageGet(CAN0_BASE, 1, &sMsgObjectRx, 1); // Clear TX interrupt
- serialport_highlevel_tx_isr(uart5_can_port_ptr); // Service the rest of the buffer on this comm channel
- break;
- case 2:
- CANMessageGet(CAN0_BASE, 2, &sMsgObjectRx, 1);
- // CANMessageSet() is called from here to service circular buffer
- // Debug note: Printing out the "sent" characters from this routine shows
- // conclusively that the bytes are actually "sent" as in CANMessageSet() is in fact
- // called for each of the desired bytes. However, it appears that some bytes don't actually end up on
- // the bus...
- serialport_highlevel_tx_isr(uart6_can_port_ptr);
- SysCtlDelay(5000); // WTF?? Without this, we miss bytes on CAN bus...
- break;
- case 3:
- CANMessageGet(CAN0_BASE, 3, &sMsgObjectRx, 1);
- serialport_highlevel_tx_isr(uart7_can_port_ptr);
- break;
- case 4:
- serialport_highlevel_rx_isr(uart5_can_port_ptr);
- break;
- case 5:
- serialport_highlevel_rx_isr(uart6_can_port_ptr);
- break;
- case 6:
- serialport_highlevel_rx_isr(uart7_can_port_ptr);
- break;
- default:
- can_err_flag = 2U;
- ++can_err_counter;
- CANMessageGet(CAN0_BASE, ui32Status, &sMsgObjectRx, 1);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment