Skip to content

Commit d8f38dc

Browse files
committed
include: drivers: misc: Add header file for Renesas LVD APIs
Add header file to support Renesas LVD APIs on Zephyr Signed-off-by: Quy Tran <[email protected]>
1 parent 8d3e42a commit d8f38dc

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief Public APIs for the Renesas LVD driver
10+
*/
11+
12+
#ifndef ZEPHYR_INCLUDE_DRIVERS_MISC_RENESAS_LVD_H_
13+
#define ZEPHYR_INCLUDE_DRIVERS_MISC_RENESAS_LVD_H_
14+
15+
/**
16+
* @brief Renesas LVD driver public APIs
17+
* @defgroup renesas_lvd_interface Renesas LVD driver APIs
18+
* @ingroup misc_interfaces
19+
* @{
20+
*/
21+
22+
#include <stdint.h>
23+
#include <zephyr/sys/slist.h>
24+
#include <zephyr/device.h>
25+
#include <zephyr/kernel.h>
26+
#include <zephyr/internal/syscall_handler.h>
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
/** @brief LVD voltage position relative to threshold.
33+
*
34+
* This enum indicates whether the monitored voltage is
35+
* currently above or below the configured threshold.
36+
*/
37+
typedef enum {
38+
/** Voltage is above threshold. */
39+
RENESAS_LVD_POSITION_ABOVE = 0,
40+
41+
/** Voltage is below threshold. */
42+
RENESAS_LVD_POSITION_BELOW,
43+
} renesas_lvd_position_t;
44+
45+
/** @brief LVD Voltage crossing status.
46+
*
47+
* This enum defines the status, whether the voltage crossed
48+
* the voltage detection level or not
49+
*/
50+
typedef enum {
51+
/** No threshold crossing detected */
52+
RENESAS_LVD_CROSS_NONE = 0,
53+
54+
/** Voltage crossed over the threshold. */
55+
RENESAS_LVD_CROSS_OVER,
56+
} renesas_lvd_cross_t;
57+
58+
/** @brief Renesas LVD generic status structure.
59+
*
60+
* This structure combines the current voltage position and
61+
* the last detected crossing type for the monitored channel.
62+
*/
63+
typedef struct {
64+
renesas_lvd_position_t position;
65+
renesas_lvd_cross_t cross;
66+
} renesas_lvd_status_t;
67+
68+
typedef void (*renesas_lvd_callback_t)(const struct device *dev, void *user_data);
69+
70+
/**
71+
* @cond INTERNAL_HIDDEN
72+
*
73+
* Renesas LVD driver API definition and system call entry points
74+
*
75+
* (Internal use only.)
76+
*/
77+
__subsystem struct renesas_lvd_driver_api {
78+
int (*get_status)(const struct device *dev, renesas_lvd_status_t *status);
79+
int (*clear_status)(const struct device *dev);
80+
int (*callback_set)(const struct device *dev, renesas_lvd_callback_t callback,
81+
void *user_data);
82+
};
83+
84+
/**
85+
* @endcond
86+
*/
87+
88+
/**
89+
* @brief Get the current state of the monitor.
90+
*
91+
* This function requests the Renesas LVD to get the current status.
92+
*
93+
* @param dev The Renesas LVD device.
94+
* @param status Pointer to the status structure to be filled.
95+
*
96+
* @return 0 if successful.
97+
* @return A negative errno code on failure.
98+
*/
99+
__syscall int renesas_lvd_get_status(const struct device *dev, renesas_lvd_status_t *status);
100+
101+
static inline int z_impl_renesas_lvd_get_status(const struct device *dev,
102+
renesas_lvd_status_t *status)
103+
{
104+
return DEVICE_API_GET(renesas_lvd, dev)->get_status(dev, status);
105+
}
106+
107+
/**
108+
* @brief Clear the current status of the monitor.
109+
*
110+
* This function requests the Renesas LVD to clear the current status.
111+
*
112+
* @param dev The Renesas LVD device.
113+
*
114+
* @return 0 if successful.
115+
* @return A negative errno code on failure.
116+
*/
117+
__syscall int renesas_lvd_clear_status(const struct device *dev);
118+
119+
static inline int z_impl_renesas_lvd_clear_status(const struct device *dev)
120+
{
121+
return DEVICE_API_GET(renesas_lvd, dev)->clear_status(dev);
122+
}
123+
124+
/**
125+
* @brief Set callback function for voltage detection.
126+
*
127+
* This function set callback function for voltage detection.
128+
*
129+
* @param dev The Renesas LVD device.
130+
* @param callback Pointer to the callback function to be set.
131+
* @param user_data Pointer to user data to be passed to the callback function.
132+
*
133+
* @return 0 if successful.
134+
* @return A negative errno code on failure.
135+
*/
136+
__syscall int renesas_lvd_callback_set(const struct device *dev, renesas_lvd_callback_t callback,
137+
void *user_data);
138+
139+
static inline int z_impl_renesas_lvd_callback_set(const struct device *dev,
140+
renesas_lvd_callback_t callback, void *user_data)
141+
{
142+
return DEVICE_API_GET(renesas_lvd, dev)->callback_set(dev, callback, user_data);
143+
}
144+
145+
#ifdef __cplusplus
146+
}
147+
#endif
148+
149+
#include <zephyr/syscalls/renesas_lvd.h>
150+
151+
#endif /* ZEPHYR_INCLUDE_DRIVERS_MISC_RENESAS_LVD_H_ */

0 commit comments

Comments
 (0)