// ---------------------------------------------------------------------------- // Low level function to receive a message from mailbox. // Called by Rx Interrupt or by getMessage. static void readMailbox(xpcc::can::Message& message, uint32_t mailboxId) { CAN_FIFOMailBox_TypeDef* mailbox = &CAN2->sFIFOMailBox[mailboxId]; uint32_t rir = mailbox->RIR; if (rir & CAN_RI0R_IDE) { message.identifier = rir >> 3; message.setExtended(); }
/* Low level function: * Called by interrupt or by getMessage to receive a message */ static void readMessageObject(xpcc::can::Message & message, uint8_t messageObjectId) { // NXP's data structure for sending CAN messages CAN_MSG_OBJ msg_obj; // Which Message Object to receive msg_obj.msgobj = messageObjectId; // Read Message Object from CAN controller (*xpcc::lpc::Can::rom)->pCAND->can_receive(&msg_obj); // Is extended Identifier? if (msg_obj.mode_id & CAN_MSGOBJ_EXT) { message.setExtended(); // The lower 29 bits are the extended identifier message.identifier = msg_obj.mode_id & 0x1fffffff; } else { message.setExtended(false); // The lower 11 bits are the standard identifier message.identifier = msg_obj.mode_id & 0x7ff; } // Is RTR ? message.setRemoteTransmitRequest( (msg_obj.mode_id & CAN_MSGOBJ_RTR) ); // Get DLC message.length = msg_obj.dlc; // Copy Data // TODO Use memcpy or reinterpret_cast for (uint8_t ii = 0; ii < message.length; ++ii) { message.data[ii] = msg_obj.data[ii]; } }