Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LIBUARTE RX Buffer Full event

Hello,

I am having an issue with the nrf_libuarte_async librairie.

I am sending data via nrf_libuarte_async_tx and receiving the data properly via the IRQ handler (user implemented). I copy the data received into a buffer and then send a notification to my task that the uart reception is completed and ready for pick-up. However issue arise when the buffer get full. The nrf_libuarte_async generates two NRF_LIBUARTE_ASYNC_EVT_RX_DATA event, the first one to notify that the buffer is full, the second one to notify that the reception is complete. My message reception is now bad as the message is split in two. The first half in the first buffer and the second half in the second buffer.

Here are my questions:

1. How can I determine that the first event is a buffer Full event and not a completed reception event?

2. I cannot change the number of buffer to 1 as it is asserted in nrf_libuarte_async.h (STATIC_ASSERT(_rx_buf_cnt >= 3, "Wrong number of RX buffers");\)

3. Is there a way to use a ring buffer instead of changing the buffer for reception. As a user I dont care that the buffer is full, when you interrupt me to tell me reception is complete I expect that reception is complete. 

I am using the SDK 17.1.0

Thank you,

Vincent

Parents
  • Hi,

    I was having a similar problem with the LIBUARTE library. In the end I realised that there is a way to understand if the event is because of a full buffer or timeout. The variable p_libuarte->p_ctrl_blk->sub_rx_count is always 0 if the event is coming from a full buffer.

    Here is my uartEventHandle if anyone else needs it:

    /**@brief Function for handling UARTE callback events.
     *
     * @param[in]   context   Pointer to UARTE library asynhronous instance.
     * @param[in]   p_evt     Pointer to UARTE library asynhronous event.
     */
    static void uartEventHandle(void * context, nrf_libuarte_async_evt_t * p_evt)
    {
        /* Holds pointer to UARTE library instance. */
        nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
        /* Holds yield request. */
        BaseType_t yieldReq = pdFALSE;
        /* Decide according to event type. */
        switch(p_evt->type)
        {
            case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
                /* Check if buffer full event. */
                if(0 == p_libuarte->p_ctrl_blk->sub_rx_count)
                {
                    /* Copy new data to buffer but wait for the second event. */
                }
                else
                {
                    /* Copy rest of data to your buffer and notify the task to process it. */   
                    vTaskNotifyGiveFromISR(taskHandle, &yieldReq);
                    portYIELD_FROM_ISR(yieldReq);
                }
                /* Free UARTE memory. */
                nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, \
                                           p_evt->data.rxtx.length);
                break;
            case NRF_LIBUARTE_ASYNC_EVT_ERROR:
                break;
            case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
                break;
            default:
                break;
        }
    }

    So there is no need to change the files from the SDK.

Reply
  • Hi,

    I was having a similar problem with the LIBUARTE library. In the end I realised that there is a way to understand if the event is because of a full buffer or timeout. The variable p_libuarte->p_ctrl_blk->sub_rx_count is always 0 if the event is coming from a full buffer.

    Here is my uartEventHandle if anyone else needs it:

    /**@brief Function for handling UARTE callback events.
     *
     * @param[in]   context   Pointer to UARTE library asynhronous instance.
     * @param[in]   p_evt     Pointer to UARTE library asynhronous event.
     */
    static void uartEventHandle(void * context, nrf_libuarte_async_evt_t * p_evt)
    {
        /* Holds pointer to UARTE library instance. */
        nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
        /* Holds yield request. */
        BaseType_t yieldReq = pdFALSE;
        /* Decide according to event type. */
        switch(p_evt->type)
        {
            case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
                /* Check if buffer full event. */
                if(0 == p_libuarte->p_ctrl_blk->sub_rx_count)
                {
                    /* Copy new data to buffer but wait for the second event. */
                }
                else
                {
                    /* Copy rest of data to your buffer and notify the task to process it. */   
                    vTaskNotifyGiveFromISR(taskHandle, &yieldReq);
                    portYIELD_FROM_ISR(yieldReq);
                }
                /* Free UARTE memory. */
                nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, \
                                           p_evt->data.rxtx.length);
                break;
            case NRF_LIBUARTE_ASYNC_EVT_ERROR:
                break;
            case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
                break;
            default:
                break;
        }
    }

    So there is no need to change the files from the SDK.

Children
No Data
Related