Zephyr API 3.6.99
Loading...
Searching...
No Matches
onoff.h File Reference
#include <zephyr/kernel.h>
#include <zephyr/types.h>
#include <zephyr/sys/notify.h>

Go to the source code of this file.

Data Structures

struct  onoff_transitions
 On-off service transition functions. More...
 
struct  onoff_manager
 State associated with an on-off manager. More...
 
struct  onoff_client
 State associated with a client of an on-off service. More...
 
struct  onoff_monitor
 Registration state for notifications of onoff service transitions. More...
 
struct  onoff_sync_service
 State used when a driver uses the on-off service API for synchronous operations. More...
 

Macros

#define ONOFF_FLAG_ERROR   BIT(0)
 Flag indicating an error state.
 
#define ONOFF_STATE_MASK
 Mask used to isolate bits defining the service state.
 
#define ONOFF_STATE_OFF   0U
 Value exposed by ONOFF_STATE_MASK when service is off.
 
#define ONOFF_STATE_ON   ONOFF_FLAG_ONOFF
 Value exposed by ONOFF_STATE_MASK when service is on.
 
#define ONOFF_STATE_ERROR   ONOFF_FLAG_ERROR
 Value exposed by ONOFF_STATE_MASK when the service is in an error state (and not in the process of resetting its state).
 
#define ONOFF_STATE_TO_ON   (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ON)
 Value exposed by ONOFF_STATE_MASK when service is transitioning to on.
 
#define ONOFF_STATE_TO_OFF   (ONOFF_FLAG_TRANSITION | ONOFF_STATE_OFF)
 Value exposed by ONOFF_STATE_MASK when service is transitioning to off.
 
#define ONOFF_STATE_RESETTING   (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ERROR)
 Value exposed by ONOFF_STATE_MASK when service is in the process of resetting.
 
#define ONOFF_TRANSITIONS_INITIALIZER(_start, _stop, _reset)
 Initializer for a onoff_transitions object.
 
#define ONOFF_CLIENT_EXTENSION_POS   SYS_NOTIFY_EXTENSION_POS
 Identify region of sys_notify flags available for containing services.
 

Typedefs

typedef void(* onoff_notify_fn) (struct onoff_manager *mgr, int res)
 Signature used to notify an on-off manager that a transition has completed.
 
typedef void(* onoff_transition_fn) (struct onoff_manager *mgr, onoff_notify_fn notify)
 Signature used by service implementations to effect a transition.
 
typedef 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.
 
typedef 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.
 

Functions

int onoff_manager_init (struct onoff_manager *mgr, const struct onoff_transitions *transitions)
 Initialize an on-off service to off state.
 
static bool onoff_has_error (const struct onoff_manager *mgr)
 Test whether an on-off service has recorded an error.
 
int onoff_request (struct onoff_manager *mgr, struct onoff_client *cli)
 Request a reservation to use an on-off service.
 
int onoff_release (struct onoff_manager *mgr)
 Release a reserved use of an on-off service.
 
int onoff_cancel (struct onoff_manager *mgr, struct onoff_client *cli)
 Attempt to cancel an in-progress client operation.
 
static int onoff_cancel_or_release (struct onoff_manager *mgr, struct onoff_client *cli)
 Helper function to safely cancel a request.
 
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.
 
int onoff_monitor_register (struct onoff_manager *mgr, struct onoff_monitor *mon)
 Add a monitor of state changes for a manager.
 
int onoff_monitor_unregister (struct onoff_manager *mgr, struct onoff_monitor *mon)
 Remove a monitor of state changes from a manager.
 
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_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.