14#ifndef ZEPHYR_INCLUDE_SYS_ONOFF_H_
15#define ZEPHYR_INCLUDE_SYS_ONOFF_H_
36#define ONOFF_FLAG_ERROR BIT(0)
39#define ONOFF_FLAG_ONOFF BIT(1)
40#define ONOFF_FLAG_TRANSITION BIT(2)
51#define ONOFF_STATE_MASK (ONOFF_FLAG_ERROR \
53 | ONOFF_FLAG_TRANSITION)
58#define ONOFF_STATE_OFF 0U
63#define ONOFF_STATE_ON ONOFF_FLAG_ONOFF
69#define ONOFF_STATE_ERROR ONOFF_FLAG_ERROR
75#define ONOFF_STATE_TO_ON (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ON)
81#define ONOFF_STATE_TO_OFF (ONOFF_FLAG_TRANSITION | ONOFF_STATE_OFF)
87#define ONOFF_STATE_RESETTING (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ERROR)
196#define ONOFF_TRANSITIONS_INITIALIZER(_start, _stop, _reset) { \
203#define ONOFF_MANAGER_INITIALIZER(_transitions) { \
204 .transitions = (_transitions), \
306#define ONOFF_CLIENT_EXTENSION_POS SYS_NOTIFY_EXTENSION_POS
int onoff_sync_lock(struct onoff_sync_service *srv, k_spinlock_key_t *keyp)
Lock a synchronous onoff service and provide its state.
int onoff_release(struct onoff_manager *mgr)
Release a reserved use of an on-off service.
int onoff_request(struct onoff_manager *mgr, struct onoff_client *cli)
Request a reservation to use an on-off service.
static bool onoff_has_error(const struct onoff_manager *mgr)
Test whether an on-off service has recorded an error.
Definition onoff.h:321
void(* onoff_client_callback)(struct onoff_manager *mgr, struct onoff_client *cli, uint32_t state, int res)
Signature used to notify an on-off service client of the completion of an operation.
Definition onoff.h:258
int onoff_monitor_unregister(struct onoff_manager *mgr, struct onoff_monitor *mon)
Remove a monitor of state changes from a manager.
void(* onoff_transition_fn)(struct onoff_manager *mgr, onoff_notify_fn notify)
Signature used by service implementations to effect a transition.
Definition onoff.h:135
int onoff_manager_init(struct onoff_manager *mgr, const struct onoff_transitions *transitions)
Initialize an on-off service to off state.
static int onoff_cancel_or_release(struct onoff_manager *mgr, struct onoff_client *cli)
Helper function to safely cancel a request.
Definition onoff.h:441
int onoff_monitor_register(struct onoff_manager *mgr, struct onoff_monitor *mon)
Add a monitor of state changes for a manager.
#define ONOFF_FLAG_ERROR
Flag indicating an error state.
Definition onoff.h:36
void(* onoff_notify_fn)(struct onoff_manager *mgr, int res)
Signature used to notify an on-off manager that a transition has completed.
Definition onoff.h:107
int onoff_cancel(struct onoff_manager *mgr, struct onoff_client *cli)
Attempt to cancel an in-progress client operation.
int onoff_sync_finalize(struct onoff_sync_service *srv, k_spinlock_key_t key, struct onoff_client *cli, int res, bool on)
Process the completion of a transition in a synchronous service and release lock.
void(* onoff_monitor_callback)(struct onoff_manager *mgr, struct onoff_monitor *mon, uint32_t state, int res)
Signature used to notify a monitor of an onoff service of errors or completion of a state transition.
Definition onoff.h:518
int onoff_reset(struct onoff_manager *mgr, struct onoff_client *cli)
Clear errors on an on-off service and reset it to its off state.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:52
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:42
struct z_spinlock_key k_spinlock_key_t
Spinlock key type.
Definition spinlock.h:137
#define EALREADY
Operation already in progress.
Definition errno.h:104
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Kernel Spin Lock.
Definition spinlock.h:45
State associated with a client of an on-off service.
Definition onoff.h:280
struct sys_notify notify
Notification configuration.
Definition onoff.h:291
State associated with an on-off manager.
Definition onoff.h:160
sys_slist_t clients
List of clients waiting for request or reset completion notifications.
Definition onoff.h:164
uint16_t refs
Number of active clients for the service.
Definition onoff.h:184
sys_slist_t monitors
List of monitors to be notified of state changes including errors and transition completion.
Definition onoff.h:169
uint16_t flags
Flags identifying the service state.
Definition onoff.h:181
int last_res
The result of the last transition.
Definition onoff.h:178
const struct onoff_transitions * transitions
Transition functions.
Definition onoff.h:172
struct k_spinlock lock
Mutex protection for other fields.
Definition onoff.h:175
Registration state for notifications of onoff service transitions.
Definition onoff.h:530
sys_snode_t node
Links the client into the set of waiting service users.
Definition onoff.h:535
onoff_monitor_callback callback
Callback to be invoked on state change.
Definition onoff.h:541
State used when a driver uses the on-off service API for synchronous operations.
Definition onoff.h:582
struct k_spinlock lock
Mutex protection for other fields.
Definition onoff.h:584
int32_t count
Negative is error, non-negative is reference count.
Definition onoff.h:587
On-off service transition functions.
Definition onoff.h:139
onoff_transition_fn reset
Function to force the service state to reset, where supported.
Definition onoff.h:149
onoff_transition_fn start
Function to invoke to transition the service to on.
Definition onoff.h:141
onoff_transition_fn stop
Function to invoke to transition the service to off.
Definition onoff.h:144
State associated with notification for an asynchronous operation.
Definition notify.h:138