drivers: counter: add missing syscalls

Add missing syscalls and fix already present syscalls for the counter
API.

Fixes #14650.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
Henrik Brix Andersen 2020-01-18 22:11:38 +01:00 committed by Anas Nashif
commit 0f60477667
2 changed files with 143 additions and 20 deletions

View file

@ -11,30 +11,131 @@
* instance and return an integral value * instance and return an integral value
*/ */
#define COUNTER_HANDLER(name) \ #define COUNTER_HANDLER(name) \
static inline int z_vrfy_counter_##name(struct devince *dev) \ static inline int z_vrfy_counter_##name(struct device *dev) \
{ \ { \
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, name)); \ Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, name)); \
return z_impl_counter_ ## name((struct device *)dev); \ return z_impl_counter_ ## name((struct device *)dev); \
} }
COUNTER_HANDLER(get_pending_int) COUNTER_HANDLER(get_pending_int)
COUNTER_HANDLER(read)
COUNTER_HANDLER(stop) COUNTER_HANDLER(stop)
COUNTER_HANDLER(start) COUNTER_HANDLER(start)
COUNTER_HANDLER(get_top_value)
COUNTER_HANDLER(get_max_relative_alarm)
#include <syscalls/counter_get_pending_int_mrsh.c> #include <syscalls/counter_get_pending_int_mrsh.c>
#include <syscalls/counter_read_mrsh.c>
#include <syscalls/counter_stop_mrsh.c> #include <syscalls/counter_stop_mrsh.c>
#include <syscalls/counter_start_mrsh.c> #include <syscalls/counter_start_mrsh.c>
static inline bool z_vrfy_counter_is_counting_up(const struct device *dev)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_is_counting_up((const struct device *)dev);
}
#include <syscalls/counter_is_counting_up_mrsh.c>
static inline u8_t z_vrfy_counter_get_num_of_channels(const struct device *dev)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_get_num_of_channels((const struct device *)dev);
}
#include <syscalls/counter_get_num_of_channels_mrsh.c>
static inline u32_t z_vrfy_counter_get_frequency(const struct device *dev)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_get_frequency((const struct device *)dev);
}
#include <syscalls/counter_get_frequency_mrsh.c>
static inline u32_t z_vrfy_counter_us_to_ticks(const struct device *dev,
u64_t us)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_us_to_ticks((const struct device *)dev,
(u64_t)us);
}
#include <syscalls/counter_us_to_ticks_mrsh.c>
static inline u64_t z_vrfy_counter_ticks_to_us(const struct device *dev,
u32_t ticks)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_ticks_to_us((const struct device *)dev,
(u32_t)ticks);
}
#include <syscalls/counter_ticks_to_us_mrsh.c>
static inline u32_t z_vrfy_counter_read(struct device *dev)
{
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, read));
return z_impl_counter_read((struct device *)dev);
}
#include <syscalls/counter_read_mrsh.c>
static inline int z_vrfy_counter_set_channel_alarm(struct device *dev,
u8_t chan_id, const struct counter_alarm_cfg *alarm_cfg)
{
struct counter_alarm_cfg cfg_copy;
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, set_alarm));
Z_OOPS(z_user_from_copy(&cfg_copy, alarm_cfg, sizeof(cfg_copy)));
Z_OOPS(Z_SYSCALL_VERIFY_MSG(cfg_copy.callback == 0,
"callbacks may not be set from user mode"));
return z_impl_counter_set_channel_alarm((struct device *)dev,
(u8_t)chan_id, (const struct counter_alarm_cfg *)&cfg_copy);
}
#include <syscalls/counter_set_channel_alarm_mrsh.c>
static inline int z_vrfy_counter_cancel_channel_alarm(struct device *dev,
u8_t chan_id)
{
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, cancel_alarm));
return z_vrfy_counter_cancel_channel_alarm((struct device *)dev,
(u8_t)chan_id);
}
#include <syscalls/counter_cancel_channel_alarm_mrsh.c>
static inline int z_vrfy_counter_set_top_value(struct device *dev,
const struct counter_top_cfg
*cfg)
{
struct counter_top_cfg cfg_copy;
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, set_top_value));
Z_OOPS(z_user_from_copy(&cfg_copy, cfg, sizeof(cfg_copy)));
Z_OOPS(Z_SYSCALL_VERIFY_MSG(cfg_copy.callback == 0,
"callbacks may not be set from user mode"));
return z_impl_counter_set_top_value((struct device *)dev,
(const struct counter_top_cfg *)
&cfg_copy);
}
#include <syscalls/counter_set_top_value_mrsh.c>
static inline u32_t z_vrfy_counter_get_top_value(struct device *dev)
{
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, get_top_value));
return z_impl_counter_get_top_value((struct device *)dev);
}
#include <syscalls/counter_get_top_value_mrsh.c> #include <syscalls/counter_get_top_value_mrsh.c>
static inline u32_t z_vrfy_counter_get_max_top_value(const struct device *dev)
{
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_get_max_top_value((struct device *)dev);
}
#include <syscalls/counter_get_max_top_value_mrsh.c>
static inline u32_t z_vrfy_counter_get_max_relative_alarm(struct device *dev)
{
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, get_max_relative_alarm));
return z_impl_counter_get_max_relative_alarm((struct device *)dev);
}
#include <syscalls/counter_get_max_relative_alarm_mrsh.c> #include <syscalls/counter_get_max_relative_alarm_mrsh.c>
static inline u32_t z_vrfy_counter_get_guard_period(struct device *dev, static inline u32_t z_vrfy_counter_get_guard_period(struct device *dev,
u32_t flags) u32_t flags)
{ {
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, get_guard_period)); Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_get_guard_period((struct device *)dev, flags); return z_impl_counter_get_guard_period((struct device *)dev, flags);
} }
#include <syscalls/counter_get_guard_period_mrsh.c> #include <syscalls/counter_get_guard_period_mrsh.c>
@ -42,7 +143,7 @@ static inline u32_t z_vrfy_counter_get_guard_period(struct device *dev,
static inline int z_vrfy_counter_set_guard_period(struct device *dev, static inline int z_vrfy_counter_set_guard_period(struct device *dev,
u32_t ticks, u32_t flags) u32_t ticks, u32_t flags)
{ {
Z_OOPS(Z_SYSCALL_DRIVER_COUNTER(dev, set_guard_period)); Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_set_guard_period((struct device *)dev, ticks, return z_impl_counter_set_guard_period((struct device *)dev, ticks,
flags); flags);
} }

View file

@ -198,7 +198,6 @@ struct counter_driver_api {
counter_api_set_guard_period set_guard_period; counter_api_set_guard_period set_guard_period;
}; };
/** /**
* @brief Function to check if counter is counting up. * @brief Function to check if counter is counting up.
* *
@ -207,7 +206,9 @@ struct counter_driver_api {
* @retval true if counter is counting up. * @retval true if counter is counting up.
* @retval false if counter is counting down. * @retval false if counter is counting down.
*/ */
static inline bool counter_is_counting_up(const struct device *dev) __syscall bool counter_is_counting_up(const struct device *dev);
static inline bool z_impl_counter_is_counting_up(const struct device *dev)
{ {
const struct counter_config_info *config = const struct counter_config_info *config =
(struct counter_config_info *)dev->config->config_info; (struct counter_config_info *)dev->config->config_info;
@ -222,7 +223,9 @@ static inline bool counter_is_counting_up(const struct device *dev)
* *
* @return Number of alarm channels. * @return Number of alarm channels.
*/ */
static inline u8_t counter_get_num_of_channels(const struct device *dev) __syscall u8_t counter_get_num_of_channels(const struct device *dev);
static inline u8_t z_impl_counter_get_num_of_channels(const struct device *dev)
{ {
const struct counter_config_info *config = const struct counter_config_info *config =
(struct counter_config_info *)dev->config->config_info; (struct counter_config_info *)dev->config->config_info;
@ -238,7 +241,9 @@ static inline u8_t counter_get_num_of_channels(const struct device *dev)
* @return Frequency of the counter in Hz, or zero if the counter does * @return Frequency of the counter in Hz, or zero if the counter does
* not have a fixed frequency. * not have a fixed frequency.
*/ */
static inline u32_t counter_get_frequency(const struct device *dev) __syscall u32_t counter_get_frequency(const struct device *dev);
static inline u32_t z_impl_counter_get_frequency(const struct device *dev)
{ {
const struct counter_config_info *config = const struct counter_config_info *config =
(struct counter_config_info *)dev->config->config_info; (struct counter_config_info *)dev->config->config_info;
@ -254,7 +259,10 @@ static inline u32_t counter_get_frequency(const struct device *dev)
* *
* @return Converted ticks. Ticks will be saturated if exceed 32 bits. * @return Converted ticks. Ticks will be saturated if exceed 32 bits.
*/ */
static inline u32_t counter_us_to_ticks(const struct device *dev, u64_t us) __syscall u32_t counter_us_to_ticks(const struct device *dev, u64_t us);
static inline u32_t z_impl_counter_us_to_ticks(const struct device *dev,
u64_t us)
{ {
const struct counter_config_info *config = const struct counter_config_info *config =
(struct counter_config_info *)dev->config->config_info; (struct counter_config_info *)dev->config->config_info;
@ -271,7 +279,10 @@ static inline u32_t counter_us_to_ticks(const struct device *dev, u64_t us)
* *
* @return Converted microseconds. * @return Converted microseconds.
*/ */
static inline u64_t counter_ticks_to_us(const struct device *dev, u32_t ticks) __syscall u64_t counter_ticks_to_us(const struct device *dev, u32_t ticks);
static inline u64_t z_impl_counter_ticks_to_us(const struct device *dev,
u32_t ticks)
{ {
const struct counter_config_info *config = const struct counter_config_info *config =
(struct counter_config_info *)dev->config->config_info; (struct counter_config_info *)dev->config->config_info;
@ -286,7 +297,9 @@ static inline u64_t counter_ticks_to_us(const struct device *dev, u32_t ticks)
* *
* @return Max top value. * @return Max top value.
*/ */
static inline u32_t counter_get_max_top_value(const struct device *dev) __syscall u32_t counter_get_max_top_value(const struct device *dev);
static inline u32_t z_impl_counter_get_max_top_value(const struct device *dev)
{ {
const struct counter_config_info *config = const struct counter_config_info *config =
(struct counter_config_info *)dev->config->config_info; (struct counter_config_info *)dev->config->config_info;
@ -366,8 +379,11 @@ static inline u32_t z_impl_counter_read(struct device *dev)
* @retval -EINVAL if alarm settings are invalid. * @retval -EINVAL if alarm settings are invalid.
* @retval -ETIME if absolute alarm was set too late. * @retval -ETIME if absolute alarm was set too late.
*/ */
static inline int counter_set_channel_alarm(struct device *dev, u8_t chan_id, __syscall int counter_set_channel_alarm(struct device *dev, u8_t chan_id,
const struct counter_alarm_cfg *alarm_cfg) const struct counter_alarm_cfg *alarm_cfg);
static inline int z_impl_counter_set_channel_alarm(struct device *dev,
u8_t chan_id, const struct counter_alarm_cfg *alarm_cfg)
{ {
const struct counter_driver_api *api = const struct counter_driver_api *api =
(struct counter_driver_api *)dev->driver_api; (struct counter_driver_api *)dev->driver_api;
@ -391,8 +407,10 @@ static inline int counter_set_channel_alarm(struct device *dev, u8_t chan_id,
* @retval -ENOTSUP if request is not supported or the counter was not started * @retval -ENOTSUP if request is not supported or the counter was not started
* yet. * yet.
*/ */
static inline int counter_cancel_channel_alarm(struct device *dev, __syscall int counter_cancel_channel_alarm(struct device *dev, u8_t chan_id);
u8_t chan_id)
static inline int z_impl_counter_cancel_channel_alarm(struct device *dev,
u8_t chan_id)
{ {
const struct counter_driver_api *api = const struct counter_driver_api *api =
(struct counter_driver_api *)dev->driver_api; (struct counter_driver_api *)dev->driver_api;
@ -428,8 +446,12 @@ static inline int counter_cancel_channel_alarm(struct device *dev,
* @retval -ETIME if @ref COUNTER_TOP_CFG_DONT_RESET was set and new top value * @retval -ETIME if @ref COUNTER_TOP_CFG_DONT_RESET was set and new top value
* is smaller than current counter value (counter counting up). * is smaller than current counter value (counter counting up).
*/ */
static inline int counter_set_top_value(struct device *dev, __syscall int counter_set_top_value(struct device *dev,
const struct counter_top_cfg *cfg) const struct counter_top_cfg *cfg);
static inline int z_impl_counter_set_top_value(struct device *dev,
const struct counter_top_cfg
*cfg)
{ {
const struct counter_driver_api *api = const struct counter_driver_api *api =
(struct counter_driver_api *)dev->driver_api; (struct counter_driver_api *)dev->driver_api;