MCAN_RxBufElement rxMsg; volatile uint32_t gRxPkts = 0; static void App_mcanIntrISR(void *arg) { uint32_t intrStatus; intrStatus = MCAN_getIntrStatus(gMcanBaseAddr); MCAN_clearIntrStatus(gMcanBaseAddr, intrStatus); /* Could remove Tx sub-ISR function */ if (MCAN_INTR_SRC_TRANS_COMPLETE == (intrStatus & MCAN_INTR_SRC_TRANS_COMPLETE)) { App_mcanIntrISRTx(); /* Could be posted at end of sub-ISR callback */ SemaphoreP_post(&gMcanTxDoneSem); } /* If FIFO0/FIFO1 is used, then MCAN_INTR_SRC_DEDICATED_RX_BUFF_MSG macro * needs to be replaced by MCAN_INTR_SRC_RX_FIFO0_NEW_MSG/ * MCAN_INTR_SRC_RX_FIFO1_NEW_MSG respectively */ if (MCAN_INTR_SRC_DEDICATED_RX_BUFF_MSG == (intrStatus & MCAN_INTR_SRC_DEDICATED_RX_BUFF_MSG)) { App_mcanIntrISRRx(); /* Could be posted at end of sub-ISR callback */ SemaphoreP_post(&gMcanRxDoneSem); } return; } static void App_mcanIntrISRTx(void) { MCAN_ProtocolStatus protStatus; MCAN_getProtocolStatus(gMcanBaseAddr, &protStatus); /* Checking for Tx Errors */ if (((MCAN_ERR_CODE_NO_ERROR != protStatus.lastErrCode) || (MCAN_ERR_CODE_NO_CHANGE != protStatus.lastErrCode)) && ((MCAN_ERR_CODE_NO_ERROR != protStatus.dlec) || (MCAN_ERR_CODE_NO_CHANGE != protStatus.dlec)) && (0U != protStatus.pxe)) { DebugP_assert(FALSE); } return; } static void App_mcanIntrISRRx(void) { MCAN_ErrCntStatus errCounter; MCAN_RxNewDataStatus newDataStatus; uint32_t bufNum, fifoNum; /* Checking for Rx Errors */ MCAN_getErrCounters(gMcanBaseAddr, &errCounter); DebugP_assert((0U == errCounter.recErrCnt) && (0U == errCounter.canErrLogCnt)); /* Get the new data staus, indicates buffer num which received message */ MCAN_getNewDataStatus(gMcanBaseAddr, &newDataStatus); MCAN_clearNewDataStatus(gMcanBaseAddr, &newDataStatus); /* Select buffer and fifo number, buffer is used in this example */ bufNum = 0U; fifoNum = MCAN_RX_FIFO_NUM_0; /* NOTE: Determine buffer offset if needed using received packets and number of packets in buffer */ bitPos = (1U << bufNum); if (bitPos == (newDataStatus.statusLow & bitPos)) { /* NOTE: Offset read address if needed */ MCAN_readMsgRam(gMcanBaseAddr, MCAN_MEM_TYPE_BUF, bufNum, fifoNum, &rxMsg); } else { DebugP_assert(FALSE); } /* Message ID for terminate message? */ if (id == SBL_CANFD_TERMINATE_MSG_ID) { gLastMsgFlag = 1; } return; } case SBL_CAN_RECV: { uint32_t buffOffset = 0; uint32_t totDataLen = 0; while (1) { /* Wait till a new data packet is received. */ /* NOTE: The gRxPkts can be replaced with this semaphore pend instead - though the original conditional would work too */ SemaphoreP_pend(&gMcanRxDoneSem); /* Check if the terminate Message Id is received? */ if (gLastMsgFlag != 0) { break; } buffOffset = (gPktsWrt % NUM_PKT_IN_BUFF); /* NOTE: Adjust flash write function to write proper size */ Flash_write(qspiFlashHandle, flashAddr, (uint8_t *)&rxMsg.data[buffOffset * 64], 64); /* Increment the Flash pointer. */ flashAddr += 64; /* Increment the number of packets written. */ /* NOTE: This does not needed to be used but I left it here in case you want to use it for something else*/ gPktsWrt++; totDataLen += 64; } dataLength = totDataLen; goto exitGetFile; }