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

app_sched_event_put

Hi,

When calling app_sched_event_put inside the same hanler i am exit to main for(;;)

The main loop

for (;;)
  {
    nrf_drv_wdt_channel_feed(m_channel_id);
    app_sched_execute();//going to otaWifi_scheduler_event_handler
    //never get here
    power_manage();
  }

Scheduler event handler

void otaWifi_scheduler_event_handler(void *p_event_data, uint16_t event_size)
{
    uint32_t err_code = app_sched_event_put(NULL, 1, otaWifi_scheduler_event_handler);
    APP_ERROR_CHECK(err_code);
    //never exit to main loop from here!!!!
}

Why?

UPDATE 1

changed to:

uint32_t err_code = app_sched_event_put(NULL, 0, otaWifi_scheduler_event_handler);
APP_ERROR_CHECK(err_code);

but still not exit, go to the while loop inside "app_sched_execute":

void app_sched_execute(void)
{
    while (!is_app_sched_paused() && !APP_SCHED_QUEUE_EMPTY())
    {
        // Since this function is only called from the main loop, there is no
        // need for a critical region here, however a special care must be taken
        // regarding update of the queue start index (see the end of the loop).
        uint16_t event_index = m_queue_start_index;

        void * p_event_data;
        uint16_t event_data_size;
        app_sched_event_handler_t event_handler;

        p_event_data = &m_queue_event_data[event_index * m_queue_event_size];
        event_data_size = m_queue_event_headers[event_index].event_data_size;
        event_handler   = m_queue_event_headers[event_index].handler;

        event_handler(p_event_data, event_data_size);

        // Event processed, now it is safe to move the queue start index,
        // so the queue entry occupied by this event can be used to store
        // a next one.
        m_queue_start_index = next_index(m_queue_start_index);
    }

UPDATE 2

void otaWifi_scheduler_event_handler(void *p_event_data, uint16_t event_size)
    {
        bool finish = otaPro();
        if(finish) 
           return;
        else{
        uint32_t err_code = app_sched_event_put(NULL, 0, otaWifi_scheduler_event_handler);
        APP_ERROR_CHECK(err_code);
        //never exit to main loop from here!!!!
       }
    }

This is still problem because i need to feed a WDG in main loop!

Parents
  • You can put the nrf_drv_wdt_channel_feed(m_channel_id); in the otaWifi_scheduler_event_handler, but this approach is REALLY stupid and has no sense at all.

    What you are doing right now (code above) is:

    • feed watchdog
    • execute scheduler which executes event handler which queues event which is executed and it queues event which executes and queues event... to infinity and beyond!

    you can ofcourse feed the WDT in that loop of nonsense, but i see no reason why one would like to call functions like this.

    please elaborate, what exactly you want to achieve.

    what i would do is add cyclic app_timer which would queue feeding watchdog in some intervals

Reply
  • You can put the nrf_drv_wdt_channel_feed(m_channel_id); in the otaWifi_scheduler_event_handler, but this approach is REALLY stupid and has no sense at all.

    What you are doing right now (code above) is:

    • feed watchdog
    • execute scheduler which executes event handler which queues event which is executed and it queues event which executes and queues event... to infinity and beyond!

    you can ofcourse feed the WDT in that loop of nonsense, but i see no reason why one would like to call functions like this.

    please elaborate, what exactly you want to achieve.

    what i would do is add cyclic app_timer which would queue feeding watchdog in some intervals

Children
No Data
Related