09_FreeRTOS_CAN_loopback/user/CAN.cpp
/**
 * Try to receive CAN message from mailbox.
 * @param  message Pointer to CAN message
 * @return         True if message received
 */
Try to receive CAN message from mailbox.
@param  message Pointer to CAN message
@return         True if message received
Try to receive CAN message from mailbox . @param message Pointer to CAN message @return True if message received
bool CAN_Receive(CAN_Rx_t *const message) {
  bool message_received = false;
  int8_t mailbox;
  if ((CAN1->RF0R & CAN_RF0R_FMP0) != 0u) {
    message_received = true;
    mailbox = (CAN1->RF0R & CAN_RF0R_FMP0) - 1u;
    message->ExtId = CAN1->sFIFOMailBox[mailbox].RIR >> CAN_RI0R_EXID_Pos;
    message->RTR = CAN1->sFIFOMailBox[mailbox].RIR & CAN_RI0R_RTR;
    message->DLC = CAN1->sFIFOMailBox[mailbox].RDTR & CAN_RDT0R_DLC;
    message->FMI = CAN1->sFIFOMailBox[mailbox].RDTR >> CAN_RDT0R_FMI_Pos;
    message->Data[0u] = CAN1->sFIFOMailBox[mailbox].RDLR & 0xFFu;
    message->Data[1u] = (CAN1->sFIFOMailBox[mailbox].RDLR >> 8u) & 0xFFu;
    message->Data[2u] = (CAN1->sFIFOMailBox[mailbox].RDLR >> 16u) & 0xFFu;
    message->Data[3u] = (CAN1->sFIFOMailBox[mailbox].RDLR >> 24u) & 0xFFu;
    message->Data[4u] = CAN1->sFIFOMailBox[mailbox].RDHR & 0xFFu;
    message->Data[5u] = (CAN1->sFIFOMailBox[mailbox].RDHR >> 8u) & 0xFFu;
    message->Data[6u] = (CAN1->sFIFOMailBox[mailbox].RDHR >> 16u) & 0xFFu;
    message->Data[7u] = (CAN1->sFIFOMailBox[mailbox].RDHR >> 24u) & 0xFFu;
    CAN1->RF0R |= CAN_RF0R_RFOM0; 
  }
  return message_received;
}
bool CAN_Receive ( CAN_Rx_t * const message ) { bool message_received = false ; int8_t mailbox ; if ( ( CAN1 -> RF0R & CAN_RF0R_FMP0 ) != 0u ) { message_received = true ; mailbox = ( CAN1 -> RF0R & CAN_RF0R_FMP0 ) - 1u ; message -> ExtId = CAN1 -> sFIFOMailBox [ mailbox ] . RIR >> CAN_RI0R_EXID_Pos ; message -> RTR = CAN1 -> sFIFOMailBox [ mailbox ] . RIR & CAN_RI0R_RTR ; message -> DLC = CAN1 -> sFIFOMailBox [ mailbox ] . RDTR & CAN_RDT0R_DLC ; message -> FMI = CAN1 -> sFIFOMailBox [ mailbox ] . RDTR >> CAN_RDT0R_FMI_Pos ; message -> Data [ 0u ] = CAN1 -> sFIFOMailBox [ mailbox ] . RDLR & 0xFFu ; message -> Data [ 1u ] = ( CAN1 -> sFIFOMailBox [ mailbox ] . RDLR >> 8u ) & 0xFFu ; message -> Data [ 2u ] = ( CAN1 -> sFIFOMailBox [ mailbox ] . RDLR >> 16u ) & 0xFFu ; message -> Data [ 3u ] = ( CAN1 -> sFIFOMailBox [ mailbox ] . RDLR >> 24u ) & 0xFFu ; message -> Data [ 4u ] = CAN1 -> sFIFOMailBox [ mailbox ] . RDHR & 0xFFu ; message -> Data [ 5u ] = ( CAN1 -> sFIFOMailBox [ mailbox ] . RDHR >> 8u ) & 0xFFu ; message -> Data [ 6u ] = ( CAN1 -> sFIFOMailBox [ mailbox ] . RDHR >> 16u ) & 0xFFu ; message -> Data [ 7u ] = ( CAN1 -> sFIFOMailBox [ mailbox ] . RDHR >> 24u ) & 0xFFu ; CAN1 -> RF0R |= CAN_RF0R_RFOM0 ; } return message_received ; }
Try to receive CAN message from mailbox.
Try to receive CAN message from mailbox .
/* clear mailbox flag */