From d3980668eedfbb695e0b0fc772677161977cf40c Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Mon, 22 Feb 2016 20:14:06 +0100 Subject: [PATCH 01/14] Adding support for AtMega128RFR2 and AtMega256RFR2 --- cpu/avr/dev/clock-avr.h | 2 +- cpu/avr/dev/rs232.c | 2 +- cpu/avr/dev/rs232.h | 4 + .../radio/rf230bb/atmega256rfr2_registermap.h | 398 ++++++++++++++++++ cpu/avr/radio/rf230bb/hal.h | 12 +- cpu/avr/radio/rf230bb/halbb.c | 33 +- cpu/avr/radio/rf230bb/rf230bb.c | 49 ++- cpu/avr/radio/rf230bb/rf230bb.h | 6 +- cpu/avr/rtimer-arch.c | 2 +- 9 files changed, 478 insertions(+), 30 deletions(-) create mode 100644 cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h diff --git a/cpu/avr/dev/clock-avr.h b/cpu/avr/dev/clock-avr.h index 97a79ee23..662bd21d3 100644 --- a/cpu/avr/dev/clock-avr.h +++ b/cpu/avr/dev/clock-avr.h @@ -73,7 +73,7 @@ TIMSK0 = _BV (OCIE0A); -#elif defined (__AVR_ATmega1284P__) || (__AVR_AT90USB1287__) || (__AVR_ATmega1281__) || defined (__AVR_ATmega128RFA1__) +#elif defined (__AVR_ATmega1284P__) || (__AVR_AT90USB1287__) || (__AVR_ATmega1281__) || defined (__AVR_ATmega128RFA1__) || defined (__AVR_ATmega128RFR2__) || defined (__AVR_ATmega256RFR2__) /* The Raven has a 32768Hz watch crystal that can be used to clock the timer while the 1284p is sleeping. The Jackdaw has pads for a crystal. The crystal diff --git a/cpu/avr/dev/rs232.c b/cpu/avr/dev/rs232.c index 94cf5035f..2df263491 100644 --- a/cpu/avr/dev/rs232.c +++ b/cpu/avr/dev/rs232.c @@ -83,7 +83,7 @@ #define NUMPORTS RS232_CONF_NUMPORTS #endif -#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__) +#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) #ifndef NUMPORTS #define NUMPORTS 2 #elif NUMPORTS > 2 diff --git a/cpu/avr/dev/rs232.h b/cpu/avr/dev/rs232.h index 08a3d4f9f..f7e962204 100644 --- a/cpu/avr/dev/rs232.h +++ b/cpu/avr/dev/rs232.h @@ -49,6 +49,10 @@ #include "dev/rs232_at90usb1287.h" #elif defined (__AVR_ATmega128RFA1__) #include "dev/rs232_atmega128rfa1.h" +#elif defined (__AVR_ATmega128RFR2__) +#include "dev/rs232_atmega128rfa1.h" +#elif defined (__AVR_ATmega256RFR2__) +#include "dev/rs232_atmega128rfa1.h" #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__) #include "dev/rs232_atmega644.h" #elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \ diff --git a/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h b/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h new file mode 100644 index 000000000..bc737de9a --- /dev/null +++ b/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h @@ -0,0 +1,398 @@ +/** + * @file + * @brief This file contains RF230-formatted register definitions for the atmega128rfa1 + */ +/* Copyright (c) 2008, Swedish Institute of Computer Science + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * 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. + * Neither the name of the copyright holders nor the names of + 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 OWNER 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. +*/ + +#ifndef PHY256RFR2_REGISTERMAP_EXTERNAL_H +#define PHY256RFR2_REGISTERMAP_EXTERNAL_H + +/* RF230 register access is through SPI which transfers 8 bits address/8 bits data. + * ATmega128rfa1 registers are defined in I/O space, e.g. in gcc /include/avr/iom128rfa1.h + * A typical definition is #define TRX_STATUS _SFR_MEM8(0x141) + * Registers can be read with a macro, but the args for subregisters don't expand properly so the actual address + * is used with explicit _SFR_MEM8 in the subregister read/write routines. + */ +#define RG_TRX_STATUS TRX_STATUS +#define SR_TRX_STATUS 0x141, 0x1f, 0 +#define SR_TRX_CMD 0x142, 0x1f, 0 +#define STATE_TRANSITION (31) +#define SR_TX_PWR 0x145, 0x0f, 0 +#define RG_VERSION_NUM VERSION_NUM +#define RG_MAN_ID_0 MAN_ID_0 +#define RG_IRQ_MASK IRQ_MASK +#define SR_MAX_FRAME_RETRIES 0x16C, 0xf0, 4 +#define SR_TX_AUTO_CRC_ON 0x144, 0x20, 5 +#define SR_TRAC_STATUS 0x142, 0xe0, 5 +#define SR_CHANNEL 0x148, 0x1f, 0 +#define SR_CCA_MODE 0x148, 0x60, 5 +#define SR_CCA_REQUEST 0x148, 0x80, 7 +#define RG_PAN_ID_0 PAN_ID_0 +#define RG_PAN_ID_1 PAN_ID_1 +#define RG_SHORT_ADDR_0 SHORT_ADDR_0 +#define RG_SHORT_ADDR_1 SHORT_ADDR_1 +#define RG_IEEE_ADDR_0 IEEE_ADDR_0 +#define RG_IEEE_ADDR_1 IEEE_ADDR_1 +#define RG_IEEE_ADDR_2 IEEE_ADDR_2 +#define RG_IEEE_ADDR_3 IEEE_ADDR_3 +#define RG_IEEE_ADDR_4 IEEE_ADDR_4 +#define RG_IEEE_ADDR_5 IEEE_ADDR_5 +#define RG_IEEE_ADDR_6 IEEE_ADDR_6 +#define RG_IEEE_ADDR_7 IEEE_ADDR_7 +//#define SR_ED_LEVEL 0x147, 0xff, 0 +#define RG_PHY_ED_LEVEL PHY_ED_LEVEL +#define RG_RX_SYN RX_SYN +#define SR_RSSI 0x146, 0x1f, 0 +#define SR_RX_SYN 0x155, 0xff, 0 +#define SR_TRX_RPC 0x156, 0xff, 0 +#define SR_XAH_CTRL_1 0x157, 0xf5, 2 +#define SR_PLL_CF_START 0x15a, 0x80, 7 +#define SR_PLL_DCU_START 0x15b, 0x80, 7 +#define SR_MAX_CSMA_RETRIES 0x16c, 0x0e, 1 +#define RG_CSMA_BE CSMA_BE +#define RG_CSMA_SEED_0 CSMA_SEED_0 +#define RG_PHY_RSSI PHY_RSSI +//#define SR_CCA_CS_THRES 0x149, 0xf0, 4 +#define SR_CCA_ED_THRES 0x149, 0x0f, 0 +#define SR_CCA_DONE 0x141, 0x80, 7 +#define SR_CCA_STATUS 0x141, 0x40, 6 +#define SR_AACK_SET_PD 0x16e, 0x20, 5 +#define SR_CSMA_SEED_1 0x16e, 0x10, 4 + +/* RF230 register assignments, for reference */ +#if 1 +//#define HAVE_REGISTER_MAP (1) +/** Offset for register TRX_STATUS */ +//#define RG_TRX_STATUS (0x01) +/** Access parameters for sub-register CCA_DONE in register @ref RG_TRX_STATUS */ +//#define SR_CCA_DONE 0x01, 0x80, 7 +/** Access parameters for sub-register CCA_STATUS in register @ref RG_TRX_STATUS */ +//#define SR_CCA_STATUS 0x01, 0x40, 6 +//#define SR_reserved_01_3 0x01, 0x20, 5 +/** Access parameters for sub-register TRX_STATUS in register @ref RG_TRX_STATUS */ +//#define SR_TRX_STATUS 0x01, 0x1f, 0 +/** Constant P_ON for sub-register @ref SR_TRX_STATUS */ +//#define P_ON (0) +/** Constant BUSY_RX for sub-register @ref SR_TRX_STATUS */ +#define BUSY_RX (1) +/** Constant BUSY_TX for sub-register @ref SR_TRX_STATUS */ +#define BUSY_TX (2) +/** Constant RX_ON for sub-register @ref SR_TRX_STATUS */ +#define RX_ON (6) +/** Constant TRX_OFF for sub-register @ref SR_TRX_STATUS */ +#define TRX_OFF (8) +/** Constant PLL_ON for sub-register @ref SR_TRX_STATUS */ +#define PLL_ON (9) +/** Constant SLEEP for sub-register @ref SR_TRX_STATUS */ +//#define SLEEP (15) +/** Constant BUSY_RX_AACK for sub-register @ref SR_TRX_STATUS */ +#define BUSY_RX_AACK (17) +/** Constant BUSY_TX_ARET for sub-register @ref SR_TRX_STATUS */ +#define BUSY_TX_ARET (18) +/** Constant RX_AACK_ON for sub-register @ref SR_TRX_STATUS */ +#define RX_AACK_ON (22) +/** Constant TX_ARET_ON for sub-register @ref SR_TRX_STATUS */ +#define TX_ARET_ON (25) +/** Constant RX_ON_NOCLK for sub-register @ref SR_TRX_STATUS */ +//#define RX_ON_NOCLK (28) +/** Constant RX_AACK_ON_NOCLK for sub-register @ref SR_TRX_STATUS */ +//#define RX_AACK_ON_NOCLK (29) +/** Constant BUSY_RX_AACK_NOCLK for sub-register @ref SR_TRX_STATUS */ +//#define BUSY_RX_AACK_NOCLK (30) +/** Constant STATE_TRANSITION for sub-register @ref SR_TRX_STATUS */ +//#define STATE_TRANSITION (31) + +/** Offset for register TRX_STATE */ +//#define RG_TRX_STATE (0x02) +/** Access parameters for sub-register TRAC_STATUS in register @ref RG_TRX_STATE */ +//#define SR_TRAC_STATUS 0x02, 0xe0, 5 +/** Access parameters for sub-register TRX_CMD in register @ref RG_TRX_STATE */ +//#define SR_TRX_CMD 0x02, 0x1f, 0 +/** Constant CMD_NOP for sub-register @ref SR_TRX_CMD */ +//#define CMD_NOP (0) +/** Constant CMD_TX_START for sub-register @ref SR_TRX_CMD */ +//#define CMD_TX_START (2) +/** Constant CMD_FORCE_TRX_OFF for sub-register @ref SR_TRX_CMD */ +#define CMD_FORCE_TRX_OFF (3) +///** Constant CMD_RX_ON for sub-register @ref SR_TRX_CMD */ +//#define CMD_RX_ON (6) +///** Constant CMD_TRX_OFF for sub-register @ref SR_TRX_CMD */ +//#define CMD_TRX_OFF (8) +///** Constant CMD_PLL_ON for sub-register @ref SR_TRX_CMD */ +//#define CMD_PLL_ON (9) +///** Constant CMD_RX_AACK_ON for sub-register @ref SR_TRX_CMD */ +//#define CMD_RX_AACK_ON (22) +///** Constant CMD_TX_ARET_ON for sub-register @ref SR_TRX_CMD */ +//#define CMD_TX_ARET_ON (25) +///** Offset for register TRX_CTRL_0 */ +//#define RG_TRX_CTRL_0 (0x03) +///** Offset for register TRX_CTRL_1 */ +//#define RG_TRX_CTRL_1 (0x04) +///** Access parameters for sub-register PAD_IO in register @ref RG_TRX_CTRL_0 */ +//#define SR_PAD_IO 0x03, 0xc0, 6 +///** Access parameters for sub-register PAD_IO_CLKM in register @ref RG_TRX_CTRL_0 */ +//#define SR_PAD_IO_CLKM 0x03, 0x30, 4 +///** Constant CLKM_2mA for sub-register @ref SR_PAD_IO_CLKM */ +//#define CLKM_2mA (0) +///** Constant CLKM_4mA for sub-register @ref SR_PAD_IO_CLKM */ +//#define CLKM_4mA (1) +///** Constant CLKM_6mA for sub-register @ref SR_PAD_IO_CLKM */ +//#define CLKM_6mA (2) +///** Constant CLKM_8mA for sub-register @ref SR_PAD_IO_CLKM */ +//#define CLKM_8mA (3) +///** Access parameters for sub-register CLKM_SHA_SEL in register @ref RG_TRX_CTRL_0 */ +//#define SR_CLKM_SHA_SEL 0x03, 0x08, 3 +///** Access parameters for sub-register CLKM_CTRL in register @ref RG_TRX_CTRL_0 */ +//#define SR_CLKM_CTRL 0x03, 0x07, 0 +///** Constant CLKM_no_clock for sub-register @ref SR_CLKM_CTRL */ +//#define CLKM_no_clock (0) +///** Constant CLKM_1MHz for sub-register @ref SR_CLKM_CTRL */ +//#define CLKM_1MHz (1) +///** Constant CLKM_2MHz for sub-register @ref SR_CLKM_CTRL */ +//#define CLKM_2MHz (2) +///** Constant CLKM_4MHz for sub-register @ref SR_CLKM_CTRL */ +//#define CLKM_4MHz (3) +///** Constant CLKM_8MHz for sub-register @ref SR_CLKM_CTRL */ +//#define CLKM_8MHz (4) +///** Constant CLKM_16MHz for sub-register @ref SR_CLKM_CTRL */ +//#define CLKM_16MHz (5) +///** Offset for register PHY_TX_PWR */ +//#define RG_PHY_TX_PWR (0x05) +///** Access parameters for sub-register TX_AUTO_CRC_ON in register @ref RG_PHY_TX_PWR */ +//#define SR_TX_AUTO_CRC_ON 0x05, 0x80, 7 +//#define SR_reserved_05_2 0x05, 0x70, 4 +///** Access parameters for sub-register TX_PWR in register @ref RG_PHY_TX_PWR */ +//#define SR_TX_PWR 0x05, 0x0f, 0 +///** Offset for register PHY_RSSI */ +//#define RG_PHY_RSSI (0x06) +//#define SR_reserved_06_1 0x06, 0xe0, 5 +///** Access parameters for sub-register RSSI in register @ref RG_PHY_RSSI */ +//#define SR_RSSI 0x06, 0x1f, 0 +///** Offset for register PHY_ED_LEVEL */ +//#define RG_PHY_ED_LEVEL (0x07) +///** Access parameters for sub-register ED_LEVEL in register @ref RG_PHY_ED_LEVEL */ +//#define SR_ED_LEVEL 0x07, 0xff, 0 +///** Offset for register PHY_CC_CCA */ +//#define RG_PHY_CC_CCA (0x08) +///** Access parameters for sub-register CCA_REQUEST in register @ref RG_PHY_CC_CCA */ +//#define SR_CCA_REQUEST 0x08, 0x80, 7 +///** Access parameters for sub-register CCA_MODE in register @ref RG_PHY_CC_CCA */ +//#define SR_CCA_MODE 0x08, 0x60, 5 +///** Access parameters for sub-register CHANNEL in register @ref RG_PHY_CC_CCA */ +//#define SR_CHANNEL 0x08, 0x1f, 0 +///** Offset for register CCA_THRES */ +//#define RG_CCA_THRES (0x09) +///** Access parameters for sub-register CCA_CS_THRES in register @ref RG_CCA_THRES */ +//#define SR_CCA_CS_THRES 0x09, 0xf0, 4 +///** Access parameters for sub-register CCA_ED_THRES in register @ref RG_CCA_THRES */ +//#define SR_CCA_ED_THRES 0x09, 0x0f, 0 +///** Offset for register IRQ_MASK */ +//#define RG_IRQ_MASK (0x0e) +///** Access parameters for sub-register IRQ_MASK in register @ref RG_IRQ_MASK */ +//#define SR_IRQ_MASK 0x0e, 0xff, 0 +///** Offset for register IRQ_STATUS */ +//#define RG_IRQ_STATUS (0x0f) +///** Access parameters for sub-register IRQ_7_BAT_LOW in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_7_BAT_LOW 0x0f, 0x80, 7 +///** Access parameters for sub-register IRQ_6_TRX_UR in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_6_TRX_UR 0x0f, 0x40, 6 +///** Access parameters for sub-register IRQ_5 in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_5 0x0f, 0x20, 5 +///** Access parameters for sub-register IRQ_4 in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_4 0x0f, 0x10, 4 +///** Access parameters for sub-register IRQ_3_TRX_END in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_3_TRX_END 0x0f, 0x08, 3 +///** Access parameters for sub-register IRQ_2_RX_START in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_2_RX_START 0x0f, 0x04, 2 +///** Access parameters for sub-register IRQ_1_PLL_UNLOCK in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_1_PLL_UNLOCK 0x0f, 0x02, 1 +///** Access parameters for sub-register IRQ_0_PLL_LOCK in register @ref RG_IRQ_STATUS */ +//#define SR_IRQ_0_PLL_LOCK 0x0f, 0x01, 0 +///** Offset for register VREG_CTRL */ +//#define RG_VREG_CTRL (0x10) +///** Access parameters for sub-register AVREG_EXT in register @ref RG_VREG_CTRL */ +//#define SR_AVREG_EXT 0x10, 0x80, 7 +///** Access parameters for sub-register AVDD_OK in register @ref RG_VREG_CTRL */ +//#define SR_AVDD_OK 0x10, 0x40, 6 +///** Access parameters for sub-register AVREG_TRIM in register @ref RG_VREG_CTRL */ +//#define SR_AVREG_TRIM 0x10, 0x30, 4 +///** Constant AVREG_1_80V for sub-register @ref SR_AVREG_TRIM */ +//#define AVREG_1_80V (0) +///** Constant AVREG_1_75V for sub-register @ref SR_AVREG_TRIM */ +//#define AVREG_1_75V (1) +///** Constant AVREG_1_84V for sub-register @ref SR_AVREG_TRIM */ +//#define AVREG_1_84V (2) +///** Constant AVREG_1_88V for sub-register @ref SR_AVREG_TRIM */ +//#define AVREG_1_88V (3) +///** Access parameters for sub-register DVREG_EXT in register @ref RG_VREG_CTRL */ +//#define SR_DVREG_EXT 0x10, 0x08, 3 +///** Access parameters for sub-register DVDD_OK in register @ref RG_VREG_CTRL */ +//#define SR_DVDD_OK 0x10, 0x04, 2 +///** Access parameters for sub-register DVREG_TRIM in register @ref RG_VREG_CTRL */ +//#define SR_DVREG_TRIM 0x10, 0x03, 0 +///** Constant DVREG_1_80V for sub-register @ref SR_DVREG_TRIM */ +//#define DVREG_1_80V (0) +///** Constant DVREG_1_75V for sub-register @ref SR_DVREG_TRIM */ +//#define DVREG_1_75V (1) +///** Constant DVREG_1_84V for sub-register @ref SR_DVREG_TRIM */ +//#define DVREG_1_84V (2) +///** Constant DVREG_1_88V for sub-register @ref SR_DVREG_TRIM */ +//#define DVREG_1_88V (3) +///** Offset for register BATMON */ +//#define RG_BATMON (0x11) +//#define SR_reserved_11_1 0x11, 0xc0, 6 +///** Access parameters for sub-register BATMON_OK in register @ref RG_BATMON */ +//#define SR_BATMON_OK 0x11, 0x20, 5 +///** Access parameters for sub-register BATMON_HR in register @ref RG_BATMON */ +//#define SR_BATMON_HR 0x11, 0x10, 4 +///** Access parameters for sub-register BATMON_VTH in register @ref RG_BATMON */ +//#define SR_BATMON_VTH 0x11, 0x0f, 0 +///** Offset for register XOSC_CTRL */ +//#define RG_XOSC_CTRL (0x12) +///** Offset for register RX_SYN */ +//#define RG_RX_SYN 0x15 +///** Offset for register XAH_CTRL_1 */ +//#define RG_XAH_CTRL_1 0x17 +///** Access parameters for sub-register XTAL_MODE in register @ref RG_XOSC_CTRL */ +//#define SR_XTAL_MODE 0x12, 0xf0, 4 +///** Access parameters for sub-register XTAL_TRIM in register @ref RG_XOSC_CTRL */ +//#define SR_XTAL_TRIM 0x12, 0x0f, 0 +///** Offset for register FTN_CTRL */ +//#define RG_FTN_CTRL (0x18) +///** Access parameters for sub-register FTN_START in register @ref RG_FTN_CTRL */ +//#define SR_FTN_START 0x18, 0x80, 7 +//#define SR_reserved_18_2 0x18, 0x40, 6 +///** Access parameters for sub-register FTNV in register @ref RG_FTN_CTRL */ +//#define SR_FTNV 0x18, 0x3f, 0 +///** Offset for register PLL_CF */ +//#define RG_PLL_CF (0x1a) +///** Access parameters for sub-register PLL_CF_START in register @ref RG_PLL_CF */ +//#define SR_PLL_CF_START 0x1a, 0x80, 7 +//#define SR_reserved_1a_2 0x1a, 0x70, 4 +///** Access parameters for sub-register PLL_CF in register @ref RG_PLL_CF */ +//#define SR_PLL_CF 0x1a, 0x0f, 0 +///** Offset for register PLL_DCU */ +//#define RG_PLL_DCU (0x1b) +///** Access parameters for sub-register PLL_DCU_START in register @ref RG_PLL_DCU */ +//#define SR_PLL_DCU_START 0x1b, 0x80, 7 +//#define SR_reserved_1b_2 0x1b, 0x40, 6 +///** Access parameters for sub-register PLL_DCUW in register @ref RG_PLL_DCU */ +//#define SR_PLL_DCUW 0x1b, 0x3f, 0 +///** Offset for register PART_NUM */ +//#define RG_PART_NUM (0x1c) +///** Access parameters for sub-register PART_NUM in register @ref RG_PART_NUM */ +//#define SR_PART_NUM 0x1c, 0xff, 0 +///** Constant RF230 for sub-register @ref SR_PART_NUM */ +//#define RF230 (2) +///** Offset for register VERSION_NUM */ +//#define RG_VERSION_NUM (0x1d) +///** Access parameters for sub-register VERSION_NUM in register @ref RG_VERSION_NUM */ +//#define SR_VERSION_NUM 0x1d, 0xff, 0 +///** Offset for register MAN_ID_0 */ +//#define RG_MAN_ID_0 (0x1e) +///** Access parameters for sub-register MAN_ID_0 in register @ref RG_MAN_ID_0 */ +//#define SR_MAN_ID_0 0x1e, 0xff, 0 +///** Offset for register MAN_ID_1 */ +//#define RG_MAN_ID_1 (0x1f) +///** Access parameters for sub-register MAN_ID_1 in register @ref RG_MAN_ID_1 */ +//#define SR_MAN_ID_1 0x1f, 0xff, 0 +///** Offset for register SHORT_ADDR_0 */ +//#define RG_SHORT_ADDR_0 (0x20) +///** Access parameters for sub-register SHORT_ADDR_0 in register @ref RG_SHORT_ADDR_0 */ +//#define SR_SHORT_ADDR_0 0x20, 0xff, 0 +///** Offset for register SHORT_ADDR_1 */ +//#define RG_SHORT_ADDR_1 (0x21) +///** Access parameters for sub-register SHORT_ADDR_1 in register @ref RG_SHORT_ADDR_1 */ +//#define SR_SHORT_ADDR_1 0x21, 0xff, 0 +///** Offset for register PAN_ID_0 */ +//#define RG_PAN_ID_0 (0x22) +///** Access parameters for sub-register PAN_ID_0 in register @ref RG_PAN_ID_0 */ +//#define SR_PAN_ID_0 0x22, 0xff, 0 +///** Offset for register PAN_ID_1 */ +//#define RG_PAN_ID_1 (0x23) +///** Access parameters for sub-register PAN_ID_1 in register @ref RG_PAN_ID_1 */ +//#define SR_PAN_ID_1 0x23, 0xff, 0 +///** Offset for register IEEE_ADDR_0 */ +//#define RG_IEEE_ADDR_0 (0x24) +///** Access parameters for sub-register IEEE_ADDR_0 in register @ref RG_IEEE_ADDR_0 */ +//#define SR_IEEE_ADDR_0 0x24, 0xff, 0 +///** Offset for register IEEE_ADDR_1 */ +//#define RG_IEEE_ADDR_1 (0x25) +///** Access parameters for sub-register IEEE_ADDR_1 in register @ref RG_IEEE_ADDR_1 */ +//#define SR_IEEE_ADDR_1 0x25, 0xff, 0 +///** Offset for register IEEE_ADDR_2 */ +//#define RG_IEEE_ADDR_2 (0x26) +///** Access parameters for sub-register IEEE_ADDR_2 in register @ref RG_IEEE_ADDR_2 */ +//#define SR_IEEE_ADDR_2 0x26, 0xff, 0 +///** Offset for register IEEE_ADDR_3 */ +//#define RG_IEEE_ADDR_3 (0x27) +///** Access parameters for sub-register IEEE_ADDR_3 in register @ref RG_IEEE_ADDR_3 */ +//#define SR_IEEE_ADDR_3 0x27, 0xff, 0 +///** Offset for register IEEE_ADDR_4 */ +//#define RG_IEEE_ADDR_4 (0x28) +///** Access parameters for sub-register IEEE_ADDR_4 in register @ref RG_IEEE_ADDR_4 */ +//#define SR_IEEE_ADDR_4 0x28, 0xff, 0 +///** Offset for register IEEE_ADDR_5 */ +//#define RG_IEEE_ADDR_5 (0x29) +///** Access parameters for sub-register IEEE_ADDR_5 in register @ref RG_IEEE_ADDR_5 */ +//#define SR_IEEE_ADDR_5 0x29, 0xff, 0 +///** Offset for register IEEE_ADDR_6 */ +//#define RG_IEEE_ADDR_6 (0x2a) +///** Access parameters for sub-register IEEE_ADDR_6 in register @ref RG_IEEE_ADDR_6 */ +//#define SR_IEEE_ADDR_6 0x2a, 0xff, 0 +///** Offset for register IEEE_ADDR_7 */ +//#define RG_IEEE_ADDR_7 (0x2b) +///** Access parameters for sub-register IEEE_ADDR_7 in register @ref RG_IEEE_ADDR_7 */ +//#define SR_IEEE_ADDR_7 0x2b, 0xff, 0 +///** Offset for register XAH_CTRL */ +//#define RG_XAH_CTRL_0 (0x2c) +///** Access parameters for sub-register MAX_FRAME_RETRIES in register @ref RG_XAH_CTRL_0 */ +//#define SR_MAX_FRAME_RETRIES 0x2c, 0xf0, 4 +///** Access parameters for sub-register MAX_CSMA_RETRIES in register @ref RG_XAH_CTRL_0 */ +//#define SR_MAX_CSMA_RETRIES 0x2c, 0x0e, 1 +//#define SR_reserved_2c_3 0x2c, 0x01, 0 +///** Offset for register CSMA_SEED_0 */ +//#define RG_CSMA_SEED_0 (0x2d) +///** Access parameters for sub-register CSMA_SEED_0 in register @ref RG_CSMA_SEED_0 */ +//#define SR_CSMA_SEED_0 0x2d, 0xff, 0 +///** Offset for register CSMA_SEED_1 */ +//#define RG_CSMA_SEED_1 (0x2e) +///** Offset for register CSMA_BE */ +//#define RG_CSMA_BE 0x2f +///** Access parameters for sub-register MIN_BE in register @ref RG_CSMA_SEED_1 */ +//#define SR_MIN_BE 0x2e, 0xc0, 6 +//#define SR_reserved_2e_2 0x2e, 0x30, 4 +///** Access parameters for sub-register I_AM_COORD in register @ref RG_CSMA_SEED_1 */ +//#define SR_I_AM_COORD 0x2e, 0x08, 3 +///** Access parameters for sub-register CSMA_SEED_1 in register @ref RG_CSMA_SEED_1 */ +//#define SR_CSMA_SEED_1 0x2e, 0x07, 0 +#endif +#endif /* PHY256RFR2y_REGISTERMAP_EXTERNAL_H */ diff --git a/cpu/avr/radio/rf230bb/hal.h b/cpu/avr/radio/rf230bb/hal.h index 737680d68..b28151a0c 100644 --- a/cpu/avr/radio/rf230bb/hal.h +++ b/cpu/avr/radio/rf230bb/hal.h @@ -78,6 +78,7 @@ #define ZIGBIT 4 #define IRIS 5 #define ATMEGA128RFA1 6 +#define ATMEGA256RFR2 7 #if PLATFORM_TYPE == RCB_B /* 1281 rcb */ @@ -145,6 +146,11 @@ # define SLPTRPORT TRXPR # define SLPTRPIN 1 +#elif PLATFORM_TYPE == ATMEGA256RFR2 +/* ATmega1281 with internal AT86RF231 radio */ +# define SLPTRPORT TRXPR +# define SLPTRPIN 1 + #elif CONTIKI_TARGET_MULLE /* mulle 5.2 (TODO: move to platform specific) */ # define SSPORT 3 @@ -233,7 +239,7 @@ * that the source code can directly use. * \{ */ -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) #define hal_set_rst_low( ) ( TRXPR &= ~( 1 << TRXRST ) ) /**< This macro pulls the RST pin low. */ #define hal_set_rst_high( ) ( TRXPR |= ( 1 << TRXRST ) ) /**< This macro pulls the RST pin high. */ @@ -274,7 +280,7 @@ #define HAL_DD_SCK SCKPIN /**< Data Direction bit for SCK. */ #define HAL_DD_MOSI MOSIPIN /**< Data Direction bit for MOSI. */ #define HAL_DD_MISO MISOPIN /**< Data Direction bit for MISO. */ -#endif /* defined(__AVR_ATmega128RFA1__) */ +#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__) */ /** \} */ @@ -367,7 +373,7 @@ typedef struct{ void hal_init( void ); /* Hack for atmega128rfa1 with integrated radio. Access registers directly, not through SPI */ -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) //#define hal_register_read(address) _SFR_MEM8((uint16_t)address) #define hal_register_read(address) address uint8_t hal_subregister_read( uint16_t address, uint8_t mask, uint8_t position ); diff --git a/cpu/avr/radio/rf230bb/halbb.c b/cpu/avr/radio/rf230bb/halbb.c index 14ff57256..243e11c03 100644 --- a/cpu/avr/radio/rf230bb/halbb.c +++ b/cpu/avr/radio/rf230bb/halbb.c @@ -74,8 +74,9 @@ extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE]; #include "hal.h" #if defined(__AVR_ATmega128RFA1__) -#include #include "atmega128rfa1_registermap.h" +#elif defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) +#include "atmega256rfr2_registermap.h" #else #include "at86rf230_registermap.h" #endif @@ -88,7 +89,7 @@ volatile extern signed char rf230_last_rssi; /*============================ IMPLEMENTATION ================================*/ -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) /* AVR1281 with internal RF231 radio */ #include @@ -158,8 +159,7 @@ inline uint8_t spiWrite(uint8_t byte) /** \brief This function initializes the Hardware Abstraction Layer. */ -#if defined(__AVR_ATmega128RFA1__) - +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) void hal_init(void) { @@ -241,8 +241,7 @@ hal_init(void) } #endif /* !__AVR__ */ - -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) /* Hack for internal radio registers. hal_register_read and hal_register_write are handled through defines, but the preprocesser can't parse a macro containing another #define with multiple arguments, e.g. using @@ -279,7 +278,7 @@ hal_subregister_write(uint16_t address, uint8_t mask, uint8_t position, HAL_LEAVE_CRITICAL_REGION(); } -#else /* defined(__AVR_ATmega128RFA1__) */ +#else /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ /*----------------------------------------------------------------------------*/ /** \brief This function reads data from one of the radio transceiver's registers. * @@ -383,7 +382,7 @@ hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position, /* Write the modified register value. */ hal_register_write(address, value); } -#endif /* defined(__AVR_ATmega128RFA1__) */ +#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ /*----------------------------------------------------------------------------*/ /** \brief Transfer a frame from the radio transceiver to a RAM buffer * @@ -399,7 +398,7 @@ hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position, void hal_frame_read(hal_rx_frame_t *rx_frame) { -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) uint8_t frame_length,*rx_data,*rx_buffer; @@ -432,7 +431,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame) */ rx_frame->crc = true; -#else /* defined(__AVR_ATmega128RFA1__) */ +#else /* */ uint8_t frame_length, *rx_data; @@ -487,7 +486,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame) HAL_SPI_TRANSFER_CLOSE(); -#endif /* defined(__AVR_ATmega128RFA1__) */ +#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ } /*----------------------------------------------------------------------------*/ @@ -500,7 +499,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame) void hal_frame_write(uint8_t *write_buffer, uint8_t length) { -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) uint8_t *tx_buffer; tx_buffer=(uint8_t *)0x180; //start of fifo in i/o space /* Write frame length, including the two byte checksum */ @@ -518,7 +517,7 @@ hal_frame_write(uint8_t *write_buffer, uint8_t length) #endif do _SFR_MEM8(tx_buffer++)= *write_buffer++; while (--length); -#else /* defined(__AVR_ATmega128RFA1__) */ +#else /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ /* Optionally truncate length to maximum frame length. * Not doing this is a fast way to know when the application needs fixing! */ @@ -540,7 +539,7 @@ hal_frame_write(uint8_t *write_buffer, uint8_t length) do HAL_SPI_TRANSFER(*write_buffer++); while (--length); HAL_SPI_TRANSFER_CLOSE(); -#endif /* defined(__AVR_ATmega128RFA1__) */ +#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ } /*----------------------------------------------------------------------------*/ @@ -632,7 +631,7 @@ volatile char rf230interruptflag; #define INTERRUPTDEBUG(arg) #endif -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) /* The atmega128rfa1 has individual interrupts for the integrated radio' * Whichever are enabled by the RF230 driver must be present even if not used! */ @@ -713,7 +712,7 @@ ISR(TRX24_CCA_ED_DONE_vect) rf230_ccawait=0; } -#else /* defined(__AVR_ATmega128RFA1__) */ +#else /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ /* Separate RF230 has a single radio interrupt and the source must be read from the IRQ_STATUS register */ HAL_RF230_ISR() { @@ -803,7 +802,7 @@ HAL_RF230_ISR() ; } } -#endif /* defined(__AVR_ATmega128RFA1__) */ +#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) */ # endif /* defined(DOXYGEN) */ /** @} */ diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c index d00a24d72..cbe8160ef 100644 --- a/cpu/avr/radio/rf230bb/rf230bb.c +++ b/cpu/avr/radio/rf230bb/rf230bb.c @@ -212,7 +212,7 @@ static unsigned long total_time_for_transmission, total_transmission_len; static int num_transmissions; #endif -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) volatile uint8_t rf230_wakewait, rf230_txendwait, rf230_ccawait; #endif @@ -433,7 +433,21 @@ rf230_waitidle(void) } } -/*----------------------------------------------------------------------------*/ +/* Set reduced power consumption for AtMegaXXXRFR2 MCU's. See AT02594 */ + +static uint8_t rpc = 0xFF; /* Default max power save */ +void +rf230_set_rpc(uint8_t data) +{ + rpc = data; +} + +uint8_t +rf230_get_rpc(void) +{ + return rpc; +} + /** \brief This function will change the current state of the radio * transceiver's internal state machine. * @@ -507,6 +521,10 @@ radio_set_trx_state(uint8_t new_state) /* When the PLL is active most states can be reached in 1us. However, from */ /* TRX_OFF the PLL needs time to activate. */ if (current_state == TRX_OFF){ + +#if defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) + hal_subregister_write(SR_TRX_RPC, rpc); /* Enable RPC features */ +#endif delay_us(TIME_TRX_OFF_TO_PLL_ACTIVE); } else { delay_us(TIME_STATE_TRANSITION_PLL_ACTIVE); @@ -535,7 +553,7 @@ rf230_set_promiscuous_mode(bool isPromiscuous) { #if RF230_CONF_AUTOACK is_promiscuous = isPromiscuous; /* TODO: Figure out when to pass promisc state to 802.15.4 */ -// radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON); + radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON); #endif } @@ -585,7 +603,7 @@ radio_on(void) #if RF230BB_CONF_LEDONPORTE1 PORTE|=(1<1 { uint8_t i; @@ -1658,7 +1695,7 @@ rf230_cca(void) /* Start the CCA, wait till done, return result */ /* Note reading the TRX_STATUS register clears both CCA_STATUS and CCA_DONE bits */ -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) #if 1 //interrupt method /* Disable rx transitions to busy (RX_PDT_BIT) */ /* Note: for speed this resets rx threshold to the compiled default */ diff --git a/cpu/avr/radio/rf230bb/rf230bb.h b/cpu/avr/radio/rf230bb/rf230bb.h index 30de9a1e5..c441e09ab 100644 --- a/cpu/avr/radio/rf230bb/rf230bb.h +++ b/cpu/avr/radio/rf230bb/rf230bb.h @@ -57,6 +57,8 @@ #include "hal.h" #if defined(__AVR_ATmega128RFA1__) #include "atmega128rfa1_registermap.h" +#elif defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) +#include "atmega256rfr2_registermap.h" #else #include "at86rf230_registermap.h" #endif @@ -68,7 +70,7 @@ #define RF230_REVB ( 2 ) #define SUPPORTED_MANUFACTURER_ID ( 31 ) -#if defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) #define RF230_SUPPORTED_INTERRUPT_MASK ( 0xFF ) #else /* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */ @@ -215,6 +217,8 @@ uint8_t rf230_get_channel(void); void rf230_set_pan_addr(unsigned pan,unsigned addr,const uint8_t ieee_addr[8]); void rf230_set_txpower(uint8_t power); uint8_t rf230_get_txpower(void); +void rf230_set_rpc(uint8_t rpc); +uint8_t rf230_get_rpc(void); void rf230_set_promiscuous_mode(bool isPromiscuous); bool rf230_is_ready_to_send(); diff --git a/cpu/avr/rtimer-arch.c b/cpu/avr/rtimer-arch.c index d1d97af7e..3ef22377b 100644 --- a/cpu/avr/rtimer-arch.c +++ b/cpu/avr/rtimer-arch.c @@ -64,7 +64,7 @@ #define OCF3C OCF3B #endif -#if defined(__AVR_ATmega1281__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega128RFA1__) +#if defined(__AVR_ATmega1281__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__) #define ETIMSK TIMSK3 #define ETIFR TIFR3 #define TICIE3 ICIE3 From ce8e87d60e32ea61f7a5b2de13d84a3d0b5136c7 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Mon, 22 Feb 2016 20:46:07 +0100 Subject: [PATCH 02/14] Adding the avr-rss2 platform based on AtMega256RFR2 --- platform/avr-rss2/Makefile.avr-rss2 | 61 ++ platform/avr-rss2/README.md | 173 +++++ platform/avr-rss2/apps/sniffer/Makefile | 11 + platform/avr-rss2/apps/sniffer/README.md | 25 + platform/avr-rss2/apps/sniffer/host/Makefile | 17 + platform/avr-rss2/apps/sniffer/host/README.md | 38 ++ .../avr-rss2/apps/sniffer/host/wsbridge.c | 459 +++++++++++++ platform/avr-rss2/apps/sniffer/project-conf.h | 51 ++ .../avr-rss2/apps/sniffer/rf230-promisc.pat | 39 ++ .../apps/sniffer/sniffer-example-coap.pcapng | 0 platform/avr-rss2/apps/sniffer/sniffer.c | 67 ++ platform/avr-rss2/apps/sniffer/stub-rdc.c | 100 +++ platform/avr-rss2/contiki-conf.h | 350 ++++++++++ platform/avr-rss2/contiki-main.c | 635 ++++++++++++++++++ platform/avr-rss2/dev/adc.c | 76 +++ platform/avr-rss2/dev/adc.h | 16 + platform/avr-rss2/dev/battery-sensor.c | 87 +++ platform/avr-rss2/dev/button-sensor.c | 41 ++ platform/avr-rss2/dev/co2_sa_kxx-sensor.c | 131 ++++ platform/avr-rss2/dev/co2_sa_kxx-sensor.h | 51 ++ platform/avr-rss2/dev/ds18b20.c | 247 +++++++ platform/avr-rss2/dev/enc28j60_avr.c | 83 +++ platform/avr-rss2/dev/enc28j60_avr.h | 53 ++ platform/avr-rss2/dev/i2c.c | 228 +++++++ platform/avr-rss2/dev/i2c.h | 65 ++ platform/avr-rss2/dev/leds.c | 45 ++ platform/avr-rss2/dev/leds.h | 17 + platform/avr-rss2/dev/light-sensor.c | 64 ++ platform/avr-rss2/dev/light-sensor.h | 45 ++ platform/avr-rss2/dev/pulse-sensor.c | 120 ++++ platform/avr-rss2/dev/pulse-sensor.h | 43 ++ platform/avr-rss2/dev/temp-sensor.c | 292 ++++++++ platform/avr-rss2/dev/temp-sensor.h | 71 ++ platform/avr-rss2/dev/temp_mcu-sensor.c | 90 +++ platform/avr-rss2/dev/temp_mcu-sensor.h | 47 ++ .../AtMega256RFR2-summary-power.dat | 25 + .../examples/avr_radio_power/Makefile | 9 + .../examples/avr_radio_power/README.md | 79 +++ .../avr_radio_power/avr_radio_power.c | 164 +++++ .../examples/avr_radio_power/project-conf.h | 51 ++ .../avr-rss2/examples/hello-sensors/Makefile | 19 + .../avr-rss2/examples/hello-sensors/README.md | 11 + .../examples/hello-sensors/hello-sensors.c | 119 ++++ .../examples/hello-sensors/project-conf.h | 51 ++ .../examples/ipv6/dc-rpl-coap/Makefile | 49 ++ .../examples/ipv6/dc-rpl-coap/README.md | 67 ++ .../ipv6/dc-rpl-coap/coap-client.avr-rss2 | 0 .../examples/ipv6/dc-rpl-coap/coap-client.c | 413 ++++++++++++ .../ipv6/dc-rpl-coap/coap-server.avr-rss2 | 0 .../examples/ipv6/dc-rpl-coap/coap-server.c | 269 ++++++++ .../examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc | 168 +++++ .../ipv6/dc-rpl-coap/dev/dc-hw-sensor.c | 93 +++ .../ipv6/dc-rpl-coap/dev/dc-hw-sensor.h | 46 ++ .../ipv6/dc-rpl-coap/dev/dc-status-sensor.c | 84 +++ .../ipv6/dc-rpl-coap/dev/dc-status-sensor.h | 46 ++ .../ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c | 97 +++ .../ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h | 46 ++ .../examples/ipv6/dc-rpl-coap/er-dc-test.h | 62 ++ .../examples/ipv6/dc-rpl-coap/project-conf.h | 61 ++ .../ipv6/dc-rpl-coap/resources/res-dc-co2.c | 83 +++ .../ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c | 120 ++++ .../dc-rpl-coap/resources/res-dc-status-obs.c | 113 ++++ .../ipv6/dc-rpl-coap/resources/res-dc-vdc.c | 129 ++++ .../examples/ipv6/rpl-border-router/Makefile | 55 ++ .../ipv6/rpl-border-router/README.ETHERNET.md | 66 ++ .../examples/ipv6/rpl-border-router/README.md | 17 + .../ipv6/rpl-border-router/border-router.c | 388 +++++++++++ .../rpl-border-router/enc28j60-ip64-driver.c | 104 +++ .../rpl-border-router/enc28j60-ip64-driver.h | 38 ++ .../ipv6/rpl-border-router/eth-bridge.c | 33 + .../ipv6/rpl-border-router/httpd-simple.c | 261 +++++++ .../ipv6/rpl-border-router/httpd-simple.h | 74 ++ .../ipv6/rpl-border-router/project-conf.h | 57 ++ .../examples/ipv6/rpl-udp-report/Makefile | 21 + .../examples/ipv6/rpl-udp-report/README.md | 17 + .../ipv6/rpl-udp-report/project-conf.h | 51 ++ .../ipv6/rpl-udp-report/report.avr-rss2 | 0 .../examples/ipv6/rpl-udp-report/report.c | 240 +++++++ .../ipv6/rpl-udp-report/rss2-rpl-udp.csc | 167 +++++ .../ipv6/rpl-udp-report/sink.avr-rss2 | 0 .../examples/ipv6/rpl-udp-report/sink.c | 184 +++++ .../examples/ipv6/sensd_client/Makefile | 12 + .../examples/ipv6/sensd_client/README.md | 222 ++++++ .../examples/ipv6/sensd_client/project-conf.h | 51 ++ .../examples/ipv6/sensd_client/sensd_client.c | 188 ++++++ .../examples/ipv6/sensd_client/server.c | 128 ++++ platform/avr-rss2/ip64-conf.h | 42 ++ platform/avr-rss2/params.c | 284 ++++++++ platform/avr-rss2/params.h | 108 +++ platform/avr-rss2/rss2.h | 36 + platform/avr-rss2/slip_uart0.c | 93 +++ 91 files changed, 9349 insertions(+) create mode 100644 platform/avr-rss2/Makefile.avr-rss2 create mode 100644 platform/avr-rss2/README.md create mode 100644 platform/avr-rss2/apps/sniffer/Makefile create mode 100644 platform/avr-rss2/apps/sniffer/README.md create mode 100644 platform/avr-rss2/apps/sniffer/host/Makefile create mode 100644 platform/avr-rss2/apps/sniffer/host/README.md create mode 100644 platform/avr-rss2/apps/sniffer/host/wsbridge.c create mode 100644 platform/avr-rss2/apps/sniffer/project-conf.h create mode 100644 platform/avr-rss2/apps/sniffer/rf230-promisc.pat create mode 100644 platform/avr-rss2/apps/sniffer/sniffer-example-coap.pcapng create mode 100644 platform/avr-rss2/apps/sniffer/sniffer.c create mode 100644 platform/avr-rss2/apps/sniffer/stub-rdc.c create mode 100644 platform/avr-rss2/contiki-conf.h create mode 100644 platform/avr-rss2/contiki-main.c create mode 100644 platform/avr-rss2/dev/adc.c create mode 100644 platform/avr-rss2/dev/adc.h create mode 100644 platform/avr-rss2/dev/battery-sensor.c create mode 100644 platform/avr-rss2/dev/button-sensor.c create mode 100644 platform/avr-rss2/dev/co2_sa_kxx-sensor.c create mode 100644 platform/avr-rss2/dev/co2_sa_kxx-sensor.h create mode 100644 platform/avr-rss2/dev/ds18b20.c create mode 100644 platform/avr-rss2/dev/enc28j60_avr.c create mode 100644 platform/avr-rss2/dev/enc28j60_avr.h create mode 100644 platform/avr-rss2/dev/i2c.c create mode 100644 platform/avr-rss2/dev/i2c.h create mode 100644 platform/avr-rss2/dev/leds.c create mode 100644 platform/avr-rss2/dev/leds.h create mode 100644 platform/avr-rss2/dev/light-sensor.c create mode 100644 platform/avr-rss2/dev/light-sensor.h create mode 100644 platform/avr-rss2/dev/pulse-sensor.c create mode 100644 platform/avr-rss2/dev/pulse-sensor.h create mode 100644 platform/avr-rss2/dev/temp-sensor.c create mode 100644 platform/avr-rss2/dev/temp-sensor.h create mode 100644 platform/avr-rss2/dev/temp_mcu-sensor.c create mode 100644 platform/avr-rss2/dev/temp_mcu-sensor.h create mode 100644 platform/avr-rss2/examples/avr_radio_power/AtMega256RFR2-summary-power.dat create mode 100644 platform/avr-rss2/examples/avr_radio_power/Makefile create mode 100644 platform/avr-rss2/examples/avr_radio_power/README.md create mode 100644 platform/avr-rss2/examples/avr_radio_power/avr_radio_power.c create mode 100644 platform/avr-rss2/examples/avr_radio_power/project-conf.h create mode 100644 platform/avr-rss2/examples/hello-sensors/Makefile create mode 100644 platform/avr-rss2/examples/hello-sensors/README.md create mode 100644 platform/avr-rss2/examples/hello-sensors/hello-sensors.c create mode 100644 platform/avr-rss2/examples/hello-sensors/project-conf.h create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/Makefile create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/README.md create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.h create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/er-dc-test.h create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/project-conf.h create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-co2.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c create mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-vdc.c create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/Makefile create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/README.ETHERNET.md create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/README.md create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/border-router.c create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.c create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.h create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/eth-bridge.c create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.c create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.h create mode 100644 platform/avr-rss2/examples/ipv6/rpl-border-router/project-conf.h create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/Makefile create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/README.md create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/project-conf.h create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/rss2-rpl-udp.csc create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 create mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c create mode 100644 platform/avr-rss2/examples/ipv6/sensd_client/Makefile create mode 100644 platform/avr-rss2/examples/ipv6/sensd_client/README.md create mode 100644 platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h create mode 100644 platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c create mode 100644 platform/avr-rss2/examples/ipv6/sensd_client/server.c create mode 100644 platform/avr-rss2/ip64-conf.h create mode 100644 platform/avr-rss2/params.c create mode 100644 platform/avr-rss2/params.h create mode 100644 platform/avr-rss2/rss2.h create mode 100644 platform/avr-rss2/slip_uart0.c diff --git a/platform/avr-rss2/Makefile.avr-rss2 b/platform/avr-rss2/Makefile.avr-rss2 new file mode 100644 index 000000000..2655b8b4a --- /dev/null +++ b/platform/avr-rss2/Makefile.avr-rss2 @@ -0,0 +1,61 @@ +CONTIKI_TARGET_DIRS = . apps net loader dev + +CONTIKI_CORE=contiki-main +CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o +CONTIKI_TARGET_SOURCEFILES += contiki-main.c params.c battery-sensor.c i2c.c + +CONTIKI_TARGET_SOURCEFILES += sensors.c button-sensor.c slip_uart0.c slip.c leds.c temp_mcu-sensor.c light-sensor.c adc.c cfs-eeprom.c eeprom.c pulse-sensor.c + +CONTIKI_TARGET_SOURCEFILES += temp-sensor.c + +CONTIKI_TARGET_SOURCEFILES += enc28j60_avr.c +CONTIKI_TARGET_SOURCEFILES += co2_sa_kxx-sensor.c + +CONTIKIAVR=$(CONTIKI)/cpu/avr +CONTIKIBOARD=. + + +ifdef $(MCU) +MCU=$(MCU) +else +MCU=atmega256rfr2 +endif + +ifeq ($(MCU),atmega128rfa1) +CONTIKI_PLAT_DEFS = -DF_CPU=8000000UL -DAUTO_CRC_PADDING=2 +BOOTLOADER_START = 0x1E000 +endif + +ifeq ($(MCU),atmega128rfr2) +CONTIKI_PLAT_DEFS = -DF_CPU=8000000UL -DAUTO_CRC_PADDING=2 +BOOTLOADER_START = 0x1E000 +endif + +ifeq ($(MCU),atmega256rfr2) +CONTIKI_PLAT_DEFS = -DF_CPU=16000000UL -DAUTO_CRC_PADDING=2 +BOOTLOADER_START = 0x3E000 +endif + +AVRDUDE_PROGRAMMER=jtag2 + +# For usb devices, you may either use PORT=usb, or (e.g. if you have more than one +# programmer connected) you can use the following trick to find out the serial number: +# +# The example is for an JTAGICE mkII used to program an ATmega128: +# avrdude -v -P usb:xxxx -c jtag2 -p atmega128 +AVRDUDE_PORT=usb:00B000000D79 + +# Additional avrdude options +# Verify off +AVRDUDE_OPTIONS=-V +AVRDUDE_MCU=m256rfr2 + +include $(CONTIKIAVR)/Makefile.avr +include $(CONTIKIAVR)/radio/Makefile.radio + +#MODULES += core/net/mac core/net core/net/mac/sicslowmac core/net/mac/contikimac core/net/llsec core/net/rime + +MODULES += core/net/mac core/net core/net/mac/sicslowmac core/net/mac/contikimac core/net/llsec + + + diff --git a/platform/avr-rss2/README.md b/platform/avr-rss2/README.md new file mode 100644 index 000000000..260a7d4bb --- /dev/null +++ b/platform/avr-rss2/README.md @@ -0,0 +1,173 @@ +Getting Started with Contiki using avr-rss2 +=========================================== +This guide's aim is to help you start using Contiki for RSS2 boards +The platform supports different AtMega-RF boards: + +* Based on MCU AtMega128RFR2 +* Based on MCU AtMega256RFR2 +* Based on MCU AtMega128RFA1 + +Boards looks the same. "Made in EU" labeled on the AtMega256RFR2 boards +The platform and CPU code, are common for both boards, can be found under +`$(CONTIKI)/platfrom/avr-rssa. The port was developed and tested with RSS2. +This guide assumes that you have basic understanding of how to use the +command line and perform basic admin tasks on UNIX family OSs. You should' +also have understanding about the Contiki OS design as well have C +programming skills. + +Boards Features +---------------- +* Chip Antenna. Supercardiod. +* Robust radio performance. Up to 300 meter line-of-sight. +* Unique EUI64 address via chip combined with EEPROM +* Onboard temp sensor DS18B20, +* Light Sensor. +* 32kHz RTC xtal +* Comparator chip and input. +* SW FET, (relay) for power on/off of sensors. +* DC input via LDO up to 25V. +* Standard. 6-pin TTL-USB header for FTDI cable for UART. +* PCB formfactor for cheap project box G.40X IP54 +* Power/current: + ** RX ~10mA (Full RPC AtMegaXXRFR2). + ** Sleep ~45uA @ 16MHz XTAL + ** Sleep ~15uA @ 8MHz using internal oscillator + +* Preprogammed bootloader. +* CE certified by test institute. + +UART +---- +The board has one UART via the 6-pin TTL-USB adapter, The recommended +baudrate is 38400 bps. This speed gives the lowest error with respect +of the used clock frequency used internally. A possible hi-speed is +250000 bps wich gives 0% Error with 16MHz clock. + +Port Features +-------------- +The platform has the following key features: +* Standard, E64 address from built-in chip. +* First hooks for RPC (Reduced Power Consumption) for AtMegaXXXRFR2. + +Toolchain needs +--------------- +The Atmel toolcahin is available in most operating system. +Note. The native OS packages does not yet support the new +AtMega256RfR2 MCU. + +We'll use toolchain from Atmels web-site. You might also consider +Instant Contiki + + +* For Linux. +See http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORLINUX.aspx +Download the proper 8-bit platform 32 or 64 bit. +Unpack unpack under /usr/local +Also add to your search PATH. For example .bashrc add: +export PATH=$PATH:/usr/local/avr8-gnu-toolchain-linux_x86/bin +or +export PATH=$PATH:/usr/local/avr8-gnu-toolchain-linux_x86_64/bin + +For flash programming you'll need avrdude. For OS using apt-get +apt-get install avrdude + +* For Windows. +Goes here + +Contiki build TARGET +-------------------- +make TARGET=avr-rss2 + +For AtMega128RFR2 boards: +make TARGET=avr-rss2 MCU=atmega128rfr2 + +For AtMega128RFA1 boards: +make TARGET=avr-rss2 MCU=atmega128rfa1 + +Flashing +-------- +Programming using avrdude using serial bootloader. (TTL-USB cable) +Press the RESET button. The bootloader with wait for boot commands +for 3 seconds. + +Flashing commnad line example 256k MCU: +avrdude -p m256rfr2 -c stk500v2 -P /dev/ttyUSB0 -b 38400 -e -U flash:w:hello-world.avr-rss2 + +Flashing commnad line example 128k MCU: +avrdude -p m128rfa1 -c avr109 -P /dev/ttyUSB0 -b 38400 -e -U flash:w:hello-world.avr-rss2 + +Older boards may use the avr109 boot loader. The stk500v2 uses the yellow +lED while the avr109 uses the red LED. + +Tested applications and examples +--------------------------------- +hello-world +ipv6/rpl-udp +ipv6/simple-udp-rpl +rime +ipv6/multicast +example-shell Needs symbol.c to be added to project also seems like +in core/dev/serial-line.c process_poll must be replaced with +process_post. + + /* Wake up consumer process */ +- process_poll(&serial_line_process); ++ process_post(&serial_line_process, 0, 0); + +examples/powertrace + +Platform tutorial applications +.----------------------------- +Example to read out various sensors leds serial numbers etc. +platform/avr-rss2/examples/hello-sensors/ + +This example shows the sensd data encoding. But UDP using 6lowpan. +platform/avr-rss2/examles/ipv6/rpl-udp-report/ + +NAT ip64 ethernet GW based on Contiki core/net/ip64 code +platform/avr-rss2/examples/ipv6/rpl-border-router/ + +Regressions tests +----------------- +Travis compile regression for platform: +regression-tests/23-compile-avr + +Port adds newer version of avr-gcc compiler (4.9.2), to support +testing of newwr Atmel MCU as Atmega256RFR2. Work by Atis Elsts + + +Board approvals +--------------- +Summary: +* R&TTE 73/23/EEC, 89/336/EEC and 99/5/EC +* Safety: EN 60950-1:2006 + A12: 2011 +* RF: ETSI EN 300 328 V1.7.1 (2006-10) +* EMC: ETSI EN 301 489-1 V1.9.2 (2011-09), ETSI EN 301 489-17 V2.2.1 (2012-09) +* EMF: EN 62479:2010 +* Human exposure to electromagnetic fields: EN 62479:2010 + +Commercial availability +------------------------ +Through vendor and though resellers. Note board is will only available +were CE approval is covered. This may be further restricted by WEEE. +Contact vendor. For research legislation is more relaxed in most +countries. + +References +---------- +AtMega64/128/256/RFR2 chip documentation available via Atmel. +Schematics and boards description. Available via Radio-Senors +Smart Reduced Power Consumption Techniques. AT02594 available via Atmel. + +ToDo +----- +API for radio power saving settings introduced Atmels app note AT02594. +Also function for the desensitizing RPC resister. + +Vendor info +----------- +http://radio-sensors.com/ + +Maintainer +---------- +Robert Olsson diff --git a/platform/avr-rss2/apps/sniffer/Makefile b/platform/avr-rss2/apps/sniffer/Makefile new file mode 100644 index 000000000..63412a817 --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/Makefile @@ -0,0 +1,11 @@ +DEFINES+=PROJECT_CONF_H=\"project-conf.h\" +PROJECT_SOURCEFILES += stub-rdc.c + +CONTIKI_PROJECT = sniffer + +all: $(CONTIKI_PROJECT) + +CONTIKI = ../../../.. + +CONTIKI_WITH_RIME = 1 +include $(CONTIKI)/Makefile.include diff --git a/platform/avr-rss2/apps/sniffer/README.md b/platform/avr-rss2/apps/sniffer/README.md new file mode 100644 index 000000000..fa139878b --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/README.md @@ -0,0 +1,25 @@ +Sniffer application mote side +============================= +This put the radio in sniff mode and should capure all traffic used +on the set channel. + +Default channel +--------------- +26 + +Bulld +----- +make TARGET=avr-rss2 + +Default serial port speed +------------------------- +38400 bps + +More info & uasage +------------------ +Look in the host directory + +Contiki support +--------------- +The code promisc for support is needed. This also adds the sensniff +format. See rf230-promisc.pat for the rf230bb radions. diff --git a/platform/avr-rss2/apps/sniffer/host/Makefile b/platform/avr-rss2/apps/sniffer/host/Makefile new file mode 100644 index 000000000..7308f66a5 --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/host/Makefile @@ -0,0 +1,17 @@ + +CC = gcc +CFLAGS = -c +SOURCES = wsbridge.c +OBJECTS = $(SOURCES:.c=.o) +EXE = wsbridge + +all: $(SOURCES) $(EXE) + +$(EXE): $(OBJECTS) + $(CC) $(OBJECTS) -o $@ + +%.o:%.c + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm *.o diff --git a/platform/avr-rss2/apps/sniffer/host/README.md b/platform/avr-rss2/apps/sniffer/host/README.md new file mode 100644 index 000000000..cb7960d50 --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/host/README.md @@ -0,0 +1,38 @@ +Sniffer application host side +============================= +This a Unix application to link between the serial port having the +sensor node connected and Wireshark or tcpdump. Enclosed is a modified +wsbridge (See copyright i file) code to use the format used by sensniff. + +You can also use sensniff which is a Python script. Author of senssniff +is George Oikonomou (oikonomou@users.sf.net) + +See: +https://github.com/g-oikonomou/sensniff + + +Function +-------- +The mote captures WSN data and formats according sensniff format sends +over the serial line. The data is binary. The wsbridge reads reads serial +line (typically /dev/ttyUSB) on Linux systems decodes the sensnaiff and +create timestamp and adds the the PCAP farming and writes the result to +a FIFO or named pipe. /tmp/wireshark or /tmp/sensniff. + +Bulld +----- +Just use the Makefile. Put binary for convince in your path. + +Usage +----- +* wsbridge /dev/ttYUSB +* wireshart -k -i /tmp/wireshark + +Default serial port speed +------------------------- +38400 bps + +References +---------- +http://www.freaklabs.org/index.php/wsbridge.html +https://github.com/g-oikonomou/sensniff diff --git a/platform/avr-rss2/apps/sniffer/host/wsbridge.c b/platform/avr-rss2/apps/sniffer/host/wsbridge.c new file mode 100644 index 000000000..6809f36a8 --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/host/wsbridge.c @@ -0,0 +1,459 @@ +/******************************************************************* + Copyright (C) 2009 FreakLabs + 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 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 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 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. + + Originally written by Christopher Wang aka Akiba. + Please post support questions to the FreakLabs forum. + + *******************************************************************/ +/*! + FreakLabs Freakduino/Wireshark Bridge + + This program allows data from the Freakduino to be piped into wireshark. + When the sniffer firmware is loaded into the Freakduino, then the Freakduino + will be in promiscuous mode and will just dump any frames it sees. This + program takes the frame dump and sends it into Wireshark for analysis. The + global header is already set up to inform wireshark that the link layer for + all frames will be in IEEE 802.15.4 format. After that, it is up to the user + to choose any higher layer protocols to decode above 802.15.4 via the + wireshark "enable protocols" menu. + */ + +/* + + Modified for sensniff format. Magic[4] + Vers[1] + CMD[1] + len[1] + Robert Olsson 2015-11-10 + + */ + +/**************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PORTBUFSIZE 32 +#define BUFSIZE 1024 +#define PACKET_FCS 2 +#define DEBUG 1 +#define PIPENAME "/tmp/wireshark" +#define BAUDRATE B38400 + +enum FSM { + START_CAPTURE, + PACKET_CAPTURE +}; + +static int FD_pipe = -1; +static int FD_com = -1; +static uint8_t port_buf[PORTBUFSIZE]; +static uint8_t circ_buf[BUFSIZE]; +static uint16_t rd_idx = 0; +static uint16_t wr_idx = 0; +static uint8_t len; +static uint8_t state = START_CAPTURE; +static uint8_t file_write = 0; +static fd_set fds; +static const uint8_t magic[] = { 0xC1, 0x1F, 0xFE, 0x72 }; + +/**************************************************************************/ +/*! + Open the serial port that we'll be communicating with the Freakduino (sniffer) + through. + */ +/**************************************************************************/ + +int +serial_open(char *portname) +{ + int baud = B38400; + int fd; /* file descriptor for the serial port */ + struct termios tc, tp; + + fd = open(portname, O_RDONLY | O_NOCTTY | O_NDELAY); + + if(fd == -1) { /* if open is unsucessful */ + printf("serial_open: Unable to open %s.\n", portname); + exit(-1); + } + + fcntl(fd, F_GETFL); + fcntl(fd, F_SETFL, O_RDWR); + + tp.c_cflag = baud | CS8 | CLOCAL | CREAD; + tp.c_oflag = 0; /* Raw Input */ + tp.c_lflag = 0; /* No conoical */ + tp.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL | NLDLY | CRDLY); + + /* ignore CR, ignore parity */ + tp.c_iflag = ~(IGNBRK | PARMRK | INPCK | INLCR | IUCLC | IXOFF) | + BRKINT | IGNPAR | ICRNL | IXON | ISIG | ICANON; + + tp.c_lflag &= ~(ECHO | ECHONL); + tp.c_oflag = 0; /* Raw Input */ + tp.c_iflag &= ~ISTRIP; + + tcflush(fd, TCIFLUSH); + + cfsetospeed(&tp, baud); + cfsetispeed(&tp, baud); + + if(tcsetattr(fd, TCSANOW, &tp) < 0) { + perror("Couldn't set term attributes"); + return -1; + } + return fd; +} +/**************************************************************************/ +/*! + Create the named pipe that we will be communicating with wireshark through. + */ +/**************************************************************************/ +static void +named_pipe_create(char *name) +{ + int rv = 0; + rv = mkfifo(name, 0666); + if((rv == -1) && (errno != EEXIST)) { + perror("Error creating named pipe"); + exit(1); + } + + FD_pipe = open(name, O_WRONLY); + + if(FD_pipe == -1) { + perror("Error connecting to named pipe"); + exit(1); + } +} +/**************************************************************************/ +/*! + Write data to the pipe + */ +/**************************************************************************/ +size_t +data_write(const void *ptr, size_t size) +{ + ssize_t bytes = 0; + if(FD_pipe != -1) { + bytes = write(FD_pipe, ptr, size); + } +} +/**************************************************************************/ +/*! + Write the global header to wireshark. This is only done once at the + beginning of the capture. + */ +/**************************************************************************/ +static void +write_global_hdr() +{ + uint32_t magic_number = 0xa1b2c3d4; /* magic number */ + uint16_t version_major = 2; /* major version number */ + uint16_t version_minor = 4; /* minor version number */ + int32_t thiszone = 0; /* GMT to local correction */ + uint32_t sigfigs = 0; /* accuracy of timestamps */ + uint32_t snaplen = 65535; /* max length of captured packets, in octets */ + uint32_t network = 195; /* data link type (DLT) - IEEE 802.15.4 */ + + data_write(&magic_number, sizeof(magic_number)); + data_write(&version_major, sizeof(version_major)); + data_write(&version_minor, sizeof(version_minor)); + data_write(&thiszone, sizeof(thiszone)); + data_write(&sigfigs, sizeof(sigfigs)); + data_write(&snaplen, sizeof(snaplen)); + data_write(&network, sizeof(network)); +} +/**************************************************************************/ +/*! + Write the frame header into wireshark. This is required for the libpcap + format and informs wireshark that a new frame is coming. + */ +/**************************************************************************/ +static void +write_frame_hdr(uint8_t len) +{ + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds */ + uint32_t incl_len; /* number of octets of packet saved in file */ + uint32_t orig_len; /* actual length of packet */ + struct timeval tv; + + gettimeofday(&tv, NULL); + ts_sec = tv.tv_sec; + ts_usec = tv.tv_usec; + incl_len = len; + orig_len = len + PACKET_FCS; + + data_write(&ts_sec, sizeof(ts_sec)); + data_write(&ts_usec, sizeof(ts_usec)); + data_write(&incl_len, sizeof(incl_len)); + data_write(&orig_len, sizeof(orig_len)); +} +/**************************************************************************/ +/*! + Write one frame into wireshark (via the pipe). + */ +/**************************************************************************/ +static void +write_frame(uint8_t frame_len) +{ + uint8_t i; + + /* actual frame length for wireshark should not include FCS */ + frame_len -= PACKET_FCS; + + /* write header to inform WS that new frame has arrived */ + write_frame_hdr(frame_len); + + /* bump rd_idx. we don't want to write the length byte */ + rd_idx = (rd_idx + 1) % BUFSIZE; + + /* write frame into wireshark */ + for(i = 0; i < frame_len; i++) { + data_write(&circ_buf[rd_idx], 1); + rd_idx = (rd_idx + 1) % BUFSIZE; + } + + /* bump rd_idx. we're not using the trailing FCS value */ + rd_idx = (rd_idx + 1) % BUFSIZE; +} +/**************************************************************************/ +/*! + Calculate total number of bytes in buffer. + */ +/**************************************************************************/ +static uint16_t +calc_bytes_in_buf() +{ + if(rd_idx > wr_idx) { + /* read index is greater than write. we must have wrapped around */ + return BUFSIZE - (rd_idx - wr_idx); + } else { + return wr_idx - rd_idx; + } +} +/**************************************************************************/ +/*! + Deal with any received signals. This includes ctrl-C to stop the program. + */ +/**************************************************************************/ +static void +sig_int(int signo) +{ + (void)signo; + if(FD_pipe != -1) { + printf("\nClosing pipe.\n"); + close(FD_pipe); + } + + if(FD_com != -1) { + printf("\nClosing serial port.\n"); + close(FD_com); + } + + printf("\nSignal captured and devices shut down.\n"); + + exit(0); +} +/**************************************************************************/ +/*! + Init the signals we'll be checking for. + */ +/**************************************************************************/ +static void +signal_init(void) +{ + signal(SIGINT, sig_int); + signal(SIGHUP, sig_int); + signal(SIGTERM, sig_int); +} +int got; +int debug; + +/**************************************************************************/ +/*! + Here's the meat of the code. + */ +/**************************************************************************/ +int +main(int argc, char *argv[]) +{ + int nbytes; + uint8_t i; + + got = 0; + + /* capture any signals that will terminate program */ + signal_init(); + + /* make sure the COM port is specified */ + if(argc == 2) { + /* open the COM port */ + if((FD_com = serial_open(argv[1])) == -1) { + printf("Serial port not opened.\n"); + return 0; + } else { + /* set up the select statement for the COM port. */ + FD_ZERO(&fds); + FD_SET(FD_com, &fds); + + printf("Serial port connected. Waiting for wireshark connection.\n"); + printf("Open wireshark and connect to local interface: %s\n", PIPENAME); + } + } else { + printf("Usage: wsbridge .\n"); + return 0; + } + + /* create and open pipe for wireshark */ + named_pipe_create(PIPENAME); + + /* wait for wireshark to connect to pipe. Once wireshark */ + /* connects, then the global header will be written to it. */ + if(FD_pipe != -1) { + write_global_hdr(); + printf("Client connected to pipe.\n"); + } + + for(;;) { + uint16_t bytes_in_buf; + uint8_t frame_len, byte_ctr; + + /* block until there is data in the serial port */ + select(FD_com + 1, &fds, NULL, NULL, NULL); + if(FD_ISSET(FD_com, &fds)) { + int ii; + /* wait for data to come in on the serial port */ + if((nbytes = read(FD_com, port_buf, PORTBUFSIZE)) > 0) { + + if(debug) { + uint8_t p; + printf("read nbytes=%d\n", nbytes); + for(i = 0; i < nbytes; i++) { + printf(" %02X", port_buf[i]); + } + printf("\n"); + } + /* write data to circular buffer. loop through all received bytes */ + for(i = 0; i < nbytes; i++) { + switch(state) { + case START_CAPTURE: + /* new frame starting */ + if((got == 0) && (port_buf[i] == magic[0])) { + got = 1; + } else if((got == 1) && (port_buf[i] == magic[1])) { + got = 2; + } else if((got == 2) && (port_buf[i] == magic[2])) { + got = 3; + } else if((got == 3) && (port_buf[i] == magic[3])) { + got = 4; + if(debug) { + printf("GOT MAGIC i=%d\n", i); + } + } else if((got == 4) && (port_buf[i] == 1)) { + got = 5; + if(debug) { + printf("GOT VERSION i=%d\n", port_buf[i]); + } + } else if((got == 5) && (port_buf[i] == 0)) { + got = 6; + if(debug) { + printf("GOT COMMAND i=%d\n", port_buf[i]); + } + } else if(got == 6) { + len = port_buf[i]; + byte_ctr = 0; + if(debug) { + printf("Len = %02X.\n", len); + } + circ_buf[wr_idx] = len; + wr_idx = (wr_idx + 1) % BUFSIZE; + state = PACKET_CAPTURE; + } else { + got = 0; + } + break; + + case PACKET_CAPTURE: + /* continue capturing bytes until end of frame */ + /* write data to circular buffer and increment index */ + + circ_buf[wr_idx] = port_buf[i]; + /* ////printf("%02X ", circ_buf[wr_idx]); */ + + wr_idx = (wr_idx + 1) % BUFSIZE; + /* track number of received bytes. when received bytes */ + /* equals frame length, then restart state machine and */ + /* write bytes to wireshark */ + byte_ctr++; + if(byte_ctr == (len - 1)) { + state = START_CAPTURE; + file_write = 1; + /* printf("\n"); */ + got = 0; + } + break; + } + fflush(stdout); + } + /* at least one frame has been written. loop through circular buffer */ + /* and write out all completed frames */ + while(file_write) { + /* capture frame length and check buffer to see if one or more frames */ + /* are available. */ + frame_len = circ_buf[rd_idx]; + bytes_in_buf = calc_bytes_in_buf(); + + if(bytes_in_buf > frame_len) { + /* if more than one frame is available, then write one frame to */ + /* wireshark and then see if any more are available. */ + write_frame(frame_len); + } else if(bytes_in_buf == frame_len) { + /* only one frame is available. write to wireshark and then quit */ + /* the loop */ + write_frame(frame_len); + file_write = 0; + } else { + /* less than one frame is available. quit the loop and collect more */ + /* bytes. we normally should not get here. */ + file_write = 0; + } + } + } + } + } +} diff --git a/platform/avr-rss2/apps/sniffer/project-conf.h b/platform/avr-rss2/apps/sniffer/project-conf.h new file mode 100644 index 000000000..d56b19e7d --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/project-conf.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, Loughborough University - Computer Science + * 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 + * Project specific configuration defines for the sniffer example. + * + * \author + * George Oikonomou - + * Robert Olsson - + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + + +#define NETSTACK_CONF_MAC nullmac_driver +/* Can see other channels. Interesting. */ +/* #define NETSTACK_CONF_MAC csma_driver */ +#define NETSTACK_CONF_RDC stub_rdc_driver + + +#endif /* PROJECT_CONF_H_ */ diff --git a/platform/avr-rss2/apps/sniffer/rf230-promisc.pat b/platform/avr-rss2/apps/sniffer/rf230-promisc.pat new file mode 100644 index 000000000..3e2c98e6f --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/rf230-promisc.pat @@ -0,0 +1,39 @@ +diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c +index 53959d1..b9f2262 100644 +--- a/cpu/avr/radio/rf230bb/rf230bb.c ++++ b/cpu/avr/radio/rf230bb/rf230bb.c +@@ -544,7 +544,7 @@ rf230_set_promiscuous_mode(bool isPromiscuous) { + #if RF230_CONF_AUTOACK + is_promiscuous = isPromiscuous; + /* TODO: Figure out when to pass promisc state to 802.15.4 */ +-// radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON); ++ radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON); + #endif + } + +@@ -1392,6 +1392,25 @@ PROCESS_THREAD(rf230_process, ev, data) + /* Restore interrupts. */ + HAL_LEAVE_CRITICAL_REGION(); + PRINTF("rf230_read: %u bytes lqi %u\n",len,rf230_last_correlation); ++ ++ if(is_promiscuous) { ++ uint8_t i; ++ unsigned const char * rxdata = packetbuf_dataptr(); ++ /* Print magic */ ++ putchar(0xC1); ++ putchar(0x1F); ++ putchar(0xFE); ++ putchar(0x72); ++ /* Print version */ ++ putchar(0x01); ++ /* Print CMD == frame */ ++ putchar(0x00); ++ putchar(len+3); ++ ++ for (i=0;i1 + { + uint8_t i; diff --git a/platform/avr-rss2/apps/sniffer/sniffer-example-coap.pcapng b/platform/avr-rss2/apps/sniffer/sniffer-example-coap.pcapng new file mode 100644 index 000000000..e69de29bb diff --git a/platform/avr-rss2/apps/sniffer/sniffer.c b/platform/avr-rss2/apps/sniffer/sniffer.c new file mode 100644 index 000000000..be572bce1 --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/sniffer.c @@ -0,0 +1,67 @@ +/* + * 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. + * + */ + +/* + Author: Robert Olsson +*/ + +#include "contiki.h" +#include "net/rime/rime.h" +#include "random.h" +#include "dev/button-sensor.h" +#include "dev/leds.h" +#include +/*---------------------------------------------------------------------------*/ + +PROCESS(sniffer_process, "Sniffer process"); +AUTOSTART_PROCESSES(&sniffer_process); + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(sniffer_process, ev, data) +{ + PROCESS_BEGIN(); + + /* + To get rf230bb radio in sniff mode we need to have radio in RX_ON. + The promisc commands fixes this for us. No need to set PAN and + address or MAC to zero is this case. Se Atmel datasheet. There is + a chance other radios works the same way. + */ + + rf230_set_promiscuous_mode(1); + + printf("Sniffer started\n"); + + while(1) { + PROCESS_YIELD(); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/apps/sniffer/stub-rdc.c b/platform/avr-rss2/apps/sniffer/stub-rdc.c new file mode 100644 index 000000000..a4db0710d --- /dev/null +++ b/platform/avr-rss2/apps/sniffer/stub-rdc.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2010, Loughborough University - Computer Science + * 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 + * Definition of a fake RDC driver to be used with passive + * examples. The sniffer will never send packets and it will never + * push incoming packets up the stack. We do this by defining this + * driver as our RDC. We then drop everything + * + * \author + * George Oikonomou - + */ + +#include "net/mac/mac.h" +#include "net/mac/rdc.h" +/*---------------------------------------------------------------------------*/ +static void +send(mac_callback_t sent, void *ptr) +{ + if(sent) { + sent(ptr, MAC_TX_OK, 1); + } +} +/*---------------------------------------------------------------------------*/ +static void +send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *list) +{ + if(sent) { + sent(ptr, MAC_TX_OK, 1); + } +} +/*---------------------------------------------------------------------------*/ +static void +input(void) +{ +} +/*---------------------------------------------------------------------------*/ +static int +on(void) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +off(int keep_radio_on) +{ + return keep_radio_on; +} +/*---------------------------------------------------------------------------*/ +static unsigned short +cca(void) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static void +init(void) +{ +} +/*---------------------------------------------------------------------------*/ +const struct rdc_driver stub_rdc_driver = { + "stub-rdc", + init, + send, + send_list, + input, + on, + off, + cca, +}; +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/contiki-conf.h b/platform/avr-rss2/contiki-conf.h new file mode 100644 index 000000000..3e1f5dfc2 --- /dev/null +++ b/platform/avr-rss2/contiki-conf.h @@ -0,0 +1,350 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * 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 + * Configuration for RSS2 (radio-sensors.com) platform + */ + +#ifndef CONTIKI_CONF_H_ +#define CONTIKI_CONF_H_ + +/* include the project config */ +/* PROJECT_CONF_H might be defined in the project Makefile */ +#ifdef PROJECT_CONF_H +#include PROJECT_CONF_H +#endif + +/* Platform name, type, and MCU clock rate */ +#define PLATFORM_NAME "rss2" +#define PLATFORM_TYPE ATMEGA256RFR2 +#ifndef F_CPU +#define F_CPU 8000000UL +#endif + +#include + +#ifndef NETSTACK_CONF_MAC +#define NETSTACK_CONF_MAC csma_driver +#endif + +#ifndef NETSTACK_CONF_RDC +#define NETSTACK_CONF_RDC contikimac_driver +#endif + +#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 contikimac_framer +#else +#define NETSTACK_CONF_FRAMER framer_802154 +#endif +#endif + +#ifndef NETSTACK_CONF_RADIO +#define NETSTACK_CONF_RADIO rf230_driver +#endif + +#ifndef CHANNEL_802_15_4 +#define CHANNEL_802_15_4 26 +#endif + +/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ +#ifndef RF230_CONF_AUTOACK +#define RF230_CONF_AUTOACK 1 +#endif + +#define MCUCSR MCUSR + +/* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz. + * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit + * clock_time_t. + */ +/* Clock ticks per second */ + +#define CLOCK_CONF_SECOND 128 +typedef unsigned long clock_time_t; +#define CLOCK_LT(a, b) ((signed long)((a) - (b)) < 0) +#define INFINITE_TIME 0xffffffff +/* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */ +void clock_delay_msec(uint16_t howlong); +void clock_adjust_ticks(clock_time_t howmany); + +/* The radio needs to interrupt during an rtimer interrupt */ +#define RTIMER_CONF_NESTED_INTERRUPTS 1 + +/* RSS2 boards has a 32768Hz on TIMER2 */ +#define AVR_CONF_USE32KCRYSTAL 1 +#define SLIP_PORT RS232_PORT_0 + +/* Pre-allocated memory for loadable modules heap space (in bytes)*/ +/* Default is 4096. Currently used only when elfloader is present. Not tested on Raven */ +/* #define MMEM_CONF_SIZE 256 */ + +/* Starting address for code received via the codeprop facility. Not tested. */ +typedef unsigned long off_t; +/* #define EEPROMFS_ADDR_CODEPROP 0x8000 */ + +/* Logging adds 200 bytes to program size. RS232 output slows down webserver. */ +/* #define LOG_CONF_ENABLED 1 */ + +/* RADIOSTATS is used in rf230bb, clock.c and the webserver cgi to report radio usage */ +/* It has less overhead than ENERGEST */ +#define RADIOSTATS 1 + +/* More extensive stats, via main loop printfs or webserver status pages */ +#define ENERGEST_CONF_ON 1 + +/* Packet statistics */ +typedef unsigned short uip_stats_t; +#define UIP_STATISTICS 0 + +/* Available watchdog timeouts depend on mcu. Default is WDTO_2S. -1 Disables the watchdog. */ +/* AVR Studio simulator tends to reboot due to clocking the WD 8 times too fast */ +/* #define WATCHDOG_CONF_TIMEOUT -1 */ + +/* Debugflow macro, useful for tracing path through mac and radio interrupts */ +/* #define DEBUGFLOWSIZE 128 */ + +/* Define MAX_*X_POWER to reduce tx power and ignore weak rx packets for testing a miniature multihop network. + * Leave undefined for full power and sensitivity. + * tx=0 (3dbm, default) to 15 (-17.2dbm) + * RF230_CONF_AUTOACK sets the extended mode using the energy-detect register with rx=0 (-91dBm) to 84 (-7dBm) + * else the rssi register is used having range 0 (91dBm) to 28 (-10dBm) + * For simplicity RF230_MIN_RX_POWER is based on the energy-detect value and divided by 3 when autoack is not set. + * On the RF230 a reduced rx power threshold will not prevent autoack if enabled and requested. + * These numbers applied to both Raven and Jackdaw give a maximum communication distance of about 15 cm + * and a 10 meter range to a full-sensitivity RF230 sniffer. + *#define RF230_MAX_TX_POWER 15 + *#define RF230_MIN_RX_POWER 30 + */ +/* The rf231 and atmega128rfa1 can use an rssi threshold for triggering rx_busy that saves 0.5ma in rx mode */ +/* 1 - 15 maps into -90 to -48 dBm; the register is written with RF230_MIN_RX_POWER/6 + 1. Undefine for -100dBm sensitivity */ +/* #define RF230_MIN_RX_POWER 0 */ + +/* Network setup */ +/* TX routine passes the cca/ack result in the return parameter */ +#define RDC_CONF_HARDWARE_ACK 1 +/* TX routine does automatic cca and optional backoffs */ +#define RDC_CONF_HARDWARE_CSMA 1 +/* Allow MCU sleeping between channel checks */ +#define RDC_CONF_MCU_SLEEP 1 + +#if NETSTACK_CONF_WITH_IPV6 +#define LINKADDR_CONF_SIZE 8 +#define UIP_CONF_ICMP6 1 +#define UIP_CONF_UDP 1 +#ifndef UIP_CONF_TCP +#define UIP_CONF_TCP 1 +#endif +#define NETSTACK_CONF_NETWORK sicslowpan_driver +#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 +#else +/* ip4 should build but is largely untested */ +#define LINKADDR_CONF_SIZE 2 +#define NETSTACK_CONF_NETWORK rime_driver +#endif + +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 0 + +/* 10 bytes per stateful address context - see sicslowpan.c */ +/* Default is 1 context with prefix aaaa::/64 */ +/* These must agree with all the other nodes or there will be a failure to communicate! */ +#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1 +#define SICSLOWPAN_CONF_ADDR_CONTEXT_0 { addr_contexts[0].prefix[0] = 0xaa; addr_contexts[0].prefix[1] = 0xaa; } +#define SICSLOWPAN_CONF_ADDR_CONTEXT_1 { addr_contexts[1].prefix[0] = 0xbb; addr_contexts[1].prefix[1] = 0xbb; } +#define SICSLOWPAN_CONF_ADDR_CONTEXT_2 { addr_contexts[2].prefix[0] = 0x20; addr_contexts[2].prefix[1] = 0x01; addr_contexts[2].prefix[2] = 0x49; addr_contexts[2].prefix[3] = 0x78, addr_contexts[2].prefix[4] = 0x1d; addr_contexts[2].prefix[5] = 0xb1; } + +/* Take the default TCP maximum segment size for efficiency and simpler wireshark captures */ +/* Use this to prevent 6LowPAN fragmentation (whether or not fragmentation is enabled) */ +/* #define UIP_CONF_TCP_MSS 48 */ + +#define UIP_CONF_IP_FORWARD 0 +#define UIP_CONF_FWCACHE_SIZE 0 + +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_QUEUE_PKT 1 +#define UIP_CONF_IPV6_REASSEMBLY 0 + +#define UIP_CONF_UDP_CHECKSUMS 1 +#define UIP_CONF_TCP_SPLIT 1 +#define UIP_CONF_DHCP_LIGHT 1 + +#if 0 /* No radio cycling */ + +#define NETSTACK_CONF_MAC nullmac_driver +#define NETSTACK_CONF_RDC sicslowmac_driver +#define NETSTACK_CONF_FRAMER framer_802154 +/* 1 + Number of auto retry attempts 0-15 (0 implies don't use extended TX_ARET_ON mode) */ +#define RF230_CONF_FRAME_RETRIES 2 +/* Number of csma retry attempts 0-5 in extended tx mode (7 does immediate tx with no csma) */ +#define RF230_CONF_CSMA_RETRIES 5 +/* Default is one RAM buffer for received packets. More than one may benefit multiple TCP connections or ports */ +#define RF230_CONF_RX_BUFFERS 3 +#define SICSLOWPAN_CONF_FRAG 1 +/* Most browsers reissue GETs after 3 seconds which stops fragment reassembly so a longer MAXAGE does no good */ +#define SICSLOWPAN_CONF_MAXAGE 3 +/* How long to wait before terminating an idle TCP connection. Smaller to allow faster sleep. Default is 120 seconds */ +/* If wait is too short the connection can be reset as a result of multiple fragment reassembly timeouts */ +#define UIP_CONF_WAIT_TIMEOUT 20 +/* 54 bytes per queue ref buffer */ +#define QUEUEBUF_CONF_REF_NUM 2 +/* Allocate remaining RAM as desired */ +/* 30 bytes per TCP connection */ +/* 6LoWPAN does not do well with concurrent TCP streams, as new browser GETs collide with packets coming */ +/* from previous GETs, causing decreased throughput, retransmissions, and timeouts. Increase to study this. */ +/* ACKs to other ports become interleaved with computation-intensive GETs, so ACKs are particularly missed. */ +/* Increasing the number of packet receive buffers in RAM helps to keep ACKs from being lost */ +#define UIP_CONF_MAX_CONNECTIONS 4 +/* 2 bytes per TCP listening port */ +#define UIP_CONF_MAX_LISTENPORTS 4 +/* 25 bytes per UDP connection */ +#define UIP_CONF_UDP_CONNS 10 +/* See uip-ds6.h */ +#define NBR_TABLE_CONF_MAX_NEIGHBORS 20 +#define UIP_CONF_DS6_DEFRT_NBU 2 +#define UIP_CONF_DS6_PREFIX_NBU 3 +#define UIP_CONF_MAX_ROUTES 20 +#define UIP_CONF_DS6_ADDR_NBU 3 +#define UIP_CONF_DS6_MADDR_NBU 0 +#define UIP_CONF_DS6_AADDR_NBU 0 + +#elif 1 /* Contiki-mac radio cycling */ +/* #define NETSTACK_CONF_MAC nullmac_driver */ +/* csma needed for burst mode at present. Webserver won't work without it */ +/* #define NETSTACK_CONF_MAC csma_driver */ +/* #define NETSTACK_CONF_RDC contikimac_driver */ +/* Default is two CCA separated by 500 usec */ + +/* So without the header this needed for RPL mesh to form */ +#define CONTIKIMAC_FRAMER_CONF_SHORTEST_PACKET_SIZE (43 - 18) /* multicast RPL DIS length */ +/* Not tested much yet */ +#define CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION 0 +#define CONTIKIMAC_CONF_COMPOWER 1 +#define RIMESTATS_CONF_ENABLED 0 + +/* A 0 here means non-extended mode; 1 means extended mode with no retry, >1 for retrys */ +/* Contikimac strobes on its own, but hardware retries are faster */ +#define RF230_CONF_FRAME_RETRIES 1 +/* Long csma backoffs will compromise radio cycling; set to 0 for 1 csma */ +#define RF230_CONF_CSMA_RETRIES 0 +#define SICSLOWPAN_CONF_FRAG 1 +#define SICSLOWPAN_CONF_MAXAGE 3 +/* 54 bytes per queue ref buffer */ +#define QUEUEBUF_CONF_REF_NUM 2 +/* Allocate remaining RAM. Not much left due to queuebuf increase */ +#define UIP_CONF_MAX_CONNECTIONS 2 +#define UIP_CONF_MAX_LISTENPORTS 4 +#define UIP_CONF_UDP_CONNS 5 +#define NBR_TABLE_CONF_MAX_NEIGHBORS 20 +#define UIP_CONF_DS6_DEFRT_NBU 2 +#define UIP_CONF_DS6_PREFIX_NBU 3 +#define UIP_CONF_MAX_ROUTES 4 +#define UIP_CONF_DS6_ADDR_NBU 3 +#define UIP_CONF_DS6_MADDR_NBU 0 +#define UIP_CONF_DS6_AADDR_NBU 0 + +#elif 0 /* cx-mac radio cycling */ +/* RF230 does clear-channel assessment in extended mode (autoretries>0) */ +/* These values are guesses */ +#define RF230_CONF_FRAME_RETRIES 10 +#define RF230_CONF_CSMA_RETRIES 2 +#if RF230_CONF_CSMA_RETRIES +#define NETSTACK_CONF_MAC nullmac_driver +#else +#define NETSTACK_CONF_MAC csma_driver +#endif +#define NETSTACK_CONF_RDC cxmac_driver +#define NETSTACK_CONF_FRAMER framer_802154 +#define SICSLOWPAN_CONF_FRAG 1 +#define SICSLOWPAN_CONF_MAXAGE 3 +#define CXMAC_CONF_ANNOUNCEMENTS 0 +/* 54 bytes per queue ref buffer */ +#define QUEUEBUF_CONF_REF_NUM 2 +/* Allocate remaining RAM. Not much left due to queuebuf increase */ +#define UIP_CONF_MAX_CONNECTIONS 2 +#define UIP_CONF_MAX_LISTENPORTS 4 +#define UIP_CONF_UDP_CONNS 5 +#define NBR_TABLE_CONF_MAX_NEIGHBORS 4 +#define UIP_CONF_DS6_DEFRT_NBU 2 +#define UIP_CONF_DS6_PREFIX_NBU 3 +#define UIP_CONF_MAX_ROUTES 4 +#define UIP_CONF_DS6_ADDR_NBU 3 +#define UIP_CONF_DS6_MADDR_NBU 0 +#define UIP_CONF_DS6_AADDR_NBU 0 +/* Below gives 10% duty cycle, undef for default 5% */ +/* #define CXMAC_CONF_ON_TIME (RTIMER_ARCH_SECOND / 80) */ +/* Below gives 50% duty cycle */ +/* #define CXMAC_CONF_ON_TIME (RTIMER_ARCH_SECOND / 16) */ + +#else +/* #error Network configuration not specified! */ +#endif /* Network setup */ + +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 15 +#endif + +/* ************************************************************************** */ +/* #pragma mark RPL Settings */ +/* ************************************************************************** */ +#if UIP_CONF_IPV6_RPL + +#define UIP_CONF_ROUTER 1 +#define UIP_CONF_ND6_SEND_RA 0 +#define UIP_CONF_ND6_REACHABLE_TIME 600000 +#define UIP_CONF_ND6_RETRANS_TIMER 10000 + +/* For slow slip connections, to prevent buffer overruns */ +/* #define UIP_CONF_RECEIVE_WINDOW 300 */ +#undef UIP_CONF_FWCACHE_SIZE +#define UIP_CONF_BUFFER_SIZE 600 /* DHCPv4 packets by ip64 module */ +#define UIP_CONF_FWCACHE_SIZE 30 +#define UIP_CONF_BROADCAST 1 +#define UIP_ARCH_IPCHKSUM 1 +#define UIP_CONF_PINGADDRCONF 0 +#define UIP_CONF_LOGGING 0 + +#endif /* RPL */ + +#define CCIF +#define CLIF +#ifndef CC_CONF_INLINE +#define CC_CONF_INLINE inline +#endif + +#endif /* CONTIKI_CONF_H_ */ diff --git a/platform/avr-rss2/contiki-main.c b/platform/avr-rss2/contiki-main.c new file mode 100644 index 000000000..172c6139f --- /dev/null +++ b/platform/avr-rss2/contiki-main.c @@ -0,0 +1,635 @@ +/* + * Copyright (c) 2006, Technical University of Munich + * 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. + * + * Reworked for avr-rss2 platform. Robert Olsson + */ + +#define PRINTF(FORMAT, args ...) printf_P(PSTR(FORMAT),##args) + +#define ANNOUNCE_BOOT 1 /* adds about 600 bytes to program size */ +#if ANNOUNCE_BOOT +#define PRINTA(FORMAT, args ...) printf_P(PSTR(FORMAT),##args) +#else +#define PRINTA(...) +#endif + +#define DEBUG 0 +#if DEBUG +#define PRINTD(FORMAT, args ...) printf_P(PSTR(FORMAT),##args) +#else +#define PRINTD(...) +#endif + +#include +#include +#include +#include +#include +#include + +#include "loader/symbols-def.h" +#include "loader/symtab.h" + +#include "params.h" +#include "rss2.h" +#include "leds.h" +#include "i2c.h" +#include "radio/rf230bb/rf230bb.h" +#include "net/mac/frame802154.h" +#include "net/mac/framer-802154.h" +#include "net/ipv6/sicslowpan.h" + +#include "contiki.h" +#include "contiki-net.h" +#include "contiki-lib.h" + +#include "dev/rs232.h" +#include "dev/serial-line.h" +#include "dev/slip.h" + +#if AVR_WEBSERVER +#include "httpd-fs.h" +#include "httpd-cgi.h" +#endif + +#ifdef COFFEE_FILES +#include "cfs/cfs.h" +#include "cfs/cfs-coffee.h" +#endif + +#if UIP_CONF_ROUTER && 0 +#include "net/routing/rimeroute.h" +#include "net/rime/rime-udp.h" +#endif + +#include "net/rime/rime.h" + +/* Track interrupt flow through mac, rdc and radio driver */ +/* #define DEBUGFLOWSIZE 32 */ +#if DEBUGFLOWSIZE +uint8_t debugflowsize, debugflow[DEBUGFLOWSIZE]; +#define DEBUGFLOW(c) if(debugflowsize < (DEBUGFLOWSIZE - 1)) debugflow[debugflowsize++] = c +#else +#define DEBUGFLOW(c) +#endif + +/* Get periodic prints from idle loop, from clock seconds or rtimer interrupts */ +/* Use of rtimer will conflict with other rtimer interrupts such as contikimac radio cycling */ +/* STAMPS will print ENERGEST outputs if that is enabled. */ +#define PERIODICPRINTS 1 +#if PERIODICPRINTS +/* #define PINGS 64 */ +#define ROUTES 600 +#define STAMPS 60 +#define STACKMONITOR 1024 +uint32_t clocktime; +#define TESTRTIMER 0 +#if TESTRTIMER +uint8_t rtimerflag = 1; +struct rtimer rt; +void +rtimercycle(void) +{ + rtimerflag = 1; +} +#endif +#endif + +uint16_t node_id; /* Can be set by cooja */ + +uint16_t ledtimer_red, ledtimer_yellow; +uint16_t i2c_probed; /* i2c devices we have probed */ + + +/*-------------------------------------------------------------------------*/ +/*----------------------Configuration of the .elf file---------------------*/ +#if 1 +/* The proper way to set the signature is */ +#include +#else +/* Older avr-gcc's may not define the needed SIGNATURE bytes. Do it manually if you get an error */ +typedef struct {const unsigned char B2; + const unsigned char B1; + const unsigned char B0; +} __signature_t; +#define SIGNATURE __signature_t __signature __attribute__((section(".signature"))) +SIGNATURE = { + .B2 = 0x01, /* SIGNATURE_2, //ATMEGA128rfa1 */ + .B1 = 0xA7, /* SIGNATURE_1, //128KB flash */ + .B0 = 0x1E, /* SIGNATURE_0, //Atmel */ +}; +#endif + +#if 1 +/* JTAG, SPI enabled, Internal RC osc, Boot flash size 4K, 6CK+65msec delay, brownout disabled */ +FUSES = { .low = 0xe2, .high = 0x99, .extended = 0xff, }; +#else +/* JTAG+SPI, Boot 4096 words @ $F000, Internal oscillator, startup 6 CK +0 ms, Brownout 1.8 volts */ +FUSES = { .low = 0xC2, .high = 0x99, .extended = 0xfe, }; +#endif + +uint8_t +rng_get_uint8(void) +{ +#if 1 + /* Upper two RSSI reg bits (RND_VALUE) are random in rf231 */ + uint8_t j; + j = (PHY_RSSI & 0xc0) + ((PHY_RSSI >> 2) & 0x30) + ((PHY_RSSI >> 4) & 0x0c) + ((PHY_RSSI >> 6) & 0x03); +#else +/* Get a pseudo random number using the ADC */ + uint8_t i, j; + ADCSRA = 1 << ADEN; /* Enable ADC, not free running, interrupt disabled, fastest clock */ + for(i = 0; i < 4; i++) { + ADMUX = 0; /* toggle reference to increase noise */ + ADMUX = 0x1E; /* Select AREF as reference, measure 1.1 volt bandgap reference. */ + ADCSRA |= 1 << ADSC; /* Start conversion */ + while(ADCSRA & (1 << ADSC)) ; /* Wait till done */ + j = (j << 2) + ADC; + } + ADCSRA = 0; /* Disable ADC */ +#endif + PRINTD("rng issues %d\n", j); + return j; +} +/*-------------------------Low level initialization------------------------*/ +/*------Done in a subroutine to keep main routine stack usage small--------*/ +void +initialize(void) +{ + watchdog_init(); + watchdog_start(); + leds_init(); + serial_line_init(); + + rs232_init(RS232_PORT_0, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + rs232_redirect_stdout(RS232_PORT_0); + +#if 0 + /* Do it my way... */ + UBRR0L = 25; + UBRR0H = 0; + UCSR0A = (1 << U2X0); /*Double */ +#endif + + rs232_set_input(RS232_PORT_0, serial_line_input_byte); + + clock_init(); + + if(MCUSR & (1 << PORF)) { + PRINTD("Power-on reset.\n"); + } + if(MCUSR & (1 << EXTRF)) { + PRINTD("External reset!\n"); + } + if(MCUSR & (1 << BORF)) { + PRINTD("Brownout reset!\n"); + } + if(MCUSR & (1 << WDRF)) { + PRINTD("Watchdog reset!\n"); + } + if(MCUSR & (1 << JTRF)) { + PRINTD("JTAG reset!\n"); + } + + i2c_init(100000); /* 100 bit/s */ + +#if STACKMONITOR + /* Simple stack pointer highwater monitor. Checks for magic numbers in the main + * loop. In conjuction with PERIODICPRINTS, never-used stack will be printed + * every STACKMONITOR seconds. + */ + { + extern uint16_t __bss_end; + uint16_t p = (uint16_t)&__bss_end; + do { + *(uint16_t *)p = 0x4242; + p += 10; + } while(p < SP - 10); /* don't overwrite our own stack */ + } +#endif + +#define CONF_CALIBRATE_OSCCAL 0 +#if CONF_CALIBRATE_OSCCAL + void calibrate_rc_osc_32k(); + { + extern uint8_t osccal_calibrated; + uint8_t i; + PRINTD("\nBefore calibration OSCCAL=%x\n", OSCCAL); + for(i = 0; i < 10; i++) { + calibrate_rc_osc_32k(); + PRINTD("Calibrated=%x\n", osccal_calibrated); +/* #include */ +/* #define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) ) */ +/* delay_us(50000); */ + } + clock_init(); + } +#endif + + PRINTA("\n*******Booting %s*******\n", CONTIKI_VERSION_STRING); + +/* rtimers needed for radio cycling */ + rtimer_init(); + + /* Initialize process subsystem */ + process_init(); + + /* etimers must be started before ctimer_init */ + process_start(&etimer_process, NULL); + ctimer_init(); + + /* Start radio and radio receive process */ + NETSTACK_RADIO.init(); + +/* Get a random seed for the 802.15.4 packet sequence number. + * Some layers will ignore duplicates found in a history (e.g. Contikimac) + * causing the initial packets to be ignored after a short-cycle restart. + */ + random_init(rng_get_uint8()); + + /* Set addresses BEFORE starting tcpip process */ + + linkaddr_t addr; + + printf("I2C: "); + i2c_probed = i2c_probe(); + printf("\n"); + + if( i2c_probed & I2C_AT24MAC ) { + i2c_at24mac_read((char *)&addr.u8, 1); + linkaddr_set_node_addr(&addr); + } + else { + char eui64[8]; + printf("Random EUI64 address generated\n"); + eui64[0] = 0xfc; /* Atmels OUI */ + eui64[1] = 0xc2; + eui64[2] = 0x3d; + eui64[3] = 0; + eui64[4] = 0; + eui64[5] = 0; + eui64[6] = node_id >> 8; + eui64[7] = node_id & 0xff; + linkaddr_set_node_addr(&eui64); + } + + /* memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t)); */ + +#if NETSTACK_CONF_WITH_IPV6 + memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t)); +#endif + + rf230_set_pan_addr(params_get_panid(), params_get_panaddr(), (uint8_t *)&addr.u8); + rf230_set_channel(params_get_channel()); + rf230_set_txpower(params_get_txpower()); + +#if NETSTACK_CONF_WITH_IPV6 + PRINTA("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n", addr.u8[0], addr.u8[1], addr.u8[2], addr.u8[3], addr.u8[4], addr.u8[5], addr.u8[6], addr.u8[7]); +#else + PRINTA("MAC address "); + uint8_t i; + for(i = sizeof(linkaddr_t); i > 0; i--) { + PRINTA("%x:", addr.u8[i - 1]); + } + PRINTA("\n"); +#endif + + /* Initialize stack protocols */ + queuebuf_init(); + NETSTACK_RDC.init(); + NETSTACK_MAC.init(); + NETSTACK_NETWORK.init(); + +#if ANNOUNCE_BOOT + PRINTA("MAC=%s, RDC=%s, NETWORK=%s, channel=%-u, check-rate-Hz=%-u, tx-power=%-u\n", NETSTACK_MAC.name, + NETSTACK_RDC.name, NETSTACK_NETWORK.name, rf230_get_channel(), + CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 : NETSTACK_RDC.channel_check_interval()), + rf230_get_txpower()); +#if UIP_CONF_IPV6_RPL + PRINTA("RPL Enabled\n"); +#endif +#if UIP_CONF_ROUTER + PRINTA("Routing Enabled\n"); +#endif + +#endif /* ANNOUNCE_BOOT */ + +#if NETSTACK_CONF_WITH_IPV6 || NETSTACK_CONF_WITH_IPV4 + process_start(&tcpip_process, NULL); +#endif + + /* Autostart other processes */ + autostart_start(autostart_processes); + + /*---If using coffee file system create initial web content if necessary---*/ +#if COFFEE_FILES + int fa = cfs_open("/index.html", CFS_READ); + if(fa < 0) { /* Make some default web content */ + PRINTA("No index.html file found, creating upload.html!\n"); + PRINTA("Formatting FLASH file system for coffee..."); + cfs_coffee_format(); + PRINTA("Done!\n"); + fa = cfs_open("/index.html", CFS_WRITE); + int r = cfs_write(fa, &"It works!", 9); + if(r < 0) { + PRINTA("Can''t create /index.html!\n"); + } + cfs_close(fa); +/* fa = cfs_open("upload.html"), CFW_WRITE); */ +/*
*/ + } +#endif /* COFFEE_FILES */ + +/* Add addresses for testing */ +#if 0 + { + uip_ip6addr_t ipaddr; + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); +/* uip_ds6_prefix_add(&ipaddr,64,0); */ + } +#endif +/*--------------------------Announce the configuration---------------------*/ +#if ANNOUNCE_BOOT +#if AVR_WEBSERVER + { uint8_t i; + char buf[80]; + unsigned int size; + + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + if(uip_ds6_if.addr_list[i].isused) { + httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf); + PRINTA("IPv6 Address: %s\n", buf); + } + } + cli(); + eeprom_read_block(buf, eemem_server_name, sizeof(eemem_server_name)); + sei(); + buf[sizeof(eemem_server_name)] = 0; + PRINTA("%s", buf); + cli(); + eeprom_read_block(buf, eemem_domain_name, sizeof(eemem_domain_name)); + sei(); + buf[sizeof(eemem_domain_name)] = 0; + size = httpd_fs_get_size(); +#ifndef COFFEE_FILES + PRINTA(".%s online with fixed %u byte web content\n", buf, size); +#elif COFFEE_FILES == 1 + PRINTA(".%s online with static %u byte EEPROM file system\n", buf, size); +#elif COFFEE_FILES == 2 + PRINTA(".%s online with dynamic %u KB EEPROM file system\n", buf, size >> 10); +#elif COFFEE_FILES == 3 + PRINTA(".%s online with static %u byte program memory file system\n", buf, size); +#elif COFFEE_FILES == 4 + PRINTA(".%s online with dynamic %u KB program memory file system\n", buf, size >> 10); +#endif /* COFFEE_FILES */ + } +#else + PRINTA("Online\n"); +#endif +#endif /* ANNOUNCE_BOOT */ + + ledtimer_red = 1000; + leds_on(LEDS_RED); +} + + +#if ROUTES && NETSTACK_CONF_WITH_IPV6 +static void +ipaddr_add(const uip_ipaddr_t *addr) +{ + uint16_t a; + int8_t i, f; + for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { + a = (addr->u8[i] << 8) + addr->u8[i + 1]; + if(a == 0 && f >= 0) { + if(f++ == 0) { + PRINTF("::"); + } + } else { + if(f > 0) { + f = -1; + } else if(i > 0) { + PRINTF(":"); + } + PRINTF("%x", a); + } + } +} +#endif +/*-------------------------------------------------------------------------*/ +/*------------------------- Main Scheduler loop----------------------------*/ +/*-------------------------------------------------------------------------*/ +int +main(void) +{ +#if NETSTACK_CONF_WITH_IPV6 + uip_ds6_nbr_t *nbr; +#endif /* NETSTACK_CONF_WITH_IPV6 */ + initialize(); + + while(1) { + process_run(); + watchdog_periodic(); + + /* Turn off LED's */ + if(ledtimer_red) { + if(--ledtimer_red == 0) { + leds_off(LEDS_RED); + } + } + if(ledtimer_yellow) { + if(--ledtimer_yellow == 0) { + leds_off(LEDS_YELLOW); + } + } + leds_off(LEDS_RED); + leds_off(LEDS_YELLOW); + +#if 0 +/* Various entry points for debugging in the AVR Studio simulator. + * Set as next statement and step into the routine. + */ + NETSTACK_RADIO.send(packetbuf_hdrptr(), 42); + process_poll(&rf230_process); + packetbuf_clear(); + len = rf230_read(packetbuf_dataptr(), PACKETBUF_SIZE); + packetbuf_set_datalen(42); + NETSTACK_RDC.input(); +#endif + +#if 0 +/* Clock.c can trigger a periodic PLL calibration in the RF230BB driver. + * This can show when that happens. + */ + extern uint8_t rf230_calibrated; + if(rf230_calibrated) { + PRINTD("\nRF230 calibrated!\n"); + rf230_calibrated = 0; + } +#endif + +/* Set DEBUGFLOWSIZE in contiki-conf.h to track path through MAC, RDC, and RADIO */ +#if DEBUGFLOWSIZE + if(debugflowsize) { + debugflow[debugflowsize] = 0; + PRINTF("%s", debugflow); + debugflowsize = 0; + } +#endif + +#if PERIODICPRINTS +#if TESTRTIMER +/* Timeout can be increased up to 8 seconds maximum. + * A one second cycle is convenient for triggering the various debug printouts. + * The triggers are staggered to avoid printing everything at once. + */ + if(rtimerflag) { + rtimer_set(&rt, RTIMER_NOW() + RTIMER_ARCH_SECOND * 1UL, 1, (void *)rtimercycle, NULL); + rtimerflag = 0; +#else + if(clocktime != clock_seconds()) { + clocktime = clock_seconds(); +#endif + +#if STAMPS + if((clocktime % STAMPS) == 0) { +#if ENERGEST_CONF_ON +#include "lib/print-stats.h" + print_stats(); +#elif RADIOSTATS + extern volatile unsigned long radioontime; + PRINTF("%u(%u)s\n", clocktime, radioontime); +#else + PRINTF("%us\n", clocktime); +#endif + } +#endif +#if TESTRTIMER + clocktime += 1; +#endif + +#if PINGS && NETSTACK_CONF_WITH_IPV6 + extern void raven_ping6(void); + if((clocktime % PINGS) == 1) { + PRINTF("**Ping\n"); + raven_ping6(); + } +#endif + +#if ROUTES && NETSTACK_CONF_WITH_IPV6 + if((clocktime % ROUTES) == 2) { + + extern uip_ds6_netif_t uip_ds6_if; + + uint8_t i, j; + PRINTF("\nAddresses [%u max]\n", UIP_DS6_ADDR_NB); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + if(uip_ds6_if.addr_list[i].isused) { + ipaddr_add(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + } + } + PRINTF("\nNeighbors [%u max]\n", NBR_TABLE_MAX_NEIGHBORS); + j = 0; + for(nbr = nbr_table_head(ds6_neighbors); + nbr != NULL; + nbr = nbr_table_next(ds6_neighbors, nbr)) { + ipaddr_add(&nbr->ipaddr); + PRINTF("\n"); + j++; + } + if(!j) { + PRINTF(" "); + } + PRINTF("\nRoutes [%u max]\n", UIP_DS6_ROUTE_NB); + { + uip_ds6_route_t *r; + j = 0; + for(r = uip_ds6_route_head(); + r != NULL; + r = uip_ds6_route_next(r)) { + ipaddr_add(&r->ipaddr); + PRINTF("/%u (via ", r->length); + ipaddr_add(uip_ds6_route_nexthop(r)); + PRINTF(") %lus\n", r->state.lifetime); + j++; + } + } + if(!j) { + PRINTF(" "); + } + PRINTF("\n---------\n"); + } +#endif + +#if STACKMONITOR + if((clocktime % STACKMONITOR) == 3) { + extern uint16_t __bss_end; + uint16_t p = (uint16_t)&__bss_end; + do { + if(*(uint16_t *)p != 0x4242) { + PRINTF("Never-used stack > %d bytes\n", p - (uint16_t)&__bss_end); + break; + } + p += 10; + } while(p < RAMEND - 10); + } +#endif + } +#endif /* PERIODICPRINTS */ + +#if RF230BB && 0 + extern uint8_t rf230processflag; + if(rf230processflag) { + PRINTF("rf230p%d", rf230processflag); + rf230processflag = 0; + } +#endif + +#if RF230BB && 0 + extern uint8_t rf230_interrupt_flag; + if(rf230_interrupt_flag) { + /* if (rf230_interrupt_flag!=11) { */ + PRINTF("**RI%u", rf230_interrupt_flag); + /* } */ + rf230_interrupt_flag = 0; + } +#endif + } + return 0; +} +/*---------------------------------------------------------------------------*/ + +void +log_message(char *m1, char *m2) +{ + PRINTF("%s%s\n", m1, m2); +} diff --git a/platform/avr-rss2/dev/adc.c b/platform/avr-rss2/dev/adc.c new file mode 100644 index 000000000..cb82d16b7 --- /dev/null +++ b/platform/avr-rss2/dev/adc.c @@ -0,0 +1,76 @@ +/* Copyright Robert Olsson */ + +#include +#include +#include +#include +#include +#include +#include "params.h" +#include "rss2.h" +#include "contiki.h" +#include "adc.h" +#include "rss2.h" + +uint16_t +adc_read(uint8_t pin) +{ + uint16_t volt = 0; + int i; + + ADMUX = pin; /* ADC pin PA0-PA7 -> 0-7 */ + ADCSRB &= ~(1 << MUX5); /* Needs to write before ADMUX pp 418 */ + ADMUX |= (1 << REFS1) | (1 << REFS0); /* 1.6 */ + + /* Maximal Track and Hold time */ + + ADCSRA = (1 << ADPS2) | (0 << ADPS1) | (1 << ADPS0); /* Prescaler /32 */ + ADCSRA |= (1 << ADEN); /* Enable the ADC */ + + while(!(ADCSRB & (1 << AVDDOK))) ; /* Wait for AVDD ok */ + while(!(ADCSRB & (1 << REFOK))) ; /* Wait for ref ok */ + + /* Ignore first result */ + + ADCSRA |= (1 << ADSC); + while(ADCSRA & _BV(ADSC)) { + } + + ADCW = 0; +#define RES 4 + + for(i = 0; i < RES; i++) { + + /* Start the conversion */ + ADCSRA |= (1 << ADSC); + + /* Wait for conversion */ + while(ADCSRA & (1 << ADSC)) { + } + + volt += ADCW; + } + ADMUX = 0; /* turn off internal vref */ + volt = volt / RES; + + /* Disable the ADC to save power */ + ADCSRA &= ~_BV(ADEN); + + return volt; +} +double +adc_read_v_in(void) +{ + /* Special treatment for v_in. Schottky voltage drop add */ + return ((double)adc_read(AV_IN)) * V_IN_FACTOR_SCHOTTKY + SCHOTTKY_DROP; +} +double +adc_read_a1(void) +{ + return ((double)adc_read(A1)) * V_IN_FACTOR; +} +double +adc_read_a2(void) +{ + return ((double)adc_read(A2)) * V_IN_FACTOR; +} diff --git a/platform/avr-rss2/dev/adc.h b/platform/avr-rss2/dev/adc.h new file mode 100644 index 000000000..9e9473e31 --- /dev/null +++ b/platform/avr-rss2/dev/adc.h @@ -0,0 +1,16 @@ +/* Copyright Robert Olsson */ + +#define V_IN_FACTOR 0.006256 /* 6.4/1023 */ +#define V_IN_FACTOR_NONE 0.001564 /* 1.6/1023 */ +#define SCHOTTKY_DROP 0.29 +#define V_IN_FACTOR_SCHOTTKY 0.0292 /* 30.19-SCHOTTKY_DROP/1023 schottky corr */ + +uint16_t +adc_read(uint8_t pin); +double +adc_read_v_in(void); +double +adc_read_a1(void); +double +adc_read_a2(void); + diff --git a/platform/avr-rss2/dev/battery-sensor.c b/platform/avr-rss2/dev/battery-sensor.c new file mode 100644 index 000000000..b81db95f6 --- /dev/null +++ b/platform/avr-rss2/dev/battery-sensor.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2006, Swedish Institute of Computer Science. + * 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 ADVISE OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + * ----------------------------------------------------------------- + * + * Author : Dag Björklund, Robert Olsson + * Created : 2005-11-01 + * Updated : $Date: 2010/08/25 19:30:52 $ + * $Revision: 1.11 $ + */ + +#include "contiki.h" +#include "dev/battery-sensor.h" +#include +#define delay_us(us) (_delay_loop_2(1 + (us * F_CPU) / 4000000UL)) + +const struct sensors_sensor battery_sensor; + +/* Returns the MCU voltage in mV read from the BATMON MCU register + * See AtMega chip docs for BATMON details. + */ + +static int +value(int type) +{ + uint16_t mv; + int i; + /* Resolution is 75mV if V>=2.55V; and 50mV if V<=2.45V */ + mv = 3675; + + for(i = 0x1f; 1; i--) { + + BATMON = i; + delay_us(100); + if(BATMON & 0x20) { + break; + } + + if(i == 0x10) { /* Range hi or lo */ + mv = 2500; + } + if(i > 0x10) { + mv -= 75; + } else { + mv -= 50; + } + } + return (int)((float)mv); +} +static int +configure(int type, int c) +{ + return 0; +} +static int +status(int type) +{ + return 1; +} +SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status); + diff --git a/platform/avr-rss2/dev/button-sensor.c b/platform/avr-rss2/dev/button-sensor.c new file mode 100644 index 000000000..664278993 --- /dev/null +++ b/platform/avr-rss2/dev/button-sensor.c @@ -0,0 +1,41 @@ +/* Dummy sensor routine */ + +#include "lib/sensors.h" +#include "dev/button-sensor.h" +const struct sensors_sensor button_sensor; +static int status(int type); +struct sensors_sensor *sensors[1]; +unsigned char sensors_flags[1]; + +static int +value(int type) +{ + return 0; +} +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if(c) { + if(!status(SENSORS_ACTIVE)) { + } + } else { + } + return 1; + } + return 0; +} +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return 1; + } + return 0; +} +SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, + value, configure, status); + diff --git a/platform/avr-rss2/dev/co2_sa_kxx-sensor.c b/platform/avr-rss2/dev/co2_sa_kxx-sensor.c new file mode 100644 index 000000000..1866c0f2f --- /dev/null +++ b/platform/avr-rss2/dev/co2_sa_kxx-sensor.c @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2015, Copyright Markus Hidell, Robert Olsson + * 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. + * + * + * Authors : Markus Hidell, Robert Olsson {mahidell, roolss} @kth.se + * Created : 2015-10-27 + * Updated : $Date: 2010/01/14 20:23:02 $ + * $Revision: 1.2 $ + */ + +#include "contiki.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "dev/watchdog.h" +#include "lib/list.h" +#include "lib/memb.h" +#include "co2_sa_kxx-sensor.h" + +static int +status(int type) +{ + return 0; +} +static int +configure(int type, int c) +{ + return 0; +} +static int +value(int var) +{ + int val, status; + uint8_t buf[2], csum; + int16_t res; + (void) status; + (void) csum; + + res = 0; + i2c_start_wait(I2C_CO2SA_ADDR | I2C_WRITE); + if(res) { + goto err; + } + + i2c_write(0x22); + i2c_write(0x00); + + if(var == CO2_SA_KXX_CO2) { + i2c_write(0x08); + i2c_write(0x2A); + } + + if(var == CO2_SA_KXX_TEMP) { + i2c_write(0x12); + i2c_write(0x34); + } + + if(var == CO2_SA_KXX_RH) { + i2c_write(0x14); + i2c_write(0x36); + } + + i2c_stop(); + + if(res) { + goto err; + } + + clock_delay_msec(20); + + res = 0; + i2c_start(I2C_CO2SA_ADDR | I2C_READ); + + if(res) { + goto err; + } + + + status = i2c_readAck(); + + if(status & 0x01 == 0) + goto err; + + buf[0] = i2c_readAck(); + buf[1] = i2c_readAck(); + csum = i2c_readNak(); + i2c_stop(); + + val = ((int16_t)(buf[0] << 8)) | buf[1]; + + return val; + +err: + i2c_stop(); + return 0; +} +SENSORS_SENSOR(co2_sa_kxx_sensor, "CO2", value, configure, status); diff --git a/platform/avr-rss2/dev/co2_sa_kxx-sensor.h b/platform/avr-rss2/dev/co2_sa_kxx-sensor.h new file mode 100644 index 000000000..bdb366fea --- /dev/null +++ b/platform/avr-rss2/dev/co2_sa_kxx-sensor.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, Copyright Markus Hidell, Robert Olsson + * 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. + * + * + * Authors : Markus Hidell, Robert Olsson {mahidell, roolss} @kth.se + * Created : 2015-10-27 + * Updated : $Date: 2010/01/14 20:23:02 $ + * $Revision: 1.2 $ + */ + +#ifndef CO2_SA_KXX_SENSOR_H_ +#define CO2_SA_KXX_SENSOR_H_ + +#define CO2_SA_KXX_CO2 0 +#define CO2_SA_KXX_TEMP 1 +#define CO2_SA_KXX_RH 3 + +#include "lib/sensors.h" + +extern const struct sensors_sensor co2_sa_kxx_sensor; + +#define I2C_CO2SA_ADDR (0x68 << 1) + +#endif /* CO2_SA_KXX-SENSOR_H_ */ diff --git a/platform/avr-rss2/dev/ds18b20.c b/platform/avr-rss2/dev/ds18b20.c new file mode 100644 index 000000000..6044ad91e --- /dev/null +++ b/platform/avr-rss2/dev/ds18b20.c @@ -0,0 +1,247 @@ +/* + + Contiki library for DS18B20 temperature sensor - + For more details see http://xxx + + Author - + Author - + + License - GPLv3 + + */ + +#include "ds18b20.h" + +/* probe_for_ds18b20 probes for the sensor. Returns 0 on failure, 1 on success */ +/* Assumptions: only one sensor on the "1-wire bus", on port WSN_DS18B20_PORT */ +/* BUG: THIS CODE DOES NOT WORK AS INTENDED! IT RETURNS "1" EVEN WHEN THERE IS NO */ +/* SENSOR CONNECTED. */ + +uint8_t +ds18b20_probe(void) +{ + uint8_t result = 0; + + /* Reset 1W-bus */ + + /* Pull PIN low for 480 microseconds (us) */ + /* Start with setting bit DS18B20_1_PIN to 0 */ + OW_SET_PIN_LOW(); + /* then set direction to OUT by setting DS18B20_1_DDR bit to 1 */ + OW_SET_OUTPUT(); + /* Delay 480 us */ + clock_delay_usec(480); + /* See if sensor responds. First release the bus and switch to INput mode */ + /* by setting DS18B20_1_DDR bit to 0 */ + OW_SET_INPUT(); + /* Activate internal pull-up by setting pin to HIGH (when in INput mode) */ + /* OW_SET_PIN_HIGH(); */ + /* Wait for the pin to go HIGH for 64 us */ + clock_delay_usec(64); + /* Now the sensor, if present, pulls the pin LOW for 60-240 us */ + /* Detect 0 on PIND bit DS18B20_1_PIN. Invert the result so a presence (aka a 0) */ + /* sets "result" to 1 (for success) */ + result = !OW_GET_PIN_STATE(); + + /* The sensor releases the pin so it goes HIGH after 240 us, add some */ + /* for the signal to stabilize, say 300 usecs to be on the safe side? */ + if(result) { + clock_delay_usec(300); + /* Now the bus should be HIGH again */ + result = OW_GET_PIN_STATE(); + } + + return result; +} +/* Write 1 or 0 on the bus */ + +void +write_bit(uint8_t bit) +{ + /* Set pin to 0 */ + OW_SET_OUTPUT(); + OW_SET_PIN_LOW(); + + /* Pin should be 0 for at least 1 us */ + clock_delay_usec(2); + + /* If we're writing a 1, let interna pull-up pull the bus high */ + /* within 15 us of setting the bus to low */ + if(bit) { + /* Internal pull-up is activated by setting direction to IN and the */ + /* setting the pin to HIGH */ + OW_SET_INPUT(); + OW_SET_PIN_HIGH(); + } + /* OK, now the bus is either LOW, or pulled HIGH by the internal pull-up */ + /* Let this state remain for 60 us, then release the bus */ + clock_delay_usec(60); + + /* Release the bus */ + OW_SET_PIN_HIGH(); + OW_SET_INPUT(); + + /* Allow > 1 us between read/write operations */ + clock_delay_usec(2); +} +/* */ +/* Read one bit of information from the bus, and return it as 1 or 0 */ +/* */ + +uint8_t +read_bit(void) +{ + uint8_t bit = 0; + + /* Set pin to 0 */ + OW_SET_OUTPUT(); + OW_SET_PIN_LOW(); + + /* Pin should be 0 for at least 1 us */ + clock_delay_usec(2); + + /* Now read the bus, start by setting in/out direction and activating internal */ + /* pull-up resistor */ + OW_SET_INPUT(); + OW_SET_PIN_HIGH(); + + /* ds18b20 either keeps the pin down or releases the bus and the */ + /* bus then goes high because of the interna pull-up resistor */ + /* Check whichever happens before 15 us has passed */ + clock_delay_usec(15 - 2 - 1); + bit = OW_GET_PIN_STATE(); + + /* The complete read cycle must last at least 60 us. We have now spent */ + /* about 14-15 us in delays, so add another delay to reach >= 60 us */ + clock_delay_usec(50); + + /* Release bus */ + OW_SET_PIN_HIGH(); + OW_SET_INPUT(); + + /* Allow > 1 us between read/write operations */ + clock_delay_usec(2); + + return bit ? 1 : 0; +} +/* */ +/* Read one byte of information. A byte is read least significant bit first */ +/* */ + +uint8_t +read_byte(void) +{ + uint8_t result = 0; + uint8_t bit; + int i; + + for(i = 0; i < 8; i++) { + bit = read_bit(); + result += (bit << i); + } + return result; +} +/* */ +/* Write one byte of information. A byte is written least significant bit first */ +/* */ + +void +write_byte(uint8_t byte) +{ + int i; + + for(i = 0; i < 8; i++) { + write_bit((byte >> i) & 1); + } +} +/* */ +/* ds18b20_get_temp returns the temperature in "temp" (in degrees celsius) */ +/* Returns 0 on failure (and then "temp" is left unchanged */ +/* Returns 1 on success, and sets temp */ +/* */ + +uint8_t +ds18b20_get_temp(float *temp) +{ + uint8_t result = 0; + + /* Reset bus by probing. Probe returns 1 on success/presence of sensor */ + if(ds18b20_probe()) { + /* write command "skip rom" since we only have one sensor on the wire! */ + write_byte(DS18B20_COMMAND_SKIP_ROM); + + /* write command to start measurement */ + write_byte(DS18B20_COMMAND_START_CONVERSION); + + /* Wait for conversion to complete */ + /* Conversion is 12-bit by default. */ + /* Since we have external power to the sensor (ie not in "parasitic power" mode) */ + /* the bus is held LOW by the sensor while the conversion is going on, and then HIGH */ + /* when conversion is finished. */ + OW_SET_INPUT(); + int count = 0; + while(!OW_GET_PIN_STATE()) { + clock_delay_msec(10); + count++; + /* Longest conversion time is 750 ms (12-bit resolution) */ + /* So if count > 80 (for a little margin!), we return -274.0 */ + /* which indicates failure to read the temperature. */ + if(count > 80) { + return 0; + } + } + + /* The result is stored in the "scratch pad", a 9 byte memory block. */ + /* The first two bytes are the conversion result. Reading the scratch pad */ + /* can be terminated by sending a reset signal (but we read all 9 bytes) */ + (void)ds18b20_probe(); + write_byte(DS18B20_COMMAND_SKIP_ROM); + write_byte(DS18B20_COMMAND_READ_SCRATCH_PAD); + uint8_t i, sp_arr[9]; + for(i = 0; i < 9; i++) { + sp_arr[i] = read_byte(); + } + + /* Check CRC, if mismatch, return 0 (failure to read temperature) */ + uint8_t crc_cal = crc8_ds18b20(sp_arr, 8); + + if(crc_cal != sp_arr[8]) { + return 0; + } + + /* OK, now decode what the temperature reading is. This code assumes 12-bit resolution, */ + /* so this must be modified if the code is modified to use any other resolution! */ + int16_t temp_res; + uint8_t temp_lsb = sp_arr[0]; + uint8_t temp_msb = sp_arr[1]; + + temp_res = (int16_t)temp_msb << 8 | temp_lsb; + *temp = (float)temp_res * 0.0625; + + result = 1; + } + return result; +} +/* */ +/* crc8 algorithm for ds18b20 */ +/* http://www.miscel.dk/MiscEl/CRCcalculations.html */ +/* */ + +uint8_t +crc8_ds18b20(uint8_t *buf, uint8_t buf_len) +{ + uint8_t result = 0; + uint8_t i, b; + + for(i = 0; i < buf_len; i++) { + result = result ^ buf[i]; + for(b = 1; b < 9; b++) { + if(result & 0x1) { + result = (result >> 1) ^ 0x8C; + } else { + result = result >> 1; + } + } + } + return result; +} diff --git a/platform/avr-rss2/dev/enc28j60_avr.c b/platform/avr-rss2/dev/enc28j60_avr.c new file mode 100644 index 000000000..2bfb49562 --- /dev/null +++ b/platform/avr-rss2/dev/enc28j60_avr.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012-2013, Robert Olsson + * 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. + * + */ + +#include +#include +#include +#include "dev/watchdog.h" +#include "contiki.h" +#include "i2c.h" +#include +#include +#include +#include "enc28j60_avr.h" + +#include +#define delay_us(us) (_delay_loop_2(1 + (us * F_CPU) / 4000000UL)) + +void +enc28j60_arch_spi_init(void) +{ + CS_SPI_DDR |= (1 << SPI_CS); + CS_SPI_PORT |= (1 << SPI_CS); + + SPI_DDR |= (1 << SPI_MOSI) | (1 << SPI_SCK); + SPI_DDR &= ~(1 << SPI_MISO); + SPI_PORT &= ~(1 << SPI_MOSI); + SPI_PORT &= ~(1 << SPI_SCK); + SPCR = (1 << SPE) | (1 << MSTR); + /* SPSR |= (1< + * 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. + * + */ + +#ifndef ENC28J60_AVR_H +#define ENC28J60_AVR_H + +#define SPI_DDR DDRB /* Data Direction Register: Port B */ +#define SPI_PORT PORTB /* Serial Peripheral Interface */ +#define SPI_MOSI 2 /* PB2: Master Out Slave In */ +#define SPI_MISO 3 /* PB3: Master In Slave out */ +#define SPI_SCK 1 /* PB1: Serial Clock */ + +#define CS_SPI_DDR DDRD /* Data Direction Register: Port B */ +#define CS_SPI_PORT PORTD /* Serial Peripheral Interface */ +#define SPI_CS 6 /* PD6: OW2_PIN, Chip Select */ + +/* AVR specific's for enc28j60 */ + +void enc28j60_arch_spi_init(void); +uint8_t enc28j60_arch_spi_write(uint8_t data); +uint8_t enc28j60_arch_spi_read(void); +void enc28j60_arch_spi_select(void); +void enc28j60_arch_spi_deselect(void); + +#endif /* ENC28J60_AVR_H */ diff --git a/platform/avr-rss2/dev/i2c.c b/platform/avr-rss2/dev/i2c.c new file mode 100644 index 000000000..2668aad58 --- /dev/null +++ b/platform/avr-rss2/dev/i2c.c @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * 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. + * + */ + +/** + * \file + * i2c core functions + * \author + * Robert Olsson + */ + +#include +#include +#include +#include +#include "dev/watchdog.h" +#include "contiki.h" +#include "i2c.h" +#include +#include +#include +#include "dev/co2_sa_kxx-sensor.h" + +void +i2c_init(uint32_t speed) +{ + /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ + + TWSR = 0; /* no prescaler */ + TWBR = ((F_CPU / speed) - 16) / 2; /* must be > 10 for stable operation */ +} +uint8_t +i2c_start(uint8_t addr) +{ + uint8_t twst; + uint32_t n; + + /* Send START condition */ + TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); + + /* Wait until transmission completed */ + for(n = 0; n < 100000 && !(TWCR & (1 << TWINT)); n++) { + } + if(n >= 100000) { + return 1; + } + + /* check value of TWI Status Register. Mask prescaler bits. */ + twst = TW_STATUS & 0xF8; + if((twst != TW_START) && (twst != TW_REP_START)) { + return 1; + } + + /* send device address */ + TWDR = addr; + TWCR = (1 << TWINT) | (1 << TWEN); + + /* wail until transmission completed and ACK/NACK has been received */ + for(n = 0; n < 100000 && !(TWCR & (1 << TWINT)); n++) { + } + if(n >= 100000) { + return 1; + } + + /* check value of TWI Status Register. Mask prescaler bits. */ + twst = TW_STATUS & 0xF8; + if((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { + return 1; + } + + return 0; +} +void +i2c_start_wait(uint8_t addr) +{ + uint8_t twst; + while ( 1 ) + { + // send START condition + TWCR = (1< + */ + +#include "contiki.h" + +/* Here we define the i2c address for dev we support */ +#define I2C_AT24MAC_ADDR 0xB0 /* EUI64 ADDR */ +#define I2C_SHT2X_ADDR (0x40 << 1) /* SHT2X ADDR */ + + +/* Here we define a enumration for devices */ +#define I2C_AT24MAC (1<<0) +#define I2C_SHT2X (1<<1) +#define I2C_CO2SA (1<<2) /* Sense-Air CO2 */ + +#define I2C_READ 1 +#define I2C_WRITE 0 + +void i2c_init(uint32_t speed); +uint8_t i2c_start(uint8_t addr); +void i2c_start_wait(uint8_t addr); +void i2c_stop(void); +void i2c_write(uint8_t u8data); +uint8_t i2c_readAck(void); +uint8_t i2c_readNak(void); +uint8_t i2c_getstatus(void); +uint16_t i2c_probe(void); +void i2c_read_mem(uint8_t addr, uint8_t reg, uint8_t buf[], uint8_t bytes); +void i2c_write_mem(uint8_t addr, uint8_t reg, uint8_t value); +void i2c_at24mac_read(char *buf, uint8_t eui64); +extern uint16_t i2c_probed; /* i2c devices we have probed */ diff --git a/platform/avr-rss2/dev/leds.c b/platform/avr-rss2/dev/leds.c new file mode 100644 index 000000000..c59f9d09f --- /dev/null +++ b/platform/avr-rss2/dev/leds.c @@ -0,0 +1,45 @@ +#include +#include "rss2.h" +#include "leds.h" + +void +leds_init(void) +{ + DDRE |= (1 << LED_RED); + DDRE |= (1 << LED_YELLOW); + /* Off */ + leds_off(LEDS_ALL); +} +void +leds_on(unsigned char ledv) +{ + if(ledv & LEDS_YELLOW) { + PORTE &= ~(1 << LED_YELLOW); + } + if(ledv & LEDS_RED) { + PORTE &= ~(1 << LED_RED); + } +} +void +leds_off(unsigned char ledv) +{ + if(ledv & LEDS_YELLOW) { + PORTE |= (1 << LED_YELLOW); + } + if(ledv & LEDS_RED) { + PORTE |= (1 << LED_RED); + } +} +void +leds_toggle(unsigned char ledv) +{ +} +void +leds_invert(unsigned char ledv) +{ +} +unsigned char +leds_get(void) +{ + return 0; +} diff --git a/platform/avr-rss2/dev/leds.h b/platform/avr-rss2/dev/leds.h new file mode 100644 index 000000000..6dee358c8 --- /dev/null +++ b/platform/avr-rss2/dev/leds.h @@ -0,0 +1,17 @@ + +#ifndef CONTIKI_LED_H_ +#define CONTIKI_LED_H_ + +#define LEDS_GREEN 1 +#define LEDS_YELLOW 2 +#define LEDS_RED 4 +#define LEDS_ALL 7 + +void leds_init(void); /* Initialize the LEDs driver. */ +unsigned char leds_get(void); /* Get the status of a LED. */ +void leds_on(unsigned char ledv); /* Turn on a set of LEDs. */ +void leds_off(unsigned char ledv); /* Turn off a set of LEDs. */ +void leds_toggle(unsigned char ledv); /* Toggle a set of LEDs. */ +void leds_invert(unsigned char ledv); /* Toggle a set of LEDs. */ + +#endif /* CONTIKI_LED_H_ */ diff --git a/platform/avr-rss2/dev/light-sensor.c b/platform/avr-rss2/dev/light-sensor.c new file mode 100644 index 000000000..cbb0a93f7 --- /dev/null +++ b/platform/avr-rss2/dev/light-sensor.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson + * 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. + * + */ + +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/light-sensor.h" +#include "rss2.h" +#include "adc.h" + +const struct sensors_sensor light_sensor; + +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return adc_read(A3); +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + DDRF &= ~(1 << A3); /* Light sensor */ + DDRF &= ~(1 << A3_PWR); + + PORTF |= (1 << A3_PWR); /* Light sensor */ + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(light_sensor, "Light", value, configure, status); diff --git a/platform/avr-rss2/dev/light-sensor.h b/platform/avr-rss2/dev/light-sensor.h new file mode 100644 index 000000000..da26c724e --- /dev/null +++ b/platform/avr-rss2/dev/light-sensor.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson + * 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. + * + * + * Author : Robert Olsson + * Created : 2015-10-27 + * Updated : $Date: 2010/01/14 20:23:02 $ + * $Revision: 1.2 $ + */ + +#ifndef LIGHT_SENSOR_H_ +#define LIGHT_SENSOR_H_ + +#include "lib/sensors.h" + +extern const struct sensors_sensor light_sensor; + +#endif /* LIGHT-SENSOR_H_ */ diff --git a/platform/avr-rss2/dev/pulse-sensor.c b/platform/avr-rss2/dev/pulse-sensor.c new file mode 100644 index 000000000..eb0f3a842 --- /dev/null +++ b/platform/avr-rss2/dev/pulse-sensor.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/pulse-sensor.h" +#include "rss2.h" + +const struct sensors_sensor pulse_sensor; + +#define NP 2 + +uint32_t volatile pc[NP]; + +/* + * Note interrupt sources can be woken up from sleep mode PWR_SAVE + * Two interrupt ports, #0 green terminal block. #1 pin header via + * a comparator. + */ + +static void +port_irq_ctrl(uint8_t on) +{ + if(on) { + + DDRD &= ~(1 << PD2); + PORTD &= ~(1 << PD2); + EIMSK = 0; + EICRA |= 0x20; /* Falling edge INT2 */ + EIMSK |= (1 << PD2); /* Enable interrupt for pin */ + + /* p1 port */ + DDRD &= ~(1 << PD3); + PORTD &= ~(1 << PD3); + EIMSK |= (1 << PD3); /* Enable interrupt for pin */ + EICRA |= 0x80; /* Falling edge */ + PCICR |= (1 << PCIE0); /* And enable irq PCINT 7:0 */ + } else { + EICRA = 0; + PORTD |= (1 << PD2); + EIMSK &= ~(1 << PD2); /* Disable interrupt for pin */ + + PORTD |= (1 << PD3); + EIMSK &= ~(1 << PD3); /* Disable interrupt for pin */ + } +} +ISR(INT2_vect) +{ + if(!(PCICR & (1 << PCIE0))) { + return; + } + pc[0]++; +} + +ISR(INT3_vect) +{ + if(!(PCICR & (1 << PCIE0))) { + return; + } + pc[1]++; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + if(type == 0) { + return (int)pc[0]; + } + if(type == 1) { + return (int)pc[1]; + } + return -1; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + port_irq_ctrl(1); /* Enable pulse counts */ + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(pulse_sensor, "Pulse", value, configure, status); diff --git a/platform/avr-rss2/dev/pulse-sensor.h b/platform/avr-rss2/dev/pulse-sensor.h new file mode 100644 index 000000000..03a09cd1b --- /dev/null +++ b/platform/avr-rss2/dev/pulse-sensor.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +#ifndef PULSE_SENSOR_H_ +#define PULSE_SENSOR_H_ + +#include "lib/sensors.h" + +extern const struct sensors_sensor pulse_sensor; + +#endif /* PULSE-SENSOR_H_ */ diff --git a/platform/avr-rss2/dev/temp-sensor.c b/platform/avr-rss2/dev/temp-sensor.c new file mode 100644 index 000000000..5bc108c7e --- /dev/null +++ b/platform/avr-rss2/dev/temp-sensor.c @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2015, Copyright Per Lindgren + * 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. + * + * + * Author : Per Lindgren + * Hacked by: Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +#include "contiki.h" +#include "dev/temp-sensor.h" +#include +#define delay_us(us) (_delay_loop_2(1 + (us * F_CPU) / 4000000UL)) + +const struct sensors_sensor temp_mcu_sensor; + +/* probe_for_ds18b20 probes for the sensor. Returns 0 on failure, 1 on success + * Assumptions: only one sensor on the "1-wire bus", on port WSN_DS18B20_PORT + * BUG: THIS CODE DOES NOT WORK AS INTENDED! IT RETURNS "1" EVEN WHEN THERE + * IS NO SENSOR CONNECTED. + */ + +uint8_t +ds18b20_probe(void) +{ + uint8_t result = 0; + + /* Reset 1W-bus */ + + /* Pull PIN low for 480 microseconds (us) + * Start with setting bit DS18B20_1_PIN to 0 */ + OW_SET_PIN_LOW(); + /* then set direction to OUT by setting DS18B20_1_DDR bit to 1 */ + OW_SET_OUTPUT(); + /* Delay 480 us */ + clock_delay_usec(480); + /* See if sensor responds. First release the bus and switch to INput mode + * by setting DS18B20_1_DDR bit to 0 */ + OW_SET_INPUT(); + /* Activate internal pull-up by setting pin to HIGH (when in INput mode) + * OW_SET_PIN_HIGH(); + * Wait for the pin to go HIGH for 64 us */ + clock_delay_usec(64); + /* Now the sensor, if present, pulls the pin LOW for 60-240 us + * Detect 0 on PIND bit DS18B20_1_PIN. Invert the result so a presence + * (aka * a 0) sets "result" to 1 (for success) */ + result = !OW_GET_PIN_STATE(); + + /* The sensor releases the pin so it goes HIGH after 240 us, add some + for the signal to stabilize, say 300 usecs to be on the safe side? */ + if(result) { + clock_delay_usec(300); + /* Now the bus should be HIGH again */ + result = OW_GET_PIN_STATE(); + } + return result; +} +/* Write 1 or 0 on the bus */ + +void +write_bit(uint8_t bit) +{ + /* Set pin to 0 */ + OW_SET_OUTPUT(); + OW_SET_PIN_LOW(); + + /* Pin should be 0 for at least 1 us */ + clock_delay_usec(2); + + /* If we're writing a 1, let interna pull-up pull the bus high + * within 15 us of setting the bus to low */ + if(bit) { + /* Internal pull-up is activated by setting direction to IN and the + * setting the pin to HIGH */ + OW_SET_INPUT(); + OW_SET_PIN_HIGH(); + } + /* OK, now the bus is either LOW, or pulled HIGH by the internal pull-up + * Let this state remain for 60 us, then release the bus */ + clock_delay_usec(60); + + /* Release the bus */ + OW_SET_PIN_HIGH(); + OW_SET_INPUT(); + + /* Allow > 1 us between read/write operations */ + clock_delay_usec(2); +} +/* Read one bit of information from the bus, and return it as 1 or 0 */ + +uint8_t +read_bit(void) +{ + uint8_t bit = 0; + + /* Set pin to 0 */ + OW_SET_OUTPUT(); + OW_SET_PIN_LOW(); + + /* Pin should be 0 for at least 1 us */ + clock_delay_usec(2); + + /* Now read the bus, start by setting in/out direction and activating + * internal pull-up resistor */ + OW_SET_INPUT(); + OW_SET_PIN_HIGH(); + + /* ds18b20 either keeps the pin down or releases the bus and the + * bus then goes high because of the interna pull-up resistor + * Check whichever happens before 15 us has passed */ + clock_delay_usec(15 - 2 - 1); + bit = OW_GET_PIN_STATE(); + + /* The complete read cycle must last at least 60 us. We have now spent + * about 14-15 us in delays, so add another delay to reach >= 60 us */ + clock_delay_usec(50); + + /* Release bus */ + OW_SET_PIN_HIGH(); + OW_SET_INPUT(); + + /* Allow > 1 us between read/write operations */ + clock_delay_usec(2); + + return bit ? 1 : 0; +} +/* Read one byte of information. A byte is read least significant bit first */ + +uint8_t +read_byte(void) +{ + uint8_t result = 0; + uint8_t bit; + int i; + + for(i = 0; i < 8; i++) { + bit = read_bit(); + result += (bit << i); + } + return result; +} +/* Write one byte of information. A byte is written least significant bit first */ + +void +write_byte(uint8_t byte) +{ + int i; + + for(i = 0; i < 8; i++) { + write_bit((byte >> i) & 1); + } +} +/* ds18b20_get_temp returns the temperature in "temp" (in degrees celsius) + * Returns 0 on failure (and then "temp" is left unchanged + * Returns 1 on success, and sets temp */ + +uint8_t +ds18b20_get_temp(double *temp) +{ + uint8_t result = 0; + + /* Reset bus by probing. Probe returns 1 on success/presence of sensor */ + if(ds18b20_probe()) { + /* write command "skip rom" since we only have one sensor on the wire! */ + write_byte(DS18B20_COMMAND_SKIP_ROM); + + /* write command to start measurement */ + write_byte(DS18B20_COMMAND_START_CONVERSION); + + /* Wait for conversion to complete. Conversion is 12-bit by default. + * Since we have external power to the sensor (ie not in "parasitic power" + * mode) the bus is held LOW by the sensor while the conversion is going + * on, and then HIGH when conversion is finished. */ + OW_SET_INPUT(); + int count = 0; + while(!OW_GET_PIN_STATE()) { + clock_delay_msec(10); + count++; + /* Longest conversion time is 750 ms (12-bit resolution) + * So if count > 80 (for a little margin!), we return -274.0 + * which indicates failure to read the temperature. */ + if(count > 80) { + return 0; + } + } + + /* The result is stored in the "scratch pad", a 9 byte memory block. + * The first two bytes are the conversion result. Reading the scratch pad + * can be terminated by sending a reset signal (but we read all 9 bytes) */ + (void)ds18b20_probe(); + write_byte(DS18B20_COMMAND_SKIP_ROM); + write_byte(DS18B20_COMMAND_READ_SCRATCH_PAD); + uint8_t i, sp_arr[9]; + for(i = 0; i < 9; i++) { + sp_arr[i] = read_byte(); + } + + /* Check CRC, if mismatch, return 0 (failure to read temperature) */ + uint8_t crc_cal = crc8_ds18b20(sp_arr, 8); + + if(crc_cal != sp_arr[8]) { + return 0; + } + + /* OK, now decode what the temperature reading is. This code assumes + * 12-bit resolution, so this must be modified if the code is modified + * to use any other resolution! */ + int16_t temp_res; + uint8_t temp_lsb = sp_arr[0]; + uint8_t temp_msb = sp_arr[1]; + + temp_res = (int16_t)temp_msb << 8 | temp_lsb; + *temp = (double)temp_res * 0.0625; + + result = 1; + } + return result; +} +/* crc8 algorithm for ds18b20 */ +/* http://www.miscel.dk/MiscEl/CRCcalculations.html */ + +uint8_t +crc8_ds18b20(uint8_t *buf, uint8_t buf_len) +{ + uint8_t result = 0; + uint8_t i, b; + + for(i = 0; i < buf_len; i++) { + result = result ^ buf[i]; + for(b = 1; b < 9; b++) { + if(result & 0x1) { + result = (result >> 1) ^ 0x8C; + } else { + result = result >> 1; + } + } + } + return result; +} +static int +value(int type) +{ + double t; + int ret; + ret = ds18b20_get_temp(&t); + + /* Return temp multiplied by 100 for two decimals */ + if(ret) + return (int) (t * 100); + + /* Error return largest negative value */ + return 0x8000; +} +static int +configure(int type, int c) +{ + ds18b20_probe(); + return 0; +} +static int +status(int type) +{ + return 1; +} +SENSORS_SENSOR(temp_sensor, TEMP_SENSOR, value, configure, status); diff --git a/platform/avr-rss2/dev/temp-sensor.h b/platform/avr-rss2/dev/temp-sensor.h new file mode 100644 index 000000000..b5ab53659 --- /dev/null +++ b/platform/avr-rss2/dev/temp-sensor.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Copyright Per Lindgren + * 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. + * + * + * Author : Per Lindgren + * Hacked by: Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +#ifndef TEMP_SENSOR_H_ +#define TEMP_SENSOR_H_ + +#include "lib/sensors.h" +#include +#include "contiki.h" +#include "rss2.h" + +#define DS18B20_1_PIN OW_BUS_0 +#define DS18B20_1_IN PIND +#define DS18B20_1_OUT PORTD +#define DS18B20_1_DDR DDRD + +#define OW_SET_PIN_LOW() (DS18B20_1_OUT &= ~(1 << DS18B20_1_PIN)) +#define OW_SET_PIN_HIGH() (DS18B20_1_OUT |= (1 << DS18B20_1_PIN)) +#define OW_SET_OUTPUT() (DS18B20_1_DDR |= (1 << DS18B20_1_PIN)) +#define OW_SET_INPUT() (DS18B20_1_DDR &= ~(1 << DS18B20_1_PIN)) +#define OW_GET_PIN_STATE() ((DS18B20_1_IN & (1 << DS18B20_1_PIN)) ? 1 : 0) + +#define DS18B20_COMMAND_READ_SCRATCH_PAD 0xBE +#define DS18B20_COMMAND_START_CONVERSION 0x44 +#define DS18B20_COMMAND_SKIP_ROM 0xCC + +/* probe_for_ds18b20 probes for the sensor. Returns 0 on failure, 1 on success + * Assumption: only one sensor on the "1-wire bus", on port DS18B20_1_PIN */ + +extern uint8_t ds18b20_probe(void); +extern uint8_t ds18b20_get_temp(double *temp); +extern uint8_t crc8_ds18b20(uint8_t *buf, uint8_t buf_len); + +extern const struct sensors_sensor temp_sensor; + +#define TEMP_SENSOR "temp" + +#endif /* TEMP_SENSOR_H_ */ diff --git a/platform/avr-rss2/dev/temp_mcu-sensor.c b/platform/avr-rss2/dev/temp_mcu-sensor.c new file mode 100644 index 000000000..cfa21707d --- /dev/null +++ b/platform/avr-rss2/dev/temp_mcu-sensor.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2006, Swedish Institute of Computer Science. + * 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 ADVISE OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + * ----------------------------------------------------------------- + * + * Author : Robert Olsson + * Created : 2015-10-27 + * Updated : $Date: 2010/08/25 19:30:52 $ + * $Revision: 1.11 $ + */ + +#include "contiki.h" +#include "dev/temp_mcu-sensor.h" +#include +#define delay_us(us) (_delay_loop_2(1 + (us * F_CPU) / 4000000UL)) + +const struct sensors_sensor temp_mcu_sensor; + +/* Returns the MCU temp in C*10 read from the BATMON MCU register + * See AtMega chip docs for BATMON details. + */ + +static int +value(int type) +{ + uint16_t v; + + ADCSRB |= (1 << MUX5); /* this bit buffered till ADMUX written to! */ + ADMUX = 0xc9; + + /* ADC on /32 ADC start */ + ADCSRA = (1 << ADPS2) | (0 << ADPS1) | (1 << ADPS0); + ADCSRA |= (1 << ADEN); /* Enable the ADC */ + + while(!(ADCSRB & (1 << AVDDOK))) ; /* Wait for AVDD ok */ + while(!(ADCSRB & (1 << REFOK))) ; /* Wait for ref ok */ + + ADCSRA |= (1 << ADSC); /* Throwaway conversion */ + while + (ADCSRA & (1 << ADSC)) ; + + ADCSRA |= (1 << ADSC); /* Start conversion */ + while + (ADCSRA & (1 << ADSC)) ; + + v = ADC; + + /* Disable the ADC to save power */ + ADCSRA &= ~_BV(ADEN); + /* ADMUX = 0; //turn off internal vref */ + return (int)((double)(v * 1.13 - 272.8) * 10); +} +static int +configure(int type, int c) +{ + return 0; +} +static int +status(int type) +{ + return 1; +} +SENSORS_SENSOR(temp_mcu_sensor, TEMP_MCU_SENSOR, value, configure, status); + diff --git a/platform/avr-rss2/dev/temp_mcu-sensor.h b/platform/avr-rss2/dev/temp_mcu-sensor.h new file mode 100644 index 000000000..c311fdb16 --- /dev/null +++ b/platform/avr-rss2/dev/temp_mcu-sensor.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2006, Swedish Institute of Computer Science. + * 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. + * + * + * ----------------------------------------------------------------- + * + * Author : Robert Olsson + * Created : 2015-10-27 + * Updated : $Date: 2007/11/13 20:36:40 $ + * $Revision: 1.1 $ + */ + +#ifndef TEMP_MCU_SENSOR_H_ +#define TEMP_MCU_SENSOR_H_ + +#include "lib/sensors.h" + +extern const struct sensors_sensor temp_mcu_sensor; + +#define TEMP_MCU_SENSOR "temp_mcu" + +#endif /* TEMP_MCU_SENSOR_H_ */ diff --git a/platform/avr-rss2/examples/avr_radio_power/AtMega256RFR2-summary-power.dat b/platform/avr-rss2/examples/avr_radio_power/AtMega256RFR2-summary-power.dat new file mode 100644 index 000000000..bc4e1f0cc --- /dev/null +++ b/platform/avr-rss2/examples/avr_radio_power/AtMega256RFR2-summary-power.dat @@ -0,0 +1,25 @@ + +# Atmega256RFR2 @ 20C, UNT-61E, RSS2 Mote 2015-12-30 +# TX-PWR RPC=0x0 vs RPC=0xFF. Current mA +# +15 14.6 11.8 +14 15.0 12.1 +13 15.3 12.5 +12 15.6 12.8 +11 15.9 13.1 +10 16.1 13.4 + 9 16.3 13.7 + 8 16.5 13.8 + 7 16.7 13.9 + 6 16.9 14.0 + 5 17.0 14.2 + 4 17.2 14.3 + 3 17.2 14.5 + 2 17.2 14.6 + 1 17.3 14.6 + 0 17.4 14.5 +RX 13.7 7.3 +IDLE 0 0 + + + diff --git a/platform/avr-rss2/examples/avr_radio_power/Makefile b/platform/avr-rss2/examples/avr_radio_power/Makefile new file mode 100644 index 000000000..fb9b062a1 --- /dev/null +++ b/platform/avr-rss2/examples/avr_radio_power/Makefile @@ -0,0 +1,9 @@ +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" + +CONTIKI_PROJECT = avr_radio_power +APPS+=powertrace +all: $(CONTIKI_PROJECT) + +CONTIKI = ../../../.. +CONTIKI_WITH_RIME = 1 +include $(CONTIKI)/Makefile.include diff --git a/platform/avr-rss2/examples/avr_radio_power/README.md b/platform/avr-rss2/examples/avr_radio_power/README.md new file mode 100644 index 000000000..745a31790 --- /dev/null +++ b/platform/avr-rss2/examples/avr_radio_power/README.md @@ -0,0 +1,79 @@ +avr_radio_power +=============== + +Motivation +----------- +Spins over different radio seting for the Atmel radio. The motivation is to +get understanding and also to get correct data for avrora and Contiki + simulations. Program loops over different TX-power setting and measures +RX consumption also radio off and idle power use in SLEEP_MODE_PWR_SAVE is +measured. Program disables radio duty cycling (RDC) and sets MCU in deep +sleep mode to only get radio consumption. + +Usage +----- +The different setting is printed on the terminal. You need a way to measure +the current consumption and relate to the tests. + +Example +------- +Program printout with added measurements. The used board was RSS2 mote +with a AtMega256RFR2 CPU. Max is when 0xFF is written to the RPC register. + + +Run/setup Current use +------------------------------------------------ +TX with PWR=0 RPC=0x00 17.80 mA (MAX TX-pwr) +TX with PWR=1 RPC=0x00 17.74 +TX with PWR=2 RPC=0x00 +TX with PWR=3 RPC=0x00 +TX with PWR=4 RPC=0x00 +TX with PWR=5 RPC=0x00 17.43 +TX with PWR=6 RPC=0x00 +TX with PWR=7 RPC=0x00 +TX with PWR=8 RPC=0x00 +TX with PWR=9 RPC=0x00 17.68 +TX with PWR=10 RPC=0x00 +TX with PWR=11 RPC=0x00 +TX with PWR=12 RPC=0x00 +TX with PWR=13 RPC=0x00 +TX with PWR=14 RPC=0x00 +TX with PWR=15 RPC=0x00 +RX with RPC=0x00 -------------------- 13.43 (RX) + +------------------------------------------------- +TX with PWR=0 RPC=0xff 14.63 mA (MAX TX-pwr) +TX with PWR=1 RPC=0xff +TX with PWR=2 RPC=0xff +TX with PWR=3 RPC=0xff +TX with PWR=4 RPC=0xff +TX with PWR=5 RPC=0xff +TX with PWR=6 RPC=0xff 14.45 +TX with PWR=7 RPC=0xff +TX with PWR=8 RPC=0xff +TX with PWR=9 RPC=0xff +TX with PWR=10 RPC=0xff +TX with PWR=11 RPC=0xff +TX with PWR=12 RPC=0xff +TX with PWR=13 RPC=0xff +TX with PWR=14 RPC=0xff +TX with PWR=15 RPC=0xff +RX with RPC=0xFF -------------------- 7.11 (RX) + +RX radio off 0.001 mA + + +Comments +-------- +We see TX consumption decreases from 17.80 to 14.63 mA using Max RPC (0xFF). +NOTE! For RX 13.43 to 7.11 mA. Nice. This actual measurements. +The avr-rss2 port adds support for the AtMegaXXXRFR2 including the new RPC +function. + + +References +---------- +Atmel application note. AT02594: Smart Reduced Power Consumption Techniques +[Here] (http://www.atmel.com/images/atmel-42356-smart-reduced-power-consumption-techniques_applicationnote_at02594.pdf) + +Multimeter UNI-T UT61E with USB-logging. \ No newline at end of file diff --git a/platform/avr-rss2/examples/avr_radio_power/avr_radio_power.c b/platform/avr-rss2/examples/avr_radio_power/avr_radio_power.c new file mode 100644 index 000000000..5be61d8bd --- /dev/null +++ b/platform/avr-rss2/examples/avr_radio_power/avr_radio_power.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-12-30 + */ + +/** + * \file + * An application for monitoring current use on Atmel + * radios also supporting the RPC function on RFR2 chips. + * Current needs to be measured with amp-meter. + */ + +#include "contiki.h" +#include "net/rime/rime.h" +#include "powertrace.h" +#include +#include "dev/leds.h" +#include "rf230bb.h" +#include "net/packetbuf.h" +#include "net/rime/rimestats.h" +#include "net/netstack.h" +#include +#include + +#define TEST_PERIOD 6 + +static int ps = 0; /* Power-save false */ +static char buf[110]; +static struct etimer et; + +PROCESS(power_use_process, "Power use test"); +PROCESS(sleep_process, "Sleep process"); +AUTOSTART_PROCESSES(&power_use_process, &sleep_process); + +static void +broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) +{ + printf("broadcast message received from %d.%d: '%s'\n", + from->u8[0], from->u8[1], (char *)packetbuf_dataptr()); +} + +static const struct broadcast_callbacks broadcast_call = {broadcast_recv}; +static struct broadcast_conn broadcast; + + +PROCESS_THREAD(power_use_process, ev, data) +{ + static int i, j; + PROCESS_EXITHANDLER(broadcast_close(&broadcast);) + PROCESS_BEGIN(); + + /* powertrace_start(CLOCK_SECOND * 2); */ + broadcast_open(&broadcast, 129, &broadcast_call); + leds_init(); + rf230_set_channel(25); + + for(i=0; i < 2; i++) { /* Loop over min and max rpc settings */ + + NETSTACK_RADIO.off(); /* Radio off for rpc change */ + NETSTACK_RADIO.off(); + etimer_set(&et, CLOCK_SECOND * 8); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + if(i == 0) + rf230_set_rpc(0x0); /* Disbable all RPC features */ + else + rf230_set_rpc(0xFF); /* Enable all RPC features. Only XRFR2 radios */ + NETSTACK_RADIO.on(); + + /* Loop over the different TX power settings 0-15 */ + + for(j=15; j >= 0; j--) { + NETSTACK_RADIO.on(); + rf230_set_txpower(j); + ps = 0; + printf("TX with PWR=%d RPC=0x%02x\n", rf230_get_txpower(), rf230_get_rpc()); + ps = 1; + + etimer_set(&et, CLOCK_SECOND * TEST_PERIOD); + + while(1) { + if(etimer_expired(&et)) + break; + packetbuf_copyfrom(buf, sizeof(buf)); /* Dummy data */ + broadcast_send(&broadcast); + PROCESS_PAUSE(); + //leds_on(LEDS_RED); + } + /* Barrier so we can see next run */ + NETSTACK_RADIO.off(); + etimer_set(&et, CLOCK_SECOND * TEST_PERIOD); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + } + + /* RX */ + NETSTACK_RADIO.on(); + ps = 0; + printf("RX radio on RPC=0x%02x\n", rf230_get_rpc()); + ps = 1; + etimer_set(&et, CLOCK_SECOND * TEST_PERIOD); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + NETSTACK_RADIO.off(); + } + + /* Last just RX OFF*/ + ps = 0; + printf("RX radio off\n"); + ps = 1; + etimer_set(&et, CLOCK_SECOND * TEST_PERIOD); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + + PROCESS_END(); +} + +/* Sleep process is just put MCU in sleep so we minimiza MCU impact */ +PROCESS_THREAD(sleep_process, ev, data) +{ + PROCESS_BEGIN(); + while(1) { + watchdog_periodic(); + if(ps) + set_sleep_mode(SLEEP_MODE_PWR_SAVE); + else + set_sleep_mode(SLEEP_MODE_IDLE); + cli(); + sleep_enable(); + sei(); + sleep_cpu(); + sleep_disable(); + sei(); + PROCESS_PAUSE(); + } + PROCESS_END(); +} + diff --git a/platform/avr-rss2/examples/avr_radio_power/project-conf.h b/platform/avr-rss2/examples/avr_radio_power/project-conf.h new file mode 100644 index 000000000..8d1bc434f --- /dev/null +++ b/platform/avr-rss2/examples/avr_radio_power/project-conf.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +/** + * \file + * Project specific configuration defines for example + * + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_MAC nullmac_driver + +//#define NETSTACK_CONF_MAC csma_driver +//#define NETSTACK_CONF_RDC contikimac_driver + +#endif /* PROJECT_CONF_H_ */ diff --git a/platform/avr-rss2/examples/hello-sensors/Makefile b/platform/avr-rss2/examples/hello-sensors/Makefile new file mode 100644 index 000000000..c6e0da805 --- /dev/null +++ b/platform/avr-rss2/examples/hello-sensors/Makefile @@ -0,0 +1,19 @@ +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" +CONTIKI_PROJECT = hello-sensors +all: $(CONTIKI_PROJECT) + +# We use floating vars. Add library. +PRINTF_LIB_FLT = -Wl,-u,vfprintf -lprintf_flt -lm +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min +PRINTF_LIB = $(PRINTF_LIB_FLT) +CLIBS = $(PRINTF_LIB) + + +CUSTOM_RULE_LINK = 1 +%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a + $(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ $(CLIBS) + + + +CONTIKI = ../../../.. +include $(CONTIKI)/Makefile.include diff --git a/platform/avr-rss2/examples/hello-sensors/README.md b/platform/avr-rss2/examples/hello-sensors/README.md new file mode 100644 index 000000000..9b204a2a6 --- /dev/null +++ b/platform/avr-rss2/examples/hello-sensors/README.md @@ -0,0 +1,11 @@ +Hello-sensors +============= + +Simple demo to read out sensors from the RSS2 mote. + +Demo uses double which has the same size as float on Atmel. We sacrifice +some bytes for this. + +Build +----- +make TARGET=avr-rss2 diff --git a/platform/avr-rss2/examples/hello-sensors/hello-sensors.c b/platform/avr-rss2/examples/hello-sensors/hello-sensors.c new file mode 100644 index 000000000..42be6109e --- /dev/null +++ b/platform/avr-rss2/examples/hello-sensors/hello-sensors.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +/** + * \file + * A simple application showing sensor reading on RSS2 mote + */ + +#include "contiki.h" +#include "sys/etimer.h" +#include +#include "adc.h" +#include "i2c.h" +#include "dev/leds.h" +#include "dev/battery-sensor.h" +#include "dev/temp-sensor.h" +#include "dev/temp_mcu-sensor.h" +#include "dev/light-sensor.h" +#include "dev/pulse-sensor.h" +#ifdef CO2 +#include "dev/co2_sa_kxx-sensor.h" +#endif +/*---------------------------------------------------------------------------*/ +PROCESS(hello_sensors_process, "Hello sensor process"); +AUTOSTART_PROCESSES(&hello_sensors_process); + +static struct etimer et; + +static void +read_values(void) +{ + char serial[16]; + + int i; + + /* Read out mote unique 128 bit ID */ + i2c_at24mac_read((char *) &serial, 0); + printf("128_bit_ID="); + for(i=0; i < 15; i++) + printf("%02x", serial[i]); + printf("%02x\n", serial[15]); + printf("T=%-5.2f", ((double) temp_sensor.value(0)/100.)); + printf(" V_MCU=%-3.1f", ((double) battery_sensor.value(0))/1000.); + printf(" V_IN=%-4.2f", adc_read_v_in()); + printf(" V_AD1=%-4.2f", adc_read_a1()); + printf(" V_AD2=%-4.2f", adc_read_a2()); + printf(" T_MCU=%-4.1f", ((double) temp_mcu_sensor.value(0)/10.)); + printf(" LIGHT=%-d", light_sensor.value(0)); + printf(" PULSE_0=%-d", pulse_sensor.value(0)); + printf(" PULSE_1=%-d", pulse_sensor.value(1)); +#ifdef CO2 + printf(" CO2=%-d", co2_sa_kxx_sensor.value( CO2_SA_KXX_CO2)); +#endif + printf("\n"); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(hello_sensors_process, ev, data) +{ + PROCESS_BEGIN(); + + SENSORS_ACTIVATE(temp_sensor); + SENSORS_ACTIVATE(battery_sensor); + SENSORS_ACTIVATE(temp_mcu_sensor); + SENSORS_ACTIVATE(light_sensor); + SENSORS_ACTIVATE(pulse_sensor); +#ifdef CO2 + SENSORS_ACTIVATE(co2_sa_kxx_sensor); +#endif + leds_init(); + leds_on(LEDS_RED); + leds_on(LEDS_YELLOW); + + /* + * Delay 5 sec + * Gives a chance to trigger some pulses + */ + + etimer_set(&et, CLOCK_SECOND * 5); + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + read_values(); + etimer_reset(&et); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/hello-sensors/project-conf.h b/platform/avr-rss2/examples/hello-sensors/project-conf.h new file mode 100644 index 000000000..8d1bc434f --- /dev/null +++ b/platform/avr-rss2/examples/hello-sensors/project-conf.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-11-22 + */ + +/** + * \file + * Project specific configuration defines for example + * + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_MAC nullmac_driver + +//#define NETSTACK_CONF_MAC csma_driver +//#define NETSTACK_CONF_RDC contikimac_driver + +#endif /* PROJECT_CONF_H_ */ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/Makefile b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/Makefile new file mode 100644 index 000000000..9d8bccece --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/Makefile @@ -0,0 +1,49 @@ +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" + +all: coap-client coap-server +APPS=servreg-hack +CONTIKI=../../../../.. + +ifdef WITH_COMPOWER +APPS+=powertrace +CFLAGS+= -DCONTIKIMAC_CONF_COMPOWER=1 -DWITH_COMPOWER=1 -DQUEUEBUF_CONF_NUM=4 +endif + +ifdef SERVER_REPLY +CFLAGS+=-DSERVER_REPLY=$(SERVER_REPLY) +endif +ifdef PERIOD +CFLAGS+=-DPERIOD=$(PERIOD) +endif + +### -------------------------------------------------------- ### + +#CONTIKI_TARGET_SOURCEFILES += control.c vdc.c + +# automatically build RESTful resources +REST_RESOURCES_DIR = ./resources +REST_RESOURCES_FILES = $(notdir $(shell find $(REST_RESOURCES_DIR) -name '*.c')) + +DC_SENSOR_DIR = ./dev +DC_SENSOR_FILES = $(notdir $(shell find $(DC_SENSOR_DIR) -name '*.c')) + +PROJECTDIRS += $(REST_RESOURCES_DIR) $(DC_SENSOR_DIR) +PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES) $(DC_SENSOR_FILES) + +# linker optimizations +SMALL=1 + +# REST Engine shall use Erbium CoAP implementation +APPS += er-coap +APPS += rest-engine + +#CFLAGS += -DUIP_CONF_BUFFER_SIZE=384 +CFLAGS += -DREST_MAX_CHUNK_SIZE=128 +CFLAGS += -DCOAP_MAX_HEADER_SIZE=64 + +CFLAGS += -DUIP_CONF_TCP=0 + +### -------------------------------------------------------- ### + +CONTIKI_WITH_IPV6 = 1 +include $(CONTIKI)/Makefile.include diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/README.md b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/README.md new file mode 100644 index 000000000..ba14cb756 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/README.md @@ -0,0 +1,67 @@ +Example: mockup of DC converter functionality for IoT-grid. +=========================================== +This example imitates DC converter functionality for IoT-grid. +We use standard IoT protocol stack with CoAP application-level protocol. +The settings are as follows. + +* APPLICATION: CoAP +* TRANSPORT: UDP +* NETWORK: IPv6/RPL +* ADAPTATION: 6LoWPAN +* MAC: nullmac_driver +* RADIO DUTY CYCLE: nullrdc_driver +* PHYSICAL: IEEE 802.15.4 + +CoAP resources +---------------- +We define a CoAP resource for each functionality of DC converter. +Since each functionality may have several parameters, we define each resource +as a vector of parameters as follows. + +* /dcdc/status read-only parameters for power monitoring. +It also support periodic monitoring through CoAP observe option. + ** 0 VOUT Output voltage + ** 1 VIN Input voltage + ** 2 IOUT Output current + ** 3 IIN Input current + +* /dcdc/vdc configurable parameters for voltage droop control function. + ** 0 VGRID Desired grid output voltage + ** 1 SLOPE Slope of voltage droop control function + ** 2 PMAX Maximum output power allowed + +* /dcdc/hwcfg configurable parameters for DC converter hardware. + ** 0 VMAX Maximum output voltage allowed + ** 1 IMAX Maximum output current allowed + +Each functionality is implemented as a sensor type device. +They are located in "dev" folder. +* dc-status-sensor for /dcdc/status +* dc-vdc-sensor for /dcdc/vdc +* dc-hw-sensor for /dcdc/hwcfg + +The corresponding CoAP handler for each resource is defined in "resources" folder. +* res-dc-status-obs for /dcdc/status +* res-dc-vdc for /dcdc/vdc +* res-dc-hwcfg for /dcdc/hwcfg + +coap-server.c +---------------- +The server acts as the RPL root node. +It has 3 CoAP resources as described above. + +coap-client.c +---------------- +The client periodically send a CoAP command (either GET or PUT) to monitor/update +values of parameters of a resource. + +project-conf.h +---------------- +This file contains definitions needed for this IoT-grid example as follows. +* Enable IPv6 network stack +* Set nullrdc_driver +* Set nullmac_driver +* Activate CoAP observe client library (COAP_OBSERVE_CLIENT = 1) +* Increase the maximum number of observee and maximum number of open transaction to 10 +(COAP_MAX_OPEN_TRANSACTIONS and COAP_MAX_OBSERVEES = 10) + diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 new file mode 100644 index 000000000..e69de29bb diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c new file mode 100644 index 000000000..691b48e40 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c @@ -0,0 +1,413 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include "contiki-net.h" +#include "lib/random.h" +#include "sys/ctimer.h" +#include "net/ip/uip.h" +#include "net/ipv6/uip-ds6.h" +#include "net/ip/uip-udp-packet.h" +#ifdef WITH_COMPOWER +#include "powertrace.h" +#endif +#include +#include + +/**************************************************************************/ +/* from er-rest-example/er-rexample-client.c */ +#include +#include "er-coap-engine.h" +#include "er-coap.h" +#include "er-coap-observe-client.h" +/* #include "dev/button-sensor.h" */ + +#if PLATFORM_HAS_LEDS +#include "dev/leds.h" +#endif + +#define DEBUG 1 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) +#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5]) +#else +#define PRINTF(...) +#define PRINT6ADDR(addr) +#define PRINTLLADDR(addr) +#endif + +/* FIXME: This server address is hard-coded for Cooja and link-local for unconnected border router. */ +/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xfe80, 0, 0, 0, 0x0212, 0x7402, 0x0002, 0x0202) / * cooja2 * / */ +/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0xbbbb, 0, 0, 0, 0, 0, 0, 0x1) */ + +/* #define SERVER_NODE(ipaddr) uip_ip6addr(ipaddr, 0x2000, 0, 0, 0, 0, 0, 0, 0x0001) */ +#define LOCAL_PORT UIP_HTONS(COAP_DEFAULT_PORT + 1) +#define REMOTE_PORT UIP_HTONS(COAP_DEFAULT_PORT) + +#define GET_INTERVAL 10 +/* #define OBSERVE_INTERVAL 10 */ + +/**************************************************************************/ + +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +#define UDP_EXAMPLE_ID 190 + +/* #define DEBUG DEBUG_PRINT */ +/* #include "net/ip/uip-debug.h" */ + +#ifndef PERIOD +/* #define PERIOD 60 */ +#define PERIOD 10 +#endif + +#define START_INTERVAL (15 * CLOCK_SECOND) +#define SEND_INTERVAL (PERIOD * CLOCK_SECOND) +#define SEND_TIME (random_rand() % (SEND_INTERVAL)) + +/* static struct uip_udp_conn *client_conn; */ +static uip_ipaddr_t server_ipaddr; +static coap_observee_t *obs; +static int count_notify = 0; + +/**************************************************************************/ +static struct etimer et; + +/* Example URIs that can be queried. */ +#define NUMBER_OF_URLS 4 +/* leading and ending slashes only for demo purposes, get cropped automatically when setting the Uri-Path */ +char *service_urls[NUMBER_OF_URLS] = +{ ".well-known/core", "/dcdc/status", "/dcdc/vdc", "/dcdc/hwcfg" }; +/* + #if PLATFORM_HAS_BUTTON + static int uri_switch = 0; + #endif + */ +/* This function is will be passed to COAP_BLOCKING_REQUEST() to handle responses. */ +void +client_chunk_handler(void *response) +{ + const uint8_t *chunk; + + int len = coap_get_payload(response, &chunk); + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + +/* printf("|%.*s", len, (char *)chunk); */ + printf("RX: %d\n%s\n", len, (char *)chunk); +} +/**************************************************************************/ + +/*---------------------------------------------------------------------------*/ +PROCESS(coap_client_process, "CoAP client process"); +AUTOSTART_PROCESSES(&coap_client_process); +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + char *str; + + if(uip_newdata()) { + str = uip_appdata; + str[uip_datalen()] = '\0'; + printf("DATA recv '%s'\n", str); + } +} +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTF("Client IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + /* hack to make address "final" */ + if(state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } +} +/*---------------------------------------------------------------------------*/ +static void +set_global_address(void) +{ + uip_ipaddr_t ipaddr; + + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); + +/* The choice of server address determines its 6LoPAN header compression. + * (Our address will be compressed Mode 3 since it is derived from our link-local address) + * Obviously the choice made here must also be selected in udp-server.c. + * + * For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences, + * e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it. + * (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx) + * + * Note the IPCMV6 checksum verification depends on the correct uncompressed addresses. + */ + +#if 0 +/* Mode 1 - 64 bits inline */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); +#elif 1 +/* Mode 2 - 16 bits inline */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1); +#else +/* Mode 3 - derived from server link-local (MAC) address */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); /* redbee-econotag */ +#endif +/* Voravit Added */ +/* PRINTF("VORAVIT CLIENT: SERVER IPv6 addresses: \n"); */ +/* PRINT6ADDR(&server_ipaddr); */ +} +/*---------------------------------------------------------------------------*/ + +static void +generate_random_payload(int type, char *msg) +{ + if(type == 2) { /* /dcdc/vdc */ + snprintf((char *)msg, 64, "&VG=%d&SL=%d&PMX=%d", (random_rand() % 25) + 1, (random_rand() % 10) + 1, (random_rand() % 100) + 1); + } else if(type == 3) { /* /dcdc/hwcfg */ + snprintf((char *)msg, 64, "&VMX=%d&IMX=%d", (random_rand() % 25) + 1, (random_rand() % 6) + 1); + } +} +/*----------------------------------------------------------------------------*/ +/* + * Handle the response to the observe request and the following notifications + */ +static void +notification_callback(coap_observee_t *obs, void *notification, coap_notification_flag_t flag) +{ + int len = 0; + const uint8_t *payload = NULL; + +/* printf("Notification handler\n"); */ +/* printf("Observee URI: %s\n", obs->url); */ + if(notification) { + len = coap_get_payload(notification, &payload); + } + switch(flag) { + case NOTIFICATION_OK: + count_notify++; + printf("NOTIFICATION OK: %d\n%*s\n", count_notify, len, (char *)payload); + break; + case OBSERVE_OK: /* server accepeted observation request */ + printf("OBSERVE_OK: \n%*s\n", len, (char *)payload); + break; + case OBSERVE_NOT_SUPPORTED: + printf("OBSERVE_NOT_SUPPORTED: \n%*s\n", len, (char *)payload); + obs = NULL; + break; + case ERROR_RESPONSE_CODE: + printf("ERROR_RESPONSE_CODE: \n%*s\n", len, (char *)payload); + obs = NULL; + break; + case NO_REPLY_FROM_SERVER: + printf("NO_REPLY_FROM_SERVER: " + "removing observe registration with token %x%x\n", + obs->token[0], obs->token[1]); + obs = NULL; + break; + } +} +/*---------------------------------------------------------------------------*/ +/* + * Toggle the observation of the remote resource + */ +void +toggle_observation(void) +{ + if(obs) { + printf("Stopping observation\n"); + coap_obs_remove_observee(obs); + obs = NULL; + } else { + printf("Starting observation\n"); + obs = coap_obs_request_registration(&server_ipaddr, REMOTE_PORT, service_urls[1], notification_callback, NULL); + } +} +/*---------------------------------------------------------------------------*/ +static int count_get = 0; +static int count_put = 0; +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(coap_client_process, ev, data) +{ +/* + #if WITH_COMPOWER + static int print = 0; + #endif + */ + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + set_global_address(); + + PRINTF("CoAP client process started\n"); + + print_local_addresses(); + +/**************************************************************************/ + static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */ + + /* receives all CoAP messages */ + coap_init_engine(); + + etimer_set(&et, GET_INTERVAL * CLOCK_SECOND); + + while(1) { + PROCESS_YIELD(); + + if(ev == tcpip_event) { + printf("TCPIP_HANDLER\n"); + tcpip_handler(); + } + + if(etimer_expired(&et)) { + count_get++; + +/*---------------------------------------------------------------------------*/ + if(count_get < 10) { /* we do normal GET 3 times for each resource */ + /* TEST GET: looping through the 3 resources: status, vdc, hwcfg */ + /* Also CoAP GET doesn't need to have a payload */ + coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0); + if(count_get % 3 == 1) { + coap_set_header_uri_path(request, service_urls[1]); + PRINTF("GET %d: %s\n", count_get, service_urls[1]); + } else if(count_get % 3 == 2) { + coap_set_header_uri_path(request, service_urls[2]); + PRINTF("GET %d: %s\n", count_get, service_urls[2]); + } else { + coap_set_header_uri_path(request, service_urls[3]); + PRINTF("GET %d: %s\n", count_get, service_urls[3]); + } + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif + COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request, + client_chunk_handler); + } /* if (count_get < 10) */ +/*---------------------------------------------------------------------------*/ + /* test PUT: vdc and hwcfg on odd and even packet */ + /* every 10th timer we PUT a resource: vdc and hwcfg alternately */ + if(count_get % 10 == 0) { + /* static char msg[64] = ""; */ + char msg[64] = ""; + + /*---------------------------------------------------------------------------*/ + /* We read CO2 sensor if it is enable */ + #ifdef CO2 + coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0); + coap_set_header_uri_path(request, "/dcdc/co2"); + PRINTF("GET %d: %s\n", count_get, "/dcdc/co2"); + #if PLATFORM_HAS_LEDS + leds_on(LEDS_YELLOW); + #endif + COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request, + client_chunk_handler); + #endif + /*---------------------------------------------------------------------------*/ + + count_put++; + coap_init_message(request, COAP_TYPE_CON, COAP_PUT, 0); + + if(count_put % 2 == 0) { + coap_set_header_uri_path(request, service_urls[3]); + generate_random_payload(3, msg); + coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1); + PRINTF("PUT %d: %s PAYLOAD: %s\n", count_get, service_urls[3], msg); + } else { + coap_set_header_uri_path(request, service_urls[2]); + generate_random_payload(2, msg); + coap_set_payload(request, (uint8_t *)msg, sizeof(msg) - 1); + PRINTF("PUT %d: %s PAYLOAD: %s\n", count_get, service_urls[2], msg); + } + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif + COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request, + client_chunk_handler); + + + } + + /* after 2 more timeout we do GET to check the resource new value */ + if((count_get > 10) && ((count_get - 2) % 10 == 0)) { + coap_init_message(request, COAP_TYPE_CON, COAP_GET, 0); + + if(count_put % 2 == 0) { + coap_set_header_uri_path(request, service_urls[3]); + PRINTF("GET %d: %s\n", count_get, service_urls[3]); + } else { + coap_set_header_uri_path(request, service_urls[2]); + PRINTF("GET %d: %s\n", count_get, service_urls[2]); + } + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif + COAP_BLOCKING_REQUEST(&server_ipaddr, REMOTE_PORT, request, + client_chunk_handler); + } + +/*---------------------------------------------------------------------------*/ + + /* test GET with observe option when timer expires the 15th time */ + if(count_get == 15) { + /* PRINTF("GET %d: OBSERVE: %s\n", count_get, service_urls[2]); */ + toggle_observation(); + } + + etimer_reset(&et); + } + } /* END_WHILE(1) */ + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 new file mode 100644 index 000000000..e69de29bb diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c new file mode 100644 index 000000000..8e1ee552d --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c @@ -0,0 +1,269 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" +#include "net/ip/uip.h" +#include "net/rpl/rpl.h" + +#include "net/netstack.h" +/* #include "dev/leds.h" */ +#include +#include +#include +#include + +/* + #define DEBUG DEBUG_PRINT + #include "net/ip/uip-debug.h" + */ +/**************************************************************************/ +/* add mock-up code for DC-DC converter */ +/* #include "control.h" */ +/* #include "vdc.h" */ +#ifdef CO2 +#include "dev/co2_sa_kxx-sensor.h" +#endif +#include "dev/dc-status-sensor.h" +#include "dev/dc-vdc-sensor.h" +#include "dev/dc-hw-sensor.h" + +/* from er-rest-example/er-rexample-server.c */ +#include "rest-engine.h" +/* #include "er-coap.h" */ + +#if PLATFORM_HAS_LEDS +#include "dev/leds.h" +#endif + +/* + #if PLATFORM_HAS_BUTTON + #include "dev/button-sensor.h" + #endif + */ +#define DEBUG 1 +#if DEBUG +/* #include */ +#define PRINTF(...) printf(__VA_ARGS__) +#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) +#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5]) +#else +#define PRINTF(...) +#define PRINT6ADDR(addr) +#define PRINTLLADDR(addr) +#endif + +/* #define TOGGLE_INTERVAL 10 */ +/* #define OBSERVE_INTERVAL 10 */ + +/* + * Resources to be activated need to be imported through the extern keyword. + * The build system automatically compiles the resources in the corresponding sub-directory. + */ +extern resource_t +/* res_hello, */ +/* res_push, */ +/* res_event, */ +/* res_sub; */ +/* res_dc_status_obs; */ +/* res_dc_status, */ +#ifdef CO2 + res_dc_co2, +#endif + res_dc_status_obs, + res_dc_vdc, + res_dc_hwcfg; +/* + #if PLATFORM_HAS_LEDS + extern resource_t + // res_leds, + res_toggle; + #endif + */ +/* #if PLATFORM_HAS_LIGHT */ +/* #include "dev/light-sensor.h" */ +/* extern resource_t res_light; */ +/* #endif */ + +/**************************************************************************/ + +PROCESS(coap_server_process, "CoAP server process"); +AUTOSTART_PROCESSES(&coap_server_process); +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTF("Server IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(state == ADDR_TENTATIVE || state == ADDR_PREFERRED) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + /* hack to make address "final" */ + if(state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(coap_server_process, ev, data) +{ + uip_ipaddr_t ipaddr; + struct uip_ds6_addr *root_if; + + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + +/* SENSORS_ACTIVATE(button_sensor); */ +#ifdef CO2 + SENSORS_ACTIVATE(co2_sa_kxx_sensor); +#endif + SENSORS_ACTIVATE(dc_status_sensor); + SENSORS_ACTIVATE(dc_vdc_sensor); + SENSORS_ACTIVATE(dc_hw_sensor); + +/**************************************************************************/ + +#if PLATFORM_HAS_LEDS +/* initialize leds */ + leds_init(); + leds_on(LEDS_RED); + leds_on(LEDS_YELLOW); +#endif + +/* Initilize DC-DC converter parameters */ +/* ValueInit(); */ +/* VDCInit(); */ +/* + #ifdef PARAMS_CHANNEL + PRINTF("PARAMs channel: %u\n", PARAMS_CHANNEL); + #endif + */ +#ifdef RF_CHANNEL + PRINTF("RF channel: %u\n", RF_CHANNEL); +#endif +#ifdef IEEE802154_PANID + PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID); +#endif + + PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); + PRINTF("LL header: %u\n", UIP_LLH_LEN); + PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); + PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); + + /* Initialize the REST engine. */ + rest_init_engine(); + + /* + * Bind the resources to their Uri-Path. + * WARNING: Activating twice only means alternate path, not two instances! + * All static variables are the same for each URI path. + */ +/* rest_activate_resource(&res_hello, "test/hello"); */ +/* rest_activate_resource(&res_mirror, "debug/mirror"); */ +/* rest_activate_resource(&res_chunks, "test/chunks"); */ +/* rest_activate_resource(&res_separate, "test/separate"); */ +/* rest_activate_resource(&res_push, "test/push"); */ +/* rest_activate_resource(&res_event, "sensors/button"); */ +/* rest_activate_resource(&res_sub, "test/sub"); */ +/* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */ +#ifdef CO2 + rest_activate_resource(&res_dc_co2, "dcdc/co2"); +#endif + rest_activate_resource(&res_dc_status_obs, "dcdc/status"); +/* rest_activate_resource(&res_dc_status, "dcdc/status"); */ + rest_activate_resource(&res_dc_vdc, "dcdc/vdc"); + rest_activate_resource(&res_dc_hwcfg, "dcdc/hwcfg"); +/* #if PLATFORM_HAS_LEDS */ +/* / * rest_activate_resource(&res_leds, "actuators/leds"); * / */ +/* rest_activate_resource(&res_toggle, "actuators/toggle"); */ +/* #endif */ +/* #if PLATFORM_HAS_LIGHT */ +/* rest_activate_resource(&res_light, "sensors/light"); */ +/* SENSORS_ACTIVATE(light_sensor); */ +/* #endif */ + +/**************************************************************************/ + + PRINTF("CoAP server started\n"); + +#if UIP_CONF_ROUTER +/* The choice of server address determines its 6LoPAN header compression. + * Obviously the choice made here must also be selected in udp-client.c. + * + * For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences, + * e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it. + * (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx) + * Note Wireshark's IPCMV6 checksum verification depends on the correct uncompressed addresses. + */ + +#if 0 +/* Mode 1 - 64 bits inline */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); +#elif 1 +/* Mode 2 - 16 bits inline */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1); +#else +/* Mode 3 - derived from link local (MAC) address */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); +#endif + + uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL); + root_if = uip_ds6_addr_lookup(&ipaddr); + if(root_if != NULL) { + rpl_dag_t *dag; + dag = rpl_set_root(RPL_DEFAULT_INSTANCE, (uip_ip6addr_t *)&ipaddr); + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + rpl_set_prefix(dag, &ipaddr, 64); + PRINTF("created a new RPL dag\n"); + } else { + PRINTF("failed to create a new RPL DAG\n"); + } +#endif /* UIP_CONF_ROUTER */ + + print_local_addresses(); + + /* The data sink runs with a 100% duty cycle in order to ensure high + packet reception rates. */ + NETSTACK_MAC.off(1); + + while(1) { + PROCESS_WAIT_EVENT(); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc new file mode 100644 index 000000000..40faff223 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc @@ -0,0 +1,168 @@ + + + [CONTIKI_DIR]/tools/cooja/apps/mrm + [CONTIKI_DIR]/tools/cooja/apps/mspsim + [CONTIKI_DIR]/tools/cooja/apps/avrora + [CONTIKI_DIR]/tools/cooja/apps/native_gateway + [CONTIKI_DIR]/tools/cooja/apps/serial_socket + /home/user/contikiprojects/sics.se/mobility + [CONTIKI_DIR]/tools/cooja/apps/collect-view + /home/user/contikiprojects/sics.se/powertracker + + My simulation + 123456 + 1000000 + + se.sics.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + se.sics.cooja.avrmote.RSS2MoteType + mote1 + Mote1 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c + make coap-server.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.avrmote.interfaces.AvroraClock + se.sics.cooja.avrmote.interfaces.AvroraMoteID + se.sics.cooja.avrmote.interfaces.AvroraUsart0 + se.sics.cooja.avrmote.interfaces.AvroraUsart1 + se.sics.cooja.avrmote.interfaces.RFR2Radio + se.sics.cooja.avrmote.interfaces.AvroraADC + se.sics.cooja.avrmote.interfaces.AvroraLED + + + se.sics.cooja.avrmote.RSS2MoteType + mote2 + Mote2 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c + make coap-client.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.avrmote.interfaces.AvroraClock + se.sics.cooja.avrmote.interfaces.AvroraMoteID + se.sics.cooja.avrmote.interfaces.AvroraUsart0 + se.sics.cooja.avrmote.interfaces.AvroraUsart1 + se.sics.cooja.avrmote.interfaces.RFR2Radio + se.sics.cooja.avrmote.interfaces.AvroraADC + se.sics.cooja.avrmote.interfaces.AvroraLED + + + + + se.sics.cooja.interfaces.Position + 100.0 + 100.0 + 0.0 + + + se.sics.cooja.avrmote.interfaces.AvroraMoteID + 1 + + mote1 + + + + + se.sics.cooja.interfaces.Position + 110.0 + 100.0 + 0.0 + + + se.sics.cooja.avrmote.interfaces.AvroraMoteID + 2 + + mote2 + + + + se.sics.cooja.plugins.SimControl + 280 + 9 + 160 + 400 + 0 + + + se.sics.cooja.plugins.Visualizer + + true + se.sics.cooja.plugins.skins.IDVisualizerSkin + se.sics.cooja.plugins.skins.GridVisualizerSkin + 3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074 + + 400 + 5 + 400 + 1 + 1 + + + se.sics.cooja.plugins.LogListener + + + + + + 1269 + 8 + 240 + 400 + 160 + + + se.sics.cooja.plugins.Notes + + Enter notes here + true + + 989 + 6 + 160 + 680 + 0 + + + se.sics.cooja.plugins.MoteInterfaceViewer + 0 + + Serial port + 0,0 + + 508 + 4 + 389 + 13 + 413 + + + se.sics.cooja.plugins.MoteInterfaceViewer + 1 + + Serial port + 0,0 + + 545 + 3 + 392 + 531 + 413 + + + diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c new file mode 100644 index 000000000..d5715b820 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/hwcfg for DC-DC converter hardware configuration + * \author + * Voravit Tanyingyong + */ + +#include "contiki.h" +/* #include "lib/sensors.h" */ +#include "dev/dc-hw-sensor.h" + +const struct sensors_sensor dc_hw_sensor; + +/* + * hw contains 2 parameters + * hw[0] VMAX + * hw[1] IMAX + */ + +uint32_t volatile hw[2] = { 25, 6 }; + +static int +value(int type) +{ + switch(type) { + case 0: + return hw[0]; + + case 1: + return hw[1]; + } + return -1; +} +static int +configure(int type, int c) +{ + switch(type) { + case 0: + if((c >= 0) && (c <= 25)) { + hw[0] = c; + return 0; + } else { + return 1; + } + + case 1: + if((c >= 0) && (c <= 6)) { + hw[1] = c; + return 0; + } else { + return 0; + } + } + return 1; +} +static int +status(int type) +{ + return 1; +} +SENSORS_SENSOR(dc_hw_sensor, "hw sensors", value, configure, status); + diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h new file mode 100644 index 000000000..538dd2be3 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/hwcfg header file + * \author + * Voravit Tanyingyong + */ + +#ifndef DC_HW_SENSOR_H +#define DC_HW_SENSOR_H + +#include "lib/sensors.h" + +extern const struct sensors_sensor dc_hw_sensor; + +#endif /* DC_HW_SENSOR_H */ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.c new file mode 100644 index 000000000..c4998e61c --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/status read-only parameters for power monitoring + * \author + * Voravit Tanyingyong + */ + +#include "contiki.h" +/* #include "lib/sensors.h" */ +#include "dev/dc-status-sensor.h" + +const struct sensors_sensor dc_status_sensor; + +/* + * Status contains 4 parameters + * status[0] VOUT + * status[1] VIN + * status[2] IOUT + * status[3] IIN + */ + +uint32_t volatile s[4] = { 18, 20, 1, 2 }; + +static int +value(int type) +{ + switch(type) { + case 0: + return s[0]; + + case 1: + return s[1]; + + case 2: + return s[2]; + + case 3: + return s[3]; + } + return -1; +} +static int +configure(int type, int c) +{ + return 0; +} +static int +status(int type) +{ + return 1; +} +SENSORS_SENSOR(dc_status_sensor, "DC status sensors", value, configure, status); + diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.h b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.h new file mode 100644 index 000000000..97bb7c0c2 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/status header file + * \author + * Voravit Tanyingyong + */ + +#ifndef DC_STATUS_SENSOR_H +#define DC_STATUS_SENSOR_H + +#include "lib/sensors.h" + +extern const struct sensors_sensor dc_status_sensor; + +#endif /* DC_STATUS_SENSOR_H */ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c new file mode 100644 index 000000000..bdec4df70 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/vdc for voltage droop control function + * \author + * Voravit Tanyingyong + */ + +#include "contiki.h" +/* #include "lib/sensors.h" */ +#include "dev/dc-vdc-sensor.h" + +const struct sensors_sensor dc_vdc_sensor; + +/* + * vdc contains 3 parameters + * vdc[0] VGRID + * vdc[1] SLOPE + * vdc[2] PMAX + */ + +uint32_t volatile vdc[3] = { 18, 1, 100 }; + +static int +value(int type) +{ + switch(type) { + case 0: + return vdc[0]; + + case 1: + return vdc[1]; + + case 2: + return vdc[2]; + } + return -1; +} +static int +configure(int type, int c) +{ + switch(type) { + case 0: + if((c >= 0) && (c <= 25)) { + vdc[0] = c; + return 0; + } else { + return 1; + } + + case 1: + vdc[1] = c; + return 0; + + case 2: + vdc[2] = c; + return 0; + } + return 1; +} +static int +status(int type) +{ + return 1; +} +SENSORS_SENSOR(dc_vdc_sensor, "vdc sensors", value, configure, status); + diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h new file mode 100644 index 000000000..72749c1c6 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/vdc sensor header file + * \author + * Voravit Tanyingyong + */ + +#ifndef DC_VDC_SENSOR_H +#define DC_VDC_SENSOR_H + +#include "lib/sensors.h" + +extern const struct sensors_sensor dc_vdc_sensor; + +#endif /* DC_VDC_SENSOR_H */ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/er-dc-test.h b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/er-dc-test.h new file mode 100644 index 000000000..5c34cb847 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/er-dc-test.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * header file for resources + * \author + * Voravit Tanyingyong + */ + +#ifndef __ER_DC_TEST_H__ +#define __ER_DC_TEST_H__ + +#define DEBUG 1 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#define PRINT6ADDR(addr) PRINTF("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) +#define PRINTLLADDR(lladdr) PRINTF("[%02x:%02x:%02x:%02x:%02x:%02x]", (lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3], (lladdr)->addr[4], (lladdr)->addr[5]) +#else +#define PRINTF(...) +#define PRINT6ADDR(addr) +#define PRINTLLADDR(addr) +#endif + +/* double expansion */ +#define TO_STRING2(x) # x +#define TO_STRING(x) TO_STRING2(x) + +#define MAX_COAP_PAYLOAD 64 + 1 /* +1 for the terminating zero, which is not transmitted */ +/* #define MAX_PLUGFEST_BODY 2048 */ +/* #define CHUNKS_TOTAL 2012 */ + +#endif /* __ER_DC_TEST_H__ */ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/project-conf.h b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/project-conf.h new file mode 100644 index 000000000..8193c1ee0 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/project-conf.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * test rpl configuration. + * \author + * Voravit Tanyingyong + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +/* enable IPv6 */ +/* #ifndef NETSTACK_CONF_WITH_IPV6 */ +#define NETSTACK_CONF_WITH_IPV6 1 +/* #endif / * NETSTACK_CONF_WITH_IPV6 * / */ + +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_MAC nullmac_driver + +#define COAP_OBSERVE_CLIENT 1 +#define COAP_MAX_OBSERVEES 10 +#define COAP_MAX_OPEN_TRANSACTIONS 10 + +/* enable debug to activate PRINT6ADDR macro */ +/* #undef DEBUG_PRINT */ +/* #define DEBUG_PRINT 1 */ + +/* #define PRINTF(...) printf(__VA_ARGS__) */ +/* #define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15]) */ + +#endif /* PROJECT_CONF_H_ */ diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-co2.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-co2.c new file mode 100644 index 000000000..45860653a --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-co2.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/co2 testing coap with CO2 sensor from SenseAir + * \author + * Voravit Tanyingyong + */ + +/* #include */ +#include +#include +#include "rest-engine.h" +#include "er-coap.h" +#include "er-dc-test.h" +#if PLATFORM_HAS_LEDS +#include "dev/leds.h" +#endif +#include "dev/co2_sa_kxx-sensor.h" + +static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); + +RESOURCE(res_dc_co2, "title=\"co2 reading\"", res_get_handler, NULL, NULL, NULL); + +/*---------------------------------------------------------------------------*/ +static void +res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + coap_packet_t *const coap_req = (coap_packet_t *)request; + + int co2 = co2_sa_kxx_sensor.value(CO2_SA_KXX_CO2); // 0 is CO2_SA_KXX_CO2 + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + + PRINTF("dcdc/co2 GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + + /* Code 2.05 CONTENT is default. */ + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + /* REST.set_header_max_age(response, 30); */ + REST.set_response_payload( + response, + buffer, +/* snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\nINT\t%d\n", v_max, i_max, interval)); */ + snprintf((char *)buffer, MAX_COAP_PAYLOAD, "CO2\t%d\n", co2)); + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif +} + diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c new file mode 100644 index 000000000..6c8091774 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/vdc configurable parameters for voltage droop control function + * \author + * Voravit Tanyingyong + */ + +/* #include */ +#include +#include +#include "rest-engine.h" +#include "er-coap.h" +#include "er-dc-test.h" +#if PLATFORM_HAS_LEDS +#include "dev/leds.h" +#endif +#include "dev/dc-hw-sensor.h" + +static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); +static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); + +RESOURCE(res_dc_hwcfg, "title=\"hwcfg parameters\"", res_get_handler, res_post_put_handler, res_post_put_handler, NULL); + +/*---------------------------------------------------------------------------*/ +static void +res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + coap_packet_t *const coap_req = (coap_packet_t *)request; + + int v_max = dc_hw_sensor.value(0); + int i_max = dc_hw_sensor.value(1); + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + + PRINTF("dcdc/hwcfg GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + + /* Code 2.05 CONTENT is default. */ + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + /* REST.set_header_max_age(response, 30); */ + REST.set_response_payload( + response, + buffer, +/* snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\nINT\t%d\n", v_max, i_max, interval)); */ + snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VMX\t%d.000\nIMX\t%d.000\n", v_max, i_max)); + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif +} +/*---------------------------------------------------------------------------*/ +static void +res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + coap_packet_t *const coap_req = (coap_packet_t *)request; + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + + PRINTF("dcdc/hwcfg PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + + const char *variable = NULL; + + if(REST.get_post_variable(request, "VMX", &variable) > 0) { + int v_max = atoi(variable); + if(dc_hw_sensor.configure(0, v_max)) { + PRINTF("Value out of range: must be 0 <= VMX <= 30"); + } + } + + if(REST.get_post_variable(request, "IMX", &variable) > 0) { + int i_max = atoi(variable); + if(dc_hw_sensor.configure(1, i_max)) { + PRINTF("Value out of range: must be 0 <= Imax <= 6"); + } + } + + REST.set_response_status(response, REST.status.CHANGED); + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif +} diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c new file mode 100644 index 000000000..75d992fe2 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/status read-only parameters for power monitoring + * \author + * Voravit Tanyingyong + */ + +#include +#include +#include "rest-engine.h" +#include "er-coap.h" +#include "er-coap-observe.h" +#include "../er-dc-test.h" +#if PLATFORM_HAS_LEDS +#include "dev/leds.h" +#endif +#include "dev/dc-status-sensor.h" + +static void res_dc_status_obs_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); +static void res_dc_status_obs_periodic_handler(void); + +PERIODIC_RESOURCE(res_dc_status_obs, "title=\"status parameters\"", res_dc_status_obs_get_handler, NULL, NULL, NULL, 10 * CLOCK_SECOND, res_dc_status_obs_periodic_handler); + +static uint32_t observe = 0; +static count = 0; +/*---------------------------------------------------------------------------*/ +static void +res_dc_status_obs_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + + int vout_value = dc_status_sensor.value(0); + int vin_value = dc_status_sensor.value(1); + int iout_value = dc_status_sensor.value(2); + int iin_value = dc_status_sensor.value(3); + + /* a request comes from a remote host */ + if(request != NULL) { + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + + coap_packet_t *const coap_req = (coap_packet_t *)request; + + PRINTF("dcdc/status GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + + /* if comes with observe then register it */ + if(coap_get_header_observe(request, &observe)) { +/* PRINTF("OBSERVE set\n"); */ + /* respond with empty ack */ + REST.set_header_content_type(response, observe); + REST.set_response_payload(response, 0, 0); + } else { /* if no observe option, then answer to GET request as normal */ +/* PRINTF("OBSERVE NOT set\n"); */ + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + REST.set_response_payload( + response, + buffer, + snprintf((char *)buffer, MAX_COAP_PAYLOAD, "ST\tON\nVO\t%d.000\nIO\t%d.000\nVI\t%d.000\nII\t%d.000\n", vout_value, iout_value, vin_value, iin_value)); + } + } else { /* this is a notification: need to set payload */ +/* PRINTF("NULL REQUEST = PERIODIC\n"); */ + REST.set_response_payload( + response, + buffer, + snprintf((char *)buffer, MAX_COAP_PAYLOAD, "ST\tON\nVO\t%d.000\nIO\t%d.000\nVI\t%d.000\nII\t%d.000\n", vout_value, iout_value, vin_value, iin_value)); + } + count++; + printf("PERIODIC %d: ST:ON VO:%d IO:%d VI:%d II:%d\n", count, vout_value, iout_value, vin_value, iin_value); +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif +} +/*---------------------------------------------------------------------------*/ +static void +res_dc_status_obs_periodic_handler() +{ + /* send periodic notification to the observers */ + REST.notify_subscribers(&res_dc_status_obs); +} diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-vdc.c b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-vdc.c new file mode 100644 index 000000000..8157fbf90 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-vdc.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2015, ICT/COS/NSLab, KTH Royal Institute of Technology + * 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 + * dcdc/vdc configurable parameters for voltage droop control function + * \author + * Voravit Tanyingyong + */ + +/* #include */ +#include +#include +#include "rest-engine.h" +#include "er-coap.h" +#include "er-dc-test.h" +#if PLATFORM_HAS_LEDS +#include "dev/leds.h" +#endif +#include "dev/dc-vdc-sensor.h" + +static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); +static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); + +RESOURCE(res_dc_vdc, "title=\"vdc parameters\"", res_get_handler, res_post_put_handler, res_post_put_handler, NULL); + +/*---------------------------------------------------------------------------*/ +static void +res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + coap_packet_t *const coap_req = (coap_packet_t *)request; + + int vdc_grid = dc_vdc_sensor.value(0); + int vdc_slope = dc_vdc_sensor.value(1); + int vdc_pmax = dc_vdc_sensor.value(2); + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + + PRINTF("dcdc/vdc GET (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + + /* Code 2.05 CONTENT is default. */ + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + /* REST.set_header_max_age(response, 30); */ + REST.set_response_payload( + response, + buffer, + snprintf((char *)buffer, MAX_COAP_PAYLOAD, "VG\t%d.000\nSL\t%d.000\nPMAX\t%d.000\n", vdc_grid, vdc_slope, vdc_pmax)); + +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif +} +/*---------------------------------------------------------------------------*/ +static void +res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + coap_packet_t *const coap_req = (coap_packet_t *)request; + +#if PLATFORM_HAS_LEDS + /* set red led when receiving a packet */ + leds_on(LEDS_RED); +#endif + + PRINTF("dcdc/vdc PUT (%s %u)\n", coap_req->type == COAP_TYPE_CON ? "CON" : "NON", coap_req->mid); + + const char *variable = NULL; + + if(REST.get_post_variable(request, "VG", &variable) > 0) { + int vdc_grid = atoi(variable); + /* PRINTF("VG: %d\n",vdc_grid); */ + if(dc_vdc_sensor.configure(0, vdc_grid)) { + PRINTF("Value out of range: must be 0 <= Vgrid <= Vmax"); + } + } + + if(REST.get_post_variable(request, "SL", &variable) > 0) { + int vdc_slope = atoi(variable); + /* PRINTF("SL: %d\n",vdc_slope); */ + if(dc_vdc_sensor.configure(1, vdc_slope)) { + PRINTF("Error: SLOPE is not set!"); + } + } + + if(REST.get_post_variable(request, "PMX", &variable) > 0) { + int vdc_pmax = atoi(variable); + /* PRINTF("PMAX: %d\n",vdc_pmax); */ + if(dc_vdc_sensor.configure(2, vdc_pmax)) { + PRINTF("Error: PMAX is not set!"); + } + } + + REST.set_response_status(response, REST.status.CHANGED); +#if PLATFORM_HAS_LEDS + /* set yellow led when sending packet */ + leds_on(LEDS_YELLOW); +#endif +} diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/Makefile b/platform/avr-rss2/examples/ipv6/rpl-border-router/Makefile new file mode 100644 index 000000000..ba3f16af6 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/Makefile @@ -0,0 +1,55 @@ +CONTIKI_PROJECT=border-router +all: $(CONTIKI_PROJECT) + +CONTIKI=../../../../.. + +#linker optimizations +SMALL=1 + +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" +PROJECT_SOURCEFILES += eth-bridge.c +#PROJECT_SOURCEFILES += enc28j60.c +PROJECT_SOURCEFILES += enc28j60-ip64-driver.c + +APPS += ping6 + +MODULES += dev/enc28j60 core/net/ip64 + +#Simple built-in webserver is the default. +#Override with make WITH_WEBSERVER=0 for no webserver. +#WITH_WEBSERVER=webserver-name will use /apps/webserver-name if it can be +#found in the /apps, /platform/$(TARGET)/apps/, or current directory (in that order). +# WITH_WEBSERVER=webserver for /apps/webserver +# WITH_WEBSERVER=raven-webserver for /platform/avr-raven/apps/raven-webserver/ +#make clean before changing webservers! + +#Note /apps/webserver contains a 2500 byte style sheet which is a severe test +#of the slip connection. Large MSS together with low baud rates without flow +#control will overrun the transmit buffer when the style sheet is requested. + +WITH_WEBSERVER=1 +ifeq ($(WITH_WEBSERVER),1) +CFLAGS += -DUIP_CONF_TCP=1 +CFLAGS += -DWEBSERVER=1 +PROJECT_SOURCEFILES += httpd-simple.c +else ifneq ($(WITH_WEBSERVER), 0) +APPS += $(WITH_WEBSERVER) +CFLAGS += -DUIP_CONF_TCP=1 +CFLAGS += -DWEBSERVER=2 +endif + +ifeq ($(PREFIX),) + PREFIX = aaaa::1/64 +endif + +CONTIKI_WITH_IPV6 = 1 +include $(CONTIKI)/Makefile.include + +$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c + (cd $(CONTIKI)/tools && $(MAKE) tunslip6) + +connect-router: $(CONTIKI)/tools/tunslip6 + sudo $(CONTIKI)/tools/tunslip6 $(PREFIX) + +connect-router-cooja: $(CONTIKI)/tools/tunslip6 + sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 $(PREFIX) diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/README.ETHERNET.md b/platform/avr-rss2/examples/ipv6/rpl-border-router/README.ETHERNET.md new file mode 100644 index 000000000..ab63e9ae3 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/README.ETHERNET.md @@ -0,0 +1,66 @@ +Document version: 2015-12-29 + +HOWTO connect the Microchip enc28j60 module +=========================================== + +It's possible to to add Ethernet to most microcontrollers having a SPI inter- +face. In the Atmel world the SPI pins are used for the ISP programming. Usually +a 6-pin header. Named MOSI, MISO, SCK, CS (Chup Select), Vcc, GND + +One popular Ethernet chip is Microchip ENC28J60. It been used for quite some +time and is easy to program and are also supported by many platforms and +projects. Contiki has files under: + +Most focus fon AVR platforms. The SPI is used by Atmel ISP-progammings +interface. In addition to those pins you to selects a pin for chip +select (CS). + +dev/enc28j60/ +The low-level SPI drives is platform or rather CPU-specific. The avr-rss2 +platform adds the low-level drivers for Atmel. + +platform/avr-rss2/enc28j60_avr.[ch] +This should be usable on most 8-bit avr platforms. + +The power consumption might be a problem. The enc28j60 consumes 160mA at 3.3V +when transmitting. The LDO (voltage reg. LP2950) on the mote can only handle +100mA. So external power is needed. Below is a description of a prototype. + +Used components: +---------------- +Externel power supply 5V. +Small breadboard +DC-jack +Voltage Reg. LCP1700 3.3V +Capacitor 4.7uF +enc28j60 (From Ebay) +Pin-headers +Cables 2x5 (enc28j60) 2x3 SPI (AtMega node) + +Used colors: +Black GND +Red VCC 3.3V +Yellow SCK +Green MISO +White MOSI +Blue CS (Chip select) + +SPI (Connector view) +-------------------- +GREEN YELLOW NC +RED WHITE BLACK + +CS is connected to external temp sensor middle pin. Consequently the +external temp sensor can not be used in this application. + +Pictures +-------- +![Module] ( http://www.radio-sensors.com/pictures/enc28j60.jpg) +![Connector] (http://www.radio-sensors.com/pictures/enc28c60-cable.jpg) + + +References +----------- + + + diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/README.md b/platform/avr-rss2/examples/ipv6/rpl-border-router/README.md new file mode 100644 index 000000000..fa3019c2d --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/README.md @@ -0,0 +1,17 @@ +Document version: 2016-02-22 + +An ethernet-to-802.15.4 NAT/GW IP64 +=================================== + +This project is heavily based on the rpl-border-router in the example directory +using the IP64 framework. This work is done Contiki/Thingsquare as the driver +for enc28j60. + +But rather than using slip as in the original example an ethernet interface +the Microchip enc28j60 is used. The needed SPI-glue for AtMega's is added by +this platform. (avr-rss2) + +See the README.ETHERNET.md for ethernet module info. + + + diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/border-router.c b/platform/avr-rss2/examples/ipv6/rpl-border-router/border-router.c new file mode 100644 index 000000000..6a992982f --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/border-router.c @@ -0,0 +1,388 @@ +/* + * 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 + * border-router + * \author + * Niclas Finne + * Joakim Eriksson + * Nicolas Tsiftes + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" +#include "net/ip/uip.h" +#include "net/ipv6/uip-ds6.h" +#include "ip64.h" +#include "net/rpl/rpl.h" +#include "enc28j60.h" +#include "enc28j60-ip64-driver.h" +#include "net/netstack.h" +#include "dev/button-sensor.h" +#include "dev/slip.h" +#include "dev/leds.h" + +#include +#include +#include +#include + +#define DEBUG DEBUG_PRINT +#include "net/ip/uip-debug.h" + +static uip_ipaddr_t prefix; +static uint8_t prefix_set; + +PROCESS(border_router_process, "Border router process"); + +#if WEBSERVER==0 +/* No webserver */ +AUTOSTART_PROCESSES(&border_router_process); +#elif WEBSERVER>1 +/* Use an external webserver application */ +#include "webserver-nogui.h" +AUTOSTART_PROCESSES(&border_router_process,&webserver_nogui_process); +#else +/* Use simple webserver with only one page for minimum footprint. + * Multiple connections can result in interleaved tcp segments since + * a single static buffer is used for all segments. + */ +#include "httpd-simple.h" +/* The internal webserver can provide additional information if + * enough program flash is available. + */ +#define WEBSERVER_CONF_LOADTIME 1 +#define WEBSERVER_CONF_FILESTATS 1 +#define WEBSERVER_CONF_NEIGHBOR_STATUS 1 +/* Adding links requires a larger RAM buffer. To avoid static allocation + * the stack can be used for formatting; however tcp retransmissions + * and multiple connections can result in garbled segments. + * TODO:use PSOCk_GENERATOR_SEND and tcp state storage to fix this. + */ +#define WEBSERVER_CONF_ROUTE_LINKS 1 +#if WEBSERVER_CONF_ROUTE_LINKS +#define BUF_USES_STACK 1 +#endif + +PROCESS(webserver_nogui_process, "Web server"); +PROCESS_THREAD(webserver_nogui_process, ev, data) +{ + PROCESS_BEGIN(); + + httpd_init(); + + while(1) { + PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); + httpd_appcall(data); + } + + PROCESS_END(); +} +AUTOSTART_PROCESSES(&border_router_process,&webserver_nogui_process); + +static const char *TOP = "ContikiRPL\n"; +static const char *BOTTOM = "\n"; +#if BUF_USES_STACK +static char *bufptr, *bufend; +#define ADD(...) do { \ + bufptr += snprintf(bufptr, bufend - bufptr, __VA_ARGS__); \ + } while(0) +#else +static char buf[256]; +static int blen; +#define ADD(...) do { \ + blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \ + } while(0) +#endif + +/*---------------------------------------------------------------------------*/ +static void +ipaddr_add(const uip_ipaddr_t *addr) +{ + uint16_t a; + int i, f; + for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { + a = (addr->u8[i] << 8) + addr->u8[i + 1]; + if(a == 0 && f >= 0) { + if(f++ == 0) ADD("::"); + } else { + if(f > 0) { + f = -1; + } else if(i > 0) { + ADD(":"); + } + ADD("%x", a); + } + } +} +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(generate_routes(struct httpd_state *s)) +{ + static uip_ds6_route_t *r; + static uip_ds6_nbr_t *nbr; +#if BUF_USES_STACK + char buf[256]; +#endif +#if WEBSERVER_CONF_LOADTIME + static clock_time_t numticks; + numticks = clock_time(); +#endif + + PSOCK_BEGIN(&s->sout); + + SEND_STRING(&s->sout, TOP); +#if BUF_USES_STACK + bufptr = buf;bufend=bufptr+sizeof(buf); +#else + blen = 0; +#endif + ADD("Neighbors
");
+
+  for(nbr = nbr_table_head(ds6_neighbors);
+      nbr != NULL;
+      nbr = nbr_table_next(ds6_neighbors, nbr)) {
+
+#if WEBSERVER_CONF_NEIGHBOR_STATUS
+#if BUF_USES_STACK
+{char* j=bufptr+25;
+      ipaddr_add(&nbr->ipaddr);
+      while (bufptr < j) ADD(" ");
+      switch (nbr->state) {
+      case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
+      case NBR_REACHABLE: ADD(" REACHABLE");break;
+      case NBR_STALE: ADD(" STALE");break;
+      case NBR_DELAY: ADD(" DELAY");break;
+      case NBR_PROBE: ADD(" NBR_PROBE");break;
+      }
+}
+#else
+{uint8_t j=blen+25;
+      ipaddr_add(&nbr->ipaddr);
+      while (blen < j) ADD(" ");
+      switch (nbr->state) {
+      case NBR_INCOMPLETE: ADD(" INCOMPLETE");break;
+      case NBR_REACHABLE: ADD(" REACHABLE");break;
+      case NBR_STALE: ADD(" STALE");break;
+      case NBR_DELAY: ADD(" DELAY");break;
+      case NBR_PROBE: ADD(" NBR_PROBE");break;
+      }
+}
+#endif
+#else
+      ipaddr_add(&nbr->ipaddr);
+#endif
+
+      ADD("\n");
+#if BUF_USES_STACK
+      if(bufptr > bufend - 45) {
+        SEND_STRING(&s->sout, buf);
+        bufptr = buf; bufend = bufptr + sizeof(buf);
+      }
+#else
+      if(blen > sizeof(buf) - 45) {
+        SEND_STRING(&s->sout, buf);
+        blen = 0;
+      }
+#endif
+  }
+  ADD("
Routes
");
+  SEND_STRING(&s->sout, buf);
+#if BUF_USES_STACK
+  bufptr = buf; bufend = bufptr + sizeof(buf);
+#else
+  blen = 0;
+#endif
+
+  for(r = uip_ds6_route_head(); r != NULL; r = uip_ds6_route_next(r)) {
+
+#if BUF_USES_STACK
+#if WEBSERVER_CONF_ROUTE_LINKS
+    ADD("ipaddr);
+    ADD("]/status.shtml>");
+    ipaddr_add(&r->ipaddr);
+    ADD("");
+#else
+    ipaddr_add(&r->ipaddr);
+#endif
+#else
+#if WEBSERVER_CONF_ROUTE_LINKS
+    ADD("ipaddr);
+    ADD("]/status.shtml>");
+    SEND_STRING(&s->sout, buf); //TODO: why tunslip6 needs an output here, wpcapslip does not
+    blen = 0;
+    ipaddr_add(&r->ipaddr);
+    ADD("");
+#else
+    ipaddr_add(&r->ipaddr);
+#endif
+#endif
+    ADD("/%u (via ", r->length);
+    ipaddr_add(uip_ds6_route_nexthop(r));
+    if(1 || (r->state.lifetime < 600)) {
+      ADD(") %lus\n", (unsigned long)r->state.lifetime);
+    } else {
+      ADD(")\n");
+    }
+    SEND_STRING(&s->sout, buf);
+#if BUF_USES_STACK
+    bufptr = buf; bufend = bufptr + sizeof(buf);
+#else
+    blen = 0;
+#endif
+  }
+  ADD("
"); + +#if WEBSERVER_CONF_FILESTATS + static uint16_t numtimes; + ADD("
This page sent %u times",++numtimes); +#endif + +#if WEBSERVER_CONF_LOADTIME + numticks = clock_time() - numticks + 1; + ADD(" (%lu.%02lu sec)",numticks/CLOCK_SECOND,((100*(numticks%CLOCK_SECOND))/CLOCK_SECOND)); +#endif + + + SEND_STRING(&s->sout, buf); + SEND_STRING(&s->sout, BOTTOM); + + PSOCK_END(&s->sout); +} +/*---------------------------------------------------------------------------*/ +httpd_simple_script_t +httpd_simple_get_script(const char *name) +{ + return generate_routes; +} + +#endif /* WEBSERVER */ + +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTA("Server IPv6 addresses:\n"); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + PRINTA(" "); + uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); + PRINTA("\n"); + } + } +} +/*---------------------------------------------------------------------------*/ +void +request_prefix(void) +{ + /* mess up uip_buf with a dirty request... */ + uip_buf[0] = '?'; + uip_buf[1] = 'P'; + uip_len = 2; + //slip_send(); + uip_clear_buf(); +} +/*---------------------------------------------------------------------------*/ +void +set_prefix_64(uip_ipaddr_t *prefix_64) +{ + rpl_dag_t *dag; + uip_ipaddr_t ipaddr; + memcpy(&prefix, prefix_64, 16); + memcpy(&ipaddr, prefix_64, 16); + prefix_set = 1; + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); + + dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr); + if(dag != NULL) { + rpl_set_prefix(dag, &prefix, 64); + PRINTF("created a new RPL dag\n"); + } +} + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(border_router_process, ev, data) +{ + PROCESS_BEGIN(); + uip_ipaddr_t ipaddr; + +/* While waiting for the prefix to be sent through the SLIP connection, the future + * border router can join an existing DAG as a parent or child, or acquire a default + * router that will later take precedence over the SLIP fallback interface. + * Prevent that by turning the radio off until we are initialized as a DAG root. + */ + prefix_set = 0; + NETSTACK_MAC.off(0); + + PROCESS_PAUSE(); + + SENSORS_ACTIVATE(button_sensor); + leds_init(); + ip64_init(); + + PRINTF("RPL-Border router started\n"); +#if 0 + /* The border router runs with a 100% duty cycle in order to ensure high + packet reception rates. + Note if the MAC RDC is not turned off now, aggressive power management of the + cpu will interfere with establishing the SLIP connection */ + NETSTACK_MAC.off(1); +#endif + + /* Now turn the radio on, but disable radio duty cycling. + * Since we are the DAG root, reception delays would constrain mesh throughbut. + */ + NETSTACK_MAC.off(1); + +/* Derived from link local (MAC) address */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + set_prefix_64(&ipaddr); + print_local_addresses(); + + while(1) { + PROCESS_YIELD(); + leds_on(LEDS_YELLOW); + if (ev == sensors_event && data == &button_sensor) { + PRINTF("Initiating global repair\n"); + rpl_repair_root(RPL_DEFAULT_INSTANCE); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.c b/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.c new file mode 100644 index 000000000..6bc4122a4 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012-2013, Thingsquare, http://www.thingsquare.com/. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "contiki.h" +#include "enc28j60.h" +#include "enc28j60-ip64-driver.h" +#include "net/linkaddr.h" + +#include "ip64.h" +#include "ip64-eth.h" + +#include +#include + +PROCESS(enc28j60_ip64_driver_process, "ENC28J60 IP64 driver"); + +/*---------------------------------------------------------------------------*/ +static void +init(void) +{ + uint8_t eui64[8]; + uint8_t macaddr[6]; + + /* Assume that linkaddr_node_addr holds the EUI64 of this device. */ + memcpy(eui64, &linkaddr_node_addr, sizeof(eui64)); + + /* Mangle the EUI64 into a 48-bit Ethernet address. */ + memcpy(&macaddr[0], &eui64[0], 3); + memcpy(&macaddr[3], &eui64[5], 3); + + /* In case the OUI happens to contain a broadcast bit, we mask that + out here. */ + macaddr[0] = (macaddr[0] & 0xfe); + + /* Set the U/L bit, in order to create a locally administered MAC address */ + macaddr[0] = (macaddr[0] | 0x02); + + memcpy(ip64_eth_addr.addr, macaddr, sizeof(macaddr)); + + printf("MAC addr %02x:%02x:%02x:%02x:%02x:%02x\n", + macaddr[0], macaddr[1], macaddr[2], + macaddr[3], macaddr[4], macaddr[5]); + enc28j60_init(macaddr); + process_start(&enc28j60_ip64_driver_process, NULL); +} +/*---------------------------------------------------------------------------*/ +static int +output(uint8_t *packet, uint16_t len) +{ + enc28j60_send(packet, len); + return len; +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(enc28j60_ip64_driver_process, ev, data) +{ + static int len; + static struct etimer e; + PROCESS_BEGIN(); + + while(1) { + etimer_set(&e, 1); + PROCESS_WAIT_EVENT(); + len = enc28j60_read(ip64_packet_buffer, ip64_packet_buffer_maxlen); + if(len > 0) { + IP64_INPUT(ip64_packet_buffer, len); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +const struct ip64_driver enc28j60_ip64_driver = { + init, + output +}; +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.h b/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.h new file mode 100644 index 000000000..29d3ed5a4 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012-2013, Thingsquare, http://www.thingsquare.com/. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef ENC28J60_IP64_DRIVER_H +#define ENC28J60_IP64_DRIVER_H + +#include "ip64-driver.h" +extern const struct ip64_driver enc28j60_ip64_driver; + +#endif /* ENC28J60_IP64_DRIVER_H */ diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/eth-bridge.c b/platform/avr-rss2/examples/ipv6/rpl-border-router/eth-bridge.c new file mode 100644 index 000000000..b5d9ec498 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/eth-bridge.c @@ -0,0 +1,33 @@ +#include "net/ip/uip.h" +#include "net/ipv6/uip-ds6.h" +#include +#include "ip64-eth-interface.h" + +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) + +#define DEBUG DEBUG_NONE +#include "net/ip/uip-debug.h" + +static void +init(void) +{ + PRINTF("eth-bridge: init\n"); + ip64_eth_interface.init(); +} +/*---------------------------------------------------------------------------*/ +static int +output() +{ + PRINTF("eth-bridge: src="); + PRINT6ADDR(&UIP_IP_BUF->srcipaddr); + PRINTF(" dst="); + PRINT6ADDR(&UIP_IP_BUF->destipaddr); + PRINTF("\n"); + ip64_eth_interface.output(); + return 0; +} +/*---------------------------------------------------------------------------*/ +const struct uip_fallback_interface rpl_interface = { + init, output +}; +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.c b/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.c new file mode 100644 index 000000000..115e54d45 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.c @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * 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. + * + */ + +/** + * \file + * A simple web server forwarding page generation to a protothread + * \author + * Adam Dunkels + * Niclas Finne + * Joakim Eriksson + */ + +#include +#include + +#include "contiki-net.h" + +//#include "urlconv.h" + +#include "httpd-simple.h" +#define webserver_log_file(...) +#define webserver_log(...) + +#ifndef WEBSERVER_CONF_CFS_CONNS +#define CONNS UIP_CONNS +#else /* WEBSERVER_CONF_CFS_CONNS */ +#define CONNS WEBSERVER_CONF_CFS_CONNS +#endif /* WEBSERVER_CONF_CFS_CONNS */ + +#ifndef WEBSERVER_CONF_CFS_URLCONV +#define URLCONV 0 +#else /* WEBSERVER_CONF_CFS_URLCONV */ +#define URLCONV WEBSERVER_CONF_CFS_URLCONV +#endif /* WEBSERVER_CONF_CFS_URLCONV */ + +#define STATE_WAITING 0 +#define STATE_OUTPUT 1 + +MEMB(conns, struct httpd_state, CONNS); + +#define ISO_nl 0x0a +#define ISO_space 0x20 +#define ISO_period 0x2e +#define ISO_slash 0x2f + +/*---------------------------------------------------------------------------*/ +static const char *NOT_FOUND = "" +"
" +"

404 - file not found

" +"
" +"" +""; +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(send_string(struct httpd_state *s, const char *str)) +{ + PSOCK_BEGIN(&s->sout); + + SEND_STRING(&s->sout, str); + + PSOCK_END(&s->sout); +} +/*---------------------------------------------------------------------------*/ +const char http_content_type_html[] = "Content-type: text/html\r\n\r\n"; +static +PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr)) +{ + /* char *ptr; */ + + PSOCK_BEGIN(&s->sout); + + SEND_STRING(&s->sout, statushdr); + + /* ptr = strrchr(s->filename, ISO_period); */ + /* if(ptr == NULL) { */ + /* s->ptr = http_content_type_plain; */ + /* } else if(strcmp(http_html, ptr) == 0) { */ + /* s->ptr = http_content_type_html; */ + /* } else if(strcmp(http_css, ptr) == 0) { */ + /* s->ptr = http_content_type_css; */ + /* } else if(strcmp(http_png, ptr) == 0) { */ + /* s->ptr = http_content_type_png; */ + /* } else if(strcmp(http_gif, ptr) == 0) { */ + /* s->ptr = http_content_type_gif; */ + /* } else if(strcmp(http_jpg, ptr) == 0) { */ + /* s->ptr = http_content_type_jpg; */ + /* } else { */ + /* s->ptr = http_content_type_binary; */ + /* } */ + /* SEND_STRING(&s->sout, s->ptr); */ + SEND_STRING(&s->sout, http_content_type_html); + PSOCK_END(&s->sout); +} +/*---------------------------------------------------------------------------*/ +const char http_header_200[] = "HTTP/1.0 200 OK\r\nServer: Contiki/2.4 http://www.sics.se/contiki/\r\nConnection: close\r\n"; +const char http_header_404[] = "HTTP/1.0 404 Not found\r\nServer: Contiki/2.4 http://www.sics.se/contiki/\r\nConnection: close\r\n"; +static +PT_THREAD(handle_output(struct httpd_state *s)) +{ + PT_BEGIN(&s->outputpt); + + s->script = NULL; + s->script = httpd_simple_get_script(&s->filename[1]); + if(s->script == NULL) { + strncpy(s->filename, "/notfound.html", sizeof(s->filename)); + PT_WAIT_THREAD(&s->outputpt, + send_headers(s, http_header_404)); + PT_WAIT_THREAD(&s->outputpt, + send_string(s, NOT_FOUND)); + uip_close(); + webserver_log_file(&uip_conn->ripaddr, "404 - not found"); + PT_EXIT(&s->outputpt); + } else { + PT_WAIT_THREAD(&s->outputpt, + send_headers(s, http_header_200)); + PT_WAIT_THREAD(&s->outputpt, s->script(s)); + } + s->script = NULL; + PSOCK_CLOSE(&s->sout); + PT_END(&s->outputpt); +} +/*---------------------------------------------------------------------------*/ +const char http_get[] = "GET "; +const char http_index_html[] = "/index.html"; +//const char http_referer[] = "Referer:" +static +PT_THREAD(handle_input(struct httpd_state *s)) +{ + PSOCK_BEGIN(&s->sin); + + PSOCK_READTO(&s->sin, ISO_space); + + if(strncmp(s->inputbuf, http_get, 4) != 0) { + PSOCK_CLOSE_EXIT(&s->sin); + } + PSOCK_READTO(&s->sin, ISO_space); + + if(s->inputbuf[0] != ISO_slash) { + PSOCK_CLOSE_EXIT(&s->sin); + } + +#if URLCONV + s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; + urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename)); +#else /* URLCONV */ + if(s->inputbuf[1] == ISO_space) { + strncpy(s->filename, http_index_html, sizeof(s->filename)); + } else { + s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; + strncpy(s->filename, s->inputbuf, sizeof(s->filename)); + } +#endif /* URLCONV */ + + webserver_log_file(&uip_conn->ripaddr, s->filename); + + s->state = STATE_OUTPUT; + + while(1) { + PSOCK_READTO(&s->sin, ISO_nl); +#if 0 + if(strncmp(s->inputbuf, http_referer, 8) == 0) { + s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0; + webserver_log(s->inputbuf); + } +#endif + } + + PSOCK_END(&s->sin); +} +/*---------------------------------------------------------------------------*/ +static void +handle_connection(struct httpd_state *s) +{ + handle_input(s); + if(s->state == STATE_OUTPUT) { + handle_output(s); + } +} + +/*---------------------------------------------------------------------------*/ +void +httpd_appcall(void *state) +{ + struct httpd_state *s = (struct httpd_state *)state; + + if(uip_closed() || uip_aborted() || uip_timedout()) { + if(s != NULL) { + s->script = NULL; + memb_free(&conns, s); + } + } else if(uip_connected()) { + s = (struct httpd_state *)memb_alloc(&conns); + if(s == NULL) { + uip_abort(); + webserver_log_file(&uip_conn->ripaddr, "reset (no memory block)"); + return; + } + tcp_markconn(uip_conn, s); + PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); + PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); + PT_INIT(&s->outputpt); + s->script = NULL; + s->state = STATE_WAITING; + timer_set(&s->timer, CLOCK_SECOND * 10); + handle_connection(s); + } else if(s != NULL) { + if(uip_poll()) { + if(timer_expired(&s->timer)) { + uip_abort(); + s->script = NULL; + memb_free(&conns, s); + webserver_log_file(&uip_conn->ripaddr, "reset (timeout)"); + } + } else { + timer_restart(&s->timer); + } + handle_connection(s); + } else { + uip_abort(); + } +} + +/*---------------------------------------------------------------------------*/ +void +httpd_init(void) +{ + + tcp_listen(UIP_HTONS(80)); + memb_init(&conns); +#if URLCONV + urlconv_init(); +#endif /* URLCONV */ +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.h b/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.h new file mode 100644 index 000000000..a16dbd99e --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * 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. + * + */ + +/** + * \file + * A simple webserver + * \author + * Adam Dunkels + * Niclas Finne + * Joakim Eriksson + */ + +#ifndef HTTPD_SIMPLE_H_ +#define HTTPD_SIMPLE_H_ + +#include "contiki-net.h" + +/* The current internal border router webserver ignores the requested file name */ +/* and needs no per-connection output buffer, so save some RAM */ +#ifndef WEBSERVER_CONF_CFS_PATHLEN +#define HTTPD_PATHLEN 2 +#else /* WEBSERVER_CONF_CFS_CONNS */ +#define HTTPD_PATHLEN WEBSERVER_CONF_CFS_PATHLEN +#endif /* WEBSERVER_CONF_CFS_CONNS */ + +struct httpd_state; +typedef char (* httpd_simple_script_t)(struct httpd_state *s); + +struct httpd_state { + struct timer timer; + struct psock sin, sout; + struct pt outputpt; + char inputbuf[HTTPD_PATHLEN + 24]; +/*char outputbuf[UIP_TCP_MSS]; */ + char filename[HTTPD_PATHLEN]; + httpd_simple_script_t script; + char state; +}; + +void httpd_init(void); +void httpd_appcall(void *state); + +httpd_simple_script_t httpd_simple_get_script(const char *name); + +#define SEND_STRING(s, str) PSOCK_SEND(s, (uint8_t *)str, strlen(str)) + +#endif /* HTTPD_SIMPLE_H_ */ diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/project-conf.h b/platform/avr-rss2/examples/ipv6/rpl-border-router/project-conf.h new file mode 100644 index 000000000..f1d9e8cda --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-border-router/project-conf.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * 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. + * + */ + +#ifndef PROJECT_ROUTER_CONF_H_ +#define PROJECT_ROUTER_CONF_H_ + +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_MAC nullmac_driver + +#ifndef UIP_FALLBACK_INTERFACE +#define UIP_FALLBACK_INTERFACE rpl_interface +#endif + +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 4 +#endif + +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 600 +#endif + +#ifndef UIP_CONF_RECEIVE_WINDOW +#define UIP_CONF_RECEIVE_WINDOW 60 +#endif + +#ifndef WEBSERVER_CONF_CFS_CONNS +#define WEBSERVER_CONF_CFS_CONNS 2 +#endif + +#endif /* PROJECT_ROUTER_CONF_H_ */ diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/Makefile b/platform/avr-rss2/examples/ipv6/rpl-udp-report/Makefile new file mode 100644 index 000000000..770ad3749 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-udp-report/Makefile @@ -0,0 +1,21 @@ + +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" + +all: report sink +APPS=servreg-hack +CONTIKI=../../../../.. + +ifdef WITH_COMPOWER +APPS+=powertrace +CFLAGS+= -DCONTIKIMAC_CONF_COMPOWER=1 -DWITH_COMPOWER=1 -DQUEUEBUF_CONF_NUM=4 +endif + +ifdef SERVER_REPLY +CFLAGS+=-DSERVER_REPLY=$(SERVER_REPLY) +endif +ifdef PERIOD +CFLAGS+=-DPERIOD=$(PERIOD) +endif + +CONTIKI_WITH_IPV6 = 1 +include $(CONTIKI)/Makefile.include diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/README.md b/platform/avr-rss2/examples/ipv6/rpl-udp-report/README.md new file mode 100644 index 000000000..1f10ff7e5 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-udp-report/README.md @@ -0,0 +1,17 @@ + +This application is derived form rpl-udp. + +It's modified to show: + +* Reading out sensors from the avr-rss2 platform. Which should follow the + Contiki conventions. + +* Encode the data according to the sensd TAG format. In effect the sensd + GW and rest of "eco-system" as Mobile apps etc can be used for a simple + and flexible data collection, Sink mote will be connected to sensd GW. + +References and code: +https://github.com/herjulf/sensd +https://github.com/herjulf/Read-Sensors (Android app. Also at Google Play) + + diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/project-conf.h b/platform/avr-rss2/examples/ipv6/rpl-udp-report/project-conf.h new file mode 100644 index 000000000..b004c6335 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-udp-report/project-conf.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, RAdio Sensors AB, Uppsala Sweden + * 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 + * Project specific configuration defines for example + * + * \author + * Robert Olsson + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_MAC nullmac_driver + +//#define NETSTACK_CONF_MAC csma_driver +//#define NETSTACK_CONF_RDC contikimac_driver +//#define NETSTACK_CONF_FRAMER framer_802154 +//#define NETSTACK_CONF_RADIO rf230_driver + +#endif /* PROJECT_CONF_H_ */ diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 b/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 new file mode 100644 index 000000000..e69de29bb diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c b/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c new file mode 100644 index 000000000..7915dff2f --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c @@ -0,0 +1,240 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include "lib/random.h" +#include "sys/ctimer.h" +#include "net/ip/uip.h" +#include "net/ipv6/uip-ds6.h" +#include "net/ip/uip-udp-packet.h" +#include "sys/ctimer.h" +#include "dev/leds.h" +#include "dev/battery-sensor.h" +#include "dev/temp_mcu-sensor.h" +#include "dev/light-sensor.h" +#ifdef CO2 +#include "dev/co2_sa_kxx-sensor.h" +#endif +#ifdef WITH_COMPOWER +#include "powertrace.h" +#endif +#include +#include + +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +#define UDP_EXAMPLE_ID 190 + +#define DEBUG DEBUG_PRINT +#include "net/ip/uip-debug.h" + +#ifndef PERIOD +#define PERIOD 10 +#endif + +#define START_INTERVAL (15 * CLOCK_SECOND) +#define SEND_INTERVAL (PERIOD * CLOCK_SECOND) +#define SEND_TIME (random_rand() % (SEND_INTERVAL)) +#define MAX_PAYLOAD_LEN 50 + +static struct uip_udp_conn *client_conn; +static uip_ipaddr_t server_ipaddr; + +extern uint16_t node_id; /* Can be set by cooja */ + +/*---------------------------------------------------------------------------*/ +PROCESS(udp_client_process, "UDP client process"); +AUTOSTART_PROCESSES(&udp_client_process); +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + char *str; + + if(uip_newdata()) { + str = uip_appdata; + str[uip_datalen()] = '\0'; + printf("DATA recv '%s'\n", str); + } +} +/*---------------------------------------------------------------------------*/ +static void +send_packet(void *ptr) +{ + static int seq_id; + char buf[MAX_PAYLOAD_LEN]; + int len = 0; + + seq_id++; + + len += snprintf((char *) &buf[len], sizeof(buf), "&: "); + len += snprintf((char *) &buf[len], sizeof(buf), "V_MCU=%-d ", battery_sensor.value(0)); + + /* + * Cooja needs to set a node_id. So we can skip sensor reading in case of simulation. + */ + + if(node_id == 0) { + len += snprintf((char *) &buf[len], sizeof(buf), "T_MCU=%-d ", temp_mcu_sensor.value(0)); + len += snprintf((char *) &buf[len], sizeof(buf), "LIGHT=%-d ", light_sensor.value(0)); +#ifdef CO2 + len += snprintf((char *) &buf[len], sizeof(buf), "CO2=%-d ", co2_sa_kxx_sensor.value(value)); +#endif + } + PRINTF("TX %d to %d %s\n", + server_ipaddr.u8[sizeof(server_ipaddr.u8) - 1], seq_id, buf); + + leds_on(LEDS_YELLOW); + + uip_udp_packet_sendto(client_conn, buf, strlen(buf), + &server_ipaddr, UIP_HTONS(UDP_SERVER_PORT)); +} +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTF("Client IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + /* hack to make address "final" */ + if (state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } +} +/*---------------------------------------------------------------------------*/ +static void +set_global_address(void) +{ + uip_ipaddr_t ipaddr; + + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); + +/* The choice of server address determines its 6LoPAN header compression. + * (Our address will be compressed Mode 3 since it is derived from our link-local address) + * Obviously the choice made here must also be selected in udp-server.c. + * + * For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences, + * e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it. + * (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx) + * + * Note the IPCMV6 checksum verification depends on the correct uncompressed addresses. + */ + +#if 0 +/* Mode 1 - 64 bits inline */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); +#elif 1 +/* Mode 2 - 16 bits inline */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1); +#else +/* Mode 3 - derived from server link-local (MAC) address */ + uip_ip6addr(&server_ipaddr, 0xaaaa, 0, 0, 0, 0x0250, 0xc2ff, 0xfea8, 0xcd1a); //redbee-econotag +#endif +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_client_process, ev, data) +{ + static struct etimer periodic; + static struct ctimer backoff_timer; +#if WITH_COMPOWER + static int print = 0; +#endif + + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + SENSORS_ACTIVATE(battery_sensor); + SENSORS_ACTIVATE(temp_mcu_sensor); + SENSORS_ACTIVATE(light_sensor); +#ifdef CO2 + SENSORS_ACTIVATE(co2_sa_kxx_sensor); +#endif + set_global_address(); + leds_init(); + + PRINTF("UDP client process started\n"); + + print_local_addresses(); + + /* new connection with remote host */ + client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); + if(client_conn == NULL) { + PRINTF("No UDP connection available, exiting the process!\n"); + PROCESS_EXIT(); + } + udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); + + PRINTF("Created a connection with the server "); + PRINT6ADDR(&client_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", + UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); + +#if WITH_COMPOWER + powertrace_sniff(POWERTRACE_ON); +#endif + + etimer_set(&periodic, SEND_INTERVAL); + while(1) { + PROCESS_YIELD(); + if(ev == tcpip_event) { + tcpip_handler(); + } + + if(etimer_expired(&periodic)) { + etimer_reset(&periodic); + ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); + +#if WITH_COMPOWER + if (print == 0) { + powertrace_print("#P"); + } + if (++print == 3) { + print = 0; + } +#endif + + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/rss2-rpl-udp.csc b/platform/avr-rss2/examples/ipv6/rpl-udp-report/rss2-rpl-udp.csc new file mode 100644 index 000000000..b2d599577 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-udp-report/rss2-rpl-udp.csc @@ -0,0 +1,167 @@ + + + [CONTIKI_DIR]/tools/cooja/apps/mrm + [CONTIKI_DIR]/tools/cooja/apps/mspsim + [CONTIKI_DIR]/tools/cooja/apps/avrora + [CONTIKI_DIR]/tools/cooja/apps/native_gateway + [CONTIKI_DIR]/tools/cooja/apps/serial_socket + /home/user/contikiprojects/sics.se/mobility + [CONTIKI_DIR]/tools/cooja/apps/collect-view + /home/user/contikiprojects/sics.se/powertracker + + UDP sink/report simulation + 123456 + 1000000 + + se.sics.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + se.sics.cooja.avrmote.RSS2MoteType + mote1 + Mote1 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c + make report.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.avrmote.interfaces.AvroraClock + se.sics.cooja.avrmote.interfaces.AvroraMoteID + se.sics.cooja.avrmote.interfaces.AvroraUsart0 + se.sics.cooja.avrmote.interfaces.AvroraUsart1 + se.sics.cooja.avrmote.interfaces.RFR2Radio + se.sics.cooja.avrmote.interfaces.AvroraADC + se.sics.cooja.avrmote.interfaces.AvroraLED + + + se.sics.cooja.avrmote.RSS2MoteType + mote2 + Mote2 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c + make sink.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2 + [CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 + se.sics.cooja.interfaces.Position + se.sics.cooja.interfaces.RimeAddress + se.sics.cooja.interfaces.IPAddress + se.sics.cooja.interfaces.Mote2MoteRelations + se.sics.cooja.interfaces.MoteAttributes + se.sics.cooja.avrmote.interfaces.AvroraClock + se.sics.cooja.avrmote.interfaces.AvroraMoteID + se.sics.cooja.avrmote.interfaces.AvroraUsart0 + se.sics.cooja.avrmote.interfaces.AvroraUsart1 + se.sics.cooja.avrmote.interfaces.RFR2Radio + se.sics.cooja.avrmote.interfaces.AvroraADC + se.sics.cooja.avrmote.interfaces.AvroraLED + + + + + se.sics.cooja.interfaces.Position + 100.0 + 100.0 + 0.0 + + + se.sics.cooja.avrmote.interfaces.AvroraMoteID + 1 + + mote1 + + + + + se.sics.cooja.interfaces.Position + 110.0 + 100.0 + 0.0 + + + se.sics.cooja.avrmote.interfaces.AvroraMoteID + 2 + + mote2 + + + + se.sics.cooja.plugins.SimControl + 280 + 9 + 160 + 400 + 0 + + + se.sics.cooja.plugins.Visualizer + + true + se.sics.cooja.plugins.skins.IDVisualizerSkin + se.sics.cooja.plugins.skins.GridVisualizerSkin + 3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074 + + 400 + 5 + 400 + 1 + 1 + + + se.sics.cooja.plugins.LogListener + + + + + + 1269 + 8 + 240 + 400 + 160 + + + se.sics.cooja.plugins.Notes + + Enter notes here + true + + 989 + 6 + 160 + 680 + 0 + + + se.sics.cooja.plugins.MoteInterfaceViewer + 0 + + Serial port + 0,0 + + 508 + 4 + 389 + 13 + 413 + + + se.sics.cooja.plugins.MoteInterfaceViewer + 1 + + Serial port + 0,0 + + 545 + 3 + 392 + 531 + 413 + + diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 b/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 new file mode 100644 index 000000000..e69de29bb diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c b/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c new file mode 100644 index 000000000..cb8421943 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c @@ -0,0 +1,184 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" +#include "net/ip/uip.h" +#include "net/rpl/rpl.h" + +#include "net/netstack.h" +#include "dev/button-sensor.h" +#include "dev/leds.h" +#include +#include +#include +#include + +#define DEBUG DEBUG_PRINT +#include "net/ip/uip-debug.h" + +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) + +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +#define UDP_EXAMPLE_ID 190 + +static struct uip_udp_conn *server_conn; + +PROCESS(udp_server_process, "UDP server process"); +AUTOSTART_PROCESSES(&udp_server_process); +/*---------------------------------------------------------------------------*/ +static void +tcpip_handler(void) +{ + char *appdata; + + if(uip_newdata()) { + + leds_on(LEDS_RED); + + appdata = (char *)uip_appdata; + appdata[uip_datalen()] = 0; + PRINTF("Report RX '%s' from ", appdata); + PRINTF("%d", + UIP_IP_BUF->srcipaddr.u8[sizeof(UIP_IP_BUF->srcipaddr.u8) - 1]); + PRINTF("\n"); +#if SERVER_REPLY + PRINTF("DATA sending reply\n"); + uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr); + uip_udp_packet_send(server_conn, "Reply", sizeof("Reply")); + uip_create_unspecified(&server_conn->ripaddr); +#endif + } +} +/*---------------------------------------------------------------------------*/ +static void +print_local_addresses(void) +{ + int i; + uint8_t state; + + PRINTF("Server IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(state == ADDR_TENTATIVE || state == ADDR_PREFERRED) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n"); + /* hack to make address "final" */ + if (state == ADDR_TENTATIVE) { + uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; + } + } + } +} + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_server_process, ev, data) +{ + uip_ipaddr_t ipaddr; + struct uip_ds6_addr *root_if; + + PROCESS_BEGIN(); + + PROCESS_PAUSE(); + + SENSORS_ACTIVATE(button_sensor); + + leds_init(); + PRINTF("UDP server started\n"); + + +#if UIP_CONF_ROUTER +/* The choice of server address determines its 6LoPAN header compression. + * Obviously the choice made here must also be selected in udp-client.c. + * + * For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences, + * e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it. + * (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx) + * Note Wireshark's IPCMV6 checksum verification depends on the correct uncompressed addresses. + */ + +#if 0 +/* Mode 1 - 64 bits inline */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); +#elif 1 +/* Mode 2 - 16 bits inline */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1); +#else +/* Mode 3 - derived from link local (MAC) address */ + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); +#endif + + uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL); + root_if = uip_ds6_addr_lookup(&ipaddr); + if(root_if != NULL) { + rpl_dag_t *dag; + dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&ipaddr); + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + rpl_set_prefix(dag, &ipaddr, 64); + PRINTF("created a new RPL dag\n"); + } else { + PRINTF("failed to create a new RPL DAG\n"); + } +#endif /* UIP_CONF_ROUTER */ + + print_local_addresses(); + + /* The data sink runs with a 100% duty cycle in order to ensure high + packet reception rates. */ + //NETSTACK_MAC.off(1); + + server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL); + if(server_conn == NULL) { + PRINTF("No UDP connection available, exiting the process!\n"); + PROCESS_EXIT(); + } + udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT)); + + PRINTF("Created a server connection with remote address "); + PRINT6ADDR(&server_conn->ripaddr); + PRINTF(" local/remote port %u/%u\n", UIP_HTONS(server_conn->lport), + UIP_HTONS(server_conn->rport)); + + while(1) { + PROCESS_YIELD(); + if(ev == tcpip_event) { + tcpip_handler(); + } else if (ev == sensors_event && data == &button_sensor) { + PRINTF("Initiaing global repair\n"); + rpl_repair_root(RPL_DEFAULT_INSTANCE); + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/Makefile b/platform/avr-rss2/examples/ipv6/sensd_client/Makefile new file mode 100644 index 000000000..c0eabf9b0 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/sensd_client/Makefile @@ -0,0 +1,12 @@ + +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" + +all: sensd_client server +CONTIKI=../../../../.. + +ifdef PERIOD +CFLAGS+=-DPERIOD=$(PERIOD) +endif + +CONTIKI_WITH_IPV6 = 1 +include $(CONTIKI)/Makefile.include diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/README.md b/platform/avr-rss2/examples/ipv6/sensd_client/README.md new file mode 100644 index 000000000..17beb02f3 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/sensd_client/README.md @@ -0,0 +1,222 @@ +Contiki client for sensd +======================== + +Sensd README describes the concept. sensd code is on github. + + +sensd - A WSN Internet GW, hub, agent, proxy & cloud +==================================================== + +Authors +-------- +Robert Olsson +Jens Laas + +Contributors +------------ + +Abstract +-------- +We've outlined, designed and implemented and very simple concept for WSN +data sharing, including data collection, storage and retrieval using +standard text tools. The concept restricts Internet access to WSN +motes and acts agent not to expose motes directly for robustness and +security reasons. Low level, physical or link WSN protocol can be used. +including 6lowpan, RIME etc and any type of Radio Duty Cycling (RDC). +sensd works on the application layer. A TCP connection initiates an +implicit "subscribe". The M2P model is currently supported. + +Key concepts +------------ + +* Agent. sensd works as an agent and does not allow direct Internet + access to motes. Recall motes are constrained in most aspects and + can not support many connections, has weak security etc. + +* Hub. Share the data from the root or sink node over TCP. In effect sensor + data can be sent over Internet to be shared over among TCP active listeners. + The TCP connection initiates an implicit "subscribe". + +* Proxy. The support proxy functions over ipv4 and well as ipv6. Sensd can + forward to a proxy on a public IP. The typical case is when GW is behind + a NAT. + +* WSN RP "rendez-vous point". A concepts where data from various WSN nets + are merged. This models a "cloud service" functionality for WSN networks. + sensd can be used both to forward data to RP. It can also work as the RP. + RP receiving WSN data and allowing multiple TCP listeners. + +* All programs are written C, script in Java and bash. Designed for small + footprint and with minimal dependencies. sensd runs on Raspberry Pi and + Openwrt. + +* This work introduces a simple tag format for sensor data. The overall + idea is that data tagging is an "agreement" between producers and consumer. + Tags are simple are description of the data. Example T=25.2. where T= + is the tag 25.2 the value. Most likely this a temperature. But we + can't be sure since we don't know since this is an agreement between + the producer and the consumer. Tags are also used for identification. + Example tags, E64= Where globally unique ID can used. Another more + relaxed example is TXT= a user description. See docs. + +* Geotagging and timestamping is supported via tags. + +* Ecosystem support. There are telphone apps to for data monitoring and + and plotting. Android app can act as WSN-agent and forward to proxy/RP. + +* The concept also includes a mapping to URI (Unified Resource Identifier) + to form a WSN caching server similar to CoAP using http-proxy. + +* Copyright. Open-Source via GPL. Projecet used github.com + + +Introduction +------------ + +This is collection of software to implement data monitoring and data collection +from WSN Wireless Sensor Networks. The goal is to have a very simple, +straight-forward and robust framework. + +The scenario: One or several motes is connected to USB or serial port to gather +received information from connected WSN motes. Data can be visualized in +several ways. + +* Sensor data report can be transmitted and propagated throughout the + Internet. sensd acts as server and sends incoming report to active + listeners. + +* Data is kept in ASCII with tagging and ID information. Data is conveniently + handled, copied and viewed with standard text utilities of your OS. + +* Last mote report is cached into the file system suitable for URI use. The + Format is SID/TAG. Typical tags are EUI64 and unique serial numbers. The + different TAGS are left for mote user to define. Although the TAGS used in + our example setup are included in this draft for example purposes. + + +Both formats can easily be stored or linked directly in web tree to form a +URI to format WSN logging/datafile or caching service. + +A daemon that reads WSN mote reports from USB/serial and stores data in a ASCII +data file. Default is located at _/var/log/sensors.dat_ + +Addtional components +-------------------- + +* seltag [More info] (https://github.com/herjulf/sensd/blob/master/seltag/README.md) + +* js A set of Java-scripts can plot, print and visualize sensor data from + sensd directly in your web-browser. + +* documentation and sample files. [More info] (https://github.com/herjulf/sensd/blob/master/seltag/README.md) + +* Read Sensors Android app. [Source Code] (https://github.com/herjulf/Read-Sensors) + + +Datafile logging +---------------- + +Below is and example of the anatomy of a sensors.dat file we are currently using in our WSN +data collection networks. + + 2012-05-22 14:07:46 UT=1337688466 ID=283c0cdd030000d7 PS=0 T=30.56 T_MCU=34.6 V_MCU=3.08 UP=2C15C V_IN=4.66 + + 2012-05-22 14:11:41 UT=1337688701 ID=28a9d5dc030000af PS=0 T=36.00 V_MCU=2.92 UP=12C8A0 RH=42.0 V_IN=4.13 V_A1=3.43 [ADDR=0.175 SEQ=33 RSSI=21 LQI=255 DRP=1.00] + +Each line is a mote report. They start with date and time and are followed by a set of +tags. The tags is different for different motes. In other words they can +send different data. Essential is the ID which should be unique for each mote. + +The information with brackets is information generated by the receiving mote +and is not a part the motes data. Typically RSSI (Receiver Signal Strength +Indicator) and LQI (Link Quality Indicator) + + +Internet sensor data +-------------------- + +Start sensd with the `-report` option. This enables reports to be transmitted +over IP to remote listeners. Default TCP port 1234. + +Server side example: + + sensd -report -p 1234 -D /dev/ttyUSB0 + +Client side. Example using netcat: + + nc server-ip 1234 + +URI format +---------- + +URI (Unified Resource Identifier) displays the node ID and the tags in a file tree. +It is easy to export this into a web tree to form a URI similar to a CoAP gateway. + +Example: In our case we have a unique sensor ID followed by the different data +fields represented by "tags". + + /tmp/WSN1-GW1/281a98d20200004a: + DRP ID LQI PS RH RSSI SEQ T V_IN V_MCU ADDR + + /tmp/WSN1-GW1/28be51ce02000031: + DRP ID LQI PS RH RSSI SEQ T UP V_IN V_MCU ADDR + +Read Temp from a sensor: + + cat /tmp/WSN1-GW1/281a98d20200004a/T + 19.44 + +And it's very easy to link this tree into a web-server. + +GPS support +----------- + +Positioning support has been added via GPS device connected to serial +or USB port. Tags added when enabled GWGPS_LON & GWGPS_LAT. +GPS code from. https://github.com/herjulf/gps_simple + +Getting the source and building +------------------------------- + +Code is stored in github. Typically procedure below is the very straight- +forward unix way: + + git clone http://github.com/herjulf/sensd + cd sensd + make + +Put your binaries after your preference: + +Pre-built binary versions +-------------------------- + +For x86: +Sensd and friends are available in Bifrost/Linux packages. Those packages are +statically linked and can be used on most x86 Linuxes. 32-bit compiled. + +http://ftp.sunet.se/pub/Linux/distributions/bifrost/download/opt/opt-sensd-2.3-1.tar.gz + + +Use +--- + +The WSN data logging and caching concept is in actual use with Contiki, RIME +broadcast application. + +Tips +---- + +One can use netcat to listen to reports: + +Example: + + nc radio-sensors.com 1235 + +To save in file use nohup: + + nohup nc radio-sensors.com 1235 > /var/log/sensors.dat + +As sensd used TCP and ASCII encoding. tetlnet and web-browsers can be used +as well. + + diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h b/platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h new file mode 100644 index 000000000..b004c6335 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, RAdio Sensors AB, Uppsala Sweden + * 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 + * Project specific configuration defines for example + * + * \author + * Robert Olsson + */ + +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_MAC nullmac_driver + +//#define NETSTACK_CONF_MAC csma_driver +//#define NETSTACK_CONF_RDC contikimac_driver +//#define NETSTACK_CONF_FRAMER framer_802154 +//#define NETSTACK_CONF_RADIO rf230_driver + +#endif /* PROJECT_CONF_H_ */ diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c b/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c new file mode 100644 index 000000000..b523e87c4 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-12-28 + */ + +/** + * \file + * A simple application reporting sensor data. Can be sensd + */ + +#include +#include "contiki-net.h" +#include "leds.h" +#include "dev/leds.h" +#include "dev/battery-sensor.h" +#include "dev/temp_mcu-sensor.h" +#include "dev/light-sensor.h" +#ifdef CO2 +#include "dev/co2_sa_kxx-sensor.h" +#endif + +#ifndef PERIOD +#define PERIOD 10 +#endif + +#define REPORT_INTERVAL (PERIOD * CLOCK_SECOND) + +#define DEBUG DEBUG_PRINT +#include "uip-debug.h" + +#define PORT 1236 +#define MAX_PAYLOAD_LEN 80 + +static struct psock ps; +static uint8_t out_buf[MAX_PAYLOAD_LEN]; +static char in_buffer[MAX_PAYLOAD_LEN]; +static int i; +static int send_now; +static clock_time_t report_interval = REPORT_INTERVAL; +static uint8_t state; +static uip_ipaddr_t addr; +static struct timer t, t1; +static struct etimer et, et1; + +PROCESS(sensd_client_process, "sensd TCP client process"); +PROCESS(report_timer_process, "report pacemaker"); +AUTOSTART_PROCESSES +(&sensd_client_process,&report_timer_process); + +static int +do_report(void) +{ + static int seq_id; + int len = 0; + + seq_id++; + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "&: "); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TXT=6LOWPAN "); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TARGET=avr-rss2 "); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "V_MCU=%-d ", battery_sensor.value(0)); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "T_MCU=%-d ", temp_mcu_sensor.value(0)); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "LIGHT=%-d ", light_sensor.value(0)); +#ifdef CO2 + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "CO2=%-d ", co2_sa_kxx_sensor.value(value)); +#endif + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "\n\r"); + + return len; +} + +static void +print_local_addresses(void) +{ + PRINTF("Server IPv6 addresses:\n\r"); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n\r"); + } + } +} + +static void +set_global_address(void) +{ + uip_ipaddr_t ipaddr; + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); +} + +static int handle_connection(struct psock *p, long ts) { + PSOCK_BEGIN(p); + if(send_now) { + do_report(); + leds_on(LEDS_YELLOW); + PSOCK_SEND(p, (const uint8_t *) out_buf, strlen((const char *) out_buf)); + send_now = 0; + } + PSOCK_END(p); +} + +PROCESS_THREAD(report_timer_process, ev, data) { + PROCESS_BEGIN(); + while(1) { + timer_set(&t1, report_interval); + etimer_set(&et1, timer_remaining(&t1)); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et1)); + send_now = 1; + leds_on(LEDS_RED); + } + PROCESS_END(); +} + +PROCESS_THREAD(sensd_client_process, ev, data) { + PROCESS_BEGIN(); + + set_global_address(); + leds_init(); + print_local_addresses(); + printf("Starting TCP client on port=%d\n", PORT); + + /* Set server address. typically sensd */ + //uip_ip6addr(&addr, 0xfe80, 0, 0, 0, 0xfec2, 0x3d00, 1, 0x63ae); + uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0201); + //uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0255); + + random_init(50); + + while(1) { + + /* Delay connection attempts */ + timer_set(&t, 2*CLOCK_SECOND); + etimer_set(&et, timer_remaining(&t)); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + + /* Time out teh actual connection attempt */ + timer_set(&t, 10*CLOCK_SECOND); + printf("Connecting"); + tcp_connect(&addr, UIP_HTONS(PORT), NULL); + PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); + + if(uip_aborted() || uip_timedout() || uip_closed()) { + printf(" Failed\n"); + } else if(uip_connected()) { + printf(" Success\n"); + PSOCK_INIT(&ps, (uint8_t *)in_buffer, sizeof(in_buffer)); + do { + handle_connection(&ps, clock_seconds()); + PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); + } while(!(uip_closed() || uip_aborted() || uip_timedout())); + printf("Disconnected\n"); + } + } + PROCESS_END(); +} diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/server.c b/platform/avr-rss2/examples/ipv6/sensd_client/server.c new file mode 100644 index 000000000..c2dea4514 --- /dev/null +++ b/platform/avr-rss2/examples/ipv6/sensd_client/server.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, Copyright Robert Olsson / Radio Sensors AB + * 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. + * + * + * Author : Robert Olsson robert@radio-sensors.com + * Created : 2015-12-28 + */ + +/** + * \file + * A simple TCP server for client app. + */ + +#include +#include "contiki-net.h" +#include "leds.h" + +#define DEBUG DEBUG_PRINT +#include "uip-debug.h" + +#define PORT 1236 + +static struct psock ps; +static uint8_t buf[120]; +static int i; +static uint8_t state; + +static void +print_local_addresses(void) +{ + PRINTF("Server IPv6 addresses:\n\r"); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + PRINTF("\n\r"); + } + } +} + +static void +set_global_address(void) +{ + uip_ipaddr_t ipaddr; + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); +} + +static +PT_THREAD(handle_connection(struct psock *p)) +{ + PSOCK_BEGIN(p); + //PSOCK_SEND_STR(p, "Type something!\n"); + leds_on(LEDS_RED); + PSOCK_READTO(p, '\n'); + printf("RX=%s", buf); + //PSOCK_SEND_STR(p, "Got: "); + //PSOCK_SEND(p, buf, PSOCK_DATALEN(p)); + //PSOCK_SEND_STR(p, "EOL\r\n"); + //PSOCK_CLOSE(p); + PSOCK_END(p); +} + +PROCESS(server_process, "Server"); +AUTOSTART_PROCESSES(&server_process); + +PROCESS_THREAD(server_process, ev, data) +{ + PROCESS_BEGIN(); + + set_global_address(); + leds_init(); + print_local_addresses(); + printf("Starting TCP server on port=%d\n", PORT); + tcp_listen(UIP_HTONS(PORT)); + + while(1) { + PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); + + if(uip_aborted() ) + printf("TCP aborted\n"); + if(uip_timedout() ) + printf("TCP timeoutn\n"); + if(uip_closed() ) + printf("TCP closed\n"); + + if(uip_connected()) { + printf("TCP Connected\n\r"); + PSOCK_INIT(&ps, buf, sizeof(buf)); + + while(!(uip_aborted() || uip_closed() || uip_timedout())) { + PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); + handle_connection(&ps); + } + } + } + PROCESS_END(); +} + diff --git a/platform/avr-rss2/ip64-conf.h b/platform/avr-rss2/ip64-conf.h new file mode 100644 index 000000000..26c51a55f --- /dev/null +++ b/platform/avr-rss2/ip64-conf.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, Thingsquare, http://www.thingsquare.com/. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef IP64_CONF_H +#define IP64_CONF_H + +#include "net/ip64/ip64-eth-interface.h" +#include "dev/enc28j60/enc28j60-ip64-driver.h" +#define IP64_CONF_UIP_FALLBACK_INTERFACE ip64_eth_interface +#define IP64_CONF_INPUT ip64_eth_interface_input +#define IP64_CONF_DHCP 1 +#define IP64_CONF_ETH_DRIVER enc28j60_ip64_driver + +#endif /* IP64_CONF_H */ diff --git a/platform/avr-rss2/params.c b/platform/avr-rss2/params.c new file mode 100644 index 000000000..f2ae2abfc --- /dev/null +++ b/platform/avr-rss2/params.c @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2011, Swedish Institute of Computer Science. + * 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. + * + */ +#define PRINTF(FORMAT, args ...) printf_P(PSTR(FORMAT),##args) + +#define DEBUG 1 +#if DEBUG +#define PRINTD(FORMAT, args ...) printf_P(PSTR(FORMAT),##args) +#else +#define PRINTD(...) +#endif + +#include "contiki.h" +#include +#include +#include +#include + +#if AVR_WEBSERVER +/* #include "httpd-fs.h" */ +/* #include "httpd-cgi.h" */ +#endif + +#include "contiki-net.h" +#include "params.h" + +#if CONTIKI_CONF_RANDOM_MAC +extern uint8_t rng_get_uint8(void); +static void +generate_new_eui64(uint8_t eui64[8]) +{ + eui64[0] = 0x02; + eui64[1] = rng_get_uint8(); + eui64[2] = rng_get_uint8(); + eui64[3] = 0xFF; + eui64[4] = 0xFE; + eui64[5] = rng_get_uint8(); + eui64[6] = rng_get_uint8(); + eui64[7] = rng_get_uint8(); +} +#endif + +#if AVR_WEBSERVER +/* Webserver builds can set these in httpd-fsdata.c via makefsdata.h */ +extern uint8_t default_mac_address[8]; +extern uint8_t default_server_name[16]; +extern uint8_t default_domain_name[30]; +#else +const uint8_t default_mac_address[8] PROGMEM = PARAMS_EUI64ADDR; +const uint8_t default_server_name[] PROGMEM = PARAMS_SERVERNAME; +const uint8_t default_domain_name[] PROGMEM = PARAMS_DOMAINNAME; +#endif + +#if PARAMETER_STORAGE == 0 +/* 0 Hard coded, minmal program and eeprom usage. */ +uint8_t +params_get_eui64(uint8_t *eui64) +{ +#if CONTIKI_CONF_RANDOM_MAC + PRINTD("Generating random EUI64 MAC\n"); + generate_new_eui64(eui64); + return 1; +#else + uint8_t i; + for(i = 0; i < sizeof(default_mac_address); i++) { + eui64[i] = pgm_read_byte_near(default_mac_address + i); + } + return 0; +#endif +} +#elif PARAMETER_STORAGE == 1 +/* 1 Stored in fixed eeprom locations, rewritten from flash if corrupt. + * They can be manually changed and kept over program reflash. + * The channel and bit complement are used to check EEMEM integrity, + * If corrupt all values will be rewritten with the default flash values. + * To make this work, get the channel before anything else. + */ +#if !AVR_WEBSERVER +uint8_t eemem_mac_address[] EEMEM = PARAMS_EUI64ADDR; +uint8_t eemem_server_name[] EEMEM = PARAMS_SERVERNAME; +uint8_t eemem_domain_name[] EEMEM = PARAMS_DOMAINNAME; +#endif /*AVR_WEBSERVER */ + +uint16_t eemem_nodeid EEMEM = PARAMS_NODEID; +uint8_t eemem_channel[2] EEMEM = { PARAMS_CHANNEL, ~PARAMS_CHANNEL }; +uint16_t eemem_panid EEMEM = PARAMS_PANID; +uint16_t eemem_panaddr EEMEM = PARAMS_PANADDR; +uint8_t eemem_txpower EEMEM = PARAMS_TXPOWER; + +#if CONTIKI_CONF_RANDOM_MAC +static uint8_t randomeui64; +#endif + +uint8_t +params_get_channel(void) +{ + uint8_t x[2]; + *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel); +/* Don't return an invalid channel number */ + if((x[0] < 11) || (x[0] > 26)) { + x[1] = x[0]; + } +/* Do exclusive or test on the two values read */ + if((uint8_t)x[0] != (uint8_t) ~x[1]) { /* ~x[1] can promote comparison to 16 bit */ +/* Verification fails, rewrite everything */ + uint8_t i, buffer[32]; + PRINTD("EEPROM is corrupt, rewriting with defaults.\n"); +#if CONTIKI_CONF_RANDOM_MAC + PRINTD("Generating random EUI64 MAC\n"); + generate_new_eui64(&buffer); + randomeui64 = 1; +#else + for(i = 0; i < sizeof(default_mac_address); i++) { + buffer[i] = pgm_read_byte_near(default_mac_address + i); + } +#endif +/* eeprom_write_block should not be interrupted */ + cli(); + eeprom_write_block(&buffer, &eemem_mac_address, sizeof(eemem_mac_address)); + for(i = 0; i < sizeof(default_server_name); i++) { + buffer[i] = pgm_read_byte_near(default_server_name + i); + } + eeprom_write_block(&buffer, &eemem_server_name, sizeof(eemem_server_name)); + for(i = 0; i < sizeof(default_domain_name); i++) { + buffer[i] = pgm_read_byte_near(default_domain_name + i); + } + eeprom_write_block(&buffer, &eemem_domain_name, sizeof(eemem_domain_name)); + eeprom_write_word(&eemem_panid, PARAMS_PANID); + eeprom_write_word(&eemem_panaddr, PARAMS_PANADDR); + eeprom_write_byte(&eemem_txpower, PARAMS_TXPOWER); + eeprom_write_word(&eemem_nodeid, PARAMS_NODEID); + x[0] = PARAMS_CHANNEL; + x[1] = ~x[0]; + eeprom_write_word((uint16_t *)&eemem_channel, *(uint16_t *)x); + sei(); + } +/* Always returns a valid channel */ + return x[0]; +} +uint8_t +params_get_eui64(uint8_t *eui64) +{ + cli(); + eeprom_read_block((void *)eui64, &eemem_mac_address, sizeof(linkaddr_t)); + sei(); +#if CONTIKI_CONF_RANDOM_MAC + return randomeui64; +#else + return 0; +#endif +} +uint16_t +params_get_panid(void) +{ + return eeprom_read_word(&eemem_panid); +} +uint16_t +params_get_panaddr(void) +{ + return eeprom_read_word(&eemem_panaddr); +} +uint8_t +params_get_txpower(void) +{ + return eeprom_read_byte(&eemem_txpower); +} +#else /* CONTIKI_CONF_SETTINGS_MANAGER */ + +uint8_t +params_get_channel() +{ + uint8_t x; + size_t size = 1; + if(settings_get(SETTINGS_KEY_CHANNEL, 0, (unsigned char *)&x, &size) == SETTINGS_STATUS_OK) { + PRINTD("<-Get RF channel %u\n", x); + } else { + x = PARAMS_CHANNEL; + if(settings_add_uint8(SETTINGS_KEY_CHANNEL, x) == SETTINGS_STATUS_OK) { + PRINTD("->Set EEPROM RF channel to %d\n", x); + } + } + return x; +} +uint8_t +params_get_eui64(uint8_t *eui64) +{ + size_t size = sizeof(linkaddr_t); + if(settings_get(SETTINGS_KEY_EUI64, 0, (unsigned char *)eui64, &size) == SETTINGS_STATUS_OK) { + PRINTD("<-Get EUI64 MAC\n"); + return 0; + } +#if CONTIKI_CONF_RANDOM_MAC + PRINTD("Generating random EUI64 MAC\n"); + generate_new_eui64(eui64); +#else + { uint8_t i; + for(i = 0; i < 8; i++) { + eui64[i] = pgm_read_byte_near(default_mac_address + i); + } + } /* test this */ +#endif + if(settings_add(SETTINGS_KEY_EUI64, (unsigned char *)eui64, 8) == SETTINGS_STATUS_OK) { + PRINTD("->Set EEPROM MAC address\n"); + } +#if CONTIKI_CONF_RANDOM_MAC + return 1; +#else + return 0; +#endif +} +uint16_t +params_get_panid(void) +{ + uint16_t x; + size_t size = 2; + if(settings_get(SETTINGS_KEY_PAN_ID, 0, (unsigned char *)&x, &size) == SETTINGS_STATUS_OK) { + PRINTD("<-Get PAN ID of %04x\n", x); + } else { + x = PARAMS_PANID; + if(settings_add_uint16(SETTINGS_KEY_PAN_ID, x) == SETTINGS_STATUS_OK) { + PRINTD("->Set EEPROM PAN ID to %04x\n", x); + } + } + return x; +} +uint16_t +params_get_panaddr(void) +{ + uint16_t x; + size_t size = 2; + if(settings_get(SETTINGS_KEY_PAN_ADDR, 0, (unsigned char *)&x, &size) == SETTINGS_STATUS_OK) { + PRINTD("<-Get PAN address of %04x\n", x); + } else { + x = PARAMS_PANADDR; + if(settings_add_uint16(SETTINGS_KEY_PAN_ADDR, x) == SETTINGS_STATUS_OK) { + PRINTD("->Set EEPROM PAN address to %04x\n", x); + } + } + return x; +} +uint8_t +params_get_txpower(void) +{ + uint8_t x; + size_t size = 1; + if(settings_get(SETTINGS_KEY_TXPOWER, 0, (unsigned char *)&x, &size) == SETTINGS_STATUS_OK) { + PRINTD("<-Get tx power of %d (0=max)\n", x); + } else { + x = PARAMS_TXPOWER; + if(settings_add_uint8(SETTINGS_KEY_TXPOWER, x) == SETTINGS_STATUS_OK) { + PRINTD("->Set EEPROM tx power of %d (0=max)\n", x); + } + } + return x; +} +#endif /* CONTIKI_CONF_SETTINGS_MANAGER */ diff --git a/platform/avr-rss2/params.h b/platform/avr-rss2/params.h new file mode 100644 index 000000000..95150333b --- /dev/null +++ b/platform/avr-rss2/params.h @@ -0,0 +1,108 @@ +#ifndef __PARAMS_H__ +#define __PARAMS_H__ +/* PARAMETER_STORAGE = + * 0 Hard coded, minmal program and eeprom usage. + * 1 Stored in fixed eeprom locations, rewritten from flash if corrupt. + * This allows parameter changes using a hardware programmer or custom application code. + * Corruption test is based on channel verify so get the channel before anything else! + * 2 Obtained from eeprom using the general settings manager and read from program flash if not present. + * Useful for for testing builds without wearing out flash memory. + * 3 Obtained from eeprom using the settings manager and rewritten from flash if not present. + * This ensures all parameters are present in upper eeprom flash. + * + * Note the parameters in this file can be changed without forcing a complete rebuild. + */ +#define CONTIKI_CONF_RANDOM_MAC 0 /* adds 78 bytes */ +#define CONTIKI_CONF_SETTINGS_MANAGER 0 /* adds 1696 bytes */ + +#if CONTIKI_CONF_SETTINGS_MANAGER +/* #define PARAMETER_STORAGE 2 */ +#define PARAMETER_STORAGE 2 +#else +#define PARAMETER_STORAGE 1 +#endif + +/* Include settings.h, then dummy out the write routines */ +#include "settings.h" +#if PARAMETER_STORAGE == 2 +#define settings_add(...) 0 +#define settings_add_uint8(...) 0 +#define settings_add_uint16(...) 0 +#endif + +#if AVR_WEBSERVER +/* Webserver builds can set some defaults in httpd-fsdata.c via makefsdata.h */ +extern uint8_t eemem_mac_address[8]; +extern uint8_t eemem_server_name[16]; +extern uint8_t eemem_domain_name[30]; +#endif + +#ifdef SERVER_NAME +#define PARAMS_SERVERNAME SERVER_NAME +#else +#define PARAMS_SERVERNAME "ATMEGA256rfr2" +#endif +#ifdef DOMAIN_NAME +#define PARAMS_DOMAINNAME DOMAIN_NAME +#else +#define PARAMS_DOMAINNAME "localhost" +#endif +#ifdef NODE_ID +#define PARAMS_NODEID NODE_ID +#else +#define PARAMS_NODEID 0 +#endif +#ifdef CHANNEL_802_15_4 +#define PARAMS_CHANNEL CHANNEL_802_15_4 +#else +#define PARAMS_CHANNEL 26 +#endif +#ifdef IEEE802154_PANID +#define PARAMS_PANID IEEE802154_PANID +#else +#define PARAMS_PANID 0xABCD +#endif +#ifdef IEEE802154_PANADDR +#define PARAMS_PANADDR IEEE802154_PANADDR +#else +#define PARAMS_PANADDR 0 +#endif +#ifdef RF230_MAX_TX_POWER +#define PARAMS_TXPOWER RF230_MAX_TX_POWER +#else +#define PARAMS_TXPOWER 0 +#endif +#ifdef EUI64_ADDRESS +#define PARAMS_EUI64ADDR EUI64_ADDRESS +#else +/* This form of of EUI64 mac allows full 6LoWPAN header compression from mac address */ +#if UIP_CONF_LL_802154 +/* #define PARAMS_EUI64ADDR {0x02, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN, 0xNN} */ +#define PARAMS_EUI64ADDR { 0x02, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01 } +#else +/* #define PARAMS_EUI64ADDR {0x02, 0xNN, 0xNN, 0xff, 0xfe, 0xNN, 0xNN, 0xNN} */ +#define PARAMS_EUI64ADDR { 0x00, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x01 } +#endif +/* This form of of EUI64 mac allows 16 bit 6LoWPAN header compression on multihops */ +/* #define PARAMS_EUI64ADDR {0x02, 0x00, 0x00, 0xff, 0xfe, 0x00, 0xNN, 0xNN} */ +#endif + +uint8_t params_get_eui64(uint8_t *eui64); +#if PARAMETER_STORAGE == 0 +/* Hard coded program flash parameters */ +#define params_get_servername(...) +#define params_get_nodeid(...) PARAMS_NODEID +#define params_get_channel(...) PARAMS_CHANNEL +#define params_get_panid(...) PARAMS_PANID +#define params_get_panaddr(...) PARAMS_PANADDR +#define params_get_txpower(...) PARAMS_TXPOWER +#else +/* Parameters stored in eeprom */ +uint16_t params_get_nodeid(void); +uint8_t params_get_channel(void); +uint16_t params_get_panid(void); +uint16_t params_get_panaddr(void); +uint8_t params_get_txpower(void); +#endif + +#endif /* __PARAMS_H__ */ diff --git a/platform/avr-rss2/rss2.h b/platform/avr-rss2/rss2.h new file mode 100644 index 000000000..46ade3822 --- /dev/null +++ b/platform/avr-rss2/rss2.h @@ -0,0 +1,36 @@ + +/* + Pin assigments for Radio Sensors board revision 2.3 + using MCU AtMega128rfa1 + */ + +#define ISP_1 PB1 /* SCK */ +#define ISP_2 PB2 /* MOSI */ +#define ISP_3 PB3 /* MISO */ + +#define LED_YELLOW PE3 /* 1k pullup to Vcc */ +#define LED_RED PE4 /* 1k pullup to Vcc */ +#define USB_PWR PB5 /* High if FTDI TTL-USB cable sources */ +#define P0 PD2 /* Pulse count input. Pullup via jumper */ +#define P1 PD3 /* Pulse count input via optional Comparator */ +#define PWR_1 PE7 /* Programmable power pin Vcc via P-FET */ + +#define AV_IN PF0 /* V_IN ADC input. 100k/1M volt. divider */ +#define A1 PF1 /* A1 ADC input. 100k/300k volt. divider */ +#define A2 PF2 /* A2 ADC input 100k/300k volt. divider */ +#define A3 PF3 /* Light sensor A3 ADC input 100k/100k volt. divider */ +#define A3_PWR PF4 /* Light sensor power A3_PWR */ + +#define RX0 PE0 /* RX UART0 -- FTDI TTL-USB cable */ +#define TX0 PE1 /* TX UART0 -- FTDI TTL-USB cable */ + +#define OW_BUS_0 PD7 /* One-Wire bus w temp/ID Pulled Up. Separate Vcc */ +#define OW_BUS_1 PD6 /* One-Wire bus extra Pulled Up. Separate Vcc */ + +/* AVR ISP standard connected */ +/* 16 MHz xtal */ +/* RTC 32.768 Hz xtal */ + +/*Optional HIH610 connected on SPI */ +#define HUM_PWR PE2 /* Power pin for HIH6130 also to ena. HIH 6130 Alarm mode */ + diff --git a/platform/avr-rss2/slip_uart0.c b/platform/avr-rss2/slip_uart0.c new file mode 100644 index 000000000..8f064f980 --- /dev/null +++ b/platform/avr-rss2/slip_uart0.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2010, University of Colombo School of Computing + * 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 + * Machine dependent AVR SLIP routines for UART0. + * \author + * Kasun Hewage + */ + +#include +#include "contiki.h" +#include "dev/rs232.h" +#include "slip.h" + +/*---------------------------------------------------------------------------*/ +static int +slip_putchar(char c, FILE *stream) +{ +#define SLIP_END 0300 + static char debug_frame = 0; + + if(!debug_frame) { /* Start of debug output */ + slip_arch_writeb(SLIP_END); + slip_arch_writeb('\r'); /* Type debug line == '\r' */ + debug_frame = 1; + } + + slip_arch_writeb((unsigned char)c); + + /* + * Line buffered output, a newline marks the end of debug output and + * implicitly flushes debug output. + */ + if(c == '\n') { + slip_arch_writeb(SLIP_END); + debug_frame = 0; + } + + return c; +} +/*---------------------------------------------------------------------------*/ +static FILE slip_stdout = FDEV_SETUP_STREAM(slip_putchar, NULL, + _FDEV_SETUP_WRITE); +/*---------------------------------------------------------------------------*/ +void +slip_arch_init(unsigned long ubr) +{ + rs232_set_input(SLIP_PORT, slip_input_byte); + stdout = &slip_stdout; +} +/*---------------------------------------------------------------------------*/ +/* + XXX: + Currently, the following function is in cpu/avr/dev/rs232.c file. this + should be moved to here from there hence this is a platform specific slip + related function. + void + slip_arch_writeb(unsigned char c) + { + rs232_send(RS232_PORT_0, c); + } + */ From 42e7a6a7e1f9427239e0916b9a8a021ccab4c663 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Mon, 22 Feb 2016 20:50:49 +0100 Subject: [PATCH 03/14] Adding travis regression compile test for the avr-rss2 platform. --- .travis.yml | 7 ++++++- regression-tests/23-compile-avr/Makefile | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 regression-tests/23-compile-avr/Makefile diff --git a/.travis.yml b/.travis.yml index 3a035fd2e..f00dc2f9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,11 @@ before_script: msp430-gcc --version ## Install avr toolchain - - sudo apt-get -qq install gcc-avr avr-libc + - $WGET http://atiselsts.github.io/resources/avr-gcc-4.9.2-compiled.tar.bz2 && + tar xjf avr-gcc*.tar.bz2 -C /tmp/ && + sudo cp -f -r /tmp/avr-gcc/* /usr/local/ && + rm -rf /tmp/avr-gcc avr-gcc*.tar.bz2 && + avr-gcc --version ## Install 32-bit compatibility libraries - sudo apt-get -qq install libc6:i386 libgcc1:i386 gcc-4.6-base:i386 @@ -140,3 +144,4 @@ env: - BUILD_TYPE='compile-nxp-ports' BUILD_CATEGORY='compile' BUILD_ARCH='jn516x' - BUILD_TYPE='slip-radio' MAKE_TARGETS='cooja' - BUILD_TYPE='llsec' MAKE_TARGETS='cooja' + - BUILD_TYPE='compile-avr' BUILD_CATEGORY='compile' BUILD_ARCH='avr-rss2' diff --git a/regression-tests/23-compile-avr/Makefile b/regression-tests/23-compile-avr/Makefile new file mode 100644 index 000000000..0904e2f37 --- /dev/null +++ b/regression-tests/23-compile-avr/Makefile @@ -0,0 +1,15 @@ +EXAMPLESDIR=../.. +TOOLSDIR=../../tools + +# build avr-rss2 examples, covering IPv6, RPL, Rime, Nullrdc, Contikimac + +EXAMPLES = \ +platform/avr-rss2/examples/hello-sensors/avr-rss2 \ +platform/avr-rss2/examples/ipv6/rpl-udp-report/avr-rss2 \ +platform/avr-rss2/examples/ipv6/rpl-border-router/avr-rss2 \ +examples/ipv6/rpl-udp/avr-rss2 \ +examples/powertrace/avr-rss2 \ +examples/rime/avr-rss2 +TOOLS= + +include ../Makefile.compile-test From d8f2129b17b0dbb7dbd184850b1565373f4ab44b Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 23 Feb 2016 11:28:50 +0200 Subject: [PATCH 04/14] avr-rss2 platform: Update README.md --- platform/avr-rss2/README.md | 100 ++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/platform/avr-rss2/README.md b/platform/avr-rss2/README.md index 260a7d4bb..05d448fc6 100644 --- a/platform/avr-rss2/README.md +++ b/platform/avr-rss2/README.md @@ -7,15 +7,15 @@ The platform supports different AtMega-RF boards: * Based on MCU AtMega256RFR2 * Based on MCU AtMega128RFA1 -Boards looks the same. "Made in EU" labeled on the AtMega256RFR2 boards +Boards all looks the same. AtMega256RFR2 boards are labeled with "Made in EU". The platform and CPU code, are common for both boards, can be found under -`$(CONTIKI)/platfrom/avr-rssa. The port was developed and tested with RSS2. +`$(CONTIKI)/platfrom/avr-rssa`. The port was developed and tested with RSS2. This guide assumes that you have basic understanding of how to use the -command line and perform basic admin tasks on UNIX family OSs. You should' +command line and perform basic admin tasks on UNIX family OSs. You should also have understanding about the Contiki OS design as well have C programming skills. -Boards Features +Board Features ---------------- * Chip Antenna. Supercardiod. * Robust radio performance. Up to 300 meter line-of-sight. @@ -29,10 +29,9 @@ Boards Features * Standard. 6-pin TTL-USB header for FTDI cable for UART. * PCB formfactor for cheap project box G.40X IP54 * Power/current: - ** RX ~10mA (Full RPC AtMegaXXRFR2). - ** Sleep ~45uA @ 16MHz XTAL - ** Sleep ~15uA @ 8MHz using internal oscillator - + * RX ~10mA (Full RPC AtMegaXXRFR2). + * Sleep ~45uA @ 16MHz XTAL + * Sleep ~15uA @ 8MHz using internal oscillator * Preprogammed bootloader. * CE certified by test institute. @@ -56,33 +55,33 @@ Note. The native OS packages does not yet support the new AtMega256RfR2 MCU. We'll use toolchain from Atmels web-site. You might also consider -Instant Contiki +Instant Contiki. -* For Linux. -See http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORLINUX.aspx -Download the proper 8-bit platform 32 or 64 bit. -Unpack unpack under /usr/local -Also add to your search PATH. For example .bashrc add: -export PATH=$PATH:/usr/local/avr8-gnu-toolchain-linux_x86/bin -or -export PATH=$PATH:/usr/local/avr8-gnu-toolchain-linux_x86_64/bin +###### For Linux -For flash programming you'll need avrdude. For OS using apt-get -apt-get install avrdude +1. See http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORLINUX.aspx +2. Download the proper 8-bit platform 32 or 64 bit. +3. Unpack under `/usr/local` +4. Add to your search PATH. For example add to `.bashrc`: `export PATH=$PATH:/usr/local/avr8-gnu-toolchain-linux_x86_64/bin` (for 64 bit systems) or `export PATH=$PATH:/usr/local/avr8-gnu-toolchain-linux_x86/bin` (for 32 birt systems). +5. For flash programming you'll need `avrdude`. It can be installed with the command +`apt-get install avrdude` + +###### For Windows -* For Windows. Goes here Contiki build TARGET -------------------- -make TARGET=avr-rss2 + make TARGET=avr-rss2 For AtMega128RFR2 boards: -make TARGET=avr-rss2 MCU=atmega128rfr2 + + make TARGET=avr-rss2 MCU=atmega128rfr2 For AtMega128RFA1 boards: -make TARGET=avr-rss2 MCU=atmega128rfa1 + + make TARGET=avr-rss2 MCU=atmega128rfa1 Flashing -------- @@ -91,49 +90,52 @@ Press the RESET button. The bootloader with wait for boot commands for 3 seconds. Flashing commnad line example 256k MCU: -avrdude -p m256rfr2 -c stk500v2 -P /dev/ttyUSB0 -b 38400 -e -U flash:w:hello-world.avr-rss2 + + avrdude -p m256rfr2 -c stk500v2 -P /dev/ttyUSB0 -b 38400 -e -U flash:w:hello-world.avr-rss2 Flashing commnad line example 128k MCU: -avrdude -p m128rfa1 -c avr109 -P /dev/ttyUSB0 -b 38400 -e -U flash:w:hello-world.avr-rss2 -Older boards may use the avr109 boot loader. The stk500v2 uses the yellow + avrdude -p m128rfa1 -c avr109 -P /dev/ttyUSB0 -b 38400 -e -U flash:w:hello-world.avr-rss2 + +Older boards may use the avr109 boot loader. The `stk500v2` uses the yellow lED while the avr109 uses the red LED. Tested applications and examples --------------------------------- -hello-world -ipv6/rpl-udp -ipv6/simple-udp-rpl -rime -ipv6/multicast -example-shell Needs symbol.c to be added to project also seems like -in core/dev/serial-line.c process_poll must be replaced with -process_post. +* `hello-world` +* `ipv6/rpl-udp` +* `ipv6/simple-udp-rpl` +* `rime` +* `ipv6/multicast` +* `examples/powertrace` +* `example-shell` - /* Wake up consumer process */ -- process_poll(&serial_line_process); -+ process_post(&serial_line_process, 0, 0); +Note that the shell example needs file `symbols.c` to be added to project also seems like +in `core/dev/serial-line.c` the function `process_poll` must be replaced with `process_post`: + + /* Wake up consumer process */ + - process_poll(&serial_line_process); + + process_post(&serial_line_process, 0, 0); -examples/powertrace Platform tutorial applications -.----------------------------- -Example to read out various sensors leds serial numbers etc. -platform/avr-rss2/examples/hello-sensors/ +----------------------------- +Example to read out various sensors, leds, serial numbers, and so on: +[platform/avr-rss2/examples/hello-sensors/](examples/hello-sensors/). -This example shows the sensd data encoding. But UDP using 6lowpan. -platform/avr-rss2/examles/ipv6/rpl-udp-report/ +The previous example uses the `sensd` data encoding. An example that uses UDP through 6lowpan is here: +[platform/avr-rss2/examples/ipv6/rpl-udp-report](examples/ipv6/rpl-udp-report). -NAT ip64 ethernet GW based on Contiki core/net/ip64 code -platform/avr-rss2/examples/ipv6/rpl-border-router/ +An Ethernet gateway with ip64 NAT, based on Contiki `core/net/ip64` code: +[platform/avr-rss2/examples/ipv6/rpl-border-router/](examples/ipv6/rpl-border-router/). Regressions tests ----------------- -Travis compile regression for platform: -regression-tests/23-compile-avr +Travis compile regression test for the platform: +[regression-tests/23-compile-avr](../../regression-tests/23-compile-avr). -Port adds newer version of avr-gcc compiler (4.9.2), to support -testing of newwr Atmel MCU as Atmega256RFR2. Work by Atis Elsts +This port adds newer version of `avr-gcc` compiler (4.9.2), to support +testing of newer Atmel MCU as Atmega256RFR2. Board approvals From 9f1fedfbc1ba122f3484abeeb6a634e6ce360877 Mon Sep 17 00:00:00 2001 From: Atis Elsts Date: Tue, 23 Feb 2016 11:43:51 +0200 Subject: [PATCH 05/14] avr-rss2 platform examples: remove some binary files --- platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 | 0 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 | 0 platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 | 0 platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 | 0 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 delete mode 100644 platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 delete mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 delete mode 100644 platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2 deleted file mode 100644 index e69de29bb..000000000 diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 b/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2 deleted file mode 100644 index e69de29bb..000000000 diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 b/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2 deleted file mode 100644 index e69de29bb..000000000 diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 b/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2 deleted file mode 100644 index e69de29bb..000000000 From 07ec06ad092c6029c6a580fe5560e116f89332ca Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sun, 6 Mar 2016 21:35:19 +0100 Subject: [PATCH 06/14] Setting node_id and RIME linkaddr from EUI64 chip. --- platform/avr-rss2/contiki-main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/platform/avr-rss2/contiki-main.c b/platform/avr-rss2/contiki-main.c index 172c6139f..8abac4d04 100644 --- a/platform/avr-rss2/contiki-main.c +++ b/platform/avr-rss2/contiki-main.c @@ -193,9 +193,9 @@ initialize(void) #if 0 /* Do it my way... */ - UBRR0L = 25; - UBRR0H = 0; - UCSR0A = (1 << U2X0); /*Double */ + //UBRR0L = 8; UBRR0H = 0; UCSR0A = (0 << U2X0); // 115.2k err=-3.5% + //UBRR0L = 16; UBRR0H = 0; UCSR0A = (1 << U2X0); // 115.2k 2.1% + //UBRR0L = 3; UBRR0H = 0; UCSR0A = (1 << U2X0); // 500k 0% #endif rs232_set_input(RS232_PORT_0, serial_line_input_byte); @@ -277,17 +277,18 @@ initialize(void) /* Set addresses BEFORE starting tcpip process */ linkaddr_t addr; + char eui64[8]; printf("I2C: "); i2c_probed = i2c_probe(); printf("\n"); if( i2c_probed & I2C_AT24MAC ) { - i2c_at24mac_read((char *)&addr.u8, 1); - linkaddr_set_node_addr(&addr); + i2c_at24mac_read((char *)&eui64, 1); + linkaddr_set_node_addr((linkaddr_t *) &eui64); + node_id = (eui64[1] << 8) + eui64[7]; } else { - char eui64[8]; printf("Random EUI64 address generated\n"); eui64[0] = 0xfc; /* Atmels OUI */ eui64[1] = 0xc2; @@ -297,12 +298,13 @@ initialize(void) eui64[5] = 0; eui64[6] = node_id >> 8; eui64[7] = node_id & 0xff; - linkaddr_set_node_addr(&eui64); + linkaddr_set_node_addr((linkaddr_t *)&eui64); } /* memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t)); */ #if NETSTACK_CONF_WITH_IPV6 + memcpy(&addr.u8, &eui64, sizeof(linkaddr_t)); memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t)); #endif @@ -315,6 +317,9 @@ initialize(void) #else PRINTA("MAC address "); uint8_t i; + addr.u8[0] = eui64[1] ; + addr.u8[1] = eui64[7]; + for(i = sizeof(linkaddr_t); i > 0; i--) { PRINTA("%x:", addr.u8[i - 1]); } From 39094e3c415da767ed0519ece2a4a54b97284a4c Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Tue, 8 Mar 2016 20:04:01 +0100 Subject: [PATCH 07/14] CO2 sensor bug fix --- .../examples/ipv6/sensd_client/sensd_client.c | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c b/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c index b523e87c4..df6494031 100644 --- a/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c +++ b/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c @@ -43,8 +43,10 @@ #include "leds.h" #include "dev/leds.h" #include "dev/battery-sensor.h" +#include "dev/temp-sensor.h" #include "dev/temp_mcu-sensor.h" #include "dev/light-sensor.h" +#include "dev/pulse-sensor.h" #ifdef CO2 #include "dev/co2_sa_kxx-sensor.h" #endif @@ -58,7 +60,7 @@ #define DEBUG DEBUG_PRINT #include "uip-debug.h" -#define PORT 1236 +#define PORT 1234 #define MAX_PAYLOAD_LEN 80 static struct psock ps; @@ -85,13 +87,13 @@ do_report(void) seq_id++; len += snprintf((char *) &out_buf[len], sizeof(out_buf), "&: "); - len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TXT=6LOWPAN "); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TXT=ERICSON-6LOWPAN "); len += snprintf((char *) &out_buf[len], sizeof(out_buf), "TARGET=avr-rss2 "); len += snprintf((char *) &out_buf[len], sizeof(out_buf), "V_MCU=%-d ", battery_sensor.value(0)); len += snprintf((char *) &out_buf[len], sizeof(out_buf), "T_MCU=%-d ", temp_mcu_sensor.value(0)); len += snprintf((char *) &out_buf[len], sizeof(out_buf), "LIGHT=%-d ", light_sensor.value(0)); #ifdef CO2 - len += snprintf((char *) &out_buf[len], sizeof(out_buf), "CO2=%-d ", co2_sa_kxx_sensor.value(value)); + len += snprintf((char *) &out_buf[len], sizeof(out_buf), "CO2=%-d ", co2_sa_kxx_sensor.value(CO2_SA_KXX_CO2)); #endif len += snprintf((char *) &out_buf[len], sizeof(out_buf), "\n\r"); @@ -148,14 +150,27 @@ PROCESS_THREAD(sensd_client_process, ev, data) { PROCESS_BEGIN(); set_global_address(); - leds_init(); print_local_addresses(); + + SENSORS_ACTIVATE(temp_sensor); + SENSORS_ACTIVATE(battery_sensor); + SENSORS_ACTIVATE(temp_mcu_sensor); + SENSORS_ACTIVATE(light_sensor); + SENSORS_ACTIVATE(pulse_sensor); +#ifdef CO2 + SENSORS_ACTIVATE(co2_sa_kxx_sensor); +#endif + leds_init(); + leds_on(LEDS_RED); + leds_on(LEDS_YELLOW); + printf("Starting TCP client on port=%d\n", PORT); /* Set server address. typically sensd */ //uip_ip6addr(&addr, 0xfe80, 0, 0, 0, 0xfec2, 0x3d00, 1, 0x63ae); - uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0201); + //uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0201); //uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc0a8, 0x0255); + uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc010, 0x7dea); //192.16.125.234 random_init(50); From 3c19e870f1f264f725a3686ba70350d1f338e353 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sat, 14 May 2016 12:05:19 +0200 Subject: [PATCH 08/14] Moving the avr-rss2 platform examples to the global examples location as suggested by the maintainers. --- .../avr-rss2}/avr_radio_power/AtMega256RFR2-summary-power.dat | 0 .../examples => examples/avr-rss2}/avr_radio_power/Makefile | 0 .../examples => examples/avr-rss2}/avr_radio_power/README.md | 0 .../avr-rss2}/avr_radio_power/avr_radio_power.c | 0 .../examples => examples/avr-rss2}/avr_radio_power/project-conf.h | 0 .../examples => examples/avr-rss2}/hello-sensors/Makefile | 0 .../examples => examples/avr-rss2}/hello-sensors/README.md | 0 .../examples => examples/avr-rss2}/hello-sensors/hello-sensors.c | 0 .../examples => examples/avr-rss2}/hello-sensors/project-conf.h | 0 .../examples => examples/avr-rss2}/ipv6/dc-rpl-coap/Makefile | 0 .../examples => examples/avr-rss2}/ipv6/dc-rpl-coap/README.md | 0 .../examples => examples/avr-rss2}/ipv6/dc-rpl-coap/coap-client.c | 0 .../examples => examples/avr-rss2}/ipv6/dc-rpl-coap/coap-server.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dc-rpl-coap.csc | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dev/dc-status-sensor.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dev/dc-status-sensor.h | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h | 0 .../examples => examples/avr-rss2}/ipv6/dc-rpl-coap/er-dc-test.h | 0 .../avr-rss2}/ipv6/dc-rpl-coap/project-conf.h | 0 .../avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-co2.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c | 0 .../avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-vdc.c | 0 .../avr-rss2}/ipv6/rpl-border-router/Makefile | 0 .../avr-rss2}/ipv6/rpl-border-router/README.ETHERNET.md | 0 .../avr-rss2}/ipv6/rpl-border-router/README.md | 0 .../avr-rss2}/ipv6/rpl-border-router/border-router.c | 0 .../avr-rss2}/ipv6/rpl-border-router/enc28j60-ip64-driver.c | 0 .../avr-rss2}/ipv6/rpl-border-router/enc28j60-ip64-driver.h | 0 .../avr-rss2}/ipv6/rpl-border-router/eth-bridge.c | 0 .../avr-rss2}/ipv6/rpl-border-router/httpd-simple.c | 0 .../avr-rss2}/ipv6/rpl-border-router/httpd-simple.h | 0 .../avr-rss2}/ipv6/rpl-border-router/project-conf.h | 0 .../examples => examples/avr-rss2}/ipv6/rpl-udp-report/Makefile | 0 .../examples => examples/avr-rss2}/ipv6/rpl-udp-report/README.md | 0 .../avr-rss2}/ipv6/rpl-udp-report/project-conf.h | 0 .../examples => examples/avr-rss2}/ipv6/rpl-udp-report/report.c | 0 .../avr-rss2}/ipv6/rpl-udp-report/rss2-rpl-udp.csc | 0 .../examples => examples/avr-rss2}/ipv6/rpl-udp-report/sink.c | 0 .../examples => examples/avr-rss2}/ipv6/sensd_client/Makefile | 0 .../examples => examples/avr-rss2}/ipv6/sensd_client/README.md | 0 .../avr-rss2}/ipv6/sensd_client/project-conf.h | 0 .../avr-rss2}/ipv6/sensd_client/sensd_client.c | 0 .../examples => examples/avr-rss2}/ipv6/sensd_client/server.c | 0 47 files changed, 0 insertions(+), 0 deletions(-) rename {platform/avr-rss2/examples => examples/avr-rss2}/avr_radio_power/AtMega256RFR2-summary-power.dat (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/avr_radio_power/Makefile (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/avr_radio_power/README.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/avr_radio_power/avr_radio_power.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/avr_radio_power/project-conf.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/hello-sensors/Makefile (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/hello-sensors/README.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/hello-sensors/hello-sensors.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/hello-sensors/project-conf.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/Makefile (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/README.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/coap-client.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/coap-server.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dc-rpl-coap.csc (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dev/dc-status-sensor.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dev/dc-status-sensor.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/er-dc-test.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/project-conf.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-co2.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/dc-rpl-coap/resources/res-dc-vdc.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/Makefile (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/README.ETHERNET.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/README.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/border-router.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/enc28j60-ip64-driver.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/enc28j60-ip64-driver.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/eth-bridge.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/httpd-simple.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/httpd-simple.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-border-router/project-conf.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-udp-report/Makefile (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-udp-report/README.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-udp-report/project-conf.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-udp-report/report.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-udp-report/rss2-rpl-udp.csc (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/rpl-udp-report/sink.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/sensd_client/Makefile (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/sensd_client/README.md (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/sensd_client/project-conf.h (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/sensd_client/sensd_client.c (100%) rename {platform/avr-rss2/examples => examples/avr-rss2}/ipv6/sensd_client/server.c (100%) diff --git a/platform/avr-rss2/examples/avr_radio_power/AtMega256RFR2-summary-power.dat b/examples/avr-rss2/avr_radio_power/AtMega256RFR2-summary-power.dat similarity index 100% rename from platform/avr-rss2/examples/avr_radio_power/AtMega256RFR2-summary-power.dat rename to examples/avr-rss2/avr_radio_power/AtMega256RFR2-summary-power.dat diff --git a/platform/avr-rss2/examples/avr_radio_power/Makefile b/examples/avr-rss2/avr_radio_power/Makefile similarity index 100% rename from platform/avr-rss2/examples/avr_radio_power/Makefile rename to examples/avr-rss2/avr_radio_power/Makefile diff --git a/platform/avr-rss2/examples/avr_radio_power/README.md b/examples/avr-rss2/avr_radio_power/README.md similarity index 100% rename from platform/avr-rss2/examples/avr_radio_power/README.md rename to examples/avr-rss2/avr_radio_power/README.md diff --git a/platform/avr-rss2/examples/avr_radio_power/avr_radio_power.c b/examples/avr-rss2/avr_radio_power/avr_radio_power.c similarity index 100% rename from platform/avr-rss2/examples/avr_radio_power/avr_radio_power.c rename to examples/avr-rss2/avr_radio_power/avr_radio_power.c diff --git a/platform/avr-rss2/examples/avr_radio_power/project-conf.h b/examples/avr-rss2/avr_radio_power/project-conf.h similarity index 100% rename from platform/avr-rss2/examples/avr_radio_power/project-conf.h rename to examples/avr-rss2/avr_radio_power/project-conf.h diff --git a/platform/avr-rss2/examples/hello-sensors/Makefile b/examples/avr-rss2/hello-sensors/Makefile similarity index 100% rename from platform/avr-rss2/examples/hello-sensors/Makefile rename to examples/avr-rss2/hello-sensors/Makefile diff --git a/platform/avr-rss2/examples/hello-sensors/README.md b/examples/avr-rss2/hello-sensors/README.md similarity index 100% rename from platform/avr-rss2/examples/hello-sensors/README.md rename to examples/avr-rss2/hello-sensors/README.md diff --git a/platform/avr-rss2/examples/hello-sensors/hello-sensors.c b/examples/avr-rss2/hello-sensors/hello-sensors.c similarity index 100% rename from platform/avr-rss2/examples/hello-sensors/hello-sensors.c rename to examples/avr-rss2/hello-sensors/hello-sensors.c diff --git a/platform/avr-rss2/examples/hello-sensors/project-conf.h b/examples/avr-rss2/hello-sensors/project-conf.h similarity index 100% rename from platform/avr-rss2/examples/hello-sensors/project-conf.h rename to examples/avr-rss2/hello-sensors/project-conf.h diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/Makefile b/examples/avr-rss2/ipv6/dc-rpl-coap/Makefile similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/Makefile rename to examples/avr-rss2/ipv6/dc-rpl-coap/Makefile diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/README.md b/examples/avr-rss2/ipv6/dc-rpl-coap/README.md similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/README.md rename to examples/avr-rss2/ipv6/dc-rpl-coap/README.md diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c b/examples/avr-rss2/ipv6/dc-rpl-coap/coap-client.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/coap-client.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c b/examples/avr-rss2/ipv6/dc-rpl-coap/coap-server.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/coap-server.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc b/examples/avr-rss2/ipv6/dc-rpl-coap/dc-rpl-coap.csc similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dc-rpl-coap.csc rename to examples/avr-rss2/ipv6/dc-rpl-coap/dc-rpl-coap.csc diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c b/examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h b/examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h rename to examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.c b/examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.h b/examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-status-sensor.h rename to examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.h diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c b/examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h b/examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h rename to examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/er-dc-test.h b/examples/avr-rss2/ipv6/dc-rpl-coap/er-dc-test.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/er-dc-test.h rename to examples/avr-rss2/ipv6/dc-rpl-coap/er-dc-test.h diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/project-conf.h b/examples/avr-rss2/ipv6/dc-rpl-coap/project-conf.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/project-conf.h rename to examples/avr-rss2/ipv6/dc-rpl-coap/project-conf.h diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-co2.c b/examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-co2.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-co2.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-co2.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c b/examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c b/examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c diff --git a/platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-vdc.c b/examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-vdc.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/dc-rpl-coap/resources/res-dc-vdc.c rename to examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-vdc.c diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/Makefile b/examples/avr-rss2/ipv6/rpl-border-router/Makefile similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/Makefile rename to examples/avr-rss2/ipv6/rpl-border-router/Makefile diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/README.ETHERNET.md b/examples/avr-rss2/ipv6/rpl-border-router/README.ETHERNET.md similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/README.ETHERNET.md rename to examples/avr-rss2/ipv6/rpl-border-router/README.ETHERNET.md diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/README.md b/examples/avr-rss2/ipv6/rpl-border-router/README.md similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/README.md rename to examples/avr-rss2/ipv6/rpl-border-router/README.md diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/border-router.c b/examples/avr-rss2/ipv6/rpl-border-router/border-router.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/border-router.c rename to examples/avr-rss2/ipv6/rpl-border-router/border-router.c diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.c b/examples/avr-rss2/ipv6/rpl-border-router/enc28j60-ip64-driver.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.c rename to examples/avr-rss2/ipv6/rpl-border-router/enc28j60-ip64-driver.c diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.h b/examples/avr-rss2/ipv6/rpl-border-router/enc28j60-ip64-driver.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/enc28j60-ip64-driver.h rename to examples/avr-rss2/ipv6/rpl-border-router/enc28j60-ip64-driver.h diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/eth-bridge.c b/examples/avr-rss2/ipv6/rpl-border-router/eth-bridge.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/eth-bridge.c rename to examples/avr-rss2/ipv6/rpl-border-router/eth-bridge.c diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.c b/examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.c rename to examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.c diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.h b/examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/httpd-simple.h rename to examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.h diff --git a/platform/avr-rss2/examples/ipv6/rpl-border-router/project-conf.h b/examples/avr-rss2/ipv6/rpl-border-router/project-conf.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-border-router/project-conf.h rename to examples/avr-rss2/ipv6/rpl-border-router/project-conf.h diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/Makefile b/examples/avr-rss2/ipv6/rpl-udp-report/Makefile similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-udp-report/Makefile rename to examples/avr-rss2/ipv6/rpl-udp-report/Makefile diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/README.md b/examples/avr-rss2/ipv6/rpl-udp-report/README.md similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-udp-report/README.md rename to examples/avr-rss2/ipv6/rpl-udp-report/README.md diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/project-conf.h b/examples/avr-rss2/ipv6/rpl-udp-report/project-conf.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-udp-report/project-conf.h rename to examples/avr-rss2/ipv6/rpl-udp-report/project-conf.h diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c b/examples/avr-rss2/ipv6/rpl-udp-report/report.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c rename to examples/avr-rss2/ipv6/rpl-udp-report/report.c diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/rss2-rpl-udp.csc b/examples/avr-rss2/ipv6/rpl-udp-report/rss2-rpl-udp.csc similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-udp-report/rss2-rpl-udp.csc rename to examples/avr-rss2/ipv6/rpl-udp-report/rss2-rpl-udp.csc diff --git a/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c b/examples/avr-rss2/ipv6/rpl-udp-report/sink.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c rename to examples/avr-rss2/ipv6/rpl-udp-report/sink.c diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/Makefile b/examples/avr-rss2/ipv6/sensd_client/Makefile similarity index 100% rename from platform/avr-rss2/examples/ipv6/sensd_client/Makefile rename to examples/avr-rss2/ipv6/sensd_client/Makefile diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/README.md b/examples/avr-rss2/ipv6/sensd_client/README.md similarity index 100% rename from platform/avr-rss2/examples/ipv6/sensd_client/README.md rename to examples/avr-rss2/ipv6/sensd_client/README.md diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h b/examples/avr-rss2/ipv6/sensd_client/project-conf.h similarity index 100% rename from platform/avr-rss2/examples/ipv6/sensd_client/project-conf.h rename to examples/avr-rss2/ipv6/sensd_client/project-conf.h diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c b/examples/avr-rss2/ipv6/sensd_client/sensd_client.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/sensd_client/sensd_client.c rename to examples/avr-rss2/ipv6/sensd_client/sensd_client.c diff --git a/platform/avr-rss2/examples/ipv6/sensd_client/server.c b/examples/avr-rss2/ipv6/sensd_client/server.c similarity index 100% rename from platform/avr-rss2/examples/ipv6/sensd_client/server.c rename to examples/avr-rss2/ipv6/sensd_client/server.c From d331d39e93ed7696c5c31a1dbe2287c2e80936d5 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sat, 14 May 2016 22:48:09 +0200 Subject: [PATCH 09/14] Correct paths when moving examples for regession tests --- examples/avr-rss2/avr_radio_power/Makefile | 2 +- examples/avr-rss2/hello-sensors/Makefile | 2 +- examples/avr-rss2/ipv6/dc-rpl-coap/Makefile | 2 +- examples/avr-rss2/ipv6/rpl-border-router/Makefile | 2 +- examples/avr-rss2/ipv6/rpl-udp-report/Makefile | 2 +- examples/avr-rss2/ipv6/sensd_client/Makefile | 2 +- regression-tests/23-compile-avr/Makefile | 6 +++--- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/avr-rss2/avr_radio_power/Makefile b/examples/avr-rss2/avr_radio_power/Makefile index fb9b062a1..abaab89f1 100644 --- a/examples/avr-rss2/avr_radio_power/Makefile +++ b/examples/avr-rss2/avr_radio_power/Makefile @@ -4,6 +4,6 @@ CONTIKI_PROJECT = avr_radio_power APPS+=powertrace all: $(CONTIKI_PROJECT) -CONTIKI = ../../../.. +CONTIKI = ../../.. CONTIKI_WITH_RIME = 1 include $(CONTIKI)/Makefile.include diff --git a/examples/avr-rss2/hello-sensors/Makefile b/examples/avr-rss2/hello-sensors/Makefile index c6e0da805..0d1d41b9f 100644 --- a/examples/avr-rss2/hello-sensors/Makefile +++ b/examples/avr-rss2/hello-sensors/Makefile @@ -15,5 +15,5 @@ CUSTOM_RULE_LINK = 1 -CONTIKI = ../../../.. +CONTIKI = ../../.. include $(CONTIKI)/Makefile.include diff --git a/examples/avr-rss2/ipv6/dc-rpl-coap/Makefile b/examples/avr-rss2/ipv6/dc-rpl-coap/Makefile index 9d8bccece..46a7e9c3f 100644 --- a/examples/avr-rss2/ipv6/dc-rpl-coap/Makefile +++ b/examples/avr-rss2/ipv6/dc-rpl-coap/Makefile @@ -2,7 +2,7 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" all: coap-client coap-server APPS=servreg-hack -CONTIKI=../../../../.. +CONTIKI=../../../.. ifdef WITH_COMPOWER APPS+=powertrace diff --git a/examples/avr-rss2/ipv6/rpl-border-router/Makefile b/examples/avr-rss2/ipv6/rpl-border-router/Makefile index ba3f16af6..630d9dd53 100644 --- a/examples/avr-rss2/ipv6/rpl-border-router/Makefile +++ b/examples/avr-rss2/ipv6/rpl-border-router/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT=border-router all: $(CONTIKI_PROJECT) -CONTIKI=../../../../.. +CONTIKI=../../../.. #linker optimizations SMALL=1 diff --git a/examples/avr-rss2/ipv6/rpl-udp-report/Makefile b/examples/avr-rss2/ipv6/rpl-udp-report/Makefile index 770ad3749..f4c90317e 100644 --- a/examples/avr-rss2/ipv6/rpl-udp-report/Makefile +++ b/examples/avr-rss2/ipv6/rpl-udp-report/Makefile @@ -3,7 +3,7 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" all: report sink APPS=servreg-hack -CONTIKI=../../../../.. +CONTIKI=../../../.. ifdef WITH_COMPOWER APPS+=powertrace diff --git a/examples/avr-rss2/ipv6/sensd_client/Makefile b/examples/avr-rss2/ipv6/sensd_client/Makefile index c0eabf9b0..f1b0d7d48 100644 --- a/examples/avr-rss2/ipv6/sensd_client/Makefile +++ b/examples/avr-rss2/ipv6/sensd_client/Makefile @@ -2,7 +2,7 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" all: sensd_client server -CONTIKI=../../../../.. +CONTIKI=../../../.. ifdef PERIOD CFLAGS+=-DPERIOD=$(PERIOD) diff --git a/regression-tests/23-compile-avr/Makefile b/regression-tests/23-compile-avr/Makefile index 0904e2f37..56cef07d3 100644 --- a/regression-tests/23-compile-avr/Makefile +++ b/regression-tests/23-compile-avr/Makefile @@ -4,9 +4,9 @@ TOOLSDIR=../../tools # build avr-rss2 examples, covering IPv6, RPL, Rime, Nullrdc, Contikimac EXAMPLES = \ -platform/avr-rss2/examples/hello-sensors/avr-rss2 \ -platform/avr-rss2/examples/ipv6/rpl-udp-report/avr-rss2 \ -platform/avr-rss2/examples/ipv6/rpl-border-router/avr-rss2 \ +examples/avr-rss2/hello-sensors/avr-rss2 \ +examples/avr-rss2/ipv6/rpl-udp-report/avr-rss2 \ +examples/avr-rss2/ipv6/rpl-border-router/avr-rss2 \ examples/ipv6/rpl-udp/avr-rss2 \ examples/powertrace/avr-rss2 \ examples/rime/avr-rss2 From 18876a1fae22b302c1d951b6268627134d789157 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Fri, 18 Mar 2016 10:55:54 +0100 Subject: [PATCH 10/14] Adding CRC valid check in rf230bb radios registermaps --- cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h | 1 + cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h | 1 + 2 files changed, 2 insertions(+) diff --git a/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h b/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h index 7eeb068ab..b28ed0ec0 100644 --- a/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h +++ b/cpu/avr/radio/rf230bb/atmega128rfa1_registermap.h @@ -71,6 +71,7 @@ #define RG_PHY_ED_LEVEL PHY_ED_LEVEL #define RG_RX_SYN RX_SYN #define SR_RSSI 0x146, 0x1f, 0 +#define SR_RX_CRC_VALID 0x146, 0x80, 7 #define SR_PLL_CF_START 0x15a, 0x80, 7 #define SR_PLL_DCU_START 0x15b, 0x80, 7 #define SR_MAX_CSMA_RETRIES 0x16c, 0x0e, 1 diff --git a/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h b/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h index bc737de9a..1baf1a3ac 100644 --- a/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h +++ b/cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h @@ -71,6 +71,7 @@ #define RG_PHY_ED_LEVEL PHY_ED_LEVEL #define RG_RX_SYN RX_SYN #define SR_RSSI 0x146, 0x1f, 0 +#define SR_RX_CRC_VALID 0x146, 0x80, 7 #define SR_RX_SYN 0x155, 0xff, 0 #define SR_TRX_RPC 0x156, 0xff, 0 #define SR_XAH_CTRL_1 0x157, 0xf5, 2 From 868f100366f8fad5224e8bf362a4b3012f69581e Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sun, 15 May 2016 16:23:29 +0200 Subject: [PATCH 11/14] Fix compilation warning in co2_sa_kxx-sensor.c --- platform/avr-rss2/dev/co2_sa_kxx-sensor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/avr-rss2/dev/co2_sa_kxx-sensor.c b/platform/avr-rss2/dev/co2_sa_kxx-sensor.c index 1866c0f2f..564f8c011 100644 --- a/platform/avr-rss2/dev/co2_sa_kxx-sensor.c +++ b/platform/avr-rss2/dev/co2_sa_kxx-sensor.c @@ -112,7 +112,7 @@ value(int var) status = i2c_readAck(); - if(status & 0x01 == 0) + if((status & 0x01) == 0) goto err; buf[0] = i2c_readAck(); From a11cfa10b44e5938977ae7f0af49d453c3214dd9 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sun, 15 May 2016 16:36:19 +0200 Subject: [PATCH 12/14] Removed unneeded file for avr-rss2 sniffer --- .../avr-rss2/apps/sniffer/rf230-promisc.pat | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 platform/avr-rss2/apps/sniffer/rf230-promisc.pat diff --git a/platform/avr-rss2/apps/sniffer/rf230-promisc.pat b/platform/avr-rss2/apps/sniffer/rf230-promisc.pat deleted file mode 100644 index 3e2c98e6f..000000000 --- a/platform/avr-rss2/apps/sniffer/rf230-promisc.pat +++ /dev/null @@ -1,39 +0,0 @@ -diff --git a/cpu/avr/radio/rf230bb/rf230bb.c b/cpu/avr/radio/rf230bb/rf230bb.c -index 53959d1..b9f2262 100644 ---- a/cpu/avr/radio/rf230bb/rf230bb.c -+++ b/cpu/avr/radio/rf230bb/rf230bb.c -@@ -544,7 +544,7 @@ rf230_set_promiscuous_mode(bool isPromiscuous) { - #if RF230_CONF_AUTOACK - is_promiscuous = isPromiscuous; - /* TODO: Figure out when to pass promisc state to 802.15.4 */ --// radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON); -+ radio_set_trx_state(is_promiscuous?RX_ON:RX_AACK_ON); - #endif - } - -@@ -1392,6 +1392,25 @@ PROCESS_THREAD(rf230_process, ev, data) - /* Restore interrupts. */ - HAL_LEAVE_CRITICAL_REGION(); - PRINTF("rf230_read: %u bytes lqi %u\n",len,rf230_last_correlation); -+ -+ if(is_promiscuous) { -+ uint8_t i; -+ unsigned const char * rxdata = packetbuf_dataptr(); -+ /* Print magic */ -+ putchar(0xC1); -+ putchar(0x1F); -+ putchar(0xFE); -+ putchar(0x72); -+ /* Print version */ -+ putchar(0x01); -+ /* Print CMD == frame */ -+ putchar(0x00); -+ putchar(len+3); -+ -+ for (i=0;i1 - { - uint8_t i; From 17eb0afbe2250380cd632f8cde234addfef9d541 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sun, 15 May 2016 16:38:52 +0200 Subject: [PATCH 13/14] Removed failing regression test for avr-rss2 platform --- regression-tests/23-compile-avr/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/regression-tests/23-compile-avr/Makefile b/regression-tests/23-compile-avr/Makefile index 56cef07d3..e7d2dff77 100644 --- a/regression-tests/23-compile-avr/Makefile +++ b/regression-tests/23-compile-avr/Makefile @@ -7,7 +7,6 @@ EXAMPLES = \ examples/avr-rss2/hello-sensors/avr-rss2 \ examples/avr-rss2/ipv6/rpl-udp-report/avr-rss2 \ examples/avr-rss2/ipv6/rpl-border-router/avr-rss2 \ -examples/ipv6/rpl-udp/avr-rss2 \ examples/powertrace/avr-rss2 \ examples/rime/avr-rss2 TOOLS= From 958dcf06f7d3b7086e580da9e47b57a7e29cb017 Mon Sep 17 00:00:00 2001 From: Robert Olsson Date: Sun, 15 May 2016 17:43:09 +0200 Subject: [PATCH 14/14] Remove wsnbridge. Let's focus sniffing efforts on sensniff. --- platform/avr-rss2/apps/sniffer/README.md | 6 +- platform/avr-rss2/apps/sniffer/host/Makefile | 17 - platform/avr-rss2/apps/sniffer/host/README.md | 38 -- .../avr-rss2/apps/sniffer/host/wsbridge.c | 459 ------------------ 4 files changed, 5 insertions(+), 515 deletions(-) delete mode 100644 platform/avr-rss2/apps/sniffer/host/Makefile delete mode 100644 platform/avr-rss2/apps/sniffer/host/README.md delete mode 100644 platform/avr-rss2/apps/sniffer/host/wsbridge.c diff --git a/platform/avr-rss2/apps/sniffer/README.md b/platform/avr-rss2/apps/sniffer/README.md index fa139878b..b9332893b 100644 --- a/platform/avr-rss2/apps/sniffer/README.md +++ b/platform/avr-rss2/apps/sniffer/README.md @@ -22,4 +22,8 @@ Look in the host directory Contiki support --------------- The code promisc for support is needed. This also adds the sensniff -format. See rf230-promisc.pat for the rf230bb radions. +format. + +References +---------- +https://github.com/g-oikonomou/sensniff diff --git a/platform/avr-rss2/apps/sniffer/host/Makefile b/platform/avr-rss2/apps/sniffer/host/Makefile deleted file mode 100644 index 7308f66a5..000000000 --- a/platform/avr-rss2/apps/sniffer/host/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -CC = gcc -CFLAGS = -c -SOURCES = wsbridge.c -OBJECTS = $(SOURCES:.c=.o) -EXE = wsbridge - -all: $(SOURCES) $(EXE) - -$(EXE): $(OBJECTS) - $(CC) $(OBJECTS) -o $@ - -%.o:%.c - $(CC) $(CFLAGS) $< -o $@ - -clean: - rm *.o diff --git a/platform/avr-rss2/apps/sniffer/host/README.md b/platform/avr-rss2/apps/sniffer/host/README.md deleted file mode 100644 index cb7960d50..000000000 --- a/platform/avr-rss2/apps/sniffer/host/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Sniffer application host side -============================= -This a Unix application to link between the serial port having the -sensor node connected and Wireshark or tcpdump. Enclosed is a modified -wsbridge (See copyright i file) code to use the format used by sensniff. - -You can also use sensniff which is a Python script. Author of senssniff -is George Oikonomou (oikonomou@users.sf.net) - -See: -https://github.com/g-oikonomou/sensniff - - -Function --------- -The mote captures WSN data and formats according sensniff format sends -over the serial line. The data is binary. The wsbridge reads reads serial -line (typically /dev/ttyUSB) on Linux systems decodes the sensnaiff and -create timestamp and adds the the PCAP farming and writes the result to -a FIFO or named pipe. /tmp/wireshark or /tmp/sensniff. - -Bulld ------ -Just use the Makefile. Put binary for convince in your path. - -Usage ------ -* wsbridge /dev/ttYUSB -* wireshart -k -i /tmp/wireshark - -Default serial port speed -------------------------- -38400 bps - -References ----------- -http://www.freaklabs.org/index.php/wsbridge.html -https://github.com/g-oikonomou/sensniff diff --git a/platform/avr-rss2/apps/sniffer/host/wsbridge.c b/platform/avr-rss2/apps/sniffer/host/wsbridge.c deleted file mode 100644 index 6809f36a8..000000000 --- a/platform/avr-rss2/apps/sniffer/host/wsbridge.c +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************* - Copyright (C) 2009 FreakLabs - 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 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 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 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. - - Originally written by Christopher Wang aka Akiba. - Please post support questions to the FreakLabs forum. - - *******************************************************************/ -/*! - FreakLabs Freakduino/Wireshark Bridge - - This program allows data from the Freakduino to be piped into wireshark. - When the sniffer firmware is loaded into the Freakduino, then the Freakduino - will be in promiscuous mode and will just dump any frames it sees. This - program takes the frame dump and sends it into Wireshark for analysis. The - global header is already set up to inform wireshark that the link layer for - all frames will be in IEEE 802.15.4 format. After that, it is up to the user - to choose any higher layer protocols to decode above 802.15.4 via the - wireshark "enable protocols" menu. - */ - -/* - - Modified for sensniff format. Magic[4] + Vers[1] + CMD[1] + len[1] - Robert Olsson 2015-11-10 - - */ - -/**************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PORTBUFSIZE 32 -#define BUFSIZE 1024 -#define PACKET_FCS 2 -#define DEBUG 1 -#define PIPENAME "/tmp/wireshark" -#define BAUDRATE B38400 - -enum FSM { - START_CAPTURE, - PACKET_CAPTURE -}; - -static int FD_pipe = -1; -static int FD_com = -1; -static uint8_t port_buf[PORTBUFSIZE]; -static uint8_t circ_buf[BUFSIZE]; -static uint16_t rd_idx = 0; -static uint16_t wr_idx = 0; -static uint8_t len; -static uint8_t state = START_CAPTURE; -static uint8_t file_write = 0; -static fd_set fds; -static const uint8_t magic[] = { 0xC1, 0x1F, 0xFE, 0x72 }; - -/**************************************************************************/ -/*! - Open the serial port that we'll be communicating with the Freakduino (sniffer) - through. - */ -/**************************************************************************/ - -int -serial_open(char *portname) -{ - int baud = B38400; - int fd; /* file descriptor for the serial port */ - struct termios tc, tp; - - fd = open(portname, O_RDONLY | O_NOCTTY | O_NDELAY); - - if(fd == -1) { /* if open is unsucessful */ - printf("serial_open: Unable to open %s.\n", portname); - exit(-1); - } - - fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, O_RDWR); - - tp.c_cflag = baud | CS8 | CLOCAL | CREAD; - tp.c_oflag = 0; /* Raw Input */ - tp.c_lflag = 0; /* No conoical */ - tp.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL | NLDLY | CRDLY); - - /* ignore CR, ignore parity */ - tp.c_iflag = ~(IGNBRK | PARMRK | INPCK | INLCR | IUCLC | IXOFF) | - BRKINT | IGNPAR | ICRNL | IXON | ISIG | ICANON; - - tp.c_lflag &= ~(ECHO | ECHONL); - tp.c_oflag = 0; /* Raw Input */ - tp.c_iflag &= ~ISTRIP; - - tcflush(fd, TCIFLUSH); - - cfsetospeed(&tp, baud); - cfsetispeed(&tp, baud); - - if(tcsetattr(fd, TCSANOW, &tp) < 0) { - perror("Couldn't set term attributes"); - return -1; - } - return fd; -} -/**************************************************************************/ -/*! - Create the named pipe that we will be communicating with wireshark through. - */ -/**************************************************************************/ -static void -named_pipe_create(char *name) -{ - int rv = 0; - rv = mkfifo(name, 0666); - if((rv == -1) && (errno != EEXIST)) { - perror("Error creating named pipe"); - exit(1); - } - - FD_pipe = open(name, O_WRONLY); - - if(FD_pipe == -1) { - perror("Error connecting to named pipe"); - exit(1); - } -} -/**************************************************************************/ -/*! - Write data to the pipe - */ -/**************************************************************************/ -size_t -data_write(const void *ptr, size_t size) -{ - ssize_t bytes = 0; - if(FD_pipe != -1) { - bytes = write(FD_pipe, ptr, size); - } -} -/**************************************************************************/ -/*! - Write the global header to wireshark. This is only done once at the - beginning of the capture. - */ -/**************************************************************************/ -static void -write_global_hdr() -{ - uint32_t magic_number = 0xa1b2c3d4; /* magic number */ - uint16_t version_major = 2; /* major version number */ - uint16_t version_minor = 4; /* minor version number */ - int32_t thiszone = 0; /* GMT to local correction */ - uint32_t sigfigs = 0; /* accuracy of timestamps */ - uint32_t snaplen = 65535; /* max length of captured packets, in octets */ - uint32_t network = 195; /* data link type (DLT) - IEEE 802.15.4 */ - - data_write(&magic_number, sizeof(magic_number)); - data_write(&version_major, sizeof(version_major)); - data_write(&version_minor, sizeof(version_minor)); - data_write(&thiszone, sizeof(thiszone)); - data_write(&sigfigs, sizeof(sigfigs)); - data_write(&snaplen, sizeof(snaplen)); - data_write(&network, sizeof(network)); -} -/**************************************************************************/ -/*! - Write the frame header into wireshark. This is required for the libpcap - format and informs wireshark that a new frame is coming. - */ -/**************************************************************************/ -static void -write_frame_hdr(uint8_t len) -{ - uint32_t ts_sec; /* timestamp seconds */ - uint32_t ts_usec; /* timestamp microseconds */ - uint32_t incl_len; /* number of octets of packet saved in file */ - uint32_t orig_len; /* actual length of packet */ - struct timeval tv; - - gettimeofday(&tv, NULL); - ts_sec = tv.tv_sec; - ts_usec = tv.tv_usec; - incl_len = len; - orig_len = len + PACKET_FCS; - - data_write(&ts_sec, sizeof(ts_sec)); - data_write(&ts_usec, sizeof(ts_usec)); - data_write(&incl_len, sizeof(incl_len)); - data_write(&orig_len, sizeof(orig_len)); -} -/**************************************************************************/ -/*! - Write one frame into wireshark (via the pipe). - */ -/**************************************************************************/ -static void -write_frame(uint8_t frame_len) -{ - uint8_t i; - - /* actual frame length for wireshark should not include FCS */ - frame_len -= PACKET_FCS; - - /* write header to inform WS that new frame has arrived */ - write_frame_hdr(frame_len); - - /* bump rd_idx. we don't want to write the length byte */ - rd_idx = (rd_idx + 1) % BUFSIZE; - - /* write frame into wireshark */ - for(i = 0; i < frame_len; i++) { - data_write(&circ_buf[rd_idx], 1); - rd_idx = (rd_idx + 1) % BUFSIZE; - } - - /* bump rd_idx. we're not using the trailing FCS value */ - rd_idx = (rd_idx + 1) % BUFSIZE; -} -/**************************************************************************/ -/*! - Calculate total number of bytes in buffer. - */ -/**************************************************************************/ -static uint16_t -calc_bytes_in_buf() -{ - if(rd_idx > wr_idx) { - /* read index is greater than write. we must have wrapped around */ - return BUFSIZE - (rd_idx - wr_idx); - } else { - return wr_idx - rd_idx; - } -} -/**************************************************************************/ -/*! - Deal with any received signals. This includes ctrl-C to stop the program. - */ -/**************************************************************************/ -static void -sig_int(int signo) -{ - (void)signo; - if(FD_pipe != -1) { - printf("\nClosing pipe.\n"); - close(FD_pipe); - } - - if(FD_com != -1) { - printf("\nClosing serial port.\n"); - close(FD_com); - } - - printf("\nSignal captured and devices shut down.\n"); - - exit(0); -} -/**************************************************************************/ -/*! - Init the signals we'll be checking for. - */ -/**************************************************************************/ -static void -signal_init(void) -{ - signal(SIGINT, sig_int); - signal(SIGHUP, sig_int); - signal(SIGTERM, sig_int); -} -int got; -int debug; - -/**************************************************************************/ -/*! - Here's the meat of the code. - */ -/**************************************************************************/ -int -main(int argc, char *argv[]) -{ - int nbytes; - uint8_t i; - - got = 0; - - /* capture any signals that will terminate program */ - signal_init(); - - /* make sure the COM port is specified */ - if(argc == 2) { - /* open the COM port */ - if((FD_com = serial_open(argv[1])) == -1) { - printf("Serial port not opened.\n"); - return 0; - } else { - /* set up the select statement for the COM port. */ - FD_ZERO(&fds); - FD_SET(FD_com, &fds); - - printf("Serial port connected. Waiting for wireshark connection.\n"); - printf("Open wireshark and connect to local interface: %s\n", PIPENAME); - } - } else { - printf("Usage: wsbridge .\n"); - return 0; - } - - /* create and open pipe for wireshark */ - named_pipe_create(PIPENAME); - - /* wait for wireshark to connect to pipe. Once wireshark */ - /* connects, then the global header will be written to it. */ - if(FD_pipe != -1) { - write_global_hdr(); - printf("Client connected to pipe.\n"); - } - - for(;;) { - uint16_t bytes_in_buf; - uint8_t frame_len, byte_ctr; - - /* block until there is data in the serial port */ - select(FD_com + 1, &fds, NULL, NULL, NULL); - if(FD_ISSET(FD_com, &fds)) { - int ii; - /* wait for data to come in on the serial port */ - if((nbytes = read(FD_com, port_buf, PORTBUFSIZE)) > 0) { - - if(debug) { - uint8_t p; - printf("read nbytes=%d\n", nbytes); - for(i = 0; i < nbytes; i++) { - printf(" %02X", port_buf[i]); - } - printf("\n"); - } - /* write data to circular buffer. loop through all received bytes */ - for(i = 0; i < nbytes; i++) { - switch(state) { - case START_CAPTURE: - /* new frame starting */ - if((got == 0) && (port_buf[i] == magic[0])) { - got = 1; - } else if((got == 1) && (port_buf[i] == magic[1])) { - got = 2; - } else if((got == 2) && (port_buf[i] == magic[2])) { - got = 3; - } else if((got == 3) && (port_buf[i] == magic[3])) { - got = 4; - if(debug) { - printf("GOT MAGIC i=%d\n", i); - } - } else if((got == 4) && (port_buf[i] == 1)) { - got = 5; - if(debug) { - printf("GOT VERSION i=%d\n", port_buf[i]); - } - } else if((got == 5) && (port_buf[i] == 0)) { - got = 6; - if(debug) { - printf("GOT COMMAND i=%d\n", port_buf[i]); - } - } else if(got == 6) { - len = port_buf[i]; - byte_ctr = 0; - if(debug) { - printf("Len = %02X.\n", len); - } - circ_buf[wr_idx] = len; - wr_idx = (wr_idx + 1) % BUFSIZE; - state = PACKET_CAPTURE; - } else { - got = 0; - } - break; - - case PACKET_CAPTURE: - /* continue capturing bytes until end of frame */ - /* write data to circular buffer and increment index */ - - circ_buf[wr_idx] = port_buf[i]; - /* ////printf("%02X ", circ_buf[wr_idx]); */ - - wr_idx = (wr_idx + 1) % BUFSIZE; - /* track number of received bytes. when received bytes */ - /* equals frame length, then restart state machine and */ - /* write bytes to wireshark */ - byte_ctr++; - if(byte_ctr == (len - 1)) { - state = START_CAPTURE; - file_write = 1; - /* printf("\n"); */ - got = 0; - } - break; - } - fflush(stdout); - } - /* at least one frame has been written. loop through circular buffer */ - /* and write out all completed frames */ - while(file_write) { - /* capture frame length and check buffer to see if one or more frames */ - /* are available. */ - frame_len = circ_buf[rd_idx]; - bytes_in_buf = calc_bytes_in_buf(); - - if(bytes_in_buf > frame_len) { - /* if more than one frame is available, then write one frame to */ - /* wireshark and then see if any more are available. */ - write_frame(frame_len); - } else if(bytes_in_buf == frame_len) { - /* only one frame is available. write to wireshark and then quit */ - /* the loop */ - write_frame(frame_len); - file_write = 0; - } else { - /* less than one frame is available. quit the loop and collect more */ - /* bytes. we normally should not get here. */ - file_write = 0; - } - } - } - } - } -}