Zephyr Project API 3.7.0
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
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 return api->trylock(dev, id);
85}
86
96__syscall void hwspinlock_lock(const struct device *dev, uint32_t id);
97
98static inline void z_impl_hwspinlock_lock(const struct device *dev, uint32_t id)
99{
100 const struct hwspinlock_driver_api *api =
101 (const struct hwspinlock_driver_api *)dev->api;
102
103 if (api->lock != NULL)
104 api->lock(dev, id);
105}
106
116__syscall void hwspinlock_unlock(const struct device *dev, uint32_t id);
117
118static inline void z_impl_hwspinlock_unlock(const struct device *dev, uint32_t id)
119{
120 const struct hwspinlock_driver_api *api =
121 (const struct hwspinlock_driver_api *)dev->api;
122
123 if (api->unlock != NULL)
124 api->unlock(dev, id);
125}
126
138__syscall uint32_t hwspinlock_get_max_id(const struct device *dev);
139
140static inline uint32_t z_impl_hwspinlock_get_max_id(const struct device *dev)
141{
142 const struct hwspinlock_driver_api *api =
143 (const struct hwspinlock_driver_api *)dev->api;
144
145 if (api->get_max_id == NULL)
146 return 0;
147
148 return api->get_max_id(dev);
149}
150
151#ifdef __cplusplus
152}
153#endif
154
157#include <zephyr/syscalls/hwspinlock.h>
158
159#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
static struct k_spinlock lock
Definition spinlock_error_case.c:13
__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.