This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Scheduler

Hello,

I receive a lot of data in my UART, like 256B non stop that I need to send it to a tablet through BLE.

I was thinking of using scheduler so I push the data and an event in the DATA_READY uart event and the main thread will process the pushed data to send through BLE. What do you think about that? Does it sound ok?

In my case when calling APP_SCHED_INIT what is the EVENT SIZE  parameter?

I am afraid that the fifo will be full pretty quick so maybe thats not the best design.

Parents
  • Hi,

     

    I am afraid that the fifo will be full pretty quick so maybe thats not the best design.

     Yes, this is also what I'm thinking. I think the LibUARTE library would be better fit for your project. You find the example described here.

    regards

    Jared

  • Hello Jared, thank you for your feedback.

    How libuarte could help?

    Btw I just noticed UARTE and UART are enabled. So I will investigate which one is used.

  • Hi,

    In short, the libUARTE is a good driver to use for when you have to receive lots of data through UARTE. Features such as the usage of double buffering, events for synchronization, usage of PPI to connect events, and the option of hw flow control minimizes lost data.

    regards

    Jared

  • OK thank you, we will plan to migrate to this driver for next release.

    In the meantime could you help me with this issue:

    In the uart handler, when I reaceive a buffer, I want to push it to a atfifo.

    A timer handler will get data from this fifo and will send it to the tablet. Here's my current implementation:

    typedef struct{
        uint8_t au8_uart_to_ble_tx_buffer[UART_TX_BUF_SIZE]; 
    }tStreamingData;
    
    static tStreamingData gStreamingData = {0};
    
    NRF_ATFIFO_DEF(sd_fifo, tStreamingData, 5);
    
    static void uart_event_handle(app_uart_evt_t *p_event)
    {
        static uint16_t index = 0;
        static uint8_t au8_rx_buffer[UART_RX_BUF_SIZE] = {0};            // Buffer reception for UART
        static size_t frameCounter = 0;
        uint8_t u8_rxbyte;
        
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&u8_rxbyte));    
                au8_rx_buffer[index] = u8_rxbyte;
                index++;
                if (u8_rxbyte == '\n')
                {
                    
                    //check if stream header is present  
                    if (index > 5 && au8_rx_buffer[index-5] == 0x65 && au8_rx_buffer[index-4] == 0x6E && au8_rx_buffer[index-3] == 0x64 && au8_rx_buffer[index-2] == 0x0A && au8_rx_buffer[index-1] == 0x00)    //stream starts when end\n is encontered
                    {
                        frameCounter++;
            
                        memcpy(gStreamingData.au8_uart_to_ble_tx_buffer , au8_rx_buffer, UART_TX_BUF_SIZE);
                        nrf_atfifo_alloc_put(sd_fifo, &gStreamingData, sizeof(tStreamingData), NULL);
    
                        index = 0;
                    }
    
                    if(index > UART_RX_BUF_SIZE)
                    {
                        index = 0;
                    }
                }
            break;
            case APP_UART_TX_EMPTY:
            break; 
            case APP_UART_FIFO_ERROR:
            break;
            case APP_UART_COMMUNICATION_ERROR:
            break;       
            default:
            break;
        }
    }                   

    And in a timer handler I am just polling the fifo 

    tStreamingData localSd;

    nrf_atfifo_get_free(sd_fifo, &localSd, sizeof(tStreamingData), NULL);

    But the fifo seems always empty.

    I can not use logs since the code is embedded on a chip.

    The atfifio has been definied globally using NRF_ATFIFO_DEF(sd_fifo, tStreamingData, 5);

    and initialized in main using NRF_ATFIFO_INIT(sd_fifo);

    I know for sure the data in the uart handler is correct since I detect a packet header sent by another module so the data are not 0 it is jsut somehow I failed pushing/poping the fata from the fifo but I dont know why.

    Thanks

Reply
  • OK thank you, we will plan to migrate to this driver for next release.

    In the meantime could you help me with this issue:

    In the uart handler, when I reaceive a buffer, I want to push it to a atfifo.

    A timer handler will get data from this fifo and will send it to the tablet. Here's my current implementation:

    typedef struct{
        uint8_t au8_uart_to_ble_tx_buffer[UART_TX_BUF_SIZE]; 
    }tStreamingData;
    
    static tStreamingData gStreamingData = {0};
    
    NRF_ATFIFO_DEF(sd_fifo, tStreamingData, 5);
    
    static void uart_event_handle(app_uart_evt_t *p_event)
    {
        static uint16_t index = 0;
        static uint8_t au8_rx_buffer[UART_RX_BUF_SIZE] = {0};            // Buffer reception for UART
        static size_t frameCounter = 0;
        uint8_t u8_rxbyte;
        
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&u8_rxbyte));    
                au8_rx_buffer[index] = u8_rxbyte;
                index++;
                if (u8_rxbyte == '\n')
                {
                    
                    //check if stream header is present  
                    if (index > 5 && au8_rx_buffer[index-5] == 0x65 && au8_rx_buffer[index-4] == 0x6E && au8_rx_buffer[index-3] == 0x64 && au8_rx_buffer[index-2] == 0x0A && au8_rx_buffer[index-1] == 0x00)    //stream starts when end\n is encontered
                    {
                        frameCounter++;
            
                        memcpy(gStreamingData.au8_uart_to_ble_tx_buffer , au8_rx_buffer, UART_TX_BUF_SIZE);
                        nrf_atfifo_alloc_put(sd_fifo, &gStreamingData, sizeof(tStreamingData), NULL);
    
                        index = 0;
                    }
    
                    if(index > UART_RX_BUF_SIZE)
                    {
                        index = 0;
                    }
                }
            break;
            case APP_UART_TX_EMPTY:
            break; 
            case APP_UART_FIFO_ERROR:
            break;
            case APP_UART_COMMUNICATION_ERROR:
            break;       
            default:
            break;
        }
    }                   

    And in a timer handler I am just polling the fifo 

    tStreamingData localSd;

    nrf_atfifo_get_free(sd_fifo, &localSd, sizeof(tStreamingData), NULL);

    But the fifo seems always empty.

    I can not use logs since the code is embedded on a chip.

    The atfifio has been definied globally using NRF_ATFIFO_DEF(sd_fifo, tStreamingData, 5);

    and initialized in main using NRF_ATFIFO_INIT(sd_fifo);

    I know for sure the data in the uart handler is correct since I detect a packet header sent by another module so the data are not 0 it is jsut somehow I failed pushing/poping the fata from the fifo but I dont know why.

    Thanks

Children
Related