Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
hwspinlock.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Sequans Communications
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
14#define ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
15
23#include <errno.h>
24#include <zephyr/types.h>
25#include <zephyr/sys/util.h>
26#include <zephyr/device.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
38typedef int (*hwspinlock_api_trylock)(const struct device *dev, uint32_t id);
39
44typedef void (*hwspinlock_api_lock)(const struct device *dev, uint32_t id);
45
50typedef void (*hwspinlock_api_unlock)(const struct device *dev, uint32_t id);
51
56typedef uint32_t (*hwspinlock_api_get_max_id)(const struct device *dev);
57
58__subsystem struct hwspinlock_driver_api {
59 hwspinlock_api_trylock trylock;
60 hwspinlock_api_lock lock;
61 hwspinlock_api_unlock unlock;
62 hwspinlock_api_get_max_id get_max_id;
63};
80__syscall int hwspinlock_trylock(const struct device *dev, uint32_t id);
81
82static inline int z_impl_hwspinlock_trylock(const struct device *dev, uint32_t id)
83{
84 const struct hwspinlock_driver_api *api =
85 (const struct hwspinlock_driver_api *)dev->api;
86
87 if (api->trylock == NULL) {
88 return -ENOSYS;
89 }
90
91 return api->trylock(dev, id);
92}
93
103__syscall void hwspinlock_lock(const struct device *dev, uint32_t id);
104
105static inline void z_impl_hwspinlock_lock(const struct device *dev, uint32_t id)
106{
107 const struct hwspinlock_driver_api *api =
108 (const struct hwspinlock_driver_api *)dev->api;
109
110 if (api->lock != NULL) {
111 api->lock(dev, id);
112 }
113}
114
124__syscall void hwspinlock_unlock(const struct device *dev, uint32_t id);
125
126static inline void z_impl_hwspinlock_unlock(const struct device *dev, uint32_t id)
127{
128 const struct hwspinlock_driver_api *api =
129 (const struct hwspinlock_driver_api *)dev->api;
130
131 if (api->unlock != NULL) {
132 api->unlock(dev, id);
133 }
134}
135
147__syscall uint32_t hwspinlock_get_max_id(const struct device *dev);
148
149static inline uint32_t z_impl_hwspinlock_get_max_id(const struct device *dev)
150{
151 const struct hwspinlock_driver_api *api =
152 (const struct hwspinlock_driver_api *)dev->api;
153
154 if (api->get_max_id == NULL) {
155 return 0;
156 }
157
158 return api->get_max_id(dev);
159}
160
161#ifdef __cplusplus
162}
163#endif
164
167#include <zephyr/syscalls/hwspinlock.h>
168
169#endif /* ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_ */
System error numbers.
void hwspinlock_lock(const struct device *dev, uint32_t id)
Lock HW spinlock.
int hwspinlock_trylock(const struct device *dev, uint32_t id)
Try to lock HW spinlock.
void hwspinlock_unlock(const struct device *dev, uint32_t id)
Try to unlock HW spinlock.
uint32_t hwspinlock_get_max_id(const struct device *dev)
Get HW spinlock max ID.
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__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
Misc utilities.