PebbleOS v4.43.0-118-gb6c5f89a9
Loading...
Searching...
No Matches
Timers

One-shot software timers expiring in the tick interrupt. More...

Data Structures

struct  pbl_timer
 Software timer. More...
 

Macros

#define PBL_TIMER_INITIALIZER(_fn)   {.fn = (_fn)}
 Static initializer for a timer.
 

Typedefs

typedef void(* pbl_timer_fn_t) (struct pbl_timer *timer)
 Timer callback, run in the tick ISR.
 

Functions

void pbl_timer_init (struct pbl_timer *timer, pbl_timer_fn_t fn)
 Initialize a timer.
 
void pbl_timer_start (struct pbl_timer *timer, pbl_timeout_t delay)
 Start a timer, or restart it if it is active.
 
void pbl_timer_stop (struct pbl_timer *timer)
 Stop a timer.
 
bool pbl_timer_is_active (const struct pbl_timer *timer)
 Check whether a timer is active.
 

Detailed Description

One-shot software timers expiring in the tick interrupt.

The callback runs in the tick ISR, so it must not block. Timers keep the idle thread from sleeping past their expiry. All functions may be called from ISRs, including from a callback to restart its own timer.

static void prv_expired(struct pbl_timer *timer) {
struct foo *foo = container_of(timer, struct foo, timer);
...
}
pbl_timer_init(&foo->timer, prv_expired);
pbl_timer_start(&foo->timer, PBL_MSEC(40));
Software timer.
Definition timer.h:35
void pbl_timer_init(struct pbl_timer *timer, pbl_timer_fn_t fn)
Initialize a timer.
void pbl_timer_start(struct pbl_timer *timer, pbl_timeout_t delay)
Start a timer, or restart it if it is active.
#define PBL_MSEC(ms)
Timeout in milliseconds, rounded down to whole ticks.
Definition types.h:61
#define container_of(ptr, type, member)
Get the structure that contains a member.
Definition misc.h:44

Data Structure Documentation

◆ pbl_timer

struct pbl_timer

Software timer.

Data Fields
pbl_timer_fn_t fn Callback.

Macro Definition Documentation

◆ PBL_TIMER_INITIALIZER

#define PBL_TIMER_INITIALIZER (   _fn)    {.fn = (_fn)}

Static initializer for a timer.

Parameters
_fnCallback.

Typedef Documentation

◆ pbl_timer_fn_t

typedef void(* pbl_timer_fn_t) (struct pbl_timer *timer)

Timer callback, run in the tick ISR.

Function Documentation

◆ pbl_timer_init()

void pbl_timer_init ( struct pbl_timer *  timer,
pbl_timer_fn_t  fn 
)

Initialize a timer.

Parameters
[out]timerTimer.
fnCallback.

◆ pbl_timer_is_active()

bool pbl_timer_is_active ( const struct pbl_timer *  timer)

Check whether a timer is active.

Parameters
timerTimer.
Returns
True from pbl_timer_start() until it expires or is stopped.

◆ pbl_timer_start()

void pbl_timer_start ( struct pbl_timer *  timer,
pbl_timeout_t  delay 
)

Start a timer, or restart it if it is active.

Parameters
timerTimer.
delayTime until the callback runs, at least one tick; must not be PBL_FOREVER.

◆ pbl_timer_stop()

void pbl_timer_stop ( struct pbl_timer *  timer)

Stop a timer.

Does nothing if it is not active.

Parameters
timerTimer.