Merge pull request #1530 from herjulf/avr-rss2
Adding AtMegaXXRFR2 support and avr-rss2 platform
This commit is contained in:
commit
c5bea81bb6
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__) \
|
||||
|
|
|
@ -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
|
||||
|
|
399
cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h
Normal file
399
cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h
Normal file
|
@ -0,0 +1,399 @@
|
|||
/**
|
||||
* @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_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
|
||||
#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 */
|
|
@ -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 );
|
||||
|
|
|
@ -74,8 +74,9 @@ extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
|||
#include "hal.h"
|
||||
|
||||
#if defined(__AVR_ATmega128RFA1__)
|
||||
#include <avr/io.h>
|
||||
#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 <avr/interrupt.h>
|
||||
|
@ -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) */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -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<<PE1); //ledon
|
||||
#endif
|
||||
#if defined(__AVR_ATmega128RFA1__)
|
||||
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__)
|
||||
/* Use the poweron interrupt for delay */
|
||||
rf230_wakewait=1;
|
||||
{
|
||||
|
@ -937,7 +955,7 @@ rf230_transmit(unsigned short payload_len)
|
|||
/* If radio is sleeping we have to turn it on first */
|
||||
/* This automatically does the PLL calibrations */
|
||||
if (hal_get_slptr()) {
|
||||
#if defined(__AVR_ATmega128RFA1__)
|
||||
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega128RFR2__) || defined(__AVR_ATmega256RFR2__)
|
||||
ENERGEST_ON(ENERGEST_TYPE_LED_RED);
|
||||
#if RF230BB_CONF_LEDONPORTE1
|
||||
PORTE|=(1<<PE1); //ledon
|
||||
|
@ -1383,6 +1401,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;i<len;i++) putchar(rxdata[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#if DEBUG>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 */
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
9
examples/avr-rss2/avr_radio_power/Makefile
Normal file
9
examples/avr-rss2/avr_radio_power/Makefile
Normal file
|
@ -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
|
79
examples/avr-rss2/avr_radio_power/README.md
Normal file
79
examples/avr-rss2/avr_radio_power/README.md
Normal file
|
@ -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.
|
164
examples/avr-rss2/avr_radio_power/avr_radio_power.c
Normal file
164
examples/avr-rss2/avr_radio_power/avr_radio_power.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include "dev/leds.h"
|
||||
#include "rf230bb.h"
|
||||
#include "net/packetbuf.h"
|
||||
#include "net/rime/rimestats.h"
|
||||
#include "net/netstack.h"
|
||||
#include <avr/sleep.h>
|
||||
#include <dev/watchdog.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
51
examples/avr-rss2/avr_radio_power/project-conf.h
Normal file
51
examples/avr-rss2/avr_radio_power/project-conf.h
Normal file
|
@ -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_ */
|
19
examples/avr-rss2/hello-sensors/Makefile
Normal file
19
examples/avr-rss2/hello-sensors/Makefile
Normal file
|
@ -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
|
11
examples/avr-rss2/hello-sensors/README.md
Normal file
11
examples/avr-rss2/hello-sensors/README.md
Normal file
|
@ -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
|
119
examples/avr-rss2/hello-sensors/hello-sensors.c
Normal file
119
examples/avr-rss2/hello-sensors/hello-sensors.c
Normal file
|
@ -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 <stdio.h>
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
51
examples/avr-rss2/hello-sensors/project-conf.h
Normal file
51
examples/avr-rss2/hello-sensors/project-conf.h
Normal file
|
@ -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_ */
|
49
examples/avr-rss2/ipv6/dc-rpl-coap/Makefile
Normal file
49
examples/avr-rss2/ipv6/dc-rpl-coap/Makefile
Normal file
|
@ -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
|
67
examples/avr-rss2/ipv6/dc-rpl-coap/README.md
Normal file
67
examples/avr-rss2/ipv6/dc-rpl-coap/README.md
Normal file
|
@ -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)
|
||||
|
413
examples/avr-rss2/ipv6/dc-rpl-coap/coap-client.c
Normal file
413
examples/avr-rss2/ipv6/dc-rpl-coap/coap-client.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/**************************************************************************/
|
||||
/* from er-rest-example/er-rexample-client.c */
|
||||
#include <stdlib.h>
|
||||
#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 <stdio.h>
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
269
examples/avr-rss2/ipv6/dc-rpl-coap/coap-server.c
Normal file
269
examples/avr-rss2/ipv6/dc-rpl-coap/coap-server.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
#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 <stdio.h> */
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
168
examples/avr-rss2/ipv6/dc-rpl-coap/dc-rpl-coap.csc
Normal file
168
examples/avr-rss2/ipv6/dc-rpl-coap/dc-rpl-coap.csc
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/native_gateway</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
|
||||
<project EXPORT="discard">/home/user/contikiprojects/sics.se/mobility</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
|
||||
<project EXPORT="discard">/home/user/contikiprojects/sics.se/powertracker</project>
|
||||
<simulation>
|
||||
<title>My simulation</title>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
se.sics.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
se.sics.cooja.avrmote.RSS2MoteType
|
||||
<identifier>mote1</identifier>
|
||||
<description>Mote1</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.c</source>
|
||||
<commands EXPORT="discard">make coap-server.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-server.avr-rss2</firmware>
|
||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
|
||||
</motetype>
|
||||
<motetype>
|
||||
se.sics.cooja.avrmote.RSS2MoteType
|
||||
<identifier>mote2</identifier>
|
||||
<description>Mote2</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.c</source>
|
||||
<commands EXPORT="discard">make coap-client.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/dc-rpl-coap/coap-client.avr-rss2</firmware>
|
||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
se.sics.cooja.interfaces.Position
|
||||
<x>100.0</x>
|
||||
<y>100.0</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
se.sics.cooja.avrmote.interfaces.AvroraMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>mote1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
se.sics.cooja.interfaces.Position
|
||||
<x>110.0</x>
|
||||
<y>100.0</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
se.sics.cooja.avrmote.interfaces.AvroraMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>mote2</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.SimControl
|
||||
<width>280</width>
|
||||
<z>9</z>
|
||||
<height>160</height>
|
||||
<location_x>400</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<moterelations>true</moterelations>
|
||||
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>se.sics.cooja.plugins.skins.GridVisualizerSkin</skin>
|
||||
<viewport>3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074</viewport>
|
||||
</plugin_config>
|
||||
<width>400</width>
|
||||
<z>5</z>
|
||||
<height>400</height>
|
||||
<location_x>1</location_x>
|
||||
<location_y>1</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
<formatted_time />
|
||||
<coloring />
|
||||
</plugin_config>
|
||||
<width>1269</width>
|
||||
<z>8</z>
|
||||
<height>240</height>
|
||||
<location_x>400</location_x>
|
||||
<location_y>160</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.Notes
|
||||
<plugin_config>
|
||||
<notes>Enter notes here</notes>
|
||||
<decorations>true</decorations>
|
||||
</plugin_config>
|
||||
<width>989</width>
|
||||
<z>6</z>
|
||||
<height>160</height>
|
||||
<location_x>680</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.MoteInterfaceViewer
|
||||
<mote_arg>0</mote_arg>
|
||||
<plugin_config>
|
||||
<interface>Serial port</interface>
|
||||
<scrollpos>0,0</scrollpos>
|
||||
</plugin_config>
|
||||
<width>508</width>
|
||||
<z>4</z>
|
||||
<height>389</height>
|
||||
<location_x>13</location_x>
|
||||
<location_y>413</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.MoteInterfaceViewer
|
||||
<mote_arg>1</mote_arg>
|
||||
<plugin_config>
|
||||
<interface>Serial port</interface>
|
||||
<scrollpos>0,0</scrollpos>
|
||||
</plugin_config>
|
||||
<width>545</width>
|
||||
<z>3</z>
|
||||
<height>392</height>
|
||||
<location_x>531</location_x>
|
||||
<location_y>413</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
93
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c
Normal file
93
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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);
|
||||
|
46
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h
Normal file
46
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-hw-sensor.h
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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 */
|
84
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.c
Normal file
84
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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);
|
||||
|
46
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.h
Normal file
46
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-status-sensor.h
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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 */
|
97
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c
Normal file
97
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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);
|
||||
|
46
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h
Normal file
46
examples/avr-rss2/ipv6/dc-rpl-coap/dev/dc-vdc-sensor.h
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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 */
|
62
examples/avr-rss2/ipv6/dc-rpl-coap/er-dc-test.h
Normal file
62
examples/avr-rss2/ipv6/dc-rpl-coap/er-dc-test.h
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#ifndef __ER_DC_TEST_H__
|
||||
#define __ER_DC_TEST_H__
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#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__ */
|
61
examples/avr-rss2/ipv6/dc-rpl-coap/project-conf.h
Normal file
61
examples/avr-rss2/ipv6/dc-rpl-coap/project-conf.h
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#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_ */
|
83
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-co2.c
Normal file
83
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-co2.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
/* #include <math.h> */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
}
|
||||
|
120
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c
Normal file
120
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-hwcfg.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
/* #include <math.h> */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
}
|
113
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c
Normal file
113
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-status-obs.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
}
|
129
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-vdc.c
Normal file
129
examples/avr-rss2/ipv6/dc-rpl-coap/resources/res-dc-vdc.c
Normal file
|
@ -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 <voravit@kth.se>
|
||||
*/
|
||||
|
||||
/* #include <math.h> */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
}
|
55
examples/avr-rss2/ipv6/rpl-border-router/Makefile
Normal file
55
examples/avr-rss2/ipv6/rpl-border-router/Makefile
Normal file
|
@ -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)
|
66
examples/avr-rss2/ipv6/rpl-border-router/README.ETHERNET.md
Normal file
66
examples/avr-rss2/ipv6/rpl-border-router/README.ETHERNET.md
Normal file
|
@ -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
|
||||
-----------
|
||||
|
||||
|
||||
|
17
examples/avr-rss2/ipv6/rpl-border-router/README.md
Normal file
17
examples/avr-rss2/ipv6/rpl-border-router/README.md
Normal file
|
@ -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.
|
||||
|
||||
|
||||
|
388
examples/avr-rss2/ipv6/rpl-border-router/border-router.c
Normal file
388
examples/avr-rss2/ipv6/rpl-border-router/border-router.c
Normal file
|
@ -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 <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
*/
|
||||
|
||||
#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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#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 = "<html><head><title>ContikiRPL</title></head><body>\n";
|
||||
static const char *BOTTOM = "</body></html>\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<pre>");
|
||||
|
||||
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("</pre>Routes<pre>");
|
||||
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("<a href=http://[");
|
||||
ipaddr_add(&r->ipaddr);
|
||||
ADD("]/status.shtml>");
|
||||
ipaddr_add(&r->ipaddr);
|
||||
ADD("</a>");
|
||||
#else
|
||||
ipaddr_add(&r->ipaddr);
|
||||
#endif
|
||||
#else
|
||||
#if WEBSERVER_CONF_ROUTE_LINKS
|
||||
ADD("<a href=http://[");
|
||||
ipaddr_add(&r->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("</a>");
|
||||
#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("</pre>");
|
||||
|
||||
#if WEBSERVER_CONF_FILESTATS
|
||||
static uint16_t numtimes;
|
||||
ADD("<br><i>This page sent %u times</i>",++numtimes);
|
||||
#endif
|
||||
|
||||
#if WEBSERVER_CONF_LOADTIME
|
||||
numticks = clock_time() - numticks + 1;
|
||||
ADD(" <i>(%lu.%02lu sec)</i>",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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
104
examples/avr-rss2/ipv6/rpl-border-router/enc28j60-ip64-driver.c
Normal file
104
examples/avr-rss2/ipv6/rpl-border-router/enc28j60-ip64-driver.c
Normal file
|
@ -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 <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -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 */
|
33
examples/avr-rss2/ipv6/rpl-border-router/eth-bridge.c
Normal file
33
examples/avr-rss2/ipv6/rpl-border-router/eth-bridge.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "net/ip/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#include <string.h>
|
||||
#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
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
261
examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.c
Normal file
261
examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.c
Normal file
|
@ -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 <adam@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 = "<html><body bgcolor=\"white\">"
|
||||
"<center>"
|
||||
"<h1>404 - file not found</h1>"
|
||||
"</center>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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 */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
74
examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.h
Normal file
74
examples/avr-rss2/ipv6/rpl-border-router/httpd-simple.h
Normal file
|
@ -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 <adam@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#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_ */
|
57
examples/avr-rss2/ipv6/rpl-border-router/project-conf.h
Normal file
57
examples/avr-rss2/ipv6/rpl-border-router/project-conf.h
Normal file
|
@ -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_ */
|
21
examples/avr-rss2/ipv6/rpl-udp-report/Makefile
Normal file
21
examples/avr-rss2/ipv6/rpl-udp-report/Makefile
Normal file
|
@ -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
|
17
examples/avr-rss2/ipv6/rpl-udp-report/README.md
Normal file
17
examples/avr-rss2/ipv6/rpl-udp-report/README.md
Normal file
|
@ -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)
|
||||
|
||||
|
51
examples/avr-rss2/ipv6/rpl-udp-report/project-conf.h
Normal file
51
examples/avr-rss2/ipv6/rpl-udp-report/project-conf.h
Normal file
|
@ -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 <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#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_ */
|
240
examples/avr-rss2/ipv6/rpl-udp-report/report.c
Normal file
240
examples/avr-rss2/ipv6/rpl-udp-report/report.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
167
examples/avr-rss2/ipv6/rpl-udp-report/rss2-rpl-udp.csc
Normal file
167
examples/avr-rss2/ipv6/rpl-udp-report/rss2-rpl-udp.csc
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/native_gateway</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
|
||||
<project EXPORT="discard">/home/user/contikiprojects/sics.se/mobility</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
|
||||
<project EXPORT="discard">/home/user/contikiprojects/sics.se/powertracker</project>
|
||||
<simulation>
|
||||
<title>UDP sink/report simulation</title>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
se.sics.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
se.sics.cooja.avrmote.RSS2MoteType
|
||||
<identifier>mote1</identifier>
|
||||
<description>Mote1</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.c</source>
|
||||
<commands EXPORT="discard">make report.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/report.avr-rss2</firmware>
|
||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
|
||||
</motetype>
|
||||
<motetype>
|
||||
se.sics.cooja.avrmote.RSS2MoteType
|
||||
<identifier>mote2</identifier>
|
||||
<description>Mote2</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.c</source>
|
||||
<commands EXPORT="discard">make sink.avr-rss2 TARGET=avr-rss2 MCU=atmega128rfr2</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/platform/avr-rss2/examples/ipv6/rpl-udp-report/sink.avr-rss2</firmware>
|
||||
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraClock</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraMoteID</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart0</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraUsart1</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.RFR2Radio</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraADC</moteinterface>
|
||||
<moteinterface>se.sics.cooja.avrmote.interfaces.AvroraLED</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
se.sics.cooja.interfaces.Position
|
||||
<x>100.0</x>
|
||||
<y>100.0</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
se.sics.cooja.avrmote.interfaces.AvroraMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>mote1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
se.sics.cooja.interfaces.Position
|
||||
<x>110.0</x>
|
||||
<y>100.0</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
se.sics.cooja.avrmote.interfaces.AvroraMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>mote2</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.SimControl
|
||||
<width>280</width>
|
||||
<z>9</z>
|
||||
<height>160</height>
|
||||
<location_x>400</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<moterelations>true</moterelations>
|
||||
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>se.sics.cooja.plugins.skins.GridVisualizerSkin</skin>
|
||||
<viewport>3.908924509090908 0.0 0.0 3.908924509090908 -216.43707345454544 -217.89245090909074</viewport>
|
||||
</plugin_config>
|
||||
<width>400</width>
|
||||
<z>5</z>
|
||||
<height>400</height>
|
||||
<location_x>1</location_x>
|
||||
<location_y>1</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
<formatted_time />
|
||||
<coloring />
|
||||
</plugin_config>
|
||||
<width>1269</width>
|
||||
<z>8</z>
|
||||
<height>240</height>
|
||||
<location_x>400</location_x>
|
||||
<location_y>160</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.Notes
|
||||
<plugin_config>
|
||||
<notes>Enter notes here</notes>
|
||||
<decorations>true</decorations>
|
||||
</plugin_config>
|
||||
<width>989</width>
|
||||
<z>6</z>
|
||||
<height>160</height>
|
||||
<location_x>680</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.MoteInterfaceViewer
|
||||
<mote_arg>0</mote_arg>
|
||||
<plugin_config>
|
||||
<interface>Serial port</interface>
|
||||
<scrollpos>0,0</scrollpos>
|
||||
</plugin_config>
|
||||
<width>508</width>
|
||||
<z>4</z>
|
||||
<height>389</height>
|
||||
<location_x>13</location_x>
|
||||
<location_y>413</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
se.sics.cooja.plugins.MoteInterfaceViewer
|
||||
<mote_arg>1</mote_arg>
|
||||
<plugin_config>
|
||||
<interface>Serial port</interface>
|
||||
<scrollpos>0,0</scrollpos>
|
||||
</plugin_config>
|
||||
<width>545</width>
|
||||
<z>3</z>
|
||||
<height>392</height>
|
||||
<location_x>531</location_x>
|
||||
<location_y>413</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
184
examples/avr-rss2/ipv6/rpl-udp-report/sink.c
Normal file
184
examples/avr-rss2/ipv6/rpl-udp-report/sink.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
12
examples/avr-rss2/ipv6/sensd_client/Makefile
Normal file
12
examples/avr-rss2/ipv6/sensd_client/Makefile
Normal file
|
@ -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
|
222
examples/avr-rss2/ipv6/sensd_client/README.md
Normal file
222
examples/avr-rss2/ipv6/sensd_client/README.md
Normal file
|
@ -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 <robert@radio-sensors.com>
|
||||
Jens Laas <jens.laas@uadm.uu.se>
|
||||
|
||||
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.
|
||||
|
||||
|
51
examples/avr-rss2/ipv6/sensd_client/project-conf.h
Normal file
51
examples/avr-rss2/ipv6/sensd_client/project-conf.h
Normal file
|
@ -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 <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#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_ */
|
203
examples/avr-rss2/ipv6/sensd_client/sensd_client.c
Normal file
203
examples/avr-rss2/ipv6/sensd_client/sensd_client.c
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* 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 <string.h>
|
||||
#include "contiki-net.h"
|
||||
#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
|
||||
|
||||
#ifndef PERIOD
|
||||
#define PERIOD 10
|
||||
#endif
|
||||
|
||||
#define REPORT_INTERVAL (PERIOD * CLOCK_SECOND)
|
||||
|
||||
#define DEBUG DEBUG_PRINT
|
||||
#include "uip-debug.h"
|
||||
|
||||
#define PORT 1234
|
||||
#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=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(CO2_SA_KXX_CO2));
|
||||
#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();
|
||||
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, 0x0255);
|
||||
uip_ip6addr(&addr, 0x0000, 0, 0, 0, 0, 0xffff, 0xc010, 0x7dea); //192.16.125.234
|
||||
|
||||
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();
|
||||
}
|
128
examples/avr-rss2/ipv6/sensd_client/server.c
Normal file
128
examples/avr-rss2/ipv6/sensd_client/server.c
Normal file
|
@ -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 <string.h>
|
||||
#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();
|
||||
}
|
||||
|
61
platform/avr-rss2/Makefile.avr-rss2
Normal file
61
platform/avr-rss2/Makefile.avr-rss2
Normal file
|
@ -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
|
||||
|
||||
|
||||
|
175
platform/avr-rss2/README.md
Normal file
175
platform/avr-rss2/README.md
Normal file
|
@ -0,0 +1,175 @@
|
|||
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 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.
|
||||
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.
|
||||
|
||||
Board 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
|
||||
|
||||
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
|
||||
|
||||
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`
|
||||
* `examples/powertrace`
|
||||
* `example-shell`
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Platform tutorial applications
|
||||
-----------------------------
|
||||
Example to read out various sensors, leds, serial numbers, and so on:
|
||||
[platform/avr-rss2/examples/hello-sensors/](examples/hello-sensors/).
|
||||
|
||||
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).
|
||||
|
||||
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 test for the platform:
|
||||
[regression-tests/23-compile-avr](../../regression-tests/23-compile-avr).
|
||||
|
||||
This port adds newer version of `avr-gcc` compiler (4.9.2), to support
|
||||
testing of newer Atmel MCU as Atmega256RFR2.
|
||||
|
||||
|
||||
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 <robert@radio-sensors.com>
|
11
platform/avr-rss2/apps/sniffer/Makefile
Normal file
11
platform/avr-rss2/apps/sniffer/Makefile
Normal file
|
@ -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
|
29
platform/avr-rss2/apps/sniffer/README.md
Normal file
29
platform/avr-rss2/apps/sniffer/README.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
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.
|
||||
|
||||
References
|
||||
----------
|
||||
https://github.com/g-oikonomou/sensniff
|
51
platform/avr-rss2/apps/sniffer/project-conf.h
Normal file
51
platform/avr-rss2/apps/sniffer/project-conf.h
Normal file
|
@ -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 - <oikonomou@users.sourceforge.net>
|
||||
* Robert Olsson - <robert@radio.sensors.com>
|
||||
*/
|
||||
|
||||
#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_ */
|
67
platform/avr-rss2/apps/sniffer/sniffer.c
Normal file
67
platform/avr-rss2/apps/sniffer/sniffer.c
Normal file
|
@ -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 <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "net/rime/rime.h"
|
||||
#include "random.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
100
platform/avr-rss2/apps/sniffer/stub-rdc.c
Normal file
100
platform/avr-rss2/apps/sniffer/stub-rdc.c
Normal file
|
@ -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 - <oikonomou@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
#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,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
350
platform/avr-rss2/contiki-conf.h
Normal file
350
platform/avr-rss2/contiki-conf.h
Normal file
|
@ -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 <stdint.h>
|
||||
|
||||
#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_ */
|
640
platform/avr-rss2/contiki-main.c
Normal file
640
platform/avr-rss2/contiki-main.c
Normal file
|
@ -0,0 +1,640 @@
|
|||
/*
|
||||
* 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 <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#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 <avr/pgmspace.h>
|
||||
#include <avr/fuse.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dev/watchdog.h>
|
||||
|
||||
#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 <avr/signature.h>
|
||||
#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 = 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);
|
||||
|
||||
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 <util/delay_basic.h> */
|
||||
/* #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;
|
||||
char eui64[8];
|
||||
|
||||
printf("I2C: ");
|
||||
i2c_probed = i2c_probe();
|
||||
printf("\n");
|
||||
|
||||
if( i2c_probed & I2C_AT24MAC ) {
|
||||
i2c_at24mac_read((char *)&eui64, 1);
|
||||
linkaddr_set_node_addr((linkaddr_t *) &eui64);
|
||||
node_id = (eui64[1] << 8) + eui64[7];
|
||||
}
|
||||
else {
|
||||
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((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
|
||||
|
||||
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;
|
||||
addr.u8[0] = eui64[1] ;
|
||||
addr.u8[1] = eui64[7];
|
||||
|
||||
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); */
|
||||
/* <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> */
|
||||
}
|
||||
#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(" <none>");
|
||||
}
|
||||
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(" <none>");
|
||||
}
|
||||
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);
|
||||
}
|
76
platform/avr-rss2/dev/adc.c
Normal file
76
platform/avr-rss2/dev/adc.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* Copyright Robert Olsson */
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/fuse.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dev/watchdog.h>
|
||||
#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;
|
||||
}
|
16
platform/avr-rss2/dev/adc.h
Normal file
16
platform/avr-rss2/dev/adc.h
Normal file
|
@ -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);
|
||||
|
87
platform/avr-rss2/dev/battery-sensor.c
Normal file
87
platform/avr-rss2/dev/battery-sensor.c
Normal file
|
@ -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 <util/delay_basic.h>
|
||||
#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);
|
||||
|
41
platform/avr-rss2/dev/button-sensor.c
Normal file
41
platform/avr-rss2/dev/button-sensor.c
Normal file
|
@ -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);
|
||||
|
131
platform/avr-rss2/dev/co2_sa_kxx-sensor.c
Normal file
131
platform/avr-rss2/dev/co2_sa_kxx-sensor.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <i2c.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/boot.h>
|
||||
#include <avr/eeprom.h>
|
||||
#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);
|
51
platform/avr-rss2/dev/co2_sa_kxx-sensor.h
Normal file
51
platform/avr-rss2/dev/co2_sa_kxx-sensor.h
Normal file
|
@ -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_ */
|
247
platform/avr-rss2/dev/ds18b20.c
Normal file
247
platform/avr-rss2/dev/ds18b20.c
Normal file
|
@ -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;
|
||||
}
|
83
platform/avr-rss2/dev/enc28j60_avr.c
Normal file
83
platform/avr-rss2/dev/enc28j60_avr.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2013, Robert Olsson <robert@radio-sensors.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 <avr/pgmspace.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/sleep.h>
|
||||
#include "dev/watchdog.h"
|
||||
#include "contiki.h"
|
||||
#include "i2c.h"
|
||||
#include <compat/twi.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "enc28j60_avr.h"
|
||||
|
||||
#include <util/delay_basic.h>
|
||||
#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<<SPI2X); */
|
||||
}
|
||||
uint8_t
|
||||
enc28j60_arch_spi_write(uint8_t data)
|
||||
{
|
||||
SPDR = data;
|
||||
while(!(SPSR & (1 << SPIF))) ;
|
||||
return SPDR;
|
||||
}
|
||||
uint8_t
|
||||
enc28j60_arch_spi_read(void)
|
||||
{
|
||||
SPDR = 0xAA; /* dummy */
|
||||
while(!(SPSR & (1 << SPIF))) ;
|
||||
return SPDR;
|
||||
}
|
||||
void
|
||||
enc28j60_arch_spi_select(void)
|
||||
{
|
||||
CS_SPI_PORT &= ~(1 << SPI_CS);
|
||||
delay_us(1000);
|
||||
}
|
||||
void
|
||||
enc28j60_arch_spi_deselect(void)
|
||||
{
|
||||
CS_SPI_PORT |= (1 << SPI_CS);
|
||||
}
|
53
platform/avr-rss2/dev/enc28j60_avr.h
Normal file
53
platform/avr-rss2/dev/enc28j60_avr.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2013, Robert Olsson <robert@radio-sensors.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_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 */
|
228
platform/avr-rss2/dev/i2c.c
Normal file
228
platform/avr-rss2/dev/i2c.c
Normal file
|
@ -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 <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/wdt.h>
|
||||
#include "dev/watchdog.h"
|
||||
#include "contiki.h"
|
||||
#include "i2c.h"
|
||||
#include <compat/twi.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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<<TWINT) | (1<<TWSTA) | (1<<TWEN);
|
||||
// wait until transmission completed
|
||||
while(!(TWCR & (1<<TWINT)));
|
||||
// check value of TWI Status Register. Mask prescaler bits.
|
||||
twst = TW_STATUS & 0xF8;
|
||||
if ( (twst != TW_START) && (twst != TW_REP_START)) continue;
|
||||
// send device address
|
||||
TWDR = addr;
|
||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||
// wail until transmission completed
|
||||
while(!(TWCR & (1<<TWINT)));
|
||||
// check value of TWI Status Register. Mask prescaler bits.
|
||||
twst = TW_STATUS & 0xF8;
|
||||
if ( (twst == TW_MT_SLA_NACK )||(twst ==TW_MR_DATA_NACK) )
|
||||
{
|
||||
/* device busy, send stop condition to terminate write operation */
|
||||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
||||
// wait until stop condition is executed and bus released
|
||||
while(TWCR & (1<<TWSTO));
|
||||
continue;
|
||||
}
|
||||
//if( twst != TW_MT_SLA_ACK) return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void
|
||||
i2c_stop(void)
|
||||
{
|
||||
TWCR = (1 << TWINT) | (1 << TWSTO) | (1 << TWEN);
|
||||
/* wait until ready */
|
||||
while(TWCR & (1<<TWSTO));
|
||||
}
|
||||
void
|
||||
i2c_write(uint8_t u8data)
|
||||
{
|
||||
TWDR = u8data;
|
||||
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||
while((TWCR & (1 << TWINT)) == 0) ;
|
||||
}
|
||||
uint8_t
|
||||
i2c_readAck(void)
|
||||
{
|
||||
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA);
|
||||
while((TWCR & (1 << TWINT)) == 0) ;
|
||||
return TWDR;
|
||||
}
|
||||
uint8_t
|
||||
i2c_readNak(void)
|
||||
{
|
||||
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||
while((TWCR & (1 << TWINT)) == 0) ;
|
||||
return TWDR;
|
||||
}
|
||||
static void
|
||||
print_delim(int p, char *s, const char *d)
|
||||
{
|
||||
if(p) {
|
||||
printf("%s", d);
|
||||
}
|
||||
printf("%s", s);
|
||||
}
|
||||
void
|
||||
i2c_write_mem(uint8_t addr, uint8_t reg, uint8_t value)
|
||||
{
|
||||
i2c_start(addr | I2C_WRITE);
|
||||
i2c_write(reg);
|
||||
i2c_write(value);
|
||||
i2c_stop();
|
||||
}
|
||||
void
|
||||
i2c_read_mem(uint8_t addr, uint8_t reg, uint8_t buf[], uint8_t bytes)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
i2c_start(addr | I2C_WRITE);
|
||||
i2c_write(reg);
|
||||
i2c_start(addr | I2C_READ);
|
||||
for(i = 0; i < bytes; i++) {
|
||||
if(i == bytes - 1) {
|
||||
buf[i] = i2c_readNak();
|
||||
} else {
|
||||
buf[i] = i2c_readAck();
|
||||
}
|
||||
}
|
||||
i2c_stop();
|
||||
}
|
||||
void
|
||||
i2c_at24mac_read(char *buf, uint8_t eui64)
|
||||
{
|
||||
if(eui64) {
|
||||
i2c_read_mem(I2C_AT24MAC_ADDR, 0x98, (uint8_t *)buf, 8);
|
||||
}
|
||||
/* 128bit unique serial number */
|
||||
else {
|
||||
i2c_read_mem(I2C_AT24MAC_ADDR, 0x80, (uint8_t *)buf, 16);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t
|
||||
i2c_probe(void)
|
||||
{
|
||||
int p = 0;
|
||||
const char *del = ",";
|
||||
uint16_t probed = 0;
|
||||
watchdog_periodic();
|
||||
if(!i2c_start(I2C_AT24MAC_ADDR)) {
|
||||
i2c_stop();
|
||||
probed |= I2C_AT24MAC;
|
||||
print_delim(p++, "AT24MAC", del);
|
||||
}
|
||||
watchdog_periodic();
|
||||
if(!i2c_start(I2C_SHT2X_ADDR)) {
|
||||
i2c_stop();
|
||||
probed |= I2C_SHT2X;
|
||||
print_delim(p++, "SHT2X", del);
|
||||
}
|
||||
watchdog_periodic();
|
||||
if(!i2c_start(I2C_CO2SA_ADDR)) {
|
||||
i2c_stop();
|
||||
probed |= I2C_CO2SA;
|
||||
print_delim(p++, "CO2SA", del);
|
||||
}
|
||||
return probed;
|
||||
}
|
65
platform/avr-rss2/dev/i2c.h
Normal file
65
platform/avr-rss2/dev/i2c.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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
|
||||
* includes for i2c core functions
|
||||
* \author
|
||||
* Robert Olsson <robert@radio-sensors.com>
|
||||
*/
|
||||
|
||||
#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 */
|
45
platform/avr-rss2/dev/leds.c
Normal file
45
platform/avr-rss2/dev/leds.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <avr/pgmspace.h>
|
||||
#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;
|
||||
}
|
17
platform/avr-rss2/dev/leds.h
Normal file
17
platform/avr-rss2/dev/leds.h
Normal file
|
@ -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_ */
|
64
platform/avr-rss2/dev/light-sensor.c
Normal file
64
platform/avr-rss2/dev/light-sensor.c
Normal file
|
@ -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);
|
45
platform/avr-rss2/dev/light-sensor.h
Normal file
45
platform/avr-rss2/dev/light-sensor.h
Normal file
|
@ -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_ */
|
120
platform/avr-rss2/dev/pulse-sensor.c
Normal file
120
platform/avr-rss2/dev/pulse-sensor.c
Normal file
|
@ -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);
|
43
platform/avr-rss2/dev/pulse-sensor.h
Normal file
43
platform/avr-rss2/dev/pulse-sensor.h
Normal file
|
@ -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_ */
|
292
platform/avr-rss2/dev/temp-sensor.c
Normal file
292
platform/avr-rss2/dev/temp-sensor.c
Normal file
|
@ -0,0 +1,292 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Copyright Per Lindgren <per.o.lindgren@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* Author : Per Lindgren <per.o.lindgren@gmail.com>
|
||||
* Hacked by: Robert Olsson robert@radio-sensors.com
|
||||
* Created : 2015-11-22
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/temp-sensor.h"
|
||||
#include <util/delay_basic.h>
|
||||
#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);
|
71
platform/avr-rss2/dev/temp-sensor.h
Normal file
71
platform/avr-rss2/dev/temp-sensor.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Copyright Per Lindgren <per.o.lindgren@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* Author : Per Lindgren <per.o.lindgren@gmail.com>
|
||||
* 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 <sys/clock.h>
|
||||
#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_ */
|
90
platform/avr-rss2/dev/temp_mcu-sensor.c
Normal file
90
platform/avr-rss2/dev/temp_mcu-sensor.c
Normal file
|
@ -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 <util/delay_basic.h>
|
||||
#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);
|
||||
|
47
platform/avr-rss2/dev/temp_mcu-sensor.h
Normal file
47
platform/avr-rss2/dev/temp_mcu-sensor.h
Normal file
|
@ -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_ */
|
42
platform/avr-rss2/ip64-conf.h
Normal file
42
platform/avr-rss2/ip64-conf.h
Normal file
|
@ -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 */
|
284
platform/avr-rss2/params.c
Normal file
284
platform/avr-rss2/params.c
Normal file
|
@ -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 <avr/pgmspace.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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 */
|
108
platform/avr-rss2/params.h
Normal file
108
platform/avr-rss2/params.h
Normal file
|
@ -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__ */
|
36
platform/avr-rss2/rss2.h
Normal file
36
platform/avr-rss2/rss2.h
Normal file
|
@ -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 */
|
||||
|
93
platform/avr-rss2/slip_uart0.c
Normal file
93
platform/avr-rss2/slip_uart0.c
Normal file
|
@ -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 <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
*/
|
14
regression-tests/23-compile-avr/Makefile
Normal file
14
regression-tests/23-compile-avr/Makefile
Normal file
|
@ -0,0 +1,14 @@
|
|||
EXAMPLESDIR=../..
|
||||
TOOLSDIR=../../tools
|
||||
|
||||
# build avr-rss2 examples, covering IPv6, RPL, Rime, Nullrdc, Contikimac
|
||||
|
||||
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/powertrace/avr-rss2 \
|
||||
examples/rime/avr-rss2
|
||||
TOOLS=
|
||||
|
||||
include ../Makefile.compile-test
|
Loading…
Reference in a new issue