13#ifndef ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
14#define ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
74#define HWSPINLOCK_CTX_INITIALIZER \
105#define HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, idx) \
107 .dev = DEVICE_DT_GET(DT_HWSPINLOCK_CTRL_BY_IDX(node_id, idx)), \
108 .id = DT_HWSPINLOCK_ID_BY_IDX(node_id, idx), \
109 .ctx = HWSPINLOCK_CTX_INITIALIZER, \
139#define HWSPINLOCK_DT_SPEC_GET_BY_NAME(node_id, name) \
141 .dev = DEVICE_DT_GET(DT_HWSPINLOCK_CTRL_BY_NAME(node_id, name)), \
142 .id = DT_HWSPINLOCK_ID_BY_NAME(node_id, name), \
143 .ctx = HWSPINLOCK_CTX_INITIALIZER, \
154#define HWSPINLOCK_DT_SPEC_GET(node_id) \
155 HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, 0)
165#define HWSPINLOCK_DT_SPEC_INST_GET_BY_IDX(inst, idx) \
166 HWSPINLOCK_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
176#define HWSPINLOCK_DT_SPEC_INST_GET_BY_NAME(inst, name) \
177 HWSPINLOCK_DT_SPEC_GET_BY_NAME(DT_DRV_INST(inst), name)
185#define HWSPINLOCK_DT_SPEC_INST_GET(inst) \
186 HWSPINLOCK_DT_SPEC_GET(DT_DRV_INST(inst))
319 __ASSERT(api->
lock !=
NULL,
"hwspinlock lock callback must be implemented");
343 __ASSERT(api->
unlock !=
NULL,
"hwspinlock unlock callback must be implemented");
363 __ASSERT(api->
get_max_id !=
NULL,
"hwspinlock get_max_id callback must be implemented");
void(* hwspinlock_api_lock)(const struct device *dev, uint32_t id)
Callback API to lock an HW spinlock.
Definition hwspinlock.h:205
uint32_t(* hwspinlock_api_get_max_id)(const struct device *dev)
Callback API to get the maximum HW spinlock ID.
Definition hwspinlock.h:219
int(* hwspinlock_api_trylock)(const struct device *dev, uint32_t id)
Callback API to try to lock an HW spinlock.
Definition hwspinlock.h:198
void(* hwspinlock_api_unlock)(const struct device *dev, uint32_t id)
Callback API to unlock an HW spinlock.
Definition hwspinlock.h:212
static uint32_t hw_spinlock_get_max_id_dt(struct hwspinlock_dt_spec *spec)
Get HW spinlock max ID from a struct hwspinlock_dt_spec.
Definition hwspinlock.h:424
static void hw_spin_unlock_dt(struct hwspinlock_dt_spec *spec, k_spinlock_key_t key)
Unlock HW spinlock from a struct hwspinlock_dt_spec.
Definition hwspinlock.h:409
struct hwspinlock_context hwspinlock_ctx_t
Opaque type to represent a hwspinlock runtime context.
Definition hwspinlock.h:53
static int hw_spin_trylock(const struct device *dev, hwspinlock_ctx_t *ctx, uint32_t id, k_spinlock_key_t *key)
Try to lock HW spinlock.
Definition hwspinlock.h:264
static k_spinlock_key_t hw_spin_lock_dt(struct hwspinlock_dt_spec *spec)
Lock HW spinlock from a struct hwspinlock_dt_spec.
Definition hwspinlock.h:394
static void hw_spin_unlock(const struct device *dev, hwspinlock_ctx_t *ctx, uint32_t id, k_spinlock_key_t key)
Unlock HW spinlock.
Definition hwspinlock.h:338
static k_spinlock_key_t hw_spin_lock(const struct device *dev, hwspinlock_ctx_t *ctx, uint32_t id)
Lock HW spinlock.
Definition hwspinlock.h:313
static uint32_t hw_spinlock_get_max_id(const struct device *dev)
Get HW spinlock max ID.
Definition hwspinlock.h:359
static int hw_spin_trylock_dt(struct hwspinlock_dt_spec *spec, k_spinlock_key_t *key)
Try to lock HW spinlock from a struct hwspinlock_dt_spec.
Definition hwspinlock.h:379
static ALWAYS_INLINE int k_spin_trylock(struct k_spinlock *l, k_spinlock_key_t *k)
Attempt to lock a spinlock.
Definition spinlock.h:229
static ALWAYS_INLINE void k_spin_unlock(struct k_spinlock *l, k_spinlock_key_t key)
Unlock a spin lock.
Definition spinlock.h:299
static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
Lock a spinlock.
Definition spinlock.h:181
struct z_spinlock_key k_spinlock_key_t
Spinlock key type.
Definition spinlock.h:126
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
Public interface for spinlocks.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
HW spinlock controller runtime context.
Definition hwspinlock.h:37
struct k_spinlock lock
Definition hwspinlock.h:45
<span class="mlabel">Driver Operations</span> Hardware Spinlock driver operations
Definition hwspinlock.h:224
hwspinlock_api_unlock unlock
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition hwspinlock.h:236
hwspinlock_api_lock lock
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition hwspinlock.h:232
hwspinlock_api_get_max_id get_max_id
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition hwspinlock.h:240
hwspinlock_api_trylock trylock
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition hwspinlock.h:228
Complete hardware spinlock DT information.
Definition hwspinlock.h:58
hwspinlock_ctx_t ctx
Runtime context.
Definition hwspinlock.h:64
const struct device * dev
HW spinlock device.
Definition hwspinlock.h:60
uint32_t id
HW spinlock id.
Definition hwspinlock.h:62
Kernel Spin Lock.
Definition spinlock.h:45