i.MX RT 1176 FlexCAN FiFo EDMA transfer QUEUESEND USAGE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i.MX RT 1176 FlexCAN FiFo EDMA transfer QUEUESEND USAGE

365 Views
Vivekananda
Contributor I

Hi, 

i am uisng FIFO Edma transfer for the recieving the can data via call back function.

problem is that i am not able use xQueueSendFromISR or xQueueSend functions in call back function. 

following is the function implememtation.

 

 

static void CAN_DMA_Callback(CAN_Type *base, flexcan_edma_handle_t *handle, status_t status, void *userData)
{
(void)base;
(void)handle;
hal_can_t * pHanCb = (hal_can_t * )(userData);
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    /* Process FlexCAN Rx event. */
    if (kStatus_FLEXCAN_RxFifoIdle == status)
    {
    for (uint32_t i = 0; i < RX_MESSAGE_NUM; i++)
        {
    pHanCb->iIsDataReceived = 1;
 
pHanCb->sMsg[i].iEventId =0;
if(pHanCb->qRxMsg != NULL)
{
if(pdFALSE == xQueueIsQueueFullFromISR(pHanCb->qRxMsg))
{
memcpy(&pHanCb->sMsg[i].sRxFrame,&rxFrame[i],sizeof(flexcan_frame_t));
bool rval = xQueueSendFromISR(pHanCb->qRxMsg,
(void*)(&(pHanCb->sMsg[i])),
&xHigherPriorityTaskWoken);
 
 
if( rval != pdPASS )
{
NVIC_ClearPendingIRQ(pHanCb->IRqn);
}
}
else
{
PRINTF("\r\n The Data Queue is FULL\r\n");
}
}
        }
        /* Receive data through Rx FIFO. */
        pHanCb->rxFifoXfer.frame    = &rxFrame[0];
        pHanCb->rxFifoXfer.frameNum = RX_MESSAGE_NUM;
        (void)FLEXCAN_TransferReceiveFifoEDMA(pHanCb->pCanType, &pHanCb->hFlexcanEdmaHandle, &pHanCb->rxFifoXfer);
    }
}

 

0 Kudos
Reply
1 Reply

320 Views
mayliu1
NXP Employee
NXP Employee

Hi @Vivekananda ,

Thank you so much for your interest in our products and for using our community.

There are two key pointes need to check in your code:

1: Your CAN_DMA_Callback is called from an EDMA interrupt context. So In this case, you must use xQueueSendFromISR (not xQueueSend).

2: After calling xQueueSendFromISR, you need to check the xHigherPriorityTaskWoken flag and call portYIELD_FROM_ISR(xHigherPriorityTaskWoken)

mayliu1_0-1762938894194.png

 

Wish it helps you.
If you still have question about it, please kindly let me know.

Best Regards

MayLiu

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2202441%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Ei.MX%20RT%201176%20FlexCAN%20FiFo%20EDMA%20transfer%20QUEUESEND%20USAGE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2202441%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3Ei%20am%20uisng%20FIFO%20Edma%20transfer%20for%20the%20recieving%20the%20can%20data%20via%20call%20back%20function.%3C%2FP%3E%3CP%3Eproblem%20is%20that%20i%20am%20not%20able%20use%26nbsp%3BxQueueSendFromISR%20or%26nbsp%3BxQueueSend%20functions%20in%20call%20back%20function.%26nbsp%3B%3C%2FP%3E%3CP%3Efollowing%20is%20the%20function%20implememtation.%3C%2FP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CDIV%3Estatic%20void%20CAN_DMA_Callback(CAN_Type%20*base%2C%20flexcan_edma_handle_t%20*handle%2C%20status_t%20status%2C%20void%20*userData)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E(void)base%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E(void)handle%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ehal_can_t%20*%20pHanCb%20%3D%20(hal_can_t%20*%20)(userData)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EBaseType_t%20xHigherPriorityTaskWoken%20%3D%20pdFALSE%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Process%20FlexCAN%20Rx%20event.%20*%2F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20if%20(kStatus_FLEXCAN_RxFifoIdle%20%3D%3D%20status)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20for%20(uint32_t%20i%20%3D%200%3B%20i%20%26lt%3B%20RX_MESSAGE_NUM%3B%20i%2B%2B)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20pHanCb-%26gt%3BiIsDataReceived%20%3D%201%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EpHanCb-%26gt%3BsMsg%5Bi%5D.iEventId%20%3D0%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif(pHanCb-%26gt%3BqRxMsg%20!%3D%20NULL)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif(pdFALSE%20%3D%3D%20xQueueIsQueueFullFromISR(pHanCb-%26gt%3BqRxMsg))%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ememcpy(%26amp%3BpHanCb-%26gt%3BsMsg%5Bi%5D.sRxFrame%2C%26amp%3BrxFrame%5Bi%5D%2Csizeof(flexcan_frame_t))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ebool%20rval%20%3D%20xQueueSendFromISR(pHanCb-%26gt%3BqRxMsg%2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20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pHanCb-%26gt%3BrxFifoXfer.frame%26nbsp%3B%20%26nbsp%3B%20%3D%20%26amp%3BrxFrame%5B0%5D%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20pHanCb-%26gt%3BrxFifoXfer.frameNum%20%3D%20RX_MESSAGE_NUM%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20(void)FLEXCAN_TransferReceiveFifoEDMA(pHanCb-%26gt%3BpCanType%2C%20%26amp%3BpHanCb-%26gt%3BhFlexcanEdmaHandle%2C%20%26amp%3BpHanCb-%26gt%3BrxFifoXfer)%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2203449%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20i.MX%20RT%201176%20FlexCAN%20FiFo%20EDMA%20transfer%20QUEUESEND%20USAGE%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2203449%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F226296%22%20target%3D%22_blank%22%3E%40Vivekananda%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%0A%3CP%3EThank%20you%20so%20much%20for%20your%20interest%20in%20our%20products%20and%20for%20using%20our%20community.%3C%2FP%3E%0A%3CP%3EThere%20are%20two%20key%20pointes%20need%20to%20check%20in%20your%20code%3A%3C%2FP%3E%0A%3CP%3E1%3A%26nbsp%3BYour%20CAN_DMA_Callback%20is%20called%20from%20an%20EDMA%20interrupt%20context.%20So%20In%20this%20case%2C%20you%20must%20use%3CFONT%20color%3D%22%23993366%22%3E%20xQueueSendFromISR%3C%2FFONT%3E%20(not%20xQueueSend).%3C%2FP%3E%0A%3CP%3E2%3A%26nbsp%3BAfter%20calling%20%3CCODE%3ExQueueSendFromISR%3C%2FCODE%3E%2C%20you%20need%20to%20check%20the%20%3CCODE%3ExHigherPriorityTaskWoken%3C%2FCODE%3E%20flag%20and%20call%20%3CCODE%3EportYIELD_FROM_ISR(xHigherPriorityTaskWoken)%3C%2FCODE%3E.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22mayliu1_0-1762938894194.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22mayliu1_0-1762938894194.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F365206i3C1531D21FB21762%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22mayliu1_0-1762938894194.png%22%20alt%3D%22mayliu1_0-1762938894194.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EWish%20it%20helps%20you.%3CBR%20%2F%3EIf%20you%20still%20have%20question%20about%20it%2C%20please%20kindly%20let%20me%20know.%3C%2FP%3E%0A%3CP%3EBest%20Regards%3C%2FP%3E%0A%3CP%3EMayLiu%3C%2FP%3E%3C%2FLINGO-BODY%3E