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

app_scheduler "size of events"?

I am using SDK version 15.3.0 and would love to know  what exactly is the meaning of the first parameter "size of event" used in the macro APP_SCHED_INIT(X,Y)?

I treat "events" as integer designators for events -- so not sure why I should care to specify the "size" of an event?

Was it the author's intent to refer to the maximum value of the event designator?

On the other hand, if the event is truly a 1-to-1 "association or match" between a collection of bytes to an integer value then how is that "association or match" determined at run time?

Parents
  • Hi,

    The app scheduler library supports passing event data along with the functions pointer to the event handler. This is sometimes convenient, and it is application-specific whether you want it to be an integer (as you write you do), or want to pass more data, or perhaps don't need to pass any data at all. Therefore it is flexible, and you can configure this to meet your needs. The reason you need to specify the maximum event size in APP_SCHED_INIT() is that it is used to determine the size of the scheduler buffer. (And the buffer is just a circular buffer holding elements of the same size, scaled for the maximum specified event size).

Reply
  • Hi,

    The app scheduler library supports passing event data along with the functions pointer to the event handler. This is sometimes convenient, and it is application-specific whether you want it to be an integer (as you write you do), or want to pass more data, or perhaps don't need to pass any data at all. Therefore it is flexible, and you can configure this to meet your needs. The reason you need to specify the maximum event size in APP_SCHED_INIT() is that it is used to determine the size of the scheduler buffer. (And the buffer is just a circular buffer holding elements of the same size, scaled for the maximum specified event size).

Children
  • Thanks,  you did confirm what I was expecting for part of my question.

    Can you also explain how the scheduler determines what event (or event data as you put it) was placed in the buffer? Two different occurrences of the same event, at different times, could then generate different data which needs to be accounted for by the scheduler.

  • Hi,

    The scheduler does not care about the content of the event at all. It just passes it on to the event handler. In a bit more detail:

    1. A key thing to remember is that you also pass a function pointer to the event handler, and this means that you typically nave different event handlers for different event types. This is used by the scheduler in the sense that it reads the function pointer in the queue and calls it when the event is processed.
    2. When you schedule an event you do something like: app_sched_event_put(p_event_data, sizeof(p_event_data), my_event_handler);
    3. And then "receive" the event data in your event handler which has a prototype similar to this: void my_event_handler(void * p_event_data, uint16_t event_size);
      1. And this is where you use the data for something useful (if needed).
  • Thanks. Looks like this is then simply a first-in first-out queue and the originator/callee needs to track the order of insertion i.e. the scheduler does NOT dynamically rearrange the events based on any semantic interpretations associated with either the "event data" or the "event handler"

Related