From 1d3c37d6da6af000088a4373d1e1fa3da201792b Mon Sep 17 00:00:00 2001 From: Pere Tuset Date: Thu, 11 Feb 2016 01:34:08 +0100 Subject: [PATCH 1/2] Add OpenMote-CC2538 platform and examples. --- examples/openmote-cc2538/Makefile | 9 + examples/openmote-cc2538/openmote-demo.c | 152 +++++ examples/openmote-cc2538/project-conf.h | 46 ++ examples/openmote-cc2538/test-adxl346.c | 86 +++ examples/openmote-cc2538/test-max44009.c | 86 +++ examples/openmote-cc2538/test-sht21.c | 92 +++ examples/openmote-cc2538/test-timer.c | 188 ++++++ .../openmote-cc2538/Makefile.openmote-cc2538 | 50 ++ platform/openmote-cc2538/README.md | 0 platform/openmote-cc2538/board.c | 61 ++ platform/openmote-cc2538/board.h | 166 ++++++ platform/openmote-cc2538/contiki-conf.h | 536 ++++++++++++++++++ platform/openmote-cc2538/contiki-main.c | 248 ++++++++ platform/openmote-cc2538/dev/adxl346.c | 252 ++++++++ platform/openmote-cc2538/dev/adxl346.h | 57 ++ platform/openmote-cc2538/dev/antenna.c | 99 ++++ platform/openmote-cc2538/dev/antenna.h | 50 ++ platform/openmote-cc2538/dev/button-sensor.c | 136 +++++ platform/openmote-cc2538/dev/button-sensor.h | 59 ++ platform/openmote-cc2538/dev/leds-arch.c | 69 +++ platform/openmote-cc2538/dev/max44009.c | 197 +++++++ platform/openmote-cc2538/dev/max44009.h | 56 ++ platform/openmote-cc2538/dev/sht21.c | 208 +++++++ platform/openmote-cc2538/dev/sht21.h | 58 ++ .../openmote-cc2538/dev/smartrf-sensors.c | 53 ++ platform/openmote-cc2538/dev/tps62730.c | 98 ++++ platform/openmote-cc2538/dev/tps62730.h | 54 ++ 27 files changed, 3166 insertions(+) create mode 100644 examples/openmote-cc2538/Makefile create mode 100644 examples/openmote-cc2538/openmote-demo.c create mode 100644 examples/openmote-cc2538/project-conf.h create mode 100644 examples/openmote-cc2538/test-adxl346.c create mode 100644 examples/openmote-cc2538/test-max44009.c create mode 100644 examples/openmote-cc2538/test-sht21.c create mode 100644 examples/openmote-cc2538/test-timer.c create mode 100644 platform/openmote-cc2538/Makefile.openmote-cc2538 create mode 100644 platform/openmote-cc2538/README.md create mode 100644 platform/openmote-cc2538/board.c create mode 100644 platform/openmote-cc2538/board.h create mode 100644 platform/openmote-cc2538/contiki-conf.h create mode 100644 platform/openmote-cc2538/contiki-main.c create mode 100644 platform/openmote-cc2538/dev/adxl346.c create mode 100644 platform/openmote-cc2538/dev/adxl346.h create mode 100644 platform/openmote-cc2538/dev/antenna.c create mode 100644 platform/openmote-cc2538/dev/antenna.h create mode 100644 platform/openmote-cc2538/dev/button-sensor.c create mode 100644 platform/openmote-cc2538/dev/button-sensor.h create mode 100644 platform/openmote-cc2538/dev/leds-arch.c create mode 100644 platform/openmote-cc2538/dev/max44009.c create mode 100644 platform/openmote-cc2538/dev/max44009.h create mode 100644 platform/openmote-cc2538/dev/sht21.c create mode 100644 platform/openmote-cc2538/dev/sht21.h create mode 100644 platform/openmote-cc2538/dev/smartrf-sensors.c create mode 100644 platform/openmote-cc2538/dev/tps62730.c create mode 100644 platform/openmote-cc2538/dev/tps62730.h diff --git a/examples/openmote-cc2538/Makefile b/examples/openmote-cc2538/Makefile new file mode 100644 index 000000000..9f925fb70 --- /dev/null +++ b/examples/openmote-cc2538/Makefile @@ -0,0 +1,9 @@ +DEFINES+=PROJECT_CONF_H=\"project-conf.h\" + +CONTIKI_PROJECT = openmote-demo test-timer test-adxl346 test-max44009 test-sht21 + +all: $(CONTIKI_PROJECT) + +CONTIKI = ../.. +CONTIKI_WITH_RIME = 1 +include $(CONTIKI)/Makefile.include diff --git a/examples/openmote-cc2538/openmote-demo.c b/examples/openmote-cc2538/openmote-demo.c new file mode 100644 index 000000000..10a1c0762 --- /dev/null +++ b/examples/openmote-cc2538/openmote-demo.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup openmote-cc2538 + * @{ + * + * \defgroup openmote-examples OpenMote-CC2538 Example Projects + * @{ + * + * \defgroup openmote-demo OpenMote-CC2538 Demo Project + * + * Example project demonstrating the OpenMote-CC2538 functionality + * + * This assumes that you are using an OpenMote-CC2538 + * + * - Boot sequence: LEDs flashing, LED2 followed by LED3 then LED4 + * - etimer/clock : Every LOOP_INTERVAL clock ticks the LED defined as + * LEDS_PERIODIC will turn on + * - rtimer : Exactly LEDS_OFF_HYSTERISIS rtimer ticks later, + * LEDS_PERIODIC will turn back off + * - UART : Every LOOP_INTERVAL the EM will print something over the + * UART. Receiving an entire line of text over UART (ending + * in \\r) will cause LEDS_SERIAL_IN to toggle + * - Radio comms : BTN_SELECT sends a rime broadcast. Reception of a rime + * packet will toggle LEDs defined as LEDS_RF_RX + * + * @{ + * + * \file + * Example demonstrating the OpenMote platform. + * \author + * Pere Tuset + */ +#include "contiki.h" +#include "cpu.h" +#include "sys/etimer.h" +#include "sys/rtimer.h" +#include "dev/leds.h" +#include "dev/uart.h" +#include "dev/button-sensor.h" +#include "dev/watchdog.h" +#include "dev/serial-line.h" +#include "dev/sys-ctrl.h" +#include "net/rime/broadcast.h" + +#include +#include +/*---------------------------------------------------------------------------*/ +#define LOOP_INTERVAL CLOCK_SECOND +#define LEDS_OFF_HYSTERISIS (RTIMER_SECOND >> 1) +#define LEDS_PERIODIC LEDS_YELLOW +#define LEDS_BUTTON LEDS_RED +#define LEDS_SERIAL_IN LEDS_ORANGE +#define LEDS_REBOOT LEDS_ALL +#define LEDS_RF_RX (LEDS_YELLOW | LEDS_ORANGE) +#define BROADCAST_CHANNEL 129 +/*---------------------------------------------------------------------------*/ +static struct etimer et; +static struct rtimer rt; +static uint16_t counter; +/*---------------------------------------------------------------------------*/ +PROCESS(openmote_demo_process, "OpenMote-CC2538 demo process"); +AUTOSTART_PROCESSES(&openmote_demo_process); +/*---------------------------------------------------------------------------*/ +static void +broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) +{ + leds_toggle(LEDS_RF_RX); + printf("Received %u bytes: '0x%04x'\n", packetbuf_datalen(), + *(uint16_t *)packetbuf_dataptr()); +} +/*---------------------------------------------------------------------------*/ +static const struct broadcast_callbacks bc_rx = { broadcast_recv }; +static struct broadcast_conn bc; +/*---------------------------------------------------------------------------*/ +void +rt_callback(struct rtimer *t, void *ptr) +{ + leds_off(LEDS_PERIODIC); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(openmote_demo_process, ev, data) +{ + + PROCESS_EXITHANDLER(broadcast_close(&bc)) + + PROCESS_BEGIN(); + + counter = 0; + broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx); + + while(1) { + etimer_set(&et, CLOCK_SECOND); + + PROCESS_YIELD(); + + if(ev == PROCESS_EVENT_TIMER) { + leds_on(LEDS_PERIODIC); + printf("Counter = 0x%08x\n", counter); + + etimer_set(&et, CLOCK_SECOND); + rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1, + rt_callback, NULL); + } else if(ev == sensors_event) { + if(data == &button_user_sensor) { + packetbuf_copyfrom(&counter, sizeof(counter)); + broadcast_send(&bc); + } + } else if(ev == serial_line_event_message) { + leds_toggle(LEDS_SERIAL_IN); + } + counter++; + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + * @} + */ diff --git a/examples/openmote-cc2538/project-conf.h b/examples/openmote-cc2538/project-conf.h new file mode 100644 index 000000000..126ea1058 --- /dev/null +++ b/examples/openmote-cc2538/project-conf.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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 remote-examples + * @{ + * + * \file + * Project specific configuration defines for the basic RE-Mote examples + */ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#define BROADCAST_CHANNEL 129 +#define NETSTACK_CONF_RDC nullrdc_driver + +#endif /* PROJECT_CONF_H_ */ + +/** @} */ diff --git a/examples/openmote-cc2538/test-adxl346.c b/examples/openmote-cc2538/test-adxl346.c new file mode 100644 index 000000000..1a750a67c --- /dev/null +++ b/examples/openmote-cc2538/test-adxl346.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup openmote-examples + * @{ + * + * \defgroup openmote-adxl346 + * + * This example tests the correct functionality of the ADXL346 acceleration + * sensor using the I2C bus. + * + * @{ + * + * \file + * Testing the ADXL346 sensor on the OpenMote-CC2538 platform. + * \author + * Pere Tuset + */ + +#include "contiki.h" +#include "dev/adxl346.h" + +#include + +PROCESS(test_adxl346_process, "ADXL346 test"); +AUTOSTART_PROCESSES(&test_adxl346_process); + +PROCESS_THREAD(test_adxl346_process, ev, data) +{ + static struct etimer et; + static unsigned acceleration; + + PROCESS_BEGIN(); + adxl346_init(); + + if (!adxl346_is_present()) { + leds_on(LEDS_ORANGE); + } + + while(1) { + etimer_set(&et, CLOCK_SECOND); + + PROCESS_YIELD(); + + if (ev == PROCESS_EVENT_TIMER) { + acceleration = adxl346_read_x(); + printf("X Acceleration: %u\n", acceleration); + acceleration = adxl346_read_y(); + printf("Y Acceleration: %u\n", acceleration); + acceleration = adxl346_read_z(); + printf("Z Acceleration: %u\n", acceleration); + } + } + + PROCESS_END(); +} diff --git a/examples/openmote-cc2538/test-max44009.c b/examples/openmote-cc2538/test-max44009.c new file mode 100644 index 000000000..8085283ca --- /dev/null +++ b/examples/openmote-cc2538/test-max44009.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup openmote-examples + * @{ + * + * \defgroup openmote-max44009 + * + * This example tests the correct functionality of the MAX44009 light + * sensor using the I2C bus. + * + * @{ + * + * \file + * Testing the MAX44009 sensor on the OpenMote-CC2538 platform. + * \author + * Pere Tuset + */ + +#include "contiki.h" +#include "dev/max44009.h" +#include "dev/leds.h" +#include + +PROCESS(test_max44009_process, "MAX44009 test"); +AUTOSTART_PROCESSES(&test_max44009_process); + +PROCESS_THREAD(test_max44009_process, ev, data) +{ + static struct etimer et; + static unsigned raw; + static float light; + + PROCESS_BEGIN(); + max44009_init(); + +if (!max44009_is_present()) { + leds_on(LEDS_ORANGE); + } + + while(1) { + etimer_set(&et, CLOCK_SECOND); + + PROCESS_YIELD(); + + if (ev == PROCESS_EVENT_TIMER) { + leds_on(LEDS_YELLOW); + raw = max44009_read_light(); + light = max44009_convert_light(raw); + printf("Light: %u.%u\n", (unsigned int) light, (unsigned int) (light * 100) % 100); + leds_off(LEDS_YELLOW); + } + } + + PROCESS_END(); +} diff --git a/examples/openmote-cc2538/test-sht21.c b/examples/openmote-cc2538/test-sht21.c new file mode 100644 index 000000000..cefdb3266 --- /dev/null +++ b/examples/openmote-cc2538/test-sht21.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup openmote-examples + * @{ + * + * \defgroup openmote-sht21 + * + * This example tests the correct functionality of the SHT21 temperature + * and humidity sensor using the I2C bus. + * + * @{ + * + * \file + * Testing the SHT21 sensor on the OpenMote-CC2538 platform. + * \author + * Pere Tuset + */ + +#include "contiki.h" +#include "dev/sht21.h" +#include "dev/leds.h" +#include "sys/etimer.h" + +#include + +PROCESS(test_sht21_process, "SHT21 test"); +AUTOSTART_PROCESSES(&test_sht21_process); + +PROCESS_THREAD(test_sht21_process, ev, data) +{ + static struct etimer et; + static unsigned raw; + static float temperature; + static float humidity; + + PROCESS_BEGIN(); + sht21_init(); + + if (!sht21_is_present()) { + leds_on(LEDS_ORANGE); + } + + while(1) { + etimer_set(&et, CLOCK_SECOND); + + PROCESS_YIELD(); + + if (ev == PROCESS_EVENT_TIMER) { + leds_on(LEDS_YELLOW); + raw = sht21_read_temperature(); + temperature = sht21_convert_temperature(raw); + printf("Temperature: %u.%u degrees Celsius\n", (unsigned int) temperature, (unsigned int) (temperature * 100) % 100); + raw = sht21_read_humidity(); + humidity = sht21_convert_humidity(raw); + printf("Rel. humidity: %u.%u%%\n", (unsigned int) humidity, (unsigned int) (humidity * 100) % 100); + leds_off(LEDS_YELLOW ); + } + } + + PROCESS_END(); +} diff --git a/examples/openmote-cc2538/test-timer.c b/examples/openmote-cc2538/test-timer.c new file mode 100644 index 000000000..3eb8ff2ff --- /dev/null +++ b/examples/openmote-cc2538/test-timer.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup openmote-examples + * @{ + * + * \defgroup openmote-timers OpenMote-CC2538 Timer Test Project + * + * This example tests the correct functionality of clocks and timers. + * + * More specifically, it tests clock_seconds, rtimers, etimers and + * clock_delay_usec. + * + * This is largely-based on the same example of the cc2530 port. + * @{ + * + * \file + * Tests related to clocks and timers. + * \author + * Pere Tuset + */ + +#include "contiki.h" +#include "sys/clock.h" +#include "sys/rtimer.h" +#include "dev/leds.h" + +#include +/*---------------------------------------------------------------------------*/ +#define TIMER_TEST_CONF_TEST_CLOCK_DELAY_USEC 1 +#define TIMER_TEST_CONF_TEST_RTIMER 1 +#define TIMER_TEST_CONF_TEST_ETIMER 1 +#define TIMER_TEST_CONF_TEST_CLOCK_SECONDS 1 +/*---------------------------------------------------------------------------*/ +static struct etimer et; + +#if TIMER_TEST_CONF_TEST_CLOCK_DELAY_USEC +static rtimer_clock_t start_count, end_count, diff; +#endif + +#if TIMER_TEST_CONF_TEST_CLOCK_SECONDS +static unsigned long sec; +#endif + +#if TIMER_TEST_CONF_TEST_ETIMER +static clock_time_t count; +#endif + +#if TIMER_TEST_CONF_TEST_RTIMER +static struct rtimer rt; +rtimer_clock_t rt_now, rt_for; +static clock_time_t ct; +#endif + +static uint8_t i; +/*---------------------------------------------------------------------------*/ +PROCESS(timer_test_process, "Timer test process"); +AUTOSTART_PROCESSES(&timer_test_process); +/*---------------------------------------------------------------------------*/ +#if TIMER_TEST_CONF_TEST_RTIMER +void +rt_callback(struct rtimer *t, void *ptr) +{ + rt_now = RTIMER_NOW(); + ct = clock_time(); + printf("Task called at %lu (clock = %lu)\n", rt_now, ct); +} +#endif +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(timer_test_process, ev, data) +{ + + PROCESS_BEGIN(); + + etimer_set(&et, 2 * CLOCK_SECOND); + + PROCESS_YIELD(); + +#if TIMER_TEST_CONF_TEST_CLOCK_DELAY_USEC + printf("-----------------------------------------\n"); + printf("clock_delay_usec test, (10,000 x i) usec:\n"); + printf("N.B. clock_delay_usec is more accurate than rtimers\n"); + i = 1; + while(i < 7) { + start_count = RTIMER_NOW(); + clock_delay_usec(10000 * i); + end_count = RTIMER_NOW(); + diff = end_count - start_count; + printf("Requested: %u usec, Real: %lu rtimer ticks = ~%lu us\n", + 10000 * i, diff, diff * 1000000 / RTIMER_SECOND); + i++; + } +#endif + +#if TIMER_TEST_CONF_TEST_RTIMER + printf("-----------------------------------------\n"); + printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND); + i = 0; + while(i < 5) { + etimer_set(&et, 2 * CLOCK_SECOND); + printf("=======================\n"); + ct = clock_time(); + rt_now = RTIMER_NOW(); + rt_for = rt_now + RTIMER_SECOND; + printf("Now=%lu (clock = %lu) - For=%lu\n", rt_now, ct, rt_for); + if(rtimer_set(&rt, rt_for, 1, rt_callback, NULL) != RTIMER_OK) { + printf("Error setting\n"); + } + + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + i++; + } +#endif + +#if TIMER_TEST_CONF_TEST_ETIMER + printf("-----------------------------------------\n"); + printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", + CLOCK_SECOND); + i = 0; + while(i < 10) { + etimer_set(&et, CLOCK_SECOND); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + + count = clock_time(); + printf("%lu ticks\n", count); + + leds_toggle(LEDS_RED); + i++; + } +#endif + +#if TIMER_TEST_CONF_TEST_CLOCK_SECONDS + printf("-----------------------------------------\n"); + printf("Clock seconds test (5s):\n"); + i = 0; + while(i < 10) { + etimer_set(&et, 5 * CLOCK_SECOND); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + + sec = clock_seconds(); + printf("%lu seconds\n", sec); + + leds_toggle(LEDS_GREEN); + i++; + } +#endif + + printf("Done!\n"); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/Makefile.openmote-cc2538 b/platform/openmote-cc2538/Makefile.openmote-cc2538 new file mode 100644 index 000000000..878b81877 --- /dev/null +++ b/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -0,0 +1,50 @@ +# openmote-cc2538 platform makefile + +ifndef CONTIKI + $(error CONTIKI not defined! You must specify where CONTIKI resides!) +endif + +### Configure the build for the board and pull in board-specific sources +CONTIKI_TARGET_DIRS += . dev +PLATFORM_ROOT_DIR = $(CONTIKI)/platform/$(TARGET) + +### Include +CONTIKI_TARGET_SOURCEFILES += contiki-main.c board.c +CONTIKI_TARGET_SOURCEFILES += leds-arch.c button-sensor.c smartrf-sensors.c +CONTIKI_TARGET_SOURCEFILES += antenna.c adxl346.c max44009.c sht21.c tps62730.c + +CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) + +CLEAN += *.openmote-cc2538 + +### Unless the example dictates otherwise, build with code size optimisations +ifndef SMALL + SMALL = 1 +endif + +### Define the CPU directory +CONTIKI_CPU=$(CONTIKI)/cpu/cc2538 +include $(CONTIKI_CPU)/Makefile.cc2538 + +MODULES += core/net core/net/mac \ + core/net/mac/contikimac \ + core/net/llsec core/net/llsec/noncoresec + +PYTHON = python +BSL_FLAGS += -e -w --bootloader-invert-lines -b 115200 -v + +ifdef PORT + BSL_FLAGS += -p $(PORT) +endif + +BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py + +%.upload: %.bin %.elf +ifeq ($(wildcard $(BSL)), ) + @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" +else + $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h $*.elf | grep -B1 LOAD | \ + grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$5}' | \ + sort -g | head -1)) + $(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $< +endif diff --git a/platform/openmote-cc2538/README.md b/platform/openmote-cc2538/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/platform/openmote-cc2538/board.c b/platform/openmote-cc2538/board.c new file mode 100644 index 000000000..0b565b43c --- /dev/null +++ b/platform/openmote-cc2538/board.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * 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 openmote-cc2538 + * @{ + * + * \file + * Board-initialisation for the OpenMote-CC2538 platform + * + */ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +#include "dev/antenna.h" +#include +#include +/*---------------------------------------------------------------------------*/ +static void +configure_unused_pins(void) +{ + /* FIXME */ +} +/*---------------------------------------------------------------------------*/ +void +board_init() +{ + antenna_init(); + configure_unused_pins(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + */ + diff --git a/platform/openmote-cc2538/board.h b/platform/openmote-cc2538/board.h new file mode 100644 index 000000000..08538a995 --- /dev/null +++ b/platform/openmote-cc2538/board.h @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Header file with definitions related to the I/O connections on the + * OpenMote-CC2538 platform. This file provides connectivity information on + * LEDs, Buttons, UART and other peripherals. + * + * \note + * Do not include this file directly. It gets included by contiki-conf + * after all relevant directives have been set. + */ + +#ifndef BOARD_H_ +#define BOARD_H_ +/*---------------------------------------------------------------------------*/ +#include "dev/gpio.h" +#include "dev/nvic.h" +/*---------------------------------------------------------------------------*/ +/** \name OpenMote-CC2538 LED configuration + * + * LEDs on the OpenMote-CC2538 are connected as follows: + * - LED1 (Red) -> PC4 + * - LED2 (Yellow) -> PC6 + * - LED3 (Green) -> PC7 + * - LED4 (Orange) -> PC5 + * + * @{ + */ +/*---------------------------------------------------------------------------*/ +/* Some files include leds.h before us, so we need to get rid of defaults in + * leds.h before we provide correct definitions */ +#undef LEDS_GREEN +#undef LEDS_YELLOW +#undef LEDS_RED +#undef LEDS_CONF_ALL + +#define LEDS_RED 16 /**< LED1 (Red) -> PC4 */ +#define LEDS_YELLOW 64 /**< LED2 (Yellow) -> PC6 */ +#define LEDS_GREEN 128 /**< LED3 (Green) -> PC7 */ +#define LEDS_ORANGE 32 /**< LED4 (Orange) -> PC5 */ +#define LEDS_CONF_ALL 240 + +/* Notify various examples that we have LEDs */ +#define PLATFORM_HAS_LEDS 1 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name USB configuration + * + * The USB pullup is driven by PC0 + */ +#define USB_PULLUP_PORT GPIO_C_NUM +#define USB_PULLUP_PIN 0 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name UART configuration + * + * On the OpenMote, the UART is connected to the + * following ports/pins + * - RX: PA0 + * - TX: PA1 + * - CTS: PB0 (Can only be used with UART1) + * - RTS: PD3 (Can only be used with UART1) + * + * We configure the port to use UART0. To use UART1, replace UART0_* with + * UART1_* below. + * @{ + */ +#define UART0_RX_PORT GPIO_A_NUM +#define UART0_RX_PIN 0 + +#define UART0_TX_PORT GPIO_A_NUM +#define UART0_TX_PIN 1 + +#define UART1_CTS_PORT GPIO_B_NUM +#define UART1_CTS_PIN 0 + +#define UART1_RTS_PORT GPIO_D_NUM +#define UART1_RTS_PIN 3 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name OpenMote-CC2538 Button configuration + * + * Buttons on the OpenMote-CC2538 are connected as follows: + * - BUTTON_USER -> PC3 + * @{ + */ +/** BUTTON_USER -> PC3 */ +#define BUTTON_USER_PORT GPIO_C_NUM +#define BUTTON_USER_PIN 3 +#define BUTTON_USER_VECTOR NVIC_INT_GPIO_PORT_C +/* Notify various examples that we have Buttons */ +#define PLATFORM_HAS_BUTTON 1 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SPI configuration + * + * These values configure which CC2538 pins to use for the SPI lines. + * @{ + */ +#define SPI_CLK_PORT GPIO_A_NUM +#define SPI_CLK_PIN 2 +#define SPI_MOSI_PORT GPIO_A_NUM +#define SPI_MOSI_PIN 5 +#define SPI_MISO_PORT GPIO_A_NUM +#define SPI_MISO_PIN 4 +#define SPI_SEL_PORT GPIO_A_NUM +#define SPI_SEL_PIN 3 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name I2C configuration + * + * These values configure which CC2538 pins to use for the I2C lines. + * @{ + */ +#define I2C_SCL_PORT GPIO_B_NUM +#define I2C_SCL_PIN 3 +#define I2C_SDA_PORT GPIO_B_NUM +#define I2C_SDA_PIN 4 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Device string used on startup + * @{ + */ +#define BOARD_STRING "OpenMote-CC2538" +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_H_ */ +/** @} */ diff --git a/platform/openmote-cc2538/contiki-conf.h b/platform/openmote-cc2538/contiki-conf.h new file mode 100644 index 000000000..44a15e539 --- /dev/null +++ b/platform/openmote-cc2538/contiki-conf.h @@ -0,0 +1,536 @@ +/** + * \addtogroup openmote + * @{ + * + * \file + * Configuration for the OpenMote-CC2538 platform. + */ +#ifndef CONTIKI_CONF_H_ +#define CONTIKI_CONF_H_ + +#include +#include +/*---------------------------------------------------------------------------*/ +/* Include Project Specific conf */ +#ifdef PROJECT_CONF_H +#include PROJECT_CONF_H +#endif /* PROJECT_CONF_H */ +/*---------------------------------------------------------------------------*/ +/** + * \name Compiler configuration and platform-specific type definitions + * + * Those values are not meant to be modified by the user + * @{ + */ +#define CLOCK_CONF_SECOND 128 + +/* Compiler configurations */ +#define CCIF +#define CLIF + +/* Platform typedefs */ +typedef uint32_t clock_time_t; +typedef uint32_t uip_stats_t; + +/* + * rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define + * RTIMER_CLOCK_LT to override this + */ +typedef uint32_t rtimer_clock_t; +#define RTIMER_CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Serial Boot Loader Backdoor configuration + * + * @{ + */ +#ifndef FLASH_CCA_CONF_BOOTLDR_BACKDOOR +#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR 1 /** RAM DMA channel */ +#define USB_ARCH_CONF_TX_DMA_CHAN 1 /**< RAM -> USB DMA channel */ +#define CC2538_RF_CONF_TX_DMA_CHAN 2 /**< RF -> RAM DMA channel */ +#define CC2538_RF_CONF_RX_DMA_CHAN 3 /**< RAM -> RF DMA channel */ +#define UDMA_CONF_MAX_CHANNEL CC2538_RF_CONF_RX_DMA_CHAN +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Character I/O Configuration + * + * @{ + */ +#ifndef UART_CONF_ENABLE +#define UART_CONF_ENABLE 1 /**< Enable/Disable UART I/O */ +#endif + +#ifndef UART0_CONF_BAUD_RATE +#define UART0_CONF_BAUD_RATE 115200 /**< Default UART0 baud rate */ +#endif + +#ifndef UART1_CONF_BAUD_RATE +#define UART1_CONF_BAUD_RATE 115200 /**< Default UART1 baud rate */ +#endif + +#ifndef SLIP_ARCH_CONF_USB +#define SLIP_ARCH_CONF_USB 0 /**< SLIP over UART by default */ +#endif + +#ifndef CC2538_RF_CONF_SNIFFER_USB +#define CC2538_RF_CONF_SNIFFER_USB 0 /**< Sniffer out over UART by default */ +#endif + +#ifndef DBG_CONF_USB +#define DBG_CONF_USB 0 /**< All debugging over UART by default */ +#endif + +#ifndef SERIAL_LINE_CONF_UART +#define SERIAL_LINE_CONF_UART 0 /**< UART to use with serial line */ +#endif + +#if !SLIP_ARCH_CONF_USB +#ifndef SLIP_ARCH_CONF_UART +#define SLIP_ARCH_CONF_UART 0 /**< UART to use with SLIP */ +#endif +#endif + +#if !CC2538_RF_CONF_SNIFFER_USB +#ifndef CC2538_RF_CONF_SNIFFER_UART +#define CC2538_RF_CONF_SNIFFER_UART 0 /**< UART to use with sniffer */ +#endif +#endif + +#if !DBG_CONF_USB +#ifndef DBG_CONF_UART +#define DBG_CONF_UART 0 /**< UART to use for debugging */ +#endif +#endif + +#ifndef UART1_CONF_UART +#define UART1_CONF_UART 0 /**< UART to use for examples relying on + the uart1_* API */ +#endif + +/* Turn off example-provided putchars */ +#define SLIP_BRIDGE_CONF_NO_PUTCHAR 1 +#define SLIP_RADIO_CONF_NO_PUTCHAR 1 + +#ifndef SLIP_ARCH_CONF_ENABLED +/* + * Determine whether we need SLIP + * This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT + * keep using SLIP + */ +#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT) +#define SLIP_ARCH_CONF_ENABLED 1 +#endif +#endif + +/* + * When set, the radio turns off address filtering and sends all captured + * frames down a peripheral (UART or USB, depending on the value of + * CC2538_RF_CONF_SNIFFER_USB) + */ +#ifndef CC2538_RF_CONF_SNIFFER +#define CC2538_RF_CONF_SNIFFER 0 +#endif + +/** + * \brief Define this as 1 to build a headless node. + * + * The UART will not be initialised its clock will be gated, offering some + * energy savings. The USB will not be initialised either + */ +#ifndef CC2538_CONF_QUIET +#define CC2538_CONF_QUIET 0 +#endif + +/* CC2538_CONF_QUIET is hard and overrides all other related defines */ +#if CC2538_CONF_QUIET +#undef USB_SERIAL_CONF_ENABLE +#define USB_SERIAL_CONF_ENABLE 0 + +#undef UART_CONF_ENABLE +#define UART_CONF_ENABLE 0 + +#undef STARTUP_CONF_VERBOSE +#define STARTUP_CONF_VERBOSE 0 + +/* Little sanity check: We can't have quiet sniffers */ +#if CC2538_RF_CONF_SNIFFER +#error "CC2538_RF_CONF_SNIFFER == 1 and CC2538_CONF_QUIET == 1" +#error "These values are conflicting. Please set either to 0" +#endif +#endif /* CC2538_CONF_QUIET */ + +/** + * \brief Enable the USB core only if we need it + */ +#ifndef USB_SERIAL_CONF_ENABLE +#define USB_SERIAL_CONF_ENABLE \ + ((SLIP_ARCH_CONF_USB & SLIP_ARCH_CONF_ENABLED) | \ + DBG_CONF_USB | \ + (CC2538_RF_CONF_SNIFFER & CC2538_RF_CONF_SNIFFER_USB)) +#endif + +/* + * If debugging and SLIP use the same peripheral, this will be 1. Don't modify + * this + */ +#if SLIP_ARCH_CONF_ENABLED +#define DBG_CONF_SLIP_MUX (SLIP_ARCH_CONF_USB == DBG_CONF_USB && \ + (SLIP_ARCH_CONF_USB || \ + SLIP_ARCH_CONF_UART == DBG_CONF_UART)) +#endif + +/* + * Automatic detection of whether a specific UART is in use + */ +#define UART_IN_USE_BY_SERIAL_LINE(u) (SERIAL_LINE_CONF_UART == (u)) +#define UART_IN_USE_BY_SLIP(u) (SLIP_ARCH_CONF_ENABLED && \ + !SLIP_ARCH_CONF_USB && \ + SLIP_ARCH_CONF_UART == (u)) +#define UART_IN_USE_BY_RF_SNIFFER(u) (CC2538_RF_CONF_SNIFFER && \ + !CC2538_RF_CONF_SNIFFER_USB && \ + CC2538_RF_CONF_SNIFFER_UART == (u)) +#define UART_IN_USE_BY_DBG(u) (!DBG_CONF_USB && DBG_CONF_UART == (u)) +#define UART_IN_USE_BY_UART1(u) (UART1_CONF_UART == (u)) + +#define UART_IN_USE(u) ( \ + UART_CONF_ENABLE && \ + (UART_IN_USE_BY_SERIAL_LINE(u) || \ + UART_IN_USE_BY_SLIP(u) || \ + UART_IN_USE_BY_RF_SNIFFER(u) || \ + UART_IN_USE_BY_DBG(u) || \ + UART_IN_USE_BY_UART1(u)) \ +) +/** @} */ +/*---------------------------------------------------------------------------*/ +/* board.h assumes that basic configuration is done */ +#include "board.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Network Stack Configuration + * + * @{ + */ +#ifndef NETSTACK_CONF_NETWORK +#if NETSTACK_CONF_WITH_IPV6 +#define NETSTACK_CONF_NETWORK sicslowpan_driver +#else +#define NETSTACK_CONF_NETWORK rime_driver +#endif /* NETSTACK_CONF_WITH_IPV6 */ +#endif /* NETSTACK_CONF_NETWORK */ + +#ifndef NETSTACK_CONF_MAC +#define NETSTACK_CONF_MAC csma_driver +#endif + +#ifndef NETSTACK_CONF_RDC +#define NETSTACK_CONF_RDC contikimac_driver +#endif + +/* Configure NullRDC for when it's selected */ +#define NULLRDC_802154_AUTOACK 1 +#define NULLRDC_802154_AUTOACK_HW 1 + +/* Configure ContikiMAC for when it's selected */ +#define CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION 0 +#define WITH_FAST_SLEEP 1 + +#ifndef NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE +#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8 +#endif + +#ifndef NETSTACK_CONF_FRAMER +#if NETSTACK_CONF_WITH_IPV6 +#define NETSTACK_CONF_FRAMER framer_802154 +#else /* NETSTACK_CONF_WITH_IPV6 */ +#define NETSTACK_CONF_FRAMER contikimac_framer +#endif /* NETSTACK_CONF_WITH_IPV6 */ +#endif /* NETSTACK_CONF_FRAMER */ + +#ifndef NETSTACK_CONF_RADIO +#define NETSTACK_CONF_RADIO cc2538_rf_driver +#endif + +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name LPM configuration + * @{ + */ +#ifndef LPM_CONF_ENABLE +#define LPM_CONF_ENABLE 1 /**< Set to 0 to disable LPM entirely */ +#endif + +/** + * \brief Maximum PM + * + * The SoC will never drop to a Power Mode deeper than the one specified here. + * 0 for PM0, 1 for PM1 and 2 for PM2 + */ +#ifndef LPM_CONF_MAX_PM +#define LPM_CONF_MAX_PM 1 +#endif + +#ifndef LPM_CONF_STATS +#define LPM_CONF_STATS 0 /**< Set to 1 to enable LPM-related stats */ +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name IEEE address configuration + * + * Used to generate our RIME & IPv6 address + * @{ + */ +/** + * \brief Location of the IEEE address + * 0 => Read from InfoPage, + * 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS + */ +#ifndef IEEE_ADDR_CONF_HARDCODED +#define IEEE_ADDR_CONF_HARDCODED 0 +#endif + +/** + * \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED + * is defined as 1 + */ +#ifndef IEEE_ADDR_CONF_ADDRESS +#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF } +#endif + +/** + * \brief Location of the IEEE address in the InfoPage when + * IEEE_ADDR_CONF_HARDCODED is defined as 0 + * 0 => Use the primary address location + * 1 => Use the secondary address location + */ +#ifndef IEEE_ADDR_CONF_USE_SECONDARY_LOCATION +#define IEEE_ADDR_CONF_USE_SECONDARY_LOCATION 0 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name RF configuration + * + * @{ + */ +/* RF Config */ +#ifndef IEEE802154_CONF_PANID +#define IEEE802154_CONF_PANID 0xABCD +#endif + +#ifndef CC2538_RF_CONF_CHANNEL +#define CC2538_RF_CONF_CHANNEL 26 +#endif /* CC2538_RF_CONF_CHANNEL */ + +#ifndef CC2538_RF_CONF_AUTOACK +#define CC2538_RF_CONF_AUTOACK 1 /**< RF H/W generates ACKs */ +#endif /* CC2538_CONF_AUTOACK */ + +#ifndef CC2538_RF_CONF_TX_USE_DMA +#define CC2538_RF_CONF_TX_USE_DMA 1 /**< RF TX over DMA */ +#endif + +#ifndef CC2538_RF_CONF_RX_USE_DMA +#define CC2538_RF_CONF_RX_USE_DMA 1 /**< RF RX over DMA */ +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name IPv6, RIME and network buffer configuration + * + * @{ + */ + +/* Don't let contiki-default-conf.h decide if we are an IPv6 build */ +#ifndef NETSTACK_CONF_WITH_IPV6 +#define NETSTACK_CONF_WITH_IPV6 0 +#endif + +#if NETSTACK_CONF_WITH_IPV6 +/* Addresses, Sizes and Interfaces */ +/* 8-byte addresses here, 2 otherwise */ +#define LINKADDR_CONF_SIZE 8 +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 0 +#define UIP_CONF_NETIF_MAX_ADDRESSES 3 + +/* TCP, UDP, ICMP */ +#ifndef UIP_CONF_TCP +#define UIP_CONF_TCP 1 +#endif +#ifndef UIP_CONF_TCP_MSS +#define UIP_CONF_TCP_MSS 64 +#endif +#define UIP_CONF_UDP 1 +#define UIP_CONF_UDP_CHECKSUMS 1 +#define UIP_CONF_ICMP6 1 + +/* ND and Routing */ +#ifndef UIP_CONF_ROUTER +#define UIP_CONF_ROUTER 1 +#endif + +#define UIP_CONF_ND6_SEND_RA 0 +#define UIP_CONF_IP_FORWARD 0 +#define RPL_CONF_STATS 0 + +#ifndef RPL_CONF_OF +#define RPL_CONF_OF rpl_mrhof +#endif + +#define UIP_CONF_ND6_REACHABLE_TIME 600000 +#define UIP_CONF_ND6_RETRANS_TIMER 10000 + +#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS +#define NBR_TABLE_CONF_MAX_NEIGHBORS 20 +#endif +#ifndef UIP_CONF_MAX_ROUTES +#define UIP_CONF_MAX_ROUTES 20 +#endif + +/* uIP */ +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 1300 +#endif + +#define UIP_CONF_IPV6_QUEUE_PKT 0 +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_REASSEMBLY 0 +#define UIP_CONF_MAX_LISTENPORTS 8 + +/* 6lowpan */ +#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 +#ifndef SICSLOWPAN_CONF_COMPRESSION_THRESHOLD +#define SICSLOWPAN_CONF_COMPRESSION_THRESHOLD 63 +#endif +#ifndef SICSLOWPAN_CONF_FRAG +#define SICSLOWPAN_CONF_FRAG 1 +#endif +#define SICSLOWPAN_CONF_MAXAGE 8 + +/* Define our IPv6 prefixes/contexts here */ +#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1 +#ifndef SICSLOWPAN_CONF_ADDR_CONTEXT_0 +#define SICSLOWPAN_CONF_ADDR_CONTEXT_0 { \ + addr_contexts[0].prefix[0] = 0xaa; \ + addr_contexts[0].prefix[1] = 0xaa; \ +} +#endif + +#define MAC_CONF_CHANNEL_CHECK_RATE 8 + +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 8 +#endif +/*---------------------------------------------------------------------------*/ +#else /* NETSTACK_CONF_WITH_IPV6 */ +/* Network setup for non-IPv6 (rime). */ +#define UIP_CONF_IP_FORWARD 1 + +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 108 +#endif + +#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0 + +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 8 +#endif + +#endif /* NETSTACK_CONF_WITH_IPV6 */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Security + * + * @{ + */ +#ifndef CRYPTO_CONF_INIT +#define CRYPTO_CONF_INIT 1 /**< Whether to init cryptoprocessor */ +#endif + +#ifndef AES_128_CONF +#define AES_128_CONF cc2538_aes_128_driver /**< AES-128 driver */ +#endif + +#ifndef CCM_STAR_CONF +#define CCM_STAR_CONF cc2538_ccm_star_driver /**< AES-CCM* driver */ +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ + +#endif /* CONTIKI_CONF_H_ */ + +/** @} */ diff --git a/platform/openmote-cc2538/contiki-main.c b/platform/openmote-cc2538/contiki-main.c new file mode 100644 index 000000000..72648088c --- /dev/null +++ b/platform/openmote-cc2538/contiki-main.c @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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-platforms + * @{ + * + * \defgroup openmote The OpenMote-CC2538 platform + * + * The OpenMote-CC2538 is based on the CC2538, the new platform by Texas Instruments + * based on an ARM Cortex-M3 core and a IEEE 802.15.4 radio. + * @{ + * + * \file + * Main module for the OpenMote-CC2538 platform + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +#include "dev/sys-ctrl.h" +#include "dev/scb.h" +#include "dev/nvic.h" +#include "dev/uart.h" +#include "dev/watchdog.h" +#include "dev/ioc.h" +#include "dev/button-sensor.h" +#include "dev/serial-line.h" +#include "dev/slip.h" +#include "dev/cc2538-rf.h" +#include "dev/udma.h" +#include "dev/crypto.h" +#include "usb/usb-serial.h" +#include "lib/random.h" +#include "net/netstack.h" +#include "net/queuebuf.h" +#include "net/ip/tcpip.h" +#include "net/ip/uip.h" +#include "net/mac/frame802154.h" +#include "cpu.h" +#include "reg.h" +#include "ieee-addr.h" +#include "lpm.h" + +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#if STARTUP_CONF_VERBOSE +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +#if UART_CONF_ENABLE +#define PUTS(s) puts(s) +#else +#define PUTS(s) +#endif +/*---------------------------------------------------------------------------*/ +/** \brief Board specific iniatialisation */ +void board_init(void); +/*---------------------------------------------------------------------------*/ +static void +fade(unsigned char l) +{ + volatile int i; + int k, j; + for(k = 0; k < 800; ++k) { + j = k > 400 ? 800 - k : k; + + leds_on(l); + for(i = 0; i < j; ++i) { + asm("nop"); + } + leds_off(l); + for(i = 0; i < 400 - j; ++i) { + asm("nop"); + } + } +} +/*---------------------------------------------------------------------------*/ +static void +set_rf_params(void) +{ + uint16_t short_addr; + uint8_t ext_addr[8]; + + ieee_addr_cpy_to(ext_addr, 8); + + short_addr = ext_addr[7]; + short_addr |= ext_addr[6] << 8; + + /* Populate linkaddr_node_addr. Maintain endianness */ + memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], LINKADDR_SIZE); + +#if STARTUP_CONF_VERBOSE + { + int i; + printf("Rime configured with address "); + for(i = 0; i < LINKADDR_SIZE - 1; i++) { + printf("%02x:", linkaddr_node_addr.u8[i]); + } + printf("%02x\n", linkaddr_node_addr.u8[i]); + } +#endif + + NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); + NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, CC2538_RF_CHANNEL); + NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Main routine for the OpenMote-CC2538 platforms + */ +int +main(void) +{ + nvic_init(); + ioc_init(); + sys_ctrl_init(); + clock_init(); + lpm_init(); + rtimer_init(); + gpio_init(); + leds_init(); + fade(LEDS_RED); + process_init(); + watchdog_init(); + + /* + * Character I/O Initialisation. + * When the UART receives a character it will call serial_line_input_byte to + * notify the core. The same applies for the USB driver. + * + * If slip-arch is also linked in afterwards (e.g. if we are a border router) + * it will overwrite one of the two peripheral input callbacks. Characters + * received over the relevant peripheral will be handled by + * slip_input_byte instead + */ +#if UART_CONF_ENABLE + uart_init(0); + uart_init(1); + uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte); +#endif + +#if USB_SERIAL_CONF_ENABLE + usb_serial_init(); + usb_serial_set_input(serial_line_input_byte); +#endif + + serial_line_init(); + + INTERRUPTS_ENABLE(); + fade(LEDS_BLUE); + + PUTS(CONTIKI_VERSION_STRING); + PUTS(BOARD_STRING); + + /* Initialise the H/W RNG engine. */ + random_init(0); + + udma_init(); + + process_start(&etimer_process, NULL); + ctimer_init(); + + board_init(); + +#if CRYPTO_CONF_INIT + crypto_init(); + crypto_disable(); +#endif + + netstack_init(); + set_rf_params(); + + PRINTF(" Net: "); + PRINTF("%s\n", NETSTACK_NETWORK.name); + PRINTF(" MAC: "); + PRINTF("%s\n", NETSTACK_MAC.name); + PRINTF(" RDC: "); + PRINTF("%s\n", NETSTACK_RDC.name); + +#if NETSTACK_CONF_WITH_IPV6 + memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr)); + queuebuf_init(); + process_start(&tcpip_process, NULL); +#endif /* NETSTACK_CONF_WITH_IPV6 */ + + process_start(&sensors_process, NULL); + + SENSORS_ACTIVATE(button_sensor); + + energest_init(); + ENERGEST_ON(ENERGEST_TYPE_CPU); + + autostart_start(autostart_processes); + + watchdog_start(); + fade(LEDS_GREEN); + + while(1) { + uint8_t r; + do { + /* Reset watchdog and handle polls and events */ + watchdog_periodic(); + + r = process_run(); + } while(r > 0); + + /* We have serviced all pending events. Enter a Low-Power mode. */ + lpm_enter(); + } +} +/*---------------------------------------------------------------------------*/ + +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/adxl346.c b/platform/openmote-cc2538/dev/adxl346.c new file mode 100644 index 000000000..bdb934d2d --- /dev/null +++ b/platform/openmote-cc2538/dev/adxl346.c @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the ADXL346 acceleration sensor in OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +/*---------------------------------------------------------------------------*/ +#include "dev/i2c.h" +#include "dev/adxl346.h" +/*---------------------------------------------------------------------------*/ +/* ADDRESS AND IDENTIFIER */ +#define ADXL346_ADDRESS (0x53) +#define ADXL346_DEVID_VALUE (0xE6) + +/* REGISTER ADDRESSES */ +#define ADXL346_DEVID_ADDR (0x00) +#define ADXL346_THRES_TAP_ADDR (0x1D) +#define ADXL346_OFSX_ADDR (0x1E) +#define ADXL346_OFSY_ADDR (0x1F) +#define ADXL346_OFSZ_ADDR (0x20) +#define ADXL346_DUR_ADDR (0x21) +#define ADXL346_LATENT_ADDR (0x22) +#define ADXL346_WINDOW_ADDR (0x23) +#define ADXL346_THRESH_ACT_ADDR (0x24) +#define ADXL346_THRESH_INACT_ADDR (0x25) +#define ADXL346_TIME_INACT_ADDR (0x26) +#define ADXL346_ACT_INACT_CTL_ADDR (0x27) +#define ADXL346_THRESH_FF_ADDR (0x28) +#define ADXL346_TIME_FF_ADDR (0x29) +#define ADXL346_TAP_AXES_ADDR (0x2A) +#define ADXL346_ACT_TAP_STATUS_ADDR (0x2B) +#define ADXL346_BW_RATE_ADDR (0x2C) +#define ADXL346_POWER_CTL_ADDR (0x2D) +#define ADXL346_INT_ENABLE_ADDR (0x2E) +#define ADXL346_INT_MAP_ADDR (0x2F) +#define ADXL346_INT_SOURCE_ADDR (0x30) +#define ADXL346_DATA_FORMAT_ADDR (0x31) +#define ADXL346_DATAX0_ADDR (0x32) +#define ADXL346_DATAX1_ADDR (0x33) +#define ADXL346_DATAY0_ADDR (0x34) +#define ADXL346_DATAY1_ADDR (0x35) +#define ADXL346_DATAZ0_ADDR (0x36) +#define ADXL346_DATAZ1_ADDR (0x37) +#define ADXL346_FIFO_CTL_ADDR (0x38) +#define ADXL346_FIFO_STATUS_ADDR (0x39) +#define ADXL346_TAP_SIGN_ADDR (0x3A) +#define ADXL346_ORIENT_CONF_ADDR (0x3B) +#define ADXL346_ORIENT_ADDR (0x3C) + +/* INT_ENABLE/INT_MAP/INT_SOURCE */ +#define ADXL346_INT_ENABLE_DATA_READY (1 << 7) +#define ADXL346_INT_ENABLE_SINGLE_TAP (1 << 6) +#define ADXL346_INT_ENABLE_DOUBLE_TAP (1 << 5) +#define ADXL346_INT_ENABLE_ACTIVITY (1 << 4) +#define ADXL346_INT_ENABLE_INACTIVITY (1 << 3) +#define ADXL346_INT_ENABLE_FREE_FALL (1 << 2) +#define ADXL346_INT_ENABLE_WATERMARK (1 << 1) +#define ADXL346_INT_ENABLE_OVERRUN (1 << 0) + +/* ACT_INACT_CONTROL */ +#define ADXL346_ACT_INACT_CTL_ACT_ACDC (1 << 7) +#define ADXL346_ACT_INACT_CTL_ACT_X_EN (1 << 6) +#define ADXL346_ACT_INACT_CTL_ACT_Y_EN (1 << 5) +#define ADXL346_ACT_INACT_CTL_ACT_Z_EN (1 << 4) +#define ADXL346_ACT_INACT_CTL_INACT_ACDC (1 << 3) +#define ADXL346_ACT_INACT_CTL_INACT_X_EN (1 << 2) +#define ADXL346_ACT_INACT_CTL_INACT_Y_EN (1 << 1) +#define ADXL346_ACT_INACT_CTL_INACT_Z_EN (1 << 0) + +/* TAP_AXES */ +#define ADXL346_TAP_AXES_SUPPRESS (1 << 3) +#define ADXL346_TAP_AXES_TAP_X_EN (1 << 2) +#define ADXL346_TAP_AXES_TAP_Y_EN (1 << 1) +#define ADXL346_TAP_AXES_TAP_Z_EN (1 << 0) + +/* ACT_TAP_STATUS */ +#define ADXL346_ACT_TAP_STATUS_ACT_X_SRC (1 << 6) +#define ADXL346_ACT_TAP_STATUS_ACT_Y_SRC (1 << 5) +#define ADXL346_ACT_TAP_STATUS_ACT_Z_SRC (1 << 4) +#define ADXL346_ACT_TAP_STATUS_ASLEEP (1 << 3) +#define ADXL346_ACT_TAP_STATUS_TAP_X_SRC (1 << 2) +#define ADXL346_ACT_TAP_STATUS_TAP_Y_SRC (1 << 1) +#define ADXL346_ACT_TAP_STATUS_TAP_Z_SRC (1 << 0) + +/* BW_RATE */ +#define ADXL346_BW_RATE_POWER (1 << 4) +#define ADXL346_BW_RATE_RATE(x) ((x) & 0x0F) + +/* POWER CONTROL */ +#define ADXL346_POWER_CTL_LINK (1 << 5) +#define ADXL346_POWER_CTL_AUTO_SLEEP (1 << 4) +#define ADXL346_POWER_CTL_MEASURE (1 << 3) +#define ADXL346_POWER_CTL_SLEEP (1 << 2) +#define ADXL346_POWER_CTL_WAKEUP(x) ((x) & 0x03) + +/* DATA_FORMAT */ +#define ADXL346_DATA_FORMAT_SELF_TEST (1 << 7) +#define ADXL346_DATA_FORMAT_SPI (1 << 6) +#define ADXL346_DATA_FORMAT_INT_INVERT (1 << 5) +#define ADXL346_DATA_FORMAT_FULL_RES (1 << 3) +#define ADXL346_DATA_FORMAT_JUSTIFY (1 << 2) +#define ADXL346_DATA_FORMAT_RANGE(x) ((x) & 0x03) +#define ADXL346_DATA_FORMAT_RANGE_PM_2g (0) +#define ADXL346_DATA_FORMAT_RANGE_PM_4g (1) +#define ADXL346_DATA_FORMAT_RANGE_PM_8g (2) +#define ADXL346_DATA_FORMAT_RANGE_PM_16g (3) +/*---------------------------------------------------------------------------*/ +/** + * + */ +void +adxl346_init(void) +{ + uint8_t config[2]; + + i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, + I2C_SCL_NORMAL_BUS_SPEED); + + config[0] = ADXL346_BW_RATE_ADDR; + config[1] = (ADXL346_BW_RATE_RATE(11)); + i2c_burst_send(ADXL346_ADDRESS, config, sizeof(config)); + + config[0] = ADXL346_DATA_FORMAT_ADDR; + config[1] = (ADXL346_DATA_FORMAT_SELF_TEST | + ADXL346_DATA_FORMAT_FULL_RES | + ADXL346_DATA_FORMAT_RANGE_PM_16g); + i2c_burst_send(ADXL346_ADDRESS, config, sizeof(config)); + + config[0] = ADXL346_POWER_CTL_ADDR; + config[1] = (ADXL346_POWER_CTL_MEASURE); + i2c_burst_send(ADXL346_ADDRESS, config, sizeof(config)); +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +void +adxl346_reset(void) +{ +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint8_t +adxl346_is_present(void) +{ + uint8_t is_present; + + i2c_single_send(ADXL346_ADDRESS, ADXL346_DEVID_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &is_present); + + return is_present == ADXL346_DEVID_VALUE; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint16_t +adxl346_read_x(void) +{ + uint8_t acceleration[2]; + uint16_t x; + + i2c_single_send(ADXL346_ADDRESS, ADXL346_DATAX0_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &acceleration[0]); + i2c_single_send(ADXL346_ADDRESS, ADXL346_DATAX1_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &acceleration[1]); + + x = (acceleration[0] << 8) | acceleration[1]; + + return x; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint16_t +adxl346_read_y(void) +{ + uint8_t acceleration[2]; + uint16_t y; + + i2c_single_send(ADXL346_ADDRESS, ADXL346_DATAY0_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &acceleration[0]); + i2c_single_send(ADXL346_ADDRESS, ADXL346_DATAY1_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &acceleration[1]); + + y = (acceleration[0] << 8) | acceleration[1]; + + return y; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint16_t +adxl346_read_z(void) +{ + uint8_t acceleration[2]; + uint16_t z; + + i2c_single_send(ADXL346_ADDRESS, ADXL346_DATAZ0_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &acceleration[0]); + i2c_single_send(ADXL346_ADDRESS, ADXL346_DATAZ1_ADDR); + i2c_single_receive(ADXL346_ADDRESS, &acceleration[1]); + + z = (acceleration[0] << 8) | acceleration[1]; + + return z; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/adxl346.h b/platform/openmote-cc2538/dev/adxl346.h new file mode 100644 index 000000000..d5e9eac76 --- /dev/null +++ b/platform/openmote-cc2538/dev/adxl346.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Header for the ADXL346 acceleration sensor in OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +#ifndef __ADXL346_H__ +#define __ADXL346_H__ +/*---------------------------------------------------------------------------*/ +void adxl346_init(void); +void adxl346_reset(void); +uint8_t adxl346_is_present(void); +uint16_t adxl346_read_x(void); +uint16_t adxl346_read_y(void); +uint16_t adxl346_read_z(void); +/*---------------------------------------------------------------------------*/ +#endif /* ifndef __ADXL346_H__ */ +/** @} */ diff --git a/platform/openmote-cc2538/dev/antenna.c b/platform/openmote-cc2538/dev/antenna.c new file mode 100644 index 000000000..b0ad7b07e --- /dev/null +++ b/platform/openmote-cc2538/dev/antenna.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2014, Thingsquare, http://www.thingsquare.com/. + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the antenna selection on the OpenMote-CC2538 platform. + */ + +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +#include "dev/gpio.h" +#include "dev/antenna.h" +/*---------------------------------------------------------------------------*/ +#define BSP_RADIO_BASE (GPIO_D_BASE) +#define BSP_RADIO_INT (1 << 5) +#define BSP_RADIO_EXT (1 << 4) +/*---------------------------------------------------------------------------*/ +static void +gpio_set(int port, int bit) +{ + REG((port | GPIO_DATA) + (bit << 2)) = bit; +} +/*---------------------------------------------------------------------------*/ +static void +gpio_reset(int port, int bit) +{ + REG((port | GPIO_DATA) + (bit << 2)) = 0; +} +/*---------------------------------------------------------------------------*/ +/** + * Configure the antenna using the RF switch + * INT is the internal antenna (chip) configured through ANT1_SEL (V1) + * EXT is the external antenna (connector) configured through ANT2_SEL (V2) + */ +void +antenna_init(void) +{ + /* Configure the ANT1 and ANT2 GPIO as output */ + GPIO_SET_OUTPUT(BSP_RADIO_BASE, BSP_RADIO_INT); + GPIO_SET_OUTPUT(BSP_RADIO_BASE, BSP_RADIO_EXT); + + /* Select external antenna by default. */ + antenna_external(); +} +/*---------------------------------------------------------------------------*/ +/** + * Select the external (connector) antenna + */ +void +antenna_external(void) +{ + gpio_reset(BSP_RADIO_BASE, BSP_RADIO_INT); + gpio_set(BSP_RADIO_BASE, BSP_RADIO_EXT); +} +/*---------------------------------------------------------------------------*/ +/** + * Select the internal (chip) antenna + */ +void +antenna_internal(void) +{ + gpio_reset(BSP_RADIO_BASE, BSP_RADIO_EXT); + gpio_set(BSP_RADIO_BASE, BSP_RADIO_INT); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/antenna.h b/platform/openmote-cc2538/dev/antenna.h new file mode 100644 index 000000000..8b14df4b0 --- /dev/null +++ b/platform/openmote-cc2538/dev/antenna.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Thingsquare, http://www.thingsquare.com/. + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Header for the antenna selection on the OpenMote-CC2538 platform. + */ + +#ifndef ANTENNA_H_ +#define ANTENNA_H_ +/*---------------------------------------------------------------------------*/ +void antenna_init(void); +void antenna_internal(void); +void antenna_external(void); +/*---------------------------------------------------------------------------*/ +#endif /* ANTENNA_H_ */ +/** @} */ diff --git a/platform/openmote-cc2538/dev/button-sensor.c b/platform/openmote-cc2538/dev/button-sensor.c new file mode 100644 index 000000000..6d85400d7 --- /dev/null +++ b/platform/openmote-cc2538/dev/button-sensor.c @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the OpenMote-CC2538 buttons + * + */ + +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/nvic.h" +#include "dev/ioc.h" +#include "dev/gpio.h" +#include "dev/button-sensor.h" +#include "sys/timer.h" + +#include +#include +/*---------------------------------------------------------------------------*/ +#define BUTTON_USER_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_USER_PORT) +#define BUTTON_USER_PIN_MASK GPIO_PIN_MASK(BUTTON_USER_PIN) +/*---------------------------------------------------------------------------*/ +static struct timer debouncetimer; +/*---------------------------------------------------------------------------*/ +/** + * \brief Common initialiser for all buttons + * \param port_base GPIO port's register offset + * \param pin_mask Pin mask corresponding to the button's pin + */ +static void +config(uint32_t port_base, uint32_t pin_mask) +{ + /* Software controlled */ + GPIO_SOFTWARE_CONTROL(port_base, pin_mask); + + /* Set pin to input */ + GPIO_SET_INPUT(port_base, pin_mask); + + /* Enable edge detection */ + GPIO_DETECT_EDGE(port_base, pin_mask); + + /* Single edge */ + GPIO_TRIGGER_SINGLE_EDGE(port_base, pin_mask); + + /* Trigger interrupt on Falling edge */ + GPIO_DETECT_RISING(port_base, pin_mask); + + GPIO_ENABLE_INTERRUPT(port_base, pin_mask); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Callback registered with the GPIO module. Gets fired with a button + * port/pin generates an interrupt + * \param port The port number that generated the interrupt + * \param pin The pin number that generated the interrupt. This is the pin + * absolute number (i.e. 0, 1, ..., 7), not a mask + */ +static void +btn_callback(uint8_t port, uint8_t pin) +{ + if(!timer_expired(&debouncetimer)) { + return; + } + timer_set(&debouncetimer, CLOCK_SECOND / 8); + if(port == GPIO_C_NUM) { + sensors_changed(&button_user_sensor); + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Init function for the select button. + * + * Parameters are ignored. They have been included because the prototype is + * dictated by the core sensor api. The return value is also not required by + * the API but otherwise ignored. + * + * \param type ignored + * \param value ignored + * \return ignored + */ +static int +config_user(int type, int value) +{ + config(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + + ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE); + + nvic_interrupt_enable(BUTTON_USER_VECTOR); + + gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN); + return 1; +} +/*---------------------------------------------------------------------------*/ +void +button_sensor_init() +{ + timer_set(&debouncetimer, 0); +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(button_user_sensor, BUTTON_SENSOR, NULL, config_user, NULL); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/button-sensor.h b/platform/openmote-cc2538/dev/button-sensor.h new file mode 100644 index 000000000..ec7849ee1 --- /dev/null +++ b/platform/openmote-cc2538/dev/button-sensor.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Header for the OpenMote-CC2538 buttons + * + */ + +#ifndef BUTTON_SENSOR_H_ +#define BUTTON_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" +#include "dev/gpio.h" +/*---------------------------------------------------------------------------*/ +#define BUTTON_SENSOR "Button" +/*---------------------------------------------------------------------------*/ +#define button_sensor button_user_sensor +extern const struct sensors_sensor button_user_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* BUTTON_SENSOR_H_ */ + +/** \brief Common initialiser for all SmartRF Buttons */ +void button_sensor_init(); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/leds-arch.c b/platform/openmote-cc2538/dev/leds-arch.c new file mode 100644 index 000000000..13a4c1347 --- /dev/null +++ b/platform/openmote-cc2538/dev/leds-arch.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the OpenMote-CC2538 LEDs + * + */ + +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "reg.h" +#include "dev/leds.h" +#include "dev/gpio.h" +/*---------------------------------------------------------------------------*/ +#define LEDS_GPIO_PIN_MASK LEDS_ALL +/*---------------------------------------------------------------------------*/ +void +leds_arch_init(void) +{ + GPIO_SET_OUTPUT(GPIO_C_BASE, LEDS_GPIO_PIN_MASK); +} +/*---------------------------------------------------------------------------*/ +unsigned char +leds_arch_get(void) +{ + return GPIO_READ_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK); +} +/*---------------------------------------------------------------------------*/ +void +leds_arch_set(unsigned char leds) +{ + GPIO_WRITE_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK, leds); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/max44009.c b/platform/openmote-cc2538/dev/max44009.c new file mode 100644 index 000000000..34bce89ab --- /dev/null +++ b/platform/openmote-cc2538/dev/max44009.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the MAX44009 light sensor in OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +/*---------------------------------------------------------------------------*/ +#include "dev/i2c.h" +#include "dev/max44009.h" +/*---------------------------------------------------------------------------*/ +/* ADDRESS AND NOT_FOUND VALUE */ +#define MAX44009_ADDRESS (0x4A) +#define MAX44009_NOT_FOUND (0x00) + +/* REGISTER ADDRESSES */ +#define MAX44009_INT_STATUS_ADDR (0x00) /* R */ +#define MAX44009_INT_ENABLE_ADDR (0x01) /* R/W */ +#define MAX44009_CONFIG_ADDR (0x02) /* R/W */ +#define MAX44009_LUX_HIGH_ADDR (0x03) /* R */ +#define MAX44009_LUX_LOW_ADDR (0x04) /* R */ +#define MAX44009_THR_HIGH_ADDR (0x05) /* R/W */ +#define MAX44009_THR_LOW_ADDR (0x06) /* R/W */ +#define MAX44009_THR_TIMER_ADDR (0x07) /* R/W */ + +/* INTERRUPT VALUES */ +#define MAX44009_INT_STATUS_OFF (0x00) +#define MAX44009_INT_STATUS_ON (0x01) +#define MAX44009_INT_DISABLED (0x00) +#define MAX44009_INT_ENABLED (0x01) + +/* CONFIGURATION VALUES */ +#define MAX44009_CONFIG_DEFAULT (0 << 7) +#define MAX44009_CONFIG_CONTINUOUS (1 << 7) +#define MAX44009_CONFIG_AUTO (0 << 6) +#define MAX44009_CONFIG_MANUAL (1 << 6) +#define MAX44009_CONFIG_CDR_NORMAL (0 << 5) +#define MAX44009_CONFIG_CDR_DIVIDED (1 << 5) +#define MAX44009_CONFIG_INTEGRATION_800ms (0 << 0) +#define MAX44009_CONFIG_INTEGRATION_400ms (1 << 0) +#define MAX44009_CONFIG_INTEGRATION_200ms (2 << 0) +#define MAX44009_CONFIG_INTEGRATION_100ms (3 << 0) +#define MAX44009_CONFIG_INTEGRATION_50ms (4 << 0) +#define MAX44009_CONFIG_INTEGRATION_25ms (5 << 0) +#define MAX44009_CONFIG_INTEGRATION_12ms (6 << 0) +#define MAX44009_CONFIG_INTEGRATION_6ms (7 << 0) + +/* DEFAULT CONFIGURATION */ +#define MAX44009_DEFAULT_CONFIGURATION (MAX44009_CONFIG_DEFAULT | \ + MAX44009_CONFIG_AUTO | \ + MAX44009_CONFIG_CDR_NORMAL | \ + MAX44009_CONFIG_INTEGRATION_100ms) +/*---------------------------------------------------------------------------*/ +/** + * + */ +void +max44009_init(void) +{ + uint8_t max44009_address[5] = { MAX44009_INT_ENABLE_ADDR, MAX44009_CONFIG_ADDR, \ + MAX44009_THR_HIGH_ADDR, MAX44009_THR_LOW_ADDR, \ + MAX44009_THR_TIMER_ADDR }; + uint8_t max44009_value[5]; + uint8_t max44009_data[2]; + uint8_t i; + + max44009_value[0] = (MAX44009_INT_STATUS_ON); + max44009_value[1] = (MAX44009_DEFAULT_CONFIGURATION); + max44009_value[2] = (0xFF); + max44009_value[3] = (0x00); + max44009_value[4] = (0xFF); + + i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, + I2C_SCL_NORMAL_BUS_SPEED); + + for(i = 0; i < sizeof(max44009_address); i++) { + max44009_data[0] = max44009_value[i]; + max44009_data[1] = max44009_data[i]; + i2c_burst_send(MAX44009_ADDRESS, max44009_data, 2); + } +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +void +max44009_reset(void) +{ + uint8_t max44009_address[5] = { MAX44009_INT_ENABLE_ADDR, MAX44009_CONFIG_ADDR, \ + MAX44009_THR_HIGH_ADDR, MAX44009_THR_LOW_ADDR, \ + MAX44009_THR_TIMER_ADDR }; + uint8_t max44009_value[5] = { 0x00, 0x03, 0xFF, 0x00, 0xFF }; + uint8_t max44009_data[2]; + uint8_t i; + + for(i = 0; i < sizeof(max44009_address); i++) { + max44009_data[0] = max44009_value[i]; + max44009_data[1] = max44009_data[i]; + i2c_burst_send(MAX44009_ADDRESS, max44009_data, 2); + } +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint8_t +max44009_is_present(void) +{ + uint8_t is_present; + + i2c_single_send(MAX44009_ADDRESS, MAX44009_CONFIG_ADDR); + i2c_single_receive(MAX44009_ADDRESS, &is_present); + + return is_present != MAX44009_NOT_FOUND; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint16_t +max44009_read_light(void) +{ + uint8_t exponent, mantissa; + uint8_t max44009_data[2]; + uint16_t result; + + i2c_single_send(MAX44009_ADDRESS, MAX44009_LUX_HIGH_ADDR); + i2c_single_receive(MAX44009_ADDRESS, &max44009_data[0]); + i2c_single_send(MAX44009_ADDRESS, MAX44009_LUX_LOW_ADDR); + i2c_single_receive(MAX44009_ADDRESS, &max44009_data[1]); + + exponent = ((max44009_data[0] >> 4) & 0x0E); + mantissa = ((max44009_data[0] & 0x0F) << 4) | (max44009_data[1] & 0x0F); + + result = ((uint16_t)exponent << 8) | ((uint16_t)mantissa << 0); + + return result; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +float +max44009_convert_light(uint16_t lux) +{ + uint8_t exponent, mantissa; + float result = 0.045; + + exponent = (lux >> 8) & 0xFF; + exponent = (exponent == 0x0F ? exponent & 0x0E : exponent); + + mantissa = (lux >> 0) & 0xFF; + + result *= 2 ^ exponent * mantissa; + + return result; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/max44009.h b/platform/openmote-cc2538/dev/max44009.h new file mode 100644 index 000000000..dbc40775d --- /dev/null +++ b/platform/openmote-cc2538/dev/max44009.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Header for the MAX44009 light sensor in OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +#ifndef __MAX44009_H__ +#define __MAX44009_H__ +/*---------------------------------------------------------------------------*/ +void max44009_init(void); +void max44009_reset(void); +uint8_t max44009_is_present(void); +uint16_t max44009_read_light(void); +float max44009_convert_light(uint16_t light); +/*---------------------------------------------------------------------------*/ +#endif /* ifndef __MAX44009_H__ */ +/** @} */ diff --git a/platform/openmote-cc2538/dev/sht21.c b/platform/openmote-cc2538/dev/sht21.c new file mode 100644 index 000000000..1ad07836f --- /dev/null +++ b/platform/openmote-cc2538/dev/sht21.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the SHT21 temperature and humidity sensor in OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +/*---------------------------------------------------------------------------*/ +#include "i2c.h" +#include "sht21.h" +/*---------------------------------------------------------------------------*/ +#define SHT21_ADDRESS (0x40) + +#define SHT21_USER_REG_READ (0xE7) +#define SHT21_USER_REG_WRITE (0xE6) +#define SHT21_USER_REG_RESERVED_BITS (0x38) + +#define SHT21_RESOLUTION_12b_14b ((0 << 7) | (0 << 0)) +#define SHT21_RESOLUTION_8b_12b ((0 << 7) | (1 << 0)) +#define SHT21_RESOLUTION_10b_13b ((1 << 7) | (0 << 0)) +#define SHT21_RESOLUTION_11b_11b ((1 << 7) | (1 << 0)) +#define SHT21_BATTERY_ABOVE_2V25 (0 << 6) +#define SHT21_BATTERY_BELOW_2V25 (1 << 6) +#define SHT21_ONCHIP_HEATER_ENABLE (1 << 2) +#define SHT21_ONCHIP_HEATER_DISABLE (0 << 2) +#define SHT21_OTP_RELOAD_ENABLE (0 << 1) +#define SHT21_OTP_RELOAD_DISABLE (1 << 1) + +#define SHT21_TEMPERATURE_HM_CMD (0xE3) +#define SHT21_HUMIDITY_HM_CMD (0xE5) +#define SHT21_TEMPERATURE_NHM_CMD (0xF3) +#define SHT21_HUMIDITY_NHM_CMD (0xF5) +#define SHT21_RESET_CMD (0xFE) + +#define SHT21_STATUS_MASK ( 0xFC ) + +#define SHT21_DEFAULT_CONFIG (SHT21_RESOLUTION_12b_14b | \ + SHT21_ONCHIP_HEATER_DISABLE | \ + SHT21_BATTERY_ABOVE_2V25 | \ + SHT21_OTP_RELOAD_DISABLE) + +#define SHT21_USER_CONFIG (SHT21_RESOLUTION_8b_12b | \ + SHT21_ONCHIP_HEATER_DISABLE | \ + SHT21_BATTERY_ABOVE_2V25 | \ + SHT21_OTP_RELOAD_DISABLE) +/*---------------------------------------------------------------------------*/ +/** + * + */ +void +sht21_init(void) +{ + uint8_t config[2]; + + i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, + I2C_SCL_NORMAL_BUS_SPEED); + + /* Setup the configuration vector, the first position holds address */ + /* and the second position holds the actual configuration */ + config[0] = SHT21_USER_REG_WRITE; + config[1] = 0; + + /* Read the current configuration according to the datasheet (pag. 9, fig. 18) */ + i2c_single_send(SHT21_ADDRESS, SHT21_USER_REG_READ); + i2c_single_receive(SHT21_ADDRESS, &config[1]); + + /* Clean all the configuration bits except those reserved */ + config[1] &= SHT21_USER_REG_RESERVED_BITS; + + /* Set the configuration bits without changing those reserved */ + config[1] |= SHT21_USER_CONFIG; + + i2c_burst_send(SHT21_ADDRESS, config, sizeof(config)); +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +void +sht21_reset(void) +{ + /* Send a soft-reset command according to the datasheet (pag. 9, fig. 17) */ + i2c_single_send(SHT21_ADDRESS, SHT21_RESET_CMD); +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint8_t +sht21_is_present(void) +{ + uint8_t is_present; + + /* Read the current configuration according to the datasheet (pag. 9, fig. 18) */ + i2c_single_send(SHT21_ADDRESS, SHT21_USER_REG_READ); + i2c_single_receive(SHT21_ADDRESS, &is_present); + + /* Clear the reserved bits according to the datasheet (pag. 9, tab. 8) */ + is_present &= ~SHT21_USER_REG_RESERVED_BITS; + + is_present = ((is_present == SHT21_USER_CONFIG) || (is_present == SHT21_DEFAULT_CONFIG)); + + return is_present; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint16_t +sht21_read_temperature(void) +{ + uint8_t sht21_temperature[2]; + uint16_t temperature; + + /* Read the current temperature according to the datasheet (pag. 8, fig. 15) */ + i2c_single_send(SHT21_ADDRESS, SHT21_TEMPERATURE_HM_CMD); + i2c_burst_receive(SHT21_ADDRESS, sht21_temperature, sizeof(sht21_temperature)); + + temperature = (sht21_temperature[0] << 8) | (sht21_temperature[1] & SHT21_STATUS_MASK); + + return temperature; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +float +sht21_convert_temperature(uint16_t temperature) +{ + float result; + + result = -46.85; + result += 175.72 * (float) temperature / 65536.0; + + return result; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +uint16_t +sht21_read_humidity(void) +{ + uint8_t sht21_humidity[2]; + uint16_t humidity; + + /* Read the current humidity according to the datasheet (pag. 8, fig. 15) */ + i2c_single_send(SHT21_ADDRESS, SHT21_HUMIDITY_HM_CMD); + i2c_burst_receive(SHT21_ADDRESS, sht21_humidity, sizeof(sht21_humidity)); + + humidity = (sht21_humidity[0] << 8) | (sht21_humidity[1] & SHT21_STATUS_MASK); + + return humidity; +} +/*---------------------------------------------------------------------------*/ +/** + * + */ +float +sht21_convert_humidity(uint16_t humidity) +{ + float result; + + result = -6.0; + result += 125.0 * (float) humidity / 65536.0; + + return result; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/sht21.h b/platform/openmote-cc2538/dev/sht21.h new file mode 100644 index 000000000..c95e02edf --- /dev/null +++ b/platform/openmote-cc2538/dev/sht21.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Header for the SHT21 temperature and humidity sensor in OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +#ifndef __SHT21_H__ +#define __SHT21_H__ +/*---------------------------------------------------------------------------*/ +void sht21_init(void); +void sht21_reset(void); +uint8_t sht21_is_present(void); +uint16_t sht21_read_temperature(void); +float sht21_convert_temperature(uint16_t temperature); +uint16_t sht21_read_humidity(void); +float sht21_convert_humidity(uint16_t humidity); +/*---------------------------------------------------------------------------*/ +#endif /* ifndef __SHT21_H__ */ +/** @} */ diff --git a/platform/openmote-cc2538/dev/smartrf-sensors.c b/platform/openmote-cc2538/dev/smartrf-sensors.c new file mode 100644 index 000000000..d8948a017 --- /dev/null +++ b/platform/openmote-cc2538/dev/smartrf-sensors.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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 platform + * @{ + * + * \defgroup openmote + * + * \file + * Implementation of a generic module controlling OpenMote-CC2538 sensors. + */ + +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/button-sensor.h" + +#include +/*---------------------------------------------------------------------------*/ +/** + *\brief Exports a global symbol to be used by the sensor API + */ +SENSORS(&button_user_sensor); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/tps62730.c b/platform/openmote-cc2538/dev/tps62730.c new file mode 100644 index 000000000..0356077f9 --- /dev/null +++ b/platform/openmote-cc2538/dev/tps62730.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Driver for the TPS62730 voltage regulator on the OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +#include "dev/gpio.h" +#include "dev/tps62730.h" +/*---------------------------------------------------------------------------*/ +#define BSP_TPS62730_BASE (GPIO_B_BASE) +#define BSP_TPS62730_ON (1 << 1) +#define BSP_TPS62730_STATUS (1 << 0) +/*---------------------------------------------------------------------------*/ +static void +gpio_set(int port, int bit) +{ + REG((port | GPIO_DATA) + (bit << 2)) = bit; +} +/*---------------------------------------------------------------------------*/ +static void +gpio_reset(int port, int bit) +{ + REG((port | GPIO_DATA) + (bit << 2)) = 0; +} +/*---------------------------------------------------------------------------*/ +/** + * Initializes the TPS62730 voltage regulator + * By default it is in bypass mode, Vout = Vin, Iq < 1 uA + */ +void +tps62730_init(void) +{ + GPIO_SET_OUTPUT(BSP_TPS62730_BASE, BSP_TPS62730_ON); + GPIO_SET_INPUT(BSP_TPS62730_BASE, BSP_TPS62730_STATUS); + + tps62730_bypass(); +} +/*---------------------------------------------------------------------------*/ +/** + * Enables the TPS62730, Vout = 2.2V, Iq = 30 uA + */ +void +tps62730_on(void) +{ + gpio_set(BSP_TPS62730_BASE, BSP_TPS62730_ON); +} +/*---------------------------------------------------------------------------*/ +/** + * Disables the TPS62730, Vout = Vin, Iq < 1 uA + */ +void +tps62730_bypass(void) +{ + gpio_reset(BSP_TPS62730_BASE, BSP_TPS62730_ON); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/openmote-cc2538/dev/tps62730.h b/platform/openmote-cc2538/dev/tps62730.h new file mode 100644 index 000000000..b3e99bc8d --- /dev/null +++ b/platform/openmote-cc2538/dev/tps62730.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \addtogroup platform + * @{ + * + * \defgroup openmote + * + * \file + * Header for the TPS62730 voltage regulator on the OpenMote-CC2538. + * + * \author + * Pere Tuset + */ + +#ifndef TPS62730_H_ +#define TPS62730_H_ +/*---------------------------------------------------------------------------*/ +void tps62730_init(void); +void tps62730_on(void); +void tps62730_bypass(void); +/*---------------------------------------------------------------------------*/ +#endif /* TPS62730_H_ */ +/** @} */ From 3e00ea55d1fce8a76df2ee2850541cac1fec65b4 Mon Sep 17 00:00:00 2001 From: Pere Tuset Date: Mon, 11 Apr 2016 15:32:29 +0200 Subject: [PATCH 2/2] Updated the OpenMote-CC2538 platform and examples. --- examples/openmote-cc2538/Makefile | 2 +- examples/openmote-cc2538/openmote-demo.c | 130 +++++++----- examples/openmote-cc2538/openmote-demo.gdb | 10 + examples/openmote-cc2538/project-conf.h | 8 +- examples/openmote-cc2538/test-adxl346.c | 86 -------- examples/openmote-cc2538/test-max44009.c | 86 -------- examples/openmote-cc2538/test-sht21.c | 92 --------- examples/openmote-cc2538/test-timer.c | 188 ----------------- .../openmote-cc2538/Makefile.openmote-cc2538 | 4 +- platform/openmote-cc2538/README.md | 189 ++++++++++++++++++ platform/openmote-cc2538/board.c | 5 +- platform/openmote-cc2538/board.h | 69 ++++--- platform/openmote-cc2538/contiki-conf.h | 75 +++++-- platform/openmote-cc2538/contiki-main.c | 38 ++-- platform/openmote-cc2538/dev/adxl346.c | 58 ++---- platform/openmote-cc2538/dev/adxl346.h | 46 ++++- platform/openmote-cc2538/dev/antenna.c | 56 ++---- platform/openmote-cc2538/dev/antenna.h | 31 ++- platform/openmote-cc2538/dev/button-sensor.c | 143 ++++++++----- platform/openmote-cc2538/dev/button-sensor.h | 41 ++-- platform/openmote-cc2538/dev/leds-arch.c | 20 +- platform/openmote-cc2538/dev/max44009.c | 71 +++---- platform/openmote-cc2538/dev/max44009.h | 42 +++- .../{smartrf-sensors.c => openmote-sensors.c} | 23 ++- .../openmote-cc2538/dev/openmote-sensors.h | 59 ++++++ platform/openmote-cc2538/dev/sht21.c | 81 ++++---- platform/openmote-cc2538/dev/sht21.h | 50 ++++- platform/openmote-cc2538/dev/tps62730.c | 27 +-- platform/openmote-cc2538/dev/tps62730.h | 32 ++- .../18-compile-arm-ports/Makefile | 1 + 30 files changed, 895 insertions(+), 868 deletions(-) create mode 100644 examples/openmote-cc2538/openmote-demo.gdb delete mode 100644 examples/openmote-cc2538/test-adxl346.c delete mode 100644 examples/openmote-cc2538/test-max44009.c delete mode 100644 examples/openmote-cc2538/test-sht21.c delete mode 100644 examples/openmote-cc2538/test-timer.c rename platform/openmote-cc2538/dev/{smartrf-sensors.c => openmote-sensors.c} (82%) create mode 100644 platform/openmote-cc2538/dev/openmote-sensors.h diff --git a/examples/openmote-cc2538/Makefile b/examples/openmote-cc2538/Makefile index 9f925fb70..e5e5eb4f3 100644 --- a/examples/openmote-cc2538/Makefile +++ b/examples/openmote-cc2538/Makefile @@ -1,6 +1,6 @@ DEFINES+=PROJECT_CONF_H=\"project-conf.h\" -CONTIKI_PROJECT = openmote-demo test-timer test-adxl346 test-max44009 test-sht21 +CONTIKI_PROJECT = openmote-demo all: $(CONTIKI_PROJECT) diff --git a/examples/openmote-cc2538/openmote-demo.c b/examples/openmote-cc2538/openmote-demo.c index 10a1c0762..f36c3a0b4 100644 --- a/examples/openmote-cc2538/openmote-demo.c +++ b/examples/openmote-cc2538/openmote-demo.c @@ -29,7 +29,7 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** * \addtogroup openmote-cc2538 * @{ @@ -37,65 +37,42 @@ * \defgroup openmote-examples OpenMote-CC2538 Example Projects * @{ * - * \defgroup openmote-demo OpenMote-CC2538 Demo Project - * - * Example project demonstrating the OpenMote-CC2538 functionality - * - * This assumes that you are using an OpenMote-CC2538 - * - * - Boot sequence: LEDs flashing, LED2 followed by LED3 then LED4 - * - etimer/clock : Every LOOP_INTERVAL clock ticks the LED defined as - * LEDS_PERIODIC will turn on - * - rtimer : Exactly LEDS_OFF_HYSTERISIS rtimer ticks later, - * LEDS_PERIODIC will turn back off - * - UART : Every LOOP_INTERVAL the EM will print something over the - * UART. Receiving an entire line of text over UART (ending - * in \\r) will cause LEDS_SERIAL_IN to toggle - * - Radio comms : BTN_SELECT sends a rime broadcast. Reception of a rime - * packet will toggle LEDs defined as LEDS_RF_RX + * Example project demonstrating the OpenMote-CC2538 functionality * * @{ * * \file - * Example demonstrating the OpenMote platform. + * Example demonstrating the OpenMote-CC2538 platform * \author - * Pere Tuset + * Pere Tuset */ +/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "cpu.h" #include "sys/etimer.h" -#include "sys/rtimer.h" #include "dev/leds.h" #include "dev/uart.h" #include "dev/button-sensor.h" -#include "dev/watchdog.h" #include "dev/serial-line.h" #include "dev/sys-ctrl.h" #include "net/rime/broadcast.h" +#include "dev/adxl346.h" +#include "dev/max44009.h" +#include "dev/sht21.h" + #include #include /*---------------------------------------------------------------------------*/ -#define LOOP_INTERVAL CLOCK_SECOND -#define LEDS_OFF_HYSTERISIS (RTIMER_SECOND >> 1) -#define LEDS_PERIODIC LEDS_YELLOW -#define LEDS_BUTTON LEDS_RED -#define LEDS_SERIAL_IN LEDS_ORANGE -#define LEDS_REBOOT LEDS_ALL -#define LEDS_RF_RX (LEDS_YELLOW | LEDS_ORANGE) #define BROADCAST_CHANNEL 129 /*---------------------------------------------------------------------------*/ -static struct etimer et; -static struct rtimer rt; -static uint16_t counter; -/*---------------------------------------------------------------------------*/ PROCESS(openmote_demo_process, "OpenMote-CC2538 demo process"); AUTOSTART_PROCESSES(&openmote_demo_process); /*---------------------------------------------------------------------------*/ static void broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) { - leds_toggle(LEDS_RF_RX); + leds_toggle(LEDS_GREEN); printf("Received %u bytes: '0x%04x'\n", packetbuf_datalen(), *(uint16_t *)packetbuf_dataptr()); } @@ -103,43 +80,92 @@ broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) static const struct broadcast_callbacks bc_rx = { broadcast_recv }; static struct broadcast_conn bc; /*---------------------------------------------------------------------------*/ -void -rt_callback(struct rtimer *t, void *ptr) -{ - leds_off(LEDS_PERIODIC); -} -/*---------------------------------------------------------------------------*/ PROCESS_THREAD(openmote_demo_process, ev, data) { + static struct etimer et; + static unsigned int raw, counter; + static uint8_t adxl346_present, max44009_present, sht21_present; + static float light, temperature, humidity; PROCESS_EXITHANDLER(broadcast_close(&bc)) PROCESS_BEGIN(); + adxl346_init(); + adxl346_present = adxl346_is_present(); + if(!adxl346_present) { + printf("ADXL346 sensor is NOT present!\n"); + leds_on(LEDS_YELLOW); + } + + max44009_init(); + max44009_present = max44009_is_present(); + if(!max44009_present) { + printf("MAX44009 sensor is NOT present!\n"); + leds_on(LEDS_ORANGE); + } + + sht21_init(); + sht21_present = sht21_is_present(); + if(!sht21_present) { + printf("SHT21 sensor is NOT present!\n"); + leds_on(LEDS_RED); + } + counter = 0; broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx); + printf("****************************************\n"); + while(1) { etimer_set(&et, CLOCK_SECOND); PROCESS_YIELD(); if(ev == PROCESS_EVENT_TIMER) { - leds_on(LEDS_PERIODIC); - printf("Counter = 0x%08x\n", counter); - - etimer_set(&et, CLOCK_SECOND); - rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1, - rt_callback, NULL); - } else if(ev == sensors_event) { - if(data == &button_user_sensor) { - packetbuf_copyfrom(&counter, sizeof(counter)); - broadcast_send(&bc); + if(adxl346_present) { + leds_on(LEDS_YELLOW); + raw = adxl346_read_x(); + printf("X Acceleration: %u\n", raw); + raw = adxl346_read_y(); + printf("Y Acceleration: %u\n", raw); + raw = adxl346_read_z(); + printf("Z Acceleration: %u\n", raw); + leds_off(LEDS_YELLOW); + } + + if(max44009_present) { + leds_on(LEDS_ORANGE); + raw = max44009_read_light(); + light = max44009_convert_light(raw); + printf("Light: %u.%ulux\n", (unsigned int)light, (unsigned int)(light * 100) % 100); + leds_off(LEDS_ORANGE); + } + + if(sht21_present) { + leds_on(LEDS_RED); + raw = sht21_read_temperature(); + temperature = sht21_convert_temperature(raw); + printf("Temperature: %u.%uC\n", (unsigned int)temperature, (unsigned int)(temperature * 100) % 100); + raw = sht21_read_humidity(); + humidity = sht21_convert_humidity(raw); + printf("Rel. humidity: %u.%u%%\n", (unsigned int)humidity, (unsigned int)(humidity * 100) % 100); + leds_off(LEDS_RED); + } + + printf("****************************************\n"); + } + + if(ev == sensors_event) { + if(data == &button_sensor) { + if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == + BUTTON_SENSOR_PRESSED_LEVEL) { + leds_toggle(LEDS_GREEN); + packetbuf_copyfrom(&counter, sizeof(counter)); + broadcast_send(&bc); + } } - } else if(ev == serial_line_event_message) { - leds_toggle(LEDS_SERIAL_IN); } - counter++; } PROCESS_END(); diff --git a/examples/openmote-cc2538/openmote-demo.gdb b/examples/openmote-cc2538/openmote-demo.gdb new file mode 100644 index 000000000..43cbb5530 --- /dev/null +++ b/examples/openmote-cc2538/openmote-demo.gdb @@ -0,0 +1,10 @@ +target remote localhost:2331 +monitor interface JTAG +monitor endian little +monitor speed auto +monitor flash device = CC2538SF53 +monitor flash breakpoints = 1 +monitor flash download = 1 +monitor reset +load +continue diff --git a/examples/openmote-cc2538/project-conf.h b/examples/openmote-cc2538/project-conf.h index 126ea1058..718ce668d 100644 --- a/examples/openmote-cc2538/project-conf.h +++ b/examples/openmote-cc2538/project-conf.h @@ -10,7 +10,6 @@ * 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. @@ -35,12 +34,13 @@ * \file * Project specific configuration defines for the basic RE-Mote examples */ +/*---------------------------------------------------------------------------*/ #ifndef PROJECT_CONF_H_ #define PROJECT_CONF_H_ - +/*---------------------------------------------------------------------------*/ #define BROADCAST_CHANNEL 129 #define NETSTACK_CONF_RDC nullrdc_driver - +/*---------------------------------------------------------------------------*/ #endif /* PROJECT_CONF_H_ */ - +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/examples/openmote-cc2538/test-adxl346.c b/examples/openmote-cc2538/test-adxl346.c deleted file mode 100644 index 1a750a67c..000000000 --- a/examples/openmote-cc2538/test-adxl346.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014, OpenMote Technologies, S.L. - * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - -/** - * \addtogroup openmote-examples - * @{ - * - * \defgroup openmote-adxl346 - * - * This example tests the correct functionality of the ADXL346 acceleration - * sensor using the I2C bus. - * - * @{ - * - * \file - * Testing the ADXL346 sensor on the OpenMote-CC2538 platform. - * \author - * Pere Tuset - */ - -#include "contiki.h" -#include "dev/adxl346.h" - -#include - -PROCESS(test_adxl346_process, "ADXL346 test"); -AUTOSTART_PROCESSES(&test_adxl346_process); - -PROCESS_THREAD(test_adxl346_process, ev, data) -{ - static struct etimer et; - static unsigned acceleration; - - PROCESS_BEGIN(); - adxl346_init(); - - if (!adxl346_is_present()) { - leds_on(LEDS_ORANGE); - } - - while(1) { - etimer_set(&et, CLOCK_SECOND); - - PROCESS_YIELD(); - - if (ev == PROCESS_EVENT_TIMER) { - acceleration = adxl346_read_x(); - printf("X Acceleration: %u\n", acceleration); - acceleration = adxl346_read_y(); - printf("Y Acceleration: %u\n", acceleration); - acceleration = adxl346_read_z(); - printf("Z Acceleration: %u\n", acceleration); - } - } - - PROCESS_END(); -} diff --git a/examples/openmote-cc2538/test-max44009.c b/examples/openmote-cc2538/test-max44009.c deleted file mode 100644 index 8085283ca..000000000 --- a/examples/openmote-cc2538/test-max44009.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2014, OpenMote Technologies, S.L. - * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - -/** - * \addtogroup openmote-examples - * @{ - * - * \defgroup openmote-max44009 - * - * This example tests the correct functionality of the MAX44009 light - * sensor using the I2C bus. - * - * @{ - * - * \file - * Testing the MAX44009 sensor on the OpenMote-CC2538 platform. - * \author - * Pere Tuset - */ - -#include "contiki.h" -#include "dev/max44009.h" -#include "dev/leds.h" -#include - -PROCESS(test_max44009_process, "MAX44009 test"); -AUTOSTART_PROCESSES(&test_max44009_process); - -PROCESS_THREAD(test_max44009_process, ev, data) -{ - static struct etimer et; - static unsigned raw; - static float light; - - PROCESS_BEGIN(); - max44009_init(); - -if (!max44009_is_present()) { - leds_on(LEDS_ORANGE); - } - - while(1) { - etimer_set(&et, CLOCK_SECOND); - - PROCESS_YIELD(); - - if (ev == PROCESS_EVENT_TIMER) { - leds_on(LEDS_YELLOW); - raw = max44009_read_light(); - light = max44009_convert_light(raw); - printf("Light: %u.%u\n", (unsigned int) light, (unsigned int) (light * 100) % 100); - leds_off(LEDS_YELLOW); - } - } - - PROCESS_END(); -} diff --git a/examples/openmote-cc2538/test-sht21.c b/examples/openmote-cc2538/test-sht21.c deleted file mode 100644 index cefdb3266..000000000 --- a/examples/openmote-cc2538/test-sht21.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2014, OpenMote Technologies, S.L. - * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - -/** - * \addtogroup openmote-examples - * @{ - * - * \defgroup openmote-sht21 - * - * This example tests the correct functionality of the SHT21 temperature - * and humidity sensor using the I2C bus. - * - * @{ - * - * \file - * Testing the SHT21 sensor on the OpenMote-CC2538 platform. - * \author - * Pere Tuset - */ - -#include "contiki.h" -#include "dev/sht21.h" -#include "dev/leds.h" -#include "sys/etimer.h" - -#include - -PROCESS(test_sht21_process, "SHT21 test"); -AUTOSTART_PROCESSES(&test_sht21_process); - -PROCESS_THREAD(test_sht21_process, ev, data) -{ - static struct etimer et; - static unsigned raw; - static float temperature; - static float humidity; - - PROCESS_BEGIN(); - sht21_init(); - - if (!sht21_is_present()) { - leds_on(LEDS_ORANGE); - } - - while(1) { - etimer_set(&et, CLOCK_SECOND); - - PROCESS_YIELD(); - - if (ev == PROCESS_EVENT_TIMER) { - leds_on(LEDS_YELLOW); - raw = sht21_read_temperature(); - temperature = sht21_convert_temperature(raw); - printf("Temperature: %u.%u degrees Celsius\n", (unsigned int) temperature, (unsigned int) (temperature * 100) % 100); - raw = sht21_read_humidity(); - humidity = sht21_convert_humidity(raw); - printf("Rel. humidity: %u.%u%%\n", (unsigned int) humidity, (unsigned int) (humidity * 100) % 100); - leds_off(LEDS_YELLOW ); - } - } - - PROCESS_END(); -} diff --git a/examples/openmote-cc2538/test-timer.c b/examples/openmote-cc2538/test-timer.c deleted file mode 100644 index 3eb8ff2ff..000000000 --- a/examples/openmote-cc2538/test-timer.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2014, OpenMote Technologies, S.L. - * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - -/** - * \addtogroup openmote-examples - * @{ - * - * \defgroup openmote-timers OpenMote-CC2538 Timer Test Project - * - * This example tests the correct functionality of clocks and timers. - * - * More specifically, it tests clock_seconds, rtimers, etimers and - * clock_delay_usec. - * - * This is largely-based on the same example of the cc2530 port. - * @{ - * - * \file - * Tests related to clocks and timers. - * \author - * Pere Tuset - */ - -#include "contiki.h" -#include "sys/clock.h" -#include "sys/rtimer.h" -#include "dev/leds.h" - -#include -/*---------------------------------------------------------------------------*/ -#define TIMER_TEST_CONF_TEST_CLOCK_DELAY_USEC 1 -#define TIMER_TEST_CONF_TEST_RTIMER 1 -#define TIMER_TEST_CONF_TEST_ETIMER 1 -#define TIMER_TEST_CONF_TEST_CLOCK_SECONDS 1 -/*---------------------------------------------------------------------------*/ -static struct etimer et; - -#if TIMER_TEST_CONF_TEST_CLOCK_DELAY_USEC -static rtimer_clock_t start_count, end_count, diff; -#endif - -#if TIMER_TEST_CONF_TEST_CLOCK_SECONDS -static unsigned long sec; -#endif - -#if TIMER_TEST_CONF_TEST_ETIMER -static clock_time_t count; -#endif - -#if TIMER_TEST_CONF_TEST_RTIMER -static struct rtimer rt; -rtimer_clock_t rt_now, rt_for; -static clock_time_t ct; -#endif - -static uint8_t i; -/*---------------------------------------------------------------------------*/ -PROCESS(timer_test_process, "Timer test process"); -AUTOSTART_PROCESSES(&timer_test_process); -/*---------------------------------------------------------------------------*/ -#if TIMER_TEST_CONF_TEST_RTIMER -void -rt_callback(struct rtimer *t, void *ptr) -{ - rt_now = RTIMER_NOW(); - ct = clock_time(); - printf("Task called at %lu (clock = %lu)\n", rt_now, ct); -} -#endif -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(timer_test_process, ev, data) -{ - - PROCESS_BEGIN(); - - etimer_set(&et, 2 * CLOCK_SECOND); - - PROCESS_YIELD(); - -#if TIMER_TEST_CONF_TEST_CLOCK_DELAY_USEC - printf("-----------------------------------------\n"); - printf("clock_delay_usec test, (10,000 x i) usec:\n"); - printf("N.B. clock_delay_usec is more accurate than rtimers\n"); - i = 1; - while(i < 7) { - start_count = RTIMER_NOW(); - clock_delay_usec(10000 * i); - end_count = RTIMER_NOW(); - diff = end_count - start_count; - printf("Requested: %u usec, Real: %lu rtimer ticks = ~%lu us\n", - 10000 * i, diff, diff * 1000000 / RTIMER_SECOND); - i++; - } -#endif - -#if TIMER_TEST_CONF_TEST_RTIMER - printf("-----------------------------------------\n"); - printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND); - i = 0; - while(i < 5) { - etimer_set(&et, 2 * CLOCK_SECOND); - printf("=======================\n"); - ct = clock_time(); - rt_now = RTIMER_NOW(); - rt_for = rt_now + RTIMER_SECOND; - printf("Now=%lu (clock = %lu) - For=%lu\n", rt_now, ct, rt_for); - if(rtimer_set(&rt, rt_for, 1, rt_callback, NULL) != RTIMER_OK) { - printf("Error setting\n"); - } - - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - i++; - } -#endif - -#if TIMER_TEST_CONF_TEST_ETIMER - printf("-----------------------------------------\n"); - printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", - CLOCK_SECOND); - i = 0; - while(i < 10) { - etimer_set(&et, CLOCK_SECOND); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - etimer_reset(&et); - - count = clock_time(); - printf("%lu ticks\n", count); - - leds_toggle(LEDS_RED); - i++; - } -#endif - -#if TIMER_TEST_CONF_TEST_CLOCK_SECONDS - printf("-----------------------------------------\n"); - printf("Clock seconds test (5s):\n"); - i = 0; - while(i < 10) { - etimer_set(&et, 5 * CLOCK_SECOND); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - etimer_reset(&et); - - sec = clock_seconds(); - printf("%lu seconds\n", sec); - - leds_toggle(LEDS_GREEN); - i++; - } -#endif - - printf("Done!\n"); - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/** - * @} - * @} - */ diff --git a/platform/openmote-cc2538/Makefile.openmote-cc2538 b/platform/openmote-cc2538/Makefile.openmote-cc2538 index 878b81877..3439a3211 100644 --- a/platform/openmote-cc2538/Makefile.openmote-cc2538 +++ b/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -10,7 +10,7 @@ PLATFORM_ROOT_DIR = $(CONTIKI)/platform/$(TARGET) ### Include CONTIKI_TARGET_SOURCEFILES += contiki-main.c board.c -CONTIKI_TARGET_SOURCEFILES += leds-arch.c button-sensor.c smartrf-sensors.c +CONTIKI_TARGET_SOURCEFILES += leds-arch.c button-sensor.c openmote-sensors.c CONTIKI_TARGET_SOURCEFILES += antenna.c adxl346.c max44009.c sht21.c tps62730.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) @@ -31,7 +31,7 @@ MODULES += core/net core/net/mac \ core/net/llsec core/net/llsec/noncoresec PYTHON = python -BSL_FLAGS += -e -w --bootloader-invert-lines -b 115200 -v +BSL_FLAGS += -e -w -v -b 450000 ifdef PORT BSL_FLAGS += -p $(PORT) diff --git a/platform/openmote-cc2538/README.md b/platform/openmote-cc2538/README.md index e69de29bb..2f3ee7d07 100644 --- a/platform/openmote-cc2538/README.md +++ b/platform/openmote-cc2538/README.md @@ -0,0 +1,189 @@ +OpenMote-CC2538 platform +======================== +The OpenMote-CC2538 is based on TI's CC2538 SoC (System on Chip), featuring an ARM Cortex-M3 running at 16/32 MHz and with 32 kbytes of RAM and 512 kbytes of FLASH. It has the following key features: + + * Standard Cortex M3 peripherals (NVIC, SCB, SysTick) + * Sleep Timer (underpins rtimers) + * SysTick (underpins the platform clock and Contiki's timers infrastructure) + * RF (2.4 GHz) + * UART + * Watchdog (in watchdog mode) + * USB (in CDC-ACM) + * uDMA Controller (RAM to/from USB and RAM to/from RF) + * Random number generator + * Low Power Modes + * General-Purpose Timers + * ADC + * Cryptoprocessor (AES-ECB/CBC/CTR/CBC-MAC/GCM/CCM-128/192/256, SHA-256) + * Public Key Accelerator (ECDH, ECDSA) + * Flash-based port of Coffee + * PWM + * Built-in core temperature and battery sensor + +Requirements +============ +To start using Contiki with the OpenMote-CC2538, the following is required: + + * An OpenMote-CC2538 board. + * A toolchain to compile Contiki for the CC2538. + * Drivers so that your OS can communicate with your hardware. + * Software to upload images to the CC2538. + +Install a Toolchain +------------------- +The toolchain used to build contiki is arm-gcc, also used by other arm-based Contiki ports. If you are using Instant Contiki, you may have a version pre-installed in your system. + +The platform is currently being used/tested with "GNU Tools for ARM Embedded Processors" (). The current recommended version and the one being used by Contiki's regression tests on Travis is shown below. + + $ arm-none-eabi-gcc --version + arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.2.1 20151202 (release) [ARM/embedded-5-branch revision 231848] + Copyright (C) 2015 Free Software Foundation, Inc. + This is free software; see the source for copying conditions. There is NO + warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +Software to Program the Nodes +----------------------------- +The OpenMote-CC2538 can be programmed via the jtag interface or via the serial boot loader on the chip. + +The OpenMote-CC2538 has a mini JTAG 10-pin male header, compatible with the `SmartRF06` development board, which can be used to flash and debug the platforms. Alternatively one could use the `JLink` programmer with a 20-to-10 pin converter like the following: . + +The serial boot loader on the chip is exposed to the user via the USB interface. To activate the bootloader short the ON/SLEEP pin to GND and then press the reset button. + +Instructions to flash for different OS are given below. + +* On Windows: + * Nodes can be programmed with TI's ArmProgConsole or the SmartRF Flash Programmer 2. The README should be self-explanatory. With ArmProgConsole, upload the file with a `.bin` extension. + * Nodes can also be programmed via the serial boot loader in the cc2538. In `tools/cc2538-bsl/` you can find `cc2538-bsl.py` python script, which can download firmware to your node via a serial connection. If you use this option you just need to make sure you have a working version of python installed. You can read the README in the same directory for more info. + +* On Linux: + * Nodes can be programmed with TI's [UniFlash] tool. With UniFlash, use the file with `.elf` extension. + * Nodes can also be programmed via the serial boot loader in the cc2538. No extra software needs to be installed. + +* On OSX: + * The `cc2538-bsl.py` script in `tools/cc2538-bsl/` is the only option. No extra software needs to be installed. + +Use the Port +============ +The following examples are intended to work off-the-shelf: + +* Examples under `examples/openmote-cc2538` +* MQTT example `examples/cc2538dk/mqtt-demo` +* Border router: `examples/ipv6/rpl-border-router` +* Webserver: `examples/webserver-ipv6` +* CoAP example: `examples/er-rest-example` + +Build your First Examples +------------------------- +It is recommended to start with the `openmote-demo`, it is a simple example that demonstrates the OpenMote-CC2538 features, such as the built-in sensors, LEDs, user button and radio (using RIME broadcast). + +The `Makefile.target` includes the `TARGET=` argument, predefining which is the target platform to compile for, it is automatically included at compilation. + +To generate or override an existing one, you can run: + +`make TARGET=openmote-cc2538 savetarget` + +Then you can just run `make` to compile an application, otherwise you will need to do `make TARGET=openmote-cc2538`. + +If you want to upload the compiled firmware to a node via the serial boot loader you need first to either manually enable the boot loader. + +Then use `make openmote-demo.upload`. + +The `PORT` argument could be used to specify in which port the device is connected, in case we have multiple devices connected at the same time. + +To generate an assembly listing of the compiled firmware, run `make openmote-demo.lst`. This may be useful for debugging or optimizing your application code. To intersperse the C source code within the assembly listing, you must instruct the compiler to include debugging information by adding `CFLAGS += -g` to the project Makefile and rebuild by running `make clean openmote-demo.lst`. + +To enable printing debug output to your console, use the `make login` to get the information over the USB programming/debugging port, or alternatively use `make serialview` to also add a timestamp in each print. + +Node IEEE/RIME/IPv6 Addresses +----------------------------- + +Nodes will generally autoconfigure their IPv6 address based on their IEEE address. The IEEE address can be read directly from the CC2538 Info Page, or it can be hard-coded. Additionally, the user may specify a 2-byte value at build time, which will be used as the IEEE address' 2 LSBs. + +To configure the IEEE address source location (Info Page or hard-coded), use the `IEEE_ADDR_CONF_HARDCODED` define in contiki-conf.h: + +* 0: Info Page +* 1: Hard-coded + +If `IEEE_ADDR_CONF_HARDCODED` is defined as 1, the IEEE address will take its value from the `IEEE_ADDR_CONF_ADDRESS` define. If `IEEE_ADDR_CONF_HARDCODED` is defined as 0, the IEEE address can come from either the primary or secondary location in the Info Page. To use the secondary address, define `IEEE_ADDR_CONF_USE_SECONDARY_LOCATION` as 1. + +Additionally, you can override the IEEE's 2 LSBs, by using the `NODEID` make variable. The value of `NODEID` will become the value of the `IEEE_ADDR_NODE_ID` pre-processor define. If `NODEID` is not defined, `IEEE_ADDR_NODE_ID` will not get defined either. For example: + + make NODEID=0x79ab + +This will result in the 2 last bytes of the IEEE address getting set to 0x79 0xAB + +Note: Some early production devices do not have am IEEE address written on the Info Page. For those devices, using value 0 above will result in a Rime address of all 0xFFs. If your device is in this category, define `IEEE_ADDR_CONF_HARDCODED` to 1 and specify `NODEID` to differentiate between devices. + +Low-Power Modes +--------------- +The CC2538 port supports power modes for low energy consumption. The SoC will enter a low power mode as part of the main loop when there are no more events to service. + +LPM support can be disabled in its entirety by setting `LPM_CONF_ENABLE` to 0 in `contiki-conf.h` or `project-conf.h`. + +The Low-Power module uses a simple heuristic to determine the best power mode, depending on anticipated Deep Sleep duration and the state of various peripherals. + +In a nutshell, the algorithm first answers the following questions: + +* Is the RF off? +* Are all registered peripherals permitting PM1+? +* Is the Sleep Timer scheduled to fire an interrupt? + +If the answer to any of the above question is "No", the SoC will enter PM0. If the answer to all questions is "Yes", the SoC will enter one of PMs 0/1/2 depending on the expected Deep Sleep duration and subject to user configuration and application requirements. + +At runtime, the application may enable/disable some Power Modes by making calls to `lpm_set_max_pm()`. For example, to avoid PM2 an application could call `lpm_set_max_pm(1)`. Subsequently, to re-enable PM2 the application would call `lpm_set_max_pm(2)`. + +The LPM module can be configured with a hard maximum permitted power mode. + + #define LPM_CONF_MAX_PM N + +Where N corresponds to the PM number. Supported values are 0, 1, 2. PM3 is not supported. Thus, if the value of the define is 1, the SoC will only ever enter PMs 0 or 1 but never 2 and so on. + +The configuration directive `LPM_CONF_MAX_PM` sets a hard upper boundary. For instance, if `LPM_CONF_MAX_PM` is defined as 1, calls to `lpm_set_max_pm()` can only enable/disable PM1. In this scenario, PM2 can not be enabled at runtime. + +When setting `LPM_CONF_MAX_PM` to 0 or 1, the entire SRAM will be available. Crucially, when value 2 is used the linker will automatically stop using the SoC's SRAM non-retention area, resulting in a total available RAM of 16 kbytes instead of 32 kbytes. + +### LPM and Duty Cycling Driver +LPM is highly related to the operations of the Radio Duty Cycling (RDC) driver of the Contiki network stack and will work correctly with ContikiMAC and NullRDC. + +* With ContikiMAC, PMs 0/1/2 are supported subject to user configuration. +* When NullRDC is in use, the radio will be always on. As a result, the algorithm discussed above will always choose PM0 and will never attempt to drop to PM1/2. + +Build headless nodes +-------------------- +It is possible to turn off all character I/O for nodes not connected to a PC. Doing this will entirely disable the UART as well as the USB controller, preserving energy in the long term. The define used to achieve this is (1: Quiet, 0: Normal output): + + #define CC2538_CONF_QUIET 0 + +Setting this define to 1 will automatically set the following to 0: + +* `USB_SERIAL_CONF_ENABLE` +* `UART_CONF_ENABLE` +* `STARTUP_CONF_VERBOSE` + +Code Size Optimisations +----------------------- +The build system currently uses optimization level `-Os`, which is controlled indirectly through the value of the `SMALL` make variable. This value can be overridden by example makefiles, or it can be changed directly in `platform/openmote-cc2538/Makefile.openmote-cc2538`. + +Historically, the `-Os` flag has caused problems with some toolchains. If you are using one of the toolchains documented in this README, you should be able to use it without issues. If for whatever reason you do come across problems, try setting `SMALL=0` or replacing `-Os` with `-O2` in `cpu/cc2538/Makefile.cc2538`. + +Doxygen Documentation +===================== +This port's code has been documented with doxygen. To build the documentation, navigate to `$(CONTIKI)/doc` and run `make`. This will build the entire contiki documentation and may take a while. + +If you want to build this platform's documentation only and skip the remaining platforms, run this: + + make basedirs="platform/openmote-cc2538 core cpu/cc2538 examples/openmote-cc2538 examples/openmote-cc2538" + +Once you've built the docs, open `$(CONTIKI)/doc/html/index.html` and enjoy. + +Other Versions of this Guide +============================ +If you prefer this guide in other formats, use the excellent [pandoc] to convert it. + +* **pdf**: `pandoc -s --toc README.md -o README.pdf` +* **html**: `pandoc -s --toc README.md -o README.html` + +Maintainers +=========== +The OpenMote-CC2538 is maintained by OpenMote Technologies. +Main contributor: Pere Tuset diff --git a/platform/openmote-cc2538/board.c b/platform/openmote-cc2538/board.c index 0b565b43c..c27812a9a 100644 --- a/platform/openmote-cc2538/board.c +++ b/platform/openmote-cc2538/board.c @@ -26,6 +26,9 @@ * 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. + * + * This file is part of the Contiki operating system. + * */ /*---------------------------------------------------------------------------*/ /** @@ -34,7 +37,6 @@ * * \file * Board-initialisation for the OpenMote-CC2538 platform - * */ /*---------------------------------------------------------------------------*/ #include "contiki-conf.h" @@ -58,4 +60,3 @@ board_init() /** * @} */ - diff --git a/platform/openmote-cc2538/board.h b/platform/openmote-cc2538/board.h index 08538a995..9c9a62bc1 100644 --- a/platform/openmote-cc2538/board.h +++ b/platform/openmote-cc2538/board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,7 +10,6 @@ * 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. @@ -27,22 +26,24 @@ * 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. + * + * This file is part of the Contiki operating system. + * */ - +/* -------------------------------------------------------------------------- */ /** - * \addtogroup platform + * \addtogroup openmote-cc2538 * @{ * - * \defgroup openmote - * * \file - * Header file with definitions related to the I/O connections on the - * OpenMote-CC2538 platform. This file provides connectivity information on - * LEDs, Buttons, UART and other peripherals. + * This file provides connectivity information on LEDs, Buttons, UART and + * other OpenMote-CC2538 peripherals. * - * \note - * Do not include this file directly. It gets included by contiki-conf - * after all relevant directives have been set. + * This file can be used as the basis to configure other platforms using the + * cc2538 SoC. + * + * \note Do not include this file directly. It gets included by contiki-conf + * after all relevant directives have been set. */ #ifndef BOARD_H_ @@ -69,7 +70,7 @@ #undef LEDS_RED #undef LEDS_CONF_ALL -#define LEDS_RED 16 /**< LED1 (Red) -> PC4 */ +#define LEDS_RED 16 /**< LED1 (Red) -> PC4 */ #define LEDS_YELLOW 64 /**< LED2 (Yellow) -> PC6 */ #define LEDS_GREEN 128 /**< LED3 (Green) -> PC7 */ #define LEDS_ORANGE 32 /**< LED4 (Orange) -> PC5 */ @@ -102,15 +103,17 @@ */ #define UART0_RX_PORT GPIO_A_NUM #define UART0_RX_PIN 0 - #define UART0_TX_PORT GPIO_A_NUM #define UART0_TX_PIN 1 -#define UART1_CTS_PORT GPIO_B_NUM -#define UART1_CTS_PIN 0 - -#define UART1_RTS_PORT GPIO_D_NUM -#define UART1_RTS_PIN 3 +#define UART1_RX_PORT GPIO_B_NUM +#define UART1_RX_PIN 0 +#define UART1_TX_PORT GPIO_D_NUM +#define UART1_TX_PIN 3 +#define UART1_CTS_PORT (-1) +#define UART1_CTS_PIN (-1) +#define UART1_RTS_PORT (-1) +#define UART1_RTS_PIN (-1) /** @} */ /*---------------------------------------------------------------------------*/ /** \name OpenMote-CC2538 Button configuration @@ -128,9 +131,11 @@ /** @} */ /*---------------------------------------------------------------------------*/ /** - * \name SPI configuration + * \name SPI (SSI0) configuration * - * These values configure which CC2538 pins to use for the SPI lines. + * These values configure which CC2538 pins to use for the SPI (SSI0) lines. + * The SSI0 is currently used to interface with the Ethernet driver (ENC28J60) + * on the OpenBase board. * @{ */ #define SPI_CLK_PORT GPIO_A_NUM @@ -139,8 +144,21 @@ #define SPI_MOSI_PIN 5 #define SPI_MISO_PORT GPIO_A_NUM #define SPI_MISO_PIN 4 -#define SPI_SEL_PORT GPIO_A_NUM -#define SPI_SEL_PIN 3 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SPI (SSI1) configuration + * + * These values configure which CC2538 pins to use for the SPI (SSI1) lines. + * The SSI1 is currently not used. + * @{ + */ +#define SPI1_CLK_PORT GPIO_C_NUM +#define SPI1_CLK_PIN 4 +#define SPI1_TX_PORT GPIO_C_NUM +#define SPI1_TX_PIN 5 +#define SPI1_RX_PORT GPIO_C_NUM +#define SPI1_RX_PIN 6 /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -163,4 +181,7 @@ /** @} */ /*---------------------------------------------------------------------------*/ #endif /* BOARD_H_ */ -/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/platform/openmote-cc2538/contiki-conf.h b/platform/openmote-cc2538/contiki-conf.h index 44a15e539..6c0349025 100644 --- a/platform/openmote-cc2538/contiki-conf.h +++ b/platform/openmote-cc2538/contiki-conf.h @@ -1,9 +1,48 @@ +/* + * Copyright (c) 2014, OpenMote Technologies, S.L. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ +/*---------------------------------------------------------------------------*/ /** - * \addtogroup openmote + * \addtogroup openmote-cc2538 * @{ * + * \defgroup openmote-cc2538-platforms OpenMote-CC2538 platform + * + * The OpenMote-CC2538 platform was designed at UC Berkeley in 2013 and + * is comercialized by OpenMote Technologies since 2014. It is the first + * commercial platform based on the powerful TI CC2538 SoC. It uses a + * XBee form-factor to ease prototyping. + * * \file - * Configuration for the OpenMote-CC2538 platform. + * Configuration for the OpenMote-CC2538 platform */ #ifndef CONTIKI_CONF_H_ #define CONTIKI_CONF_H_ @@ -48,7 +87,7 @@ typedef uint32_t rtimer_clock_t; #ifndef FLASH_CCA_CONF_BOOTLDR_BACKDOOR #define FLASH_CCA_CONF_BOOTLDR_BACKDOOR 1 /** 0); - /* We have serviced all pending events. Enter a Low-Power mode. */ lpm_enter(); } } /*---------------------------------------------------------------------------*/ - /** * @} * @} diff --git a/platform/openmote-cc2538/dev/adxl346.c b/platform/openmote-cc2538/dev/adxl346.c index bdb934d2d..650b7cfda 100644 --- a/platform/openmote-cc2538/dev/adxl346.c +++ b/platform/openmote-cc2538/dev/adxl346.c @@ -29,29 +29,33 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-adxl346-sensor * @{ * - * \defgroup openmote - * * \file - * Driver for the ADXL346 acceleration sensor in OpenMote-CC2538. + * Driver for the ADXL346 acceleration sensor * * \author * Pere Tuset */ - /*---------------------------------------------------------------------------*/ #include "dev/i2c.h" #include "dev/adxl346.h" /*---------------------------------------------------------------------------*/ -/* ADDRESS AND IDENTIFIER */ +/** + * \name ADXL346 address and device identifier + * @{ + */ #define ADXL346_ADDRESS (0x53) #define ADXL346_DEVID_VALUE (0xE6) - -/* REGISTER ADDRESSES */ +/** @} */ +/* -------------------------------------------------------------------------- */ +/** + * \name ADXL346 register addresses + * @{ + */ #define ADXL346_DEVID_ADDR (0x00) #define ADXL346_THRES_TAP_ADDR (0x1D) #define ADXL346_OFSX_ADDR (0x1E) @@ -85,8 +89,12 @@ #define ADXL346_TAP_SIGN_ADDR (0x3A) #define ADXL346_ORIENT_CONF_ADDR (0x3B) #define ADXL346_ORIENT_ADDR (0x3C) - -/* INT_ENABLE/INT_MAP/INT_SOURCE */ +/** @} */ +/* -------------------------------------------------------------------------- */ +/** + * \name ADXL346 register values + * @{ + */ #define ADXL346_INT_ENABLE_DATA_READY (1 << 7) #define ADXL346_INT_ENABLE_SINGLE_TAP (1 << 6) #define ADXL346_INT_ENABLE_DOUBLE_TAP (1 << 5) @@ -96,7 +104,6 @@ #define ADXL346_INT_ENABLE_WATERMARK (1 << 1) #define ADXL346_INT_ENABLE_OVERRUN (1 << 0) -/* ACT_INACT_CONTROL */ #define ADXL346_ACT_INACT_CTL_ACT_ACDC (1 << 7) #define ADXL346_ACT_INACT_CTL_ACT_X_EN (1 << 6) #define ADXL346_ACT_INACT_CTL_ACT_Y_EN (1 << 5) @@ -106,13 +113,11 @@ #define ADXL346_ACT_INACT_CTL_INACT_Y_EN (1 << 1) #define ADXL346_ACT_INACT_CTL_INACT_Z_EN (1 << 0) -/* TAP_AXES */ #define ADXL346_TAP_AXES_SUPPRESS (1 << 3) #define ADXL346_TAP_AXES_TAP_X_EN (1 << 2) #define ADXL346_TAP_AXES_TAP_Y_EN (1 << 1) #define ADXL346_TAP_AXES_TAP_Z_EN (1 << 0) -/* ACT_TAP_STATUS */ #define ADXL346_ACT_TAP_STATUS_ACT_X_SRC (1 << 6) #define ADXL346_ACT_TAP_STATUS_ACT_Y_SRC (1 << 5) #define ADXL346_ACT_TAP_STATUS_ACT_Z_SRC (1 << 4) @@ -121,18 +126,15 @@ #define ADXL346_ACT_TAP_STATUS_TAP_Y_SRC (1 << 1) #define ADXL346_ACT_TAP_STATUS_TAP_Z_SRC (1 << 0) -/* BW_RATE */ #define ADXL346_BW_RATE_POWER (1 << 4) #define ADXL346_BW_RATE_RATE(x) ((x) & 0x0F) -/* POWER CONTROL */ #define ADXL346_POWER_CTL_LINK (1 << 5) #define ADXL346_POWER_CTL_AUTO_SLEEP (1 << 4) #define ADXL346_POWER_CTL_MEASURE (1 << 3) #define ADXL346_POWER_CTL_SLEEP (1 << 2) #define ADXL346_POWER_CTL_WAKEUP(x) ((x) & 0x03) -/* DATA_FORMAT */ #define ADXL346_DATA_FORMAT_SELF_TEST (1 << 7) #define ADXL346_DATA_FORMAT_SPI (1 << 6) #define ADXL346_DATA_FORMAT_INT_INVERT (1 << 5) @@ -143,18 +145,13 @@ #define ADXL346_DATA_FORMAT_RANGE_PM_4g (1) #define ADXL346_DATA_FORMAT_RANGE_PM_8g (2) #define ADXL346_DATA_FORMAT_RANGE_PM_16g (3) +/** @} */ /*---------------------------------------------------------------------------*/ -/** - * - */ void adxl346_init(void) { uint8_t config[2]; - i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, - I2C_SCL_NORMAL_BUS_SPEED); - config[0] = ADXL346_BW_RATE_ADDR; config[1] = (ADXL346_BW_RATE_RATE(11)); i2c_burst_send(ADXL346_ADDRESS, config, sizeof(config)); @@ -170,17 +167,11 @@ adxl346_init(void) i2c_burst_send(ADXL346_ADDRESS, config, sizeof(config)); } /*---------------------------------------------------------------------------*/ -/** - * - */ void adxl346_reset(void) { } /*---------------------------------------------------------------------------*/ -/** - * - */ uint8_t adxl346_is_present(void) { @@ -192,9 +183,6 @@ adxl346_is_present(void) return is_present == ADXL346_DEVID_VALUE; } /*---------------------------------------------------------------------------*/ -/** - * - */ uint16_t adxl346_read_x(void) { @@ -211,9 +199,6 @@ adxl346_read_x(void) return x; } /*---------------------------------------------------------------------------*/ -/** - * - */ uint16_t adxl346_read_y(void) { @@ -230,9 +215,6 @@ adxl346_read_y(void) return y; } /*---------------------------------------------------------------------------*/ -/** - * - */ uint16_t adxl346_read_z(void) { diff --git a/platform/openmote-cc2538/dev/adxl346.h b/platform/openmote-cc2538/dev/adxl346.h index d5e9eac76..d5751ce70 100644 --- a/platform/openmote-cc2538/dev/adxl346.h +++ b/platform/openmote-cc2538/dev/adxl346.h @@ -29,29 +29,57 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-sensors * @{ * - * \defgroup openmote + * \defgroup openmote-adxl346-sensor ADXL346 acceleration sensor + * @{ * * \file - * Header for the ADXL346 acceleration sensor in OpenMote-CC2538. + * ADXL346 acceleration sensor driver header file * * \author * Pere Tuset */ - -#ifndef __ADXL346_H__ -#define __ADXL346_H__ /*---------------------------------------------------------------------------*/ +#ifndef ADXL346_H_ +#define ADXL346_H_ +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the ADXL346 sensor + */ void adxl346_init(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Reset the ADXL346 sensor + */ void adxl346_reset(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Check if the ADXL346 sensor is present + */ uint8_t adxl346_is_present(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the x-axis from the ADXL346 sensor + */ uint16_t adxl346_read_x(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the y-axis from the ADXL346 sensor + */ uint16_t adxl346_read_y(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the z-axis from the ADXL346 sensor + */ uint16_t adxl346_read_z(void); /*---------------------------------------------------------------------------*/ -#endif /* ifndef __ADXL346_H__ */ -/** @} */ +#endif /* ADXL346_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/antenna.c b/platform/openmote-cc2538/dev/antenna.c index b0ad7b07e..3672258f9 100644 --- a/platform/openmote-cc2538/dev/antenna.c +++ b/platform/openmote-cc2538/dev/antenna.c @@ -27,44 +27,31 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * + * This file is part of the Contiki operating system. + * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-antenna * @{ * - * \defgroup openmote + * Driver for the OpenMote-CC2538 RF switch. + * INT is the internal antenna (chip) configured through ANT1_SEL (V1) + * EXT is the external antenna (connector) configured through ANT2_SEL (V2) + * @{ * * \file - * Driver for the antenna selection on the OpenMote-CC2538 platform. + * Driver implementation for the OpenMote-CC2538 antenna switch */ - /*---------------------------------------------------------------------------*/ #include "contiki-conf.h" #include "dev/gpio.h" #include "dev/antenna.h" /*---------------------------------------------------------------------------*/ -#define BSP_RADIO_BASE (GPIO_D_BASE) -#define BSP_RADIO_INT (1 << 5) -#define BSP_RADIO_EXT (1 << 4) +#define BSP_RADIO_BASE GPIO_PORT_TO_BASE(GPIO_D_NUM) +#define BSP_RADIO_INT GPIO_PIN_MASK(5) +#define BSP_RADIO_EXT GPIO_PIN_MASK(4) /*---------------------------------------------------------------------------*/ -static void -gpio_set(int port, int bit) -{ - REG((port | GPIO_DATA) + (bit << 2)) = bit; -} -/*---------------------------------------------------------------------------*/ -static void -gpio_reset(int port, int bit) -{ - REG((port | GPIO_DATA) + (bit << 2)) = 0; -} -/*---------------------------------------------------------------------------*/ -/** - * Configure the antenna using the RF switch - * INT is the internal antenna (chip) configured through ANT1_SEL (V1) - * EXT is the external antenna (connector) configured through ANT2_SEL (V2) - */ void antenna_init(void) { @@ -76,24 +63,21 @@ antenna_init(void) antenna_external(); } /*---------------------------------------------------------------------------*/ -/** - * Select the external (connector) antenna - */ void antenna_external(void) { - gpio_reset(BSP_RADIO_BASE, BSP_RADIO_INT); - gpio_set(BSP_RADIO_BASE, BSP_RADIO_EXT); + GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_INT, 0); + GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_EXT, 1); } /*---------------------------------------------------------------------------*/ -/** - * Select the internal (chip) antenna - */ void antenna_internal(void) { - gpio_reset(BSP_RADIO_BASE, BSP_RADIO_EXT); - gpio_set(BSP_RADIO_BASE, BSP_RADIO_INT); + GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_EXT, 0); + GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_INT, 1); } /*---------------------------------------------------------------------------*/ -/** @} */ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/antenna.h b/platform/openmote-cc2538/dev/antenna.h index 8b14df4b0..9c42bf885 100644 --- a/platform/openmote-cc2538/dev/antenna.h +++ b/platform/openmote-cc2538/dev/antenna.h @@ -27,24 +27,43 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * + * This file is part of the Contiki operating system. + * */ - +/*--------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-cc2538 * @{ * - * \defgroup openmote + * \defgroup openmote-antenna OpenMote-CC2538 antenna switch + * + * Driver for the OpenMote-CC2538 antenna switch + * @{ * * \file - * Header for the antenna selection on the OpenMote-CC2538 platform. + * Header for the OpenMote-CC2538 antenna switch */ - +/*---------------------------------------------------------------------------*/ #ifndef ANTENNA_H_ #define ANTENNA_H_ /*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the antenna switch, by default it uses the external + */ void antenna_init(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Select the external (connector) antenna + */ void antenna_internal(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Select the internal (chip) antenna + */ void antenna_external(void); /*---------------------------------------------------------------------------*/ #endif /* ANTENNA_H_ */ -/** @} */ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/button-sensor.c b/platform/openmote-cc2538/dev/button-sensor.c index 6d85400d7..6477045c5 100644 --- a/platform/openmote-cc2538/dev/button-sensor.c +++ b/platform/openmote-cc2538/dev/button-sensor.c @@ -27,19 +27,18 @@ * 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. + * + * This file is part of the Contiki operating system. + * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-button-sensor * @{ * - * \defgroup openmote - * * \file - * Driver for the OpenMote-CC2538 buttons - * + * Driver for for the OpenMote-CC2538 user button */ - /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/nvic.h" @@ -47,6 +46,8 @@ #include "dev/gpio.h" #include "dev/button-sensor.h" #include "sys/timer.h" +#include "sys/ctimer.h" +#include "sys/process.h" #include #include @@ -54,32 +55,44 @@ #define BUTTON_USER_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_USER_PORT) #define BUTTON_USER_PIN_MASK GPIO_PIN_MASK(BUTTON_USER_PIN) /*---------------------------------------------------------------------------*/ +#define DEBOUNCE_DURATION (CLOCK_SECOND >> 4) + static struct timer debouncetimer; /*---------------------------------------------------------------------------*/ -/** - * \brief Common initialiser for all buttons - * \param port_base GPIO port's register offset - * \param pin_mask Pin mask corresponding to the button's pin - */ +static clock_time_t press_duration = 0; +static struct ctimer press_counter; +static uint8_t press_event_counter; + +process_event_t button_press_duration_exceeded; +/*---------------------------------------------------------------------------*/ static void -config(uint32_t port_base, uint32_t pin_mask) +duration_exceeded_callback(void *data) { - /* Software controlled */ - GPIO_SOFTWARE_CONTROL(port_base, pin_mask); + press_event_counter++; + process_post(PROCESS_BROADCAST, button_press_duration_exceeded, + &press_event_counter); + ctimer_set(&press_counter, press_duration, duration_exceeded_callback, + NULL); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Retrieves the value of the button pin + * \param type Returns the pin level or the counter of press duration events. + * type == BUTTON_SENSOR_VALUE_TYPE_LEVEL or + * type == BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION + * respectively + */ +static int +value(int type) +{ + switch(type) { + case BUTTON_SENSOR_VALUE_TYPE_LEVEL: + return GPIO_READ_PIN(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + case BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION: + return press_event_counter; + } - /* Set pin to input */ - GPIO_SET_INPUT(port_base, pin_mask); - - /* Enable edge detection */ - GPIO_DETECT_EDGE(port_base, pin_mask); - - /* Single edge */ - GPIO_TRIGGER_SINGLE_EDGE(port_base, pin_mask); - - /* Trigger interrupt on Falling edge */ - GPIO_DETECT_RISING(port_base, pin_mask); - - GPIO_ENABLE_INTERRUPT(port_base, pin_mask); + return 0; } /*---------------------------------------------------------------------------*/ /** @@ -95,42 +108,72 @@ btn_callback(uint8_t port, uint8_t pin) if(!timer_expired(&debouncetimer)) { return; } - timer_set(&debouncetimer, CLOCK_SECOND / 8); - if(port == GPIO_C_NUM) { - sensors_changed(&button_user_sensor); + + timer_set(&debouncetimer, DEBOUNCE_DURATION); + + if(press_duration) { + press_event_counter = 0; + if(value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == BUTTON_SENSOR_PRESSED_LEVEL) { + ctimer_set(&press_counter, press_duration, duration_exceeded_callback, + NULL); + } else { + ctimer_stop(&press_counter); + } } + + sensors_changed(&button_sensor); } /*---------------------------------------------------------------------------*/ /** - * \brief Init function for the select button. + * \brief Init function for the User button. + * \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1 + * or 0 respectively) * - * Parameters are ignored. They have been included because the prototype is - * dictated by the core sensor api. The return value is also not required by - * the API but otherwise ignored. - * - * \param type ignored - * \param value ignored - * \return ignored + * \param value Depends on the value of the type argument + * \return Depends on the value of the type argument */ static int config_user(int type, int value) { - config(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + switch(type) { + case SENSORS_HW_INIT: + button_press_duration_exceeded = process_alloc_event(); - ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE); + /* Software controlled */ + GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); - nvic_interrupt_enable(BUTTON_USER_VECTOR); + /* Set pin to input */ + GPIO_SET_INPUT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + + /* Enable edge detection */ + GPIO_DETECT_EDGE(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + + /* Both Edges */ + GPIO_TRIGGER_BOTH_EDGES(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + + ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE); + + gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN); + break; + case SENSORS_ACTIVE: + if(value) { + GPIO_ENABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + nvic_interrupt_enable(BUTTON_USER_VECTOR); + } else { + GPIO_DISABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK); + nvic_interrupt_disable(BUTTON_USER_VECTOR); + } + return value; + case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL: + press_duration = (clock_time_t)value; + break; + default: + break; + } - gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN); return 1; } /*---------------------------------------------------------------------------*/ -void -button_sensor_init() -{ - timer_set(&debouncetimer, 0); -} -/*---------------------------------------------------------------------------*/ -SENSORS_SENSOR(button_user_sensor, BUTTON_SENSOR, NULL, config_user, NULL); +SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, config_user, NULL); /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/platform/openmote-cc2538/dev/button-sensor.h b/platform/openmote-cc2538/dev/button-sensor.h index ec7849ee1..9a08634ae 100644 --- a/platform/openmote-cc2538/dev/button-sensor.h +++ b/platform/openmote-cc2538/dev/button-sensor.h @@ -27,33 +27,48 @@ * 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. + * + * This file is part of the Contiki operating system. + * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-cc2538 * @{ * - * \defgroup openmote + * \defgroup openmote-button-sensor OpenMote-CC2538 user button driver + * + * The user button will generate a sensors_changed event on press as + * well as on release. + * + * @{ * * \file - * Header for the OpenMote-CC2538 buttons - * + * Header for the OpenMote-CC2538 button driver */ - +/*---------------------------------------------------------------------------*/ #ifndef BUTTON_SENSOR_H_ #define BUTTON_SENSOR_H_ /*---------------------------------------------------------------------------*/ #include "lib/sensors.h" -#include "dev/gpio.h" /*---------------------------------------------------------------------------*/ #define BUTTON_SENSOR "Button" + +extern const struct sensors_sensor button_sensor; /*---------------------------------------------------------------------------*/ -#define button_sensor button_user_sensor -extern const struct sensors_sensor button_user_sensor; +extern process_event_t button_press_duration_exceeded; +/*---------------------------------------------------------------------------*/ +#define BUTTON_SENSOR_CONFIG_TYPE_INTERVAL 0x0100 + +#define BUTTON_SENSOR_VALUE_TYPE_LEVEL 0 +#define BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION 1 + +#define BUTTON_SENSOR_PRESSED_LEVEL 0 +#define BUTTON_SENSOR_RELEASED_LEVEL 8 /*---------------------------------------------------------------------------*/ #endif /* BUTTON_SENSOR_H_ */ - -/** \brief Common initialiser for all SmartRF Buttons */ -void button_sensor_init(); /*---------------------------------------------------------------------------*/ -/** @} */ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/leds-arch.c b/platform/openmote-cc2538/dev/leds-arch.c index 13a4c1347..28454dacf 100644 --- a/platform/openmote-cc2538/dev/leds-arch.c +++ b/platform/openmote-cc2538/dev/leds-arch.c @@ -10,7 +10,6 @@ * 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. @@ -27,19 +26,21 @@ * 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. + * + * This file is part of the Contiki operating system. + * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-cc2538 * @{ * - * \defgroup openmote + * \defgroup openmote-leds OpenMote-CC2538 LED driver + * @{ * * \file - * Driver for the OpenMote-CC2538 LEDs - * + * LED driver implementation for the OpenMote-CC2538 platform */ - /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "reg.h" @@ -66,4 +67,7 @@ leds_arch_set(unsigned char leds) GPIO_WRITE_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK, leds); } /*---------------------------------------------------------------------------*/ -/** @} */ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/max44009.c b/platform/openmote-cc2538/dev/max44009.c index 34bce89ab..233b07d13 100644 --- a/platform/openmote-cc2538/dev/max44009.c +++ b/platform/openmote-cc2538/dev/max44009.c @@ -29,29 +29,33 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-max44009-sensor * @{ * - * \defgroup openmote - * * \file - * Driver for the MAX44009 light sensor in OpenMote-CC2538. + * Driver for the MAX44009 light sensor * * \author * Pere Tuset */ - /*---------------------------------------------------------------------------*/ #include "dev/i2c.h" #include "dev/max44009.h" /*---------------------------------------------------------------------------*/ -/* ADDRESS AND NOT_FOUND VALUE */ +/** + * \name MAX44009 address and device identifier + * @{ + */ #define MAX44009_ADDRESS (0x4A) #define MAX44009_NOT_FOUND (0x00) - -/* REGISTER ADDRESSES */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name MAX44009 register addresses + * @{ + */ #define MAX44009_INT_STATUS_ADDR (0x00) /* R */ #define MAX44009_INT_ENABLE_ADDR (0x01) /* R/W */ #define MAX44009_CONFIG_ADDR (0x02) /* R/W */ @@ -60,14 +64,17 @@ #define MAX44009_THR_HIGH_ADDR (0x05) /* R/W */ #define MAX44009_THR_LOW_ADDR (0x06) /* R/W */ #define MAX44009_THR_TIMER_ADDR (0x07) /* R/W */ - -/* INTERRUPT VALUES */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name MAX44009 register values + * @{ + */ #define MAX44009_INT_STATUS_OFF (0x00) #define MAX44009_INT_STATUS_ON (0x01) #define MAX44009_INT_DISABLED (0x00) #define MAX44009_INT_ENABLED (0x01) -/* CONFIGURATION VALUES */ #define MAX44009_CONFIG_DEFAULT (0 << 7) #define MAX44009_CONFIG_CONTINUOUS (1 << 7) #define MAX44009_CONFIG_AUTO (0 << 6) @@ -83,15 +90,12 @@ #define MAX44009_CONFIG_INTEGRATION_12ms (6 << 0) #define MAX44009_CONFIG_INTEGRATION_6ms (7 << 0) -/* DEFAULT CONFIGURATION */ #define MAX44009_DEFAULT_CONFIGURATION (MAX44009_CONFIG_DEFAULT | \ MAX44009_CONFIG_AUTO | \ MAX44009_CONFIG_CDR_NORMAL | \ MAX44009_CONFIG_INTEGRATION_100ms) +/** @} */ /*---------------------------------------------------------------------------*/ -/** - * - */ void max44009_init(void) { @@ -108,19 +112,13 @@ max44009_init(void) max44009_value[3] = (0x00); max44009_value[4] = (0xFF); - i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, - I2C_SCL_NORMAL_BUS_SPEED); - - for(i = 0; i < sizeof(max44009_address); i++) { - max44009_data[0] = max44009_value[i]; - max44009_data[1] = max44009_data[i]; + for(i = 0; i < sizeof(max44009_address) / sizeof(max44009_address[0]); i++) { + max44009_data[0] = max44009_address[i]; + max44009_data[1] = max44009_value[i]; i2c_burst_send(MAX44009_ADDRESS, max44009_data, 2); } } /*---------------------------------------------------------------------------*/ -/** - * - */ void max44009_reset(void) { @@ -131,30 +129,28 @@ max44009_reset(void) uint8_t max44009_data[2]; uint8_t i; - for(i = 0; i < sizeof(max44009_address); i++) { - max44009_data[0] = max44009_value[i]; - max44009_data[1] = max44009_data[i]; + for(i = 0; i < sizeof(max44009_address) / sizeof(max44009_address[0]); i++) { + max44009_data[0] = max44009_address[i]; + max44009_data[1] = max44009_value[i]; i2c_burst_send(MAX44009_ADDRESS, max44009_data, 2); } } /*---------------------------------------------------------------------------*/ -/** - * - */ uint8_t max44009_is_present(void) { + uint8_t status; uint8_t is_present; i2c_single_send(MAX44009_ADDRESS, MAX44009_CONFIG_ADDR); - i2c_single_receive(MAX44009_ADDRESS, &is_present); + status = i2c_single_receive(MAX44009_ADDRESS, &is_present); + if(status != I2C_MASTER_ERR_NONE) { + return 0; + } return is_present != MAX44009_NOT_FOUND; } /*---------------------------------------------------------------------------*/ -/** - * - */ uint16_t max44009_read_light(void) { @@ -175,9 +171,6 @@ max44009_read_light(void) return result; } /*---------------------------------------------------------------------------*/ -/** - * - */ float max44009_convert_light(uint16_t lux) { @@ -186,7 +179,7 @@ max44009_convert_light(uint16_t lux) exponent = (lux >> 8) & 0xFF; exponent = (exponent == 0x0F ? exponent & 0x0E : exponent); - + mantissa = (lux >> 0) & 0xFF; result *= 2 ^ exponent * mantissa; diff --git a/platform/openmote-cc2538/dev/max44009.h b/platform/openmote-cc2538/dev/max44009.h index dbc40775d..e94a91fca 100644 --- a/platform/openmote-cc2538/dev/max44009.h +++ b/platform/openmote-cc2538/dev/max44009.h @@ -29,28 +29,52 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-sensors * @{ * - * \defgroup openmote + * \defgroup openmote-max44009-sensor MAX4009 light sensor + * @{ * * \file - * Header for the MAX44009 light sensor in OpenMote-CC2538. + * Header file for the MAX44009 light sensor driver * * \author * Pere Tuset */ - -#ifndef __MAX44009_H__ -#define __MAX44009_H__ /*---------------------------------------------------------------------------*/ +#ifndef MAX44009_H_ +#define MAX44009_H_ +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the MAX44009 sensor + */ void max44009_init(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Reset the MAX44009 sensor + */ void max44009_reset(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Check if the MAX44009 sensor is present + */ uint8_t max44009_is_present(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the light from the MAX44009 sensor + */ uint16_t max44009_read_light(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert the light from the MAX44009 sensor + */ float max44009_convert_light(uint16_t light); /*---------------------------------------------------------------------------*/ -#endif /* ifndef __MAX44009_H__ */ -/** @} */ +#endif /* MAX44009_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/smartrf-sensors.c b/platform/openmote-cc2538/dev/openmote-sensors.c similarity index 82% rename from platform/openmote-cc2538/dev/smartrf-sensors.c rename to platform/openmote-cc2538/dev/openmote-sensors.c index d8948a017..3b55e4cbb 100644 --- a/platform/openmote-cc2538/dev/smartrf-sensors.c +++ b/platform/openmote-cc2538/dev/openmote-sensors.c @@ -27,27 +27,34 @@ * 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. + * + * This file is part of the Contiki operating system. + * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-sensors * @{ * - * \defgroup openmote + * Generic module controlling sensors on the OpenMote-CC2538 platform + * @{ * * \file - * Implementation of a generic module controlling OpenMote-CC2538 sensors. + * Implementation of a generic module controlling OpenMote-CC2538 sensors */ - /*---------------------------------------------------------------------------*/ #include "contiki.h" +#include "dev/cc2538-sensors.h" #include "dev/button-sensor.h" #include /*---------------------------------------------------------------------------*/ /** - *\brief Exports a global symbol to be used by the sensor API + * \brief Exports a global symbol to be used by the sensor API */ -SENSORS(&button_user_sensor); +SENSORS(&button_sensor, &cc2538_temp_sensor); /*---------------------------------------------------------------------------*/ -/** @} */ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/openmote-sensors.h b/platform/openmote-cc2538/dev/openmote-sensors.h new file mode 100644 index 000000000..a765dbd3d --- /dev/null +++ b/platform/openmote-cc2538/dev/openmote-sensors.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + * + * This file is part of the Contiki operating system. + * + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup openmote-cc2538 + * @{ + * + * \defgroup openmote-sensors OpenMote-CC2538 sensors + * + * Generic module controlling sensors on the OpenMote-CC2538 platform + * @{ + * + * \file + * Implementation of a generic module controlling OpenMote-CC2538 sensors + */ +/*---------------------------------------------------------------------------*/ +#ifndef OPENMOTE_SENSORS_H_ +#define OPENMOTE_SENSORS_H_ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" +#include "dev/cc2538-sensors.h" +#include "dev/button-sensor.h" +/*---------------------------------------------------------------------------*/ +#endif /* OPENMOTE_SENSORS_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/sht21.c b/platform/openmote-cc2538/dev/sht21.c index 1ad07836f..989fe2905 100644 --- a/platform/openmote-cc2538/dev/sht21.c +++ b/platform/openmote-cc2538/dev/sht21.c @@ -29,30 +29,43 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-sht21-sensor * @{ * - * \defgroup openmote - * * \file - * Driver for the SHT21 temperature and humidity sensor in OpenMote-CC2538. + * Driver for the SHT21 temperature and relative humidity sensor * * \author * Pere Tuset */ - /*---------------------------------------------------------------------------*/ #include "i2c.h" #include "sht21.h" /*---------------------------------------------------------------------------*/ +/** + * \name SHT21 address + */ #define SHT21_ADDRESS (0x40) - +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SHT21 register addresses and values + * @{ + */ #define SHT21_USER_REG_READ (0xE7) #define SHT21_USER_REG_WRITE (0xE6) #define SHT21_USER_REG_RESERVED_BITS (0x38) +#define SHT21_TEMPERATURE_HM_CMD (0xE3) +#define SHT21_HUMIDITY_HM_CMD (0xE5) +#define SHT21_TEMPERATURE_NHM_CMD (0xF3) +#define SHT21_HUMIDITY_NHM_CMD (0xF5) +#define SHT21_RESET_CMD (0xFE) + +#define SHT21_STATUS_MASK (0xFC) + #define SHT21_RESOLUTION_12b_14b ((0 << 7) | (0 << 0)) #define SHT21_RESOLUTION_8b_12b ((0 << 7) | (1 << 0)) #define SHT21_RESOLUTION_10b_13b ((1 << 7) | (0 << 0)) @@ -63,15 +76,12 @@ #define SHT21_ONCHIP_HEATER_DISABLE (0 << 2) #define SHT21_OTP_RELOAD_ENABLE (0 << 1) #define SHT21_OTP_RELOAD_DISABLE (1 << 1) - -#define SHT21_TEMPERATURE_HM_CMD (0xE3) -#define SHT21_HUMIDITY_HM_CMD (0xE5) -#define SHT21_TEMPERATURE_NHM_CMD (0xF3) -#define SHT21_HUMIDITY_NHM_CMD (0xF5) -#define SHT21_RESET_CMD (0xFE) - -#define SHT21_STATUS_MASK ( 0xFC ) - +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SHT21 configuration values + * @{ + */ #define SHT21_DEFAULT_CONFIG (SHT21_RESOLUTION_12b_14b | \ SHT21_ONCHIP_HEATER_DISABLE | \ SHT21_BATTERY_ABOVE_2V25 | \ @@ -81,18 +91,13 @@ SHT21_ONCHIP_HEATER_DISABLE | \ SHT21_BATTERY_ABOVE_2V25 | \ SHT21_OTP_RELOAD_DISABLE) +/** @} */ /*---------------------------------------------------------------------------*/ -/** - * - */ void sht21_init(void) { uint8_t config[2]; - i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, - I2C_SCL_NORMAL_BUS_SPEED); - /* Setup the configuration vector, the first position holds address */ /* and the second position holds the actual configuration */ config[0] = SHT21_USER_REG_WRITE; @@ -111,9 +116,6 @@ sht21_init(void) i2c_burst_send(SHT21_ADDRESS, config, sizeof(config)); } /*---------------------------------------------------------------------------*/ -/** - * - */ void sht21_reset(void) { @@ -121,29 +123,25 @@ sht21_reset(void) i2c_single_send(SHT21_ADDRESS, SHT21_RESET_CMD); } /*---------------------------------------------------------------------------*/ -/** - * - */ uint8_t sht21_is_present(void) { + uint8_t status; uint8_t is_present; /* Read the current configuration according to the datasheet (pag. 9, fig. 18) */ i2c_single_send(SHT21_ADDRESS, SHT21_USER_REG_READ); - i2c_single_receive(SHT21_ADDRESS, &is_present); + status = i2c_single_receive(SHT21_ADDRESS, &is_present); + if(status != I2C_MASTER_ERR_NONE) { + return 0; + } /* Clear the reserved bits according to the datasheet (pag. 9, tab. 8) */ is_present &= ~SHT21_USER_REG_RESERVED_BITS; - is_present = ((is_present == SHT21_USER_CONFIG) || (is_present == SHT21_DEFAULT_CONFIG)); - - return is_present; + return (is_present == SHT21_USER_CONFIG) || (is_present == SHT21_DEFAULT_CONFIG); } /*---------------------------------------------------------------------------*/ -/** - * - */ uint16_t sht21_read_temperature(void) { @@ -159,23 +157,17 @@ sht21_read_temperature(void) return temperature; } /*---------------------------------------------------------------------------*/ -/** - * - */ float sht21_convert_temperature(uint16_t temperature) { float result; result = -46.85; - result += 175.72 * (float) temperature / 65536.0; + result += 175.72 * (float)temperature / 65536.0; return result; } /*---------------------------------------------------------------------------*/ -/** - * - */ uint16_t sht21_read_humidity(void) { @@ -191,16 +183,13 @@ sht21_read_humidity(void) return humidity; } /*---------------------------------------------------------------------------*/ -/** - * - */ float sht21_convert_humidity(uint16_t humidity) { float result; result = -6.0; - result += 125.0 * (float) humidity / 65536.0; + result += 125.0 * (float)humidity / 65536.0; return result; } diff --git a/platform/openmote-cc2538/dev/sht21.h b/platform/openmote-cc2538/dev/sht21.h index c95e02edf..1483a70a9 100644 --- a/platform/openmote-cc2538/dev/sht21.h +++ b/platform/openmote-cc2538/dev/sht21.h @@ -29,30 +29,62 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-sensors * @{ * - * \defgroup openmote + * \defgroup openmote-sht21-sensor SHT21 sensor + * @{ * * \file - * Header for the SHT21 temperature and humidity sensor in OpenMote-CC2538. + * Header file for the SHT21 temperature and humidity sensor driver * * \author * Pere Tuset */ - -#ifndef __SHT21_H__ -#define __SHT21_H__ /*---------------------------------------------------------------------------*/ +#ifndef SHT21_H_ +#define SHT21_H_ +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the SHT21 sensor + */ void sht21_init(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Reset the SHT21 sensor + */ void sht21_reset(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Check if the SHT21 sensor is present + */ uint8_t sht21_is_present(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the temperature from the SHT21 sensor + */ uint16_t sht21_read_temperature(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert the temperature from the SHT21 sensor + */ float sht21_convert_temperature(uint16_t temperature); +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the relative humidity from the SHT21 sensor + */ uint16_t sht21_read_humidity(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert the relative humidity from the SHT21 sensor + */ float sht21_convert_humidity(uint16_t humidity); /*---------------------------------------------------------------------------*/ -#endif /* ifndef __SHT21_H__ */ -/** @} */ +#endif /* SHT21_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/tps62730.c b/platform/openmote-cc2538/dev/tps62730.c index 0356077f9..f90c0e097 100644 --- a/platform/openmote-cc2538/dev/tps62730.c +++ b/platform/openmote-cc2538/dev/tps62730.c @@ -29,20 +29,22 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-tps62730 * @{ * - * \defgroup openmote + * Driver for the TPS62730 voltage regulator, to enable power from + * the battery voltage (bypass, Vout=Vin, Iq < 1uA) or through the + * buck regulator (on, Vout=2.1V, Iq = 30uA) + * @{ * * \file - * Driver for the TPS62730 voltage regulator on the OpenMote-CC2538. + * Driver for the TPS62730 voltage regulator * * \author * Pere Tuset */ - /*---------------------------------------------------------------------------*/ #include "contiki-conf.h" #include "dev/gpio.h" @@ -64,10 +66,6 @@ gpio_reset(int port, int bit) REG((port | GPIO_DATA) + (bit << 2)) = 0; } /*---------------------------------------------------------------------------*/ -/** - * Initializes the TPS62730 voltage regulator - * By default it is in bypass mode, Vout = Vin, Iq < 1 uA - */ void tps62730_init(void) { @@ -77,22 +75,19 @@ tps62730_init(void) tps62730_bypass(); } /*---------------------------------------------------------------------------*/ -/** - * Enables the TPS62730, Vout = 2.2V, Iq = 30 uA - */ void tps62730_on(void) { gpio_set(BSP_TPS62730_BASE, BSP_TPS62730_ON); } /*---------------------------------------------------------------------------*/ -/** - * Disables the TPS62730, Vout = Vin, Iq < 1 uA - */ void tps62730_bypass(void) { gpio_reset(BSP_TPS62730_BASE, BSP_TPS62730_ON); } /*---------------------------------------------------------------------------*/ -/** @} */ +/** + * @} + * @} + */ diff --git a/platform/openmote-cc2538/dev/tps62730.h b/platform/openmote-cc2538/dev/tps62730.h index b3e99bc8d..00518c9c7 100644 --- a/platform/openmote-cc2538/dev/tps62730.h +++ b/platform/openmote-cc2538/dev/tps62730.h @@ -29,26 +29,46 @@ * This file is part of the Contiki operating system. * */ - +/*---------------------------------------------------------------------------*/ /** - * \addtogroup platform + * \addtogroup openmote-cc2538 * @{ * - * \defgroup openmote + * \defgroup openmote-tps62730 TPS62730 voltage regulator + * + * Driver for the TPS62730 voltage regulator, to enable power from + * the battery voltage (bypass, Vout=Vin, Iq < 1uA) or through the + * buck regulator (on, Vout=2.1V, Iq = 30uA) + * @{ * * \file - * Header for the TPS62730 voltage regulator on the OpenMote-CC2538. + * Driver for the TPS62730 voltage regulator * * \author * Pere Tuset */ - +/*---------------------------------------------------------------------------*/ #ifndef TPS62730_H_ #define TPS62730_H_ /*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the TPS62730 voltage regulator in bypass mode + */ void tps62730_init(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Set TPS62730 to on, Vout = 2.2V, Iq = 30 uA + */ void tps62730_on(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Set TPS62730 to bypass, Vout = Vin, Iq < 1 uA + */ void tps62730_bypass(void); /*---------------------------------------------------------------------------*/ #endif /* TPS62730_H_ */ -/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/regression-tests/18-compile-arm-ports/Makefile b/regression-tests/18-compile-arm-ports/Makefile index dbac11d43..19bd7d63e 100644 --- a/regression-tests/18-compile-arm-ports/Makefile +++ b/regression-tests/18-compile-arm-ports/Makefile @@ -32,6 +32,7 @@ cc2538-common/crypto/zoul \ cc2538-common/pka/zoul \ zolertia/zoul/zoul \ zolertia/zoul/cc1200-demo/zoul \ +openmote-cc2538/openmote-cc2538 \ er-rest-example/zoul \ ipso-objects/zoul \ hello-world/zoul \