Updated the OpenMote-CC2538 platform and examples.

master-31012017
Pere Tuset 2016-04-11 15:32:29 +02:00
parent 1d3c37d6da
commit 3e00ea55d1
30 changed files with 895 additions and 868 deletions

View File

@ -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)

View File

@ -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 <peretuset@openmote.com>
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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 <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#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();

View File

@ -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

View File

@ -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_ */
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -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 <peretuset@openmote.com>
*/
#include "contiki.h"
#include "dev/adxl346.h"
#include <stdio.h>
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();
}

View File

@ -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 <peretuset@openmote.com>
*/
#include "contiki.h"
#include "dev/max44009.h"
#include "dev/leds.h"
#include <stdio.h>
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();
}

View File

@ -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 <peretuset@openmote.com>
*/
#include "contiki.h"
#include "dev/sht21.h"
#include "dev/leds.h"
#include "sys/etimer.h"
#include <stdio.h>
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();
}

View File

@ -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 <peretuset@openmote.com>
*/
#include "contiki.h"
#include "sys/clock.h"
#include "sys/rtimer.h"
#include "dev/leds.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
#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();
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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)

View File

@ -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" (<https://launchpad.net/gcc-arm-embedded>). 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: <https://www.olimex.com/Products/ARM/JTAG/ARM-JTAG-20-10/>.
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 <peretuset@openmote.com>

View File

@ -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()
/**
* @}
*/

View File

@ -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_ */
/** @} */
/*---------------------------------------------------------------------------*/
/**
* @}
*/

View File

@ -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 /**<Enable the boot loader backdoor */
#endif
#ifndef FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN 6 /**< Pin PA6 (ON/SLEEP on the OpenBase), activates the boot loader */
#endif
@ -64,7 +103,9 @@ typedef uint32_t rtimer_clock_t;
*
* @{
*/
#ifndef COFFEE_CONF_SIZE
#define COFFEE_CONF_SIZE (4 * COFFEE_SECTOR_SIZE)
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
@ -264,13 +305,13 @@ typedef uint32_t rtimer_clock_t;
#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)) \
)
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 */
@ -484,8 +525,8 @@ typedef uint32_t rtimer_clock_t;
#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; \
addr_contexts[0].prefix[0] = UIP_DS6_DEFAULT_PREFIX_0; \
addr_contexts[0].prefix[1] = UIP_DS6_DEFAULT_PREFIX_1; \
}
#endif
@ -528,9 +569,11 @@ typedef uint32_t rtimer_clock_t;
#ifndef CCM_STAR_CONF
#define CCM_STAR_CONF cc2538_ccm_star_driver /**< AES-CCM* driver */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
#endif /* CONTIKI_CONF_H_ */
/** @} */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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,12 +26,16 @@
* 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 cc2538-platforms
* \addtogroup platform
* @{
*
* \defgroup openmote The OpenMote-CC2538 platform
* \defgroup openmote-cc2538 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.
@ -48,6 +51,7 @@
#include "dev/scb.h"
#include "dev/nvic.h"
#include "dev/uart.h"
#include "dev/i2c.h"
#include "dev/watchdog.h"
#include "dev/ioc.h"
#include "dev/button-sensor.h"
@ -84,7 +88,9 @@
#define PUTS(s)
#endif
/*---------------------------------------------------------------------------*/
/** \brief Board specific iniatialisation */
/**
* \brief Board specific iniatialisation
*/
void board_init(void);
/*---------------------------------------------------------------------------*/
static void
@ -155,16 +161,6 @@ main(void)
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);
@ -176,6 +172,8 @@ main(void)
usb_serial_set_input(serial_line_input_byte);
#endif
i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);
serial_line_init();
INTERRUPTS_ENABLE();
@ -184,7 +182,6 @@ main(void)
PUTS(CONTIKI_VERSION_STRING);
PUTS(BOARD_STRING);
/* Initialise the H/W RNG engine. */
random_init(0);
udma_init();
@ -202,11 +199,11 @@ main(void)
netstack_init();
set_rf_params();
PRINTF(" Net: ");
PRINTF("Net: ");
PRINTF("%s\n", NETSTACK_NETWORK.name);
PRINTF(" MAC: ");
PRINTF("MAC: ");
PRINTF("%s\n", NETSTACK_MAC.name);
PRINTF(" RDC: ");
PRINTF("RDC: ");
PRINTF("%s\n", NETSTACK_RDC.name);
#if NETSTACK_CONF_WITH_IPV6
@ -230,18 +227,15 @@ main(void)
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();
}
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}

View File

@ -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 <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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)
{

View File

@ -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 <peretuset@openmote.com>
*/
#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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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);
}
/*---------------------------------------------------------------------------*/
/** @} */
/**
* @}
* @}
*/

View File

@ -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_ */
/** @} */
/**
* @}
* @}
*/

View File

@ -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 <stdint.h>
#include <string.h>
@ -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);
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -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();
/*---------------------------------------------------------------------------*/
/** @} */
/**
* @}
* @}
*/

View File

@ -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);
}
/*---------------------------------------------------------------------------*/
/** @} */
/**
* @}
* @}
*/

View File

@ -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 <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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;

View File

@ -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 <peretuset@openmote.com>
*/
#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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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 <string.h>
/*---------------------------------------------------------------------------*/
/**
*\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);
/*---------------------------------------------------------------------------*/
/** @} */
/**
* @}
* @}
*/

View File

@ -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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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 <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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;
}

View File

@ -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 <peretuset@openmote.com>
*/
#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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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 <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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);
}
/*---------------------------------------------------------------------------*/
/** @} */
/**
* @}
* @}
*/

View File

@ -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 <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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_ */
/** @} */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -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 \