From 40716ab51517f20a322433ac0c9c3f54d7acf2f5 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 17:53:30 +0100 Subject: [PATCH 1/9] Add generic header for CC2538 sensors --- cpu/cc2538/dev/cc2538-sensors.h | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 cpu/cc2538/dev/cc2538-sensors.h diff --git a/cpu/cc2538/dev/cc2538-sensors.h b/cpu/cc2538/dev/cc2538-sensors.h new file mode 100644 index 000000000..b4d3ada91 --- /dev/null +++ b/cpu/cc2538/dev/cc2538-sensors.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538 + * @{ + * + * \defgroup cc2538-sensors CC2538 Built-In Sensors + * + * Module controlling sensors on the CC2538 SoC (Tmp and VDD3) + * @{ + * + * \file + * Generic header usable by all CC2538 sensor drivers + */ +/*---------------------------------------------------------------------------*/ +#ifndef CC2538_SENSORS_H_ +#define CC2538_SENSORS_H_ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" +#include "dev/cc2538-temp-sensor.h" +#include "dev/vdd3-sensor.h" +/*---------------------------------------------------------------------------*/ +/** + * \name CC2538 sensor constants + * + * These constants are used by various sensors on the CC2538. They can be used + * to differentiate between raw and converted readings, to configure ADC + * decimation rate (where applicable). + * @{ + */ +#define CC2538_SENSORS_VALUE_TYPE_RAW 0 /**< Request the raw reading */ +#define CC2538_SENSORS_VALUE_TYPE_CONVERTED 1 /**< Request the converted reading */ + +#define CC2538_SENSORS_ERROR 0x80000000 /**< Generic Error */ +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* CC2538_SENSORS_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From f474514ee5342d6827688a6760266af6f140f2af Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 17:54:25 +0100 Subject: [PATCH 2/9] Add CC2538 tmp sensor driver --- cpu/cc2538/dev/temp-sensor.c | 78 ++++++++++++++++++++++++++++++++++++ cpu/cc2538/dev/temp-sensor.h | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 cpu/cc2538/dev/temp-sensor.c create mode 100644 cpu/cc2538/dev/temp-sensor.h diff --git a/cpu/cc2538/dev/temp-sensor.c b/cpu/cc2538/dev/temp-sensor.c new file mode 100644 index 000000000..abc52e42b --- /dev/null +++ b/cpu/cc2538/dev/temp-sensor.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538-temp-sensor + * @{ + * + * \file + * Driver for the CC2538 On-Chip temperature sensor + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/temp-sensor.h" +#include "dev/adc.h" +#include "dev/cc2538-sensors.h" + +#include +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + int raw = adc_get(SOC_ADC_ADCCON_CH_TEMP, SOC_ADC_ADCCON_REF_INT, + SOC_ADC_ADCCON_DIV_512); + + if(type == CC2538_SENSORS_VALUE_TYPE_RAW) { + return raw; + } else if(type == CC2538_SENSORS_VALUE_TYPE_CONVERTED) { + return 25000 + ((raw >> 4) - 1422) * 10000 / 42; + } + + return CC2538_SENSORS_ERROR; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int value) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(temp_sensor, TEMP_SENSOR, value, configure, status); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/cpu/cc2538/dev/temp-sensor.h b/cpu/cc2538/dev/temp-sensor.h new file mode 100644 index 000000000..7f20452db --- /dev/null +++ b/cpu/cc2538/dev/temp-sensor.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538-sensors + * @{ + * + * \defgroup cc2538-temp-sensor CC2538 on-chip temperature Sensor + * + * Driver for the CC2538 on-chip temperature sensor + * + * This driver can return the raw as well as the converted value of the sensor + * reading. This is controlled by the type argument of the sensor driver's + * value() function. The choices for the type argument are: + * - CC2538_SENSORS_VALUE_TYPE_RAW (value() returns the raw reading) + * - CC2538_SENSORS_VALUE_TYPE_CONVERTED (value() returns degrees mC) + * @{ + * + * \file + * Header file for the CC2538 on-chip temperature Sensor Driver + */ +/*---------------------------------------------------------------------------*/ +#ifndef TEMP_SENSOR_H_ +#define TEMP_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +/** + * \name temperature sensor + * @{ + */ +#define TEMP_SENSOR "On-Chip Temperature" +/** @} */ +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor temp_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* TEMP_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From 9cc800d72898b56d9aaf64e05a898cc9e34affa0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 17:54:44 +0100 Subject: [PATCH 3/9] Add CC2538 VDD sensor driver --- cpu/cc2538/dev/vdd3-sensor.c | 78 ++++++++++++++++++++++++++++++++++++ cpu/cc2538/dev/vdd3-sensor.h | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 cpu/cc2538/dev/vdd3-sensor.c create mode 100644 cpu/cc2538/dev/vdd3-sensor.h diff --git a/cpu/cc2538/dev/vdd3-sensor.c b/cpu/cc2538/dev/vdd3-sensor.c new file mode 100644 index 000000000..678c25b8e --- /dev/null +++ b/cpu/cc2538/dev/vdd3-sensor.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538-vdd3-sensor + * @{ + * + * \file + * Driver for the CC2538 VDD3 sensor + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/vdd3-sensor.h" +#include "dev/adc.h" +#include "dev/cc2538-sensors.h" + +#include +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + int raw = adc_get(SOC_ADC_ADCCON_CH_VDD_3, SOC_ADC_ADCCON_REF_INT, + SOC_ADC_ADCCON_DIV_512); + + if(type == CC2538_SENSORS_VALUE_TYPE_RAW) { + return raw; + } else if(type == CC2538_SENSORS_VALUE_TYPE_CONVERTED) { + return raw * (3 * 1190) / (2047 << 4); + } + + return CC2538_SENSORS_ERROR; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int value) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(vdd3_sensor, VDD3_SENSOR, value, configure, status); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/cpu/cc2538/dev/vdd3-sensor.h b/cpu/cc2538/dev/vdd3-sensor.h new file mode 100644 index 000000000..aa0fcf94c --- /dev/null +++ b/cpu/cc2538/dev/vdd3-sensor.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc2538-sensors + * @{ + * + * \defgroup cc2538-vdd3-sensor CC2538 VDD3 Sensor + * + * Driver for the CC2538 VDD3 sensor + * + * This driver can return the raw as well as the converted value of the sensor + * reading. This is controlled by the type argument of the sensor driver's + * value() function. The choices for the type argument are: + * - REMOTE_SENSORS_VALUE_TYPE_RAW (value() returns the raw reading) + * - REMOTE_SENSORS_VALUE_TYPE_CONVERTED (value() returns mV) + * @{ + * + * \file + * Header file for the CC2538 VDD3 Sensor Driver + */ +/*---------------------------------------------------------------------------*/ +#ifndef VDD3_SENSOR_H_ +#define VDD3_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +/** + * \name VDD3 sensors + * @{ + */ +#define VDD3_SENSOR "VDD3" +/** @} */ +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor vdd3_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* VDD3_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ From 06b0ee4a8b3fa3388d2fa82d646f97cdb3b5f7d2 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 17:54:56 +0100 Subject: [PATCH 4/9] Include CC2538 sensors in the build --- cpu/cc2538/Makefile.cc2538 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cc2538/Makefile.cc2538 b/cpu/cc2538/Makefile.cc2538 index 9fd8a08be..46160ebfd 100644 --- a/cpu/cc2538/Makefile.cc2538 +++ b/cpu/cc2538/Makefile.cc2538 @@ -52,7 +52,7 @@ CONTIKI_CPU_SOURCEFILES += nvic.c cpu.c sys-ctrl.c gpio.c ioc.c spi.c adc.c CONTIKI_CPU_SOURCEFILES += cc2538-rf.c udma.c lpm.c CONTIKI_CPU_SOURCEFILES += dbg.c ieee-addr.c CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c -CONTIKI_CPU_SOURCEFILES += i2c.c +CONTIKI_CPU_SOURCEFILES += i2c.c cc2538-temp-sensor.c vdd3-sensor.c DEBUG_IO_SOURCEFILES += dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c From 371752268051d6328626324fc021a440e572a55a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 18:06:05 +0100 Subject: [PATCH 5/9] Re-work the CC2538 driver to be a driver for the Srf06 ALS only --- .../{temp-sensor.c => cc2538-temp-sensor.c} | 3 +- .../{temp-sensor.h => cc2538-temp-sensor.h} | 8 ++--- .../dev/{adc-sensor.c => als-sensor.c} | 31 +++++-------------- .../dev/{adc-sensor.h => als-sensor.h} | 22 ++++++------- 4 files changed, 22 insertions(+), 42 deletions(-) rename cpu/cc2538/dev/{temp-sensor.c => cc2538-temp-sensor.c} (96%) rename cpu/cc2538/dev/{temp-sensor.h => cc2538-temp-sensor.h} (95%) rename platform/cc2538dk/dev/{adc-sensor.c => als-sensor.c} (82%) rename platform/cc2538dk/dev/{adc-sensor.h => als-sensor.h} (79%) diff --git a/cpu/cc2538/dev/temp-sensor.c b/cpu/cc2538/dev/cc2538-temp-sensor.c similarity index 96% rename from cpu/cc2538/dev/temp-sensor.c rename to cpu/cc2538/dev/cc2538-temp-sensor.c index abc52e42b..dd5dcba6c 100644 --- a/cpu/cc2538/dev/temp-sensor.c +++ b/cpu/cc2538/dev/cc2538-temp-sensor.c @@ -40,7 +40,6 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "lib/sensors.h" -#include "dev/temp-sensor.h" #include "dev/adc.h" #include "dev/cc2538-sensors.h" @@ -73,6 +72,6 @@ status(int type) return 1; } /*---------------------------------------------------------------------------*/ -SENSORS_SENSOR(temp_sensor, TEMP_SENSOR, value, configure, status); +SENSORS_SENSOR(cc2538_temp_sensor, TEMP_SENSOR, value, configure, status); /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/cpu/cc2538/dev/temp-sensor.h b/cpu/cc2538/dev/cc2538-temp-sensor.h similarity index 95% rename from cpu/cc2538/dev/temp-sensor.h rename to cpu/cc2538/dev/cc2538-temp-sensor.h index 7f20452db..b515c5042 100644 --- a/cpu/cc2538/dev/temp-sensor.h +++ b/cpu/cc2538/dev/cc2538-temp-sensor.h @@ -49,8 +49,8 @@ * Header file for the CC2538 on-chip temperature Sensor Driver */ /*---------------------------------------------------------------------------*/ -#ifndef TEMP_SENSOR_H_ -#define TEMP_SENSOR_H_ +#ifndef CC2538_TEMP_SENSOR_H_ +#define CC2538_TEMP_SENSOR_H_ /*---------------------------------------------------------------------------*/ #include "lib/sensors.h" /*---------------------------------------------------------------------------*/ @@ -61,9 +61,9 @@ #define TEMP_SENSOR "On-Chip Temperature" /** @} */ /*---------------------------------------------------------------------------*/ -extern const struct sensors_sensor temp_sensor; +extern const struct sensors_sensor cc2538_temp_sensor; /*---------------------------------------------------------------------------*/ -#endif /* TEMP_SENSOR_H_ */ +#endif /* CC2538_TEMP_SENSOR_H_ */ /*---------------------------------------------------------------------------*/ /** * @} diff --git a/platform/cc2538dk/dev/adc-sensor.c b/platform/cc2538dk/dev/als-sensor.c similarity index 82% rename from platform/cc2538dk/dev/adc-sensor.c rename to platform/cc2538dk/dev/als-sensor.c index 4c2f1f853..3630ac80e 100644 --- a/platform/cc2538dk/dev/adc-sensor.c +++ b/platform/cc2538dk/dev/als-sensor.c @@ -30,18 +30,18 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ /** - * \addtogroup cc2538dk-adc-sensor + * \addtogroup cc2538dk-als-sensor * @{ * * \file - * Driver for the SmartRF06EB ADC + * Driver for the SmartRF06EB ALS */ #include "contiki.h" #include "sys/clock.h" #include "dev/ioc.h" #include "dev/gpio.h" #include "dev/adc.h" -#include "dev/adc-sensor.h" +#include "dev/als-sensor.h" #include @@ -52,30 +52,15 @@ static int value(int type) { - uint8_t channel; + uint8_t channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_ALS_OUT_PIN; int16_t res; - switch(type) { - case ADC_SENSOR_VDD_3: - channel = SOC_ADC_ADCCON_CH_VDD_3; - break; - case ADC_SENSOR_TEMP: - channel = SOC_ADC_ADCCON_CH_TEMP; - break; - case ADC_SENSOR_ALS: - channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_ALS_OUT_PIN; - GPIO_SET_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); - clock_delay_usec(2000); - break; - default: - return 0; - } + GPIO_SET_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); + clock_delay_usec(2000); res = adc_get(channel, SOC_ADC_ADCCON_REF_INT, SOC_ADC_ADCCON_DIV_512); - if(type == ADC_SENSOR_ALS) { - GPIO_CLR_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); - } + GPIO_CLR_PIN(ADC_ALS_PWR_PORT_BASE, ADC_ALS_PWR_PIN_MASK); return res; } @@ -106,6 +91,6 @@ status(int type) return 1; } /*---------------------------------------------------------------------------*/ -SENSORS_SENSOR(adc_sensor, ADC_SENSOR, value, configure, status); +SENSORS_SENSOR(als_sensor, ALS_SENSOR, value, configure, status); /** @} */ diff --git a/platform/cc2538dk/dev/adc-sensor.h b/platform/cc2538dk/dev/als-sensor.h similarity index 79% rename from platform/cc2538dk/dev/adc-sensor.h rename to platform/cc2538dk/dev/als-sensor.h index b6d0efbdf..abed92e13 100644 --- a/platform/cc2538dk/dev/adc-sensor.h +++ b/platform/cc2538dk/dev/als-sensor.h @@ -33,33 +33,29 @@ * \addtogroup cc2538-smartrf-sensors * @{ * - * \defgroup cc2538dk-adc-sensor cc2538dk ADC Driver + * \defgroup cc2538dk-als-sensor cc2538dk ALS Driver * - * Driver for the SmartRF06EB ADC sensors + * Driver for the SmartRF06EB ALS sensor * @{ * * \file - * Header file for the cc2538dk ADC Driver + * Header file for the cc2538dk ALS Driver */ -#ifndef ADC_SENSOR_H_ -#define ADC_SENSOR_H_ +#ifndef ALS_SENSOR_H_ +#define ALS_SENSOR_H_ #include "lib/sensors.h" /*---------------------------------------------------------------------------*/ -/** \name ADC sensors +/** \name ALS sensor * @{ */ -#define ADC_SENSOR "ADC" - -#define ADC_SENSOR_VDD_3 0 /**< On-chip VDD / 3 */ -#define ADC_SENSOR_TEMP 1 /**< On-chip temperature */ -#define ADC_SENSOR_ALS 2 /**< Ambient light sensor */ +#define ALS_SENSOR "ALS" /** @} */ -extern const struct sensors_sensor adc_sensor; +extern const struct sensors_sensor als_sensor; -#endif /* ADC_SENSOR_H_ */ +#endif /* ALS_SENSOR_H_ */ /** * @} From 12ac8e1fb58146876a69c042cc7cf13e270ab146 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 18:06:20 +0100 Subject: [PATCH 6/9] Initialise ADC in main, not in sensor drivers --- platform/cc2538dk/contiki-main.c | 3 +++ platform/cc2538dk/dev/als-sensor.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/cc2538dk/contiki-main.c b/platform/cc2538dk/contiki-main.c index 4487a07f2..71de03a10 100644 --- a/platform/cc2538dk/contiki-main.c +++ b/platform/cc2538dk/contiki-main.c @@ -43,6 +43,7 @@ */ /*---------------------------------------------------------------------------*/ #include "contiki.h" +#include "dev/adc.h" #include "dev/leds.h" #include "dev/sys-ctrl.h" #include "dev/scb.h" @@ -208,6 +209,8 @@ main(void) process_start(&tcpip_process, NULL); #endif /* NETSTACK_CONF_WITH_IPV6 */ + adc_init(); + process_start(&sensors_process, NULL); energest_init(); diff --git a/platform/cc2538dk/dev/als-sensor.c b/platform/cc2538dk/dev/als-sensor.c index 3630ac80e..2ecc857ea 100644 --- a/platform/cc2538dk/dev/als-sensor.c +++ b/platform/cc2538dk/dev/als-sensor.c @@ -79,7 +79,6 @@ configure(int type, int value) GPIO_SET_INPUT(GPIO_A_BASE, ADC_ALS_OUT_PIN_MASK); ioc_set_over(GPIO_A_NUM, ADC_ALS_OUT_PIN, IOC_OVERRIDE_ANA); - adc_init(); break; } return 0; From 4de471478a7cb3c237450b646c00d367b0b7d5ac Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 18:06:54 +0100 Subject: [PATCH 7/9] Link and build tmp, vdd and als sensors --- platform/cc2538dk/Makefile.cc2538dk | 2 +- platform/cc2538dk/dev/smartrf-sensors.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/cc2538dk/Makefile.cc2538dk b/platform/cc2538dk/Makefile.cc2538dk index a760ee5a1..8599022b1 100644 --- a/platform/cc2538dk/Makefile.cc2538dk +++ b/platform/cc2538dk/Makefile.cc2538dk @@ -9,7 +9,7 @@ CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c CONTIKI_TARGET_SOURCEFILES += contiki-main.c CONTIKI_TARGET_SOURCEFILES += sensors.c smartrf-sensors.c -CONTIKI_TARGET_SOURCEFILES += button-sensor.c adc-sensor.c +CONTIKI_TARGET_SOURCEFILES += button-sensor.c als-sensor.c TARGET_START_SOURCEFILES += startup-gcc.c TARGET_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(TARGET_START_SOURCEFILES)}} diff --git a/platform/cc2538dk/dev/smartrf-sensors.c b/platform/cc2538dk/dev/smartrf-sensors.c index 41d977783..76841af3b 100644 --- a/platform/cc2538dk/dev/smartrf-sensors.c +++ b/platform/cc2538dk/dev/smartrf-sensors.c @@ -42,13 +42,15 @@ */ #include "contiki.h" #include "dev/button-sensor.h" -#include "dev/adc-sensor.h" +#include "dev/als-sensor.h" +#include "dev/cc2538-sensors.h" #include /** \brief Exports a global symbol to be used by the sensor API */ SENSORS(&button_select_sensor, &button_left_sensor, &button_right_sensor, - &button_up_sensor, &button_down_sensor, &adc_sensor); + &button_up_sensor, &button_down_sensor, &als_sensor, + &cc2538_temp_sensor, &vdd3_sensor); /** * @} From ac459df128cd80b58bb9891d6e62768125aa0a51 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 11 Feb 2015 18:14:01 +0100 Subject: [PATCH 8/9] Re-work the CC2538 demo to use the 3 separate ADC sensors --- examples/cc2538dk/cc2538-demo.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/cc2538dk/cc2538-demo.c b/examples/cc2538dk/cc2538-demo.c index 9210968c2..e50dd3937 100644 --- a/examples/cc2538dk/cc2538-demo.c +++ b/examples/cc2538dk/cc2538-demo.c @@ -69,8 +69,9 @@ #include "sys/rtimer.h" #include "dev/leds.h" #include "dev/uart.h" +#include "dev/cc2538-sensors.h" #include "dev/button-sensor.h" -#include "dev/adc-sensor.h" +#include "dev/als-sensor.h" #include "dev/watchdog.h" #include "dev/serial-line.h" #include "dev/sys-ctrl.h" @@ -114,8 +115,6 @@ rt_callback(struct rtimer *t, void *ptr) /*---------------------------------------------------------------------------*/ PROCESS_THREAD(cc2538_demo_process, ev, data) { - int16_t value; - PROCESS_EXITHANDLER(broadcast_close(&bc)) PROCESS_BEGIN(); @@ -134,15 +133,13 @@ PROCESS_THREAD(cc2538_demo_process, ev, data) printf("-----------------------------------------\n" "Counter = 0x%08x\n", counter); - value = adc_sensor.value(ADC_SENSOR_VDD_3); - printf("VDD = %d mV\n", value * (3 * 1190) / (2047 << 4)); + printf("VDD = %d mV\n", + vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED)); - value = adc_sensor.value(ADC_SENSOR_TEMP); printf("Temperature = %d mC\n", - 25000 + ((value >> 4) - 1422) * 10000 / 42); + cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED)); - value = adc_sensor.value(ADC_SENSOR_ALS); - printf("Ambient light sensor = %d raw\n", value); + printf("Ambient light sensor = %d raw\n", als_sensor.value(0)); etimer_set(&et, CLOCK_SECOND); rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1, From 49d1782a0643341a2caf2832ba0a2dd38d50b826 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Wed, 18 Feb 2015 09:25:07 +0100 Subject: [PATCH 9/9] Adjust the MQTT demo to use re-engineered sensors --- examples/cc2538dk/mqtt-demo/mqtt-demo.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/cc2538dk/mqtt-demo/mqtt-demo.c b/examples/cc2538dk/mqtt-demo/mqtt-demo.c index 398feec68..691d4deed 100644 --- a/examples/cc2538dk/mqtt-demo/mqtt-demo.c +++ b/examples/cc2538dk/mqtt-demo/mqtt-demo.c @@ -53,7 +53,7 @@ #include "lib/sensors.h" #include "dev/button-sensor.h" #include "dev/leds.h" -#include "dev/adc-sensor.h" +#include "dev/cc2538-sensors.h" #include /*---------------------------------------------------------------------------*/ @@ -450,7 +450,6 @@ publish(void) /* Publish MQTT topic in IBM quickstart format */ int len; int remaining = APP_BUFFER_SIZE; - int16_t value; seq_nr_value++; @@ -487,9 +486,8 @@ publish(void) remaining -= len; buf_ptr += len; - value = adc_sensor.value(ADC_SENSOR_TEMP); len = snprintf(buf_ptr, remaining, ",\"On-Chip Temp (mC)\":%d", - 25000 + ((value >> 4) - 1422) * 10000 / 42); + cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED)); if(len < 0 || len >= remaining) { printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len); @@ -498,9 +496,8 @@ publish(void) remaining -= len; buf_ptr += len; - value = adc_sensor.value(ADC_SENSOR_VDD_3); len = snprintf(buf_ptr, remaining, ",\"VDD3 (mV)\":%d", - value * (3 * 1190) / (2047 << 4)); + vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED)); if(len < 0 || len >= remaining) { printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);