EVE 1.0
usec work scheduler
Collaboration diagram for usec work scheduler:

Data Structures

struct  uwork_t
 

Macros

#define UWORK_USEC(us)   (us)
 
#define UWORK_INIT(x, callback)
 
#define UWORK_INIT_TYPED(x, callback)   (struct uwork_t) UWORK_INIT(x, callback)
 
#define DECLARE_UWORK(x, callback)    struct uwork_t x = UWORK_INIT(x, callback)
 

Typedefs

typedef int32_t uwork_time_t
 
typedef void(* uwork_cb_t) (struct uwork_t *work)
 

Functions

uwork_time_t uwork_now (void)
 
void uwork_schedule (struct uwork_t *work)
 
void uwork_cancel (struct uwork_t *work)
 
static bool uwork_pending (struct uwork_t *work)
 
void uwork_init (void)
 

Detailed Description

Macro Definition Documentation

#define UWORK_USEC (   us)    (us)

Converts a time interval, given in number of microseconds, to the number of microticks.

Parameters
usduration of the time interval, microseconds
Returns
number of microticks in the time interval

Definition at line 58 of file uwork.h.

Referenced by clock_delay_usec().

#define UWORK_INIT (   x,
  callback 
)
Value:
{ \
.work.link.next = &(x).work.link, \
.work.link.prev = &(x).work.link, \
.work.cb = (work_cb_t) (callback), \
}
void(* work_cb_t)(struct work_t *work)
Definition: work.h:126

Initializes a microwork structure.

The macro is used to initialize a microsecond-scale work (microwork) structure instance.

Parameters
xmicrowork structure
callbackmicrowork callback

Usage:

1 static void MyWorkCallback(struct uwork_t *Work);
2 struct uwork_t MyWork = UWORK_INIT(MyWork, MyWorkCallback);

Definition at line 75 of file uwork.h.

#define UWORK_INIT_TYPED (   x,
  callback 
)    (struct uwork_t) UWORK_INIT(x, callback)

Initializes a microwork structure. Typed version of UWORK_INIT

Definition at line 86 of file uwork.h.

#define DECLARE_UWORK (   x,
  callback 
)    struct uwork_t x = UWORK_INIT(x, callback)

Instantiates a microwork structure.

The macro is used to instantiate a work structure.

Parameters
xname of the microwork structure
callbackthe microwork callback

Usage:

1 static void MyWorkCallback(struct uwork_t *Work);
2 DECLARE_UWORK(MyWork, MyWorkCallback);

Definition at line 104 of file uwork.h.

Typedef Documentation

typedef int32_t uwork_time_t

Microwork time type.

MSB is used as a sign bit, so, the max interval for the microwork is 2^(32-1)-1 = 2147483647 us, or ~35 min. Please use OS etimer for longer intervals. Note that system holds high-frequency clock on if a microwork is scheduled.

Definition at line 108 of file uwork.h.

typedef void(* uwork_cb_t) (struct uwork_t *work)

Microwork callback type.

Parameters
workpointer to the microwork structure

Definition at line 127 of file uwork.h.

Function Documentation

uwork_time_t uwork_now ( void  )

Returns the current timestamp, which can be used as a time reference in struct uwork_t::at

Usage:

1 MyWork.at = uwork_now() + UWORK_USEC(300);
2 uwork_schedule(&MyWork);
3 // The work is scheduled and will be executed 300 µs later.
Returns
current timestamp in microsecond-scale microticks

Referenced by clock_delay_usec().

void uwork_schedule ( struct uwork_t work)

Schedules a microwork.

The function schedules a microwork for execution at the specified point in time. The microwork will be executed at the hardware interrupt level. It is allowed to schedule a microwork in the past. In this case it is triggered for execution immediately.

If two or more microworks are scheduled for the same tick, they will be executed in the same order as thay were scheduled. As hardware interrupt routines, microworks preempt software interrupts (that implies also works and milliworks) and OS processes. A microwork selv can be preempted by high-priority low-level BLE radio interrupts.

If the microwork structure, pointed by the work parameter is already scheduled for execution, then it is re-scheduled at the new time.

A scheduled microwork holds system at PM_LEVEL_CONSTLAT power level.

Parameters
workpointer to the microwork structure

Referenced by clock_delay_usec().

void uwork_cancel ( struct uwork_t work)

Cancels a scheduled microwork.

The function cancels a previously scheduled work.

Parameters
workpointer to the microwork structure
static bool uwork_pending ( struct uwork_t work)
inlinestatic

Checks if the microwork is scheduled and pending execution.

The function checks if the microwork is scheduled for execution.

Parameters
workpointer to the microwork structure
Returns
true if the microwork is scheduled for execution
false if the microwork is not scheduled
false if the microwork is being executed

Definition at line 207 of file uwork.h.

References dlist_is_empty(), work_t::link, uwork_init(), and uwork_t::work.

Referenced by clock_delay_usec().

void uwork_init ( void  )

Initializes the microwork framework

Referenced by uwork_pending().