AnsweredAssumed Answered

An error occurs when the bus load rate is relatively high before the mpc5748g is powered on and the can interface is initialized

Question asked by 中州 周 on Jan 22, 2020
Latest reply on Jan 24, 2020 by Petr Stancik
void flexcan_callback(uint8_t instance, flexcan_event_type_t eventType,
       uint32_t buffIdx, flexcan_state_t *flexcanState)
{
 //BaseType_t status;
 struct RECV_CAN_DATA frame;
#if 0
 if (FLEXCAN_EVENT_RX_COMPLETE == eventType)
 {
  switch(instance)
  {
   case INST_CANCOM1 :
    FLEXCAN_DRV_Receive(INST_CANCOM1, 1, &recv_buff[0]);
    frame.channel =1;
   break;
   case INST_CANCOM2:
    FLEXCAN_DRV_Receive(INST_CANCOM2, 1, &recv_buff[0]);
    frame.channel =2;
    break;
   case INST_CANCOM3 :
    FLEXCAN_DRV_Receive(INST_CANCOM3, 1, &recv_buff[0]);
    frame.channel =3;
   break;
   case INST_CANCOM4 :
    FLEXCAN_DRV_Receive(INST_CANCOM4, 1, &recv_buff[0]);
    frame.channel =4;
    break;
   case INST_CANCOM5 :
    FLEXCAN_DRV_Receive(INST_CANCOM5, 1, &recv_buff[0]);
    frame.channel =5;
    break;
   default:
   break;
  }
#ifdef FREERTOS
  frame.relative_time = PIT_DRV_GetCurrentTimerUs(INST_PIT1,0);
  frame.canId = recv_buff[0].msgId;
  memcpy(frame.can_data,recv_buff[0].data,8);
  status = xQueueSendToBackFromISR(rcv_queue,(void *const)&frame,pdTRUE);
  if(status != pdPASS)
  {
  }
#else if
  frame_data[write_pstr].relative_time = PIT_DRV_GetCurrentTimerUs(INST_PIT1,0);
  frame_data[write_pstr].canId = recv_buff[0].msgId;
  memcpy(frame_data[write_pstr].can_data,recv_buff[0].data,8);
  write_pstr++;
  if(write_pstr>=100)
   write_pstr=0;
#endif
 }
#endif
 if (FLEXCAN_EVENT_RXFIFO_COMPLETE == eventType)
 {
  switch(instance)
  {
   case INST_CANCOM1 :
    FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recv_buff[0]);
    frame_data[write_pstr].channel =1;
   break;
   case INST_CANCOM2:
    FLEXCAN_DRV_RxFifo(INST_CANCOM2,&recv_buff[0]);
    frame_data[write_pstr].channel =2;
    break;
   case INST_CANCOM3 :
    FLEXCAN_DRV_RxFifo(INST_CANCOM3,&recv_buff[0]);
    frame_data[write_pstr].channel =3;
   break;
   case INST_CANCOM4 :
    FLEXCAN_DRV_RxFifo(INST_CANCOM4,&recv_buff[0]);
    frame_data[write_pstr].channel =4;
    break;
   case INST_CANCOM5 :
    FLEXCAN_DRV_RxFifo(INST_CANCOM5,&recv_buff[0]);
    frame_data[write_pstr].channel =5;
    break;
   default:
   break;
  }
  time_count = xTaskGetTickCountFromISR() - create_file_time_count;
  if(write_pstr == read_pstr)
   write_pstr = read_pstr=0;
  frame_data[write_pstr].relative_time = time_count;
  frame_data[write_pstr].canId = recv_buff[0].msgId;
  memcpy(frame_data[write_pstr].can_data,recv_buff[0].data,8);
  write_pstr++;
  /*
  if(recv_buff[0].msgId == PP7_TIME_CANID)
  {
   memcpy(&real_time,recv_buff[0].data,8);
  }
  */
  if(write_pstr>=MAX_CAN_FRAME_LEN)
   write_pstr=0;
 }
}
/*
 * @brief: Send data via CAN to the specified mailbox with the specified message id
 * @param mailbox   : Destination mailbox number
 * @param messageId : Message ID
 * @param data      : Pointer to the TX data
 * @param len       : Length of the TX data
 * @return          : None
 */
void send_can_data(uint32_t mailbox, uint32_t messageId, uint8_t *data, uint32_t len)
{
    /* Set information about the data to be sent
     *  - 1 byte in length
     *  - Standard message ID
     *  - Bit rate switch enabled to use a different bitrate for the data segment
     *  - Flexible data rate enabled
     *  - Use zeros for FD padding
     */
    flexcan_data_info_t dataInfo =
    {
  .data_length = len,
  .msg_id_type = FLEXCAN_MSG_ID_STD,
  .enable_brs = false,
  .fd_enable = false,
  .fd_padding = 0U};
    /* Configure TX message buffer with index TX_MSG_ID and TX_MAILBOX*/
    FLEXCAN_DRV_ConfigTxMb(INST_CANCOM1, mailbox, &dataInfo, messageId);
    /* Execute send non-blocking */
    FLEXCAN_DRV_Send(INST_CANCOM1, mailbox, &dataInfo, messageId, data);
}
void can_set_filter(uint8_t instance,flexcan_msgbuff_id_type_t idType,uint32_t buffIdx,uint32_t mask)
{
 uint16_t id_counter;
    /* Check buffer index to avoid overflow */
    DEV_ASSERT(buffIdx < FEATURE_CAN_MAX_MB_NUM);
 for(id_counter=0;id_counter<16;id_counter++)
 {
  filterTable[id_counter].isRemoteFrame = false;
  filterTable[id_counter].isExtendedFrame = false;
  filterTable[id_counter].id = id_counter +1 ;
 }
 /* Configure RX FIFO ID filter table elements based on filter table defined above*/
 FLEXCAN_DRV_ConfigRxFifo(instance, FLEXCAN_RX_FIFO_ID_FORMAT_A, filterTable);
 FLEXCAN_DRV_SetRxMaskType(instance,FLEXCAN_RX_MASK_INDIVIDUAL);
 for(id_counter=0;id_counter<10;id_counter++)
  FLEXCAN_DRV_SetRxIndividualMask(instance, FLEXCAN_MSG_ID_EXT, id_counter, 0);
 /* rest of filter items are masked with RXFGMASK */
 FLEXCAN_DRV_SetRxFifoGlobalMask(instance, FLEXCAN_MSG_ID_STD, 0);
}
void can_cfg_rx_mb(uint8_t instance, uint8_t mb_idx, uint32_t msgid)
{
 flexcan_data_info_t rx_info =
 {
  .data_length = 8U,
  .msg_id_type = FLEXCAN_MSG_ID_STD,
  .enable_brs = false,
  .fd_enable = false,
  .fd_padding = 0U
 };
 FLEXCAN_DRV_ConfigRxMb(instance, mb_idx, &rx_info, msgid);
}
void can_dev_init()
{
 INT_SYS_DisableIRQGlobal();
 FLEXCAN_DRV_Init(INST_CANCOM1, &canCom1_State, &canCom1_InitConfig0);
 FLEXCAN_DRV_Init(INST_CANCOM2, &canCom2_State, &canCom2_InitConfig0);
 FLEXCAN_DRV_Init(INST_CANCOM3, &canCom3_State, &canCom3_InitConfig0);
 FLEXCAN_DRV_Init(INST_CANCOM4, &canCom4_State, &canCom4_InitConfig0);
 FLEXCAN_DRV_Init(INST_CANCOM5, &canCom5_State, &canCom5_InitConfig0);
 can_cfg_rx_mb(INST_CANCOM1, 1, 0);
 can_cfg_rx_mb(INST_CANCOM2, 1, 0);
 can_cfg_rx_mb(INST_CANCOM3, 1, 0);
 can_cfg_rx_mb(INST_CANCOM4, 1, 0);
 can_cfg_rx_mb(INST_CANCOM5, 1, 0);
 can_set_filter(INST_CANCOM1,FLEXCAN_MSG_ID_EXT,0,0);
 can_set_filter(INST_CANCOM2,FLEXCAN_MSG_ID_EXT,0,0);
 can_set_filter(INST_CANCOM4,FLEXCAN_MSG_ID_EXT,0,0);
 can_set_filter(INST_CANCOM5,FLEXCAN_MSG_ID_EXT,0,0);
 can_set_filter(INST_CANCOM3,FLEXCAN_MSG_ID_EXT,0,0);
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM1, flexcan_callback, ((void *)0));
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM2, flexcan_callback, ((void *)0));
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM3, flexcan_callback, ((void *)0));
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM4, flexcan_callback, ((void *)0));
 FLEXCAN_DRV_InstallEventCallback(INST_CANCOM5, flexcan_callback, ((void *)0));
 /*
 FLEXCAN_DRV_Receive(INST_CANCOM1, 1, &recv_buff[0]);
 FLEXCAN_DRV_Receive(INST_CANCOM2, 1, &recv_buff[1]);
 FLEXCAN_DRV_Receive(INST_CANCOM3, 1, &recv_buff[2]);
 FLEXCAN_DRV_Receive(INST_CANCOM4, 1, &recv_buff[3]);
 FLEXCAN_DRV_Receive(INST_CANCOM5, 1, &recv_buff[4]);
*/
 FLEXCAN_DRV_RxFifo(INST_CANCOM1,&recv_buff[0]);
 FLEXCAN_DRV_RxFifo(INST_CANCOM2,&recv_buff[1]);
 FLEXCAN_DRV_RxFifo(INST_CANCOM3,&recv_buff[2]);
 FLEXCAN_DRV_RxFifo(INST_CANCOM4,&recv_buff[3]);
 FLEXCAN_DRV_RxFifo(INST_CANCOM5,&recv_buff[4]);
 INT_SYS_EnableIRQGlobal();
}

Outcomes