8#ifndef ZEPHYR_INCLUDE_SYS_ONOFF_H_
9#define ZEPHYR_INCLUDE_SYS_ONOFF_H_
30#define ONOFF_FLAG_ERROR BIT(0)
33#define ONOFF_FLAG_ONOFF BIT(1)
34#define ONOFF_FLAG_TRANSITION BIT(2)
45#define ONOFF_STATE_MASK (ONOFF_FLAG_ERROR \
47 | ONOFF_FLAG_TRANSITION)
52#define ONOFF_STATE_OFF 0U
57#define ONOFF_STATE_ON ONOFF_FLAG_ONOFF
63#define ONOFF_STATE_ERROR ONOFF_FLAG_ERROR
69#define ONOFF_STATE_TO_ON (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ON)
75#define ONOFF_STATE_TO_OFF (ONOFF_FLAG_TRANSITION | ONOFF_STATE_OFF)
81#define ONOFF_STATE_RESETTING (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ERROR)
190#define ONOFF_TRANSITIONS_INITIALIZER(_start, _stop, _reset) { \
197#define ONOFF_MANAGER_INITIALIZER(_transitions) { \
198 .transitions = (_transitions), \
300#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:315
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:252
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:129
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:435
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:30
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:101
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:512
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:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
struct z_spinlock_key k_spinlock_key_t
Spinlock key type.
Definition: spinlock.h:130
#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:274
struct sys_notify notify
Notification configuration.
Definition: onoff.h:285
State associated with an on-off manager.
Definition: onoff.h:154
sys_slist_t clients
List of clients waiting for request or reset completion notifications.
Definition: onoff.h:158
uint16_t refs
Number of active clients for the service.
Definition: onoff.h:178
sys_slist_t monitors
List of monitors to be notified of state changes including errors and transition completion.
Definition: onoff.h:163
uint16_t flags
Flags identifying the service state.
Definition: onoff.h:175
int last_res
The result of the last transition.
Definition: onoff.h:172
const struct onoff_transitions * transitions
Transition functions.
Definition: onoff.h:166
struct k_spinlock lock
Mutex protection for other fields.
Definition: onoff.h:169
Registration state for notifications of onoff service transitions.
Definition: onoff.h:524
sys_snode_t node
Links the client into the set of waiting service users.
Definition: onoff.h:529
onoff_monitor_callback callback
Callback to be invoked on state change.
Definition: onoff.h:535
State used when a driver uses the on-off service API for synchronous operations.
Definition: onoff.h:576
struct k_spinlock lock
Mutex protection for other fields.
Definition: onoff.h:578
int32_t count
Negative is error, non-negative is reference count.
Definition: onoff.h:581
On-off service transition functions.
Definition: onoff.h:133
onoff_transition_fn reset
Function to force the service state to reset, where supported.
Definition: onoff.h:143
onoff_transition_fn start
Function to invoke to transition the service to on.
Definition: onoff.h:135
onoff_transition_fn stop
Function to invoke to transition the service to off.
Definition: onoff.h:138
State associated with notification for an asynchronous operation.
Definition: notify.h:138