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))
197typedef int (*hwspinlock_api_trylock)(
const struct device *dev,
uint32_t id);
206typedef void (*hwspinlock_api_lock)(
const struct device *dev,
uint32_t id);
215typedef void (*hwspinlock_api_unlock)(
const struct device *dev,
uint32_t id);
224typedef uint32_t (*hwspinlock_api_get_max_id)(
const struct device *dev);
226__subsystem
struct hwspinlock_driver_api {
227 hwspinlock_api_trylock trylock;
228 hwspinlock_api_lock lock;
229 hwspinlock_api_unlock unlock;
230 hwspinlock_api_get_max_id get_max_id;
258 const struct hwspinlock_driver_api *api = (
const struct hwspinlock_driver_api *)dev->
api;
261 if (api->trylock ==
NULL) {
269 return api->trylock(dev,
id);
299 const struct hwspinlock_driver_api *api = (
const struct hwspinlock_driver_api *)dev->
api;
302 __ASSERT(api->lock !=
NULL,
"hwspinlock lock callback must be implemented");
324 const struct hwspinlock_driver_api *api = (
const struct hwspinlock_driver_api *)dev->
api;
326 __ASSERT(api->unlock !=
NULL,
"hwspinlock unlock callback must be implemented");
328 api->unlock(dev,
id);
344 const struct hwspinlock_driver_api *api = (
const struct hwspinlock_driver_api *)dev->
api;
346 __ASSERT(api->get_max_id !=
NULL,
"hwspinlock get_max_id callback must be implemented");
348 return api->get_max_id(dev);
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:407
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:392
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:255
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:377
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:321
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:296
static uint32_t hw_spinlock_get_max_id(const struct device *dev)
Get HW spinlock max ID.
Definition hwspinlock.h:342
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:362
static ALWAYS_INLINE int k_spin_trylock(struct k_spinlock *l, k_spinlock_key_t *k)
Attempt to lock a spinlock.
Definition spinlock.h:233
static ALWAYS_INLINE void k_spin_unlock(struct k_spinlock *l, k_spinlock_key_t key)
Unlock a spin lock.
Definition spinlock.h:303
static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
Lock a spinlock.
Definition spinlock.h:185
struct z_spinlock_key k_spinlock_key_t
Spinlock key type.
Definition spinlock.h:130
#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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
HW spinlock controller runtime context.
Definition hwspinlock.h:37
struct k_spinlock lock
Definition hwspinlock.h:45
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