sensors: implement system calls

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-09-29 02:56:55 -07:00 committed by Andrew Boie
parent 2f7519bfd2
commit 6d79fe54da
4 changed files with 83 additions and 10 deletions

View file

@ -265,10 +265,15 @@ struct sensor_driver_api {
*
* @return 0 if successful, negative errno code if failure.
*/
static inline int sensor_attr_set(struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
__syscall int sensor_attr_set(struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val);
static inline int _impl_sensor_attr_set(struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
{
const struct sensor_driver_api *api = dev->driver_api;
@ -287,6 +292,8 @@ static inline int sensor_attr_set(struct device *dev,
* driver. It is currently up to the caller to ensure that the handler
* does not overflow the stack.
*
* This API is not permitted for user threads.
*
* @param dev Pointer to the sensor device
* @param trig The trigger to activate
* @param handler The function that should be called when the trigger
@ -323,7 +330,9 @@ static inline int sensor_trigger_set(struct device *dev,
*
* @return 0 if successful, negative errno code if failure.
*/
static inline int sensor_sample_fetch(struct device *dev)
__syscall int sensor_sample_fetch(struct device *dev);
static inline int _impl_sensor_sample_fetch(struct device *dev)
{
const struct sensor_driver_api *api = dev->driver_api;
@ -349,8 +358,11 @@ static inline int sensor_sample_fetch(struct device *dev)
*
* @return 0 if successful, negative errno code if failure.
*/
static inline int sensor_sample_fetch_chan(struct device *dev,
enum sensor_channel type)
__syscall int sensor_sample_fetch_chan(struct device *dev,
enum sensor_channel type);
static inline int _impl_sensor_sample_fetch_chan(struct device *dev,
enum sensor_channel type)
{
const struct sensor_driver_api *api = dev->driver_api;
@ -378,9 +390,13 @@ static inline int sensor_sample_fetch_chan(struct device *dev,
*
* @return 0 if successful, negative errno code if failure.
*/
static inline int sensor_channel_get(struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
__syscall int sensor_channel_get(struct device *dev,
enum sensor_channel chan,
struct sensor_value *val);
static inline int _impl_sensor_channel_get(struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
{
const struct sensor_driver_api *api = dev->driver_api;
@ -469,6 +485,7 @@ static inline double sensor_value_to_double(struct sensor_value *val)
return (double)val->val1 + (double)val->val2 / 1000000;
}
#include <syscalls/sensor.h>
#ifdef __cplusplus
}

View file

@ -9,3 +9,4 @@ obj-$(CONFIG_CPLUSPLUS) += cpp/
obj-y += logging/
obj-y += debug/
obj-$(CONFIG_MCUBOOT_IMG_MANAGER) += dfu/
obj-$(CONFIG_USERSPACE) += driver_handlers/

View file

@ -0,0 +1,2 @@
obj-$(CONFIG_SENSOR) += sensor.o

View file

@ -0,0 +1,53 @@
/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sensor.h>
#include <syscall_handler.h>
u32_t _handler_sensor_attr_set(u32_t dev, u32_t chan, u32_t attr,
u32_t val, u32_t arg5, u32_t arg6, void *ssf)
{
_SYSCALL_ARG4;
_SYSCALL_IS_OBJ(dev, K_OBJ_DRIVER_SENSOR, 0, ssf);
_SYSCALL_MEMORY(val, sizeof(struct sensor_value), 0, ssf);
return _impl_sensor_attr_set((struct device *)dev, chan, attr,
(const struct sensor_value *)val);
}
u32_t _handler_sensor_sample_fetch(u32_t dev, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6,
void *ssf)
{
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(dev, K_OBJ_DRIVER_SENSOR, 0, ssf);
return _impl_sensor_sample_fetch((struct device *)dev);
}
u32_t _handler_sensor_sample_fetch_chan(u32_t dev, u32_t type, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6,
void *ssf)
{
_SYSCALL_ARG2;
_SYSCALL_IS_OBJ(dev, K_OBJ_DRIVER_SENSOR, 0, ssf);
return _impl_sensor_sample_fetch_chan((struct device *)dev, type);
}
u32_t _handler_sensor_channel_get(u32_t dev, u32_t chan, u32_t val,
u32_t arg4, u32_t arg5, u32_t arg6,
void *ssf)
{
_SYSCALL_ARG3;
_SYSCALL_IS_OBJ(dev, K_OBJ_DRIVER_SENSOR, 0, ssf);
_SYSCALL_MEMORY(val, sizeof(struct sensor_value), 1, ssf);
return _impl_sensor_channel_get((struct device *)dev, chan,
(struct sensor_value *)val);
}