drivers: pwm: add system call handlers

pwm_pin_set_usec now defined in terms of the other two APIs.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-10-25 11:27:37 -07:00 committed by Andrew Boie
parent c93a4789cb
commit 0f66b9f7d8
3 changed files with 58 additions and 29 deletions

View file

@ -8,3 +8,4 @@ obj-$(CONFIG_PWM_QMSI) += pwm_qmsi.o
obj-$(CONFIG_PWM_STM32) += pwm_stm32.o
obj-$(CONFIG_PWM_NRF5_SW) += pwm_nrf5_sw.o
obj-$(CONFIG_PWM_MCUX_FTM) += pwm_mcux_ftm.o
obj-$(CONFIG_USERSPACE) += pwm_handlers.o

View file

@ -0,0 +1,23 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <syscall_handler.h>
#include <pwm.h>
_SYSCALL_HANDLER(pwm_pin_set_cycles, dev, pwm, period, pulse)
{
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_PWM);
return _impl_pwm_pin_set_cycles((struct device *)dev, pwm, period,
pulse);
}
_SYSCALL_HANDLER(pwm_get_cycles_per_sec, dev, pwm, cycles)
{
_SYSCALL_OBJ(dev, K_OBJ_DRIVER_PWM);
_SYSCALL_MEMORY_WRITE(cycles, sizeof(u64_t));
return _impl_pwm_get_cycles_per_sec((struct device *)dev,
pwm, (u64_t *)cycles);
}

View file

@ -64,8 +64,11 @@ struct pwm_driver_api {
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
static inline int pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
__syscall int pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse);
static inline int _impl_pwm_pin_set_cycles(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
struct pwm_driver_api *api;
@ -73,6 +76,30 @@ static inline int pwm_pin_set_cycles(struct device *dev, u32_t pwm,
return api->pin_set(dev, pwm, period, pulse);
}
/**
* @brief Get the clock rate (cycles per second) for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param cycles Pointer to the memory to store clock rate (cycles per sec).
* HW specific.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles);
static inline int _impl_pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles)
{
struct pwm_driver_api *api;
api = (struct pwm_driver_api *)dev->driver_api;
return api->get_cycles_per_sec(dev, pwm, cycles);
}
/**
* @brief Set the period and pulse width for a single PWM output.
*
@ -87,12 +114,9 @@ static inline int pwm_pin_set_cycles(struct device *dev, u32_t pwm,
static inline int pwm_pin_set_usec(struct device *dev, u32_t pwm,
u32_t period, u32_t pulse)
{
struct pwm_driver_api *api;
u64_t period_cycles, pulse_cycles, cycles_per_sec;
api = (struct pwm_driver_api *)dev->driver_api;
if (api->get_cycles_per_sec(dev, pwm, &cycles_per_sec) != 0) {
if (pwm_get_cycles_per_sec(dev, pwm, &cycles_per_sec) != 0) {
return -EIO;
}
@ -106,31 +130,10 @@ static inline int pwm_pin_set_usec(struct device *dev, u32_t pwm,
return -ENOTSUP;
}
return api->pin_set(dev, pwm, (u32_t)period_cycles,
(u32_t)pulse_cycles);
return pwm_pin_set_cycles(dev, pwm, (u32_t)period_cycles,
(u32_t)pulse_cycles);
}
/**
* @brief Get the clock rate (cycles per second) for a single PWM output.
*
* @param dev Pointer to the device structure for the driver instance.
* @param pwm PWM pin.
* @param cycles Pointer to the memory to store clock rate (cycles per sec).
* HW specific.
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
static inline int pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
u64_t *cycles)
{
struct pwm_driver_api *api;
api = (struct pwm_driver_api *)dev->driver_api;
return api->get_cycles_per_sec(dev, pwm, cycles);
}
#ifdef __cplusplus
}
#endif
@ -139,4 +142,6 @@ static inline int pwm_get_cycles_per_sec(struct device *dev, u32_t pwm,
* @}
*/
#include <syscalls/pwm.h>
#endif /* __PWM_H__ */