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

Declaring timers

I want to include a timer within a structure and also within an array. However the SDK uses a macro to define the declaration of a timer. App_timer.h recommends not to define.

Is there a recommended method that can be used?

Eg.

typedef struct {

  uint16_t anInteger;

  app_timer_t aTimer;

} aStructure_t;

Or

app_timer_t timers[0..TIMERS];

Malcolm

Parents
  • Hi,

    There is no recommended way (this is not recommended since it is easy to get things wrong). If you do, remember to look closely at the _APP_TIMER_DEF implementation, or observe the preprocessor output to be sure that you did not miss anything. Assuming you use SDK 16 you are probably using app_timer2, and then this is what you need:

    #define _APP_TIMER_DEF(timer_id)                                      \
        static app_timer_t CONCAT_2(timer_id,_data) = { {0} };           \
        static const app_timer_id_t timer_id = &CONCAT_2(timer_id,_data)

Reply
  • Hi,

    There is no recommended way (this is not recommended since it is easy to get things wrong). If you do, remember to look closely at the _APP_TIMER_DEF implementation, or observe the preprocessor output to be sure that you did not miss anything. Assuming you use SDK 16 you are probably using app_timer2, and then this is what you need:

    #define _APP_TIMER_DEF(timer_id)                                      \
        static app_timer_t CONCAT_2(timer_id,_data) = { {0} };           \
        static const app_timer_id_t timer_id = &CONCAT_2(timer_id,_data)

Children
No Data
Related