63#ifndef _PICO_ASYNC_CONTEXT_H
64#define _PICO_ASYNC_CONTEXT_H
74 ASYNC_CONTEXT_POLL = 1,
75 ASYNC_CONTEXT_THREADSAFE_BACKGROUND = 2,
76 ASYNC_CONTEXT_FREERTOS = 3,
147#define ASYNC_CONTEXT_FLAG_CALLBACK_FROM_NON_IRQ 0x1
148#define ASYNC_CONTEXT_FLAG_CALLBACK_FROM_IRQ 0x2
149#define ASYNC_CONTEXT_FLAG_POLLED 0x4
161 uint32_t (*
execute_sync)(async_context_t *context, uint32_t (*func)(
void *param),
void *param);
167 void (*
poll)(async_context_t *self);
static void async_context_lock_check(async_context_t *context)
Assert if the caller does not own the lock for the async_context.
Definition async_context.h:236
static void async_context_set_work_pending(async_context_t *context, async_when_pending_worker_t *worker)
Mark a "when pending" worker as having work pending.
Definition async_context.h:381
struct async_context_type async_context_type_t
Implementation of an async_context type, providing methods common to that type.
static void async_context_acquire_lock_blocking(async_context_t *context)
Acquire the async_context lock.
Definition async_context.h:206
static bool async_context_remove_at_time_worker(async_context_t *context, async_at_time_worker_t *worker)
Remove an "at time" worker from a context.
Definition async_context.h:331
static uint async_context_core_num(const async_context_t *context)
Return the processor core this async_context belongs to.
Definition async_context.h:447
static void async_context_wait_for_work_until(async_context_t *context, absolute_time_t until)
Block until work needs to be done or the specified time has been reached.
Definition async_context.h:423
static void async_context_deinit(async_context_t *context)
End async_context processing, and free any resources.
Definition async_context.h:463
static bool async_context_remove_when_pending_worker(async_context_t *context, async_when_pending_worker_t *worker)
Remove a "when pending" worker from a context.
Definition async_context.h:366
struct async_work_on_timeout async_at_time_worker_t
A "timeout" instance used by an async_context.
static bool async_context_add_at_time_worker_at(async_context_t *context, async_at_time_worker_t *worker, absolute_time_t at)
Add an "at time" worker to a context.
Definition async_context.h:294
struct async_when_pending_worker async_when_pending_worker_t
A "worker" instance used by an async_context.
static bool async_context_add_when_pending_worker(async_context_t *context, async_when_pending_worker_t *worker)
Add a "when pending" worker to a context.
Definition async_context.h:351
static uint32_t async_context_execute_sync(async_context_t *context, uint32_t(*func)(void *param), void *param)
Execute work synchronously on the core the async_context belongs to.
Definition async_context.h:255
static void async_context_wait_for_work_ms(async_context_t *context, uint32_t ms)
Block until work needs to be done or the specified number of milliseconds have passed.
Definition async_context.h:436
static void async_context_wait_until(async_context_t *context, absolute_time_t until)
sleep until the specified time in an async_context callback safe way
Definition async_context.h:410
static bool async_context_add_at_time_worker(async_context_t *context, async_at_time_worker_t *worker)
Add an "at time" worker to a context.
Definition async_context.h:274
static void async_context_release_lock(async_context_t *context)
Release the async_context lock.
Definition async_context.h:225
static bool async_context_add_at_time_worker_in_ms(async_context_t *context, async_at_time_worker_t *worker, uint32_t ms)
Add an "at time" worker to a context.
Definition async_context.h:315
static void async_context_poll(async_context_t *context)
Perform any pending work for polling style async_context.
Definition async_context.h:396
static absolute_time_t make_timeout_time_ms(uint32_t ms)
Convenience method to get the timestamp a number of milliseconds from the current time.
Definition time.h:158
uint64_t absolute_time_t
An opaque 64 bit timestamp in microseconds.
Definition types.h:43
Implementation of an async_context type, providing methods common to that type.
Definition async_context.h:155
bool(* add_at_time_worker)(async_context_t *self, async_at_time_worker_t *worker)
Add an at-time worker to the context.
Definition async_context.h:162
void(* poll)(async_context_t *self)
Poll for work; may be NULL for non-polled contexts.
Definition async_context.h:167
bool(* remove_at_time_worker)(async_context_t *self, async_at_time_worker_t *worker)
Remove an at-time worker from the context.
Definition async_context.h:163
void(* deinit)(async_context_t *self)
Deinitialise and free resources associated with the context.
Definition async_context.h:170
void(* wait_for_work_until)(async_context_t *self, absolute_time_t until)
Block until work is pending or the specified time is reached.
Definition async_context.h:169
void(* release_lock)(async_context_t *self)
Release the context lock.
Definition async_context.h:159
uint16_t type
Numeric type identifier for this async_context implementation.
Definition async_context.h:156
bool(* add_when_pending_worker)(async_context_t *self, async_when_pending_worker_t *worker)
Add a when-pending worker to the context.
Definition async_context.h:164
void(* wait_until)(async_context_t *self, absolute_time_t until)
Sleep until the specified time in a callback-safe manner.
Definition async_context.h:168
uint32_t(* execute_sync)(async_context_t *context, uint32_t(*func)(void *param), void *param)
Execute a function synchronously on the context's core.
Definition async_context.h:161
bool(* remove_when_pending_worker)(async_context_t *self, async_when_pending_worker_t *worker)
Remove a when-pending worker from the context.
Definition async_context.h:165
void(* acquire_lock_blocking)(async_context_t *self)
Acquire the context lock, blocking until available.
Definition async_context.h:158
void(* lock_check)(async_context_t *self)
Assert that the caller holds the context lock.
Definition async_context.h:160
void(* set_work_pending)(async_context_t *self, async_when_pending_worker_t *worker)
Mark a when-pending worker as having work to do.
Definition async_context.h:166
Base structure type of all async_contexts. For details about its use, see pico_async_context.
Definition async_context.h:179
absolute_time_t next_time
Time at which the next at-time worker should be called.
Definition async_context.h:183
const async_context_type_t * type
Pointer to the type implementation for this context.
Definition async_context.h:180
uint16_t flags
Context flags (see ASYNC_CONTEXT_FLAG_* defines).
Definition async_context.h:184
async_at_time_worker_t * at_time_list
Linked list of registered at-time workers, ordered by next_time.
Definition async_context.h:182
async_when_pending_worker_t * when_pending_list
Linked list of registered when-pending workers.
Definition async_context.h:181
uint8_t core_num
Index of the processor core this context belongs to.
Definition async_context.h:185
A "worker" instance used by an async_context.
Definition async_context.h:125
void(* do_work)(async_context_t *context, struct async_when_pending_worker *worker)
Called by the async_context when the worker has been marked as having "work pending".
Definition async_context.h:136
struct async_when_pending_worker * next
private link list pointer
Definition async_context.h:129
bool work_pending
True if the worker need do_work called.
Definition async_context.h:140
void * user_data
User data associated with the worker instance.
Definition async_context.h:144
A "timeout" instance used by an async_context.
Definition async_context.h:90
void(* do_work)(async_context_t *context, struct async_work_on_timeout *timeout)
Method called when the timeout is reached; may not be NULL.
Definition async_context.h:103
struct async_work_on_timeout * next
private link list pointer
Definition async_context.h:94
absolute_time_t next_time
The next timeout time; this should only be modified during the above methods or via async_context met...
Definition async_context.h:108
void * user_data
User data associated with the timeout instance.
Definition async_context.h:112