NCS Conflict between Timer Interrupt and BLE stack?

Hi,

  I want to use timer interrupt in BLE code. If enable timer inside the BLE code. The code will not work properly. I want to know why this is happening like that and how can I implement the timer interrupt inside the BLE code. I am using nrf5340dk and NCS v 1.9.1 SDK. And also I want to check with the same code GPIO Interrupt and delay also not working fine. Kindly, help me to resolve the issue

Thanks & Regards,

Navin Chakravarthy K

Parents Reply Children
  • Hi Navin,

    Here are two possible solutions:

    Solution A, to run the sampling from a separate thread using a delay in the similar way to what you do currently. Delays in Zephyr are not implemented as busy waits. They allow other threads to run concurrently.

    Solution B:  Use a zephyr timer that triggers a work item. Consult the documentation for Timers, specifically check out Using a Timer Expiry Function:

    The following code uses a timer to perform a non-trivial action on a periodic basis. Since the required work cannot be done at interrupt level, the timer’s expiry function submits a work item to the system workqueue, whose thread performs the work.

    void my_work_handler(struct k_work *work)
    {
        /* do the processing that needs to be done periodically */
        ...
    }
    
    K_WORK_DEFINE(my_work, my_work_handler);
    
    void my_timer_handler(struct k_timer *dummy)
    {
        k_work_submit(&my_work);
    }
    
    K_TIMER_DEFINE(my_timer, my_timer_handler, NULL);
    
    ...
    
    /* start periodic timer that expires once every second */
    k_timer_start(&my_timer, K_SECONDS(1), K_SECONDS(1));

    Best regards,

    Håkon

  • Hi Helsing,

    Thank you so much, i will check and you know.

Related