Zolertia Re-Mote platform ported to Contiki, developed whitin RERUM FP7 European project (grant #609094).
The port was done jointly by Zolertia and George Oikonomou (University of Bristol).
This commit is contained in:
parent
2cee62eb33
commit
330e450ba4
33 changed files with 4002 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -24,6 +24,7 @@
|
|||
*.c128
|
||||
*.c64
|
||||
*.cc2538dk
|
||||
*.remote
|
||||
*.srf06-cc26xx
|
||||
*.ev-aducrf101mkxz
|
||||
*.report
|
||||
|
|
9
examples/remote/Makefile
Normal file
9
examples/remote/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
|
||||
CONTIKI_PROJECT = remote-demo test-tsl2563 test-sht25
|
||||
CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
CONTIKI = ../..
|
||||
CONTIKI_WITH_RIME = 1
|
||||
include $(CONTIKI)/Makefile.include
|
1
examples/remote/Makefile.target
Normal file
1
examples/remote/Makefile.target
Normal file
|
@ -0,0 +1 @@
|
|||
TARGET = remote
|
38
examples/remote/node-red/README.md
Normal file
38
examples/remote/node-red/README.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
Re-Mote + Node Red README
|
||||
========================
|
||||
|
||||
A very basic example of how to use MQTT-Demo + Mosquitto + Node Red
|
||||
|
||||
Install Mosquitto
|
||||
-----------------
|
||||
* Install and run [mosquitto](http://mosquitto.org/). Default configuration
|
||||
options should work.
|
||||
|
||||
Fire up a Re-Mote
|
||||
-----------------
|
||||
* Compile the MQTT demo example from `../../cc2538dk/mqtt-demo.c` following
|
||||
the instructions of the README.md therein.
|
||||
* Program your Re-Mote.
|
||||
* If you are running mosquitto with `-v`, a few seconds later you should see
|
||||
the Re-Mote connect, subscribe and start publishing.
|
||||
|
||||
Deploy your Node Red
|
||||
--------------------
|
||||
* Install and run [Node Red](https://github.com/node-red/node-red) as per the
|
||||
instructions
|
||||
* Open `mqtt-remote-demo.json` from this directory with your favourite text
|
||||
editor, select all and copy.
|
||||
* Once you have the opened the Node Red page, click the menu icon on the top
|
||||
right and go to Import -> Clipboard. Paste the copied text.
|
||||
* Double click the `MQTT input from Re-Mote` box on the top left. Set `Broker`
|
||||
IP and port to those corresponding to your running mosquitto.
|
||||
* Hit Deploy
|
||||
* Optionally, export the flow to a file for future use
|
||||
|
||||
Browse
|
||||
------
|
||||
Fire up a browser and browse to `http://<Node-Red's IP or hostname>/remote`
|
||||
|
||||
Do more cool stuff
|
||||
------------------
|
||||
Come up with more cool flows and share!
|
2
examples/remote/node-red/mqtt-remote-demo.json
Normal file
2
examples/remote/node-red/mqtt-remote-demo.json
Normal file
|
@ -0,0 +1,2 @@
|
|||
[{"id":"d95a1e7f.43a","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"ddd5cc1c.723e18","type":"mqtt in","name":"MQTT input from Re-Mote","topic":"iot-2/evt/status/fmt/json","broker":"d95a1e7f.43a","x":131.11109924316406,"y":98.88890075683594,"z":"9b2868a4.2cef5","wires":[["12ea094e.3c2447"]]},{"id":"7728d120.25c64","type":"function","name":"Parse and Store Data","func":"var dat = msg.payload.d;\n\nif(dat) {\n var ret = [\n {\n name: \"Name\",\n value: dat.myName,\n unit: \"\",\n },\n {\n name: \"Seq #\",\n value: dat[\"Seq #\"],\n unit: \"\",\n },\n {\n name: \"Uptime\",\n value: dat[\"Uptime (sec)\"],\n unit: \"sec\",\n },\n {\n name: \"On-Chip Temp\",\n value: dat[\"On-Chip Temp (mC)\"],\n unit: \"C\",\n },\n {\n name: \"VDD/3\",\n value: dat[\"VDD3 (mV)\"],\n unit: \"V\",\n },\n {\n name: \"Parent RSSI\",\n value: dat[\"RSSI (dBm)\"],\n unit: \"dBm\",\n },\n ];\n \n context.ret = ret;\n} else {\n if(context.ret) {\n msg.has_data = true;\n msg.payload = context.ret;\n } else {\n msg.payload = \"No Data!\";\n }\n return [msg, msg];\n}\nreturn [msg, null];","outputs":"2","x":545.1110992431641,"y":346.38890075683594,"z":"9b2868a4.2cef5","wires":[["4249c5c.35b5c3c"],["dacab617.9133c8"]]},{"id":"12ea094e.3c2447","type":"json","name":"Convert to JS Object","x":305.61109924316406,"y":263.13890075683594,"z":"9b2868a4.2cef5","wires":[["7728d120.25c64"]]},{"id":"e5e8271c.99c2d","type":"http response","name":"Send HTTP Reponse","x":1252.2220611572266,"y":488.38890075683594,"z":"9b2868a4.2cef5","wires":[]},{"id":"4b2260f8.436808","type":"http in","name":"","url":"/remote","method":"get","x":327.11109924316406,"y":429.88890075683594,"z":"9b2868a4.2cef5","wires":[["8a3f88a9.ec77d8","7728d120.25c64"]]},{"id":"8a3f88a9.ec77d8","type":"debug","name":"","active":false,"console":"false","complete":"req","x":459.61109924316406,"y":522.3889007568359,"z":"9b2868a4.2cef5","wires":[]},{"id":"ac349e33.beb47","type":"template","name":"Render HTML from Data","field":"payload","template":"<html>\n<body>\n<ul>\n {{#payload}}\n <li>{{name}}: {{value}}{{#unit}} {{unit}}{{/unit}}</li>\n {{/payload}}\n</ul>\n</body>\n</html>","x":1046.361099243164,"y":347.13890075683594,"z":"9b2868a4.2cef5","wires":[["e5e8271c.99c2d","530bf522.d773dc"]]},{"id":"4249c5c.35b5c3c","type":"debug","name":"","active":false,"console":"false","complete":"false","x":620.1110992431641,"y":247.88890075683594,"z":"9b2868a4.2cef5","wires":[]},{"id":"dacab617.9133c8","type":"switch","name":"","property":"has_data","rules":[{"t":"true"},{"t":"else"}],"checkall":"false","outputs":2,"x":765.1110992431641,"y":352.88890075683594,"z":"9b2868a4.2cef5","wires":[["124554c4.5b82b3","ac349e33.beb47"],["e5e8271c.99c2d"]]},{"id":"530bf522.d773dc","type":"debug","name":"","active":false,"console":"false","complete":"payload","x":1228.361099243164,"y":217.88890075683594,"z":"9b2868a4.2cef5","wires":[]},{"id":"124554c4.5b82b3","type":"debug","name":"","active":false,"console":"false","complete":"payload","x":898.1110992431641,"y":220.88890075683594,"z":"9b2868a4.2cef5","wires":[]}]
|
||||
|
45
examples/remote/project-conf.h
Normal file
45
examples/remote/project-conf.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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 NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
|
||||
/** @} */
|
196
examples/remote/remote-demo.c
Normal file
196
examples/remote/remote-demo.c
Normal file
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* 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
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-examples Re-Mote Example Projects
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-demo Re-Mote Demo Project
|
||||
*
|
||||
* Example project demonstrating the Re-Mote functionality
|
||||
*
|
||||
* - Boot sequence: LEDs flashing (Red, then yellow, finally green)
|
||||
*
|
||||
* - etimer/clock : Every LOOP_INTERVAL clock ticks (LOOP_PERIOD secs) the LED
|
||||
* defined as LEDS_PERIODIC will turn on
|
||||
* - rtimer : Exactly LEDS_OFF_HYSTERISIS rtimer ticks later,
|
||||
* LEDS_PERIODIC will turn back off
|
||||
* - ADC sensors : On-chip VDD / 3, temperature, and Phidget sensor
|
||||
* values are printed over UART periodically.
|
||||
* - UART : Every LOOP_INTERVAL the Remote will print something over
|
||||
* the UART. Receiving an entire line of text over UART (ending
|
||||
* in \\r) will cause LEDS_SERIAL_IN to toggle
|
||||
* - Radio comms : BTN_USER sends a rime broadcast. Reception of a rime
|
||||
* packet will toggle LEDs defined as LEDS_RF_RX
|
||||
* - Button : Keeping the button pressed will print a counter that
|
||||
* increments every BUTTON_PRESS_EVENT_INTERVAL ticks
|
||||
* - TMP102 : Built-in digital temperature sensor, every LOOP_INTERVAL
|
||||
* clock ticks a sensor reading will be taken
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Example demonstrating the Re-Mote platform
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "cpu.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "sys/rtimer.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/uart.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/remote-sensors.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/sys-ctrl.h"
|
||||
#include "net/rime/broadcast.h"
|
||||
#include "dev/antenna-sw.h"
|
||||
#include "dev/tmp102.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LOOP_PERIOD 8
|
||||
#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD)
|
||||
#define LEDS_OFF_HYSTERISIS ((RTIMER_SECOND * LOOP_PERIOD) >> 1)
|
||||
#define LEDS_PERIODIC LEDS_BLUE
|
||||
#define LEDS_BUTTON LEDS_RED
|
||||
#define LEDS_SERIAL_IN LEDS_GREEN
|
||||
#define LEDS_REBOOT LEDS_ALL
|
||||
#define LEDS_RF_RX (LEDS_YELLOW | LEDS_RED)
|
||||
#define BROADCAST_CHANNEL 129
|
||||
|
||||
#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
static struct rtimer rt;
|
||||
static uint16_t counter, temperature;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(cc2538_demo_process, "cc2538 demo process");
|
||||
AUTOSTART_PROCESSES(&cc2538_demo_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from)
|
||||
{
|
||||
leds_toggle(LEDS_RF_RX);
|
||||
printf("*** Received %u bytes from %u:%u: '0x%04x'\n", packetbuf_datalen(),
|
||||
from->u8[0], from->u8[1], *(uint16_t *)packetbuf_dataptr());
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const struct broadcast_callbacks bc_rx = { broadcast_recv };
|
||||
static struct broadcast_conn bc;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rt_callback(struct rtimer *t, void *ptr)
|
||||
{
|
||||
leds_off(LEDS_PERIODIC);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(cc2538_demo_process, ev, data)
|
||||
{
|
||||
PROCESS_EXITHANDLER(broadcast_close(&bc))
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
counter = 0;
|
||||
broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx);
|
||||
|
||||
/* Enable antenna */
|
||||
antenna_sw_select(ANTENNA_SW_SELECT_INTERNAL);
|
||||
|
||||
button_sensor.configure(BUTTON_SENSOR_CONFIG_TYPE_INTERVAL,
|
||||
BUTTON_PRESS_EVENT_INTERVAL);
|
||||
|
||||
tmp102_init();
|
||||
|
||||
printf("Re-Mote test application, initial values:\n");
|
||||
|
||||
etimer_set(&et, LOOP_INTERVAL);
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(ev == PROCESS_EVENT_TIMER) {
|
||||
leds_on(LEDS_PERIODIC);
|
||||
|
||||
printf("-----------------------------------------\n"
|
||||
"Counter = 0x%08x\n", counter);
|
||||
|
||||
printf("VDD = %d mV\n",
|
||||
vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
printf("Temperature = %d mC\n",
|
||||
cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
printf("Phidget ADC2 = %d raw\n",
|
||||
phidget_sensor.value(PHIDGET_SENSORS_ADC2));
|
||||
|
||||
printf("Phidget ADC3 = %d raw\n",
|
||||
phidget_sensor.value(PHIDGET_SENSORS_ADC3));
|
||||
|
||||
tmp102_read(&temperature);
|
||||
printf("TMP102 sensor = %u mC\n", temperature);
|
||||
|
||||
etimer_set(&et, LOOP_INTERVAL);
|
||||
rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1,
|
||||
rt_callback, NULL);
|
||||
counter++;
|
||||
} else if(ev == sensors_event) {
|
||||
if(data == &button_sensor) {
|
||||
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
|
||||
BUTTON_SENSOR_PRESSED_LEVEL) {
|
||||
printf("Press\n");
|
||||
packetbuf_copyfrom(&counter, sizeof(counter));
|
||||
broadcast_send(&bc);
|
||||
} else {
|
||||
printf("Release\n");
|
||||
}
|
||||
}
|
||||
} else if(ev == serial_line_event_message) {
|
||||
leds_toggle(LEDS_SERIAL_IN);
|
||||
} else if(ev == button_press_duration_exceeded) {
|
||||
printf("Button pressed for %d ticks [%u events]\n",
|
||||
(*((uint8_t *)data) * BUTTON_PRESS_EVENT_INTERVAL),
|
||||
button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION));
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
63
examples/remote/test-sht25.c
Normal file
63
examples/remote/test-sht25.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.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 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* A quick program for testing the SHT25 temperature and humidity sensor
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/sht25.h"
|
||||
|
||||
PROCESS(test_sht25_process, "SHT25 test");
|
||||
AUTOSTART_PROCESSES(&test_sht25_process);
|
||||
|
||||
static struct etimer et;
|
||||
|
||||
PROCESS_THREAD(test_sht25_process, ev, data)
|
||||
{
|
||||
int16_t temperature, humidity;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
SENSORS_ACTIVATE(sht25);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
temperature = sht25.value(SHT25_VAL_TEMP);
|
||||
printf("Temperature %d.%d ºC\n", temperature / 100, temperature % 100);
|
||||
humidity = sht25.value(SHT25_VAL_HUM);
|
||||
printf("Humidity %d.%d RH\n", humidity / 100, humidity % 100);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
85
examples/remote/test-tsl2563.c
Normal file
85
examples/remote/test-tsl2563.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.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 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.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-examples
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-tsl2563-test Re-Mote TSL2563 light sensor test
|
||||
*
|
||||
* Demonstrates the use of the TSL2563 digital ambient light sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Re-Mote external TSL2563 light sensor (Ziglet)
|
||||
*
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
* Toni Lozano <tlozano@zolertia.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/i2c.h"
|
||||
#include "dev/tsl2563.h"
|
||||
|
||||
#if 1
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 2)
|
||||
|
||||
PROCESS(test_process, "Test TSL2563 light ziglet process");
|
||||
AUTOSTART_PROCESSES(&test_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
int light;
|
||||
SENSORS_ACTIVATE(tsl2563);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, SENSOR_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
light = tsl2563.value(TSL2563_VAL_READ);
|
||||
PRINTF("Light = %u\n", light);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
46
platform/remote/Makefile.remote
Normal file
46
platform/remote/Makefile.remote
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Remote platform makefile
|
||||
|
||||
ifndef CONTIKI
|
||||
$(error CONTIKI not defined! You must specify where CONTIKI resides!)
|
||||
endif
|
||||
|
||||
PYTHON = python
|
||||
BSL_FLAGS += -e -w -v -b 115200
|
||||
|
||||
ifdef PORT
|
||||
BSL_FLAGS += -p $(PORT)
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c
|
||||
CONTIKI_TARGET_SOURCEFILES += contiki-main.c
|
||||
CONTIKI_TARGET_SOURCEFILES += sensors.c remote-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += button-sensor.c antenna-sw.c
|
||||
CONTIKI_TARGET_SOURCEFILES += phidget-sensor.c tmp102.c
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
CLEAN += *.remote
|
||||
|
||||
### 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
|
||||
|
||||
BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py
|
||||
|
||||
%.upload: %.bin
|
||||
ifeq ($(wildcard $(BSL)), )
|
||||
@echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?"
|
||||
else
|
||||
$(PYTHON) $(BSL) $(BSL_FLAGS) $<
|
||||
endif
|
282
platform/remote/README.md
Normal file
282
platform/remote/README.md
Normal file
|
@ -0,0 +1,282 @@
|
|||
Zolertia Re-Mote platform
|
||||
============================================
|
||||
|
||||
<a href="url"><img src="http://goo.gl/3AGZkI" align="center" height="320" ></a>
|
||||
|
||||
The Re-Mote platform is a IoT Hardware development platform based on TI's CC2538
|
||||
system on chip (SoC), featuring an ARM Cortex-M3 with 512KB flash, 32Kb RAM,
|
||||
double RF interface, and the following goodies:
|
||||
|
||||
* ISM 2.4-GHz IEEE 802.15.4 & Zigbee compliant.
|
||||
* ISM 868-, 915-, 920-, 950-MHz ISM/SRD Band.
|
||||
* AES-128/256, SHA2 Hardware Encryption Engine.
|
||||
* ECC-128/256, RSA Hardware Acceleration Engine for Secure Key Exchange.
|
||||
* Power consumption down to 3uA using our shutdown mode.
|
||||
* Co-Processor to allow peripheral management, programming over BSL without requiring to press any button to enter bootloader mode.
|
||||
* Built-in battery charger (500mA), Energy Harvesting and Solar Panels to be connected to standards LiPo batteries.
|
||||
* Power input with wide range 2-26VDC.
|
||||
* Built-in TMP102 temperature sensor
|
||||
* Small form-factor (as the Z1 mote, half the size of an Arduino) 57x35 mm.
|
||||
|
||||
|
||||
Port Features
|
||||
=============
|
||||
The platform has the following key features:
|
||||
|
||||
* Deep Sleep support with RAM retention for ultra-low energy consumption.
|
||||
* Native USB support (CDC-ACM). SLIP over UART for border routers is no longer a bottleneck.
|
||||
* DMA transfers for increased performance (RAM to/from RF, RAM to/from USB).
|
||||
* Shutdown mode controlled externally by the Co-processor, completely power the
|
||||
platform OFF, further reducing current consumption.
|
||||
|
||||
In terms of hardware support, the following drivers have been implemented:
|
||||
|
||||
* CC2538 System-on-Chip:
|
||||
* Standard Cortex M3 peripherals (NVIC, SCB, SysTick)
|
||||
* Sleep Timer (underpins rtimers)
|
||||
* SysTick (underpins the platform clock and Contiki's timers infrastructure)
|
||||
* RF
|
||||
* 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. NB: GPT0 is in use by the platform code, the remaining GPTs are available for application development.
|
||||
* ADC
|
||||
* LEDs
|
||||
* Buttons
|
||||
* Internal/external 2.4GHz antenna switch controllable by SW.
|
||||
* Built-in core temperature and battery sensor.
|
||||
* TMP102 temperature sensor driver.
|
||||
* CC1120 sub-1GHz radio interface:
|
||||
* Ported in Contiki, SPI based.
|
||||
* Micro-SD external storage:
|
||||
* Pending to port, SPI based.
|
||||
|
||||
Requirements
|
||||
============
|
||||
To start using Contiki, the following is required:
|
||||
|
||||
* 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
|
||||
-------------------
|
||||
Forked from `platform/cc2538dk/README.md`.
|
||||
The toolchain used to build contiki is arm-gcc, also used by other arm-based Contiki ports. If you are using Instant Contiki, you will have a version pre-installed in your system. To find out if this is the case, try this:
|
||||
|
||||
$ arm-none-eabi-gcc -v
|
||||
Using built-in specs.
|
||||
Target: arm-none-eabi
|
||||
Configured with: /scratch/julian/lite-respin/eabi/src/gcc-4.3/configure
|
||||
...
|
||||
(skip)
|
||||
...
|
||||
Thread model: single
|
||||
gcc version 4.3.2 (Sourcery G++ Lite 2008q3-66)
|
||||
|
||||
The platform is currently being used/tested with the following toolchains:
|
||||
|
||||
* GNU Tools for ARM Embedded Processors. This is the recommended version. Works nicely on OS X. <https://launchpad.net/gcc-arm-embedded>
|
||||
* Alternatively, you can use this older version for Linux. At the time of writing, this is the version used by Contiki's regression tests. <https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/arm-2008q3-66-arm-none-eabi-i686-pc-linux-gnu.tar.bz2>
|
||||
|
||||
Drivers
|
||||
-------
|
||||
The Re-Mote features a FTDI serial-to-USB module, the driver is commonly found in most OS, but if required it can be downloaded
|
||||
from <http://www.ftdichip.com/Drivers/VCP.htm>
|
||||
|
||||
|
||||
### For the CC2538EM (USB CDC-ACM)
|
||||
The Re-Mote has built-in support for USB 2.0 USB, Vendor and Product IDs are the following:
|
||||
|
||||
* VID 0x0451
|
||||
* PID 0x16C8
|
||||
|
||||
The implementation in Contiki is pure CDC-ACM: The Linux and OS X kernels know exactly what to do and drivers are not required.
|
||||
|
||||
On windows, you will need to provide a driver:
|
||||
|
||||
* Download this LUFA CDC-ACM driver:
|
||||
<https://github.com/abcminiuser/lufa/blob/master/Demos/Device/LowLevel/VirtualSerial/LUFA%20VirtualSerial.inf>
|
||||
* Adjust the VID and PID near the end with the values at the start of this section.
|
||||
* Next time you get prompted for the driver, include the directory containing the .inf file in the search path and the driver will be installed.
|
||||
|
||||
### Device Enumerations
|
||||
For the UART, serial line settings are 115200 8N1, no flow control.
|
||||
|
||||
Once all drivers have been installed correctly:
|
||||
|
||||
On windows, devices will appear as a virtual COM port.
|
||||
|
||||
On Linux and OS X, devices will appear under `/dev/`.
|
||||
|
||||
On OS X:
|
||||
|
||||
* XDS backchannel: `tty.usbserial-<serial number>`
|
||||
* EM in CDC-ACM: `tty.usbmodemf<X><ABC>` (X a letter, ABC a number e.g. `tty.usbmodemfd121`)
|
||||
|
||||
On Linux:
|
||||
|
||||
* Re-Mote over FTDI: `ttyUSB1`
|
||||
* Re-Mote over USB driver (in CDC-ACM): `ttyACMn` (n=0, 1, ....)
|
||||
|
||||
Software to Program the Nodes
|
||||
-----------------------------
|
||||
The Re-Mote can be programmed via the jtag interface or via the serial boot loader on the chip.
|
||||
|
||||
* On Windows:
|
||||
* Nodes can be programmed with TI's ArmProgConsole or the [SmartRF Flash Programmer 2][smart-rf-flashprog]. The README should be self-explanatory. With ArmProgConsole, upload the file with a `.bin` extension. (jtag + serial)
|
||||
* Nodes can also be programmed via the serial boot loader in the cc2538. In `tools/cc2538-bsl/` you can find `cc2538-bsl.py` this is a python script that 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. (serial)
|
||||
|
||||
* On Linux:
|
||||
* Nodes can be programmed with TI's [UniFlash] tool. With UniFlash, use the file with `.elf` extension. (jtag + serial)
|
||||
* Nodes can also be programmed via the serial boot loader in the cc2538. No extra software needs to be installed. (serial)
|
||||
|
||||
* On OSX:
|
||||
* The `cc2538-bsl.py` script in `tools/cc2538-bsl/` is the only option. No extra software needs to be installed. (serial)
|
||||
|
||||
The file with a `.remote` extension is a copy of the `.elf` file.
|
||||
|
||||
Use the Port
|
||||
============
|
||||
The following examples are intended to work off-the-shelf:
|
||||
|
||||
* Examples under `examples/remote`
|
||||
* 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 `remote-demo`, it is a simple example that walkthroughs the platform features, such as
|
||||
the built-in sensors, LEDs, user button operation modes (press, release, hold-press), radio (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=remote savetarget`
|
||||
|
||||
Then you can just run `make` to compile an application, otherwise you will need to do `make TARGET=remote`.
|
||||
|
||||
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, or just let the Co-Processor detect the flash sequence and do it on your behalf, as simple as not pressing anything at all!
|
||||
|
||||
Then use `make remote-demo.upload PORT=/dev/ttyUSB1`.
|
||||
|
||||
The `PORT` argument is used to specify in which port the device is connected, as we are currently using a dual-channel FTDI chip, at the moment the programming channel is always assigned to the second FTDI channel, so the FTDI will enumerate as `/dev/ttyUSB0`, `/dev/ttyUSB1`, and we would need to use the later one and specify when flashing using the `cc2538-bsl` script, as it will use the first port found by default. This will be improved in the next release.
|
||||
|
||||
To manually enable the boot loader, press the `reset` button on the board while holding the `user` button. (The boot loader backdoor needs to be enabled on the chip for this to work, see README in the `tools/cc2538-bsl` directory for more info)
|
||||
|
||||
To generate an assembly listing of the compiled firmware, run `make remote-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 remote-demo.lst`.
|
||||
|
||||
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`.
|
||||
|
||||
NOTE: If you are using PG2 version of the Evaluation Module, the SoC will refuse to enter Power Modes 1+ if the debugger is connected and will always enter PM0 regardless of configuration. In order to get real low power mode functionality, make sure the debugger is disconnected. The Battery Board is ideal to test this.
|
||||
|
||||
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 16MB instead of 32MB.
|
||||
|
||||
### 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.
|
||||
|
||||
### Shutdown Mode
|
||||
The Re-Mote allows to further reduce power consumption by shutting down entirely all the components but the Co-Processor, powering completely of the CC2538 and CC1120 even preventing quiescent current from being drawn, allowing the platform to awake after a given period governed by the Co-Processor and the built-in battery management IC. This effectively reduces the power consumption down to 3-4uA.
|
||||
|
||||
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/remote/Makefile.remote`.
|
||||
|
||||
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/remote core cpu/cc2538 examples/remote examples/cc2538dk"
|
||||
|
||||
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`
|
||||
|
||||
More Reading
|
||||
============
|
||||
1. [Zolertia Re-Mote website][remote-site]
|
||||
2. [CC2538 System-on-Chip Solution for 2.4-GHz IEEE 802.15.4 and ZigBee®/ZigBee IP® Applications, (SWRU319B)][cc2538]
|
||||
3. [CC1120 sub-1GHz RF transceiver][cc1120]
|
||||
|
||||
[remote-site]: http://www.zolertia.io/products "Zolertia Re-Mote"
|
||||
[cc1120]: http://www.ti.com/cc1120 "CC1120"
|
||||
[smart-rf-studio]: http://www.ti.com/tool/smartrftm-studio "SmartRF Studio"
|
||||
[smart-rf-flashprog]: http://www.ti.com/tool/flash-programmer "SmartRF Flash Programmer"
|
||||
[cc2538]: http://www.ti.com/product/cc2538 "CC2538"
|
||||
[uniflash]: http://processors.wiki.ti.com/index.php/Category:CCS_UniFlash "UniFlash"
|
||||
[pandoc]: http://johnmacfarlane.net/pandoc/ "Pandoc - a universal document converter"
|
525
platform/remote/contiki-conf.h
Normal file
525
platform/remote/contiki-conf.h
Normal file
|
@ -0,0 +1,525 @@
|
|||
/**
|
||||
* \addtogroup remote
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Configuration for the Re-Mote 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 3 /**< Pin PA_3 (user button), 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 Flash Memory configuration
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#ifndef FLASH_CONF_ORIGIN
|
||||
#define FLASH_CONF_ORIGIN 0x00200000
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_CONF_SIZE
|
||||
#define FLASH_CONF_SIZE 0x00080000 /* 512 KiB */
|
||||
#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 */
|
||||
|
||||
/* This can be overriden to use the cc1120_driver instead */
|
||||
#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 2
|
||||
#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 25
|
||||
#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
|
||||
#define RPL_CONF_MAX_DAG_ENTRIES 1
|
||||
#ifndef RPL_CONF_OF
|
||||
#define RPL_CONF_OF rpl_mrhof
|
||||
#endif
|
||||
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 20
|
||||
#endif
|
||||
#ifndef UIP_CONF_MAX_ROUTES
|
||||
#define UIP_CONF_MAX_ROUTES 20
|
||||
#endif
|
||||
|
||||
/* uIP */
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 1300
|
||||
#endif
|
||||
|
||||
#define UIP_CONF_IPV6_QUEUE_PKT 0
|
||||
#define UIP_CONF_IPV6_CHECKS 1
|
||||
#define UIP_CONF_IPV6_REASSEMBLY 0
|
||||
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||
|
||||
/* 6lowpan */
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#ifndef SICSLOWPAN_CONF_COMPRESSION_THRESHOLD
|
||||
#define SICSLOWPAN_CONF_COMPRESSION_THRESHOLD 63
|
||||
#endif
|
||||
#ifndef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
#endif
|
||||
#define SICSLOWPAN_CONF_MAXAGE 8
|
||||
|
||||
/* Define our IPv6 prefixes/contexts here */
|
||||
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1
|
||||
#ifndef SICSLOWPAN_CONF_ADDR_CONTEXT_0
|
||||
#define SICSLOWPAN_CONF_ADDR_CONTEXT_0 { \
|
||||
addr_contexts[0].prefix[0] = 0xaa; \
|
||||
addr_contexts[0].prefix[1] = 0xaa; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MAC_CONF_CHANNEL_CHECK_RATE 8
|
||||
|
||||
#ifndef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||
/* Network setup for non-IPv6 (rime). */
|
||||
#define UIP_CONF_IP_FORWARD 1
|
||||
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 108
|
||||
#endif
|
||||
|
||||
#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0
|
||||
|
||||
#ifndef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
#endif
|
||||
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#endif /* CONTIKI_CONF_H_ */
|
||||
|
||||
/** @} */
|
244
platform/remote/contiki-main.c
Normal file
244
platform/remote/contiki-main.c
Normal file
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup platform
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote Zolertia Re-Mote platform
|
||||
*
|
||||
* The Re-Mote is the new platform by Zolertia based on the cc2538, featuring a
|
||||
* cc2538 SoC with an ARM Cortex-M3 core plus the CC1120 Sub-1Ghz transceiver
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Main module for the Re-Mote platform
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/sys-ctrl.h"
|
||||
#include "dev/scb.h"
|
||||
#include "dev/nvic.h"
|
||||
#include "dev/uart.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/ioc.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/cc2538-rf.h"
|
||||
#include "dev/udma.h"
|
||||
#include "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 "dev/antenna-sw.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
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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 Re-Mote platform
|
||||
*/
|
||||
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();
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
/*
|
||||
* Character I/O Initialisation.
|
||||
* When the UART receives a character it will call serial_line_input_byte to
|
||||
* notify the core. The same applies for the USB driver.
|
||||
*
|
||||
* If slip-arch is also linked in afterwards (e.g. if we are a border router)
|
||||
* it will overwrite one of the two peripheral input callbacks. Characters
|
||||
* received over the relevant peripheral will be handled by
|
||||
* slip_input_byte instead
|
||||
*/
|
||||
#if UART_CONF_ENABLE
|
||||
uart_init(0);
|
||||
uart_init(1);
|
||||
uart_set_input(SERIAL_LINE_CONF_UART, serial_line_input_byte);
|
||||
#endif
|
||||
|
||||
#if USB_SERIAL_CONF_ENABLE
|
||||
usb_serial_init();
|
||||
usb_serial_set_input(serial_line_input_byte);
|
||||
#endif
|
||||
|
||||
serial_line_init();
|
||||
|
||||
INTERRUPTS_ENABLE();
|
||||
fade(LEDS_BLUE);
|
||||
|
||||
PUTS(CONTIKI_VERSION_STRING);
|
||||
PUTS(BOARD_STRING);
|
||||
|
||||
PRINTF(" Net: ");
|
||||
PRINTF("%s\n", NETSTACK_NETWORK.name);
|
||||
PRINTF(" MAC: ");
|
||||
PRINTF("%s\n", NETSTACK_MAC.name);
|
||||
PRINTF(" RDC: ");
|
||||
PRINTF("%s\n", NETSTACK_RDC.name);
|
||||
|
||||
/* Initialise the H/W RNG engine. */
|
||||
random_init(0);
|
||||
|
||||
udma_init();
|
||||
|
||||
process_start(&etimer_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
set_rf_params();
|
||||
netstack_init();
|
||||
|
||||
#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 */
|
||||
|
||||
antenna_sw_config();
|
||||
|
||||
process_start(&sensors_process, NULL);
|
||||
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
energest_init();
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
watchdog_start();
|
||||
fade(LEDS_GREEN);
|
||||
|
||||
while(1) {
|
||||
uint8_t r;
|
||||
do {
|
||||
/* Reset watchdog and handle polls and events */
|
||||
watchdog_periodic();
|
||||
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
|
||||
/* We have serviced all pending events. Enter a Low-Power mode. */
|
||||
lpm_enter();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
91
platform/remote/dev/antenna-sw.c
Normal file
91
platform/remote/dev/antenna-sw.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-antenna
|
||||
* @{
|
||||
*
|
||||
* Driver for the Re-Mote 2.4Ghz antenna switch, to enable either the internal
|
||||
* ceramic antenna or an external one connected to the uFL connector
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Re-Mote 2.4Ghz antenna switch
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "antenna-sw.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define ANTENNA_2_4GHZ_SW_PORT_BASE GPIO_PORT_TO_BASE(ANTENNA_2_4GHZ_SW_PORT)
|
||||
#define ANTENNA_2_4GHZ_SW_PIN_MASK GPIO_PIN_MASK(ANTENNA_2_4GHZ_SW_PIN)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t initialized = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
antenna_sw_config(void)
|
||||
{
|
||||
/* Software controlled */
|
||||
GPIO_SOFTWARE_CONTROL(ANTENNA_2_4GHZ_SW_PORT_BASE,
|
||||
ANTENNA_2_4GHZ_SW_PIN_MASK);
|
||||
|
||||
/* Set pin to output */
|
||||
GPIO_SET_OUTPUT(ANTENNA_2_4GHZ_SW_PORT_BASE, ANTENNA_2_4GHZ_SW_PIN_MASK);
|
||||
|
||||
/* Set the antenna selector to a default position */
|
||||
GPIO_CLR_PIN(ANTENNA_2_4GHZ_SW_PORT_BASE, ANTENNA_2_4GHZ_SW_PIN_MASK);
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
antenna_sw_select(uint8_t val)
|
||||
{
|
||||
if(!initialized) {
|
||||
return ANTENNA_SW_SELECT_ERROR;
|
||||
}
|
||||
|
||||
if(val != ANTENNA_SW_SELECT_INTERNAL && val != ANTENNA_SW_SELECT_EXTERNAL) {
|
||||
return ANTENNA_SW_SELECT_ERROR;
|
||||
}
|
||||
|
||||
/* Set the antenna selector */
|
||||
GPIO_WRITE_PIN(ANTENNA_2_4GHZ_SW_PORT_BASE, ANTENNA_2_4GHZ_SW_PIN_MASK, val);
|
||||
|
||||
return val;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
82
platform/remote/dev/antenna-sw.h
Normal file
82
platform/remote/dev/antenna-sw.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia
|
||||
* 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.
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \addtogroup remote
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-antenna Re-Mote Antenna switch
|
||||
*
|
||||
* Driver for the Re-Mote 2.4Ghz antenna switch, to enable either the internal
|
||||
* ceramic antenna or an external one connected to the uFL connector
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Re-Mote 2.4Ghz antenna switch Driver
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#ifndef ANTENNA_SW_H_
|
||||
#define ANTENNA_SW_H_
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define ANTENNA_SW_SELECT_EXTERNAL 0xFF
|
||||
#define ANTENNA_SW_SELECT_INTERNAL 0x00
|
||||
|
||||
#define ANTENNA_SW_SELECT_ERROR -1
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \brief Init function for the antenna switch
|
||||
*
|
||||
* The Re-Mote platform allows to programatically select between the 2.4Ghz
|
||||
* internal or external antenna.
|
||||
* The function is set to enable using the internal ceramic antenna as default,
|
||||
* it should be called from the contiki-main initialization process.
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
void antenna_sw_config(void);
|
||||
|
||||
/**
|
||||
* \brief Function to select between the internal or external 2.4Ghz antenna
|
||||
*
|
||||
* \param val Select antenna.
|
||||
* External: ANTENNA_SW_SELECT_EXTERNAL or
|
||||
* Internal (ceramic): ANTENNA_SW_SELECT_INTERNAL
|
||||
* \return the selected antenna position, or ANTENNA_SW_SELECT_ERROR if not
|
||||
* previously configured
|
||||
*/
|
||||
int antenna_sw_select(uint8_t val);
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef ANTENNA_SW_H_ */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
278
platform/remote/dev/board.h
Normal file
278
platform/remote/dev/board.h
Normal file
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
* 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
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-peripherals Re-Mote Peripherals
|
||||
*
|
||||
* Defines related to the Re-Mote
|
||||
*
|
||||
* This file provides connectivity information on LEDs, Buttons, UART and
|
||||
* other Re-Mote peripherals
|
||||
*
|
||||
* This file can be used as the basis to configure other platforms using the
|
||||
* cc2538 SoC.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with definitions related to the I/O connections on the Zolertia's
|
||||
* Re-Mote platform, cc2538-based
|
||||
*
|
||||
* \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 Re-Mote LED configuration
|
||||
*
|
||||
* LEDs on the Re-mote are connected as follows:
|
||||
* - LED1 (Red) -> PD2
|
||||
* - LED2 (Blue) -> PC3
|
||||
* - LED3 (Green) -> PD5
|
||||
*
|
||||
* LED1 routed also to JP5 connector
|
||||
* LED2 shares the same pin with Watchdog WDI pulse and routed to JP8 connector
|
||||
* LED3 routed also to JP5 connector
|
||||
* @{
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* 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_BLUE
|
||||
#undef LEDS_RED
|
||||
#undef LEDS_CONF_ALL
|
||||
|
||||
/* In leds.h the LEDS_BLUE is defined by LED_YELLOW definition */
|
||||
#define LEDS_GREEN 1 /**< LED1 (Green) -> PD5 */
|
||||
#define LEDS_BLUE 2 /**< LED2 (Blue) -> PC3 */
|
||||
#define LEDS_RED 4 /**< LED3 (Red) -> PD2 */
|
||||
|
||||
#define LEDS_CONF_ALL 7
|
||||
|
||||
#define LEDS_LIGHT_BLUE (LEDS_GREEN | LEDS_BLUE) /**< Green + Blue (3) */
|
||||
#define LEDS_YELLOW (LEDS_GREEN | LEDS_RED) /**< Green + Red (5) */
|
||||
#define LEDS_PURPLE (LEDS_BLUE | LEDS_RED) /**< Blue + Red (6) */
|
||||
#define LEDS_WHITE LEDS_ALL /**< Green + Blue + Red (7) */
|
||||
|
||||
/* Notify various examples that we have LEDs */
|
||||
#define PLATFORM_HAS_LEDS 1
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \name USB configuration
|
||||
*
|
||||
* The USB pullup is enabled by an external resistor, not mapped to a GPIO
|
||||
*/
|
||||
#ifdef USB_PULLUP_PORT
|
||||
#undef USB_PULLUP_PORT
|
||||
#endif
|
||||
#ifdef USB_PULLUP_PIN
|
||||
#undef USB_PULLUP_PIN
|
||||
#endif
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \name UART configuration
|
||||
*
|
||||
* On the Re-Mote, the UART is connected to the following ports/pins
|
||||
* - UART0:
|
||||
* - RX: PA0
|
||||
* - TX: PA1
|
||||
* - UART1:
|
||||
* - RX: PC6
|
||||
* - TX: PC5
|
||||
* - CTS:
|
||||
* - RTS:
|
||||
* We configure the port to use UART0 and UART1, CTS/RTS only for UART1,
|
||||
* both without a HW pull-up resistor
|
||||
* @{
|
||||
*/
|
||||
#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_C_NUM
|
||||
#define UART1_RX_PIN 6
|
||||
#define UART1_TX_PORT GPIO_C_NUM
|
||||
#define UART1_TX_PIN 5
|
||||
#define UART1_CTS_PORT GPIO_C_NUM
|
||||
#define UART1_CTS_PIN 1
|
||||
#define UART1_RTS_PORT GPIO_C_NUM
|
||||
#define UART1_RTS_PIN 2
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \name Re-Mote Button configuration
|
||||
*
|
||||
* Buttons on the Re-Mote are connected as follows:
|
||||
* - BUTTON_USER -> PA3, S1 user button, shared with bootloader
|
||||
* - BUTTON_RESET -> RESET_N line, S2 reset both CC2538 and CoP
|
||||
* - BUTTON_VBAT -> Power switch, not mounted by default
|
||||
* @{
|
||||
*/
|
||||
/** BUTTON_USER -> PA3 */
|
||||
#define BUTTON_USER_PORT GPIO_A_NUM
|
||||
#define BUTTON_USER_PIN 3
|
||||
#define BUTTON_USER_VECTOR NVIC_INT_GPIO_PORT_A
|
||||
|
||||
/* Notify various examples that we have Buttons */
|
||||
#define PLATFORM_HAS_BUTTON 1
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name ADC configuration
|
||||
*
|
||||
* These values configure which CC2538 pins and ADC channels to use for the ADC
|
||||
* inputs. By default the Re-Mote allows two out-of-the-box ADC ports with a
|
||||
* phidget-like 3-pin connector (GND/3V3/ADC)
|
||||
*
|
||||
* ADC inputs can only be on port A.
|
||||
* @{
|
||||
*/
|
||||
#define ADC_PHIDGET_PORT GPIO_A_NUM /**< Phidget GPIO control port */
|
||||
#define ADC_PHIDGET_ADC2_PIN 6 /**< ADC2 to PA6, 3V3 */
|
||||
#define ADC_PHIDGET_ADC3_PIN 7 /**< ADC3 to PA7, 3V3 */
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name SPI (SSI0) configuration
|
||||
*
|
||||
* These values configure which CC2538 pins to use for the SPI (SSI0) lines,
|
||||
* shared with the CC1120 RF transceiver
|
||||
* TX -> MOSI, RX -> MISO
|
||||
* @{
|
||||
*/
|
||||
#define SPI0_CLK_PORT GPIO_D_NUM
|
||||
#define SPI0_CLK_PIN 1
|
||||
#define SPI0_TX_PORT GPIO_D_NUM
|
||||
#define SPI0_TX_PIN 0
|
||||
#define SPI0_RX_PORT GPIO_C_NUM
|
||||
#define SPI0_RX_PIN 4
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name SPI (SSI1) configuration
|
||||
*
|
||||
* These values configure which CC2538 pins to use for the SPI (SSI1) lines,
|
||||
* shared with the microSD, not routed anywhere.
|
||||
* TX -> MOSI, RX -> MISO
|
||||
* @{
|
||||
*/
|
||||
#define SPI1_CLK_PORT GPIO_B_NUM
|
||||
#define SPI1_CLK_PIN 5
|
||||
#define SPI1_TX_PORT GPIO_C_NUM
|
||||
#define SPI1_TX_PIN 7
|
||||
#define SPI1_RX_PORT GPIO_A_NUM
|
||||
#define SPI1_RX_PIN 4
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name I2C configuration
|
||||
*
|
||||
* These values configure which CC2538 pins to use for the I2C lines, shared
|
||||
* with the TMP102 built-in temperature sensor
|
||||
* @{
|
||||
*/
|
||||
#define I2C_SCL_PORT GPIO_B_NUM
|
||||
#define I2C_SCL_PIN 1
|
||||
#define I2C_SDA_PORT GPIO_B_NUM
|
||||
#define I2C_SDA_PIN 0
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Antenna switch configuration
|
||||
*
|
||||
* These values configure the required pin to drive the antenna switch, to
|
||||
* use either the built-in ceramic antenna or an external one over the uFL
|
||||
* connector
|
||||
* - Internal antenna: LOW
|
||||
* - External antenna: HIGH
|
||||
* @{
|
||||
*/
|
||||
#define ANTENNA_2_4GHZ_SW_PORT GPIO_D_NUM
|
||||
#define ANTENNA_2_4GHZ_SW_PIN 4
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name CC1120/CC1200 configuration
|
||||
*
|
||||
* These values configure the required pins to drive the CC1120/CC1200
|
||||
* @{
|
||||
*/
|
||||
#define CC1120_SPI_SCLK_PORT SPI0_CLK_PORT
|
||||
#define CC1120_SPI_SCLK_PIN SPI0_CLK_PIN
|
||||
#define CC1120_SPI_MOSI_PORT SPIO0_TX_PORT
|
||||
#define CC1120_SPI_MOSI_PIN SPIO0_TX_PIN
|
||||
#define CC1120_SPI_MISO_PORT SPIO0_RX_PORT
|
||||
#define CC1120_SPI_MISO_PIN SPIO0_RX_PIN
|
||||
#define CC1120_SPI_CSN_PORT GPIO_D_NUM
|
||||
#define CC1120_SPI_CSN_PIN 3
|
||||
#define CC1120_GDO0_PORT GPIO_B_NUM
|
||||
#define CC1120_GDO0_PIN 4
|
||||
#define CC1120_GDO2_PORT GPIO_B_NUM
|
||||
#define CC1120_GDO2_PIN 3
|
||||
#define CC1120_RESET_PORT GPIO_B_NUM
|
||||
#define CC1120_RESET_PIN 2
|
||||
#define CC1120_GPIO0_VECTOR NVIC_INT_GPIO_PORT_B
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name microSD configuration
|
||||
*
|
||||
* These values configure the required pins to drive the built-in microSD
|
||||
* external module, to be used with SSI1
|
||||
* @{
|
||||
*/
|
||||
#define USD_CLK_PORT SPI1_CLK_PORT
|
||||
#define USD_CLK_PIN SPI1_CLK_PIN
|
||||
#define USD_MOSI_PORT SPI1_TX_PORT
|
||||
#define USD_MOSI_PIN SPI1_TX_PIN
|
||||
#define USD_MISO_PORT SPI1_RX_PORT
|
||||
#define USD_MISO_PIN SPI1_RX_PIN
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_STRING "Zolertia Re-Mote platform"
|
||||
/** @} */
|
||||
|
||||
#endif /* BOARD_H_ */
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
178
platform/remote/dev/button-sensor.c
Normal file
178
platform/remote/dev/button-sensor.c
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-button-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Re-Mote 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);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
83
platform/remote/dev/button-sensor.h
Normal file
83
platform/remote/dev/button-sensor.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-button-sensor Re-Mote User Button Driver
|
||||
*
|
||||
* Driver for the Re-Mote user button
|
||||
*
|
||||
* The Re-Mote button will generate a sensors_changed event on press as well
|
||||
* as on release.
|
||||
*
|
||||
* Unlike many other platforms, the Re-Mote user button has the ability to
|
||||
* generate events when the user keeps the button pressed. The user can
|
||||
* configure the button driver with a timer interval in clock ticks. When the
|
||||
* button is kept pressed, the driver will then generate a broadcast event
|
||||
* each time the interval passes. For example the driver can be configured to
|
||||
* generate an event every second while the button is kept pressed. This
|
||||
* functionality can be enabled through the configure() function, by passing
|
||||
* BUTTON_SENSOR_CONFIG_TYPE_INTERVAL as the type argument.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Re-Mote User 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_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
110
platform/remote/dev/led-strip.c
Normal file
110
platform/remote/dev/led-strip.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-led-strip
|
||||
* @{
|
||||
*
|
||||
* Driver to control a bright LED strip powered at 3VDC, drawing power directly
|
||||
* from the battery power supply. An example on how to adapt 12VDC LED strips
|
||||
* to 3VDC is provided at http://www.hackster.io/zolertia
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Re-Mote bright LED strip Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "led-strip.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef LED_STRIP_PORT
|
||||
#define LED_STRIP_PORT GPIO_A_NUM
|
||||
#endif
|
||||
#ifndef LED_STRIP_PIN
|
||||
#define LED_STRIP_PIN 6
|
||||
#endif
|
||||
#define LED_STRIP_PORT_BASE GPIO_PORT_TO_BASE(LED_STRIP_PORT)
|
||||
#define LED_STRIP_PIN_MASK GPIO_PIN_MASK(LED_STRIP_PIN)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t initialized = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
led_strip_config(void)
|
||||
{
|
||||
/* Software controlled */
|
||||
GPIO_SOFTWARE_CONTROL(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK);
|
||||
/* Set pin to output */
|
||||
GPIO_SET_OUTPUT(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK);
|
||||
/* Set the antenna selector to a default position */
|
||||
GPIO_SET_PIN(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK);
|
||||
|
||||
initialized = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
led_strip_switch(uint8_t val)
|
||||
{
|
||||
if(!initialized) {
|
||||
return LED_STRIP_ERROR;
|
||||
}
|
||||
|
||||
if(val != LED_STRIP_ON && val != LED_STRIP_OFF) {
|
||||
return LED_STRIP_ERROR;
|
||||
}
|
||||
|
||||
/* Set the LED to ON or OFF */
|
||||
GPIO_WRITE_PIN(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK, val);
|
||||
|
||||
return val;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
led_strip_get(void)
|
||||
{
|
||||
if(!initialized) {
|
||||
return LED_STRIP_ERROR;
|
||||
}
|
||||
|
||||
/* Inverse logic, return ON if the pin is low */
|
||||
if(GPIO_READ_PIN(LED_STRIP_PORT_BASE, LED_STRIP_PIN_MASK)) {
|
||||
return LED_STRIP_OFF;
|
||||
}
|
||||
return LED_STRIP_ON;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
90
platform/remote/dev/led-strip.h
Normal file
90
platform/remote/dev/led-strip.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia
|
||||
* 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.
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \addtogroup remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-led-strip Re-Mote LED strip driver
|
||||
*
|
||||
* Driver to control a bright LED strip powered at 3VDC, drawing power directly
|
||||
* from the battery power supply. An example on how to adapt 12VDC LED strips
|
||||
* to 3VDC is provided at http://www.hackster.io/zolertia
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Re-Mote bright LED strip Driver
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#ifndef LED_STRIP_H_
|
||||
#define LED_STRIP_H_
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define LED_STRIP_OFF 0xFF
|
||||
#define LED_STRIP_ON 0x00
|
||||
|
||||
#define LED_STRIP_ERROR -1
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \brief Init function for the bright LED strip driver
|
||||
*
|
||||
* The LED strip driver allows to lighten up any application using up to 4
|
||||
* LEDs 3VDC-powered per strip
|
||||
* The function is set to power OFF the LEDs as default,
|
||||
* it should be called from the contiki-main initialization process.
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
void led_strip_config(void);
|
||||
|
||||
/**
|
||||
* \brief Function to turn ON/OFF the LED strip
|
||||
*
|
||||
* \param val Set ON/OFF (LED_STRIP_ON or LED_STRIP_OFF)
|
||||
* \return the selected antenna position, or LED_STRIP_ERROR if not
|
||||
* previously configured
|
||||
*/
|
||||
int led_strip_switch(uint8_t val);
|
||||
|
||||
/**
|
||||
* \brief Function to get the LED strip current state
|
||||
*
|
||||
* \return Current LED strip state or LED_STRIP_ERROR if not
|
||||
* previously configured
|
||||
*/
|
||||
int led_strip_get(void);
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef LED_STRIP_H_ */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
111
platform/remote/dev/leds-arch.c
Normal file
111
platform/remote/dev/leds-arch.c
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup remote
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-leds Re-Mote LED driver
|
||||
*
|
||||
* LED driver implementation for the Re-Mote platform
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* LED driver implementation for the Re-Mote platform
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "reg.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/gpio.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LED_GREEN_PORT GPIO_D_BASE
|
||||
#define LED_GREEN_PIN (1 << 5)
|
||||
|
||||
#define LED_BLUE_PORT GPIO_C_BASE
|
||||
#define LED_BLUE_PIN (1 << 3)
|
||||
|
||||
#define LED_RED_PORT GPIO_D_BASE
|
||||
#define LED_RED_PIN (1 << 2)
|
||||
|
||||
#define PORT_D_LEDS (LED_RED_PIN | LED_GREEN_PIN)
|
||||
#define PORT_C_LEDS LED_BLUE_PIN
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
leds_arch_init(void)
|
||||
{
|
||||
/* Initialize LED1 (Red) and LED3 (Green) */
|
||||
GPIO_SET_OUTPUT(GPIO_D_BASE, PORT_D_LEDS);
|
||||
GPIO_SET_PIN(GPIO_D_BASE, PORT_D_LEDS);
|
||||
|
||||
/* Initialize LED2 - Blue */
|
||||
GPIO_SET_OUTPUT(GPIO_C_BASE, PORT_C_LEDS);
|
||||
GPIO_SET_PIN(GPIO_C_BASE, PORT_C_LEDS);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
unsigned char
|
||||
leds_arch_get(void)
|
||||
{
|
||||
uint8_t mask_leds;
|
||||
|
||||
mask_leds = GPIO_READ_PIN(LED_GREEN_PORT, LED_GREEN_PIN) == 0? LEDS_GREEN : 0;
|
||||
mask_leds |= GPIO_READ_PIN(LED_BLUE_PORT, LED_BLUE_PIN) == 0? LEDS_BLUE : 0;
|
||||
mask_leds |= GPIO_READ_PIN(LED_RED_PORT, LED_RED_PIN) == 0? LEDS_RED : 0;
|
||||
|
||||
return mask_leds;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
leds_arch_set(unsigned char leds)
|
||||
{
|
||||
if(leds & LEDS_GREEN) {
|
||||
GPIO_CLR_PIN(LED_GREEN_PORT, LED_GREEN_PIN);
|
||||
} else {
|
||||
GPIO_SET_PIN(LED_GREEN_PORT, LED_GREEN_PIN);
|
||||
}
|
||||
|
||||
if(leds & LEDS_BLUE) {
|
||||
GPIO_CLR_PIN(LED_BLUE_PORT, LED_BLUE_PIN);
|
||||
} else {
|
||||
GPIO_SET_PIN(LED_BLUE_PORT, LED_BLUE_PIN);
|
||||
}
|
||||
|
||||
if(leds & LEDS_RED) {
|
||||
GPIO_CLR_PIN(LED_RED_PORT, LED_RED_PIN);
|
||||
} else {
|
||||
GPIO_SET_PIN(LED_RED_PORT, LED_RED_PIN);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
286
platform/remote/dev/mp3-wtv020sd.c
Normal file
286
platform/remote/dev/mp3-wtv020sd.c
Normal file
|
@ -0,0 +1,286 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-mp3-wtv020sd
|
||||
* @{
|
||||
*
|
||||
* Driver to control the MP3 WTV020SD board in MP3 mode (GPIO based) and the
|
||||
* 2-line serial mode (CLK/DI). Loop Mode and Key Modes not implemented.
|
||||
* More product information available at:
|
||||
* http://avrproject.ru/chasy-budilnik/WTV020SD.pdf
|
||||
* An example on how to wire with a sound power amplifier and speakers at
|
||||
* http://www.hackster.io/zolertia
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the MP3 WTV020SD driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "mp3-wtv020sd.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* The WTV020SD can be used in MP3 mode (GPIO-controlled) or 2-line mode (CLK
|
||||
* and DATA line). The following pin-out can be implemented without reusing
|
||||
* the pins as below (in 2-line mode the CLK/DATA functions replace the VOL+/-
|
||||
* keys, others remain the same), but this would require more GPIOs to
|
||||
* interface all functions, so we chose the configuration that uses the less
|
||||
* number of GPIOs, and emulate all functions available in each mode
|
||||
*/
|
||||
#ifndef MP3_WTV020SD_P07_PORT
|
||||
#define MP3_WTV020SD_P07_PORT GPIO_B_NUM
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P07_PIN
|
||||
#define MP3_WTV020SD_P07_PIN 0
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P02_PORT
|
||||
#define MP3_WTV020SD_P02_PORT GPIO_B_NUM
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P02_PIN
|
||||
#define MP3_WTV020SD_P02_PIN 1
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P06_PORT
|
||||
#define MP3_WTV020SD_P06_PORT GPIO_C_NUM
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P06_PIN
|
||||
#define MP3_WTV020SD_P06_PIN 1
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P04_PORT
|
||||
#define MP3_WTV020SD_P04_PORT GPIO_B_NUM
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P04_PIN
|
||||
#define MP3_WTV020SD_P04_PIN 0
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P05_PORT
|
||||
#define MP3_WTV020SD_P05_PORT GPIO_B_NUM
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_P05_PIN
|
||||
#define MP3_WTV020SD_P05_PIN 1
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_RESET_PORT
|
||||
#define MP3_WTV020SD_RESET_PORT GPIO_B_NUM
|
||||
#endif
|
||||
#ifndef MP3_WTV020SD_RESET_PIN
|
||||
#define MP3_WTV020SD_RESET_PIN 1
|
||||
#endif
|
||||
|
||||
/* The BUSY pin is shared between operation modes */
|
||||
#define MP3_BUSY_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P06_PORT)
|
||||
#define MP3_BUSY_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P06_PIN)
|
||||
|
||||
#define MP3_PLAY_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P07_PORT)
|
||||
#define MP3_PLAY_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P07_PIN)
|
||||
#define MP3_NEXT_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P02_PORT)
|
||||
#define MP3_NEXT_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P02_PIN)
|
||||
|
||||
#define MP3_RESET_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_RESET_PORT)
|
||||
#define MP3_RESET_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_RESET_PIN)
|
||||
#define MP3_CLK_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P04_PORT)
|
||||
#define MP3_CLK_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P04_PIN)
|
||||
#define MP3_DATA_PORT_BASE GPIO_PORT_TO_BASE(MP3_WTV020SD_P05_PORT)
|
||||
#define MP3_DATA_PIN_MASK GPIO_PIN_MASK(MP3_WTV020SD_P05_PIN)
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t initialized = 0;
|
||||
static int mp3_line_command(uint16_t cmd);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_config(uint8_t mode)
|
||||
{
|
||||
if(mode != MP3_WTV020SD_GPIO_MODE && mode != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
|
||||
if(mode == MP3_WTV020SD_GPIO_MODE) {
|
||||
GPIO_SOFTWARE_CONTROL(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
GPIO_SET_OUTPUT(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
GPIO_SOFTWARE_CONTROL(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
|
||||
GPIO_SET_OUTPUT(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_NEXT_PORT_BASE, MP3_NEXT_PIN_MASK);
|
||||
} else {
|
||||
GPIO_SOFTWARE_CONTROL(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
|
||||
GPIO_SET_OUTPUT(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
|
||||
GPIO_SOFTWARE_CONTROL(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
GPIO_SET_OUTPUT(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
GPIO_SOFTWARE_CONTROL(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
|
||||
GPIO_SET_OUTPUT(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
|
||||
}
|
||||
|
||||
GPIO_SOFTWARE_CONTROL(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK);
|
||||
GPIO_SET_INPUT(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK);
|
||||
|
||||
initialized = mode;
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_gpio_play(void)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_GPIO_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
GPIO_CLR_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_gpio_stop(void)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_GPIO_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_gpio_next(void)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_GPIO_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
GPIO_CLR_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
clock_delay_usec(MP3_USEC_DELAY);
|
||||
GPIO_SET_PIN(MP3_PLAY_PORT_BASE, MP3_PLAY_PIN_MASK);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_busy(void)
|
||||
{
|
||||
if((initialized != MP3_WTV020SD_GPIO_MODE) &&
|
||||
(initialized != MP3_WTV020SD_LINE_MODE)) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
if(GPIO_READ_PIN(MP3_BUSY_PORT_BASE, MP3_BUSY_PIN_MASK)) {
|
||||
return MP3_WTV020SD_BUSY;
|
||||
}
|
||||
return MP3_WTV020SD_IDLE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_reset(void)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
GPIO_CLR_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
|
||||
GPIO_CLR_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
|
||||
clock_delay_usec(MP3_USEC_DELAY);
|
||||
GPIO_SET_PIN(MP3_RESET_PORT_BASE, MP3_RESET_PIN_MASK);
|
||||
GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
clock_delay_usec(MP3_USEC_RESET_DELAY);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_sync_play(uint16_t track)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
mp3_line_command(track);
|
||||
while(mp3_wtv020sd_busy());
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_async_play(uint16_t track)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
mp3_line_command(track);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_stop(void)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
mp3_line_command(MP3_WTV020SD_STOP_VAL);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_wtv020sd_pause(void)
|
||||
{
|
||||
if(initialized != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
mp3_line_command(MP3_WTV020SD_PLAY_PAUSE_VAL);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
mp3_line_command(uint16_t cmd)
|
||||
{
|
||||
uint16_t mask;
|
||||
if(initialized != MP3_WTV020SD_LINE_MODE) {
|
||||
return MP3_WTV020SD_ERROR;
|
||||
}
|
||||
GPIO_CLR_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
clock_delay_usec(MP3_USEC_CMD_DELAY / 10);
|
||||
for(mask = 0x8000; mask > 0; mask >> 1) {
|
||||
GPIO_CLR_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
clock_delay_usec(MP3_USEC_CMD_DELAY / 2);
|
||||
if(cmd & mask) {
|
||||
GPIO_SET_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
|
||||
} else {
|
||||
GPIO_CLR_PIN(MP3_DATA_PORT_BASE, MP3_DATA_PIN_MASK);
|
||||
}
|
||||
clock_delay_usec(MP3_USEC_CMD_DELAY / 2);
|
||||
GPIO_SET_PIN(MP3_CLK_PORT_BASE, MP3_CLK_PIN_MASK);
|
||||
clock_delay_usec(MP3_USEC_CMD_DELAY);
|
||||
if(mask > 0x0001) {
|
||||
clock_delay_usec(MP3_USEC_CMD_DELAY / 10);
|
||||
}
|
||||
}
|
||||
clock_delay_usec(MP3_USEC_CMD_DELAY / 8);
|
||||
return MP3_WTV020SD_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
159
platform/remote/dev/mp3-wtv020sd.h
Normal file
159
platform/remote/dev/mp3-wtv020sd.h
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia
|
||||
* 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.
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \addtogroup remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-mp3-wtv020sd Re-Mote MP3 WTV020SD driver
|
||||
*
|
||||
* Driver to control the MP3 WTV020SD board in MP3 mode (GPIO based) and the
|
||||
* 2-line serial mode (CLK/DI). Loop Mode and Key Modes not implemented.
|
||||
* More product information available at:
|
||||
* http://avrproject.ru/chasy-budilnik/WTV020SD.pdf
|
||||
* An example on how to wire with a sound power amplifier and speakers at
|
||||
* http://www.hackster.io/zolertia
|
||||
* Based on the Arduino Wtv020sd16p library
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the MP3 WTV020SD driver
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#ifndef MP3_WTV020SD_H_
|
||||
#define MP3_WTV020SD_H_
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define MP3_WTV020SD_ERROR -1
|
||||
#define MP3_WTV020SD_SUCCESS 0x00
|
||||
#define MP3_WTV020SD_GPIO_MODE 0x01
|
||||
#define MP3_WTV020SD_LINE_MODE 0x02
|
||||
#define MP3_WTV020SD_IDLE 0x00
|
||||
#define MP3_WTV020SD_BUSY 0x0F
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define MP3_WTV020SD_PLAY_PAUSE_VAL 0xFFFE
|
||||
#define MP3_WTV020SD_STOP_VAL 0xFFFF
|
||||
#define MP3_WTV020SD_VOLUME_MIN 0xFFF0
|
||||
#define MP3_WTV020SD_VOLUME_MAX 0xFFF7
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define MP3_USEC_DELAY 1000
|
||||
#define MP3_USEC_CMD_DELAY 100
|
||||
#define MP3_USEC_RESET_DELAY ((MP3_USEC_DELAY) * 30)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define MP3_TRACK_BASE 0 /* 0000.ad4 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \brief Init function for the MP3 driver
|
||||
*
|
||||
* Configures the pins required to operate in either driver mode
|
||||
*
|
||||
* \param mode drive the board using GPIOs or the two-line mode, using
|
||||
* either MP3_WTV020SD_GPIO_MODE or MP3_WTV020SD_LINE_MODE
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode selected, otherwise it
|
||||
* will return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_config(uint8_t mode);
|
||||
/**
|
||||
* \brief Function to play a current track
|
||||
*
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_gpio_play(void);
|
||||
/**
|
||||
* \brief Function to stop a current track
|
||||
*
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_gpio_stop(void);
|
||||
/**
|
||||
* \brief Advances and play the next track, wraps over the playlist
|
||||
*
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_gpio_next(void);
|
||||
/**
|
||||
* \brief Get the current status of the device (playing/stopped)
|
||||
*
|
||||
* \return MP3_WTV020SD_BUSY if a track is playing, otherwise it will
|
||||
* return MP3_WTV020SD_IDLE
|
||||
*/
|
||||
int mp3_wtv020sd_busy(void);
|
||||
/**
|
||||
* \brief Trigger a module reset
|
||||
*
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_reset(void);
|
||||
/**
|
||||
* \brief Plays the selected track and waits until it stops
|
||||
*
|
||||
* \param track forwards and play the selected track, starting from
|
||||
* MP3_TRACK_BASE (0000.ad4) up to MP3_TRACK_BASE + 511
|
||||
* (0511.ad4)
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_sync_play(uint16_t track);
|
||||
/**
|
||||
* \brief Plays the selected track and returns immediately
|
||||
*
|
||||
* \param track forwards and play the selected track, starting from
|
||||
* MP3_TRACK_BASE (0000.ad4) up to MP3_TRACK_BASE + 511
|
||||
* (0511.ad4)
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_async_play(uint16_t track);
|
||||
/**
|
||||
* \brief Stops the current track
|
||||
*
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_stop(void);
|
||||
/**
|
||||
* \brief Pauses the current track
|
||||
*
|
||||
* \return MP3_WTV020SD_ERROR if invalid mode used, otherwise it will
|
||||
* return MP3_WTV020SD_SUCCESS
|
||||
*/
|
||||
int mp3_wtv020sd_pause(void);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef MP3_WTV020SD_H_ */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
125
platform/remote/dev/phidget-sensor.c
Normal file
125
platform/remote/dev/phidget-sensor.c
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-phidget-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Generic driver for the Re-Mote Phidget/ADC sensors
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "sys/clock.h"
|
||||
#include "dev/ioc.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "dev/adc.h"
|
||||
#include "dev/phidget-sensor.h"
|
||||
#include "dev/remote-sensors.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define ADC_PHIDGET_PORT_BASE GPIO_PORT_TO_BASE(ADC_PHIDGET_PORT)
|
||||
#define ADC_PHIDGET_ADC2_PIN_MASK GPIO_PIN_MASK(ADC_PHIDGET_ADC2_PIN)
|
||||
#define ADC_PHIDGET_ADC3_PIN_MASK GPIO_PIN_MASK(ADC_PHIDGET_ADC3_PIN)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t decimation_rate;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
set_decimation_rate(uint8_t rate)
|
||||
{
|
||||
switch(rate) {
|
||||
case SOC_ADC_ADCCON_DIV_64:
|
||||
case SOC_ADC_ADCCON_DIV_128:
|
||||
case SOC_ADC_ADCCON_DIV_256:
|
||||
case SOC_ADC_ADCCON_DIV_512:
|
||||
decimation_rate = rate;
|
||||
break;
|
||||
default:
|
||||
return REMOTE_SENSORS_ERROR;
|
||||
}
|
||||
|
||||
return decimation_rate;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
uint8_t channel;
|
||||
int16_t res;
|
||||
|
||||
switch(type) {
|
||||
case PHIDGET_SENSORS_ADC2:
|
||||
channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_PHIDGET_ADC2_PIN;
|
||||
break;
|
||||
case PHIDGET_SENSORS_ADC3:
|
||||
channel = SOC_ADC_ADCCON_CH_AIN0 + ADC_PHIDGET_ADC3_PIN;
|
||||
break;
|
||||
default:
|
||||
return REMOTE_SENSORS_ERROR;
|
||||
}
|
||||
|
||||
res = adc_get(channel, SOC_ADC_ADCCON_REF_INT, decimation_rate);
|
||||
|
||||
return res;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
GPIO_SOFTWARE_CONTROL(GPIO_A_BASE, ADC_PHIDGET_ADC2_PIN_MASK);
|
||||
GPIO_SET_INPUT(GPIO_A_BASE, ADC_PHIDGET_ADC2_PIN_MASK);
|
||||
ioc_set_over(GPIO_A_NUM, ADC_PHIDGET_ADC2_PIN, IOC_OVERRIDE_ANA);
|
||||
|
||||
GPIO_SOFTWARE_CONTROL(GPIO_A_BASE, ADC_PHIDGET_ADC3_PIN_MASK);
|
||||
GPIO_SET_INPUT(GPIO_A_BASE, ADC_PHIDGET_ADC3_PIN_MASK);
|
||||
ioc_set_over(GPIO_A_NUM, ADC_PHIDGET_ADC3_PIN, IOC_OVERRIDE_ANA);
|
||||
adc_init();
|
||||
set_decimation_rate(SOC_ADC_ADCCON_DIV_512);
|
||||
break;
|
||||
case REMOTE_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE:
|
||||
return set_decimation_rate((uint8_t)value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(phidget_sensor, PHIDGET_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
84
platform/remote/dev/phidget-sensor.h
Normal file
84
platform/remote/dev/phidget-sensor.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-phidget-sensor Re-Mote Generic Phidget Sensor
|
||||
*
|
||||
* Driver for the Re-Mote phidget ADC sensor
|
||||
*
|
||||
* This driver supports phidgets connected to both the ADC2 and AND3 channels.
|
||||
* This is controlled by the type argument of the value() function. Possible
|
||||
* choices are:
|
||||
* - PHIDGET_SENSORS_ADC2 (channel 2)
|
||||
* - PHIDGET_SENSORS_ADC3 (channel 3)
|
||||
*
|
||||
* The decimation rate can be set by passing
|
||||
* REMOTE_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE as the type argument to the
|
||||
* configure() function and then specifying the rate through the value
|
||||
* argument. Valid values are:
|
||||
* - SOC_ADC_ADCCON_DIV_64 (64 bit rate)
|
||||
* - SOC_ADC_ADCCON_DIV_128 (128 bit rate)
|
||||
* - SOC_ADC_ADCCON_DIV_256 (256 bit rate)
|
||||
* - SOC_ADC_ADCCON_DIV_512 (512 bit rate)
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Re-Mote Generic Driver for Phidget/ADC sensors
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef PHIDGET_SENSOR_H_
|
||||
#define PHIDGET_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/soc-adc.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Generic phidget sensor
|
||||
* @{
|
||||
*/
|
||||
#define PHIDGET_SENSOR "Phidget ADC"
|
||||
|
||||
#define PHIDGET_SENSORS_ADC2 2 /**< 3V3 ADC phidget-like connector ADC2 */
|
||||
#define PHIDGET_SENSORS_ADC3 3 /**< 3V3 ADC phidget-like connector ADC3 */
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor phidget_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* PHIDGET_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
58
platform/remote/dev/remote-sensors.c
Normal file
58
platform/remote/dev/remote-sensors.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-sensors
|
||||
* @{
|
||||
*
|
||||
* Generic module controlling sensors on the Re-Mote platform
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Implementation of a generic module controlling Re-Mote sensors
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/phidget-sensor.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* TODO: include the tmp102 sensor as well */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Exports global symbols for the sensor API */
|
||||
SENSORS(&button_sensor, &vdd3_sensor, &cc2538_temp_sensor, &phidget_sensor);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
71
platform/remote/dev/remote-sensors.h
Normal file
71
platform/remote/dev/remote-sensors.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-sensors Re-Mote Sensors
|
||||
*
|
||||
* Generic module controlling sensors on the Re-Mote platform
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Implementation of a generic module controlling Re-Mote sensors
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef REMOTE_SENSORS_H_
|
||||
#define REMOTE_SENSORS_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/phidget-sensor.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name ReMote sensor constants
|
||||
*
|
||||
* These constants are used by various sensors on the ReMote. They can be used
|
||||
* to configure ADC decimation rate (where applicable).
|
||||
* @{
|
||||
*/
|
||||
#define REMOTE_SENSORS_CONFIGURE_TYPE_DECIMATION_RATE 0x0100 /**< Change decimation rate (used with configure()) */
|
||||
|
||||
#define REMOTE_SENSORS_ERROR CC2538_SENSORS_ERROR /**< Error */
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* REMOTE_SENSORS_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
138
platform/remote/dev/sht25.c
Normal file
138
platform/remote/dev/sht25.c
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.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 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 remote-sht25-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* SHT25 temperature and humidity sensor driver
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/i2c.h"
|
||||
#include "dev/sht25.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#warning I2C SDA AND SCL are inverted in JP8 connector, inverted in init() call
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
if(value) {
|
||||
i2c_init(I2C_SCL_PORT, I2C_SCL_PIN, I2C_SDA_PORT, I2C_SDA_PIN,
|
||||
I2C_SCL_NORMAL_BUS_SPEED);
|
||||
}
|
||||
enabled = value;
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
sht25_read_reg(uint8_t reg, uint8_t *buf, uint8_t regNum)
|
||||
{
|
||||
if(i2c_single_send(SHT25_ADDR, reg) == I2C_MASTER_ERR_NONE) {
|
||||
if(i2c_burst_receive(SHT25_ADDR, buf, regNum) == I2C_MASTER_ERR_NONE) {
|
||||
return SHT25_SUCCESS;
|
||||
}
|
||||
}
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int16_t
|
||||
sht25_convert(uint8_t variable, uint16_t value)
|
||||
{
|
||||
int16_t rd;
|
||||
uint32_t buff;
|
||||
buff = (uint32_t)value;
|
||||
if(variable == SHT25_VAL_TEMP) {
|
||||
buff *= 17572;
|
||||
buff = buff >> 16;
|
||||
rd = (int16_t)buff - 4685;
|
||||
} else {
|
||||
buff *= 12500;
|
||||
buff = buff >> 16;
|
||||
rd = (int16_t)buff - 600;
|
||||
rd = (rd > 10000) ? 10000 : rd;
|
||||
}
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int16_t
|
||||
sht25_read(uint8_t variable, uint16_t *rd)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
uint16_t raw;
|
||||
|
||||
if((variable != SHT25_VAL_TEMP) && (variable != SHT25_VAL_HUM)) {
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
|
||||
if (sht25_read_reg(variable, buf, 2) == SHT25_SUCCESS){
|
||||
raw = (buf[0] << 8) + buf[1];
|
||||
*rd = sht25_convert(variable, raw);
|
||||
return SHT25_SUCCESS;
|
||||
}
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
uint16_t val;
|
||||
if (sht25_read(type, &val) == SHT25_SUCCESS){
|
||||
return val;
|
||||
}
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(sht25, SHT25_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
84
platform/remote/dev/sht25.h
Normal file
84
platform/remote/dev/sht25.h
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.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 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 remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-sht25-sensor Re-Mote SHT25 digital temperature sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* SHT25 temperature and humidity sensor driver
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#ifndef SHT25_H_
|
||||
#define SHT25_H_
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_ADDR 0x40
|
||||
#define SHT25_TEMP_HOLD 0xE3
|
||||
#define SHT25_HUM_HOLD 0xE5
|
||||
#define SHT25_TEMP_NO_HOLD 0xF3
|
||||
#define SHT25_HUM_NO_HOLD 0xF5
|
||||
#define SHT2X_UREG_WRITE 0xE6
|
||||
#define SHT2X_UREG_READ 0xE7
|
||||
#define SHT2X_SOFT_RESET 0XFE
|
||||
#define SHT2X_NULL 0x00
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT2X_RES_14T_12RH 0x00
|
||||
#define SHT2X_RES_12T_08RH 0x01
|
||||
#define SHT2X_RES_13T_10RH 0x80
|
||||
#define SHT2X_RES_11T_11RH 0x81
|
||||
#define SHT2X_HEATER_ON 0x04
|
||||
#define SHT2X_HEATER_OFF 0x00
|
||||
#define SHT2X_OTP_RELOAD_EN 0x00
|
||||
#define SHT2X_OTP_RELOAD_DIS 0x02
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_VAL_TEMP SHT25_TEMP_HOLD
|
||||
#define SHT25_VAL_HUM SHT25_HUM_HOLD
|
||||
#define SHT25_ERROR -1
|
||||
#define SHT25_SUCCESS 0x00
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_SENSOR "SHT25 Sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor sht25;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef SHT25_H_ */
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
73
platform/remote/dev/tmp102.c
Normal file
73
platform/remote/dev/tmp102.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.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 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.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-tmp102-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Re-Mote TMP102 temperature sensor
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/i2c.h"
|
||||
#include "tmp102.h"
|
||||
|
||||
void
|
||||
tmp102_init(void)
|
||||
{
|
||||
i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
uint8_t
|
||||
tmp102_read(uint16_t *data)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
uint16_t temp;
|
||||
|
||||
/* Write to the temperature register to trigger a reading */
|
||||
if(i2c_single_send(TMP102_ADDR, TMP102_TEMP) == I2C_MASTER_ERR_NONE) {
|
||||
/* Read two bytes only */
|
||||
if(i2c_burst_receive(TMP102_ADDR, buf, 2) == I2C_MASTER_ERR_NONE) {
|
||||
temp = (buf[0] << 8) + buf[1];
|
||||
if(temp > 2047) {
|
||||
temp -= (1 << 12);
|
||||
}
|
||||
temp *= 0.625;
|
||||
*data = temp;
|
||||
return I2C_MASTER_ERR_NONE;
|
||||
}
|
||||
}
|
||||
return i2c_master_error();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
75
platform/remote/dev/tmp102.h
Normal file
75
platform/remote/dev/tmp102.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.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 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 remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-tmp102-sensor Re-Mote TMP102 Sensor
|
||||
*
|
||||
* Driver for the Re-Mote TMP102 sensor
|
||||
*
|
||||
* The TMP102 driver returns the converted temperature value in centiCelsius
|
||||
* with 2 digits precision, to get Celsius just divide by 100.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Re-Mote TMP102 Sensor Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef TMP102_H_
|
||||
#define TMP102_H_
|
||||
#include <stdio.h>
|
||||
#include "i2c.h"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \name Generic TMP102 sensor
|
||||
* @{
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TMP102_ADDR 0x48 /**< TMP102 slave address */
|
||||
#define TMP102_TEMP 0x00 /**< TMP102 temperature data register */
|
||||
/** @} */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef TMP102_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/** \brief Initialiser for the TMP102 sensor driver */
|
||||
void tmp102_init(void);
|
||||
|
||||
/** \brief Get a temperature reading from the TMP102 sensor */
|
||||
uint8_t tmp102_read(uint16_t *data);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
178
platform/remote/dev/tsl2563.c
Normal file
178
platform/remote/dev/tsl2563.c
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.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 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.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup remote-tsl2563-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Re-Mote external TSL2563 light sensor (Ziglet)
|
||||
*
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
* Toni Lozano <tlozano@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/i2c.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "tsl2563.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#warning I2C SDA AND SCL are inverted in JP8 connector, inverted in init() call
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
calculateLux(uint8_t *buf)
|
||||
{
|
||||
uint32_t ch0, ch1 = 0;
|
||||
uint32_t aux = (1 << 14);
|
||||
uint32_t ratio, lratio, tmp = 0;
|
||||
uint16_t buffer[2];
|
||||
|
||||
buffer[0] = (buf[1] << 8 | (buf[0]));
|
||||
buffer[1] = (buf[3] << 8 | (buf[2]));
|
||||
ch0 = (buffer[0] * aux) >> 10;
|
||||
ch1 = (buffer[1] * aux) >> 10;
|
||||
ratio = (ch1 << 10);
|
||||
ratio = ratio / ch0;
|
||||
lratio = (ratio + 1) >> 1;
|
||||
|
||||
if((lratio >= 0) && (lratio <= K1T)) {
|
||||
tmp = (ch0 * B1T) - (ch1 * M1T);
|
||||
} else if(lratio <= K2T) {
|
||||
tmp = (ch0 * B2T) - (ch1 * M2T);
|
||||
} else if(lratio <= K3T) {
|
||||
tmp = (ch0 * B3T) - (ch1 * M3T);
|
||||
} else if(lratio <= K4T) {
|
||||
tmp = (ch0 * B4T) - (ch1 * M4T);
|
||||
} else if(lratio <= K5T) {
|
||||
tmp = (ch0 * B5T) - (ch1 * M5T);
|
||||
} else if(lratio <= K6T) {
|
||||
tmp = (ch0 * B6T) - (ch1 * M6T);
|
||||
} else if(lratio <= K7T) {
|
||||
tmp = (ch0 * B7T) - (ch1 * M7T);
|
||||
} else if(lratio > K8T) {
|
||||
tmp = (ch0 * B8T) - (ch1 * M8T);
|
||||
}
|
||||
|
||||
if(tmp < 0) {
|
||||
tmp = 0;
|
||||
}
|
||||
|
||||
tmp += (1 << 13);
|
||||
return tmp >> 14;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
tsl2563_read_reg(uint8_t reg, uint8_t *buf, uint8_t regNum)
|
||||
{
|
||||
if(i2c_single_send(TSL2563_ADDR, reg) == I2C_MASTER_ERR_NONE) {
|
||||
if(i2c_burst_receive(TSL2563_ADDR, buf, regNum) == I2C_MASTER_ERR_NONE) {
|
||||
return TSL2563_SUCCESS;
|
||||
}
|
||||
}
|
||||
return TSL2563_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
light_ziglet_on(void)
|
||||
{
|
||||
if(i2c_single_send(TSL2563_ADDR, (uint8_t)TSL2563_PWRN) == I2C_MASTER_ERR_NONE) {
|
||||
return TSL2563_SUCCESS;
|
||||
}
|
||||
return TSL2563_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
light_ziglet_off(void)
|
||||
{
|
||||
if(i2c_single_send(TSL2563_ADDR, (uint8_t)TSL2563_PWROFF) == I2C_MASTER_ERR_NONE) {
|
||||
return TSL2563_SUCCESS;
|
||||
}
|
||||
return TSL2563_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
light_ziglet_read(uint16_t *lux)
|
||||
{
|
||||
uint8_t buf[4];
|
||||
if(light_ziglet_on() == TSL2563_SUCCESS) {
|
||||
if(tsl2563_read_reg(TSL2563_READ, buf, 4) == TSL2563_SUCCESS) {
|
||||
*lux = calculateLux(buf);
|
||||
return light_ziglet_off();
|
||||
}
|
||||
}
|
||||
return TSL2563_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return TSL2563_ERROR;
|
||||
}
|
||||
enabled = value;
|
||||
if(value) {
|
||||
i2c_init(I2C_SCL_PORT, I2C_SCL_PIN, I2C_SDA_PORT, I2C_SDA_PIN,
|
||||
I2C_SCL_NORMAL_BUS_SPEED);
|
||||
} else {
|
||||
light_ziglet_off();
|
||||
}
|
||||
return TSL2563_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
uint16_t lux;
|
||||
if(type == TSL2563_VAL_READ) {
|
||||
if(light_ziglet_read(&lux) != TSL2563_ERROR) {
|
||||
return lux;
|
||||
}
|
||||
}
|
||||
return TSL2563_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(tsl2563, TSL2563_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
111
platform/remote/dev/tsl2563.h
Normal file
111
platform/remote/dev/tsl2563.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.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 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 remote-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup remote-tsl2563-sensor Re-Mote TSL2563 Sensor
|
||||
*
|
||||
* Driver for the Re-Mote TSL2563 sensor
|
||||
*
|
||||
* The TSL2563 driver returns the converted light value value in lux
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Re-Mote external TSL2563 Sensor Driver
|
||||
*
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
* Toni Lozano <tlozano@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef LIGHT_SENSOR_H_
|
||||
#define LIGHT_SENSOR_H_
|
||||
#include <stdio.h>
|
||||
#include "lib/sensors.h"
|
||||
#include "i2c.h"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \name TSL2563 digital Light sensor
|
||||
* @{
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TSL2563_ADDR 0x39 /**< TSL2563 slave address */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TSL2563_READ 0xAC /**< TSL2563 read register */
|
||||
#define TSL2563_PWRN 0x03 /**< TSL2563 enable register */
|
||||
#define TSL2563_PWROFF 0x00 /**< TSL2563 Power OFF */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define K1T 0X0040 /**< Calibration values (hardcoded) */
|
||||
#define B1T 0x01f2
|
||||
#define M1T 0x01b2
|
||||
#define K2T 0x0080
|
||||
#define B2T 0x0214
|
||||
#define M2T 0x02d1
|
||||
#define K3T 0x00c0
|
||||
#define B3T 0x023f
|
||||
#define M3T 0x037b
|
||||
#define K4T 0x0100
|
||||
#define B4T 0x0270
|
||||
#define M4T 0x03fe
|
||||
#define K5T 0x0138
|
||||
#define B5T 0x016f
|
||||
#define M5T 0x01fc
|
||||
#define K6T 0x019a
|
||||
#define B6T 0x00d2
|
||||
#define M6T 0x00fb
|
||||
#define K7T 0x029a
|
||||
#define B7T 0x0018
|
||||
#define M7T 0x0012
|
||||
#define K8T 0x029a
|
||||
#define B8T 0x0000
|
||||
#define M8T 0x0000
|
||||
/** @} */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TSL2563_SUCCESS 0x00
|
||||
#define TSL2563_LIGHT 0x01
|
||||
#define TSL2563_ERROR -1
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TSL2563_VAL_READ 0x01
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TSL2563_SENSOR "TSL2563 Light Sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor tsl2563;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
|
Loading…
Reference in a new issue