PebbleOS
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
Time and priorities

Ticks, timeouts and thread priorities shared by every kernel object. More...

Data Structures

struct  pbl_timeout_t
 Timeout of a blocking call. More...
 

Macros

#define PBL_TICK_HZ   CONFIG_KERNEL_TICK_HZ
 Tick rate in Hz, from CONFIG_KERNEL_TICK_HZ.
 
#define PBL_TICK_FOREVER   UINT32_MAX
 Tick count that stands for an infinite timeout.
 
#define PBL_NO_WAIT   ((pbl_timeout_t){.ticks = 0})
 Do not wait: fail with -EBUSY if the call would block.
 
#define PBL_FOREVER   ((pbl_timeout_t){.ticks = PBL_TICK_FOREVER})
 Wait without a time limit.
 
#define PBL_TICKS(t)   ((pbl_timeout_t){.ticks = (t)})
 Timeout in ticks.
 
#define PBL_MSEC(ms)   ((pbl_timeout_t){.ticks = pbl_ms_to_ticks(ms)})
 Timeout in milliseconds, rounded down to whole ticks.
 
#define PBL_SEC(s)   PBL_MSEC((s) * 1000U)
 Timeout in seconds.
 
#define PBL_PRIO_IDLE   ((pbl_prio_t)0)
 Lowest priority, the one of the idle thread.
 
#define PBL_PRIO_MAX   ((pbl_prio_t)(CONFIG_KERNEL_NUM_PRIORITIES - 1))
 Highest priority, CONFIG_KERNEL_NUM_PRIORITIES - 1.
 

Typedefs

typedef uint32_t pbl_tick_t
 Kernel tick count.
 
typedef uint8_t pbl_prio_t
 Thread priority.
 

Functions

pbl_tick_t pbl_ms_to_ticks (uint32_t ms)
 Convert milliseconds to ticks, rounding down.
 
uint32_t pbl_ticks_to_ms (pbl_tick_t ticks)
 Convert ticks to milliseconds, rounding down.
 
static bool pbl_timeout_is_forever (pbl_timeout_t t)
 Check whether a timeout is PBL_FOREVER.
 
static bool pbl_timeout_is_no_wait (pbl_timeout_t t)
 Check whether a timeout is PBL_NO_WAIT.
 

Detailed Description

Ticks, timeouts and thread priorities shared by every kernel object.

Blocking calls take a pbl_timeout_t built with one of the timeout macros, so ticks and milliseconds cannot be mixed up:

pbl_sem_take(&sem, PBL_NO_WAIT); // poll
pbl_sem_take(&sem, PBL_MSEC(100)); // wait up to 100 ms
pbl_sem_take(&sem, PBL_FOREVER); // wait indefinitely
int pbl_sem_take(struct pbl_sem *s, pbl_timeout_t timeout)
Take a token.
#define PBL_NO_WAIT
Do not wait: fail with -EBUSY if the call would block.
Definition types.h:48
#define PBL_MSEC(ms)
Timeout in milliseconds, rounded down to whole ticks.
Definition types.h:62
#define PBL_FOREVER
Wait without a time limit.
Definition types.h:50

Data Structure Documentation

◆ pbl_timeout_t

struct pbl_timeout_t

Timeout of a blocking call.

A distinct type so ticks and milliseconds cannot be mixed; build it with PBL_NO_WAIT, PBL_FOREVER, PBL_TICKS, PBL_MSEC or PBL_SEC.

Data Fields
pbl_tick_t ticks Ticks to wait, 0 for no wait or PBL_TICK_FOREVER for no limit.

Macro Definition Documentation

◆ PBL_FOREVER

#define PBL_FOREVER   ((pbl_timeout_t){.ticks = PBL_TICK_FOREVER})

Wait without a time limit.

◆ PBL_MSEC

#define PBL_MSEC (   ms)    ((pbl_timeout_t){.ticks = pbl_ms_to_ticks(ms)})

Timeout in milliseconds, rounded down to whole ticks.

Parameters
msNumber of milliseconds.

◆ PBL_NO_WAIT

#define PBL_NO_WAIT   ((pbl_timeout_t){.ticks = 0})

Do not wait: fail with -EBUSY if the call would block.

◆ PBL_PRIO_IDLE

#define PBL_PRIO_IDLE   ((pbl_prio_t)0)

Lowest priority, the one of the idle thread.

◆ PBL_PRIO_MAX

#define PBL_PRIO_MAX   ((pbl_prio_t)(CONFIG_KERNEL_NUM_PRIORITIES - 1))

Highest priority, CONFIG_KERNEL_NUM_PRIORITIES - 1.

◆ PBL_SEC

#define PBL_SEC (   s)    PBL_MSEC((s) * 1000U)

Timeout in seconds.

Parameters
sNumber of seconds.

◆ PBL_TICK_FOREVER

#define PBL_TICK_FOREVER   UINT32_MAX

Tick count that stands for an infinite timeout.

◆ PBL_TICK_HZ

#define PBL_TICK_HZ   CONFIG_KERNEL_TICK_HZ

Tick rate in Hz, from CONFIG_KERNEL_TICK_HZ.

Matches the RTC tick rate.

◆ PBL_TICKS

#define PBL_TICKS (   t)    ((pbl_timeout_t){.ticks = (t)})

Timeout in ticks.

Parameters
tNumber of ticks.

Typedef Documentation

◆ pbl_prio_t

typedef uint8_t pbl_prio_t

Thread priority.

Higher value = more urgent.

◆ pbl_tick_t

typedef uint32_t pbl_tick_t

Kernel tick count.

Wraps around; compare differences, not absolute values.

Function Documentation

◆ pbl_ms_to_ticks()

pbl_tick_t pbl_ms_to_ticks ( uint32_t  ms)

Convert milliseconds to ticks, rounding down.

Parameters
msMilliseconds.
Returns
Ticks.

◆ pbl_ticks_to_ms()

uint32_t pbl_ticks_to_ms ( pbl_tick_t  ticks)

Convert ticks to milliseconds, rounding down.

Parameters
ticksTicks.
Returns
Milliseconds.

◆ pbl_timeout_is_forever()

static bool pbl_timeout_is_forever ( pbl_timeout_t  t)
inlinestatic

Check whether a timeout is PBL_FOREVER.

Parameters
tTimeout.
Returns
true if t never expires.

References PBL_TICK_FOREVER, and pbl_timeout_t::ticks.

◆ pbl_timeout_is_no_wait()

static bool pbl_timeout_is_no_wait ( pbl_timeout_t  t)
inlinestatic

Check whether a timeout is PBL_NO_WAIT.

Parameters
tTimeout.
Returns
true if t does not wait.

References pbl_timeout_t::ticks.