09_FreeRTOS_CAN_loopback/user/CAN.cpp
/**
 * Try to put CAN message to mailbox.
 * @param  message Pointer to CAN message
 * @return         True if message was put in mailbox
 */
Try to put CAN message to mailbox.
@param  message Pointer to CAN message
@return         True if message was put in mailbox
Try to put CAN message to mailbox . @param message Pointer to CAN message @return True if message was put in mailbox
bool CAN_Transmit(const CAN_Tx_t *const message) {
  bool message_in_mailbox = false;
  uint8_t mailbox = UNDEFINED_MAILBOX;
  if ((CAN1->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) {
    mailbox = 0u;
  } else if ((CAN1->TSR & CAN_TSR_TME1) == CAN_TSR_TME1) {
    mailbox = 1u;
  } else if ((CAN1->TSR & CAN_TSR_TME2) == CAN_TSR_TME2) {
    mailbox = 2u;
  } else {
  }
  if (mailbox != UNDEFINED_MAILBOX) {
    message_in_mailbox = true;
    CAN1->sTxMailBox[mailbox].TIR = message->ExtId << CAN_TI0R_EXID_Pos;
    CAN1->sTxMailBox[mailbox].TIR |= CAN_TI0R_IDE;
    CAN1->sTxMailBox[mailbox].TIR |= message->RTR;
    CAN1->sTxMailBox[mailbox].TDTR = CAN_TDT0R_DLC;
    CAN1->sTxMailBox[mailbox].TDTR &= message->DLC;
    CAN1->sTxMailBox[mailbox].TDLR = message->Data[0u];
    CAN1->sTxMailBox[mailbox].TDLR |= message->Data[1u] << 8u;
    CAN1->sTxMailBox[mailbox].TDLR |= message->Data[2u] << 16u;
    CAN1->sTxMailBox[mailbox].TDLR |= message->Data[3u] << 24u;
    CAN1->sTxMailBox[mailbox].TDHR = message->Data[4u];
    CAN1->sTxMailBox[mailbox].TDHR |= message->Data[5u] << 8u;
    CAN1->sTxMailBox[mailbox].TDHR |= message->Data[6u] << 16u;
    CAN1->sTxMailBox[mailbox].TDHR |= message->Data[7u] << 24u;
    CAN1->sTxMailBox[mailbox].TIR |= CAN_TI0R_TXRQ;
  }
  return message_in_mailbox;
}
bool CAN_Transmit ( const CAN_Tx_t * const message ) { bool message_in_mailbox = false ; uint8_t mailbox = UNDEFINED_MAILBOX ; if ( ( CAN1 -> TSR & CAN_TSR_TME0 ) == CAN_TSR_TME0 ) { mailbox = 0u ; } else if ( ( CAN1 -> TSR & CAN_TSR_TME1 ) == CAN_TSR_TME1 ) { mailbox = 1u ; } else if ( ( CAN1 -> TSR & CAN_TSR_TME2 ) == CAN_TSR_TME2 ) { mailbox = 2u ; } else { } if ( mailbox != UNDEFINED_MAILBOX ) { message_in_mailbox = true ; CAN1 -> sTxMailBox [ mailbox ] . TIR = message -> ExtId << CAN_TI0R_EXID_Pos ; CAN1 -> sTxMailBox [ mailbox ] . TIR |= CAN_TI0R_IDE ; CAN1 -> sTxMailBox [ mailbox ] . TIR |= message -> RTR ; CAN1 -> sTxMailBox [ mailbox ] . TDTR = CAN_TDT0R_DLC ; CAN1 -> sTxMailBox [ mailbox ] . TDTR &= message -> DLC ; CAN1 -> sTxMailBox [ mailbox ] . TDLR = message -> Data [ 0u ] ; CAN1 -> sTxMailBox [ mailbox ] . TDLR |= message -> Data [ 1u ] << 8u ; CAN1 -> sTxMailBox [ mailbox ] . TDLR |= message -> Data [ 2u ] << 16u ; CAN1 -> sTxMailBox [ mailbox ] . TDLR |= message -> Data [ 3u ] << 24u ; CAN1 -> sTxMailBox [ mailbox ] . TDHR = message -> Data [ 4u ] ; CAN1 -> sTxMailBox [ mailbox ] . TDHR |= message -> Data [ 5u ] << 8u ; CAN1 -> sTxMailBox [ mailbox ] . TDHR |= message -> Data [ 6u ] << 16u ; CAN1 -> sTxMailBox [ mailbox ] . TDHR |= message -> Data [ 7u ] << 24u ; CAN1 -> sTxMailBox [ mailbox ] . TIR |= CAN_TI0R_TXRQ ; } return message_in_mailbox ; }
Try to put CAN message to mailbox.
Try to put CAN message to mailbox .
/* Looking for first empty mailbox */ /* Fill tx mailbox */