Merge pull request #1590 from OpenMote/master

Add OpenMote-CC2538 platform and examples.
This commit is contained in:
George Oikonomou 2016-04-18 21:26:15 +01:00
commit 040bada378
26 changed files with 3193 additions and 0 deletions

View File

@ -0,0 +1,9 @@
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = openmote-demo
all: $(CONTIKI_PROJECT)
CONTIKI = ../..
CONTIKI_WITH_RIME = 1
include $(CONTIKI)/Makefile.include

View File

@ -0,0 +1,178 @@
/*
* 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
* @{
*
* Example project demonstrating the OpenMote-CC2538 functionality
*
* @{
*
* \file
* Example demonstrating the OpenMote-CC2538 platform
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#include "contiki.h"
#include "cpu.h"
#include "sys/etimer.h"
#include "dev/leds.h"
#include "dev/uart.h"
#include "dev/button-sensor.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 BROADCAST_CHANNEL 129
/*---------------------------------------------------------------------------*/
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_GREEN);
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;
/*---------------------------------------------------------------------------*/
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) {
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);
}
}
}
}
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

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

View File

@ -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 openmote-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 -v -b 450000
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

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

@ -0,0 +1,62 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup openmote-cc2538
* @{
*
* \file
* Board-initialisation for the OpenMote-CC2538 platform
*/
/*---------------------------------------------------------------------------*/
#include "contiki-conf.h"
#include "dev/antenna.h"
#include <stdint.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
static void
configure_unused_pins(void)
{
/* FIXME */
}
/*---------------------------------------------------------------------------*/
void
board_init()
{
antenna_init();
configure_unused_pins();
}
/*---------------------------------------------------------------------------*/
/**
* @}
*/

View File

@ -0,0 +1,187 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
*/
/* -------------------------------------------------------------------------- */
/**
* \addtogroup openmote-cc2538
* @{
*
* \file
* This file provides connectivity information on LEDs, Buttons, UART and
* other OpenMote-CC2538 peripherals.
*
* 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_
#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_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
*
* 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 (SSI0) configuration
*
* 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
#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
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \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
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
*/

View File

@ -0,0 +1,579 @@
/*
* 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-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
*/
#ifndef CONTIKI_CONF_H_
#define CONTIKI_CONF_H_
#include <stdint.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
/* 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 /**<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
#ifndef FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_ACTIVE_HIGH 0 /**< A logic low level activates the boot loader */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name CFS configuration
*
* @{
*/
#ifndef COFFEE_CONF_SIZE
#define COFFEE_CONF_SIZE (4 * COFFEE_SECTOR_SIZE)
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Watchdog Timer configuration
*
* @{
*/
#ifndef WATCHDOG_CONF_ENABLE
#define WATCHDOG_CONF_ENABLE 1 /**< Enable the watchdog timer */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name USB 'core' configuration
*
* Those values are not meant to be modified by the user, except where stated
* otherwise
* @{
*/
#define CTRL_EP_SIZE 8
#define USB_EP1_SIZE 32
#define USB_EP2_SIZE 64
#define USB_EP3_SIZE 64
#define USB_ARCH_WRITE_NOTIFY 0
#ifndef USB_ARCH_CONF_DMA
#define USB_ARCH_CONF_DMA 1 /**< Change to Enable/Disable USB DMA */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name Generic Configuration directives
*
* @{
*/
#ifndef ENERGEST_CONF_ON
#define ENERGEST_CONF_ON 0 /**< Energest Module */
#endif
#ifndef STARTUP_CONF_VERBOSE
#define STARTUP_CONF_VERBOSE 1 /**< Set to 0 to decrease startup verbosity */
#endif
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name uDMA Configuration and channel allocations
*
* @{
*/
#define USB_ARCH_CONF_RX_DMA_CHAN 0 /**< USB -> 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] = UIP_DS6_DEFAULT_PREFIX_0; \
addr_contexts[0].prefix[1] = UIP_DS6_DEFAULT_PREFIX_1; \
}
#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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,242 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup 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.
* @{
*
* \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/i2c.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 <stdint.h>
#include <string.h>
#include <stdio.h>
/*---------------------------------------------------------------------------*/
#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();
#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
i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);
serial_line_init();
INTERRUPTS_ENABLE();
fade(LEDS_BLUE);
PUTS(CONTIKI_VERSION_STRING);
PUTS(BOARD_STRING);
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 {
watchdog_periodic();
r = process_run();
} while(r > 0);
lpm_enter();
}
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,234 @@
/*
* 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-adxl346-sensor
* @{
*
* \file
* Driver for the ADXL346 acceleration sensor
*
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#include "dev/i2c.h"
#include "dev/adxl346.h"
/*---------------------------------------------------------------------------*/
/**
* \name ADXL346 address and device identifier
* @{
*/
#define ADXL346_ADDRESS (0x53)
#define ADXL346_DEVID_VALUE (0xE6)
/** @} */
/* -------------------------------------------------------------------------- */
/**
* \name ADXL346 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)
/** @} */
/* -------------------------------------------------------------------------- */
/**
* \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)
#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)
#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)
#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)
#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)
#define ADXL346_BW_RATE_POWER (1 << 4)
#define ADXL346_BW_RATE_RATE(x) ((x) & 0x0F)
#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)
#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];
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;
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,85 @@
/*
* 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-sensors
* @{
*
* \defgroup openmote-adxl346-sensor ADXL346 acceleration sensor
* @{
*
* \file
* ADXL346 acceleration sensor driver header file
*
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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 /* ADXL346_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,83 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
*/
/*---------------------------------------------------------------------------*/
/**
* \addtogroup openmote-antenna
* @{
*
* 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 implementation for the OpenMote-CC2538 antenna switch
*/
/*---------------------------------------------------------------------------*/
#include "contiki-conf.h"
#include "dev/gpio.h"
#include "dev/antenna.h"
/*---------------------------------------------------------------------------*/
#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)
/*---------------------------------------------------------------------------*/
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();
}
/*---------------------------------------------------------------------------*/
void
antenna_external(void)
{
GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_INT, 0);
GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_EXT, 1);
}
/*---------------------------------------------------------------------------*/
void
antenna_internal(void)
{
GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_EXT, 0);
GPIO_WRITE_PIN(BSP_RADIO_BASE, BSP_RADIO_INT, 1);
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,69 @@
/*
* 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.
*
* This file is part of the Contiki operating system.
*
*/
/*--------------------------------------------------------------------------*/
/**
* \addtogroup openmote-cc2538
* @{
*
* \defgroup openmote-antenna OpenMote-CC2538 antenna switch
*
* Driver for the OpenMote-CC2538 antenna switch
* @{
*
* \file
* 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

@ -0,0 +1,179 @@
/*
* 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-button-sensor
* @{
*
* \file
* Driver for for the OpenMote-CC2538 user button
*/
/*---------------------------------------------------------------------------*/
#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 "sys/ctimer.h"
#include "sys/process.h"
#include <stdint.h>
#include <string.h>
/*---------------------------------------------------------------------------*/
#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;
/*---------------------------------------------------------------------------*/
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
duration_exceeded_callback(void *data)
{
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;
}
return 0;
}
/*---------------------------------------------------------------------------*/
/**
* \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, 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 User button.
* \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
* or 0 respectively)
*
* \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)
{
switch(type) {
case SENSORS_HW_INIT:
button_press_duration_exceeded = process_alloc_event();
/* Software controlled */
GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
/* 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;
}
return 1;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, config_user, NULL);
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,74 @@
/*
* 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-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 button driver
*/
/*---------------------------------------------------------------------------*/
#ifndef BUTTON_SENSOR_H_
#define BUTTON_SENSOR_H_
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
/*---------------------------------------------------------------------------*/
#define BUTTON_SENSOR "Button"
extern const struct sensors_sensor button_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_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,73 @@
/*
* 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-leds OpenMote-CC2538 LED driver
* @{
*
* \file
* LED driver implementation for the OpenMote-CC2538 platform
*/
/*---------------------------------------------------------------------------*/
#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);
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,190 @@
/*
* 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-max44009-sensor
* @{
*
* \file
* Driver for the MAX44009 light sensor
*
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#include "dev/i2c.h"
#include "dev/max44009.h"
/*---------------------------------------------------------------------------*/
/**
* \name MAX44009 address and device identifier
* @{
*/
#define MAX44009_ADDRESS (0x4A)
#define MAX44009_NOT_FOUND (0x00)
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \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 */
#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 */
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \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)
#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)
#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);
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)
{
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) / 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);
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)
{
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;
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,80 @@
/*
* 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-sensors
* @{
*
* \defgroup openmote-max44009-sensor MAX4009 light sensor
* @{
*
* \file
* Header file for the MAX44009 light sensor driver
*
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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 /* MAX44009_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,60 @@
/*
* 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-sensors
* @{
*
* Generic module controlling sensors on the OpenMote-CC2538 platform
* @{
*
* \file
* 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
*/
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

@ -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 openmote-sht21-sensor
* @{
*
* \file
* 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))
#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)
/** @} */
/*---------------------------------------------------------------------------*/
/**
* \name SHT21 configuration values
* @{
*/
#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];
/* 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 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);
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;
return (is_present == SHT21_USER_CONFIG) || (is_present == SHT21_DEFAULT_CONFIG);
}
/*---------------------------------------------------------------------------*/
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;
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -0,0 +1,90 @@
/*
* 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-sensors
* @{
*
* \defgroup openmote-sht21-sensor SHT21 sensor
* @{
*
* \file
* Header file for the SHT21 temperature and humidity sensor driver
*
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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 /* SHT21_H_ */
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,93 @@
/*
* 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-tps62730
* @{
*
* 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
*
* \author
* Pere Tuset <peretuset@openmote.com>
*/
/*---------------------------------------------------------------------------*/
#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;
}
/*---------------------------------------------------------------------------*/
void
tps62730_init(void)
{
GPIO_SET_OUTPUT(BSP_TPS62730_BASE, BSP_TPS62730_ON);
GPIO_SET_INPUT(BSP_TPS62730_BASE, BSP_TPS62730_STATUS);
tps62730_bypass();
}
/*---------------------------------------------------------------------------*/
void
tps62730_on(void)
{
gpio_set(BSP_TPS62730_BASE, BSP_TPS62730_ON);
}
/*---------------------------------------------------------------------------*/
void
tps62730_bypass(void)
{
gpio_reset(BSP_TPS62730_BASE, BSP_TPS62730_ON);
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
*/

View File

@ -0,0 +1,74 @@
/*
* 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-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
* 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 \