zephyr/include/zephyr/drivers/hwspinlock.h
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00

160 lines
3.8 KiB
C

/*
* Copyright (c) 2023 Sequans Communications
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
#define ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_
/**
* @brief HW spinlock Interface
* @defgroup hwspinlock_interface HW spinlock Interface
* @ingroup io_interfaces
* @{
*/
#include <errno.h>
#include <zephyr/types.h>
#include <zephyr/sys/util.h>
#include <zephyr/device.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @cond INTERNAL_HIDDEN */
/**
* @brief Callback API for trying to lock HW spinlock
* @see hwspinlock_trylock().
*/
typedef int (*hwspinlock_api_trylock)(const struct device *dev, uint32_t id);
/**
* @brief Callback API to lock HW spinlock
* @see hwspinlock_lock().
*/
typedef void (*hwspinlock_api_lock)(const struct device *dev, uint32_t id);
/**
* @brief Callback API to unlock HW spinlock
* @see hwspinlock_unlock().
*/
typedef void (*hwspinlock_api_unlock)(const struct device *dev, uint32_t id);
/**
* @brief Callback API to get HW spinlock max ID
* @see hwspinlock_get_max_id().
*/
typedef uint32_t (*hwspinlock_api_get_max_id)(const struct device *dev);
__subsystem struct hwspinlock_driver_api {
hwspinlock_api_trylock trylock;
hwspinlock_api_lock lock;
hwspinlock_api_unlock unlock;
hwspinlock_api_get_max_id get_max_id;
};
/**
* @endcond
*/
/**
* @brief Try to lock HW spinlock
*
* This function is used for try to lock specific HW spinlock. It should
* be called before a critical section that we want to protect.
*
* @param dev HW spinlock device instance.
* @param id Spinlock identifier.
*
* @retval 0 If successful.
* @retval -errno In case of any failure.
*/
__syscall int hwspinlock_trylock(const struct device *dev, uint32_t id);
static inline int z_impl_hwspinlock_trylock(const struct device *dev, uint32_t id)
{
const struct hwspinlock_driver_api *api =
(const struct hwspinlock_driver_api *)dev->api;
if (api->trylock == NULL)
return -ENOSYS;
return api->trylock(dev, id);
}
/**
* @brief Lock HW spinlock
*
* This function is used to lock specific HW spinlock. It should be
* called before a critical section that we want to protect.
*
* @param dev HW spinlock device instance.
* @param id Spinlock identifier.
*/
__syscall void hwspinlock_lock(const struct device *dev, uint32_t id);
static inline void z_impl_hwspinlock_lock(const struct device *dev, uint32_t id)
{
const struct hwspinlock_driver_api *api =
(const struct hwspinlock_driver_api *)dev->api;
if (api->lock != NULL)
api->lock(dev, id);
}
/**
* @brief Try to unlock HW spinlock
*
* This function is used for try to unlock specific HW spinlock. It should
* be called after a critical section that we want to protect.
*
* @param dev HW spinlock device instance.
* @param id Spinlock identifier.
*/
__syscall void hwspinlock_unlock(const struct device *dev, uint32_t id);
static inline void z_impl_hwspinlock_unlock(const struct device *dev, uint32_t id)
{
const struct hwspinlock_driver_api *api =
(const struct hwspinlock_driver_api *)dev->api;
if (api->unlock != NULL)
api->unlock(dev, id);
}
/**
* @brief Get HW spinlock max ID
*
* This function is used to get the HW spinlock maximum ID. It should
* be called before attempting to lock/unlock a specific HW spinlock.
*
* @param dev HW spinlock device instance.
*
* @retval HW spinlock max ID.
* @retval 0 if the function is not implemented by the driver.
*/
__syscall uint32_t hwspinlock_get_max_id(const struct device *dev);
static inline uint32_t z_impl_hwspinlock_get_max_id(const struct device *dev)
{
const struct hwspinlock_driver_api *api =
(const struct hwspinlock_driver_api *)dev->api;
if (api->get_max_id == NULL)
return 0;
return api->get_max_id(dev);
}
#ifdef __cplusplus
}
#endif
/** @} */
#include <zephyr/syscalls/hwspinlock.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_HWSPINLOCK_H_ */