<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to handle Time Consuming Function Calls in Application Having SoftDevice?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84525/how-to-handle-time-consuming-function-calls-in-application-having-softdevice</link><description>Hello everybody, 
 I am working on a nRF52832 DK and implemented libuarte (on a nRF52832) to communicate with another uC on said board. I am using sdk 17.0.2. The goal is to receive data from the other uC and transmit it via BLE to a connected device</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 09 Feb 2022 17:14:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84525/how-to-handle-time-consuming-function-calls-in-application-having-softdevice" /><item><title>RE: How to handle Time Consuming Function Calls in Application Having SoftDevice?</title><link>https://devzone.nordicsemi.com/thread/352168?ContentTypeID=1</link><pubDate>Wed, 09 Feb 2022 17:14:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5281d16-0965-4c12-adeb-4f5e46263e30</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;1. If you are not able to free the libUARTE RX buffers fast enough in the&amp;nbsp;NRF_LIBUARTE_ASYNC_EVT_RX_DATA event, you may get this error when there is no available buffer for the library to use. You can try to increase the buffer count (last parameter passed to&amp;nbsp;NRF_LIBUARTE_ASYNC_DEFINE(). Alternatively, you need to either handle the events faster, reduce the baudrate, or add HW flow control pins.&lt;/p&gt;
&lt;p&gt;2. The transfer length for UARTE peripheral is limited to 255 bytes in nRF52832. There is no way to increase the receive buffer size beyond this on nRF52832 (nRF52840/nRF52833 can support longer transfers). The library will provide the data to the application through the&amp;nbsp;&lt;span&gt;NRF_LIBUARTE_ASYNC_EVT_RX_DATA event when one buffer is full/reached buffer edge, or when a timeout occurs. There is no support in the library for concatenating data from multiple buffers, this needs to be handled in the application, for instance by using a &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_ringbuf.html"&gt;ring buffer&lt;/a&gt; or similar.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. As long as you call the blocking function from main context/function, there is nothing to worry about. The softdevice runs in interrupt context, meaning it will take over execution from the blocking function whenever it needs to handle its tasks.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle Time Consuming Function Calls in Application Having SoftDevice?</title><link>https://devzone.nordicsemi.com/thread/352077?ContentTypeID=1</link><pubDate>Wed, 09 Feb 2022 13:07:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce86f7e2-86cd-4444-a81c-6799b4599db9</guid><dc:creator>sureshpawan2010@gmail.com</dc:creator><description>&lt;p&gt;&lt;span&gt;Thanks for reply J&amp;oslash;rgen Holmefjord,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Sometimes Getting Error &amp;quot;&lt;strong&gt;&amp;lt;error&amp;gt; libUARTE_async: (evt) Failed to allocate buffer for RX.&lt;/strong&gt;&amp;quot; while Transmitting and Receiving data contineouesoly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; if a big packet of data is transmitted via terminal/PC(like 612 bytes), &lt;strong&gt;Partial amount of data received on each &amp;quot;NRF_LIBUARTE_ASYNC_EVT_RX_DATA&amp;quot; event(255 bytes each and remaining on last event&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 1, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 4);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void uart_event_handler(void *context, nrf_libuarte_async_evt_t *p_evt) {

  static uint8_t Tx_Cnt=1,Rx_Cnt=1;
  nrf_libuarte_async_t *p_libuarte = (nrf_libuarte_async_t *)context;

  p_libuarte = (nrf_libuarte_async_t *)context;
  ret_code_t ret;

  switch (p_evt-&amp;gt;type) {
    case NRF_LIBUARTE_ASYNC_EVT_ERROR: {
        NRF_LOG_ERROR(&amp;quot;LIBUARTE ERROR&amp;quot;);
      break;
    }
    case NRF_LIBUARTE_ASYNC_EVT_RX_DATA: {
       // Receive complete
        memcpy(Rx_Buff, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
        Rx_len = p_evt-&amp;gt;data.rxtx.length;
        nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
        NRF_LOG_INFO(&amp;quot;Rx len: %d\r\n&amp;quot;,Rx_len);
        sendUart =1;   //Transmit Received data back to PC
        NRF_LOG_INFO(&amp;quot;RX_COUNT=%d\r\n&amp;quot;,Rx_Cnt++);
        if(Rx_Cnt &amp;gt; 10)
          Rx_Cnt = 0;
      break;
    }
    case NRF_LIBUARTE_ASYNC_EVT_TX_DONE: {
        NRF_LOG_INFO(&amp;quot;TX_COUNT=%d\r\n&amp;quot;,Tx_Cnt++);
        // Transmit complete
        Tx_Cplt_Flag = true;
        if(Tx_Cnt &amp;gt; 10)
          Tx_Cnt =0;
      break;
    }
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; but i just want to receive whole data on single event or How i can handle these multiple packets. also i am not able to capture data of last &amp;quot;NRF_LIBUARTE_ASYNC_EVT_RX_DATA&amp;quot; event.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;strong&gt;3.&lt;/strong&gt; My Application requirements is to &lt;strong&gt;send some data from Uc(Renesas RL78) to nrf52832 and vice versa continuously using UART&lt;/strong&gt;, so &lt;strong&gt;where to call &amp;quot;Send_Uart_Data()&amp;quot; function in ble stack or how to handle these blocking function so that softdevice doesn&amp;#39;t get disturbed&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t Send_Uarte_Data(uint8_t  msg[], size_t length)
{
    uint32_t Tx_Timout =0;
    static uint32_t Send_Skip_Count=0;
    ret_code_t err_code;     
    if(Tx_Cplt_Flag) 
    { 
        Tx_Cplt_Flag = false;
        err_code = nrf_libuarte_async_tx(&amp;amp;libuarte, msg,length);
        //Wait Till Tx not Done
        while(Tx_Cplt_Flag!=true)
        {
            Tx_Timout++;
            if(Tx_Timout &amp;gt;= TX_TIMEOUT)
            {
                NRF_LOG_INFO(&amp;quot;Send_Timout=%d\r\n&amp;quot;,Tx_Timout);
                Tx_Timout = 0; 
                return 0;
            }
        }
        APP_ERROR_CHECK(err_code);
        bsp_board_led_invert(1);
        NRF_LOG_INFO(&amp;quot;Transmitted Length =%d\r\n&amp;quot;,length);
        return 1;  
    }
    else
    {
      if(Send_Skip_Count++ &amp;gt; 500)
        Send_Skip_Count =0;
      NRF_LOG_INFO(&amp;quot;Send_Skip_Count = %d\r\n&amp;quot;,Send_Skip_Count);
      return 0;
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
        if(sendUart)
        {
            (void)Send_Uarte_Data(Rx_Buff,Rx_len);
            sendUart =0;
        }
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;log snipped&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot-2022_2D00_02_2D00_09-181543.png" /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot-2022_2D00_02_2D00_09-181626.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Blue Color is &lt;strong&gt;Transmitted&lt;/strong&gt; data and &lt;strong&gt;Red&lt;/strong&gt; Color Received.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle Time Consuming Function Calls in Application Having SoftDevice?</title><link>https://devzone.nordicsemi.com/thread/351926?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 19:30:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12e21287-207f-4c53-bb5e-3fbb08cc5d16</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You will get an error from&amp;nbsp;nrf_libuarte_async_tx() if you have already started one transfer, and you call the function again before the transfer is completed. You need to wait for the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__nrf__libuarte__async.html#gga2bcf57e4d184518ee514387b3b1806e7a36d71d569f410ceb9e521e0193b59812"&gt;NRF_LIBUARTE_ASYNC_EVT_TX_DONE&lt;/a&gt;&amp;nbsp;event in the event handler before calling this function again.&lt;/p&gt;
&lt;p&gt;In general, you can build the application in debug configuration (or with DEBUG preprocessor symbol defined), and read out the error code and file/line that caused the error from the logger.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle Time Consuming Function Calls in Application Having SoftDevice?</title><link>https://devzone.nordicsemi.com/thread/351909?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 17:03:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae414415-682c-41c6-9093-57d0e3278bca</guid><dc:creator>sureshpawan2010@gmail.com</dc:creator><description>&lt;p&gt;Thanks for reply J&amp;oslash;rgen Holmefjord,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;nRF52832&amp;nbsp;stuck at &lt;strong&gt;&amp;quot;NRF_BREAKPOINT_COND;&amp;quot; and get hanged&lt;/strong&gt;&amp;nbsp;when sending data via &amp;nbsp;libuarte continuously..so I&amp;nbsp;just want to know the proper place to call &lt;strong&gt;&amp;quot;nrf_libuarte_async_tx()&amp;quot;&lt;/strong&gt;&amp;nbsp; function or how to handle Continuous sending routine,&amp;nbsp;so that I&amp;nbsp;am able to send data without processor reset.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void Send_Uarte_Data(uint8_t  msg[], size_t length)
{
    ret_code_t err_code;         
    err_code = nrf_libuarte_async_tx(&amp;amp;libuarte, msg,length);
    APP_ERROR_CHECK(err_code);
    bsp_board_led_invert(1);

}&lt;/pre&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void idle_state_handle(void)
{
    
    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
    if(sendUart)
    {
        uint8_t test_Text[]=&amp;quot;Button_Pressed.\r\n&amp;quot;;
        Send_Uarte_Data(test_Text,sizeof(test_Text));
        sendUart =0;
    }
}&lt;/pre&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Application main function.
 */
int main(void)
{
    //bool erase_bonds;

    //Initialize.
    uart_init();
    log_init();
    timers_init();
    //User_timer_Init(APP_TIMER_MODE_REPEATED,user_timer_handle);

    //buttons_leds_init();
    bsp_configuration();

    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    //Start execution.
    NRF_LOG_INFO(&amp;quot;Debug logging for UART over RTT started.&amp;quot;);
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to handle Time Consuming Function Calls in Application Having SoftDevice?</title><link>https://devzone.nordicsemi.com/thread/351901?ContentTypeID=1</link><pubDate>Tue, 08 Feb 2022 16:37:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2339d49d-1ecc-4161-8b04-1c78b6a5fe82</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The softdevice runs in interrupt context, in order to handle timing-critical BLE events. The softdevice will always have higher priority than the application, so the application will be preempted if the softdevice needs to handle its tasks.&lt;/p&gt;
&lt;p&gt;See&amp;nbsp;&lt;a title="Interrupt model and processor availability" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/processor_avail_interrupt_latency/processor_avail_interrupt_latency.html?cp=4_7_3_0_15"&gt;Interrupt model and processor availability&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a title="Scheduling" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/multilink_scheduling/multilink_scheduling.html?cp=4_7_3_0_14"&gt;Scheduling&lt;/a&gt;&amp;nbsp;for more details about how this works. Make sure that you call the time consuming function from main context, to prevent blocking softdevice or other peripheral interrupts.&lt;/p&gt;
&lt;p&gt;In case you need to perform a task in the application without being interrupted by the softdevice, you can use the&amp;nbsp;&lt;a title="Concurrent multiprotocol implementation using the Radio Timeslot API" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/concurrent_multiprotocol_tsl_api/concurrent_multiprotocol_tsl_api.html?cp=4_7_3_0_8_1"&gt;Timeslot API&lt;/a&gt;&amp;nbsp;to request a timeslot.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>