13#ifndef ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
14#define ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
72#define HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, idx) \
74 .dev = DEVICE_DT_GET(DT_HWSPINLOCK_CTRL_BY_IDX(node_id, idx)), \
75 .id = DT_HWSPINLOCK_ID_BY_IDX(node_id, idx), \
105#define HWSPINLOCK_DT_SPEC_GET_BY_NAME(node_id, name) \
107 .dev = DEVICE_DT_GET(DT_HWSPINLOCK_CTRL_BY_NAME(node_id, name)), \
108 .id = DT_HWSPINLOCK_ID_BY_NAME(node_id, name), \
119#define HWSPINLOCK_DT_SPEC_GET(node_id) \
120 HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, 0)
130#define HWSPINLOCK_DT_SPEC_INST_GET_BY_IDX(inst, idx) \
131 HWSPINLOCK_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), idx)
141#define HWSPINLOCK_DT_SPEC_INST_GET_BY_NAME(inst, name) \
142 HWSPINLOCK_DT_SPEC_GET_BY_NAME(DT_DRV_INST(inst), name)
150#define HWSPINLOCK_DT_SPEC_INST_GET(inst) \
151 HWSPINLOCK_DT_SPEC_GET(DT_DRV_INST(inst))
159#define __HWSPINLOCK_NUM_LOCKS_FROM_DT_NODE(node_id) \
160 DT_PROP(node_id, num_locks)
162#define __HWSPINLOCK_SPINLOCK_ARRAY_NAME_FROM_DT_NODE(node_id) \
163 CONCAT(__hwspinlock_locks_, DT_DEP_ORD(node_id))
177#define HWSPINLOCK_COMMON_CONFIG_FROM_DT_NODE(node_id) \
179 .num_locks = __HWSPINLOCK_NUM_LOCKS_FROM_DT_NODE(node_id), \
180 .locks = __HWSPINLOCK_SPINLOCK_ARRAY_NAME_FROM_DT_NODE(node_id), \
191#define HWSPINLOCK_COMMON_CONFIG_FROM_DT_INST(inst) \
192 HWSPINLOCK_COMMON_CONFIG_FROM_DT_NODE(DT_DRV_INST(inst))
204#define HWSPINLOCK_SPINLOCK_ARRAY_DT_DEFINE(node_id) \
205 static struct k_spinlock __HWSPINLOCK_SPINLOCK_ARRAY_NAME_FROM_DT_NODE( \
206 node_id)[__HWSPINLOCK_NUM_LOCKS_FROM_DT_NODE(node_id)]
218#define HWSPINLOCK_SPINLOCK_ARRAY_DT_INST_DEFINE(inst) \
219 HWSPINLOCK_SPINLOCK_ARRAY_DT_DEFINE(DT_DRV_INST(inst))
364 __ASSERT(api->
lock !=
NULL,
"hwspinlock lock callback must be implemented");
387 __ASSERT(api->
unlock !=
NULL,
"hwspinlock unlock callback must be implemented");
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
void(* hwspinlock_api_lock)(const struct device *dev, uint32_t id)
Callback API to lock an HW spinlock.
Definition hwspinlock.h:251
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:472
static int hw_spin_trylock(const struct device *dev, uint32_t id, k_spinlock_key_t *key)
Try to lock HW spinlock.
Definition hwspinlock.h:311
uint32_t(* hwspinlock_api_get_max_id)(const struct device *dev)
Callback API to get the maximum HW spinlock ID.
Definition hwspinlock.h:267
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:457
int(* hwspinlock_api_trylock)(const struct device *dev, uint32_t id)
@def_driverbackendgroup{Hardware Spinlock,hwspinlock_interface}
Definition hwspinlock.h:244
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:442
static void hw_spin_unlock(const struct device *dev, uint32_t id, k_spinlock_key_t key)
Unlock HW spinlock.
Definition hwspinlock.h:382
static k_spinlock_key_t hw_spin_lock(const struct device *dev, uint32_t id)
Lock HW spinlock.
Definition hwspinlock.h:358
void(* hwspinlock_api_unlock)(const struct device *dev, uint32_t id)
Callback API to unlock an HW spinlock.
Definition hwspinlock.h:258
static uint32_t hw_spinlock_get_max_id(const struct device *dev)
Get HW spinlock max ID.
Definition hwspinlock.h:403
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:427
static ALWAYS_INLINE int k_spin_trylock(struct k_spinlock *l, k_spinlock_key_t *k)
Attempt to lock a spinlock.
Definition spinlock.h:242
static ALWAYS_INLINE void k_spin_unlock(struct k_spinlock *l, k_spinlock_key_t key)
Unlock a spin lock.
Definition spinlock.h:312
static ALWAYS_INLINE k_spinlock_key_t k_spin_lock(struct k_spinlock *l)
Lock a spinlock.
Definition spinlock.h:192
struct z_spinlock_key k_spinlock_key_t
Spinlock key type.
Definition spinlock.h:137
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define NULL
Definition iar_missing_defs.h:20
Public interface for spinlocks.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * config
Address of device instance config information.
Definition device.h:517
@driver_ops{Hardware Spinlock}
Definition hwspinlock.h:272
hwspinlock_api_unlock unlock
@driver_ops_mandatory Unlock HW spinlock.
Definition hwspinlock.h:284
hwspinlock_api_lock lock
@driver_ops_mandatory Lock HW spinlock.
Definition hwspinlock.h:280
hwspinlock_api_get_max_id get_max_id
@driver_ops_optional Get HW spinlock max ID.
Definition hwspinlock.h:288
hwspinlock_api_trylock trylock
@driver_ops_optional Try to lock HW spinlock.
Definition hwspinlock.h:276
This structure is common to all hardware spinlock drivers and is expected to be the first element in ...
Definition hwspinlock.h:225
uint8_t num_locks
The number of hw spinlock supported by this driver.
Definition hwspinlock.h:227
struct k_spinlock * locks
Array of spinlocks that will be used to protect access to underlying hardware.
Definition hwspinlock.h:231
Complete hardware spinlock DT information.
Definition hwspinlock.h:39
const struct device * dev
HW spinlock device.
Definition hwspinlock.h:41
uint32_t id
HW spinlock id.
Definition hwspinlock.h:43
Kernel Spin Lock.
Definition spinlock.h:45