Accessing the Receive Buffer Full Flag (RXF) for KE06 through MCUXpresso SDK 2.4.1

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Accessing the Receive Buffer Full Flag (RXF) for KE06 through MCUXpresso SDK 2.4.1

ソリューションへジャンプ
889件の閲覧回数
tomolenik
Contributor I

I am working on a project with the FRDM-KE06Z using MCUXpresso IDE and SDK 2.4.1 where I must receive CAN messages of multiple message IDs. First, the documentation generated for the SDK built with the SDK generator for this device did not include anything on the MSCAN driver. So I'm looking at the KE06 Sub-Family Reference Manual, Rev 3, July 2016. 

In the reference manual it appears that I want my MSCAN call-back function to check the RXF flag (pages 610, 640, and 652) in the MSCAN_CANRFLG field to determine if there is a message ready to read from the foreground of the receiver FIFO. Specifically, in section 32.4.4 it says my receive handler must read the received message and reset the RXF flag when it is set.

When I look in the CAN driver source for the MCUXpresso SDK, the driver example projects that came with the SDK are using kStatus_MSCAN_RxIdle state in the the handler to determine if a message is available. 

I see the MSCAN_GetRxBufferFullFlag and MSCAN_ClearRxBufferFullFlag functions in the MSCAN driver source, but I wonder if the driver examples are achieving the same thing as using these functions or is there an advantage over using one way or the other?

ラベル(2)
0 件の賞賛
1 解決策
758件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Thomas,

The MSCAN example based on FRDM-KE06Z in ksdk package uses interrupt mechanism, when the CAN module receives ONE frame, the RXF flag is set, the ISR void MSCAN_TransferHandleIRQ(MSCAN_Type *base, mscan_handle_t *handle) is called automatically.

In the ISR,check the RXF flag, if it is set, read the received frame to a buffer, clear the RXF flag, call the     handle->callback(base, handle, status, handle->userData); callback function which you defined.

Hope it can help you

BR

XiangJun Rong

//in fsl_mscan.c file

void MSCAN_TransferHandleIRQ(MSCAN_Type *base, mscan_handle_t *handle)
{
    /* Assertion. */
    assert(handle);

    status_t status = kStatus_MSCAN_UnHandled;
    
    /* Get current State of Message Buffer. */
    if (MSCAN_GetRxBufferFullFlag(base))
    {
        switch (handle->mbStateRx)
        {
            /* Solve Rx Data Frame. */
            case kMSCAN_StateRxData:
                status = MSCAN_ReadRxMb(base, handle->mbFrameBuf);
                if (kStatus_Success == status)
                {
                    status = kStatus_MSCAN_RxIdle;
                }
                MSCAN_TransferAbortReceive(base, handle, kMSCAN_RxFullInterruptEnable);
                break;

            /* Solve Rx Remote Frame. */
            case kMSCAN_StateRxRemote:
                status = MSCAN_ReadRxMb(base, handle->mbFrameBuf);
                if (kStatus_Success == status)
                {
                    status = kStatus_MSCAN_RxIdle;
                }
                MSCAN_TransferAbortReceive(base, handle, kMSCAN_RxFullInterruptEnable);
                break;
        }
        MSCAN_ClearRxBufferFullFlag(base);
    }
    else
    {
        switch (handle->mbStateTx)
        {
            /* Solve Tx Data Frame. */
            case kMSCAN_StateTxData:
                status = kStatus_MSCAN_TxIdle;
                MSCAN_TransferAbortSend(base, handle, kMSCAN_TxEmptyInterruptEnable);
                break;

            /* Solve Tx Remote Frame. */
            case kMSCAN_StateTxRemote:
                handle->mbStateRx = kMSCAN_StateRxRemote;
                status = kStatus_MSCAN_TxSwitchToRx;
                break;

            default:
                status = kStatus_MSCAN_UnHandled;
                break;
        }
    }

    handle->callback(base, handle, status, handle->userData);
}

元の投稿で解決策を見る

0 件の賞賛
2 返答(返信)
759件の閲覧回数
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Thomas,

The MSCAN example based on FRDM-KE06Z in ksdk package uses interrupt mechanism, when the CAN module receives ONE frame, the RXF flag is set, the ISR void MSCAN_TransferHandleIRQ(MSCAN_Type *base, mscan_handle_t *handle) is called automatically.

In the ISR,check the RXF flag, if it is set, read the received frame to a buffer, clear the RXF flag, call the     handle->callback(base, handle, status, handle->userData); callback function which you defined.

Hope it can help you

BR

XiangJun Rong

//in fsl_mscan.c file

void MSCAN_TransferHandleIRQ(MSCAN_Type *base, mscan_handle_t *handle)
{
    /* Assertion. */
    assert(handle);

    status_t status = kStatus_MSCAN_UnHandled;
    
    /* Get current State of Message Buffer. */
    if (MSCAN_GetRxBufferFullFlag(base))
    {
        switch (handle->mbStateRx)
        {
            /* Solve Rx Data Frame. */
            case kMSCAN_StateRxData:
                status = MSCAN_ReadRxMb(base, handle->mbFrameBuf);
                if (kStatus_Success == status)
                {
                    status = kStatus_MSCAN_RxIdle;
                }
                MSCAN_TransferAbortReceive(base, handle, kMSCAN_RxFullInterruptEnable);
                break;

            /* Solve Rx Remote Frame. */
            case kMSCAN_StateRxRemote:
                status = MSCAN_ReadRxMb(base, handle->mbFrameBuf);
                if (kStatus_Success == status)
                {
                    status = kStatus_MSCAN_RxIdle;
                }
                MSCAN_TransferAbortReceive(base, handle, kMSCAN_RxFullInterruptEnable);
                break;
        }
        MSCAN_ClearRxBufferFullFlag(base);
    }
    else
    {
        switch (handle->mbStateTx)
        {
            /* Solve Tx Data Frame. */
            case kMSCAN_StateTxData:
                status = kStatus_MSCAN_TxIdle;
                MSCAN_TransferAbortSend(base, handle, kMSCAN_TxEmptyInterruptEnable);
                break;

            /* Solve Tx Remote Frame. */
            case kMSCAN_StateTxRemote:
                handle->mbStateRx = kMSCAN_StateRxRemote;
                status = kStatus_MSCAN_TxSwitchToRx;
                break;

            default:
                status = kStatus_MSCAN_UnHandled;
                break;
        }
    }

    handle->callback(base, handle, status, handle->userData);
}

0 件の賞賛
758件の閲覧回数
tomolenik
Contributor I

Thank you very much!

0 件の賞賛