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

Examples using the scheduler

I am trying to use the Scheduler to create my own event handler system (similar to a Ti 8051 OSAL system). I'm writing separate classes that can push data/trigger handlers between classes via put/scheduled events. Sort of like a soft interrupt. For example I want a timer timeout handler of a Button_timer.c class to send an event to Main.c, to trigger enable/disable some LEDs. This way Main.c acts as the main dispatch and controller for all peripheral events. However I cannot find any examples of the Scheduler where the application created its own events and event handlers. Thus I'm still a little in the dark with exactly how to implement a Scheduler into my application. Can anyone point me to some examples that use the scheduler?

p.s. Tried looking into the HID examples, but the app_sched_init and app_sched_event_put calls are not coded in the application.

Thanks guys.

  • Could I interpret a lack of response as meaning there are a lack of available examples? The reason I made this post is as I'm developing my application, without a real-time event handler on the Nordic platofrm, I'm having to write alot of app_timers to simulate event handing. Timers are a very messy way of handling real-time events, and do not allow for any kind of queued processing? Hope someone can chime in. Thanks

    1. Need to init sheduler in main() like this:

      APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);

    2. in main() need insert this code:

      while(1) { app_sched_execute(); ... }

    3. in app_sheduler.h we have Scheduler event handler type:

      typedef void (*app_sched_event_handler_t)(void * p_event_data, uint16_t event_size);

    4. Declare own function like than typedef:

      void my_flash_event_func(void *data, uint16_t size); //this is event handler

    5. In any place where it is need, we call:

      app_sched_event_put(pointer_to_own_data, size_of_data, my_flash_event_func); //this is event

    And sheduler will call your function "my_flash_event_func" with params: "pointer_to_own_data" and "size_of_data" like this:

    my_flash_event_func(pointer_to_data, size_of_data);
    
  • @lebets_vi, What is the value of SCHED_MAX_EVENT_DATA_SIZE? No macro is defined in my app_scheduler.h. 8B, 16B, 32B? I'm also not actually passing any data at this point. Does passing 0 do anything unexpected? Is the minimum 1?

  • Values of this macro can be found in any examples in SDK:

    //Maximum size of scheduler events. Note that scheduler BLE stack events do not contain any data, as the events are being pulled from the stack in the event handler

    #define SCHED_MAX_EVENT_DATA_SIZE sizeof(app_timer_event_t)
    

    //Maximum number of events in the scheduler queue

    #define SCHED_QUEUE_SIZE    20
    
  • This is a great response. It should be included in the documentation! Item one should mention that #include "app_scheduler.h" is required.

Related