NONOS_SDK software timer API - Initialisation of os_timer_t
Posted: Mon Jan 22, 2018 8:20 am
The Espressif NONOS_SDK documentation https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf describes the API for using the software timer via (mainly) three functions: os_timer_arm(), os_timer_disarm() and os_timer_setfn(). These take a pointer to a structure os_timer_t that contains among other things a timer handle and a pointer to the next timer.
At no point do I see any mention of how you should initialise this structure. All the examples I've seen (e.g. Blinky) simply define a global os_timer_t and then without any initialisation start passing it to the API functions. This evidently works, but it feels risky - e.g. for the initial call to os_timer_disarm(). Maybe one of these calls (os_timer_arm()?) populates the structure with valid members like the timer handle, but is it known which one and which parts of the structure it populates?
At no point do I see any mention of how you should initialise this structure. All the examples I've seen (e.g. Blinky) simply define a global os_timer_t and then without any initialisation start passing it to the API functions. This evidently works, but it feels risky - e.g. for the initial call to os_timer_disarm(). Maybe one of these calls (os_timer_arm()?) populates the structure with valid members like the timer handle, but is it known which one and which parts of the structure it populates?
Code: Select all
typedef struct _os_timer_t {
struct _os_timer_t *timer_next;
void *timer_handle;
uint32 timer_expire;
uint32 timer_period;
os_timer_func_t *timer_func;
bool timer_repeat_flag;
void *timer_arg;
} os_timer_t;