Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
onoff.h File Reference
#include <kernel.h>
#include <zephyr/types.h>
#include <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. More...
 
#define ONOFF_FLAG_ONOFF   BIT(1)
 
#define ONOFF_FLAG_TRANSITION   BIT(2)
 
#define ONOFF_STATE_MASK
 Mask used to isolate bits defining the service state. More...
 
#define ONOFF_STATE_OFF   0U
 Value exposed by ONOFF_STATE_MASK when service is off. More...
 
#define ONOFF_STATE_ON   ONOFF_FLAG_ONOFF
 Value exposed by ONOFF_STATE_MASK when service is on. More...
 
#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). More...
 
#define ONOFF_STATE_TO_ON   (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ON)
 Value exposed by ONOFF_STATE_MASK when service is transitioning to on. More...
 
#define ONOFF_STATE_TO_OFF   (ONOFF_FLAG_TRANSITION | ONOFF_STATE_OFF)
 Value exposed by ONOFF_STATE_MASK when service is transitioning to off. More...
 
#define ONOFF_STATE_RESETTING   (ONOFF_FLAG_TRANSITION | ONOFF_STATE_ERROR)
 Value exposed by ONOFF_STATE_MASK when service is in the process of resetting. More...
 
#define ONOFF_TRANSITIONS_INITIALIZER(_start, _stop, _reset)
 Initializer for a onoff_transitions object. More...
 
#define ONOFF_MANAGER_INITIALIZER(_transitions)
 
#define ONOFF_CLIENT_EXTENSION_POS   SYS_NOTIFY_EXTENSION_POS
 Identify region of sys_notify flags available for containing services. More...
 

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. More...
 
typedef void(* onoff_transition_fn) (struct onoff_manager *mgr, onoff_notify_fn notify)
 Signature used by service implementations to effect a transition. More...
 
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. More...
 
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. More...
 

Functions

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