async_context.h File Reference
#include "pico.h"
#include "pico/time.h"
Include dependency graph for async_context.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  async_work_on_timeout
 A "timeout" instance used by an async_contextA "timeout" represents some future action that must be taken at a specific time. It's methods are called from the async_context under lock at the given time. More...
 
struct  async_when_pending_worker
 A "worker" instance used by an async_contextA "worker" represents some external entity that must do work in response to some external stimulus (usually an IRQ). It's methods are called from the async_context under lock at the given time. More...
 
struct  async_context_type
 Implementation of an async_context type, providing methods common to that type. More...
 
struct  async_context
 Base structure type of all async_contexts. For details about its use, see pico_async_context.Individual async_context_types with additional state, should contain this structure at the start. More...
 

Macros

#define ASYNC_CONTEXT_FLAG_CALLBACK_FROM_NON_IRQ   0x1
 
#define ASYNC_CONTEXT_FLAG_CALLBACK_FROM_IRQ   0x2
 
#define ASYNC_CONTEXT_FLAG_POLLED   0x4
 

Typedefs

typedef struct async_context async_context_t
 
typedef struct async_work_on_timeout async_at_time_worker_t
 A "timeout" instance used by an async_contextA "timeout" represents some future action that must be taken at a specific time. It's methods are called from the async_context under lock at the given time. More...
 
typedef struct async_when_pending_worker async_when_pending_worker_t
 A "worker" instance used by an async_contextA "worker" represents some external entity that must do work in response to some external stimulus (usually an IRQ). It's methods are called from the async_context under lock at the given time. More...
 
typedef struct async_context_type async_context_type_t
 Implementation of an async_context type, providing methods common to that type.
 

Enumerations

enum  { ASYNC_CONTEXT_POLL = 1, ASYNC_CONTEXT_THREADSAFE_BACKGROUND = 2, ASYNC_CONTEXT_FREERTOS = 3 }
 

Functions

static void async_context_acquire_lock_blocking (async_context_t *context)
 Acquire the async_context lockThe owner of the async_context lock is the logic owner of the async_context and other work related to this async_context will not happen concurrently. More...
 
static void async_context_release_lock (async_context_t *context)
 Release the async_context lock. More...
 
static void async_context_lock_check (async_context_t *context)
 Assert if the caller does not own the lock for the async_context. More...
 
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.This method is intended for code external to the async_context (e.g. another thread/task) to execute a function with the same guarantees (single core, logical thread of execution) that async_context workers are called with. More...
 
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 contextAn "at time" worker will run at or after a specific point in time, and is automatically when (just before) it runs. More...
 
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 contextAn "at time" worker will run at or after a specific point in time, and is automatically when (just before) it runs. More...
 
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 contextAn "at time" worker will run at or after a specific point in time, and is automatically when (just before) it runs. More...
 
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. More...
 
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 contextAn "when pending" worker will run when it is pending (can be set via async_context_set_work_pending), and is NOT automatically removed when it runs. More...
 
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. More...
 
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 pendingThe worker will be run from the async_context at a later time. More...
 
static void async_context_poll (async_context_t *context)
 Perform any pending work for polling style async_contextFor a polled async_context (e.g. async_context_poll) the user is responsible for calling this method periodically to perform any required work. More...
 
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 More...
 
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. More...
 
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. More...
 
static uint async_context_core_num (const async_context_t *context)
 Return the processor core this async_context belongs to. More...
 
static void async_context_deinit (async_context_t *context)
 End async_context processing, and free any resourcesNote the user should clean up any resources associated with workers in the async_context themselves. More...