Add infrastructure for sensor drivers

Origin: Original
Change-Id: I846b1601f1bdf15ad068b27baefc4b23ffab81e3
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
This commit is contained in:
Vlad Dogaru 2016-01-25 18:21:51 +02:00 committed by Anas Nashif
commit 48bdd70a07
5 changed files with 108 additions and 0 deletions

View file

@ -69,4 +69,6 @@ source "drivers/nble/Kconfig"
source "drivers/flash/Kconfig" source "drivers/flash/Kconfig"
source "drivers/sensor/Kconfig"
endmenu endmenu

View file

@ -22,5 +22,6 @@ obj-$(CONFIG_RTC) += rtc/
obj-$(CONFIG_CLOCK_CONTROL) += clock_control/ obj-$(CONFIG_CLOCK_CONTROL) += clock_control/
obj-$(CONFIG_IPM) += ipm/ obj-$(CONFIG_IPM) += ipm/
obj-$(CONFIG_NBLE) += nble/ obj-$(CONFIG_NBLE) += nble/
obj-$(CONFIG_SENSOR) += sensor/
obj-y += aio/ obj-y += aio/
obj-$(CONFIG_PINMUX) += pinmux/ obj-$(CONFIG_PINMUX) += pinmux/

45
drivers/sensor/Kconfig Normal file
View file

@ -0,0 +1,45 @@
# Kconfig - sensor configuration options
#
# Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
menuconfig SENSOR
bool
prompt "Sensor Drivers"
default n
help
Include sensor drivers in system config
config SENSOR_DELAYED_WORK
depends on SENSOR
bool
config SENSOR_DELAYED_WORK_STACK_SIZE
int "Sensor delayed work fiber stack size"
depends on SENSOR && SENSOR_DELAYED_WORK
default 1024
config SENSOR_DELAYED_WORK_PRIORITY
int "Sensor delayed work fiber priority"
depends on SENSOR && SENSOR_DELAYED_WORK
default 10
config SENSOR_DEBUG
bool "Enable sensor debug output"
default n
depends on SENSOR && PRINTK
help
This option enables debug output for sensor drivers.

3
drivers/sensor/Makefile Normal file
View file

@ -0,0 +1,3 @@
ccflags-y +=-I$(srctree)/drivers
obj-$(CONFIG_SENSOR_DELAYED_WORK) += sensor.o

57
drivers/sensor/sensor.c Normal file
View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <nanokernel.h>
#include <sensor.h>
#include <init.h>
static char __stack sensor_fiber_stack[CONFIG_SENSOR_DELAYED_WORK_STACK_SIZE];
static struct nano_fifo sensor_fifo;
struct nano_fifo *sensor_get_work_fifo(void)
{
return &sensor_fifo;
}
static void sensor_fiber_main(int arg1, int arg2)
{
ARG_UNUSED(arg1);
ARG_UNUSED(arg2);
while (1) {
struct sensor_work *work;
work = nano_fiber_fifo_get(&sensor_fifo, TICKS_UNLIMITED);
work->handler(work->arg);
}
}
static int sensor_init(struct device *dev)
{
ARG_UNUSED(dev);
nano_fifo_init(&sensor_fifo);
fiber_fiber_start(sensor_fiber_stack,
CONFIG_SENSOR_DELAYED_WORK_STACK_SIZE,
sensor_fiber_main, 0, 0,
CONFIG_SENSOR_DELAYED_WORK_PRIORITY, 0);
return DEV_OK;
}
SYS_INIT(sensor_init, PRIMARY, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);