Zephyr API 3.6.99
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
7#ifndef ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
8#define ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
9
17#include <errno.h>
18#include <zephyr/types.h>
19#include <zephyr/sys/util.h>
20#include <zephyr/device.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
32typedef int (*hwspinlock_api_trylock)(const struct device *dev, uint32_t id);
33
38typedef void (*hwspinlock_api_lock)(const struct device *dev, uint32_t id);
39
44typedef void (*hwspinlock_api_unlock)(const struct device *dev, uint32_t id);
45
50typedef uint32_t (*hwspinlock_api_get_max_id)(const struct device *dev);
51
52__subsystem struct hwspinlock_driver_api {
53 hwspinlock_api_trylock trylock;
54 hwspinlock_api_lock lock;
55 hwspinlock_api_unlock unlock;
56 hwspinlock_api_get_max_id get_max_id;
57};
74__syscall int hwspinlock_trylock(const struct device *dev, uint32_t id);
75
76static inline int z_impl_hwspinlock_trylock(const struct device *dev, uint32_t id)
77{
78 const struct hwspinlock_driver_api *api =
79 (const struct hwspinlock_driver_api *)dev->api;
80
81 if (api->trylock == NULL) {
82 return -ENOSYS;
83 }
84
85 return api->trylock(dev, id);
86}
87
97__syscall void hwspinlock_lock(const struct device *dev, uint32_t id);
98
99static inline void z_impl_hwspinlock_lock(const struct device *dev, uint32_t id)
100{
101 const struct hwspinlock_driver_api *api =
102 (const struct hwspinlock_driver_api *)dev->api;
103
104 if (api->lock != NULL) {
105 api->lock(dev, id);
106 }
107}
108
118__syscall void hwspinlock_unlock(const struct device *dev, uint32_t id);
119
120static inline void z_impl_hwspinlock_unlock(const struct device *dev, uint32_t id)
121{
122 const struct hwspinlock_driver_api *api =
123 (const struct hwspinlock_driver_api *)dev->api;
124
125 if (api->unlock != NULL) {
126 api->unlock(dev, id);
127 }
128}
129
141__syscall uint32_t hwspinlock_get_max_id(const struct device *dev);
142
143static inline uint32_t z_impl_hwspinlock_get_max_id(const struct device *dev)
144{
145 const struct hwspinlock_driver_api *api =
146 (const struct hwspinlock_driver_api *)dev->api;
147
148 if (api->get_max_id == NULL) {
149 return 0;
150 }
151
152 return api->get_max_id(dev);
153}
154
155#ifdef __cplusplus
156}
157#endif
158
161#include <zephyr/syscalls/hwspinlock.h>
162
163#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
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
Misc utilities.