added guhRF; added atmega256rfr2 support
This commit is contained in:
parent
9a3c6adf8d
commit
79df347afa
|
@ -73,7 +73,7 @@
|
||||||
TIMSK0 = _BV (OCIE0A);
|
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_ATmega256RFR2__)
|
||||||
/*
|
/*
|
||||||
The Raven has a 32768Hz watch crystal that can be used to clock the timer
|
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
|
while the 1284p is sleeping. The Jackdaw has pads for a crystal. The crystal
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
#define NUMPORTS RS232_CONF_NUMPORTS
|
#define NUMPORTS RS232_CONF_NUMPORTS
|
||||||
#endif
|
#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_ATmega256RFR2__)
|
||||||
#ifndef NUMPORTS
|
#ifndef NUMPORTS
|
||||||
#define NUMPORTS 2
|
#define NUMPORTS 2
|
||||||
#elif NUMPORTS > 2
|
#elif NUMPORTS > 2
|
||||||
|
|
|
@ -49,6 +49,8 @@
|
||||||
#include "dev/rs232_at90usb1287.h"
|
#include "dev/rs232_at90usb1287.h"
|
||||||
#elif defined (__AVR_ATmega128RFA1__)
|
#elif defined (__AVR_ATmega128RFA1__)
|
||||||
#include "dev/rs232_atmega128rfa1.h"
|
#include "dev/rs232_atmega128rfa1.h"
|
||||||
|
#elif defined (__AVR_ATmega256RFR2__)
|
||||||
|
#include "dev/rs232_atmega256rfr2.h"
|
||||||
#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
|
#elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega328P__)
|
||||||
#include "dev/rs232_atmega644.h"
|
#include "dev/rs232_atmega644.h"
|
||||||
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \
|
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega8515__) \
|
||||||
|
|
142
cpu/avr/dev/rs232_atmega256rfr2.h
Normal file
142
cpu/avr/dev/rs232_atmega256rfr2.h
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* AVR specific definitions for the rs232 port.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Simon Barner <barner@in.tum.de
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RS232_ATMEGA256RFR2__
|
||||||
|
#define __RS232_ATMEGA256RFR2__
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Includes */
|
||||||
|
/******************************************************************************/
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** RS232 ports */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define RS232_PORT_0 0
|
||||||
|
#define RS232_PORT_1 1
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Baud rates */
|
||||||
|
/******************************************************************************/
|
||||||
|
#if (F_CPU == 16000000UL)
|
||||||
|
/* Single speed operation (U2X = 0)*/
|
||||||
|
#define USART_BAUD_2400 416
|
||||||
|
#define USART_BAUD_4800 207
|
||||||
|
#define USART_BAUD_9600 103
|
||||||
|
#define USART_BAUD_14400 68
|
||||||
|
#define USART_BAUD_19200 51
|
||||||
|
#define USART_BAUD_28800 34
|
||||||
|
#define USART_BAUD_38400 25
|
||||||
|
#define USART_BAUD_57600 16
|
||||||
|
#define USART_BAUD_76800 12
|
||||||
|
#define USART_BAUD_115200 8
|
||||||
|
#define USART_BAUD_230400 3
|
||||||
|
#define USART_BAUD_250000 3
|
||||||
|
#define USART_BAUD_500000 1
|
||||||
|
#define USART_BAUD_1000000 0
|
||||||
|
#elif (F_CPU == 8000000UL)
|
||||||
|
/* Single speed operation (U2X = 0)*/
|
||||||
|
#define USART_BAUD_2400 207
|
||||||
|
#define USART_BAUD_4800 103
|
||||||
|
#define USART_BAUD_9600 51
|
||||||
|
#define USART_BAUD_14400 34
|
||||||
|
#define USART_BAUD_19200 25
|
||||||
|
#define USART_BAUD_28800 16
|
||||||
|
#define USART_BAUD_38400 12
|
||||||
|
#define USART_BAUD_57600 8
|
||||||
|
#define USART_BAUD_76800 6
|
||||||
|
#define USART_BAUD_115200 3
|
||||||
|
#define USART_BAUD_230400 1
|
||||||
|
#define USART_BAUD_250000 1
|
||||||
|
#define USART_BAUD_500000 0
|
||||||
|
#else
|
||||||
|
#error "Please define the baud rates for your CPU clock (see ATmega256rfr2 datasheet) \
|
||||||
|
or set the rate in contiki-conf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Interrupt settings */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_INTERRUPT_RX_COMPLETE _BV (RXCIE0)
|
||||||
|
#define USART_INTERRUPT_TX_COMPLETE _BV (TXCIE0)
|
||||||
|
#define USART_INTERRUPT_DATA_REG_EMPTY _BV (UDRIE0)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Receiver / transmitter */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_RECEIVER_ENABLE _BV (RXEN0)
|
||||||
|
#define USART_TRANSMITTER_ENABLE _BV (TXEN0)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Mode select */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_MODE_ASYNC 0x00
|
||||||
|
#define USART_MODE_SYNC _BV (UMSEL00)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Parity */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_PARITY_NONE 0x00
|
||||||
|
#define USART_PARITY_EVEN _BV (UPM01)
|
||||||
|
#define USART_PARITY_ODD _BV (UPM01) | _BV (UPM00)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Stop bits */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_STOP_BITS_1 0x00
|
||||||
|
#define USART_STOP_BITS_2 _BV (USBS)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Character size */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_DATA_BITS_5 0x00
|
||||||
|
#define USART_DATA_BITS_6 _BV (UCSZ00)
|
||||||
|
#define USART_DATA_BITS_7 _BV (UCSZ01)
|
||||||
|
#define USART_DATA_BITS_8 _BV (UCSZ01) | _BV (UCSZ00)
|
||||||
|
// #define USART_DATA_BITS_9 (needs also UCSZ2 bit in UCSRnB)
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/*** Clock polarity */
|
||||||
|
/******************************************************************************/
|
||||||
|
#define USART_RISING_XCKN_EDGE 0x00
|
||||||
|
#define USART_FALLING_XCKN_EDGE _BV (UCPOL0)
|
||||||
|
|
||||||
|
#endif /* #ifndef __RS232_ATMEGA128RFA1__ */
|
457
cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h
Normal file
457
cpu/avr/radio/rf230bb/atmega256rfr2_registermap.h
Normal file
|
@ -0,0 +1,457 @@
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
* ATmega256rfr2 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_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
|
||||||
|
//rfr2 special
|
||||||
|
#define CMD_NOP 0
|
||||||
|
#define CMD_TX_START 2
|
||||||
|
#define CMD_FORCE_TRX_OFF 3
|
||||||
|
#define CMD_FORCE_PLL_ON 4
|
||||||
|
#define CMD_RX_ON 6
|
||||||
|
#define CMD_TRX_OFF 8
|
||||||
|
#define CMD_PLL_ON 9
|
||||||
|
#define CMD_RX_AACK_ON 22
|
||||||
|
#define CMD_TX_ARET_ON 25
|
||||||
|
#define TRAC_SUCCESS 0
|
||||||
|
#define TRAC_SUCCESS_DATA_PENDING 1
|
||||||
|
#define TRAC_SUCCESS_WAIT_FOR_ACK 2
|
||||||
|
#define TRAC_CHANNEL_ACCESS_FAILURE 3
|
||||||
|
#define TRAC_NO_ACK 5
|
||||||
|
#define TRAC_INVALID 7
|
||||||
|
|
||||||
|
#define P_ON 0
|
||||||
|
#define BUSY_RX 1
|
||||||
|
#define BUSY_TX 2
|
||||||
|
#define RX_ON 6
|
||||||
|
#define TRX_OFF 8
|
||||||
|
#define PLL_ON 9
|
||||||
|
#define SLEEP 15
|
||||||
|
#define BUSY_RX_AACK 17
|
||||||
|
#define BUSY_TX_ARET 18
|
||||||
|
#define RX_AACK_ON 22
|
||||||
|
#define TX_ARET_ON 25
|
||||||
|
#define STATE_TRANSITION_IN_PROGRESS 31
|
||||||
|
#define TST_DISABLED 0
|
||||||
|
#define TST_ENABLED 1
|
||||||
|
#define CCA_BUSY 0
|
||||||
|
#define CCA_IDLE 1
|
||||||
|
#define CCA_NOT_FIN 0
|
||||||
|
#define CCA_FIN 1
|
||||||
|
|
||||||
|
#define CMD_NOP 0
|
||||||
|
#define CMD_TX_START 2
|
||||||
|
#define CMD_FORCE_TRX_OFF 3
|
||||||
|
#define CMD_FORCE_PLL_ON 4
|
||||||
|
#define CMD_RX_ON 6
|
||||||
|
#define CMD_TRX_OFF 8
|
||||||
|
#define CMD_PLL_ON 9
|
||||||
|
#define CMD_RX_AACK_ON 22
|
||||||
|
#define CMD_TX_ARET_ON 25
|
||||||
|
#define TRAC_SUCCESS 0
|
||||||
|
#define TRAC_SUCCESS_DATA_PENDING 1
|
||||||
|
#define TRAC_SUCCESS_WAIT_FOR_ACK 2
|
||||||
|
#define TRAC_CHANNEL_ACCESS_FAILURE 3
|
||||||
|
#define TRAC_NO_ACK 5
|
||||||
|
#define TRAC_INVALID 7
|
||||||
|
|
||||||
|
/** Offset for register TRX_CTRL_0 */
|
||||||
|
#define RG_TRX_CTRL_0 0x143
|
||||||
|
/** Offset for register TRX_CTRL_1 */
|
||||||
|
#define RG_TRX_CTRL_1 0x144
|
||||||
|
|
||||||
|
#define SR_PA_EXT_EN 0x144, 0x80, 7
|
||||||
|
#define SR_IRQ_2_EXT_EN 0x144, 0x40, 6
|
||||||
|
#define SR_ANT_EXT_SW_EN 0x14d, 0x04, 2
|
||||||
|
#define SR_ANT_DIV_EN 0x14d, 0x08, 3
|
||||||
|
#define SR_SET_OUT_ANT0 0x14d, 0x03, 1
|
||||||
|
#define SR_SET_OUT_ANT1 0x14d, 0x03, 0
|
||||||
|
|
||||||
|
/* RF230 register assignments, for reference */
|
||||||
|
#if 0
|
||||||
|
#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 /* PHY128RFA1_REGISTERMAP_EXTERNAL_H */
|
|
@ -78,6 +78,7 @@
|
||||||
#define ZIGBIT 4
|
#define ZIGBIT 4
|
||||||
#define IRIS 5
|
#define IRIS 5
|
||||||
#define ATMEGA128RFA1 6
|
#define ATMEGA128RFA1 6
|
||||||
|
#define ATMEGA256RFR2 7
|
||||||
|
|
||||||
#if PLATFORM_TYPE == RCB_B
|
#if PLATFORM_TYPE == RCB_B
|
||||||
/* 1281 rcb */
|
/* 1281 rcb */
|
||||||
|
@ -140,7 +141,7 @@
|
||||||
# define SLPTRPORT B
|
# define SLPTRPORT B
|
||||||
# define SLPTRPIN (0x04)
|
# define SLPTRPIN (0x04)
|
||||||
|
|
||||||
#elif PLATFORM_TYPE == ATMEGA128RFA1
|
#elif PLATFORM_TYPE == ATMEGA128RFA1 || PLATFORM_TYPE == ATMEGA256RFR2
|
||||||
/* ATmega1281 with internal AT86RF231 radio */
|
/* ATmega1281 with internal AT86RF231 radio */
|
||||||
# define SLPTRPORT TRXPR
|
# define SLPTRPORT TRXPR
|
||||||
# define SLPTRPIN 1
|
# define SLPTRPIN 1
|
||||||
|
@ -233,7 +234,7 @@
|
||||||
* that the source code can directly use.
|
* that the source code can directly use.
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
|
|
||||||
#define hal_set_rst_low( ) ( TRXPR &= ~( 1 << TRXRST ) ) /**< This macro pulls the RST pin low. */
|
#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. */
|
#define hal_set_rst_high( ) ( TRXPR |= ( 1 << TRXRST ) ) /**< This macro pulls the RST pin high. */
|
||||||
|
@ -367,7 +368,7 @@ typedef struct{
|
||||||
void hal_init( void );
|
void hal_init( void );
|
||||||
|
|
||||||
/* Hack for atmega128rfa1 with integrated radio. Access registers directly, not through SPI */
|
/* Hack for atmega128rfa1 with integrated radio. Access registers directly, not through SPI */
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
//#define hal_register_read(address) _SFR_MEM8((uint16_t)address)
|
//#define hal_register_read(address) _SFR_MEM8((uint16_t)address)
|
||||||
#define hal_register_read(address) address
|
#define hal_register_read(address) address
|
||||||
uint8_t hal_subregister_read( uint16_t address, uint8_t mask, uint8_t position );
|
uint8_t hal_subregister_read( uint16_t address, uint8_t mask, uint8_t position );
|
||||||
|
|
|
@ -76,6 +76,9 @@ extern uint8_t debugflowsize,debugflow[DEBUGFLOWSIZE];
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__)
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include "atmega128rfa1_registermap.h"
|
#include "atmega128rfa1_registermap.h"
|
||||||
|
#elif defined(__AVR_ATmega256RFR2__)
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include "atmega256rfr2_registermap.h"
|
||||||
#else
|
#else
|
||||||
#include "at86rf230_registermap.h"
|
#include "at86rf230_registermap.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,7 +91,7 @@ volatile extern signed char rf230_last_rssi;
|
||||||
|
|
||||||
|
|
||||||
/*============================ IMPLEMENTATION ================================*/
|
/*============================ IMPLEMENTATION ================================*/
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
|
|
||||||
/* AVR1281 with internal RF231 radio */
|
/* AVR1281 with internal RF231 radio */
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
@ -158,7 +161,7 @@ inline uint8_t spiWrite(uint8_t byte)
|
||||||
|
|
||||||
/** \brief This function initializes the Hardware Abstraction Layer.
|
/** \brief This function initializes the Hardware Abstraction Layer.
|
||||||
*/
|
*/
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
|
|
||||||
void
|
void
|
||||||
hal_init(void)
|
hal_init(void)
|
||||||
|
@ -242,7 +245,7 @@ hal_init(void)
|
||||||
#endif /* !__AVR__ */
|
#endif /* !__AVR__ */
|
||||||
|
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
/* Hack for internal radio registers. hal_register_read and hal_register_write are
|
/* 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
|
handled through defines, but the preprocesser can't parse a macro containing
|
||||||
another #define with multiple arguments, e.g. using
|
another #define with multiple arguments, e.g. using
|
||||||
|
@ -279,7 +282,7 @@ hal_subregister_write(uint16_t address, uint8_t mask, uint8_t position,
|
||||||
HAL_LEAVE_CRITICAL_REGION();
|
HAL_LEAVE_CRITICAL_REGION();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* defined(__AVR_ATmega128RFA1__) */
|
#else /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)*/
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/** \brief This function reads data from one of the radio transceiver's registers.
|
/** \brief This function reads data from one of the radio transceiver's registers.
|
||||||
*
|
*
|
||||||
|
@ -383,7 +386,7 @@ hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position,
|
||||||
/* Write the modified register value. */
|
/* Write the modified register value. */
|
||||||
hal_register_write(address, value);
|
hal_register_write(address, value);
|
||||||
}
|
}
|
||||||
#endif /* defined(__AVR_ATmega128RFA1__) */
|
#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__) */
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
/** \brief Transfer a frame from the radio transceiver to a RAM buffer
|
/** \brief Transfer a frame from the radio transceiver to a RAM buffer
|
||||||
*
|
*
|
||||||
|
@ -399,7 +402,7 @@ hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position,
|
||||||
void
|
void
|
||||||
hal_frame_read(hal_rx_frame_t *rx_frame)
|
hal_frame_read(hal_rx_frame_t *rx_frame)
|
||||||
{
|
{
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
|
|
||||||
uint8_t frame_length,*rx_data,*rx_buffer;
|
uint8_t frame_length,*rx_data,*rx_buffer;
|
||||||
|
|
||||||
|
@ -432,7 +435,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame)
|
||||||
*/
|
*/
|
||||||
rx_frame->crc = true;
|
rx_frame->crc = true;
|
||||||
|
|
||||||
#else /* defined(__AVR_ATmega128RFA1__) */
|
#else /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__) */
|
||||||
|
|
||||||
uint8_t frame_length, *rx_data;
|
uint8_t frame_length, *rx_data;
|
||||||
|
|
||||||
|
@ -487,7 +490,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame)
|
||||||
|
|
||||||
HAL_SPI_TRANSFER_CLOSE();
|
HAL_SPI_TRANSFER_CLOSE();
|
||||||
|
|
||||||
#endif /* defined(__AVR_ATmega128RFA1__) */
|
#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__) */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -500,7 +503,7 @@ hal_frame_read(hal_rx_frame_t *rx_frame)
|
||||||
void
|
void
|
||||||
hal_frame_write(uint8_t *write_buffer, uint8_t length)
|
hal_frame_write(uint8_t *write_buffer, uint8_t length)
|
||||||
{
|
{
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
uint8_t *tx_buffer;
|
uint8_t *tx_buffer;
|
||||||
tx_buffer=(uint8_t *)0x180; //start of fifo in i/o space
|
tx_buffer=(uint8_t *)0x180; //start of fifo in i/o space
|
||||||
/* Write frame length, including the two byte checksum */
|
/* Write frame length, including the two byte checksum */
|
||||||
|
@ -632,7 +635,7 @@ volatile char rf230interruptflag;
|
||||||
#define INTERRUPTDEBUG(arg)
|
#define INTERRUPTDEBUG(arg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
/* The atmega128rfa1 has individual interrupts for the integrated radio'
|
/* The atmega128rfa1 has individual interrupts for the integrated radio'
|
||||||
* Whichever are enabled by the RF230 driver must be present even if not used!
|
* Whichever are enabled by the RF230 driver must be present even if not used!
|
||||||
*/
|
*/
|
||||||
|
@ -715,7 +718,7 @@ ISR(TRX24_CCA_ED_DONE_vect)
|
||||||
rf230_ccawait=0;
|
rf230_ccawait=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* defined(__AVR_ATmega128RFA1__) */
|
#else /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)*/
|
||||||
/* Separate RF230 has a single radio interrupt and the source must be read from the IRQ_STATUS register */
|
/* Separate RF230 has a single radio interrupt and the source must be read from the IRQ_STATUS register */
|
||||||
HAL_RF230_ISR()
|
HAL_RF230_ISR()
|
||||||
{
|
{
|
||||||
|
@ -805,7 +808,7 @@ HAL_RF230_ISR()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* defined(__AVR_ATmega128RFA1__) */
|
#endif /* defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)*/
|
||||||
# endif /* defined(DOXYGEN) */
|
# endif /* defined(DOXYGEN) */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -212,7 +212,7 @@ static unsigned long total_time_for_transmission, total_transmission_len;
|
||||||
static int num_transmissions;
|
static int num_transmissions;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
volatile uint8_t rf230_wakewait, rf230_txendwait, rf230_ccawait;
|
volatile uint8_t rf230_wakewait, rf230_txendwait, rf230_ccawait;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -585,7 +585,7 @@ radio_on(void)
|
||||||
#if RF230BB_CONF_LEDONPORTE1
|
#if RF230BB_CONF_LEDONPORTE1
|
||||||
PORTE|=(1<<PE1); //ledon
|
PORTE|=(1<<PE1); //ledon
|
||||||
#endif
|
#endif
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
/* Use the poweron interrupt for delay */
|
/* Use the poweron interrupt for delay */
|
||||||
rf230_wakewait=1;
|
rf230_wakewait=1;
|
||||||
{
|
{
|
||||||
|
@ -909,6 +909,25 @@ void rf230_warm_reset(void) {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*set external PA in on state, used for Dresden Elektronik m12 modules*/
|
||||||
|
/*needed for guhRF Modules and RaspBee Boarder Router*/
|
||||||
|
#if defined( _EXT_PA_ )
|
||||||
|
hal_subregister_write(SR_PA_EXT_EN, 1);
|
||||||
|
hal_subregister_write(SR_IRQ_2_EXT_EN, 0); //Must be disabled for antenna diversity
|
||||||
|
hal_subregister_write(SR_ANT_EXT_SW_EN, 1);
|
||||||
|
// hal_subregister_write(SR_ANT_DIV_EN, 1);
|
||||||
|
|
||||||
|
/* Registers for fixed Antenna out - Diversity disabled */
|
||||||
|
// hal_subregister_write(SR_ANT_DIV_EN, 0);
|
||||||
|
// hal_subregister_write(SR_SET_OUT_ANT1, 1); //Set Antenna 1 RFOUT1-deRFmega256-23M12
|
||||||
|
hal_subregister_write(SR_SET_OUT_ANT0, 1); //Set Antenna 0 RFOUT2-deRFmega256-23M12
|
||||||
|
DDRD |= (1<<PD6); // PIND6 High to wake amplifier
|
||||||
|
PORTD |= (1<<PD6);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Use automatic CRC unless manual is specified */
|
/* Use automatic CRC unless manual is specified */
|
||||||
#if RF230_CONF_CHECKSUM
|
#if RF230_CONF_CHECKSUM
|
||||||
hal_subregister_write(SR_TX_AUTO_CRC_ON, 0);
|
hal_subregister_write(SR_TX_AUTO_CRC_ON, 0);
|
||||||
|
@ -937,7 +956,7 @@ rf230_transmit(unsigned short payload_len)
|
||||||
/* If radio is sleeping we have to turn it on first */
|
/* If radio is sleeping we have to turn it on first */
|
||||||
/* This automatically does the PLL calibrations */
|
/* This automatically does the PLL calibrations */
|
||||||
if (hal_get_slptr()) {
|
if (hal_get_slptr()) {
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
ENERGEST_ON(ENERGEST_TYPE_LED_RED);
|
ENERGEST_ON(ENERGEST_TYPE_LED_RED);
|
||||||
#if RF230BB_CONF_LEDONPORTE1
|
#if RF230BB_CONF_LEDONPORTE1
|
||||||
PORTE|=(1<<PE1); //ledon
|
PORTE|=(1<<PE1); //ledon
|
||||||
|
@ -1658,7 +1677,7 @@ rf230_cca(void)
|
||||||
|
|
||||||
/* Start the CCA, wait till done, return result */
|
/* Start the CCA, wait till done, return result */
|
||||||
/* Note reading the TRX_STATUS register clears both CCA_STATUS and CCA_DONE bits */
|
/* Note reading the TRX_STATUS register clears both CCA_STATUS and CCA_DONE bits */
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
#if 1 //interrupt method
|
#if 1 //interrupt method
|
||||||
/* Disable rx transitions to busy (RX_PDT_BIT) */
|
/* Disable rx transitions to busy (RX_PDT_BIT) */
|
||||||
/* Note: for speed this resets rx threshold to the compiled default */
|
/* Note: for speed this resets rx threshold to the compiled default */
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__)
|
||||||
#include "atmega128rfa1_registermap.h"
|
#include "atmega128rfa1_registermap.h"
|
||||||
|
#elif defined(__AVR_ATmega256RFR2__)
|
||||||
|
#include "atmega256rfr2_registermap.h"
|
||||||
#else
|
#else
|
||||||
#include "at86rf230_registermap.h"
|
#include "at86rf230_registermap.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,7 +70,7 @@
|
||||||
#define RF230_REVB ( 2 )
|
#define RF230_REVB ( 2 )
|
||||||
#define SUPPORTED_MANUFACTURER_ID ( 31 )
|
#define SUPPORTED_MANUFACTURER_ID ( 31 )
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128RFA1__)
|
#if defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
|
||||||
#define RF230_SUPPORTED_INTERRUPT_MASK ( 0xFF )
|
#define RF230_SUPPORTED_INTERRUPT_MASK ( 0xFF )
|
||||||
#else
|
#else
|
||||||
/* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
|
/* RF230 does not support RX_START interrupts in extended mode, but it seems harmless to always enable it. */
|
||||||
|
|
73
platform/RaspBee/Makefile.RaspBee
Normal file
73
platform/RaspBee/Makefile.RaspBee
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
CONTIKI_TARGET_DIRS = . dev apps net loader
|
||||||
|
|
||||||
|
CONTIKI_CORE=contiki-main
|
||||||
|
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += contiki-main.c params.c node-id.c
|
||||||
|
#Needed for slip
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += temperature-sensor.c adc.c led.c sensors.c slip_uart0.c slip.c leds-arch.c
|
||||||
|
#Needed for Button
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += button-sensor.c
|
||||||
|
# i2c Master
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += i2c.c
|
||||||
|
|
||||||
|
#Needed for Battery test
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += battery-sensor.c batmon.c
|
||||||
|
|
||||||
|
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# guh Source Files
|
||||||
|
|
||||||
|
|
||||||
|
# Smart Grid Ready Interface
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += sg-ready.c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
CONTIKIBOARD=.
|
||||||
|
BOOTLOADER_START = 0x1F000
|
||||||
|
CONTIKI_PLAT_DEFS = -DF_CPU=16000000UL -DAUTO_CRC_PADDING=2 -DPLAT_TIMER=5
|
||||||
|
|
||||||
|
MCU=atmega256rfr2
|
||||||
|
|
||||||
|
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 atmega256:
|
||||||
|
# avrdude -v -P usb:xxxx -c jtag2 -p atmega256
|
||||||
|
AVRDUDE_PORT=usb:00B000000D79
|
||||||
|
|
||||||
|
|
||||||
|
# Additional avrdude options
|
||||||
|
# Verify off
|
||||||
|
AVRDUDE_OPTIONS=-V
|
||||||
|
AVRDUDE_MCU=m256rfr2
|
||||||
|
|
||||||
|
#debug
|
||||||
|
# CFLAGS += -save-temps
|
||||||
|
# Bootloader bonsai
|
||||||
|
# LDFLAGS += -save-temps
|
||||||
|
# For the old bonsai bootloader compiled with squeeze gcc-avr we
|
||||||
|
# directly used the address of the bootloader:
|
||||||
|
#BOOTLOADER_GET_MAC=0x0001f3a0
|
||||||
|
# For newer bonsai we have a jump table at the end of the bootloader
|
||||||
|
# section:
|
||||||
|
BOOTLOADER_GET_MAC=0x0001ff80
|
||||||
|
|
||||||
|
LDFLAGS += -Wl,--defsym,bootloader_get_mac=$(BOOTLOADER_GET_MAC)
|
||||||
|
|
||||||
|
|
||||||
|
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/ipv6 core/net/ipv4 core/net/ip \
|
||||||
|
# core/net/rime \
|
||||||
|
# core/net/rpl \
|
324
platform/RaspBee/contiki-conf.h
Normal file
324
platform/RaspBee/contiki-conf.h
Normal file
|
@ -0,0 +1,324 @@
|
||||||
|
/*
|
||||||
|
* 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 Atmel ATMEGA256RFR2
|
||||||
|
* \author
|
||||||
|
* David Kopf <dak664@embarqmail.com>
|
||||||
|
Bernhard Trinnes <bernhard.trinnes@guh.guru>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONTIKI_CONF_H_
|
||||||
|
#define CONTIKI_CONF_H_
|
||||||
|
|
||||||
|
/* Platform name, type, and MCU clock rate */
|
||||||
|
#define PLATFORM_NAME "guhRF"
|
||||||
|
#define PLATFORM_TYPE ATMEGA256RFR2
|
||||||
|
#ifndef F_CPU
|
||||||
|
#define F_CPU 16000000UL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define IEEE802154_CONF_PANID 0xABCD // default panid
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
#if 1
|
||||||
|
/* 16 bit counter overflows every ~10 minutes */
|
||||||
|
typedef unsigned short clock_time_t;
|
||||||
|
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
|
||||||
|
#define INFINITE_TIME 0xffff
|
||||||
|
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
|
||||||
|
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
|
||||||
|
#else
|
||||||
|
typedef unsigned long clock_time_t;
|
||||||
|
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
|
||||||
|
#define INFINITE_TIME 0xffffffff
|
||||||
|
#endif
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
|
||||||
|
/* and theoretically can use TIMER2 with it to keep time. Else TIMER0 is used. */
|
||||||
|
/* The sleep timer requires the crystal and adds a TIMER2 interrupt routine if not already define by clock.c */
|
||||||
|
#define AVR_CONF_USE32KCRYSTAL 0
|
||||||
|
|
||||||
|
/* However this results in disabling UART0. */
|
||||||
|
#define RF230BB_CONF_LEDONPORTE1 0
|
||||||
|
|
||||||
|
/* COM port to be used for SLIP connection. This is usually UART0, but see above */
|
||||||
|
#if RF230BB_CONF_LEDONPORTE1
|
||||||
|
#define SLIP_PORT RS232_PORT_1
|
||||||
|
#else
|
||||||
|
#define SLIP_PORT RS232_PORT_0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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 1
|
||||||
|
|
||||||
|
/* 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 ATMEGA256RFR2 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
|
||||||
|
|
||||||
|
/* External Amplifier installed */
|
||||||
|
#define _EXT_PA_ 1
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
#define LINKADDR_CONF_SIZE 8
|
||||||
|
#define UIP_CONF_ICMP6 1
|
||||||
|
#define UIP_CONF_UDP 1
|
||||||
|
#define UIP_CONF_TCP 1
|
||||||
|
#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 1 /* No radio cycling */
|
||||||
|
#if 0 /* radio cycling */
|
||||||
|
|
||||||
|
#define NETSTACK_CONF_MAC nullmac_driver
|
||||||
|
#define NETSTACK_CONF_RDC sicslowmac_driver
|
||||||
|
#define NETSTACK_CONF_FRAMER framer_802154
|
||||||
|
#define NETSTACK_CONF_RADIO rf230_driver
|
||||||
|
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
|
||||||
|
#define RF230_CONF_AUTOACK 1
|
||||||
|
/* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */
|
||||||
|
#define SICSLOWPAN_CONF_ACK_ALL 0
|
||||||
|
/* 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
|
||||||
|
/* 211 bytes per queue buffer */
|
||||||
|
#define QUEUEBUF_CONF_NUM 8
|
||||||
|
/* 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 */
|
||||||
|
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||||
|
/* 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
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
#define NETSTACK_CONF_FRAMER framer_802154
|
||||||
|
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||||
|
#define NETSTACK_CONF_FRAMER contikimac_framer
|
||||||
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||||
|
|
||||||
|
#define NETSTACK_CONF_RADIO rf230_driver
|
||||||
|
/* The radio needs to interrupt during an rtimer interrupt */
|
||||||
|
#define RTIMER_CONF_NESTED_INTERRUPTS 1
|
||||||
|
#define RF230_CONF_AUTOACK 1
|
||||||
|
/* 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
|
||||||
|
/* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */
|
||||||
|
#define QUEUEBUF_CONF_NUM 15
|
||||||
|
/* 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
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error Network configuration not specified!
|
||||||
|
#endif /* Network setup */
|
||||||
|
|
||||||
|
/* ************************************************************************** */
|
||||||
|
//#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_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
|
||||||
|
|
||||||
|
/* include the project config */
|
||||||
|
/* PROJECT_CONF_H might be defined in the project Makefile */
|
||||||
|
#ifdef PROJECT_CONF_H
|
||||||
|
#include PROJECT_CONF_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONTIKI_CONF_H_ */
|
625
platform/RaspBee/contiki-main.c
Normal file
625
platform/RaspBee/contiki-main.c
Normal file
|
@ -0,0 +1,625 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#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 <avr/io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dev/watchdog.h>
|
||||||
|
|
||||||
|
#include "loader/symbols-def.h"
|
||||||
|
#include "loader/symtab.h"
|
||||||
|
|
||||||
|
#include "params.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"
|
||||||
|
|
||||||
|
#ifdef RAVEN_LCD_INTERFACE
|
||||||
|
#include "raven-lcd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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 ledtimer;
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/*----------------------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 = 0x02,//SIGNATURE_2, //ATMEGA256rfr2
|
||||||
|
.B1 = 0xA8,//SIGNATURE_1, //256KB flash
|
||||||
|
.B0 = 0x1E,//SIGNATURE_0, //Atmel
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
/* JTAG+SPI enabled, External osc 1kck4ms1 , Boot 4096 words @ $1F000, TXC1K+4,1msec delay, Brownout 1.8 volts */
|
||||||
|
FUSES ={.low = 0xF6, .high = 0x98, .extended = 0xfe,};
|
||||||
|
#define BOOTLOADER_START = 0x1F000
|
||||||
|
#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
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/battery-sensor.h"
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_delay(unsigned int howlong)
|
||||||
|
{
|
||||||
|
if(howlong<2) return;
|
||||||
|
clock_delay_usec((45*howlong)>>4);
|
||||||
|
}
|
||||||
|
/*-------------------------Low level initialization------------------------*/
|
||||||
|
/*------Done in a subroutine to keep main routine stack usage small--------*/
|
||||||
|
void initialize(void)
|
||||||
|
{
|
||||||
|
watchdog_init();
|
||||||
|
watchdog_start();
|
||||||
|
|
||||||
|
/* The Raven implements a serial command and data interface via uart0 to a 3290p,
|
||||||
|
* which could be duplicated using another host computer.
|
||||||
|
*/
|
||||||
|
#if !RF230BB_CONF_LEDONPORTE1 //Conflicts with USART0
|
||||||
|
#ifdef RAVEN_LCD_INTERFACE
|
||||||
|
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||||
|
rs232_set_input(0,raven_lcd_serial_input);
|
||||||
|
#else
|
||||||
|
/* Generic or slip connection on uart0 */
|
||||||
|
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Second rs232 port for debugging or slip alternative */
|
||||||
|
// rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||||
|
/* Redirect stdout */
|
||||||
|
#if RF230BB_CONF_LEDONPORTE1 || defined(RAVEN_LCD_INTERFACE)
|
||||||
|
rs232_redirect_stdout(RS232_PORT_1);
|
||||||
|
#else
|
||||||
|
rs232_redirect_stdout(RS232_PORT_0);
|
||||||
|
#endif
|
||||||
|
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");
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
if (params_get_eui64(addr.u8)) {
|
||||||
|
PRINTA("Random EUI64 address generated\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t));
|
||||||
|
#elif WITH_NODE_ID
|
||||||
|
node_id=get_panaddr_from_eeprom();
|
||||||
|
addr.u8[1]=node_id&0xff;
|
||||||
|
addr.u8[0]=(node_id&0xff00)>>8;
|
||||||
|
PRINTA("Node ID from eeprom: %X\n",node_id);
|
||||||
|
#endif
|
||||||
|
linkaddr_set_node_addr(&addr);
|
||||||
|
|
||||||
|
PRINTA("Panid:%x\n", params_get_panid());
|
||||||
|
// framer_802154_set_panid(params_get_panid());
|
||||||
|
rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
|
||||||
|
rf230_set_channel(params_get_channel());
|
||||||
|
rf230_set_txpower(params_get_txpower());
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
PRINTA("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
|
||||||
|
#else
|
||||||
|
PRINTA("MAC address ");
|
||||||
|
uint8_t i;
|
||||||
|
for (i=sizeof(linkaddr_t); i>0; i--){
|
||||||
|
PRINTA("%x:",addr.u8[i-1]);
|
||||||
|
}
|
||||||
|
PRINTA("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initialize stack protocols */
|
||||||
|
queuebuf_init();
|
||||||
|
NETSTACK_RDC.init();
|
||||||
|
NETSTACK_MAC.init();
|
||||||
|
NETSTACK_NETWORK.init();
|
||||||
|
|
||||||
|
#if ANNOUNCE_BOOT
|
||||||
|
PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.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
|
||||||
|
|
||||||
|
#ifdef RAVEN_LCD_INTERFACE
|
||||||
|
process_start(&raven_lcd_process, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
process_start(&sensors_process, NULL);
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
|
#if RF230BB_CONF_LEDONPORTE1
|
||||||
|
/* NB: PORTE1 conflicts with UART0 */
|
||||||
|
DDRE|=(1<<DDE1); //set led pin to output (Micheal Hatrtman board)
|
||||||
|
PORTE&=~(1<<PE1); //and low to turn led off
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#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();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Turn off LED after a while */
|
||||||
|
if (ledtimer) {
|
||||||
|
if (--ledtimer==0) {
|
||||||
|
#if RF230BB_CONF_LEDONPORTE1
|
||||||
|
PORTE&=~(1<<PE1);
|
||||||
|
#endif
|
||||||
|
#if defined(RAVEN_LCD_INTERFACE)&&0
|
||||||
|
/* ledtimer can be set by received ping; ping the other way for testing */
|
||||||
|
extern void raven_ping6(void);
|
||||||
|
raven_ping6();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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=0;
|
||||||
|
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);
|
||||||
|
|
||||||
|
for(nbr = nbr_table_head(ds6_neighbors);
|
||||||
|
nbr != NULL;
|
||||||
|
nbr = nbr_table_next(ds6_neighbors, nbr)) {
|
||||||
|
ipaddr_add(&nbr->ipaddr);
|
||||||
|
PRINTF("\n");
|
||||||
|
j=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j) PRINTF(" <none>");
|
||||||
|
PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
|
||||||
|
{
|
||||||
|
uip_ds6_route_t *r;
|
||||||
|
j = 1;
|
||||||
|
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 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
172
platform/RaspBee/dev/Arduino.h
Normal file
172
platform/RaspBee/dev/Arduino.h
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
#ifndef Arduino_h
|
||||||
|
#define Arduino_h
|
||||||
|
|
||||||
|
#include <hw-arduino.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
#include "binary.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HIGH 0x1
|
||||||
|
#define LOW 0x0
|
||||||
|
|
||||||
|
#define INPUT 0x0
|
||||||
|
#define OUTPUT 0x1
|
||||||
|
#define INPUT_PULLUP 0x2
|
||||||
|
|
||||||
|
#define true 0x1
|
||||||
|
#define false 0x0
|
||||||
|
|
||||||
|
#define PI 3.1415926535897932384626433832795
|
||||||
|
#define HALF_PI 1.5707963267948966192313216916398
|
||||||
|
#define TWO_PI 6.283185307179586476925286766559
|
||||||
|
#define DEG_TO_RAD 0.017453292519943295769236907684886
|
||||||
|
#define RAD_TO_DEG 57.295779513082320876798154814105
|
||||||
|
|
||||||
|
#define SERIAL 0x0
|
||||||
|
#define DISPLAY 0x1
|
||||||
|
|
||||||
|
#define LSBFIRST 0
|
||||||
|
#define MSBFIRST 1
|
||||||
|
|
||||||
|
#define CHANGE 1
|
||||||
|
#define FALLING 2
|
||||||
|
#define RISING 3
|
||||||
|
|
||||||
|
#define DEFAULT ADC_DEFAULT
|
||||||
|
#define EXTERNAL ADC_EXTERNAL
|
||||||
|
|
||||||
|
// undefine stdlib's abs if encountered
|
||||||
|
#ifdef abs
|
||||||
|
#undef abs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
#define max(a,b) ((a)>(b)?(a):(b))
|
||||||
|
#define abs(x) ((x)>0?(x):-(x))
|
||||||
|
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||||
|
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||||
|
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||||
|
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||||
|
#define sq(x) ((x)*(x))
|
||||||
|
|
||||||
|
#define interrupts() sei()
|
||||||
|
#define noInterrupts() cli()
|
||||||
|
|
||||||
|
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||||
|
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||||
|
|
||||||
|
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||||
|
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||||
|
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||||
|
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||||
|
|
||||||
|
|
||||||
|
typedef unsigned int word;
|
||||||
|
|
||||||
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
|
typedef uint8_t boolean;
|
||||||
|
typedef uint8_t byte;
|
||||||
|
|
||||||
|
void pinMode(uint8_t, uint8_t);
|
||||||
|
void digitalWrite(uint8_t, uint8_t);
|
||||||
|
int digitalRead(uint8_t);
|
||||||
|
|
||||||
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
|
||||||
|
|
||||||
|
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
||||||
|
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
|
||||||
|
|
||||||
|
void attachInterrupt(uint8_t, void (*)(void), int mode);
|
||||||
|
void detachInterrupt(uint8_t);
|
||||||
|
|
||||||
|
void setup(void);
|
||||||
|
void loop(void);
|
||||||
|
|
||||||
|
// Get the bit location within the hardware port of the given virtual pin.
|
||||||
|
// This comes from the pins_*.c file for the active board configuration.
|
||||||
|
|
||||||
|
#define analogInPinToBit(P) (P)
|
||||||
|
|
||||||
|
// On the ATmega1280, the addresses of some of the port registers are
|
||||||
|
// greater than 255, so we can't store them in uint8_t's.
|
||||||
|
extern const uint16_t PROGMEM port_to_mode_PGM[];
|
||||||
|
extern const uint16_t PROGMEM port_to_input_PGM[];
|
||||||
|
extern const uint16_t PROGMEM port_to_output_PGM[];
|
||||||
|
|
||||||
|
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
|
||||||
|
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
|
||||||
|
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
|
||||||
|
|
||||||
|
// Get the bit location within the hardware port of the given virtual pin.
|
||||||
|
// This comes from the pins_*.c file for the active board configuration.
|
||||||
|
//
|
||||||
|
// These perform slightly better as macros compared to inline functions
|
||||||
|
//
|
||||||
|
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
|
||||||
|
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
|
||||||
|
#define analogInPinToBit(P) (P)
|
||||||
|
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
|
||||||
|
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
|
||||||
|
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
|
||||||
|
|
||||||
|
#define NOT_A_PIN 0
|
||||||
|
#define NOT_A_PORT 0
|
||||||
|
|
||||||
|
#ifdef ARDUINO_MAIN
|
||||||
|
#define PA 1
|
||||||
|
#define PB 2
|
||||||
|
#define PC 3
|
||||||
|
#define PD 4
|
||||||
|
#define PE 5
|
||||||
|
#define PF 6
|
||||||
|
#define PG 7
|
||||||
|
#define PH 8
|
||||||
|
#define PJ 10
|
||||||
|
#define PK 11
|
||||||
|
#define PL 12
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
// look at this again when considering implementing serial
|
||||||
|
//#include "WCharacter.h"
|
||||||
|
//#include "WString.h"
|
||||||
|
//#include "HardwareSerial.h"
|
||||||
|
|
||||||
|
uint16_t makeWord(uint16_t w);
|
||||||
|
uint16_t makeWord(byte h, byte l);
|
||||||
|
|
||||||
|
#define word(...) makeWord(__VA_ARGS__)
|
||||||
|
|
||||||
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||||
|
|
||||||
|
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
||||||
|
void noTone(uint8_t _pin);
|
||||||
|
|
||||||
|
// WMath prototypes
|
||||||
|
long random(long);
|
||||||
|
long random(long, long);
|
||||||
|
void randomSeed(unsigned int);
|
||||||
|
long map(long, long, long, long, long);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
#include "dev/arduino/arduino-compat.h"
|
||||||
|
|
||||||
|
#endif
|
84
platform/RaspBee/dev/adc.c
Normal file
84
platform/RaspBee/dev/adc.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: adc.c,v 1.1 2010/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* ADC file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adc.h"
|
||||||
|
|
||||||
|
static uint8_t analog_reference = ADC_DEFAULT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For arduino interface for setting external reference voltage
|
||||||
|
* Note that applying an external voltage *and* then setting the analog
|
||||||
|
* reference to something internal will short the internal and the
|
||||||
|
* external reference voltage and most likely destroy the processor.
|
||||||
|
*/
|
||||||
|
void analogReference(uint8_t mode)
|
||||||
|
{
|
||||||
|
analog_reference = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readADC(uint8_t pin)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
adc_setup (analog_reference, pin);
|
||||||
|
result = adc_read ();
|
||||||
|
adc_fin ();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \return Internal temperature in 0.01C, e.g. 25C is 2500
|
||||||
|
*/
|
||||||
|
int readInternalTemp(void)
|
||||||
|
{
|
||||||
|
int reading = 0;
|
||||||
|
|
||||||
|
ADCSRB |= _BV(MUX5);
|
||||||
|
ADMUX = _BV(REFS1) | _BV(REFS0) | 0b1001 ;
|
||||||
|
ADCSRA = _BV(ADEN) | _BV(ADPS0) | _BV(ADPS2) ;
|
||||||
|
|
||||||
|
ADCSRA |= 1 << ADSC;
|
||||||
|
loop_until_bit_is_clear(ADCSRA,ADSC);
|
||||||
|
reading = ADC;
|
||||||
|
|
||||||
|
ADCSRB=0; //disable ADC, need to write B first for MUX5 bit
|
||||||
|
ADCSRA=0; //disable ADC
|
||||||
|
ADMUX=0; //turn off internal vref
|
||||||
|
|
||||||
|
return reading * 113 - 27280;
|
||||||
|
}
|
65
platform/RaspBee/dev/adc.h
Normal file
65
platform/RaspBee/dev/adc.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#ifndef __ADC_ARCH_H__
|
||||||
|
#define __ADC_ARCH_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reference voltage
|
||||||
|
* The default is 1.6V reference voltage
|
||||||
|
* The selected reference voltage is the maximum voltage that can be
|
||||||
|
* measured.
|
||||||
|
* Directly provide shifted variants so we don't need to shift.
|
||||||
|
*/
|
||||||
|
#define ADC_1_5 (2<<6)
|
||||||
|
#define ADC_1_6 (3<<6)
|
||||||
|
#define ADC_1_8 (1<<6)
|
||||||
|
#define ADC_EXTERNAL (0<<6)
|
||||||
|
#define ADC_DEFAULT ADC_1_6
|
||||||
|
|
||||||
|
/* sometimes it's desirable to decouple setup / finish from sampling */
|
||||||
|
|
||||||
|
static inline void adc_setup (uint8_t ref_volt, uint8_t pin)
|
||||||
|
{
|
||||||
|
ADMUX = ref_volt | (pin & 0x7);
|
||||||
|
ADCSRA = _BV(ADEN) | _BV(ADPS0) | _BV(ADPS2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int adc_read (void)
|
||||||
|
{
|
||||||
|
ADCSRA |= (1 << ADSC);
|
||||||
|
loop_until_bit_is_clear (ADCSRA, ADSC);
|
||||||
|
return ADC;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void adc_fin (void)
|
||||||
|
{
|
||||||
|
ADCSRA = 0;
|
||||||
|
ADMUX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void adc_init (void)
|
||||||
|
{
|
||||||
|
uint8_t temp;
|
||||||
|
ADCSRC = 0;
|
||||||
|
ADCSRB = 0;
|
||||||
|
adc_fin ();
|
||||||
|
/*
|
||||||
|
* Disable JTAG interface
|
||||||
|
* Hardware manual about JTD bit:
|
||||||
|
* "In order to avoid unintentional disabling or enabling of the
|
||||||
|
* JTAG interface, a timed sequence must be followed when changing
|
||||||
|
* this bit: The application software must write this bit to the
|
||||||
|
* desired value twice within four cycles to change its value."
|
||||||
|
* 15.4.1 "MCUCR - MCU Control Register", p. 219
|
||||||
|
*/
|
||||||
|
temp = MCUCR | (1 << JTD);
|
||||||
|
MCUCR = temp;
|
||||||
|
MCUCR = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readADC(uint8_t pin);
|
||||||
|
long readVcc();
|
||||||
|
int readInternalTemp(void);
|
||||||
|
void analogReference(uint8_t mode);
|
||||||
|
|
||||||
|
#endif /* __ADC_ARCH_H__ */
|
55
platform/RaspBee/dev/batmon.c
Normal file
55
platform/RaspBee/dev/batmon.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "batmon.h"
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int8_t batmon_init()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t batmon_get_voltage(uint16_t* voltage)
|
||||||
|
{
|
||||||
|
uint16_t volt = 0;
|
||||||
|
uint16_t resolution = 75;
|
||||||
|
uint16_t offset = 2550;
|
||||||
|
int8_t ctr = 0;
|
||||||
|
|
||||||
|
BATMON = 0 | _BV(BATMON_HR);
|
||||||
|
_delay_us(2);
|
||||||
|
|
||||||
|
if(BATMON & _BV(BATMON_OK))
|
||||||
|
{
|
||||||
|
// voltage above 2.550 V
|
||||||
|
resolution = 75;
|
||||||
|
offset = 2550;
|
||||||
|
for(ctr=15; ctr>=0; ctr--)
|
||||||
|
{
|
||||||
|
BATMON = (BATMON & 0xF0) | (ctr);
|
||||||
|
_delay_us(2);
|
||||||
|
if(BATMON & _BV(BATMON_OK)) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// voltage below 2.550 V
|
||||||
|
resolution = 50;
|
||||||
|
offset = 1700;
|
||||||
|
|
||||||
|
BATMON &= ~_BV(BATMON_HR);
|
||||||
|
|
||||||
|
for(ctr=15; ctr>=0; ctr--)
|
||||||
|
{
|
||||||
|
BATMON = (BATMON & 0xF0) | (ctr);
|
||||||
|
_delay_us(2);
|
||||||
|
if(BATMON & _BV(BATMON_OK)) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
volt = resolution*ctr+offset;
|
||||||
|
*voltage=volt;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
8
platform/RaspBee/dev/batmon.h
Normal file
8
platform/RaspBee/dev/batmon.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef BATMON_H_
|
||||||
|
#define BATMON_H_
|
||||||
|
|
||||||
|
int8_t batmon_init();
|
||||||
|
int8_t batmon_get_voltage(uint16_t* voltage);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BATMON_H_ */
|
90
platform/RaspBee/dev/battery-sensor.c
Normal file
90
platform/RaspBee/dev/battery-sensor.c
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Battery sensor file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*The atmel rf23x radios have a low voltage detector that can be configured in units of 75 millivolts. Here is example *code for the ATmega128rfa1, where the BATMON register is in extended io space [dak664]
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dev/battery-sensor.h"
|
||||||
|
#include "dev/batmon.h"
|
||||||
|
|
||||||
|
const struct sensors_sensor battery_sensor;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \return Voltage on battery measurement with BATMON register.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint16_t h;
|
||||||
|
/*
|
||||||
|
uint8_t p1;
|
||||||
|
BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage
|
||||||
|
|
||||||
|
// Bandgap can't be measured against supply voltage in this chip.
|
||||||
|
// Use BATMON register instead
|
||||||
|
for ( p1=16; p1<31; p1++) {
|
||||||
|
BATMON = p1;
|
||||||
|
clock_delay_usec(100); // delay needed !!
|
||||||
|
if ((BATMON&(1<<BATMON_OK))==0) break;
|
||||||
|
}
|
||||||
|
h=2550-75*16-75+75*p1; //-75 to take the floor of the 75 mv transition window
|
||||||
|
*/
|
||||||
|
batmon_get_voltage(&h);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
// No configuration needed. readADC() handles all the config needed.
|
||||||
|
batmon_init();
|
||||||
|
return type == SENSORS_ACTIVE;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
// analog sensors are always ready
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
48
platform/RaspBee/dev/battery-sensor.h
Normal file
48
platform/RaspBee/dev/battery-sensor.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Battery sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __BATTERY_SENSOR_H__
|
||||||
|
#define __BATTERY_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor battery_sensor;
|
||||||
|
|
||||||
|
#define BATTERY_SENSOR "Battery"
|
||||||
|
|
||||||
|
#endif /* __BATTERY_SENSOR_H__ */
|
515
platform/RaspBee/dev/binary.h
Normal file
515
platform/RaspBee/dev/binary.h
Normal file
|
@ -0,0 +1,515 @@
|
||||||
|
#ifndef Binary_h
|
||||||
|
#define Binary_h
|
||||||
|
|
||||||
|
#define B0 0
|
||||||
|
#define B00 0
|
||||||
|
#define B000 0
|
||||||
|
#define B0000 0
|
||||||
|
#define B00000 0
|
||||||
|
#define B000000 0
|
||||||
|
#define B0000000 0
|
||||||
|
#define B00000000 0
|
||||||
|
#define B1 1
|
||||||
|
#define B01 1
|
||||||
|
#define B001 1
|
||||||
|
#define B0001 1
|
||||||
|
#define B00001 1
|
||||||
|
#define B000001 1
|
||||||
|
#define B0000001 1
|
||||||
|
#define B00000001 1
|
||||||
|
#define B10 2
|
||||||
|
#define B010 2
|
||||||
|
#define B0010 2
|
||||||
|
#define B00010 2
|
||||||
|
#define B000010 2
|
||||||
|
#define B0000010 2
|
||||||
|
#define B00000010 2
|
||||||
|
#define B11 3
|
||||||
|
#define B011 3
|
||||||
|
#define B0011 3
|
||||||
|
#define B00011 3
|
||||||
|
#define B000011 3
|
||||||
|
#define B0000011 3
|
||||||
|
#define B00000011 3
|
||||||
|
#define B100 4
|
||||||
|
#define B0100 4
|
||||||
|
#define B00100 4
|
||||||
|
#define B000100 4
|
||||||
|
#define B0000100 4
|
||||||
|
#define B00000100 4
|
||||||
|
#define B101 5
|
||||||
|
#define B0101 5
|
||||||
|
#define B00101 5
|
||||||
|
#define B000101 5
|
||||||
|
#define B0000101 5
|
||||||
|
#define B00000101 5
|
||||||
|
#define B110 6
|
||||||
|
#define B0110 6
|
||||||
|
#define B00110 6
|
||||||
|
#define B000110 6
|
||||||
|
#define B0000110 6
|
||||||
|
#define B00000110 6
|
||||||
|
#define B111 7
|
||||||
|
#define B0111 7
|
||||||
|
#define B00111 7
|
||||||
|
#define B000111 7
|
||||||
|
#define B0000111 7
|
||||||
|
#define B00000111 7
|
||||||
|
#define B1000 8
|
||||||
|
#define B01000 8
|
||||||
|
#define B001000 8
|
||||||
|
#define B0001000 8
|
||||||
|
#define B00001000 8
|
||||||
|
#define B1001 9
|
||||||
|
#define B01001 9
|
||||||
|
#define B001001 9
|
||||||
|
#define B0001001 9
|
||||||
|
#define B00001001 9
|
||||||
|
#define B1010 10
|
||||||
|
#define B01010 10
|
||||||
|
#define B001010 10
|
||||||
|
#define B0001010 10
|
||||||
|
#define B00001010 10
|
||||||
|
#define B1011 11
|
||||||
|
#define B01011 11
|
||||||
|
#define B001011 11
|
||||||
|
#define B0001011 11
|
||||||
|
#define B00001011 11
|
||||||
|
#define B1100 12
|
||||||
|
#define B01100 12
|
||||||
|
#define B001100 12
|
||||||
|
#define B0001100 12
|
||||||
|
#define B00001100 12
|
||||||
|
#define B1101 13
|
||||||
|
#define B01101 13
|
||||||
|
#define B001101 13
|
||||||
|
#define B0001101 13
|
||||||
|
#define B00001101 13
|
||||||
|
#define B1110 14
|
||||||
|
#define B01110 14
|
||||||
|
#define B001110 14
|
||||||
|
#define B0001110 14
|
||||||
|
#define B00001110 14
|
||||||
|
#define B1111 15
|
||||||
|
#define B01111 15
|
||||||
|
#define B001111 15
|
||||||
|
#define B0001111 15
|
||||||
|
#define B00001111 15
|
||||||
|
#define B10000 16
|
||||||
|
#define B010000 16
|
||||||
|
#define B0010000 16
|
||||||
|
#define B00010000 16
|
||||||
|
#define B10001 17
|
||||||
|
#define B010001 17
|
||||||
|
#define B0010001 17
|
||||||
|
#define B00010001 17
|
||||||
|
#define B10010 18
|
||||||
|
#define B010010 18
|
||||||
|
#define B0010010 18
|
||||||
|
#define B00010010 18
|
||||||
|
#define B10011 19
|
||||||
|
#define B010011 19
|
||||||
|
#define B0010011 19
|
||||||
|
#define B00010011 19
|
||||||
|
#define B10100 20
|
||||||
|
#define B010100 20
|
||||||
|
#define B0010100 20
|
||||||
|
#define B00010100 20
|
||||||
|
#define B10101 21
|
||||||
|
#define B010101 21
|
||||||
|
#define B0010101 21
|
||||||
|
#define B00010101 21
|
||||||
|
#define B10110 22
|
||||||
|
#define B010110 22
|
||||||
|
#define B0010110 22
|
||||||
|
#define B00010110 22
|
||||||
|
#define B10111 23
|
||||||
|
#define B010111 23
|
||||||
|
#define B0010111 23
|
||||||
|
#define B00010111 23
|
||||||
|
#define B11000 24
|
||||||
|
#define B011000 24
|
||||||
|
#define B0011000 24
|
||||||
|
#define B00011000 24
|
||||||
|
#define B11001 25
|
||||||
|
#define B011001 25
|
||||||
|
#define B0011001 25
|
||||||
|
#define B00011001 25
|
||||||
|
#define B11010 26
|
||||||
|
#define B011010 26
|
||||||
|
#define B0011010 26
|
||||||
|
#define B00011010 26
|
||||||
|
#define B11011 27
|
||||||
|
#define B011011 27
|
||||||
|
#define B0011011 27
|
||||||
|
#define B00011011 27
|
||||||
|
#define B11100 28
|
||||||
|
#define B011100 28
|
||||||
|
#define B0011100 28
|
||||||
|
#define B00011100 28
|
||||||
|
#define B11101 29
|
||||||
|
#define B011101 29
|
||||||
|
#define B0011101 29
|
||||||
|
#define B00011101 29
|
||||||
|
#define B11110 30
|
||||||
|
#define B011110 30
|
||||||
|
#define B0011110 30
|
||||||
|
#define B00011110 30
|
||||||
|
#define B11111 31
|
||||||
|
#define B011111 31
|
||||||
|
#define B0011111 31
|
||||||
|
#define B00011111 31
|
||||||
|
#define B100000 32
|
||||||
|
#define B0100000 32
|
||||||
|
#define B00100000 32
|
||||||
|
#define B100001 33
|
||||||
|
#define B0100001 33
|
||||||
|
#define B00100001 33
|
||||||
|
#define B100010 34
|
||||||
|
#define B0100010 34
|
||||||
|
#define B00100010 34
|
||||||
|
#define B100011 35
|
||||||
|
#define B0100011 35
|
||||||
|
#define B00100011 35
|
||||||
|
#define B100100 36
|
||||||
|
#define B0100100 36
|
||||||
|
#define B00100100 36
|
||||||
|
#define B100101 37
|
||||||
|
#define B0100101 37
|
||||||
|
#define B00100101 37
|
||||||
|
#define B100110 38
|
||||||
|
#define B0100110 38
|
||||||
|
#define B00100110 38
|
||||||
|
#define B100111 39
|
||||||
|
#define B0100111 39
|
||||||
|
#define B00100111 39
|
||||||
|
#define B101000 40
|
||||||
|
#define B0101000 40
|
||||||
|
#define B00101000 40
|
||||||
|
#define B101001 41
|
||||||
|
#define B0101001 41
|
||||||
|
#define B00101001 41
|
||||||
|
#define B101010 42
|
||||||
|
#define B0101010 42
|
||||||
|
#define B00101010 42
|
||||||
|
#define B101011 43
|
||||||
|
#define B0101011 43
|
||||||
|
#define B00101011 43
|
||||||
|
#define B101100 44
|
||||||
|
#define B0101100 44
|
||||||
|
#define B00101100 44
|
||||||
|
#define B101101 45
|
||||||
|
#define B0101101 45
|
||||||
|
#define B00101101 45
|
||||||
|
#define B101110 46
|
||||||
|
#define B0101110 46
|
||||||
|
#define B00101110 46
|
||||||
|
#define B101111 47
|
||||||
|
#define B0101111 47
|
||||||
|
#define B00101111 47
|
||||||
|
#define B110000 48
|
||||||
|
#define B0110000 48
|
||||||
|
#define B00110000 48
|
||||||
|
#define B110001 49
|
||||||
|
#define B0110001 49
|
||||||
|
#define B00110001 49
|
||||||
|
#define B110010 50
|
||||||
|
#define B0110010 50
|
||||||
|
#define B00110010 50
|
||||||
|
#define B110011 51
|
||||||
|
#define B0110011 51
|
||||||
|
#define B00110011 51
|
||||||
|
#define B110100 52
|
||||||
|
#define B0110100 52
|
||||||
|
#define B00110100 52
|
||||||
|
#define B110101 53
|
||||||
|
#define B0110101 53
|
||||||
|
#define B00110101 53
|
||||||
|
#define B110110 54
|
||||||
|
#define B0110110 54
|
||||||
|
#define B00110110 54
|
||||||
|
#define B110111 55
|
||||||
|
#define B0110111 55
|
||||||
|
#define B00110111 55
|
||||||
|
#define B111000 56
|
||||||
|
#define B0111000 56
|
||||||
|
#define B00111000 56
|
||||||
|
#define B111001 57
|
||||||
|
#define B0111001 57
|
||||||
|
#define B00111001 57
|
||||||
|
#define B111010 58
|
||||||
|
#define B0111010 58
|
||||||
|
#define B00111010 58
|
||||||
|
#define B111011 59
|
||||||
|
#define B0111011 59
|
||||||
|
#define B00111011 59
|
||||||
|
#define B111100 60
|
||||||
|
#define B0111100 60
|
||||||
|
#define B00111100 60
|
||||||
|
#define B111101 61
|
||||||
|
#define B0111101 61
|
||||||
|
#define B00111101 61
|
||||||
|
#define B111110 62
|
||||||
|
#define B0111110 62
|
||||||
|
#define B00111110 62
|
||||||
|
#define B111111 63
|
||||||
|
#define B0111111 63
|
||||||
|
#define B00111111 63
|
||||||
|
#define B1000000 64
|
||||||
|
#define B01000000 64
|
||||||
|
#define B1000001 65
|
||||||
|
#define B01000001 65
|
||||||
|
#define B1000010 66
|
||||||
|
#define B01000010 66
|
||||||
|
#define B1000011 67
|
||||||
|
#define B01000011 67
|
||||||
|
#define B1000100 68
|
||||||
|
#define B01000100 68
|
||||||
|
#define B1000101 69
|
||||||
|
#define B01000101 69
|
||||||
|
#define B1000110 70
|
||||||
|
#define B01000110 70
|
||||||
|
#define B1000111 71
|
||||||
|
#define B01000111 71
|
||||||
|
#define B1001000 72
|
||||||
|
#define B01001000 72
|
||||||
|
#define B1001001 73
|
||||||
|
#define B01001001 73
|
||||||
|
#define B1001010 74
|
||||||
|
#define B01001010 74
|
||||||
|
#define B1001011 75
|
||||||
|
#define B01001011 75
|
||||||
|
#define B1001100 76
|
||||||
|
#define B01001100 76
|
||||||
|
#define B1001101 77
|
||||||
|
#define B01001101 77
|
||||||
|
#define B1001110 78
|
||||||
|
#define B01001110 78
|
||||||
|
#define B1001111 79
|
||||||
|
#define B01001111 79
|
||||||
|
#define B1010000 80
|
||||||
|
#define B01010000 80
|
||||||
|
#define B1010001 81
|
||||||
|
#define B01010001 81
|
||||||
|
#define B1010010 82
|
||||||
|
#define B01010010 82
|
||||||
|
#define B1010011 83
|
||||||
|
#define B01010011 83
|
||||||
|
#define B1010100 84
|
||||||
|
#define B01010100 84
|
||||||
|
#define B1010101 85
|
||||||
|
#define B01010101 85
|
||||||
|
#define B1010110 86
|
||||||
|
#define B01010110 86
|
||||||
|
#define B1010111 87
|
||||||
|
#define B01010111 87
|
||||||
|
#define B1011000 88
|
||||||
|
#define B01011000 88
|
||||||
|
#define B1011001 89
|
||||||
|
#define B01011001 89
|
||||||
|
#define B1011010 90
|
||||||
|
#define B01011010 90
|
||||||
|
#define B1011011 91
|
||||||
|
#define B01011011 91
|
||||||
|
#define B1011100 92
|
||||||
|
#define B01011100 92
|
||||||
|
#define B1011101 93
|
||||||
|
#define B01011101 93
|
||||||
|
#define B1011110 94
|
||||||
|
#define B01011110 94
|
||||||
|
#define B1011111 95
|
||||||
|
#define B01011111 95
|
||||||
|
#define B1100000 96
|
||||||
|
#define B01100000 96
|
||||||
|
#define B1100001 97
|
||||||
|
#define B01100001 97
|
||||||
|
#define B1100010 98
|
||||||
|
#define B01100010 98
|
||||||
|
#define B1100011 99
|
||||||
|
#define B01100011 99
|
||||||
|
#define B1100100 100
|
||||||
|
#define B01100100 100
|
||||||
|
#define B1100101 101
|
||||||
|
#define B01100101 101
|
||||||
|
#define B1100110 102
|
||||||
|
#define B01100110 102
|
||||||
|
#define B1100111 103
|
||||||
|
#define B01100111 103
|
||||||
|
#define B1101000 104
|
||||||
|
#define B01101000 104
|
||||||
|
#define B1101001 105
|
||||||
|
#define B01101001 105
|
||||||
|
#define B1101010 106
|
||||||
|
#define B01101010 106
|
||||||
|
#define B1101011 107
|
||||||
|
#define B01101011 107
|
||||||
|
#define B1101100 108
|
||||||
|
#define B01101100 108
|
||||||
|
#define B1101101 109
|
||||||
|
#define B01101101 109
|
||||||
|
#define B1101110 110
|
||||||
|
#define B01101110 110
|
||||||
|
#define B1101111 111
|
||||||
|
#define B01101111 111
|
||||||
|
#define B1110000 112
|
||||||
|
#define B01110000 112
|
||||||
|
#define B1110001 113
|
||||||
|
#define B01110001 113
|
||||||
|
#define B1110010 114
|
||||||
|
#define B01110010 114
|
||||||
|
#define B1110011 115
|
||||||
|
#define B01110011 115
|
||||||
|
#define B1110100 116
|
||||||
|
#define B01110100 116
|
||||||
|
#define B1110101 117
|
||||||
|
#define B01110101 117
|
||||||
|
#define B1110110 118
|
||||||
|
#define B01110110 118
|
||||||
|
#define B1110111 119
|
||||||
|
#define B01110111 119
|
||||||
|
#define B1111000 120
|
||||||
|
#define B01111000 120
|
||||||
|
#define B1111001 121
|
||||||
|
#define B01111001 121
|
||||||
|
#define B1111010 122
|
||||||
|
#define B01111010 122
|
||||||
|
#define B1111011 123
|
||||||
|
#define B01111011 123
|
||||||
|
#define B1111100 124
|
||||||
|
#define B01111100 124
|
||||||
|
#define B1111101 125
|
||||||
|
#define B01111101 125
|
||||||
|
#define B1111110 126
|
||||||
|
#define B01111110 126
|
||||||
|
#define B1111111 127
|
||||||
|
#define B01111111 127
|
||||||
|
#define B10000000 128
|
||||||
|
#define B10000001 129
|
||||||
|
#define B10000010 130
|
||||||
|
#define B10000011 131
|
||||||
|
#define B10000100 132
|
||||||
|
#define B10000101 133
|
||||||
|
#define B10000110 134
|
||||||
|
#define B10000111 135
|
||||||
|
#define B10001000 136
|
||||||
|
#define B10001001 137
|
||||||
|
#define B10001010 138
|
||||||
|
#define B10001011 139
|
||||||
|
#define B10001100 140
|
||||||
|
#define B10001101 141
|
||||||
|
#define B10001110 142
|
||||||
|
#define B10001111 143
|
||||||
|
#define B10010000 144
|
||||||
|
#define B10010001 145
|
||||||
|
#define B10010010 146
|
||||||
|
#define B10010011 147
|
||||||
|
#define B10010100 148
|
||||||
|
#define B10010101 149
|
||||||
|
#define B10010110 150
|
||||||
|
#define B10010111 151
|
||||||
|
#define B10011000 152
|
||||||
|
#define B10011001 153
|
||||||
|
#define B10011010 154
|
||||||
|
#define B10011011 155
|
||||||
|
#define B10011100 156
|
||||||
|
#define B10011101 157
|
||||||
|
#define B10011110 158
|
||||||
|
#define B10011111 159
|
||||||
|
#define B10100000 160
|
||||||
|
#define B10100001 161
|
||||||
|
#define B10100010 162
|
||||||
|
#define B10100011 163
|
||||||
|
#define B10100100 164
|
||||||
|
#define B10100101 165
|
||||||
|
#define B10100110 166
|
||||||
|
#define B10100111 167
|
||||||
|
#define B10101000 168
|
||||||
|
#define B10101001 169
|
||||||
|
#define B10101010 170
|
||||||
|
#define B10101011 171
|
||||||
|
#define B10101100 172
|
||||||
|
#define B10101101 173
|
||||||
|
#define B10101110 174
|
||||||
|
#define B10101111 175
|
||||||
|
#define B10110000 176
|
||||||
|
#define B10110001 177
|
||||||
|
#define B10110010 178
|
||||||
|
#define B10110011 179
|
||||||
|
#define B10110100 180
|
||||||
|
#define B10110101 181
|
||||||
|
#define B10110110 182
|
||||||
|
#define B10110111 183
|
||||||
|
#define B10111000 184
|
||||||
|
#define B10111001 185
|
||||||
|
#define B10111010 186
|
||||||
|
#define B10111011 187
|
||||||
|
#define B10111100 188
|
||||||
|
#define B10111101 189
|
||||||
|
#define B10111110 190
|
||||||
|
#define B10111111 191
|
||||||
|
#define B11000000 192
|
||||||
|
#define B11000001 193
|
||||||
|
#define B11000010 194
|
||||||
|
#define B11000011 195
|
||||||
|
#define B11000100 196
|
||||||
|
#define B11000101 197
|
||||||
|
#define B11000110 198
|
||||||
|
#define B11000111 199
|
||||||
|
#define B11001000 200
|
||||||
|
#define B11001001 201
|
||||||
|
#define B11001010 202
|
||||||
|
#define B11001011 203
|
||||||
|
#define B11001100 204
|
||||||
|
#define B11001101 205
|
||||||
|
#define B11001110 206
|
||||||
|
#define B11001111 207
|
||||||
|
#define B11010000 208
|
||||||
|
#define B11010001 209
|
||||||
|
#define B11010010 210
|
||||||
|
#define B11010011 211
|
||||||
|
#define B11010100 212
|
||||||
|
#define B11010101 213
|
||||||
|
#define B11010110 214
|
||||||
|
#define B11010111 215
|
||||||
|
#define B11011000 216
|
||||||
|
#define B11011001 217
|
||||||
|
#define B11011010 218
|
||||||
|
#define B11011011 219
|
||||||
|
#define B11011100 220
|
||||||
|
#define B11011101 221
|
||||||
|
#define B11011110 222
|
||||||
|
#define B11011111 223
|
||||||
|
#define B11100000 224
|
||||||
|
#define B11100001 225
|
||||||
|
#define B11100010 226
|
||||||
|
#define B11100011 227
|
||||||
|
#define B11100100 228
|
||||||
|
#define B11100101 229
|
||||||
|
#define B11100110 230
|
||||||
|
#define B11100111 231
|
||||||
|
#define B11101000 232
|
||||||
|
#define B11101001 233
|
||||||
|
#define B11101010 234
|
||||||
|
#define B11101011 235
|
||||||
|
#define B11101100 236
|
||||||
|
#define B11101101 237
|
||||||
|
#define B11101110 238
|
||||||
|
#define B11101111 239
|
||||||
|
#define B11110000 240
|
||||||
|
#define B11110001 241
|
||||||
|
#define B11110010 242
|
||||||
|
#define B11110011 243
|
||||||
|
#define B11110100 244
|
||||||
|
#define B11110101 245
|
||||||
|
#define B11110110 246
|
||||||
|
#define B11110111 247
|
||||||
|
#define B11111000 248
|
||||||
|
#define B11111001 249
|
||||||
|
#define B11111010 250
|
||||||
|
#define B11111011 251
|
||||||
|
#define B11111100 252
|
||||||
|
#define B11111101 253
|
||||||
|
#define B11111110 254
|
||||||
|
#define B11111111 255
|
||||||
|
|
||||||
|
#endif
|
87
platform/RaspBee/dev/button-sensor.c
Normal file
87
platform/RaspBee/dev/button-sensor.c
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
/* Sensor routine */
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/button-sensor.h"
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include "led.h" // debug
|
||||||
|
|
||||||
|
const struct sensors_sensor button_sensor;
|
||||||
|
|
||||||
|
static struct timer debouncetimer;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
struct sensors_sensor *sensors[1];
|
||||||
|
unsigned char sensors_flags[1];
|
||||||
|
|
||||||
|
#define BUTTON_BIT INTF4
|
||||||
|
#define BUTTON_CHECK_IRQ() (EIFR & BUTTON_BIT) ? 0 : 1
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
ISR(INT4_vect)
|
||||||
|
{
|
||||||
|
|
||||||
|
// leds_toggle(LEDS_RED);
|
||||||
|
|
||||||
|
if(BUTTON_CHECK_IRQ()) {
|
||||||
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
led1_on();
|
||||||
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
|
sensors_changed(&button_sensor);
|
||||||
|
led1_off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer);
|
||||||
|
|
||||||
|
//return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if (c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
led1_on();
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
|
DDRE |= (0<<DDRE4); // Set pin as input
|
||||||
|
PORTE |= (1<<PORTE4); // Set port PORTE bint 5 with pullup resistor
|
||||||
|
EICRB |= (1<<ISC40); // For falling edge
|
||||||
|
EIMSK |= (1<<INT4); // Set int
|
||||||
|
enabled = 1;
|
||||||
|
sei();
|
||||||
|
led1_off();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 0;
|
||||||
|
EIMSK &= ~(1<<INT4); // clear int
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;//(EIMSK & (1<<INT5) ? 0 : 1);//BUTTON_IRQ_ENABLED();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||||
|
value, configure, status);
|
||||||
|
|
125
platform/RaspBee/dev/dht11.c
Normal file
125
platform/RaspBee/dev/dht11.c
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
DHT-11 Library
|
||||||
|
(c) Created by Charalampos Andrianakis on 18/12/11.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dht11.h"
|
||||||
|
#include "led.h" // debug
|
||||||
|
|
||||||
|
#define udelay(u) clock_delay_usec(u)
|
||||||
|
#define mdelay(u) clock_delay_msec(u)
|
||||||
|
|
||||||
|
// todo: set DHT22 or DHT11 in project file
|
||||||
|
// define for DHT11 else for DHT22, RHT03
|
||||||
|
// #define DHT11 1
|
||||||
|
|
||||||
|
uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity){
|
||||||
|
|
||||||
|
//data[5] is 8byte table where data come from DHT are stored
|
||||||
|
//laststate holds laststate value
|
||||||
|
//counter is used to count microSeconds
|
||||||
|
uint8_t data[5], laststate = 0, counter = 0, j = 0, i = 0;
|
||||||
|
|
||||||
|
//Clear array
|
||||||
|
data[0] = data[1] = data[2] = data[3] = data[4] = 0;
|
||||||
|
|
||||||
|
uint8_t volatile sreg;
|
||||||
|
sreg = SREG; /* Save status register before disabling interrupts. */
|
||||||
|
cli(); /* Disable interrupts. */
|
||||||
|
|
||||||
|
//Set pin Output
|
||||||
|
//Pin High
|
||||||
|
DHT_DRIVE();
|
||||||
|
mdelay(100); //Wait for 100mS
|
||||||
|
|
||||||
|
//Send Request Signal
|
||||||
|
//Pin Low
|
||||||
|
OUTP_0(); //20ms Low
|
||||||
|
mdelay(20);
|
||||||
|
//Pin High
|
||||||
|
OUTP_1();
|
||||||
|
udelay(40); //40us High
|
||||||
|
|
||||||
|
//Set pin Input to read Bus
|
||||||
|
//Set pin Input
|
||||||
|
DHT_RELEASE();
|
||||||
|
laststate=DHT_INP(); //Read Pin value
|
||||||
|
|
||||||
|
//Repeat for each Transistions
|
||||||
|
for (i=0; i<MAXTIMINGS; i++) {
|
||||||
|
//While state is the same count microseconds
|
||||||
|
//led1_on();
|
||||||
|
//led1_off();
|
||||||
|
|
||||||
|
while (laststate==DHT_INP()) {
|
||||||
|
udelay(1);
|
||||||
|
counter++;
|
||||||
|
if (counter>254) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter>254) break;
|
||||||
|
|
||||||
|
//laststate==_BV(DHT_PIN) checks if laststate was High
|
||||||
|
//ignore the first 2 transitions which are the DHT Response
|
||||||
|
//if (laststate==_BV(DHT_PIN) && (i > 2)) {
|
||||||
|
if ((i&0x01) && (i > 2)) {
|
||||||
|
//Save bits in segments of bytes
|
||||||
|
//Shift data[] value 1 position left
|
||||||
|
//Example. 01010100 if we shift it left one time it will be
|
||||||
|
//10101000
|
||||||
|
|
||||||
|
data[j/8]<<=1;
|
||||||
|
if (counter >= 15) { //If it was high for more than 40uS
|
||||||
|
//led1_on();
|
||||||
|
data[j/8]|=1; //it means it is bit '1' so make a logic
|
||||||
|
//led1_off();
|
||||||
|
} //OR with the value (save it)
|
||||||
|
j++; //making an OR by 1 to this value 10101000
|
||||||
|
} //we will have the resault 10101001
|
||||||
|
//1 in 8-bit binary is 00000001
|
||||||
|
//j/8 changes table record every 8 bits which means a byte has been saved
|
||||||
|
//so change to next record. 0/8=0 1/8=0 ... 7/8=0 8/8=1 ... 15/8=1 16/8=2
|
||||||
|
laststate=DHT_INP(); //save current state
|
||||||
|
counter=0; //reset counter
|
||||||
|
|
||||||
|
}
|
||||||
|
SREG = sreg; /* Enable interrupts. */
|
||||||
|
//printf("HUM %d %d %d %d %d %d",data[0],data[1],data[2],data[3],data[4],(uint8_t)(data[0] + data[1] + data[2] + data[3]) );
|
||||||
|
//Check if data received are correct by checking the CheckSum
|
||||||
|
if ((uint8_t)(data[0] + data[1] + data[2] + data[3]) == data[4]) {
|
||||||
|
#ifdef DHT11
|
||||||
|
*humidity = data[0]*100;
|
||||||
|
*temperature = data[2]*100;
|
||||||
|
#else
|
||||||
|
*humidity = ((uint16_t)data[0]<<8 | data[1])*10;
|
||||||
|
*temperature = ((uint16_t)data[2]<<8 | data[3])*10;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
*humidity = 2;
|
||||||
|
*temperature = 2;
|
||||||
|
// uart_puts("\r\nCheck Sum Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xff; // Check Sum Error
|
||||||
|
}
|
67
platform/RaspBee/dev/dht11.h
Normal file
67
platform/RaspBee/dev/dht11.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
DHT-11 Library
|
||||||
|
(c) Created by Charalampos Andrianakis on 18/12/11.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
/* DHT 1-wire is at PortE.6 */
|
||||||
|
#define DHT_PIN_READ PINE
|
||||||
|
#define DHT_PIN_MASK _BV(PE6)
|
||||||
|
#define DHT_PxOUT PORTE
|
||||||
|
#define DHT_PxDIR DDRE
|
||||||
|
|
||||||
|
#define SET_PIN_INPUT() (DHT_PxDIR &= ~DHT_PIN_MASK)
|
||||||
|
#define SET_PIN_OUTPUT() (DHT_PxDIR |= DHT_PIN_MASK)
|
||||||
|
|
||||||
|
#define OUTP_0() (DHT_PxOUT &= ~DHT_PIN_MASK)
|
||||||
|
#define OUTP_1() (DHT_PxOUT |= DHT_PIN_MASK)
|
||||||
|
|
||||||
|
#define PIN_INIT() do{ \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_0(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
/* Drive the one wire interface hight */
|
||||||
|
#define DHT_DRIVE() do { \
|
||||||
|
SET_PIN_OUTPUT(); \
|
||||||
|
OUTP_1(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Release the one wire by turning on the internal pull-up. */
|
||||||
|
#define DHT_RELEASE() do { \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_1(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Read one bit. */
|
||||||
|
#define DHT_INP() (DHT_PIN_READ & DHT_PIN_MASK)
|
||||||
|
|
||||||
|
//The packet size is 40bit but each bit consists of low and high state
|
||||||
|
//so 40 x 2 = 80 transitions. Also we have 2 transistions DHT response
|
||||||
|
//and 2 transitions which indicates End Of Frame. In total 84
|
||||||
|
#define MAXTIMINGS 84
|
||||||
|
|
||||||
|
//This is the main function which requests and reads the packet
|
||||||
|
uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity);
|
291
platform/RaspBee/dev/ds1820.c
Normal file
291
platform/RaspBee/dev/ds1820.c
Normal file
|
@ -0,0 +1,291 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: ds1820.c,v 1.5 2010/08/25 18:35:52 nifi Exp $
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Device driver for the Dallas Semiconductor DS1820 chip. Heavily
|
||||||
|
* based on the application note 126 "1-Wire Communications Through
|
||||||
|
* Software".
|
||||||
|
*
|
||||||
|
* http://www.maxim-ic.com/appnotes.cfm/appnote_number/126
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For now we stuff in Moteiv Corporation's unique OUI.
|
||||||
|
* From http://www.ethereal.com/distribution/manuf.txt:
|
||||||
|
* 00:12:75 Moteiv # Moteiv Corporation
|
||||||
|
*
|
||||||
|
* The EUI-64 is a concatenation of the 24-bit OUI value assigned by
|
||||||
|
* the IEEE Registration Authority and a 40-bit extension identifier
|
||||||
|
* assigned by the organization with that OUI assignment.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "ds1820.h"
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char ds1820_id[8];
|
||||||
|
unsigned char ds1820_ok[8];
|
||||||
|
|
||||||
|
/* 1-wire is at PortE.3 */
|
||||||
|
#define SERIAL_ID_PIN_READ PINE
|
||||||
|
//#define SERIAL_ID_PIN_MASK _BV(PE3)
|
||||||
|
#define SERIAL_ID_PIN_MASK _BV(PE4)
|
||||||
|
#define SERIAL_ID_PxOUT PORTE
|
||||||
|
#define SERIAL_ID_PxDIR DDRE
|
||||||
|
|
||||||
|
#define SET_PIN_INPUT() (SERIAL_ID_PxDIR &= ~SERIAL_ID_PIN_MASK)
|
||||||
|
#define SET_PIN_OUTPUT() (SERIAL_ID_PxDIR |= SERIAL_ID_PIN_MASK)
|
||||||
|
|
||||||
|
#define OUTP_0() (SERIAL_ID_PxOUT &= ~SERIAL_ID_PIN_MASK)
|
||||||
|
#define OUTP_1() (SERIAL_ID_PxOUT |= SERIAL_ID_PIN_MASK)
|
||||||
|
|
||||||
|
#define PIN_INIT() do{ \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_0(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
/* Drive the one wire interface low */
|
||||||
|
#define OW_DRIVE() do { \
|
||||||
|
SET_PIN_OUTPUT(); \
|
||||||
|
OUTP_0(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Release the one wire by turning on the internal pull-up. */
|
||||||
|
#define OW_RELEASE() do { \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_1(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Read one bit. */
|
||||||
|
#define INP() (SERIAL_ID_PIN_READ & SERIAL_ID_PIN_MASK)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delay times in us.
|
||||||
|
*/
|
||||||
|
#define tA 6 /* min-5, recommended-6, max-15 */
|
||||||
|
#define tB 64 /* min-59, recommended-64, max-N/A */
|
||||||
|
#define tC 60 /* min-60, recommended-60, max-120 */
|
||||||
|
#define tD 10 /* min-5.3, recommended-10, max-N/A */
|
||||||
|
#define tE 9 /* min-0.3, recommended-9, max-9.3 */
|
||||||
|
#define tF 55 /* min-50, recommended-55, max-N/A */
|
||||||
|
#define tG 0 /* min-0, recommended-0, max-0 */
|
||||||
|
#define tH 480 /* min-480, recommended-480, max-640 */
|
||||||
|
#define tI 70 /* min-60.3, recommended-70, max-75.3 */
|
||||||
|
#define tJ 410 /* min-410, recommended-410, max-N/A */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#define udelay(u) clock_delay_usec(u)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
owreset(void)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tH); /* 480 < tH < 640 */
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tI);
|
||||||
|
result = INP();
|
||||||
|
udelay(tJ);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
owwriteb(unsigned byte)
|
||||||
|
{
|
||||||
|
int i = 7;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(byte & 0x01) {
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tA);
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tB);
|
||||||
|
} else {
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tC);
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tD);
|
||||||
|
}
|
||||||
|
if(i == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
byte >>= 1;
|
||||||
|
} while(1);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static unsigned
|
||||||
|
owreadb(void)
|
||||||
|
{
|
||||||
|
unsigned result = 0;
|
||||||
|
int i = 7;
|
||||||
|
|
||||||
|
do {
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tA);
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tE);
|
||||||
|
if (INP()){
|
||||||
|
result |= 0x80; /* LSbit first */
|
||||||
|
}
|
||||||
|
udelay(tF);
|
||||||
|
if(i == 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
result >>= 1;
|
||||||
|
} while(1);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Polynomial ^8 + ^5 + ^4 + 1 */
|
||||||
|
static unsigned
|
||||||
|
crc8_add(unsigned acc, unsigned byte)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
acc ^= byte;
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
if(acc & 1) {
|
||||||
|
acc = (acc >> 1) ^ 0x8c;
|
||||||
|
} else {
|
||||||
|
acc >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ds1820_init()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned family, crc, acc;
|
||||||
|
|
||||||
|
PIN_INIT();
|
||||||
|
|
||||||
|
if(owreset() == 0) { /* Something pulled down 1-wire. */
|
||||||
|
|
||||||
|
owwriteb(0x33); /* Read ROM command. */
|
||||||
|
family = owreadb();
|
||||||
|
/* We receive 6 bytes in the reverse order, LSbyte first. */
|
||||||
|
for(i = 7; i >= 2; i--) {
|
||||||
|
ds1820_id[i] = owreadb();
|
||||||
|
}
|
||||||
|
crc = owreadb();
|
||||||
|
|
||||||
|
/* Verify family DS1820 and that CRC match. */
|
||||||
|
if(family != 0x10) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
acc = crc8_add(0x0, family);
|
||||||
|
for(i = 7; i >= 2; i--) {
|
||||||
|
acc = crc8_add(acc, ds1820_id[i]);
|
||||||
|
}
|
||||||
|
if(acc == crc) {
|
||||||
|
ds1820_id[0] = 0x00;
|
||||||
|
ds1820_id[1] = 0x00;
|
||||||
|
ds1820_id[2] = 0x00;
|
||||||
|
return 1; /* Success! */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fail:
|
||||||
|
memset(ds1820_id, 0x0, sizeof(ds1820_id));
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ds1820_temp()
|
||||||
|
{
|
||||||
|
ds1820_convert();
|
||||||
|
// wait max 750ms pin lo
|
||||||
|
clock_wait(CLOCK_SECOND);
|
||||||
|
ds1820_read();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ds1820_convert()
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
PIN_INIT();
|
||||||
|
for(i=0;i<3;i++){
|
||||||
|
if(owreset() == 0) { /* Something pulled down 1-wire. */
|
||||||
|
owwriteb(0xCC); /* Skip ROM command. */
|
||||||
|
owwriteb(0x44); /* Convert T command. */
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ds1820_read()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned crc, acc;
|
||||||
|
|
||||||
|
if(owreset() == 0) { /* Something pulled down 1-wire. */
|
||||||
|
owwriteb(0xCC); /* Skip ROM command. */
|
||||||
|
owwriteb(0xBE); /* Read Scratchpad command. */
|
||||||
|
/* We receive 8 bytes in the reverse order, LSbyte first. */
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
ds1820_id[i] = owreadb();
|
||||||
|
}
|
||||||
|
crc = owreadb();
|
||||||
|
|
||||||
|
acc=0;
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
acc = crc8_add(acc, ds1820_id[i]);
|
||||||
|
}
|
||||||
|
if(acc == crc) {
|
||||||
|
// store temp
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
ds1820_ok[i]=ds1820_id[i];
|
||||||
|
}
|
||||||
|
return 1; /* Success! */
|
||||||
|
} else {
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
return 1; /* Fail! */
|
||||||
|
}
|
45
platform/RaspBee/dev/ds1820.h
Normal file
45
platform/RaspBee/dev/ds1820.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: ds1820.h,v 1.1 2006/06/17 22:41:16 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
/* -*- C -*- */
|
||||||
|
/* @(#)$Id: ds1820.h,v 1.1 2006/06/17 22:41:16 adamdunkels Exp $ */
|
||||||
|
|
||||||
|
#ifndef DS1820_H
|
||||||
|
#define DS1820_H
|
||||||
|
|
||||||
|
extern unsigned char ds1820_id[8];
|
||||||
|
extern unsigned char ds1820_ok[8];
|
||||||
|
extern int ds1820_init();
|
||||||
|
extern int ds1820_convert();
|
||||||
|
extern int ds1820_read();
|
||||||
|
extern int ds1820_temp();
|
||||||
|
#endif /* DS1820_H */
|
83
platform/RaspBee/dev/hw-arduino.h
Normal file
83
platform/RaspBee/dev/hw-arduino.h
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Ralf Schlatterbeck Open Source Consulting
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup compatibility Arduino - Contiki
|
||||||
|
*
|
||||||
|
* This defines contiki-compatible hardware definitions for running
|
||||||
|
* arduino sketches (or just to call arduino-compatible function).
|
||||||
|
* For now only for osd hardware, a similar file should exist for each
|
||||||
|
* arduino-compatible hardware.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Header file for arduino compatibility
|
||||||
|
* \author
|
||||||
|
* Ralf Schlatterbeck <rsc@runtux.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The OSD hardware only supports timer 3 for PWM, timer 2 is used by
|
||||||
|
* contiki for sleep/wakeup timing and is not usable for PWM.
|
||||||
|
*/
|
||||||
|
#define digitalPinToTimer(pin) \
|
||||||
|
( (pin) == 2 \
|
||||||
|
? TIMER3A \
|
||||||
|
: ( (pin) == 3 \
|
||||||
|
? TIMER3B \
|
||||||
|
: ((pin == 4) ? TIMER3C : NOT_ON_TIMER) \
|
||||||
|
) \
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Only init timer 3 with phase correct pwm 8-bit and prescaler 64 */
|
||||||
|
#define arduino_pwm_timer_init() \
|
||||||
|
(hwtimer_ini (3, HWT_WGM_PWM_PHASE_8_BIT, HWT_CLOCK_PRESCALER_64, 0))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* VI settings, see coding style
|
||||||
|
* ex:ts=8:et:sw=2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** @} */
|
391
platform/RaspBee/dev/i2c.c
Normal file
391
platform/RaspBee/dev/i2c.c
Normal file
|
@ -0,0 +1,391 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Ingo Gulyas Intembsys
|
||||||
|
* 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
|
||||||
|
* I2C driver for ATMEGA128rfa1
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Ingo Gulyas Intembsys
|
||||||
|
* office@intembsys.at
|
||||||
|
* www.intembsys.at
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "contiki-conf.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/power.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#if I2C_TD != 0
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include "system_mgmt.h"
|
||||||
|
#define PRINTD(FORMAT,args...) {sleep_acquire_lock(); printf_P(PSTR(FORMAT),##args); sleep_release_lock();}
|
||||||
|
#else
|
||||||
|
#define PRINTD(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WITH_RTDEBUG == 1
|
||||||
|
#include "rtdebug.h"
|
||||||
|
#define RTDEBUG_PUSH(x) rtdebug_push(x)
|
||||||
|
#else
|
||||||
|
#warning "I2C Driver compiling without RTDEBUG!"
|
||||||
|
#define RTDEBUG_PUSH(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TIMEOUT_TIMER
|
||||||
|
#warning "I2C Driver compiling without TIMEOUT!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static int8_t wait_job();
|
||||||
|
static int8_t wait_stop();
|
||||||
|
|
||||||
|
static int8_t i2c_ioctl(const i2c_driver* const me, uint8_t cmd, uint8_t arg);
|
||||||
|
static int8_t i2c_read(const i2c_driver* const me, uint8_t cmd_flags, uint8_t* buffer, uint8_t len);
|
||||||
|
static int8_t i2c_write(const i2c_driver* const me, uint8_t cmd_flags, const uint8_t* data, uint8_t len);
|
||||||
|
|
||||||
|
|
||||||
|
// static linkage of member functions
|
||||||
|
i2c_driver i2c_drv = {i2c_ioctl, i2c_read, i2c_write};
|
||||||
|
// lock spi if driver opened to prevent further opening access
|
||||||
|
static volatile bool i2c_lock = false;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// global functions
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
i2c_driver* i2c_open(void)
|
||||||
|
{
|
||||||
|
if(i2c_lock == true)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_OPEN__DEVICE_BUSY);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_lock = true;
|
||||||
|
power_twi_enable();
|
||||||
|
I2C_INIT();
|
||||||
|
|
||||||
|
TWBR = I2C_FREQ_STANDARD;
|
||||||
|
TWSR &= ~((1<<TWPS1) | (1<<TWPS0));
|
||||||
|
TWSR |= (1<<TWPS0);
|
||||||
|
TWCR = (1<<TWEN);
|
||||||
|
|
||||||
|
return &i2c_drv;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_close(i2c_driver* const me)
|
||||||
|
{
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_CLOSE__NO_DEVICE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_reset();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_reset(void)
|
||||||
|
{
|
||||||
|
TWCR &= ~(1<<TWEN);
|
||||||
|
I2C_DEINIT();
|
||||||
|
power_twi_disable();
|
||||||
|
i2c_lock = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// local helper functions
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef TIMEOUT_TIMER
|
||||||
|
static int8_t wait_job()
|
||||||
|
{
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
uint16_t timeout = TIMEOUT_TIMER_NOW_ADD(I2C_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
|
while (!(TWCR & (1<<TWINT)))
|
||||||
|
{
|
||||||
|
if(!(TIMEOUT_TIMER_LT(TIMEOUT_TIMER_NOW(), timeout)))
|
||||||
|
{
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t wait_stop()
|
||||||
|
{
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
uint16_t timeout = TIMEOUT_TIMER_NOW_ADD(I2C_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
|
while (TWCR & (1<<TWSTO))
|
||||||
|
{
|
||||||
|
if(!(TIMEOUT_TIMER_LT(TIMEOUT_TIMER_NOW(), timeout)))
|
||||||
|
{
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static int8_t wait_job()
|
||||||
|
{
|
||||||
|
while (!(TWCR & (1<<TWINT)));
|
||||||
|
return I2C_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t wait_stop()
|
||||||
|
{
|
||||||
|
while (TWCR & (1<<TWSTO));
|
||||||
|
return I2C_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// member functions
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static int8_t i2c_ioctl(const i2c_driver* const me, uint8_t cmd, uint8_t arg)
|
||||||
|
{
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_IOCTL__DEVICE_CLOSED);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cmd == I2C_IOCTL_CMD_SET_FREQ)
|
||||||
|
{
|
||||||
|
switch(arg)
|
||||||
|
{
|
||||||
|
case I2C_FREQ_400KHZ: TWBR = I2C_FREQ_400KHZ; break;
|
||||||
|
case I2C_FREQ_250KHZ: TWBR = I2C_FREQ_250KHZ; break;
|
||||||
|
case I2C_FREQ_100KHZ: TWBR = I2C_FREQ_100KHZ; break;
|
||||||
|
case I2C_FREQ_50KHZ: TWBR = I2C_FREQ_50KHZ; break;
|
||||||
|
case I2C_FREQ_10KHZ: TWBR = I2C_FREQ_10KHZ; break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_IOCTL__ARG_INVALID);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_IOCTL__CMD_INVALID);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return I2C_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t i2c_read(const i2c_driver* const me, uint8_t cmd_flags, uint8_t* buffer, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
|
||||||
|
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__DEVICE_CLOSED);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((len > 0) && (buffer == NULL))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__ERROR_NULLPOINTER);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_START)
|
||||||
|
{
|
||||||
|
I2C_START();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__START_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((I2C_STATUS() != I2C_STATUS_START) && (I2C_STATUS() != I2C_STATUS_START_REP))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__START_ERROR);
|
||||||
|
status = I2C_ERROR_START;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-RD-START\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(len == 0) break;
|
||||||
|
|
||||||
|
for(i=0; i<(len-1); i++)
|
||||||
|
{
|
||||||
|
I2C_READ_BYTE_ACK();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_ACK_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(I2C_STATUS() != I2C_STATUS_DATAR_ACK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_ACK_ERROR);
|
||||||
|
status = I2C_ERROR_READ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer[i] = I2C_RX_REG;
|
||||||
|
PRINTD("I2C-RD-RACK: 0x%02X\n", buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
I2C_READ_BYTE_NACK();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_NACK_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(I2C_STATUS() != I2C_STATUS_DATAR_NACK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_NACK_ERROR);
|
||||||
|
status = I2C_ERROR_READ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer[i] = I2C_RX_REG;
|
||||||
|
PRINTD("I2C-RD-RNACK: 0x%02X\n", buffer[i]);
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_STOP)
|
||||||
|
{
|
||||||
|
I2C_STOP();
|
||||||
|
if(wait_stop() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__STOP_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-RD_STOP\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t i2c_write(const i2c_driver* const me, uint8_t cmd_flags, const uint8_t* data, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
|
||||||
|
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__DEVICE_CLOSED);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((len > 0) && (data == NULL))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__ERROR_NULLPOINTER);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_START)
|
||||||
|
{
|
||||||
|
I2C_START();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__START_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((I2C_STATUS() != I2C_STATUS_START) && (I2C_STATUS() != I2C_STATUS_START_REP))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__START_ERROR);
|
||||||
|
status = I2C_ERROR_START;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-WR-START\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(i=0; i<len; i++)
|
||||||
|
{
|
||||||
|
I2C_TX_REG = data[i];
|
||||||
|
I2C_WRITE_BYTE();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__WRITE_BYTE_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((I2C_STATUS() != I2C_STATUS_DATAW_ACK) && (I2C_STATUS() != I2C_STATUS_SLAW_ACK) && (I2C_STATUS() != I2C_STATUS_SLAR_ACK))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__WRITE_BYTE_ERROR);
|
||||||
|
status = I2C_ERROR_WRITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-WR-BYTE: 0x%02X\n", data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_STOP)
|
||||||
|
{
|
||||||
|
I2C_STOP();
|
||||||
|
if(wait_stop() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__STOP_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-WR-STOP\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
131
platform/RaspBee/dev/i2c.h
Normal file
131
platform/RaspBee/dev/i2c.h
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Ingo Gulyas Intembsys
|
||||||
|
* 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
|
||||||
|
* I2C driver for ATMEGA128rfa1
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Ingo Gulyas Intembsys
|
||||||
|
* office@intembsys.at
|
||||||
|
* www.intembsys.at
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef I2C_H_
|
||||||
|
#define I2C_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CONFIGURATION SECTION:
|
||||||
|
|
||||||
|
#define I2C_TD 0 // compiler switch: i2c testdriver code
|
||||||
|
|
||||||
|
#define I2C_PORT PORTD
|
||||||
|
#define I2C_DDR DDRD
|
||||||
|
#define I2C_SCL_PIN 0
|
||||||
|
#define I2C_SDA_PIN 1
|
||||||
|
|
||||||
|
// END OF CONFIGURATION SECTION
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define I2C_INIT() ({I2C_DDR &= ~((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN)); I2C_PORT |= ((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN));})
|
||||||
|
#define I2C_DEINIT() ({I2C_DDR &= ~((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN)); I2C_PORT |= ((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN));})
|
||||||
|
|
||||||
|
#define I2C_FREQ_STANDARD I2C_FREQ_50KHZ
|
||||||
|
|
||||||
|
#if F_CPU == 16000000UL
|
||||||
|
#define I2C_FREQ_400KHZ 0x03
|
||||||
|
#define I2C_FREQ_250KHZ 0x06
|
||||||
|
#define I2C_FREQ_100KHZ 0x12
|
||||||
|
#define I2C_FREQ_50KHZ 0x26
|
||||||
|
#define I2C_FREQ_10KHZ 0xC6
|
||||||
|
#else
|
||||||
|
#error "NO I2C FREQUENCY DEFINED -> CHECK F_CPU SETTINGS!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_STATUS_REG TWSR
|
||||||
|
#define I2C_TX_REG TWDR
|
||||||
|
#define I2C_RX_REG TWDR
|
||||||
|
|
||||||
|
#define I2C_START() (TWCR = (1<<TWINT) |(1<<TWSTA) | (1<<TWEN))
|
||||||
|
#define I2C_STOP() (TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO))
|
||||||
|
#define I2C_WRITE_BYTE() (TWCR = (1<<TWINT) | (1<<TWEN))
|
||||||
|
#define I2C_READ_BYTE_ACK() (TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA))
|
||||||
|
#define I2C_READ_BYTE_NACK() (TWCR = (1<<TWINT) | (1<<TWEN))
|
||||||
|
#define I2C_STATUS() (I2C_STATUS_REG & I2C_STATUS_MASK)
|
||||||
|
|
||||||
|
#define I2C_STATUS_MASK 0xF8
|
||||||
|
#define I2C_STATUS_START 0x08
|
||||||
|
#define I2C_STATUS_START_REP 0x10
|
||||||
|
#define I2C_STATUS_SLAW_ACK 0x18
|
||||||
|
#define I2C_STATUS_DATAW_ACK 0x28
|
||||||
|
#define I2C_STATUS_SLAR_ACK 0x40
|
||||||
|
#define I2C_STATUS_DATAR_ACK 0x50
|
||||||
|
#define I2C_STATUS_DATAR_NACK 0x58
|
||||||
|
|
||||||
|
#define I2C_ADR_WR(adr) ((adr<<1) & ~(1<<0))
|
||||||
|
#define I2C_ADR_RD(adr) ((adr<<1) | (1<<0))
|
||||||
|
|
||||||
|
#define I2C_CMD_FLAG_NONE 0x00
|
||||||
|
#define I2C_CMD_FLAG_START (1<<0)
|
||||||
|
#define I2C_CMD_FLAG_STOP (1<<1)
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_OK 0
|
||||||
|
#define I2C_ERROR_DRIVER -1
|
||||||
|
#define I2C_ERROR_TIMEOUT -2
|
||||||
|
#define I2C_ERROR_START -3
|
||||||
|
#define I2C_ERROR_WRITE -4
|
||||||
|
#define I2C_ERROR_READ -5
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_IOCTL_CMD_SET_FREQ 0x01
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct i2c_driver i2c_driver;
|
||||||
|
struct i2c_driver
|
||||||
|
{
|
||||||
|
int8_t (*ioctl)(const i2c_driver* const me, uint8_t cmd, uint8_t arg);
|
||||||
|
int8_t (*read)(const i2c_driver* const me, uint8_t cmd_flags, uint8_t* buffer, uint8_t len);
|
||||||
|
int8_t (*write)(const i2c_driver* const me, uint8_t cmd_flags, const uint8_t* data, uint8_t len);
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_driver* i2c_open(void);
|
||||||
|
void i2c_close(i2c_driver* const me);
|
||||||
|
void i2c_reset(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* I2C_H_ */
|
73
platform/RaspBee/dev/key.c
Normal file
73
platform/RaspBee/dev/key.c
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 harald pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven KEY support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "key.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief This will intialize the KEY for button readings.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
key_init(void)
|
||||||
|
{
|
||||||
|
/* Enter is input w/pullup */
|
||||||
|
DDRF &= ~(1<<PINF1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief This will poll run key_task() to determine if a button has been pressed.
|
||||||
|
*
|
||||||
|
* \retval True if button is pressed
|
||||||
|
* \retval False if button is not pressed
|
||||||
|
*/
|
||||||
|
uint8_t
|
||||||
|
is_button(void)
|
||||||
|
{
|
||||||
|
/* Return true if button has been pressed. */
|
||||||
|
if ( PINF & (1<<PINF1) ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
50
platform/RaspBee/dev/key.h
Normal file
50
platform/RaspBee/dev/key.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Harald Pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven Key support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pixhlwe harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __KEY_H__
|
||||||
|
#define __KEY_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
void key_init(void);
|
||||||
|
uint8_t is_button(void);
|
||||||
|
|
||||||
|
#endif /* __KEY_H__ */
|
90
platform/RaspBee/dev/led.c
Normal file
90
platform/RaspBee/dev/led.c
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Bernhard Trinnes
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides RaspBee LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Bernhard Trinnes bernhard.trinnes@guh.guru
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup relay
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns LED1 on.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
led1_on(void)
|
||||||
|
{
|
||||||
|
PORTD &= ~(1<<PIND7);
|
||||||
|
DDRD |= (1<<PIND7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns LED1 off.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
led1_off(void)
|
||||||
|
{
|
||||||
|
PORTD |= (1<<PIND7);
|
||||||
|
DDRD |= (1<<PIND7);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void
|
||||||
|
led2_on(void)
|
||||||
|
{
|
||||||
|
PORTG &= ~(1<<PING2);
|
||||||
|
DDRG |= (1<<PING2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns LED2 off.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
led2_off(void)
|
||||||
|
{
|
||||||
|
PORTG |= (1<<PING2);
|
||||||
|
DDRG |= (1<<PING2);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
54
platform/RaspBee/dev/led.h
Normal file
54
platform/RaspBee/dev/led.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Harald Pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LED_H__
|
||||||
|
#define __LED_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/** @name LED Functions */
|
||||||
|
/** @{ */
|
||||||
|
void led1_on(void);
|
||||||
|
void led1_off(void);
|
||||||
|
void led2_on(void);
|
||||||
|
void led2_off(void);
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif /* __LED_H__ */
|
84
platform/RaspBee/dev/leds-arch.c
Normal file
84
platform/RaspBee/dev/leds-arch.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 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.
|
||||||
|
*
|
||||||
|
* $Id: leds-arch.c,v 1.1 2006/06/17 22:41:31 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Leds arch. for STK600-Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// WARNING : Blink function is disabled on the core leds.c file
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/leds.h"
|
||||||
|
#include "leds-arch.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
leds_arch_init(void)
|
||||||
|
{
|
||||||
|
DDRE|=(1<<DDRE5); // Set pins as output since leds are mounted on the VDD bus
|
||||||
|
LEDS_OFF();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
unsigned char
|
||||||
|
leds_arch_get(void)
|
||||||
|
{
|
||||||
|
return ((LED_OUT & BIT_RED) ? 0 : LEDS_RED)
|
||||||
|
| ((LED_OUT & BIT_GREEN) ? 0 : LEDS_GREEN)
|
||||||
|
| ((LED_OUT & BIT_YELLOW) ? 0 : LEDS_YELLOW);
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
leds_arch_set(unsigned char leds)
|
||||||
|
{
|
||||||
|
if(leds & LEDS_GREEN) {
|
||||||
|
LED_OUT &= ~BIT_GREEN;
|
||||||
|
} else {
|
||||||
|
LED_OUT |= BIT_GREEN;
|
||||||
|
}
|
||||||
|
if(leds & LEDS_YELLOW) {
|
||||||
|
LED_OUT &= ~BIT_YELLOW;
|
||||||
|
} else {
|
||||||
|
LED_OUT |= BIT_YELLOW;
|
||||||
|
}
|
||||||
|
if(leds & LEDS_RED) {
|
||||||
|
LED_OUT &= ~BIT_RED;
|
||||||
|
} else {
|
||||||
|
LED_OUT |= BIT_RED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
36
platform/RaspBee/dev/leds-arch.h
Normal file
36
platform/RaspBee/dev/leds-arch.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
guhRF Platform has just one green LED on PIN E5
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LEDS_ARCH_H__
|
||||||
|
#define __LEDS_ARCH_H__
|
||||||
|
|
||||||
|
#define LED_OUT PORTE
|
||||||
|
|
||||||
|
#define BIT_RED _BV(PE5)
|
||||||
|
#define BIT_BLUE BIT_RED
|
||||||
|
#define BIT_GREEN BIT_RED
|
||||||
|
#define BIT_YELLOW BIT_RED
|
||||||
|
|
||||||
|
#define LED_GREEN_ON() LED_OUT &= ~BIT_GREEN
|
||||||
|
#define LED_GREEN_OFF() LED_OUT |= BIT_GREEN
|
||||||
|
#define LED_YELLOW_ON() LED_OUT &= ~BIT_YELLOW
|
||||||
|
#define LED_YELLOW_OFF() LED_OUT |= BIT_YELLOW
|
||||||
|
#define LED_RED_ON() LED_OUT &= ~BIT_RED
|
||||||
|
#define LED_RED_OFF() LED_OUT |= BIT_RED
|
||||||
|
|
||||||
|
|
||||||
|
#define LED_GREEN_TOGGLE() LED_OUT ^= BIT_GREEN
|
||||||
|
#define LED_YELLOW_TOGGLE() LED_OUT ^= BIT_YELLOW
|
||||||
|
#define LED_RED_TOGGLE() LED_OUT ^= BIT_RED
|
||||||
|
|
||||||
|
#define LEDS_ON() LED_OUT &= ~(BIT_BLUE | BIT_GREEN | BIT_RED)
|
||||||
|
#define LEDS_OFF() LED_OUT |= (BIT_BLUE | BIT_GREEN | BIT_RED)
|
||||||
|
|
||||||
|
|
||||||
|
void leds_arch_init(void);
|
||||||
|
unsigned char leds_arch_get(void);
|
||||||
|
void leds_arch_set(unsigned char leds);
|
||||||
|
|
||||||
|
#endif /* __LEDS_ARCH_H__ */
|
102
platform/RaspBee/dev/optriac-sensor.c
Normal file
102
platform/RaspBee/dev/optriac-sensor.c
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.c,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* optriac sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "dev/optriac-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
const struct sensors_sensor optriac_sensor;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
static int optriac[2]={0,0};
|
||||||
|
static int optriacpin[8]={OPTRIAC_PIN_1,OPTRIAC_PIN_2};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return optriac[type];
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
pinMode(optriacpin[OPTRIAC_SENSOR_1], OUTPUT);
|
||||||
|
digitalWrite(optriacpin[OPTRIAC_SENSOR_1], LOW);
|
||||||
|
pinMode(optriacpin[OPTRIAC_SENSOR_2], OUTPUT);
|
||||||
|
digitalWrite(optriacpin[OPTRIAC_SENSOR_2], LOW);
|
||||||
|
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPTRIAC_SENSOR_1:
|
||||||
|
case OPTRIAC_SENSOR_2:
|
||||||
|
|
||||||
|
if(c==0){
|
||||||
|
digitalWrite(optriacpin[type], LOW);
|
||||||
|
optriac[type]=0;
|
||||||
|
}else{
|
||||||
|
digitalWrite(optriacpin[type], HIGH);
|
||||||
|
optriac[type]=1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(optriac_sensor, OPTRIAC_SENSOR, value, configure, status);
|
54
platform/RaspBee/dev/optriac-sensor.h
Normal file
54
platform/RaspBee/dev/optriac-sensor.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c), Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.h,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Servo sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __OPTRIAC_SENSOR_H__
|
||||||
|
#define __OPTRIAC_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor optriac_sensor;
|
||||||
|
|
||||||
|
#define OPTRIAC_SENSOR "TRIAC"
|
||||||
|
#define OPTRIAC_SENSOR_1 0
|
||||||
|
#define OPTRIAC_SENSOR_2 1
|
||||||
|
|
||||||
|
/* default pins Arduino-Merkurboard */
|
||||||
|
#define OPTRIAC_PIN_1 2
|
||||||
|
#define OPTRIAC_PIN_2 3
|
||||||
|
|
||||||
|
#endif /* __OPTRIAC_SENSOR_H__ */
|
218
platform/RaspBee/dev/pins_arduino.h
Normal file
218
platform/RaspBee/dev/pins_arduino.h
Normal file
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
pins_arduino.h - Pin definition functions for Arduino
|
||||||
|
Part of Arduino - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2014 Harald Pichler
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General
|
||||||
|
Public License along with this library; if not, write to the
|
||||||
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
$Id: wiring.h 249 2014-04-18 17:35:12Z pichler $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This version of pins_arduino.h is for the Merkur Dev Board r1
|
||||||
|
Harald Pichler 2014 Apr 18
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Pins_Arduino_h
|
||||||
|
#define Pins_Arduino_h
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#define NUM_DIGITAL_PINS 15
|
||||||
|
#define NUM_ANALOG_INPUTS 6
|
||||||
|
#define analogInputToDigitalPin(p) ((p < NUM_ANALOG_INPUTS) ? (p) + NUM_DIGITAL_PINS : -1)
|
||||||
|
#define digitalPinHasPWM(p) ((p) == 2 ||(p) == 3 ||(p) == 4 ||(p) == 14 )
|
||||||
|
|
||||||
|
// Dev board specific defines: RF RX and TX LEDs:
|
||||||
|
#define RXLED_DDR DDRB
|
||||||
|
#define RXLED_PORT PORTB
|
||||||
|
#define RXLED_POS PB6
|
||||||
|
|
||||||
|
#define TXLED_DDR DDRB
|
||||||
|
#define TXLED_PORT PORTB
|
||||||
|
#define TXLED_POS PB7
|
||||||
|
|
||||||
|
const static uint8_t SS = 10;
|
||||||
|
const static uint8_t MOSI = 11;
|
||||||
|
const static uint8_t MISO = 13;
|
||||||
|
const static uint8_t SCK = 12;
|
||||||
|
|
||||||
|
const static uint8_t SDA = 9;
|
||||||
|
const static uint8_t SCL = 8;
|
||||||
|
const static uint8_t LED = 4;
|
||||||
|
const static uint8_t LED1 = 4;
|
||||||
|
const static uint8_t LED2 = 5;
|
||||||
|
|
||||||
|
const static uint8_t A0 = 7;
|
||||||
|
const static uint8_t A1 = 6;
|
||||||
|
const static uint8_t A2 = 5;
|
||||||
|
const static uint8_t A3 = 4;
|
||||||
|
const static uint8_t A4 = 0;
|
||||||
|
const static uint8_t A5 = 1;
|
||||||
|
|
||||||
|
// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
|
||||||
|
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
|
||||||
|
// Pins: 10, 11, 12, 13, 14
|
||||||
|
|
||||||
|
#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 14)) || ? (&PCICR) : ((uint8_t *)0) )
|
||||||
|
|
||||||
|
#define digitalPinToPCICRbit(p) ( 0 )
|
||||||
|
|
||||||
|
#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 14)) ? (&PCMSK0) : ((uint8_t *)0) )
|
||||||
|
|
||||||
|
#define digitalPinToPCMSKbit(p) ( ((p) == 10) ? 6 : \
|
||||||
|
( ((p) == 11) ? 5 : \
|
||||||
|
( ((p) == 12) ? 1 : \
|
||||||
|
( ((p) == 13) ? 3 : \
|
||||||
|
( ((p) == 14) ? 7 : \
|
||||||
|
0 ) ) ) ) )
|
||||||
|
|
||||||
|
#ifdef ARDUINO_MAIN
|
||||||
|
|
||||||
|
const uint16_t PROGMEM port_to_mode_PGM[] = {
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&DDRB,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&DDRD,
|
||||||
|
(uint16_t)&DDRE,
|
||||||
|
(uint16_t)&DDRF,
|
||||||
|
(uint16_t)&DDRG,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM port_to_output_PGM[] = {
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&PORTB,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&PORTD,
|
||||||
|
(uint16_t)&PORTE,
|
||||||
|
(uint16_t)&PORTF,
|
||||||
|
(uint16_t)&PORTG,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM port_to_input_PGM[] = {
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
(uint16_t)&PINC,
|
||||||
|
(uint16_t)&PIND,
|
||||||
|
(uint16_t)&PINE,
|
||||||
|
(uint16_t)&PINF,
|
||||||
|
(uint16_t)&PING,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
|
||||||
|
// PORTLIST
|
||||||
|
// -------------------------------------------
|
||||||
|
PE , // PE 1 ** 0 ** D0 / USART0_TX
|
||||||
|
PE , // PE 0 ** 1 ** D1 / USART0_RX
|
||||||
|
PE , // PE 3 ** 2 ** D2 / PWM
|
||||||
|
PE , // PE 4 ** 3 ** D3 / PWM
|
||||||
|
PE , // PE 5 ** 4 ** D4 / PWM / LED1 / LED
|
||||||
|
PE , // PE 6 ** 5 ** D5 / LED2
|
||||||
|
PD , // PD 3 ** 6 ** D6 / USART1_TX
|
||||||
|
PD , // PD 2 ** 7 ** D7 / USART1_RX
|
||||||
|
PD , // PD 0 ** 8 ** D8 / I2C_SCL
|
||||||
|
PD , // PD 1 ** 9 ** D9 / I2C_SDA
|
||||||
|
PB , // PB 0 ** 10 ** D10 / SPI_SSN
|
||||||
|
PB , // PB 2 ** 11 ** D11 / SPI_MOSI
|
||||||
|
PB , // PB 1 ** 12 ** D12 / SPI_SCK
|
||||||
|
PB , // PB 3 ** 13 ** D13 / SPI_MISO
|
||||||
|
PB , // PB 4 ** 14 ** D14 / PWM
|
||||||
|
PF , // PF 7 ** 15 ** A0 / D15
|
||||||
|
PF , // PF 6 ** 16 ** A1 / D16
|
||||||
|
PF , // PF 5 ** 17 ** A2 / D17
|
||||||
|
PF , // PF 4 ** 18 ** A3 / D18
|
||||||
|
PF , // PF 0 ** 19 ** A4 / D19
|
||||||
|
PF , // PF 1 ** 20 ** A5 / D20
|
||||||
|
// PB , // PB 6 ** 34 ** D34 / LED1 / LED / PWM
|
||||||
|
// PB , // PB 7 ** 35 ** D35 / LED2 / PWM
|
||||||
|
// PE , // PE 2 ** 2 ** D2
|
||||||
|
// PE , // PE 7 ** 7 ** D7
|
||||||
|
// PB , // PB 5 ** 8 ** D8 / PWM
|
||||||
|
// PG , // PG 0 ** 16 ** D16
|
||||||
|
// PG , // PG 1 ** 17 ** D17
|
||||||
|
// PG , // PG 2 ** 18 ** D18
|
||||||
|
// PG , // PG 5 ** 19 ** D19 / PWM
|
||||||
|
// PD , // PD 4 ** 22 ** D22
|
||||||
|
// PD , // PD 5 ** 23 ** D23
|
||||||
|
// PD , // PD 6 ** 24 ** D24
|
||||||
|
// PD , // PD 7 ** 25 ** D25
|
||||||
|
// PF , // PF 2 ** 28 ** A2 / D28
|
||||||
|
// PF , // PF 3 ** 29 ** A3 / D29
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
|
||||||
|
// PIN IN PORT
|
||||||
|
// -------------------------------------------
|
||||||
|
_BV( 1 ) , // PE 1 ** 0 ** USART0_TX
|
||||||
|
_BV( 0 ) , // PE 0 ** 1 ** USART0_RX
|
||||||
|
_BV( 3 ) , // PE 3 ** 2 ** D3 / PWM
|
||||||
|
_BV( 4 ) , // PE 4 ** 3 ** D4 / PWM
|
||||||
|
_BV( 5 ) , // PE 5 ** 4 ** D5 / PWM
|
||||||
|
_BV( 6 ) , // PE 6 ** 5 ** D6
|
||||||
|
_BV( 3 ) , // PD 3 ** 6 ** D21 / USART1_TX
|
||||||
|
_BV( 2 ) , // PD 2 ** 7 ** D20 / USART1_RX
|
||||||
|
_BV( 0 ) , // PD 0 ** 8 ** D15 / I2C_SCL
|
||||||
|
_BV( 1 ) , // PD 1 ** 9 ** D14 / I2C_SDA
|
||||||
|
_BV( 0 ) , // PB 0 ** 10 ** D10 / SPI_SSN
|
||||||
|
_BV( 2 ) , // PB 2 ** 11 ** D11 / SPI_MOSI
|
||||||
|
_BV( 1 ) , // PB 1 ** 12 ** D13 / SPI_SCK
|
||||||
|
_BV( 3 ) , // PB 3 ** 13 ** D12 / SPI_MISO
|
||||||
|
_BV( 4 ) , // PB 4 ** 14 ** D9 / PWM
|
||||||
|
_BV( 7 ) , // PF 7 ** 15 ** A0 / D33
|
||||||
|
_BV( 6 ) , // PF 6 ** 16 ** A1 / D32
|
||||||
|
_BV( 5 ) , // PF 5 ** 17 ** A2 / D31
|
||||||
|
_BV( 4 ) , // PF 4 ** 18 ** A3 / D30
|
||||||
|
_BV( 0 ) , // PF 0 ** 19 ** A4 / D26
|
||||||
|
_BV( 1 ) , // PF 1 ** 20 ** A5 / D27
|
||||||
|
// _BV( 2 ) , // PE 2 ** 2 ** D2
|
||||||
|
// _BV( 7 ) , // PE 7 ** 7 ** D7
|
||||||
|
// _BV( 5 ) , // PB 5 ** 8 ** D8 / PWM
|
||||||
|
// _BV( 0 ) , // PG 0 ** 16 ** D16
|
||||||
|
// _BV( 1 ) , // PG 1 ** 17 ** D17
|
||||||
|
// _BV( 2 ) , // PG 2 ** 18 ** D18
|
||||||
|
// _BV( 5 ) , // PG 5 ** 19 ** D19 / PWM
|
||||||
|
// _BV( 4 ) , // PD 4 ** 22 ** D22
|
||||||
|
// _BV( 5 ) , // PD 5 ** 23 ** D23
|
||||||
|
// _BV( 6 ) , // PD 6 ** 24 ** D24
|
||||||
|
// _BV( 7 ) , // PD 7 ** 25 ** D25
|
||||||
|
// _BV( 2 ) , // PF 2 ** 28 ** A2 / D28
|
||||||
|
// _BV( 3 ) , // PF 3 ** 29 ** A3 / D29
|
||||||
|
// _BV( 6 ) , // PB 6 ** 34 ** D34 / LED1 / LED / PWM
|
||||||
|
// _BV( 7 ) , // PB 7 ** 35 ** D35 / LED2 / PWM
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
85
platform/RaspBee/dev/pir-sensor.c
Normal file
85
platform/RaspBee/dev/pir-sensor.c
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/* Sensor routine */
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/pir-sensor.h"
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include "led.h" // debug
|
||||||
|
|
||||||
|
const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
|
static struct timer debouncetimer;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
struct sensors_sensor *sensors[1];
|
||||||
|
unsigned char sensors_flags[1];
|
||||||
|
|
||||||
|
#define PIR_BIT INTF6
|
||||||
|
#define PIR_CHECK_IRQ() (EIFR & PIR_BIT) ? 0 : 1
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
ISR(INT6_vect)
|
||||||
|
{
|
||||||
|
|
||||||
|
// leds_toggle(LEDS_YELLOW);
|
||||||
|
|
||||||
|
if(PIR_CHECK_IRQ()) {
|
||||||
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
// led1_on();
|
||||||
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
|
sensors_changed(&pir_sensor);
|
||||||
|
// led1_off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return (PORTE & _BV(PE6) ? 0 : 1) || !timer_expired(&debouncetimer);
|
||||||
|
//return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if (c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
// led1_on();
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
|
DDRE |= (0<<DDRE6); // Set pin as input
|
||||||
|
PORTE |= (1<<PORTE6); // Set port PORTE bint 6 with pullup resistor
|
||||||
|
EICRB |= (3<<ISC60); // For rising edge
|
||||||
|
EIMSK |= (1<<INT6); // Set int
|
||||||
|
enabled = 1;
|
||||||
|
sei();
|
||||||
|
// led1_off();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 0;
|
||||||
|
EIMSK &= ~(1<<INT6); // clear int
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;//(EIMSK & (1<<INT6) ? 0 : 1);//PIR_IRQ_ENABLED();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
|
||||||
|
value, configure, status);
|
||||||
|
|
48
platform/RaspBee/dev/pir-sensor.h
Normal file
48
platform/RaspBee/dev/pir-sensor.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* PIR sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PIR_SENSOR_H__
|
||||||
|
#define __PIR_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
|
#define PIR_SENSOR "PIR"
|
||||||
|
|
||||||
|
#endif /* __PIR_SENSOR_H__ */
|
109
platform/RaspBee/dev/relay-sensor.c
Normal file
109
platform/RaspBee/dev/relay-sensor.c
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: relay-sensor.c,v 1.0 2013/11/22 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* relay sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/relay.h"
|
||||||
|
#include "dev/relay-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
const struct sensors_sensor relay_sensor;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
static int relay[8]={0,0,0,0,0,0,0,0};
|
||||||
|
static int relaypin[8]={RELAY_PIN_1,RELAY_PIN_2,RELAY_PIN_3,RELAY_PIN_4,RELAY_PIN_5,RELAY_PIN_6,RELAY_PIN_7,RELAY_PIN_8};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return relay[type];
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_1]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_2]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_3]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_4]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_5]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_6]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_7]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_8]);
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELAY_SENSOR_1:
|
||||||
|
case RELAY_SENSOR_2:
|
||||||
|
case RELAY_SENSOR_3:
|
||||||
|
case RELAY_SENSOR_4:
|
||||||
|
case RELAY_SENSOR_5:
|
||||||
|
case RELAY_SENSOR_6:
|
||||||
|
case RELAY_SENSOR_7:
|
||||||
|
case RELAY_SENSOR_8:
|
||||||
|
if(c==0){
|
||||||
|
relay_off(relaypin[type]);
|
||||||
|
relay[type]=0;
|
||||||
|
}else{
|
||||||
|
relay_on(relaypin[type]);
|
||||||
|
relay[type]=1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(relay_sensor, RELAY_SENSOR, value, configure, status);
|
66
platform/RaspBee/dev/relay-sensor.h
Normal file
66
platform/RaspBee/dev/relay-sensor.h
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c), Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: relay-sensor.h,v 1.0 2013/11/22 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Relay sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RELAY_SENSOR_H__
|
||||||
|
#define __RELAY_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor relay_sensor;
|
||||||
|
|
||||||
|
#define RELAY_SENSOR "RELAY"
|
||||||
|
#define RELAY_SENSOR_1 0
|
||||||
|
#define RELAY_SENSOR_2 1
|
||||||
|
#define RELAY_SENSOR_3 2
|
||||||
|
#define RELAY_SENSOR_4 3
|
||||||
|
#define RELAY_SENSOR_5 4
|
||||||
|
#define RELAY_SENSOR_6 5
|
||||||
|
#define RELAY_SENSOR_7 6
|
||||||
|
#define RELAY_SENSOR_8 7
|
||||||
|
|
||||||
|
/* default pins Arduino-Merkurboard */
|
||||||
|
#define RELAY_PIN_1 10
|
||||||
|
#define RELAY_PIN_2 11
|
||||||
|
#define RELAY_PIN_3 12
|
||||||
|
#define RELAY_PIN_4 13
|
||||||
|
#define RELAY_PIN_5 15
|
||||||
|
#define RELAY_PIN_6 16
|
||||||
|
#define RELAY_PIN_7 17
|
||||||
|
#define RELAY_PIN_8 18
|
||||||
|
|
||||||
|
#endif /* __RELAY_SENSOR_H__ */
|
76
platform/RaspBee/dev/relay.c
Normal file
76
platform/RaspBee/dev/relay.c
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 harald pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "relay.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup relay
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief init RELAY PINS.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
relay_init(uint8_t pin)
|
||||||
|
{
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* \brief Turns the RELAY on.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
relay_on(uint8_t pin)
|
||||||
|
{
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns the RELAY off
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
relay_off(uint8_t pin)
|
||||||
|
{
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
}
|
54
platform/RaspBee/dev/relay.h
Normal file
54
platform/RaspBee/dev/relay.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Harald Pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RELAY_H__
|
||||||
|
#define __RELAY_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/** @name RELAY Functions */
|
||||||
|
/** @{ */
|
||||||
|
void relay_init(uint8_t pin);
|
||||||
|
void relay_on(uint8_t pin);
|
||||||
|
void relay_off(uint8_t pin);
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif /* __RELAY_H__ */
|
100
platform/RaspBee/dev/servo-sensor.c
Normal file
100
platform/RaspBee/dev/servo-sensor.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.c,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Servo sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/servo.h"
|
||||||
|
#include "dev/servo-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
const struct sensors_sensor servo_sensor;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SERVO_SENSOR_A:
|
||||||
|
return servo_get(0);;
|
||||||
|
|
||||||
|
/* Total Solar Radiation. */
|
||||||
|
case SERVO_SENSOR_B:
|
||||||
|
return servo_get(1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
servo_init();
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
servo_off();
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SERVO_SENSOR_A:
|
||||||
|
servo_set(0,c);
|
||||||
|
break;
|
||||||
|
case SERVO_SENSOR_B:
|
||||||
|
servo_set(1,c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(servo_sensor, SERVO_SENSOR, value, configure, status);
|
50
platform/RaspBee/dev/servo-sensor.h
Normal file
50
platform/RaspBee/dev/servo-sensor.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c), Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.h,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Servo sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVO_SENSOR_H__
|
||||||
|
#define __SERVO_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor servo_sensor;
|
||||||
|
|
||||||
|
#define SERVO_SENSOR "Servo"
|
||||||
|
#define SERVO_SENSOR_A 0
|
||||||
|
#define SERVO_SENSOR_B 1
|
||||||
|
|
||||||
|
#endif /* __SERVO_SENSOR_H__ */
|
152
platform/RaspBee/dev/servo.c
Normal file
152
platform/RaspBee/dev/servo.c
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Device driver for the Sensirion SHT1x/SHT7x family of humidity and
|
||||||
|
* temperature sensors.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dev/servo.h>
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* servo device
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned int servoa=SERVO_INIT;
|
||||||
|
unsigned int servob=SERVO_INIT;
|
||||||
|
|
||||||
|
void
|
||||||
|
servo_init(void)
|
||||||
|
{
|
||||||
|
// Port E initialization
|
||||||
|
// Set Pin 3 and 4 to output mode for OCR1A and OCR2A
|
||||||
|
DDRE |= 1<<3 | 1<<4;
|
||||||
|
|
||||||
|
// Timer/Counter 3 initialization
|
||||||
|
// Clock source: System Clock
|
||||||
|
// Clock value: 2000.000 kHz
|
||||||
|
// Mode: Ph. & fr. cor. PWM top=ICR1
|
||||||
|
// OC3A output: Connected
|
||||||
|
// OC3B output: Connected
|
||||||
|
// OC3C output: Connected
|
||||||
|
// Noise Canceler: Off
|
||||||
|
// Input Capture on Falling Edge
|
||||||
|
// Timer3 Overflow Interrupt: Off
|
||||||
|
// Input Capture Interrupt: Off
|
||||||
|
// Compare A Match Interrupt: Off
|
||||||
|
// Compare B Match Interrupt: Off
|
||||||
|
// Compare C Match Interrupt: Off
|
||||||
|
|
||||||
|
/* TCCR3A = [COM3A1|COM3A0|COM3B1|COM3B0||FOC3A|FOC3B|WGM31|WGM30] */
|
||||||
|
/* 1 0 1 0 1 0 0 0 */
|
||||||
|
TCCR3A=0xA8;
|
||||||
|
/* TCCR3B = [ ICNC3| ICES3| -| WGM33||WGM32| CS32| CS31| CS30] */
|
||||||
|
/* 0 0 0 1 0 0 1 0 */
|
||||||
|
TCCR3B=0x12;
|
||||||
|
TCNT3H=0x00;
|
||||||
|
TCNT3L=0x00;
|
||||||
|
// ICR3 has a computed value of 20,000 - see the chip manual for how this
|
||||||
|
// value was derived.
|
||||||
|
// 20000 == 0x4e20 so that's what goes into the high and low byte of the ICR3 register
|
||||||
|
// alternatively, Codevision would let you just do ICR3 = 20000;
|
||||||
|
ICR3H=0x4E;
|
||||||
|
ICR3L=0x20;
|
||||||
|
|
||||||
|
// OCR3A will govern the steering servo, OCR3B will govern throttle
|
||||||
|
OCR3A = servoa; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
||||||
|
|
||||||
|
// OCR3A will govern the steering servo, OCR3B will govern throttle
|
||||||
|
OCR3B = servob; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
||||||
|
// start with motor off - no duty cycle at all
|
||||||
|
OCR3CH=0x00;
|
||||||
|
OCR3CL=0x00;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Power of device.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
servo_off(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* get servo position
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
servo_get(unsigned int i)
|
||||||
|
{
|
||||||
|
if(i==0)
|
||||||
|
return servoa;
|
||||||
|
if(i==1)
|
||||||
|
return servob;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Set servo position
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
servo_set(unsigned i,unsigned int j)
|
||||||
|
{
|
||||||
|
if(j > SERVO_MAX)
|
||||||
|
j=SERVO_MAX;
|
||||||
|
if(j < SERVO_MIN)
|
||||||
|
j=SERVO_MIN;
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
servoa=j;
|
||||||
|
OCR3A = servoa;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(i==1)
|
||||||
|
{
|
||||||
|
servob=j;
|
||||||
|
OCR3B = servob;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
platform/RaspBee/dev/servo.h
Normal file
44
platform/RaspBee/dev/servo.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007, 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 SERVO_H
|
||||||
|
#define SERVO_H
|
||||||
|
|
||||||
|
#define SERVO_MIN 575
|
||||||
|
#define SERVO_MAX 2425
|
||||||
|
#define SERVO_INIT 1500
|
||||||
|
|
||||||
|
void servo_init(void);
|
||||||
|
void servo_off(void);
|
||||||
|
|
||||||
|
unsigned int servo_get(unsigned int i);
|
||||||
|
unsigned int servo_set(unsigned i,unsigned int j);
|
||||||
|
|
||||||
|
#endif /* SHT11_H */
|
218
platform/RaspBee/dev/sg-ready.c
Normal file
218
platform/RaspBee/dev/sg-ready.c
Normal file
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Bernhard Trinnes
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* Smart Grid Ready Module - guhRF
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Bernhard Trinnes bernhard.trinnes@guh.guru
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sg-ready.h"
|
||||||
|
#define LATCH_TIME 3000 // time in micro seconds
|
||||||
|
|
||||||
|
#define RELAY1_ON (1<<DDRB4)
|
||||||
|
#define RELAY1_OFF (1<<DDRB5)
|
||||||
|
#define RELAY2_ON (1<<DDRB6)
|
||||||
|
#define RELAY2_OFF (1<<DDRB7)
|
||||||
|
#define RELAY1_FB (1<<DDRD5)
|
||||||
|
#define RELAY2_FB (1<<DDRD7)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup relay
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief init RELAY PINS - direction & pull-ups
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
releay_init()
|
||||||
|
{
|
||||||
|
/*2 latching dual coal relay
|
||||||
|
RELAY 1 Coil 1 PB4 - ON
|
||||||
|
Coil 2 PB5 - OFF
|
||||||
|
Feedback PD5
|
||||||
|
RELAY 2 Coil 1 PB6 - ON
|
||||||
|
Coil 2 PB7 - OFF
|
||||||
|
Feedback PD7
|
||||||
|
|
||||||
|
*/
|
||||||
|
DDRB |= (RELAY1_ON | RELAY1_OFF | RELAY2_ON | RELAY2_OFF);
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY1_OFF | RELAY2_ON | RELAY2_OFF);
|
||||||
|
|
||||||
|
DDRD &= ~(RELAY1_FB | RELAY2_FB);
|
||||||
|
PORTD |= (RELAY1_FB | RELAY2_FB);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* \brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
set_state(uint8_t state)
|
||||||
|
{
|
||||||
|
/* State 1 - Relays 1:0
|
||||||
|
State 2 - Relays 0:0
|
||||||
|
State 3 - Relays 0:1
|
||||||
|
State 4 - Relays 1:1
|
||||||
|
*/
|
||||||
|
uint8_t i = 0;
|
||||||
|
uint8_t current_state;
|
||||||
|
current_state = get_state();
|
||||||
|
while ( i<=3 || (current_state != state)){
|
||||||
|
i++;
|
||||||
|
switch_difference(current_state, state);
|
||||||
|
current_state = get_state();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* \brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t
|
||||||
|
get_state()
|
||||||
|
{
|
||||||
|
uint8_t state;
|
||||||
|
/* Pull up -> Pin high = Relay Open */
|
||||||
|
if ((~PIND & RELAY1_FB) && (~PIND & RELAY2_FB)){
|
||||||
|
state = 4;
|
||||||
|
}else if (~PIND & RELAY1_FB){
|
||||||
|
state = 1;
|
||||||
|
} else if (~PIND & RELAY2_FB){
|
||||||
|
state = 3;
|
||||||
|
} else {
|
||||||
|
state = 2;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* \brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
switch_difference(uint8_t old, uint8_t new)
|
||||||
|
{
|
||||||
|
switch(old) {
|
||||||
|
case 1:
|
||||||
|
switch(new) {
|
||||||
|
case 2:
|
||||||
|
PORTB |= RELAY1_OFF;
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY2_ON | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_OFF);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
PORTB |= (RELAY1_OFF | RELAY2_ON );
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_OFF | RELAY2_ON);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
PORTB |= RELAY2_ON;
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY1_OFF | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY2_ON);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
switch(new) {
|
||||||
|
case 1:
|
||||||
|
PORTB |= RELAY1_ON;
|
||||||
|
PORTB &= ~(RELAY1_OFF | RELAY2_ON | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_ON);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
PORTB |= (RELAY2_ON);
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY1_OFF | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY2_ON);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
PORTB |= (RELAY1_ON | RELAY2_ON);
|
||||||
|
PORTB &= ~(RELAY1_OFF | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY2_ON);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
switch(new) {
|
||||||
|
case 1:
|
||||||
|
PORTB |= (RELAY1_ON | RELAY2_OFF);
|
||||||
|
PORTB &= ~(RELAY1_OFF | RELAY2_ON);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY2_OFF);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
PORTB |= RELAY2_OFF;
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY1_OFF | RELAY2_ON);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY2_OFF);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
PORTB |= RELAY1_ON;
|
||||||
|
PORTB &= ~(RELAY1_OFF | RELAY2_ON | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_ON);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
switch(new) {
|
||||||
|
case 1:
|
||||||
|
PORTB |= RELAY2_OFF;
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY1_OFF | RELAY2_ON);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY2_OFF);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
PORTB |= (RELAY1_OFF | RELAY2_OFF);
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY2_ON );
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_OFF | RELAY2_OFF);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
PORTB |= RELAY1_OFF;
|
||||||
|
PORTB &= ~(RELAY1_ON | RELAY2_ON | RELAY2_OFF);
|
||||||
|
clock_delay_usec (LATCH_TIME);
|
||||||
|
PORTB &= ~(RELAY1_OFF);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
55
platform/RaspBee/dev/sg-ready.h
Normal file
55
platform/RaspBee/dev/sg-ready.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Bernhard Trinnes
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Bernhard Trinnes bernhard.trinnes@guh.guru
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SGREADY_H__
|
||||||
|
#define __SGREADY_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/** @name Smart Grid Ready Functions */
|
||||||
|
/** @{ */
|
||||||
|
void relay_init(uint8_t pin);
|
||||||
|
void set_state(uint8_t pin);
|
||||||
|
uint8_t get_state();
|
||||||
|
void switch_difference(uint8_t old, uint8_t new);
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif /* __SGREADY_H__ */
|
101
platform/RaspBee/dev/t4-servo-sensor.c
Normal file
101
platform/RaspBee/dev/t4-servo-sensor.c
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2013-2014 Marcus Priesch, All rights reserved
|
||||||
|
** In Prandnern 31, A--2122 Riedenthal, Austria. office@priesch.co.at
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
**++
|
||||||
|
** Name
|
||||||
|
** t4-servo-sensor
|
||||||
|
**
|
||||||
|
** Purpose
|
||||||
|
** Implements a sensor around t4servo.c
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Revision Dates
|
||||||
|
** 31-Mar-2013 (MPR) Creation
|
||||||
|
** 12-Mar-2014 (MPR) Factored to support configurable amount of pwm's
|
||||||
|
** ««revision-date»»···
|
||||||
|
**--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/t4-servo.h"
|
||||||
|
#include "dev/t4-servo-sensor.h"
|
||||||
|
|
||||||
|
const struct sensors_sensor t4_servo_sensor;
|
||||||
|
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
|
||||||
|
static int value (int channel)
|
||||||
|
{
|
||||||
|
if (channel >= SERVO_COUNT)
|
||||||
|
return -1;
|
||||||
|
else if (channel < 0)
|
||||||
|
return -2;
|
||||||
|
else
|
||||||
|
return t4_servo_get (channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int configure (int type, int c) // type, c: SENSORS_ACTIVE, 1 -> act.
|
||||||
|
// type, c: SENSORS_ACTIVE, 0 -> deact.
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SENSORS_ACTIVE :
|
||||||
|
if (c == 0)
|
||||||
|
{
|
||||||
|
t4_servo_off ();
|
||||||
|
}
|
||||||
|
else if (c == 1)
|
||||||
|
{
|
||||||
|
t4_servo_init ();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
if (type >= SERVO_COUNT)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
t4_servo_set (type, c);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int status(int type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SENSORS_SENSOR(t4_servo_sensor, T4_SENSOR_NAME, value, configure, status);
|
52
platform/RaspBee/dev/t4-servo-sensor.h
Normal file
52
platform/RaspBee/dev/t4-servo-sensor.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2013-2014 Marcus Priesch, All rights reserved
|
||||||
|
** In Prandnern 31, A--2122 Riedenthal, Austria. office@priesch.co.at
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
**++
|
||||||
|
** Name
|
||||||
|
** t4-servo-sensor
|
||||||
|
**
|
||||||
|
** Purpose
|
||||||
|
** Implements a sensor around t4servo.c
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Revision Dates
|
||||||
|
** 31-Mar-2013 (MPR) Creation
|
||||||
|
** 12-Mar-2014 (MPR) Factored to support configurable amount of pwm's
|
||||||
|
««revision-date»»···
|
||||||
|
**--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __T4_SERVO_SENSOR_H__
|
||||||
|
#define __T4_SERVO_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "t4-servo-config.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor t4_servo_sensor;
|
||||||
|
|
||||||
|
#endif /* __T4_SERVO_SENSOR_H__ */
|
139
platform/RaspBee/dev/t4-servo.c
Normal file
139
platform/RaspBee/dev/t4-servo.c
Normal file
|
@ -0,0 +1,139 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2013-2014 Marcus Priesch, All rights reserved
|
||||||
|
** In Prandnern 31, A--2122 Riedenthal, Austria. office@priesch.co.at
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
**++
|
||||||
|
** Name
|
||||||
|
** t4-servo
|
||||||
|
**
|
||||||
|
** Purpose
|
||||||
|
** Implements software pwm on any portpins via timer 4
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Revision Dates
|
||||||
|
** 31-Mar-2013 (MPR) Creation
|
||||||
|
** 12-Mar-2014 (MPR) Factored to support configurable amount of pwm's
|
||||||
|
** ««revision-date»»···
|
||||||
|
**--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "t4-servo.h"
|
||||||
|
#include "t4-servo-config.h"
|
||||||
|
#include "t4-servo-hardware.h"
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
// static servo_channel_type servo_channels [SERVO_COUNT];
|
||||||
|
|
||||||
|
// timer 4: CTC OCR4A
|
||||||
|
#define WGM4 0x4
|
||||||
|
|
||||||
|
void t4_servo_init (void)
|
||||||
|
{
|
||||||
|
unsigned char channel;
|
||||||
|
|
||||||
|
for (channel = 0; channel < SERVO_COUNT; channel ++)
|
||||||
|
{
|
||||||
|
_SFR_IO8 (servo_channels [channel].ddr ) |= servo_channels [channel].pin;
|
||||||
|
_SFR_IO8 (servo_channels [channel].port) &= ~(servo_channels [channel].pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
cli ();
|
||||||
|
TCCR4A = 0x00;
|
||||||
|
TCCR4A_struct.wgm4 = WGM4 & 0x3;
|
||||||
|
TCCR4B_struct.wgm4 = (WGM4 & 0xc) >> 2;
|
||||||
|
TCCR4B_struct.cs4 = 0x1; // No prescaler
|
||||||
|
TCCR4C = 0x00;
|
||||||
|
OCR4A = (T4_VALUE);
|
||||||
|
TIMSK4_struct.ocie4a = 1;
|
||||||
|
TIMSK4_struct.toie4 = 1;
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
|
||||||
|
void t4_servo_off (void)
|
||||||
|
{
|
||||||
|
TIMSK4_struct.toie4 = 0;
|
||||||
|
TIMSK4_struct.ocie4a = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int t4_servo_get (unsigned int channel)
|
||||||
|
{
|
||||||
|
if (channel >= SERVO_COUNT)
|
||||||
|
return -1;
|
||||||
|
//printf ("t4_servo_get: %d, %d\n", channel, servo_channels [channel].duty);
|
||||||
|
return servo_channels [channel].duty;
|
||||||
|
}
|
||||||
|
|
||||||
|
int t4_servo_set (unsigned int channel, unsigned char duty)
|
||||||
|
{
|
||||||
|
//printf ("t4_servo_set: %d, %d\n", channel, duty);
|
||||||
|
|
||||||
|
if (channel >= SERVO_COUNT)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (duty > SERVO_MAX)
|
||||||
|
return -2;
|
||||||
|
|
||||||
|
if (duty < SERVO_MIN)
|
||||||
|
return -3;
|
||||||
|
|
||||||
|
servo_channels [channel].duty = duty;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR (TIMER4_COMPA_vect, ISR_NOBLOCK)
|
||||||
|
{
|
||||||
|
unsigned char channel;
|
||||||
|
static unsigned int tick_count = 0;
|
||||||
|
|
||||||
|
cli ();
|
||||||
|
for (channel = 0; channel < SERVO_COUNT; channel ++)
|
||||||
|
{
|
||||||
|
if (tick_count < servo_channels [channel].duty)
|
||||||
|
{
|
||||||
|
// turn on
|
||||||
|
// _SFR_IO8 (servo_channels [channel].ddr ) |= servo_channels [channel].pin;
|
||||||
|
_SFR_IO8 (servo_channels [channel].port) |= servo_channels [channel].pin;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// turn off
|
||||||
|
_SFR_IO8 (servo_channels [channel].port) &= ~(servo_channels [channel].pin);
|
||||||
|
// _SFR_IO8 (servo_channels [channel].ddr ) |= servo_channels [channel].pin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tick_count ++;
|
||||||
|
|
||||||
|
if (tick_count >= (SERVO_MAX + SERVO_OFFSET))
|
||||||
|
{
|
||||||
|
tick_count = 0;
|
||||||
|
}
|
||||||
|
sei();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
61
platform/RaspBee/dev/t4-servo.h
Normal file
61
platform/RaspBee/dev/t4-servo.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
** Copyright (C) 2013-2014 Marcus Priesch, All rights reserved
|
||||||
|
** In Prandnern 31, A--2122 Riedenthal, Austria. office@priesch.co.at
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
**++
|
||||||
|
** Name
|
||||||
|
** t4-servo
|
||||||
|
**
|
||||||
|
** Purpose
|
||||||
|
** Implements software pwm on any portpins via timer 4
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Revision Dates
|
||||||
|
** 31-Mar-2013 (MPR) Creation
|
||||||
|
** 12-Mar-2014 (MPR) Factored to support configurable amount of pwm's
|
||||||
|
««revision-date»»···
|
||||||
|
**--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __T4_SERVO_H__
|
||||||
|
#define __T4_SERVO_H__
|
||||||
|
|
||||||
|
typedef struct struct_servo_channel
|
||||||
|
{
|
||||||
|
unsigned char port;
|
||||||
|
unsigned char ddr;
|
||||||
|
unsigned char pin;
|
||||||
|
unsigned char duty;
|
||||||
|
} servo_channel_type;
|
||||||
|
|
||||||
|
void t4_servo_init(void);
|
||||||
|
void t4_servo_off(void);
|
||||||
|
|
||||||
|
int t4_servo_get(unsigned int channel);
|
||||||
|
int t4_servo_set(unsigned int channel, unsigned char duty);
|
||||||
|
|
||||||
|
#endif /* __T4_SERVO_H__ */
|
66
platform/RaspBee/dev/temperature-sensor.c
Normal file
66
platform/RaspBee/dev/temperature-sensor.c
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: temperature-sensor.c,v 1.1 2010/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Temperature sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/temperature-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
const struct sensors_sensor temperature_sensor;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return readInternalTemp();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR, value, configure, status);
|
49
platform/RaspBee/dev/temperature-sensor.h
Normal file
49
platform/RaspBee/dev/temperature-sensor.h
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: temperature-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Temperature sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TEMPERATURE_SENSOR_H__
|
||||||
|
#define __TEMPERATURE_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/adc.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor temperature_sensor;
|
||||||
|
|
||||||
|
#define TEMPERATURE_SENSOR "Temperature"
|
||||||
|
|
||||||
|
#endif /* __TEMPERATURE_SENSOR_H__ */
|
104
platform/RaspBee/dev/wiring_digital.c
Normal file
104
platform/RaspBee/dev/wiring_digital.c
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
wiring_digital.c - digital input and output functions
|
||||||
|
Part of Arduino - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2005-2006 David A. Mellis
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General
|
||||||
|
Public License along with this library; if not, write to the
|
||||||
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Modified 28 September 2010 by Mark Sproul
|
||||||
|
|
||||||
|
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ARDUINO_MAIN
|
||||||
|
#include "wiring_private.h"
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
void pinMode(uint8_t pin, uint8_t mode)
|
||||||
|
{
|
||||||
|
uint8_t bit = digitalPinToBitMask(pin);
|
||||||
|
uint8_t port = digitalPinToPort(pin);
|
||||||
|
volatile uint8_t *reg, *out;
|
||||||
|
|
||||||
|
if (port == NOT_A_PIN) return;
|
||||||
|
|
||||||
|
// JWS: can I let the optimizer do this?
|
||||||
|
reg = portModeRegister(port);
|
||||||
|
out = portOutputRegister(port);
|
||||||
|
|
||||||
|
if (mode == INPUT) {
|
||||||
|
uint8_t oldSREG = SREG;
|
||||||
|
cli();
|
||||||
|
*reg &= ~bit;
|
||||||
|
*out &= ~bit;
|
||||||
|
SREG = oldSREG;
|
||||||
|
} else if (mode == INPUT_PULLUP) {
|
||||||
|
uint8_t oldSREG = SREG;
|
||||||
|
cli();
|
||||||
|
*reg &= ~bit;
|
||||||
|
*out |= bit;
|
||||||
|
SREG = oldSREG;
|
||||||
|
} else {
|
||||||
|
uint8_t oldSREG = SREG;
|
||||||
|
cli();
|
||||||
|
*reg |= bit;
|
||||||
|
SREG = oldSREG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void digitalWrite(uint8_t pin, uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t timer = digitalPinToTimer(pin);
|
||||||
|
uint8_t bit = digitalPinToBitMask(pin);
|
||||||
|
uint8_t port = digitalPinToPort(pin);
|
||||||
|
volatile uint8_t *out;
|
||||||
|
|
||||||
|
if (port == NOT_A_PIN) return;
|
||||||
|
|
||||||
|
// If the pin that support PWM output, we need to turn it off
|
||||||
|
// before doing a digital write.
|
||||||
|
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
|
||||||
|
|
||||||
|
out = portOutputRegister(port);
|
||||||
|
|
||||||
|
uint8_t oldSREG = SREG;
|
||||||
|
cli();
|
||||||
|
|
||||||
|
if (val == LOW) {
|
||||||
|
*out &= ~bit;
|
||||||
|
} else {
|
||||||
|
*out |= bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
SREG = oldSREG;
|
||||||
|
}
|
||||||
|
|
||||||
|
int digitalRead(uint8_t pin)
|
||||||
|
{
|
||||||
|
uint8_t timer = digitalPinToTimer(pin);
|
||||||
|
uint8_t bit = digitalPinToBitMask(pin);
|
||||||
|
uint8_t port = digitalPinToPort(pin);
|
||||||
|
|
||||||
|
if (port == NOT_A_PIN) return LOW;
|
||||||
|
|
||||||
|
// If the pin that support PWM output, we need to turn it off
|
||||||
|
// before getting a digital reading.
|
||||||
|
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
|
||||||
|
|
||||||
|
if (*portInputRegister(port) & bit) return HIGH;
|
||||||
|
return LOW;
|
||||||
|
}
|
69
platform/RaspBee/dev/wiring_private.h
Normal file
69
platform/RaspBee/dev/wiring_private.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
wiring_private.h - Internal header file.
|
||||||
|
Part of Arduino - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2005-2006 David A. Mellis
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General
|
||||||
|
Public License along with this library; if not, write to the
|
||||||
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
$Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WiringPrivate_h
|
||||||
|
#define WiringPrivate_h
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef cbi
|
||||||
|
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||||
|
#endif
|
||||||
|
#ifndef sbi
|
||||||
|
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define EXTERNAL_INT_0 0
|
||||||
|
#define EXTERNAL_INT_1 1
|
||||||
|
#define EXTERNAL_INT_2 2
|
||||||
|
#define EXTERNAL_INT_3 3
|
||||||
|
#define EXTERNAL_INT_4 4
|
||||||
|
#define EXTERNAL_INT_5 5
|
||||||
|
#define EXTERNAL_INT_6 6
|
||||||
|
#define EXTERNAL_INT_7 7
|
||||||
|
|
||||||
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
|
#define EXTERNAL_NUM_INTERRUPTS 8
|
||||||
|
#elif defined(__AVR_ATmega128RFA1__) || (__AVR_ATmega256RFR2__)
|
||||||
|
#define EXTERNAL_NUM_INTERRUPTS 8
|
||||||
|
#else
|
||||||
|
#define EXTERNAL_NUM_INTERRUPTS 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void (*voidFuncPtr)(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
79
platform/RaspBee/node-id.c
Normal file
79
platform/RaspBee/node-id.c
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* $Id: node-id.c,v 1.1 2007/03/23 09:59:08 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Utility to store a node id in the external flash
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "node-id.h"
|
||||||
|
#include "contiki-conf.h"
|
||||||
|
#include "dev/xmem.h"
|
||||||
|
|
||||||
|
unsigned short node_id = 0;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
node_id_restore(void)
|
||||||
|
{
|
||||||
|
/* todo */
|
||||||
|
/*
|
||||||
|
unsigned char buf[4];
|
||||||
|
xmem_pread(buf, 4, NODE_ID_XMEM_OFFSET);
|
||||||
|
if(buf[0] == 0xad &&
|
||||||
|
buf[1] == 0xde) {
|
||||||
|
node_id = (buf[2] << 8) | buf[3];
|
||||||
|
} else {
|
||||||
|
node_id = 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
node_id = 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
node_id_burn(unsigned short id)
|
||||||
|
{
|
||||||
|
/* todo */
|
||||||
|
/*
|
||||||
|
unsigned char buf[4];
|
||||||
|
buf[0] = 0xad;
|
||||||
|
buf[1] = 0xde;
|
||||||
|
buf[2] = id >> 8;
|
||||||
|
buf[3] = id & 0xff;
|
||||||
|
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
|
||||||
|
xmem_pwrite(buf, 4, NODE_ID_XMEM_OFFSET);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
44
platform/RaspBee/node-id.h
Normal file
44
platform/RaspBee/node-id.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* Author: Adam Dunkels <adam@sics.se>
|
||||||
|
*
|
||||||
|
* $Id: node-id.h,v 1.1 2007/03/23 09:59:08 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NODE_ID_H__
|
||||||
|
#define __NODE_ID_H__
|
||||||
|
|
||||||
|
void node_id_restore(void);
|
||||||
|
void node_id_burn(unsigned short node_id);
|
||||||
|
|
||||||
|
extern unsigned short node_id;
|
||||||
|
|
||||||
|
#endif /* __NODE_ID_H__ */
|
273
platform/RaspBee/params.c
Normal file
273
platform/RaspBee/params.c
Normal file
|
@ -0,0 +1,273 @@
|
||||||
|
/*
|
||||||
|
* 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 WITH_NODE_ID
|
||||||
|
uint16_t node_id;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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. */
|
||||||
|
|
||||||
|
extern uint8_t bootloader_get_mac(uint8_t);
|
||||||
|
|
||||||
|
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;
|
||||||
|
#if BOOTLOADER_GET_MAC
|
||||||
|
for (i=0;i<sizeof(default_mac_address);i++){
|
||||||
|
eui64[i] = bootloader_get_mac(i);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
for (i=0;i<sizeof(default_mac_address);i++) eui64[i] = pgm_read_byte_near(default_mac_address+i);
|
||||||
|
#endif
|
||||||
|
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 = {CHANNEL_802_15_4, ~CHANNEL_802_15_4};
|
||||||
|
uint16_t eemem_panid EEMEM = IEEE802154_CONF_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 , IEEE802154_CONF_PANID);
|
||||||
|
eeprom_write_word(&eemem_panaddr, PARAMS_PANADDR);
|
||||||
|
eeprom_write_byte(&eemem_txpower, PARAMS_TXPOWER);
|
||||||
|
eeprom_write_word(&eemem_nodeid, PARAMS_NODEID);
|
||||||
|
x[0] = CHANNEL_802_15_4;
|
||||||
|
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 = CHANNEL_802_15_4;
|
||||||
|
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=IEEE802154_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 */
|
105
platform/RaspBee/params.h
Normal file
105
platform/RaspBee/params.h
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
#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.
|
||||||
|
*/
|
||||||
|
// default settings
|
||||||
|
#define CHANNEL_802_15_4 26 // default frequency (11-26)
|
||||||
|
|
||||||
|
// end default settings
|
||||||
|
|
||||||
|
#define CONTIKI_CONF_RANDOM_MAC 1 //adds 78 bytes
|
||||||
|
#define CONTIKI_CONF_SETTINGS_MANAGER 0 //adds 1696 bytes
|
||||||
|
#define BOOTLOADER_GET_MAC 0 // get mac form boolaoder, need bootlaoder bonsai, PARAMETER_STORAGE 0
|
||||||
|
|
||||||
|
#if CONTIKI_CONF_SETTINGS_MANAGER
|
||||||
|
//#define PARAMETER_STORAGE 2
|
||||||
|
#define PARAMETER_STORAGE 2
|
||||||
|
#else
|
||||||
|
//#define PARAMETER_STORAGE 1
|
||||||
|
#define PARAMETER_STORAGE 1 // get mac form boolaoder, need bootlaoder bonsai, PARAMETER_STORAGE 0
|
||||||
|
#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 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 {0x00, 0x21, 0x2e, 0xff, 0xff, 0x00, 0x1E, 0xFB}
|
||||||
|
#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, 0x03}
|
||||||
|
#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(...) CHANNEL_802_15_4
|
||||||
|
#define params_get_panid(...) IEEE802154_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_ */
|
93
platform/RaspBee/slip_uart0.c
Normal file
93
platform/RaspBee/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);
|
||||||
|
}
|
||||||
|
*/
|
95
platform/guhRF/Makefile.guhRF
Normal file
95
platform/guhRF/Makefile.guhRF
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
CONTIKI_TARGET_DIRS = . dev apps net loader
|
||||||
|
|
||||||
|
CONTIKI_CORE=contiki-main
|
||||||
|
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += contiki-main.c params.c node-id.c
|
||||||
|
|
||||||
|
#Needed for slip
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += led.c sensors.c slip_uart0.c slip.c leds-arch.c
|
||||||
|
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += temperature-sensor.c adc.c
|
||||||
|
#Needed for Button
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += button-sensor.c
|
||||||
|
|
||||||
|
# i2c Master
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += i2c.c
|
||||||
|
#Needed for DHT11 humidity sensor
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += dht11.c
|
||||||
|
#Needed for DS18S20 temperature sensor
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += ds1820.c
|
||||||
|
|
||||||
|
#Needed for Battery test
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += battery-sensor.c batmon.c
|
||||||
|
|
||||||
|
#Needed for PIR
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += pir-sensor.c
|
||||||
|
#Needed for OPTRIAC
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += optriac-sensor.c
|
||||||
|
|
||||||
|
CONTIKIAVR=$(CONTIKI)/cpu/avr
|
||||||
|
|
||||||
|
#Needed for SERVO
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += servo.c servo-sensor.c
|
||||||
|
#Needed for Timer4 Servo
|
||||||
|
##CONTIKI_TARGET_SOURCEFILES += t4-servo.c t4-servo-sensor.c
|
||||||
|
#Needed for Relay 1 to 4
|
||||||
|
#CONTIKI_TARGET_SOURCEFILES += relay.c relay-sensor.c
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# guh Source Files
|
||||||
|
|
||||||
|
|
||||||
|
# Smart Grid Ready Interface
|
||||||
|
CONTIKI_TARGET_SOURCEFILES += sg-ready.c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
CONTIKIBOARD=.
|
||||||
|
#BOOTLOADER_START = 0x1F000
|
||||||
|
BOOTLOADER_START = 0x3E000
|
||||||
|
CONTIKI_PLAT_DEFS = -DF_CPU=16000000UL -DAUTO_CRC_PADDING=2 -DPLAT_TIMER=5
|
||||||
|
|
||||||
|
MCU=atmega256rfr2
|
||||||
|
|
||||||
|
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 atmega256:
|
||||||
|
# avrdude -v -P usb:xxxx -c jtag2 -p atmega256
|
||||||
|
AVRDUDE_PORT=usb:00B000000D79
|
||||||
|
|
||||||
|
|
||||||
|
# Additional avrdude options
|
||||||
|
# Verify off
|
||||||
|
AVRDUDE_OPTIONS=-V
|
||||||
|
AVRDUDE_MCU=m256rfr2
|
||||||
|
|
||||||
|
#debug
|
||||||
|
# CFLAGS += -save-temps
|
||||||
|
# Bootloader bonsai
|
||||||
|
# LDFLAGS += -save-temps
|
||||||
|
# For the old bonsai bootloader compiled with squeeze gcc-avr we
|
||||||
|
# directly used the address of the bootloader:
|
||||||
|
#BOOTLOADER_GET_MAC=0x0001f3a0
|
||||||
|
# For newer bonsai we have a jump table at the end of the bootloader
|
||||||
|
# section:
|
||||||
|
#BOOTLOADER_GET_MAC=0x0001ff80
|
||||||
|
#guhRF Bootloader MAC Address
|
||||||
|
BOOTLOADER_GET_MAC=0x0003ff80
|
||||||
|
|
||||||
|
LDFLAGS += -Wl,--defsym,bootloader_get_mac=$(BOOTLOADER_GET_MAC)
|
||||||
|
|
||||||
|
|
||||||
|
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/ipv6 core/net/ipv4 core/net/ip \
|
||||||
|
# core/net/rime \
|
||||||
|
# core/net/rpl \
|
315
platform/guhRF/contiki-conf.h
Normal file
315
platform/guhRF/contiki-conf.h
Normal file
|
@ -0,0 +1,315 @@
|
||||||
|
/*
|
||||||
|
* 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 Atmel ATMEGA256RFR2
|
||||||
|
* \author
|
||||||
|
* David Kopf <dak664@embarqmail.com>
|
||||||
|
Bernhard Trinnes <bernhard.trinnes@guh.guru>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONTIKI_CONF_H_
|
||||||
|
#define CONTIKI_CONF_H_
|
||||||
|
|
||||||
|
/* Platform name, type, and MCU clock rate */
|
||||||
|
#define PLATFORM_NAME "guhRF"
|
||||||
|
#define PLATFORM_TYPE ATMEGA256RFR2
|
||||||
|
#ifndef F_CPU
|
||||||
|
#define F_CPU 16000000UL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define IEEE802154_CONF_PANID 0xABCD // default panid
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
#if 1
|
||||||
|
/* 16 bit counter overflows every ~10 minutes */
|
||||||
|
typedef unsigned short clock_time_t;
|
||||||
|
#define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
|
||||||
|
#define INFINITE_TIME 0xffff
|
||||||
|
#define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
|
||||||
|
#define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
|
||||||
|
#else
|
||||||
|
typedef unsigned long clock_time_t;
|
||||||
|
#define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
|
||||||
|
#define INFINITE_TIME 0xffffffff
|
||||||
|
#endif
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
|
||||||
|
/* and theoretically can use TIMER2 with it to keep time. Else TIMER0 is used. */
|
||||||
|
/* The sleep timer requires the crystal and adds a TIMER2 interrupt routine if not already define by clock.c */
|
||||||
|
#define AVR_CONF_USE32KCRYSTAL 0
|
||||||
|
|
||||||
|
|
||||||
|
/* COM port to be used for SLIP connection. This is usually UART0, but see above */
|
||||||
|
#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 1
|
||||||
|
|
||||||
|
/* 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 ATMEGA256RFR2 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
|
||||||
|
#define UIP_CONF_TCP 1
|
||||||
|
#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 1 /* No radio cycling */
|
||||||
|
#if 0 /* radio cycling */
|
||||||
|
|
||||||
|
#define NETSTACK_CONF_MAC nullmac_driver
|
||||||
|
#define NETSTACK_CONF_RDC sicslowmac_driver
|
||||||
|
#define NETSTACK_CONF_FRAMER framer_802154
|
||||||
|
#define NETSTACK_CONF_RADIO rf230_driver
|
||||||
|
/* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */
|
||||||
|
#define RF230_CONF_AUTOACK 1
|
||||||
|
/* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */
|
||||||
|
#define SICSLOWPAN_CONF_ACK_ALL 0
|
||||||
|
/* 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
|
||||||
|
/* 211 bytes per queue buffer */
|
||||||
|
#define QUEUEBUF_CONF_NUM 8
|
||||||
|
/* 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 */
|
||||||
|
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8
|
||||||
|
/* 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
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
#define NETSTACK_CONF_FRAMER framer_802154
|
||||||
|
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||||
|
#define NETSTACK_CONF_FRAMER contikimac_framer
|
||||||
|
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||||
|
|
||||||
|
#define NETSTACK_CONF_RADIO rf230_driver
|
||||||
|
/* The radio needs to interrupt during an rtimer interrupt */
|
||||||
|
#define RTIMER_CONF_NESTED_INTERRUPTS 1
|
||||||
|
#define RF230_CONF_AUTOACK 1
|
||||||
|
/* 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
|
||||||
|
/* 211 bytes per queue buffer. Contikimac burst mode needs 15 for a 1280 byte MTU */
|
||||||
|
#define QUEUEBUF_CONF_NUM 15
|
||||||
|
/* 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
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error Network configuration not specified!
|
||||||
|
#endif /* Network setup */
|
||||||
|
|
||||||
|
/* ************************************************************************** */
|
||||||
|
//#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_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
|
||||||
|
|
||||||
|
/* include the project config */
|
||||||
|
/* PROJECT_CONF_H might be defined in the project Makefile */
|
||||||
|
#ifdef PROJECT_CONF_H
|
||||||
|
#include PROJECT_CONF_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONTIKI_CONF_H_ */
|
595
platform/guhRF/contiki-main.c
Normal file
595
platform/guhRF/contiki-main.c
Normal file
|
@ -0,0 +1,595 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#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 <avr/io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dev/watchdog.h>
|
||||||
|
|
||||||
|
#include "loader/symbols-def.h"
|
||||||
|
#include "loader/symtab.h"
|
||||||
|
|
||||||
|
#include "params.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 ledtimer;
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/*----------------------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 = 0x02,//SIGNATURE_2, //ATMEGA256rfr2
|
||||||
|
.B1 = 0xA8,//SIGNATURE_1, //256KB flash
|
||||||
|
.B0 = 0x1E,//SIGNATURE_0, //Atmel
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
/* JTAG+SPI enabled, External osc 1kck4ms1 , Boot 4096 words @ $1F000, TXC1K+4,1msec delay, Brownout 1.9 volts */
|
||||||
|
FUSES ={.low = 0xF6, .high = 0x98, .extended = 0xfe,};
|
||||||
|
#define BOOTLOADER_START = 0x3E000
|
||||||
|
#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
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/button-sensor.h"
|
||||||
|
#include "dev/battery-sensor.h"
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clock_delay(unsigned int howlong)
|
||||||
|
{
|
||||||
|
if(howlong<2) return;
|
||||||
|
clock_delay_usec((45*howlong)>>4);
|
||||||
|
}
|
||||||
|
/*-------------------------Low level initialization------------------------*/
|
||||||
|
/*------Done in a subroutine to keep main routine stack usage small--------*/
|
||||||
|
void initialize(void)
|
||||||
|
{
|
||||||
|
watchdog_init();
|
||||||
|
watchdog_start();
|
||||||
|
|
||||||
|
/* Generic or slip connection on uart0 */
|
||||||
|
rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||||
|
|
||||||
|
|
||||||
|
/* Second rs232 port for debugging or slip alternative */
|
||||||
|
// rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||||
|
|
||||||
|
/* Redirect stdout */
|
||||||
|
rs232_redirect_stdout(RS232_PORT_0);
|
||||||
|
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
if (params_get_eui64(addr.u8)) {
|
||||||
|
PRINTA("Random EUI64 address generated\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
memcpy(&uip_lladdr.addr, &addr.u8, sizeof(linkaddr_t));
|
||||||
|
#elif WITH_NODE_ID
|
||||||
|
node_id=get_panaddr_from_eeprom();
|
||||||
|
addr.u8[1]=node_id&0xff;
|
||||||
|
addr.u8[0]=(node_id&0xff00)>>8;
|
||||||
|
PRINTA("Node ID from eeprom: %X\n",node_id);
|
||||||
|
#endif
|
||||||
|
linkaddr_set_node_addr(&addr);
|
||||||
|
|
||||||
|
PRINTA("Panid:%x\n", params_get_panid());
|
||||||
|
// framer_802154_set_panid(params_get_panid());
|
||||||
|
rf230_set_pan_addr(params_get_panid(),params_get_panaddr(),(uint8_t *)&addr.u8);
|
||||||
|
rf230_set_channel(params_get_channel());
|
||||||
|
rf230_set_txpower(params_get_txpower());
|
||||||
|
|
||||||
|
#if NETSTACK_CONF_WITH_IPV6
|
||||||
|
PRINTA("EUI-64 MAC: %x-%x-%x-%x-%x-%x-%x-%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
|
||||||
|
#else
|
||||||
|
PRINTA("MAC address ");
|
||||||
|
uint8_t i;
|
||||||
|
for (i=sizeof(linkaddr_t); i>0; i--){
|
||||||
|
PRINTA("%x:",addr.u8[i-1]);
|
||||||
|
}
|
||||||
|
PRINTA("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initialize stack protocols */
|
||||||
|
queuebuf_init();
|
||||||
|
NETSTACK_RDC.init();
|
||||||
|
NETSTACK_MAC.init();
|
||||||
|
NETSTACK_NETWORK.init();
|
||||||
|
|
||||||
|
#if ANNOUNCE_BOOT
|
||||||
|
PRINTA("%s %s, channel %u , check rate %u Hz tx power %u\n",NETSTACK_MAC.name, NETSTACK_RDC.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
|
||||||
|
|
||||||
|
process_start(&sensors_process, NULL);
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#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();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Turn off LED after a while */
|
||||||
|
if (ledtimer) {
|
||||||
|
if (--ledtimer==0) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#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=0;
|
||||||
|
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);
|
||||||
|
|
||||||
|
for(nbr = nbr_table_head(ds6_neighbors);
|
||||||
|
nbr != NULL;
|
||||||
|
nbr = nbr_table_next(ds6_neighbors, nbr)) {
|
||||||
|
ipaddr_add(&nbr->ipaddr);
|
||||||
|
PRINTF("\n");
|
||||||
|
j=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j) PRINTF(" <none>");
|
||||||
|
PRINTF("\nRoutes [%u max]\n",UIP_DS6_ROUTE_NB);
|
||||||
|
{
|
||||||
|
uip_ds6_route_t *r;
|
||||||
|
j = 1;
|
||||||
|
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 = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
172
platform/guhRF/dev/Arduino.h
Normal file
172
platform/guhRF/dev/Arduino.h
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
#ifndef Arduino_h
|
||||||
|
#define Arduino_h
|
||||||
|
|
||||||
|
#include <hw-arduino.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
#include "binary.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HIGH 0x1
|
||||||
|
#define LOW 0x0
|
||||||
|
|
||||||
|
#define INPUT 0x0
|
||||||
|
#define OUTPUT 0x1
|
||||||
|
#define INPUT_PULLUP 0x2
|
||||||
|
|
||||||
|
#define true 0x1
|
||||||
|
#define false 0x0
|
||||||
|
|
||||||
|
#define PI 3.1415926535897932384626433832795
|
||||||
|
#define HALF_PI 1.5707963267948966192313216916398
|
||||||
|
#define TWO_PI 6.283185307179586476925286766559
|
||||||
|
#define DEG_TO_RAD 0.017453292519943295769236907684886
|
||||||
|
#define RAD_TO_DEG 57.295779513082320876798154814105
|
||||||
|
|
||||||
|
#define SERIAL 0x0
|
||||||
|
#define DISPLAY 0x1
|
||||||
|
|
||||||
|
#define LSBFIRST 0
|
||||||
|
#define MSBFIRST 1
|
||||||
|
|
||||||
|
#define CHANGE 1
|
||||||
|
#define FALLING 2
|
||||||
|
#define RISING 3
|
||||||
|
|
||||||
|
#define DEFAULT ADC_DEFAULT
|
||||||
|
#define EXTERNAL ADC_EXTERNAL
|
||||||
|
|
||||||
|
// undefine stdlib's abs if encountered
|
||||||
|
#ifdef abs
|
||||||
|
#undef abs
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
#define max(a,b) ((a)>(b)?(a):(b))
|
||||||
|
#define abs(x) ((x)>0?(x):-(x))
|
||||||
|
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||||
|
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||||
|
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||||
|
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||||
|
#define sq(x) ((x)*(x))
|
||||||
|
|
||||||
|
#define interrupts() sei()
|
||||||
|
#define noInterrupts() cli()
|
||||||
|
|
||||||
|
#define lowByte(w) ((uint8_t) ((w) & 0xff))
|
||||||
|
#define highByte(w) ((uint8_t) ((w) >> 8))
|
||||||
|
|
||||||
|
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||||
|
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||||
|
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||||
|
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
|
||||||
|
|
||||||
|
|
||||||
|
typedef unsigned int word;
|
||||||
|
|
||||||
|
#define bit(b) (1UL << (b))
|
||||||
|
|
||||||
|
typedef uint8_t boolean;
|
||||||
|
typedef uint8_t byte;
|
||||||
|
|
||||||
|
void pinMode(uint8_t, uint8_t);
|
||||||
|
void digitalWrite(uint8_t, uint8_t);
|
||||||
|
int digitalRead(uint8_t);
|
||||||
|
|
||||||
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
|
||||||
|
|
||||||
|
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
||||||
|
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
|
||||||
|
|
||||||
|
void attachInterrupt(uint8_t, void (*)(void), int mode);
|
||||||
|
void detachInterrupt(uint8_t);
|
||||||
|
|
||||||
|
void setup(void);
|
||||||
|
void loop(void);
|
||||||
|
|
||||||
|
// Get the bit location within the hardware port of the given virtual pin.
|
||||||
|
// This comes from the pins_*.c file for the active board configuration.
|
||||||
|
|
||||||
|
#define analogInPinToBit(P) (P)
|
||||||
|
|
||||||
|
// On the ATmega1280, the addresses of some of the port registers are
|
||||||
|
// greater than 255, so we can't store them in uint8_t's.
|
||||||
|
extern const uint16_t PROGMEM port_to_mode_PGM[];
|
||||||
|
extern const uint16_t PROGMEM port_to_input_PGM[];
|
||||||
|
extern const uint16_t PROGMEM port_to_output_PGM[];
|
||||||
|
|
||||||
|
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
|
||||||
|
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
|
||||||
|
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
|
||||||
|
|
||||||
|
// Get the bit location within the hardware port of the given virtual pin.
|
||||||
|
// This comes from the pins_*.c file for the active board configuration.
|
||||||
|
//
|
||||||
|
// These perform slightly better as macros compared to inline functions
|
||||||
|
//
|
||||||
|
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
|
||||||
|
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
|
||||||
|
#define analogInPinToBit(P) (P)
|
||||||
|
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
|
||||||
|
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
|
||||||
|
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
|
||||||
|
|
||||||
|
#define NOT_A_PIN 0
|
||||||
|
#define NOT_A_PORT 0
|
||||||
|
|
||||||
|
#ifdef ARDUINO_MAIN
|
||||||
|
#define PA 1
|
||||||
|
#define PB 2
|
||||||
|
#define PC 3
|
||||||
|
#define PD 4
|
||||||
|
#define PE 5
|
||||||
|
#define PF 6
|
||||||
|
#define PG 7
|
||||||
|
#define PH 8
|
||||||
|
#define PJ 10
|
||||||
|
#define PK 11
|
||||||
|
#define PL 12
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
// look at this again when considering implementing serial
|
||||||
|
//#include "WCharacter.h"
|
||||||
|
//#include "WString.h"
|
||||||
|
//#include "HardwareSerial.h"
|
||||||
|
|
||||||
|
uint16_t makeWord(uint16_t w);
|
||||||
|
uint16_t makeWord(byte h, byte l);
|
||||||
|
|
||||||
|
#define word(...) makeWord(__VA_ARGS__)
|
||||||
|
|
||||||
|
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||||
|
|
||||||
|
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
||||||
|
void noTone(uint8_t _pin);
|
||||||
|
|
||||||
|
// WMath prototypes
|
||||||
|
long random(long);
|
||||||
|
long random(long, long);
|
||||||
|
void randomSeed(unsigned int);
|
||||||
|
long map(long, long, long, long, long);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
#include "dev/arduino/arduino-compat.h"
|
||||||
|
|
||||||
|
#endif
|
84
platform/guhRF/dev/adc.c
Normal file
84
platform/guhRF/dev/adc.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: adc.c,v 1.1 2010/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* ADC file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adc.h"
|
||||||
|
|
||||||
|
static uint8_t analog_reference = ADC_DEFAULT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For arduino interface for setting external reference voltage
|
||||||
|
* Note that applying an external voltage *and* then setting the analog
|
||||||
|
* reference to something internal will short the internal and the
|
||||||
|
* external reference voltage and most likely destroy the processor.
|
||||||
|
*/
|
||||||
|
void analogReference(uint8_t mode)
|
||||||
|
{
|
||||||
|
analog_reference = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readADC(uint8_t pin)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
adc_setup (analog_reference, pin);
|
||||||
|
result = adc_read ();
|
||||||
|
adc_fin ();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \return Internal temperature in 0.01C, e.g. 25C is 2500
|
||||||
|
*/
|
||||||
|
int readInternalTemp(void)
|
||||||
|
{
|
||||||
|
int reading = 0;
|
||||||
|
|
||||||
|
ADCSRB |= _BV(MUX5);
|
||||||
|
ADMUX = _BV(REFS1) | _BV(REFS0) | 0b1001 ;
|
||||||
|
ADCSRA = _BV(ADEN) | _BV(ADPS0) | _BV(ADPS2) ;
|
||||||
|
|
||||||
|
ADCSRA |= 1 << ADSC;
|
||||||
|
loop_until_bit_is_clear(ADCSRA,ADSC);
|
||||||
|
reading = ADC;
|
||||||
|
|
||||||
|
ADCSRB=0; //disable ADC, need to write B first for MUX5 bit
|
||||||
|
ADCSRA=0; //disable ADC
|
||||||
|
ADMUX=0; //turn off internal vref
|
||||||
|
|
||||||
|
return reading * 113 - 27280;
|
||||||
|
}
|
65
platform/guhRF/dev/adc.h
Normal file
65
platform/guhRF/dev/adc.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#ifndef __ADC_ARCH_H__
|
||||||
|
#define __ADC_ARCH_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reference voltage
|
||||||
|
* The default is 1.6V reference voltage
|
||||||
|
* The selected reference voltage is the maximum voltage that can be
|
||||||
|
* measured.
|
||||||
|
* Directly provide shifted variants so we don't need to shift.
|
||||||
|
*/
|
||||||
|
#define ADC_1_5 (2<<6)
|
||||||
|
#define ADC_1_6 (3<<6)
|
||||||
|
#define ADC_1_8 (1<<6)
|
||||||
|
#define ADC_EXTERNAL (0<<6)
|
||||||
|
#define ADC_DEFAULT ADC_1_6
|
||||||
|
|
||||||
|
/* sometimes it's desirable to decouple setup / finish from sampling */
|
||||||
|
|
||||||
|
static inline void adc_setup (uint8_t ref_volt, uint8_t pin)
|
||||||
|
{
|
||||||
|
ADMUX = ref_volt | (pin & 0x7);
|
||||||
|
ADCSRA = _BV(ADEN) | _BV(ADPS0) | _BV(ADPS2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int adc_read (void)
|
||||||
|
{
|
||||||
|
ADCSRA |= (1 << ADSC);
|
||||||
|
loop_until_bit_is_clear (ADCSRA, ADSC);
|
||||||
|
return ADC;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void adc_fin (void)
|
||||||
|
{
|
||||||
|
ADCSRA = 0;
|
||||||
|
ADMUX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void adc_init (void)
|
||||||
|
{
|
||||||
|
uint8_t temp;
|
||||||
|
ADCSRC = 0;
|
||||||
|
ADCSRB = 0;
|
||||||
|
adc_fin ();
|
||||||
|
/*
|
||||||
|
* Disable JTAG interface
|
||||||
|
* Hardware manual about JTD bit:
|
||||||
|
* "In order to avoid unintentional disabling or enabling of the
|
||||||
|
* JTAG interface, a timed sequence must be followed when changing
|
||||||
|
* this bit: The application software must write this bit to the
|
||||||
|
* desired value twice within four cycles to change its value."
|
||||||
|
* 15.4.1 "MCUCR - MCU Control Register", p. 219
|
||||||
|
*/
|
||||||
|
temp = MCUCR | (1 << JTD);
|
||||||
|
MCUCR = temp;
|
||||||
|
MCUCR = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readADC(uint8_t pin);
|
||||||
|
long readVcc();
|
||||||
|
int readInternalTemp(void);
|
||||||
|
void analogReference(uint8_t mode);
|
||||||
|
|
||||||
|
#endif /* __ADC_ARCH_H__ */
|
55
platform/guhRF/dev/batmon.c
Normal file
55
platform/guhRF/dev/batmon.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "batmon.h"
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int8_t batmon_init()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t batmon_get_voltage(uint16_t* voltage)
|
||||||
|
{
|
||||||
|
uint16_t volt = 0;
|
||||||
|
uint16_t resolution = 75;
|
||||||
|
uint16_t offset = 2550;
|
||||||
|
int8_t ctr = 0;
|
||||||
|
|
||||||
|
BATMON = 0 | _BV(BATMON_HR);
|
||||||
|
_delay_us(2);
|
||||||
|
|
||||||
|
if(BATMON & _BV(BATMON_OK))
|
||||||
|
{
|
||||||
|
// voltage above 2.550 V
|
||||||
|
resolution = 75;
|
||||||
|
offset = 2550;
|
||||||
|
for(ctr=15; ctr>=0; ctr--)
|
||||||
|
{
|
||||||
|
BATMON = (BATMON & 0xF0) | (ctr);
|
||||||
|
_delay_us(2);
|
||||||
|
if(BATMON & _BV(BATMON_OK)) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// voltage below 2.550 V
|
||||||
|
resolution = 50;
|
||||||
|
offset = 1700;
|
||||||
|
|
||||||
|
BATMON &= ~_BV(BATMON_HR);
|
||||||
|
|
||||||
|
for(ctr=15; ctr>=0; ctr--)
|
||||||
|
{
|
||||||
|
BATMON = (BATMON & 0xF0) | (ctr);
|
||||||
|
_delay_us(2);
|
||||||
|
if(BATMON & _BV(BATMON_OK)) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
volt = resolution*ctr+offset;
|
||||||
|
*voltage=volt;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
8
platform/guhRF/dev/batmon.h
Normal file
8
platform/guhRF/dev/batmon.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef BATMON_H_
|
||||||
|
#define BATMON_H_
|
||||||
|
|
||||||
|
int8_t batmon_init();
|
||||||
|
int8_t batmon_get_voltage(uint16_t* voltage);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BATMON_H_ */
|
90
platform/guhRF/dev/battery-sensor.c
Normal file
90
platform/guhRF/dev/battery-sensor.c
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Battery sensor file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*The atmel rf23x radios have a low voltage detector that can be configured in units of 75 millivolts. Here is example *code for the ATmega128rfa1, where the BATMON register is in extended io space [dak664]
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dev/battery-sensor.h"
|
||||||
|
#include "dev/batmon.h"
|
||||||
|
|
||||||
|
const struct sensors_sensor battery_sensor;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \return Voltage on battery measurement with BATMON register.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint16_t h;
|
||||||
|
/*
|
||||||
|
uint8_t p1;
|
||||||
|
BATMON = 16; //give BATMON time to stabilize at highest range and lowest voltage
|
||||||
|
|
||||||
|
// Bandgap can't be measured against supply voltage in this chip.
|
||||||
|
// Use BATMON register instead
|
||||||
|
for ( p1=16; p1<31; p1++) {
|
||||||
|
BATMON = p1;
|
||||||
|
clock_delay_usec(100); // delay needed !!
|
||||||
|
if ((BATMON&(1<<BATMON_OK))==0) break;
|
||||||
|
}
|
||||||
|
h=2550-75*16-75+75*p1; //-75 to take the floor of the 75 mv transition window
|
||||||
|
*/
|
||||||
|
batmon_get_voltage(&h);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
// No configuration needed. readADC() handles all the config needed.
|
||||||
|
batmon_init();
|
||||||
|
return type == SENSORS_ACTIVE;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
// analog sensors are always ready
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
48
platform/guhRF/dev/battery-sensor.h
Normal file
48
platform/guhRF/dev/battery-sensor.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Battery sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __BATTERY_SENSOR_H__
|
||||||
|
#define __BATTERY_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor battery_sensor;
|
||||||
|
|
||||||
|
#define BATTERY_SENSOR "Battery"
|
||||||
|
|
||||||
|
#endif /* __BATTERY_SENSOR_H__ */
|
515
platform/guhRF/dev/binary.h
Normal file
515
platform/guhRF/dev/binary.h
Normal file
|
@ -0,0 +1,515 @@
|
||||||
|
#ifndef Binary_h
|
||||||
|
#define Binary_h
|
||||||
|
|
||||||
|
#define B0 0
|
||||||
|
#define B00 0
|
||||||
|
#define B000 0
|
||||||
|
#define B0000 0
|
||||||
|
#define B00000 0
|
||||||
|
#define B000000 0
|
||||||
|
#define B0000000 0
|
||||||
|
#define B00000000 0
|
||||||
|
#define B1 1
|
||||||
|
#define B01 1
|
||||||
|
#define B001 1
|
||||||
|
#define B0001 1
|
||||||
|
#define B00001 1
|
||||||
|
#define B000001 1
|
||||||
|
#define B0000001 1
|
||||||
|
#define B00000001 1
|
||||||
|
#define B10 2
|
||||||
|
#define B010 2
|
||||||
|
#define B0010 2
|
||||||
|
#define B00010 2
|
||||||
|
#define B000010 2
|
||||||
|
#define B0000010 2
|
||||||
|
#define B00000010 2
|
||||||
|
#define B11 3
|
||||||
|
#define B011 3
|
||||||
|
#define B0011 3
|
||||||
|
#define B00011 3
|
||||||
|
#define B000011 3
|
||||||
|
#define B0000011 3
|
||||||
|
#define B00000011 3
|
||||||
|
#define B100 4
|
||||||
|
#define B0100 4
|
||||||
|
#define B00100 4
|
||||||
|
#define B000100 4
|
||||||
|
#define B0000100 4
|
||||||
|
#define B00000100 4
|
||||||
|
#define B101 5
|
||||||
|
#define B0101 5
|
||||||
|
#define B00101 5
|
||||||
|
#define B000101 5
|
||||||
|
#define B0000101 5
|
||||||
|
#define B00000101 5
|
||||||
|
#define B110 6
|
||||||
|
#define B0110 6
|
||||||
|
#define B00110 6
|
||||||
|
#define B000110 6
|
||||||
|
#define B0000110 6
|
||||||
|
#define B00000110 6
|
||||||
|
#define B111 7
|
||||||
|
#define B0111 7
|
||||||
|
#define B00111 7
|
||||||
|
#define B000111 7
|
||||||
|
#define B0000111 7
|
||||||
|
#define B00000111 7
|
||||||
|
#define B1000 8
|
||||||
|
#define B01000 8
|
||||||
|
#define B001000 8
|
||||||
|
#define B0001000 8
|
||||||
|
#define B00001000 8
|
||||||
|
#define B1001 9
|
||||||
|
#define B01001 9
|
||||||
|
#define B001001 9
|
||||||
|
#define B0001001 9
|
||||||
|
#define B00001001 9
|
||||||
|
#define B1010 10
|
||||||
|
#define B01010 10
|
||||||
|
#define B001010 10
|
||||||
|
#define B0001010 10
|
||||||
|
#define B00001010 10
|
||||||
|
#define B1011 11
|
||||||
|
#define B01011 11
|
||||||
|
#define B001011 11
|
||||||
|
#define B0001011 11
|
||||||
|
#define B00001011 11
|
||||||
|
#define B1100 12
|
||||||
|
#define B01100 12
|
||||||
|
#define B001100 12
|
||||||
|
#define B0001100 12
|
||||||
|
#define B00001100 12
|
||||||
|
#define B1101 13
|
||||||
|
#define B01101 13
|
||||||
|
#define B001101 13
|
||||||
|
#define B0001101 13
|
||||||
|
#define B00001101 13
|
||||||
|
#define B1110 14
|
||||||
|
#define B01110 14
|
||||||
|
#define B001110 14
|
||||||
|
#define B0001110 14
|
||||||
|
#define B00001110 14
|
||||||
|
#define B1111 15
|
||||||
|
#define B01111 15
|
||||||
|
#define B001111 15
|
||||||
|
#define B0001111 15
|
||||||
|
#define B00001111 15
|
||||||
|
#define B10000 16
|
||||||
|
#define B010000 16
|
||||||
|
#define B0010000 16
|
||||||
|
#define B00010000 16
|
||||||
|
#define B10001 17
|
||||||
|
#define B010001 17
|
||||||
|
#define B0010001 17
|
||||||
|
#define B00010001 17
|
||||||
|
#define B10010 18
|
||||||
|
#define B010010 18
|
||||||
|
#define B0010010 18
|
||||||
|
#define B00010010 18
|
||||||
|
#define B10011 19
|
||||||
|
#define B010011 19
|
||||||
|
#define B0010011 19
|
||||||
|
#define B00010011 19
|
||||||
|
#define B10100 20
|
||||||
|
#define B010100 20
|
||||||
|
#define B0010100 20
|
||||||
|
#define B00010100 20
|
||||||
|
#define B10101 21
|
||||||
|
#define B010101 21
|
||||||
|
#define B0010101 21
|
||||||
|
#define B00010101 21
|
||||||
|
#define B10110 22
|
||||||
|
#define B010110 22
|
||||||
|
#define B0010110 22
|
||||||
|
#define B00010110 22
|
||||||
|
#define B10111 23
|
||||||
|
#define B010111 23
|
||||||
|
#define B0010111 23
|
||||||
|
#define B00010111 23
|
||||||
|
#define B11000 24
|
||||||
|
#define B011000 24
|
||||||
|
#define B0011000 24
|
||||||
|
#define B00011000 24
|
||||||
|
#define B11001 25
|
||||||
|
#define B011001 25
|
||||||
|
#define B0011001 25
|
||||||
|
#define B00011001 25
|
||||||
|
#define B11010 26
|
||||||
|
#define B011010 26
|
||||||
|
#define B0011010 26
|
||||||
|
#define B00011010 26
|
||||||
|
#define B11011 27
|
||||||
|
#define B011011 27
|
||||||
|
#define B0011011 27
|
||||||
|
#define B00011011 27
|
||||||
|
#define B11100 28
|
||||||
|
#define B011100 28
|
||||||
|
#define B0011100 28
|
||||||
|
#define B00011100 28
|
||||||
|
#define B11101 29
|
||||||
|
#define B011101 29
|
||||||
|
#define B0011101 29
|
||||||
|
#define B00011101 29
|
||||||
|
#define B11110 30
|
||||||
|
#define B011110 30
|
||||||
|
#define B0011110 30
|
||||||
|
#define B00011110 30
|
||||||
|
#define B11111 31
|
||||||
|
#define B011111 31
|
||||||
|
#define B0011111 31
|
||||||
|
#define B00011111 31
|
||||||
|
#define B100000 32
|
||||||
|
#define B0100000 32
|
||||||
|
#define B00100000 32
|
||||||
|
#define B100001 33
|
||||||
|
#define B0100001 33
|
||||||
|
#define B00100001 33
|
||||||
|
#define B100010 34
|
||||||
|
#define B0100010 34
|
||||||
|
#define B00100010 34
|
||||||
|
#define B100011 35
|
||||||
|
#define B0100011 35
|
||||||
|
#define B00100011 35
|
||||||
|
#define B100100 36
|
||||||
|
#define B0100100 36
|
||||||
|
#define B00100100 36
|
||||||
|
#define B100101 37
|
||||||
|
#define B0100101 37
|
||||||
|
#define B00100101 37
|
||||||
|
#define B100110 38
|
||||||
|
#define B0100110 38
|
||||||
|
#define B00100110 38
|
||||||
|
#define B100111 39
|
||||||
|
#define B0100111 39
|
||||||
|
#define B00100111 39
|
||||||
|
#define B101000 40
|
||||||
|
#define B0101000 40
|
||||||
|
#define B00101000 40
|
||||||
|
#define B101001 41
|
||||||
|
#define B0101001 41
|
||||||
|
#define B00101001 41
|
||||||
|
#define B101010 42
|
||||||
|
#define B0101010 42
|
||||||
|
#define B00101010 42
|
||||||
|
#define B101011 43
|
||||||
|
#define B0101011 43
|
||||||
|
#define B00101011 43
|
||||||
|
#define B101100 44
|
||||||
|
#define B0101100 44
|
||||||
|
#define B00101100 44
|
||||||
|
#define B101101 45
|
||||||
|
#define B0101101 45
|
||||||
|
#define B00101101 45
|
||||||
|
#define B101110 46
|
||||||
|
#define B0101110 46
|
||||||
|
#define B00101110 46
|
||||||
|
#define B101111 47
|
||||||
|
#define B0101111 47
|
||||||
|
#define B00101111 47
|
||||||
|
#define B110000 48
|
||||||
|
#define B0110000 48
|
||||||
|
#define B00110000 48
|
||||||
|
#define B110001 49
|
||||||
|
#define B0110001 49
|
||||||
|
#define B00110001 49
|
||||||
|
#define B110010 50
|
||||||
|
#define B0110010 50
|
||||||
|
#define B00110010 50
|
||||||
|
#define B110011 51
|
||||||
|
#define B0110011 51
|
||||||
|
#define B00110011 51
|
||||||
|
#define B110100 52
|
||||||
|
#define B0110100 52
|
||||||
|
#define B00110100 52
|
||||||
|
#define B110101 53
|
||||||
|
#define B0110101 53
|
||||||
|
#define B00110101 53
|
||||||
|
#define B110110 54
|
||||||
|
#define B0110110 54
|
||||||
|
#define B00110110 54
|
||||||
|
#define B110111 55
|
||||||
|
#define B0110111 55
|
||||||
|
#define B00110111 55
|
||||||
|
#define B111000 56
|
||||||
|
#define B0111000 56
|
||||||
|
#define B00111000 56
|
||||||
|
#define B111001 57
|
||||||
|
#define B0111001 57
|
||||||
|
#define B00111001 57
|
||||||
|
#define B111010 58
|
||||||
|
#define B0111010 58
|
||||||
|
#define B00111010 58
|
||||||
|
#define B111011 59
|
||||||
|
#define B0111011 59
|
||||||
|
#define B00111011 59
|
||||||
|
#define B111100 60
|
||||||
|
#define B0111100 60
|
||||||
|
#define B00111100 60
|
||||||
|
#define B111101 61
|
||||||
|
#define B0111101 61
|
||||||
|
#define B00111101 61
|
||||||
|
#define B111110 62
|
||||||
|
#define B0111110 62
|
||||||
|
#define B00111110 62
|
||||||
|
#define B111111 63
|
||||||
|
#define B0111111 63
|
||||||
|
#define B00111111 63
|
||||||
|
#define B1000000 64
|
||||||
|
#define B01000000 64
|
||||||
|
#define B1000001 65
|
||||||
|
#define B01000001 65
|
||||||
|
#define B1000010 66
|
||||||
|
#define B01000010 66
|
||||||
|
#define B1000011 67
|
||||||
|
#define B01000011 67
|
||||||
|
#define B1000100 68
|
||||||
|
#define B01000100 68
|
||||||
|
#define B1000101 69
|
||||||
|
#define B01000101 69
|
||||||
|
#define B1000110 70
|
||||||
|
#define B01000110 70
|
||||||
|
#define B1000111 71
|
||||||
|
#define B01000111 71
|
||||||
|
#define B1001000 72
|
||||||
|
#define B01001000 72
|
||||||
|
#define B1001001 73
|
||||||
|
#define B01001001 73
|
||||||
|
#define B1001010 74
|
||||||
|
#define B01001010 74
|
||||||
|
#define B1001011 75
|
||||||
|
#define B01001011 75
|
||||||
|
#define B1001100 76
|
||||||
|
#define B01001100 76
|
||||||
|
#define B1001101 77
|
||||||
|
#define B01001101 77
|
||||||
|
#define B1001110 78
|
||||||
|
#define B01001110 78
|
||||||
|
#define B1001111 79
|
||||||
|
#define B01001111 79
|
||||||
|
#define B1010000 80
|
||||||
|
#define B01010000 80
|
||||||
|
#define B1010001 81
|
||||||
|
#define B01010001 81
|
||||||
|
#define B1010010 82
|
||||||
|
#define B01010010 82
|
||||||
|
#define B1010011 83
|
||||||
|
#define B01010011 83
|
||||||
|
#define B1010100 84
|
||||||
|
#define B01010100 84
|
||||||
|
#define B1010101 85
|
||||||
|
#define B01010101 85
|
||||||
|
#define B1010110 86
|
||||||
|
#define B01010110 86
|
||||||
|
#define B1010111 87
|
||||||
|
#define B01010111 87
|
||||||
|
#define B1011000 88
|
||||||
|
#define B01011000 88
|
||||||
|
#define B1011001 89
|
||||||
|
#define B01011001 89
|
||||||
|
#define B1011010 90
|
||||||
|
#define B01011010 90
|
||||||
|
#define B1011011 91
|
||||||
|
#define B01011011 91
|
||||||
|
#define B1011100 92
|
||||||
|
#define B01011100 92
|
||||||
|
#define B1011101 93
|
||||||
|
#define B01011101 93
|
||||||
|
#define B1011110 94
|
||||||
|
#define B01011110 94
|
||||||
|
#define B1011111 95
|
||||||
|
#define B01011111 95
|
||||||
|
#define B1100000 96
|
||||||
|
#define B01100000 96
|
||||||
|
#define B1100001 97
|
||||||
|
#define B01100001 97
|
||||||
|
#define B1100010 98
|
||||||
|
#define B01100010 98
|
||||||
|
#define B1100011 99
|
||||||
|
#define B01100011 99
|
||||||
|
#define B1100100 100
|
||||||
|
#define B01100100 100
|
||||||
|
#define B1100101 101
|
||||||
|
#define B01100101 101
|
||||||
|
#define B1100110 102
|
||||||
|
#define B01100110 102
|
||||||
|
#define B1100111 103
|
||||||
|
#define B01100111 103
|
||||||
|
#define B1101000 104
|
||||||
|
#define B01101000 104
|
||||||
|
#define B1101001 105
|
||||||
|
#define B01101001 105
|
||||||
|
#define B1101010 106
|
||||||
|
#define B01101010 106
|
||||||
|
#define B1101011 107
|
||||||
|
#define B01101011 107
|
||||||
|
#define B1101100 108
|
||||||
|
#define B01101100 108
|
||||||
|
#define B1101101 109
|
||||||
|
#define B01101101 109
|
||||||
|
#define B1101110 110
|
||||||
|
#define B01101110 110
|
||||||
|
#define B1101111 111
|
||||||
|
#define B01101111 111
|
||||||
|
#define B1110000 112
|
||||||
|
#define B01110000 112
|
||||||
|
#define B1110001 113
|
||||||
|
#define B01110001 113
|
||||||
|
#define B1110010 114
|
||||||
|
#define B01110010 114
|
||||||
|
#define B1110011 115
|
||||||
|
#define B01110011 115
|
||||||
|
#define B1110100 116
|
||||||
|
#define B01110100 116
|
||||||
|
#define B1110101 117
|
||||||
|
#define B01110101 117
|
||||||
|
#define B1110110 118
|
||||||
|
#define B01110110 118
|
||||||
|
#define B1110111 119
|
||||||
|
#define B01110111 119
|
||||||
|
#define B1111000 120
|
||||||
|
#define B01111000 120
|
||||||
|
#define B1111001 121
|
||||||
|
#define B01111001 121
|
||||||
|
#define B1111010 122
|
||||||
|
#define B01111010 122
|
||||||
|
#define B1111011 123
|
||||||
|
#define B01111011 123
|
||||||
|
#define B1111100 124
|
||||||
|
#define B01111100 124
|
||||||
|
#define B1111101 125
|
||||||
|
#define B01111101 125
|
||||||
|
#define B1111110 126
|
||||||
|
#define B01111110 126
|
||||||
|
#define B1111111 127
|
||||||
|
#define B01111111 127
|
||||||
|
#define B10000000 128
|
||||||
|
#define B10000001 129
|
||||||
|
#define B10000010 130
|
||||||
|
#define B10000011 131
|
||||||
|
#define B10000100 132
|
||||||
|
#define B10000101 133
|
||||||
|
#define B10000110 134
|
||||||
|
#define B10000111 135
|
||||||
|
#define B10001000 136
|
||||||
|
#define B10001001 137
|
||||||
|
#define B10001010 138
|
||||||
|
#define B10001011 139
|
||||||
|
#define B10001100 140
|
||||||
|
#define B10001101 141
|
||||||
|
#define B10001110 142
|
||||||
|
#define B10001111 143
|
||||||
|
#define B10010000 144
|
||||||
|
#define B10010001 145
|
||||||
|
#define B10010010 146
|
||||||
|
#define B10010011 147
|
||||||
|
#define B10010100 148
|
||||||
|
#define B10010101 149
|
||||||
|
#define B10010110 150
|
||||||
|
#define B10010111 151
|
||||||
|
#define B10011000 152
|
||||||
|
#define B10011001 153
|
||||||
|
#define B10011010 154
|
||||||
|
#define B10011011 155
|
||||||
|
#define B10011100 156
|
||||||
|
#define B10011101 157
|
||||||
|
#define B10011110 158
|
||||||
|
#define B10011111 159
|
||||||
|
#define B10100000 160
|
||||||
|
#define B10100001 161
|
||||||
|
#define B10100010 162
|
||||||
|
#define B10100011 163
|
||||||
|
#define B10100100 164
|
||||||
|
#define B10100101 165
|
||||||
|
#define B10100110 166
|
||||||
|
#define B10100111 167
|
||||||
|
#define B10101000 168
|
||||||
|
#define B10101001 169
|
||||||
|
#define B10101010 170
|
||||||
|
#define B10101011 171
|
||||||
|
#define B10101100 172
|
||||||
|
#define B10101101 173
|
||||||
|
#define B10101110 174
|
||||||
|
#define B10101111 175
|
||||||
|
#define B10110000 176
|
||||||
|
#define B10110001 177
|
||||||
|
#define B10110010 178
|
||||||
|
#define B10110011 179
|
||||||
|
#define B10110100 180
|
||||||
|
#define B10110101 181
|
||||||
|
#define B10110110 182
|
||||||
|
#define B10110111 183
|
||||||
|
#define B10111000 184
|
||||||
|
#define B10111001 185
|
||||||
|
#define B10111010 186
|
||||||
|
#define B10111011 187
|
||||||
|
#define B10111100 188
|
||||||
|
#define B10111101 189
|
||||||
|
#define B10111110 190
|
||||||
|
#define B10111111 191
|
||||||
|
#define B11000000 192
|
||||||
|
#define B11000001 193
|
||||||
|
#define B11000010 194
|
||||||
|
#define B11000011 195
|
||||||
|
#define B11000100 196
|
||||||
|
#define B11000101 197
|
||||||
|
#define B11000110 198
|
||||||
|
#define B11000111 199
|
||||||
|
#define B11001000 200
|
||||||
|
#define B11001001 201
|
||||||
|
#define B11001010 202
|
||||||
|
#define B11001011 203
|
||||||
|
#define B11001100 204
|
||||||
|
#define B11001101 205
|
||||||
|
#define B11001110 206
|
||||||
|
#define B11001111 207
|
||||||
|
#define B11010000 208
|
||||||
|
#define B11010001 209
|
||||||
|
#define B11010010 210
|
||||||
|
#define B11010011 211
|
||||||
|
#define B11010100 212
|
||||||
|
#define B11010101 213
|
||||||
|
#define B11010110 214
|
||||||
|
#define B11010111 215
|
||||||
|
#define B11011000 216
|
||||||
|
#define B11011001 217
|
||||||
|
#define B11011010 218
|
||||||
|
#define B11011011 219
|
||||||
|
#define B11011100 220
|
||||||
|
#define B11011101 221
|
||||||
|
#define B11011110 222
|
||||||
|
#define B11011111 223
|
||||||
|
#define B11100000 224
|
||||||
|
#define B11100001 225
|
||||||
|
#define B11100010 226
|
||||||
|
#define B11100011 227
|
||||||
|
#define B11100100 228
|
||||||
|
#define B11100101 229
|
||||||
|
#define B11100110 230
|
||||||
|
#define B11100111 231
|
||||||
|
#define B11101000 232
|
||||||
|
#define B11101001 233
|
||||||
|
#define B11101010 234
|
||||||
|
#define B11101011 235
|
||||||
|
#define B11101100 236
|
||||||
|
#define B11101101 237
|
||||||
|
#define B11101110 238
|
||||||
|
#define B11101111 239
|
||||||
|
#define B11110000 240
|
||||||
|
#define B11110001 241
|
||||||
|
#define B11110010 242
|
||||||
|
#define B11110011 243
|
||||||
|
#define B11110100 244
|
||||||
|
#define B11110101 245
|
||||||
|
#define B11110110 246
|
||||||
|
#define B11110111 247
|
||||||
|
#define B11111000 248
|
||||||
|
#define B11111001 249
|
||||||
|
#define B11111010 250
|
||||||
|
#define B11111011 251
|
||||||
|
#define B11111100 252
|
||||||
|
#define B11111101 253
|
||||||
|
#define B11111110 254
|
||||||
|
#define B11111111 255
|
||||||
|
|
||||||
|
#endif
|
78
platform/guhRF/dev/button-sensor.c
Normal file
78
platform/guhRF/dev/button-sensor.c
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/* Sensor routine */
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/button-sensor.h"
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
const struct sensors_sensor button_sensor;
|
||||||
|
|
||||||
|
static struct timer debouncetimer;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
struct sensors_sensor *sensors[1];
|
||||||
|
unsigned char sensors_flags[1];
|
||||||
|
|
||||||
|
#define BUTTON_BIT INTF4
|
||||||
|
#define BUTTON_CHECK_IRQ() (EIFR & BUTTON_BIT) ? 0 : 1
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
ISR(INT4_vect)
|
||||||
|
{
|
||||||
|
if(BUTTON_CHECK_IRQ()) {
|
||||||
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
|
sensors_changed(&button_sensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer);
|
||||||
|
|
||||||
|
//return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if (c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
|
DDRE |= (0<<DDRE4); // Set pin as input
|
||||||
|
PORTE |= (1<<PORTE4); // Set port PORTE bint 5 with pullup resistor
|
||||||
|
EICRB |= (1<<ISC40); // For falling edge
|
||||||
|
EIMSK |= (1<<INT4); // Set int
|
||||||
|
enabled = 1;
|
||||||
|
sei();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 0;
|
||||||
|
EIMSK &= ~(1<<INT4); // clear int
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;//(EIMSK & (1<<INT5) ? 0 : 1);//BUTTON_IRQ_ENABLED();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||||
|
value, configure, status);
|
||||||
|
|
125
platform/guhRF/dev/dht11.c
Normal file
125
platform/guhRF/dev/dht11.c
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
DHT-11 Library
|
||||||
|
(c) Created by Charalampos Andrianakis on 18/12/11.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dht11.h"
|
||||||
|
#include "led.h" // debug
|
||||||
|
|
||||||
|
#define udelay(u) clock_delay_usec(u)
|
||||||
|
#define mdelay(u) clock_delay_msec(u)
|
||||||
|
|
||||||
|
// todo: set DHT22 or DHT11 in project file
|
||||||
|
// define for DHT11 else for DHT22, RHT03
|
||||||
|
// #define DHT11 1
|
||||||
|
|
||||||
|
uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity){
|
||||||
|
|
||||||
|
//data[5] is 8byte table where data come from DHT are stored
|
||||||
|
//laststate holds laststate value
|
||||||
|
//counter is used to count microSeconds
|
||||||
|
uint8_t data[5], laststate = 0, counter = 0, j = 0, i = 0;
|
||||||
|
|
||||||
|
//Clear array
|
||||||
|
data[0] = data[1] = data[2] = data[3] = data[4] = 0;
|
||||||
|
|
||||||
|
uint8_t volatile sreg;
|
||||||
|
sreg = SREG; /* Save status register before disabling interrupts. */
|
||||||
|
cli(); /* Disable interrupts. */
|
||||||
|
|
||||||
|
//Set pin Output
|
||||||
|
//Pin High
|
||||||
|
DHT_DRIVE();
|
||||||
|
mdelay(100); //Wait for 100mS
|
||||||
|
|
||||||
|
//Send Request Signal
|
||||||
|
//Pin Low
|
||||||
|
OUTP_0(); //20ms Low
|
||||||
|
mdelay(20);
|
||||||
|
//Pin High
|
||||||
|
OUTP_1();
|
||||||
|
udelay(40); //40us High
|
||||||
|
|
||||||
|
//Set pin Input to read Bus
|
||||||
|
//Set pin Input
|
||||||
|
DHT_RELEASE();
|
||||||
|
laststate=DHT_INP(); //Read Pin value
|
||||||
|
|
||||||
|
//Repeat for each Transistions
|
||||||
|
for (i=0; i<MAXTIMINGS; i++) {
|
||||||
|
//While state is the same count microseconds
|
||||||
|
//led1_on();
|
||||||
|
//led1_off();
|
||||||
|
|
||||||
|
while (laststate==DHT_INP()) {
|
||||||
|
udelay(1);
|
||||||
|
counter++;
|
||||||
|
if (counter>254) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter>254) break;
|
||||||
|
|
||||||
|
//laststate==_BV(DHT_PIN) checks if laststate was High
|
||||||
|
//ignore the first 2 transitions which are the DHT Response
|
||||||
|
//if (laststate==_BV(DHT_PIN) && (i > 2)) {
|
||||||
|
if ((i&0x01) && (i > 2)) {
|
||||||
|
//Save bits in segments of bytes
|
||||||
|
//Shift data[] value 1 position left
|
||||||
|
//Example. 01010100 if we shift it left one time it will be
|
||||||
|
//10101000
|
||||||
|
|
||||||
|
data[j/8]<<=1;
|
||||||
|
if (counter >= 15) { //If it was high for more than 40uS
|
||||||
|
//led1_on();
|
||||||
|
data[j/8]|=1; //it means it is bit '1' so make a logic
|
||||||
|
//led1_off();
|
||||||
|
} //OR with the value (save it)
|
||||||
|
j++; //making an OR by 1 to this value 10101000
|
||||||
|
} //we will have the resault 10101001
|
||||||
|
//1 in 8-bit binary is 00000001
|
||||||
|
//j/8 changes table record every 8 bits which means a byte has been saved
|
||||||
|
//so change to next record. 0/8=0 1/8=0 ... 7/8=0 8/8=1 ... 15/8=1 16/8=2
|
||||||
|
laststate=DHT_INP(); //save current state
|
||||||
|
counter=0; //reset counter
|
||||||
|
|
||||||
|
}
|
||||||
|
SREG = sreg; /* Enable interrupts. */
|
||||||
|
//printf("HUM %d %d %d %d %d %d",data[0],data[1],data[2],data[3],data[4],(uint8_t)(data[0] + data[1] + data[2] + data[3]) );
|
||||||
|
//Check if data received are correct by checking the CheckSum
|
||||||
|
if ((uint8_t)(data[0] + data[1] + data[2] + data[3]) == data[4]) {
|
||||||
|
#ifdef DHT11
|
||||||
|
*humidity = data[0]*100;
|
||||||
|
*temperature = data[2]*100;
|
||||||
|
#else
|
||||||
|
*humidity = ((uint16_t)data[0]<<8 | data[1])*10;
|
||||||
|
*temperature = ((uint16_t)data[2]<<8 | data[3])*10;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}else{
|
||||||
|
*humidity = 2;
|
||||||
|
*temperature = 2;
|
||||||
|
// uart_puts("\r\nCheck Sum Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0xff; // Check Sum Error
|
||||||
|
}
|
67
platform/guhRF/dev/dht11.h
Normal file
67
platform/guhRF/dev/dht11.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
DHT-11 Library
|
||||||
|
(c) Created by Charalampos Andrianakis on 18/12/11.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
/* DHT 1-wire is at PortE.6 */
|
||||||
|
#define DHT_PIN_READ PINE
|
||||||
|
#define DHT_PIN_MASK _BV(PE6)
|
||||||
|
#define DHT_PxOUT PORTE
|
||||||
|
#define DHT_PxDIR DDRE
|
||||||
|
|
||||||
|
#define SET_PIN_INPUT() (DHT_PxDIR &= ~DHT_PIN_MASK)
|
||||||
|
#define SET_PIN_OUTPUT() (DHT_PxDIR |= DHT_PIN_MASK)
|
||||||
|
|
||||||
|
#define OUTP_0() (DHT_PxOUT &= ~DHT_PIN_MASK)
|
||||||
|
#define OUTP_1() (DHT_PxOUT |= DHT_PIN_MASK)
|
||||||
|
|
||||||
|
#define PIN_INIT() do{ \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_0(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
/* Drive the one wire interface hight */
|
||||||
|
#define DHT_DRIVE() do { \
|
||||||
|
SET_PIN_OUTPUT(); \
|
||||||
|
OUTP_1(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Release the one wire by turning on the internal pull-up. */
|
||||||
|
#define DHT_RELEASE() do { \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_1(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Read one bit. */
|
||||||
|
#define DHT_INP() (DHT_PIN_READ & DHT_PIN_MASK)
|
||||||
|
|
||||||
|
//The packet size is 40bit but each bit consists of low and high state
|
||||||
|
//so 40 x 2 = 80 transitions. Also we have 2 transistions DHT response
|
||||||
|
//and 2 transitions which indicates End Of Frame. In total 84
|
||||||
|
#define MAXTIMINGS 84
|
||||||
|
|
||||||
|
//This is the main function which requests and reads the packet
|
||||||
|
uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity);
|
291
platform/guhRF/dev/ds1820.c
Normal file
291
platform/guhRF/dev/ds1820.c
Normal file
|
@ -0,0 +1,291 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: ds1820.c,v 1.5 2010/08/25 18:35:52 nifi Exp $
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Device driver for the Dallas Semiconductor DS1820 chip. Heavily
|
||||||
|
* based on the application note 126 "1-Wire Communications Through
|
||||||
|
* Software".
|
||||||
|
*
|
||||||
|
* http://www.maxim-ic.com/appnotes.cfm/appnote_number/126
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For now we stuff in Moteiv Corporation's unique OUI.
|
||||||
|
* From http://www.ethereal.com/distribution/manuf.txt:
|
||||||
|
* 00:12:75 Moteiv # Moteiv Corporation
|
||||||
|
*
|
||||||
|
* The EUI-64 is a concatenation of the 24-bit OUI value assigned by
|
||||||
|
* the IEEE Registration Authority and a 40-bit extension identifier
|
||||||
|
* assigned by the organization with that OUI assignment.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "ds1820.h"
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char ds1820_id[8];
|
||||||
|
unsigned char ds1820_ok[8];
|
||||||
|
|
||||||
|
/* 1-wire is at PortE.3 */
|
||||||
|
#define SERIAL_ID_PIN_READ PINE
|
||||||
|
//#define SERIAL_ID_PIN_MASK _BV(PE3)
|
||||||
|
#define SERIAL_ID_PIN_MASK _BV(PE4)
|
||||||
|
#define SERIAL_ID_PxOUT PORTE
|
||||||
|
#define SERIAL_ID_PxDIR DDRE
|
||||||
|
|
||||||
|
#define SET_PIN_INPUT() (SERIAL_ID_PxDIR &= ~SERIAL_ID_PIN_MASK)
|
||||||
|
#define SET_PIN_OUTPUT() (SERIAL_ID_PxDIR |= SERIAL_ID_PIN_MASK)
|
||||||
|
|
||||||
|
#define OUTP_0() (SERIAL_ID_PxOUT &= ~SERIAL_ID_PIN_MASK)
|
||||||
|
#define OUTP_1() (SERIAL_ID_PxOUT |= SERIAL_ID_PIN_MASK)
|
||||||
|
|
||||||
|
#define PIN_INIT() do{ \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_0(); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
/* Drive the one wire interface low */
|
||||||
|
#define OW_DRIVE() do { \
|
||||||
|
SET_PIN_OUTPUT(); \
|
||||||
|
OUTP_0(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Release the one wire by turning on the internal pull-up. */
|
||||||
|
#define OW_RELEASE() do { \
|
||||||
|
SET_PIN_INPUT(); \
|
||||||
|
OUTP_1(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Read one bit. */
|
||||||
|
#define INP() (SERIAL_ID_PIN_READ & SERIAL_ID_PIN_MASK)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delay times in us.
|
||||||
|
*/
|
||||||
|
#define tA 6 /* min-5, recommended-6, max-15 */
|
||||||
|
#define tB 64 /* min-59, recommended-64, max-N/A */
|
||||||
|
#define tC 60 /* min-60, recommended-60, max-120 */
|
||||||
|
#define tD 10 /* min-5.3, recommended-10, max-N/A */
|
||||||
|
#define tE 9 /* min-0.3, recommended-9, max-9.3 */
|
||||||
|
#define tF 55 /* min-50, recommended-55, max-N/A */
|
||||||
|
#define tG 0 /* min-0, recommended-0, max-0 */
|
||||||
|
#define tH 480 /* min-480, recommended-480, max-640 */
|
||||||
|
#define tI 70 /* min-60.3, recommended-70, max-75.3 */
|
||||||
|
#define tJ 410 /* min-410, recommended-410, max-N/A */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#define udelay(u) clock_delay_usec(u)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
owreset(void)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tH); /* 480 < tH < 640 */
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tI);
|
||||||
|
result = INP();
|
||||||
|
udelay(tJ);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
owwriteb(unsigned byte)
|
||||||
|
{
|
||||||
|
int i = 7;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(byte & 0x01) {
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tA);
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tB);
|
||||||
|
} else {
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tC);
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tD);
|
||||||
|
}
|
||||||
|
if(i == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
byte >>= 1;
|
||||||
|
} while(1);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static unsigned
|
||||||
|
owreadb(void)
|
||||||
|
{
|
||||||
|
unsigned result = 0;
|
||||||
|
int i = 7;
|
||||||
|
|
||||||
|
do {
|
||||||
|
OW_DRIVE();
|
||||||
|
udelay(tA);
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
udelay(tE);
|
||||||
|
if (INP()){
|
||||||
|
result |= 0x80; /* LSbit first */
|
||||||
|
}
|
||||||
|
udelay(tF);
|
||||||
|
if(i == 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
result >>= 1;
|
||||||
|
} while(1);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Polynomial ^8 + ^5 + ^4 + 1 */
|
||||||
|
static unsigned
|
||||||
|
crc8_add(unsigned acc, unsigned byte)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
acc ^= byte;
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
if(acc & 1) {
|
||||||
|
acc = (acc >> 1) ^ 0x8c;
|
||||||
|
} else {
|
||||||
|
acc >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ds1820_init()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned family, crc, acc;
|
||||||
|
|
||||||
|
PIN_INIT();
|
||||||
|
|
||||||
|
if(owreset() == 0) { /* Something pulled down 1-wire. */
|
||||||
|
|
||||||
|
owwriteb(0x33); /* Read ROM command. */
|
||||||
|
family = owreadb();
|
||||||
|
/* We receive 6 bytes in the reverse order, LSbyte first. */
|
||||||
|
for(i = 7; i >= 2; i--) {
|
||||||
|
ds1820_id[i] = owreadb();
|
||||||
|
}
|
||||||
|
crc = owreadb();
|
||||||
|
|
||||||
|
/* Verify family DS1820 and that CRC match. */
|
||||||
|
if(family != 0x10) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
acc = crc8_add(0x0, family);
|
||||||
|
for(i = 7; i >= 2; i--) {
|
||||||
|
acc = crc8_add(acc, ds1820_id[i]);
|
||||||
|
}
|
||||||
|
if(acc == crc) {
|
||||||
|
ds1820_id[0] = 0x00;
|
||||||
|
ds1820_id[1] = 0x00;
|
||||||
|
ds1820_id[2] = 0x00;
|
||||||
|
return 1; /* Success! */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fail:
|
||||||
|
memset(ds1820_id, 0x0, sizeof(ds1820_id));
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ds1820_temp()
|
||||||
|
{
|
||||||
|
ds1820_convert();
|
||||||
|
// wait max 750ms pin lo
|
||||||
|
clock_wait(CLOCK_SECOND);
|
||||||
|
ds1820_read();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ds1820_convert()
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
PIN_INIT();
|
||||||
|
for(i=0;i<3;i++){
|
||||||
|
if(owreset() == 0) { /* Something pulled down 1-wire. */
|
||||||
|
owwriteb(0xCC); /* Skip ROM command. */
|
||||||
|
owwriteb(0x44); /* Convert T command. */
|
||||||
|
OW_RELEASE(); /* Releases the bus */
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ds1820_read()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned crc, acc;
|
||||||
|
|
||||||
|
if(owreset() == 0) { /* Something pulled down 1-wire. */
|
||||||
|
owwriteb(0xCC); /* Skip ROM command. */
|
||||||
|
owwriteb(0xBE); /* Read Scratchpad command. */
|
||||||
|
/* We receive 8 bytes in the reverse order, LSbyte first. */
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
ds1820_id[i] = owreadb();
|
||||||
|
}
|
||||||
|
crc = owreadb();
|
||||||
|
|
||||||
|
acc=0;
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
acc = crc8_add(acc, ds1820_id[i]);
|
||||||
|
}
|
||||||
|
if(acc == crc) {
|
||||||
|
// store temp
|
||||||
|
for(i = 0; i < 8; i++) {
|
||||||
|
ds1820_ok[i]=ds1820_id[i];
|
||||||
|
}
|
||||||
|
return 1; /* Success! */
|
||||||
|
} else {
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0; /* Fail! */
|
||||||
|
}
|
||||||
|
return 1; /* Fail! */
|
||||||
|
}
|
45
platform/guhRF/dev/ds1820.h
Normal file
45
platform/guhRF/dev/ds1820.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: ds1820.h,v 1.1 2006/06/17 22:41:16 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
/* -*- C -*- */
|
||||||
|
/* @(#)$Id: ds1820.h,v 1.1 2006/06/17 22:41:16 adamdunkels Exp $ */
|
||||||
|
|
||||||
|
#ifndef DS1820_H
|
||||||
|
#define DS1820_H
|
||||||
|
|
||||||
|
extern unsigned char ds1820_id[8];
|
||||||
|
extern unsigned char ds1820_ok[8];
|
||||||
|
extern int ds1820_init();
|
||||||
|
extern int ds1820_convert();
|
||||||
|
extern int ds1820_read();
|
||||||
|
extern int ds1820_temp();
|
||||||
|
#endif /* DS1820_H */
|
83
platform/guhRF/dev/hw-arduino.h
Normal file
83
platform/guhRF/dev/hw-arduino.h
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Ralf Schlatterbeck Open Source Consulting
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup compatibility Arduino - Contiki
|
||||||
|
*
|
||||||
|
* This defines contiki-compatible hardware definitions for running
|
||||||
|
* arduino sketches (or just to call arduino-compatible function).
|
||||||
|
* For now only for osd hardware, a similar file should exist for each
|
||||||
|
* arduino-compatible hardware.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Header file for arduino compatibility
|
||||||
|
* \author
|
||||||
|
* Ralf Schlatterbeck <rsc@runtux.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The OSD hardware only supports timer 3 for PWM, timer 2 is used by
|
||||||
|
* contiki for sleep/wakeup timing and is not usable for PWM.
|
||||||
|
*/
|
||||||
|
#define digitalPinToTimer(pin) \
|
||||||
|
( (pin) == 2 \
|
||||||
|
? TIMER3A \
|
||||||
|
: ( (pin) == 3 \
|
||||||
|
? TIMER3B \
|
||||||
|
: ((pin == 4) ? TIMER3C : NOT_ON_TIMER) \
|
||||||
|
) \
|
||||||
|
)
|
||||||
|
|
||||||
|
/* Only init timer 3 with phase correct pwm 8-bit and prescaler 64 */
|
||||||
|
#define arduino_pwm_timer_init() \
|
||||||
|
(hwtimer_ini (3, HWT_WGM_PWM_PHASE_8_BIT, HWT_CLOCK_PRESCALER_64, 0))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* VI settings, see coding style
|
||||||
|
* ex:ts=8:et:sw=2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** @} */
|
391
platform/guhRF/dev/i2c.c
Normal file
391
platform/guhRF/dev/i2c.c
Normal file
|
@ -0,0 +1,391 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Ingo Gulyas Intembsys
|
||||||
|
* 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
|
||||||
|
* I2C driver for ATMEGA128rfa1
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Ingo Gulyas Intembsys
|
||||||
|
* office@intembsys.at
|
||||||
|
* www.intembsys.at
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "contiki-conf.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/power.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#if I2C_TD != 0
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include "system_mgmt.h"
|
||||||
|
#define PRINTD(FORMAT,args...) {sleep_acquire_lock(); printf_P(PSTR(FORMAT),##args); sleep_release_lock();}
|
||||||
|
#else
|
||||||
|
#define PRINTD(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WITH_RTDEBUG == 1
|
||||||
|
#include "rtdebug.h"
|
||||||
|
#define RTDEBUG_PUSH(x) rtdebug_push(x)
|
||||||
|
#else
|
||||||
|
#warning "I2C Driver compiling without RTDEBUG!"
|
||||||
|
#define RTDEBUG_PUSH(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TIMEOUT_TIMER
|
||||||
|
#warning "I2C Driver compiling without TIMEOUT!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static int8_t wait_job();
|
||||||
|
static int8_t wait_stop();
|
||||||
|
|
||||||
|
static int8_t i2c_ioctl(const i2c_driver* const me, uint8_t cmd, uint8_t arg);
|
||||||
|
static int8_t i2c_read(const i2c_driver* const me, uint8_t cmd_flags, uint8_t* buffer, uint8_t len);
|
||||||
|
static int8_t i2c_write(const i2c_driver* const me, uint8_t cmd_flags, const uint8_t* data, uint8_t len);
|
||||||
|
|
||||||
|
|
||||||
|
// static linkage of member functions
|
||||||
|
i2c_driver i2c_drv = {i2c_ioctl, i2c_read, i2c_write};
|
||||||
|
// lock spi if driver opened to prevent further opening access
|
||||||
|
static volatile bool i2c_lock = false;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// global functions
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
i2c_driver* i2c_open(void)
|
||||||
|
{
|
||||||
|
if(i2c_lock == true)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_OPEN__DEVICE_BUSY);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_lock = true;
|
||||||
|
power_twi_enable();
|
||||||
|
I2C_INIT();
|
||||||
|
|
||||||
|
TWBR = I2C_FREQ_STANDARD;
|
||||||
|
TWSR &= ~((1<<TWPS1) | (1<<TWPS0));
|
||||||
|
TWSR |= (1<<TWPS0);
|
||||||
|
TWCR = (1<<TWEN);
|
||||||
|
|
||||||
|
return &i2c_drv;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_close(i2c_driver* const me)
|
||||||
|
{
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_CLOSE__NO_DEVICE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_reset();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_reset(void)
|
||||||
|
{
|
||||||
|
TWCR &= ~(1<<TWEN);
|
||||||
|
I2C_DEINIT();
|
||||||
|
power_twi_disable();
|
||||||
|
i2c_lock = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// local helper functions
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifdef TIMEOUT_TIMER
|
||||||
|
static int8_t wait_job()
|
||||||
|
{
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
uint16_t timeout = TIMEOUT_TIMER_NOW_ADD(I2C_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
|
while (!(TWCR & (1<<TWINT)))
|
||||||
|
{
|
||||||
|
if(!(TIMEOUT_TIMER_LT(TIMEOUT_TIMER_NOW(), timeout)))
|
||||||
|
{
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t wait_stop()
|
||||||
|
{
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
uint16_t timeout = TIMEOUT_TIMER_NOW_ADD(I2C_TIMEOUT);
|
||||||
|
|
||||||
|
|
||||||
|
while (TWCR & (1<<TWSTO))
|
||||||
|
{
|
||||||
|
if(!(TIMEOUT_TIMER_LT(TIMEOUT_TIMER_NOW(), timeout)))
|
||||||
|
{
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static int8_t wait_job()
|
||||||
|
{
|
||||||
|
while (!(TWCR & (1<<TWINT)));
|
||||||
|
return I2C_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t wait_stop()
|
||||||
|
{
|
||||||
|
while (TWCR & (1<<TWSTO));
|
||||||
|
return I2C_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
// member functions
|
||||||
|
///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static int8_t i2c_ioctl(const i2c_driver* const me, uint8_t cmd, uint8_t arg)
|
||||||
|
{
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_IOCTL__DEVICE_CLOSED);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cmd == I2C_IOCTL_CMD_SET_FREQ)
|
||||||
|
{
|
||||||
|
switch(arg)
|
||||||
|
{
|
||||||
|
case I2C_FREQ_400KHZ: TWBR = I2C_FREQ_400KHZ; break;
|
||||||
|
case I2C_FREQ_250KHZ: TWBR = I2C_FREQ_250KHZ; break;
|
||||||
|
case I2C_FREQ_100KHZ: TWBR = I2C_FREQ_100KHZ; break;
|
||||||
|
case I2C_FREQ_50KHZ: TWBR = I2C_FREQ_50KHZ; break;
|
||||||
|
case I2C_FREQ_10KHZ: TWBR = I2C_FREQ_10KHZ; break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_IOCTL__ARG_INVALID);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_IOCTL__CMD_INVALID);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return I2C_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t i2c_read(const i2c_driver* const me, uint8_t cmd_flags, uint8_t* buffer, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
|
||||||
|
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__DEVICE_CLOSED);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((len > 0) && (buffer == NULL))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__ERROR_NULLPOINTER);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_START)
|
||||||
|
{
|
||||||
|
I2C_START();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__START_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((I2C_STATUS() != I2C_STATUS_START) && (I2C_STATUS() != I2C_STATUS_START_REP))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__START_ERROR);
|
||||||
|
status = I2C_ERROR_START;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-RD-START\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(len == 0) break;
|
||||||
|
|
||||||
|
for(i=0; i<(len-1); i++)
|
||||||
|
{
|
||||||
|
I2C_READ_BYTE_ACK();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_ACK_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(I2C_STATUS() != I2C_STATUS_DATAR_ACK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_ACK_ERROR);
|
||||||
|
status = I2C_ERROR_READ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer[i] = I2C_RX_REG;
|
||||||
|
PRINTD("I2C-RD-RACK: 0x%02X\n", buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
I2C_READ_BYTE_NACK();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_NACK_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(I2C_STATUS() != I2C_STATUS_DATAR_NACK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__READ_BYTE_NACK_ERROR);
|
||||||
|
status = I2C_ERROR_READ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffer[i] = I2C_RX_REG;
|
||||||
|
PRINTD("I2C-RD-RNACK: 0x%02X\n", buffer[i]);
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_STOP)
|
||||||
|
{
|
||||||
|
I2C_STOP();
|
||||||
|
if(wait_stop() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_READ__STOP_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-RD_STOP\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int8_t i2c_write(const i2c_driver* const me, uint8_t cmd_flags, const uint8_t* data, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i = 0;
|
||||||
|
int8_t status = I2C_OK;
|
||||||
|
|
||||||
|
|
||||||
|
if(me == NULL || i2c_lock == false)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__DEVICE_CLOSED);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((len > 0) && (data == NULL))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__ERROR_NULLPOINTER);
|
||||||
|
return I2C_ERROR_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_START)
|
||||||
|
{
|
||||||
|
I2C_START();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__START_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((I2C_STATUS() != I2C_STATUS_START) && (I2C_STATUS() != I2C_STATUS_START_REP))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__START_ERROR);
|
||||||
|
status = I2C_ERROR_START;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-WR-START\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for(i=0; i<len; i++)
|
||||||
|
{
|
||||||
|
I2C_TX_REG = data[i];
|
||||||
|
I2C_WRITE_BYTE();
|
||||||
|
if(wait_job() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__WRITE_BYTE_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if((I2C_STATUS() != I2C_STATUS_DATAW_ACK) && (I2C_STATUS() != I2C_STATUS_SLAW_ACK) && (I2C_STATUS() != I2C_STATUS_SLAR_ACK))
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__WRITE_BYTE_ERROR);
|
||||||
|
status = I2C_ERROR_WRITE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-WR-BYTE: 0x%02X\n", data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
if(cmd_flags & I2C_CMD_FLAG_STOP)
|
||||||
|
{
|
||||||
|
I2C_STOP();
|
||||||
|
if(wait_stop() != I2C_OK)
|
||||||
|
{
|
||||||
|
RTDEBUG_PUSH(RTDEBUG_CODE__I2C_WRITE__STOP_TIMEOUT);
|
||||||
|
status = I2C_ERROR_TIMEOUT;
|
||||||
|
}
|
||||||
|
PRINTD("I2C-WR-STOP\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
131
platform/guhRF/dev/i2c.h
Normal file
131
platform/guhRF/dev/i2c.h
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Ingo Gulyas Intembsys
|
||||||
|
* 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
|
||||||
|
* I2C driver for ATMEGA128rfa1
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Ingo Gulyas Intembsys
|
||||||
|
* office@intembsys.at
|
||||||
|
* www.intembsys.at
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef I2C_H_
|
||||||
|
#define I2C_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CONFIGURATION SECTION:
|
||||||
|
|
||||||
|
#define I2C_TD 0 // compiler switch: i2c testdriver code
|
||||||
|
|
||||||
|
#define I2C_PORT PORTD
|
||||||
|
#define I2C_DDR DDRD
|
||||||
|
#define I2C_SCL_PIN 0
|
||||||
|
#define I2C_SDA_PIN 1
|
||||||
|
|
||||||
|
// END OF CONFIGURATION SECTION
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define I2C_INIT() ({I2C_DDR &= ~((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN)); I2C_PORT |= ((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN));})
|
||||||
|
#define I2C_DEINIT() ({I2C_DDR &= ~((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN)); I2C_PORT |= ((1<<I2C_SCL_PIN) | (1<<I2C_SDA_PIN));})
|
||||||
|
|
||||||
|
#define I2C_FREQ_STANDARD I2C_FREQ_50KHZ
|
||||||
|
|
||||||
|
#if F_CPU == 16000000UL
|
||||||
|
#define I2C_FREQ_400KHZ 0x03
|
||||||
|
#define I2C_FREQ_250KHZ 0x06
|
||||||
|
#define I2C_FREQ_100KHZ 0x12
|
||||||
|
#define I2C_FREQ_50KHZ 0x26
|
||||||
|
#define I2C_FREQ_10KHZ 0xC6
|
||||||
|
#else
|
||||||
|
#error "NO I2C FREQUENCY DEFINED -> CHECK F_CPU SETTINGS!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_STATUS_REG TWSR
|
||||||
|
#define I2C_TX_REG TWDR
|
||||||
|
#define I2C_RX_REG TWDR
|
||||||
|
|
||||||
|
#define I2C_START() (TWCR = (1<<TWINT) |(1<<TWSTA) | (1<<TWEN))
|
||||||
|
#define I2C_STOP() (TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO))
|
||||||
|
#define I2C_WRITE_BYTE() (TWCR = (1<<TWINT) | (1<<TWEN))
|
||||||
|
#define I2C_READ_BYTE_ACK() (TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA))
|
||||||
|
#define I2C_READ_BYTE_NACK() (TWCR = (1<<TWINT) | (1<<TWEN))
|
||||||
|
#define I2C_STATUS() (I2C_STATUS_REG & I2C_STATUS_MASK)
|
||||||
|
|
||||||
|
#define I2C_STATUS_MASK 0xF8
|
||||||
|
#define I2C_STATUS_START 0x08
|
||||||
|
#define I2C_STATUS_START_REP 0x10
|
||||||
|
#define I2C_STATUS_SLAW_ACK 0x18
|
||||||
|
#define I2C_STATUS_DATAW_ACK 0x28
|
||||||
|
#define I2C_STATUS_SLAR_ACK 0x40
|
||||||
|
#define I2C_STATUS_DATAR_ACK 0x50
|
||||||
|
#define I2C_STATUS_DATAR_NACK 0x58
|
||||||
|
|
||||||
|
#define I2C_ADR_WR(adr) ((adr<<1) & ~(1<<0))
|
||||||
|
#define I2C_ADR_RD(adr) ((adr<<1) | (1<<0))
|
||||||
|
|
||||||
|
#define I2C_CMD_FLAG_NONE 0x00
|
||||||
|
#define I2C_CMD_FLAG_START (1<<0)
|
||||||
|
#define I2C_CMD_FLAG_STOP (1<<1)
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_OK 0
|
||||||
|
#define I2C_ERROR_DRIVER -1
|
||||||
|
#define I2C_ERROR_TIMEOUT -2
|
||||||
|
#define I2C_ERROR_START -3
|
||||||
|
#define I2C_ERROR_WRITE -4
|
||||||
|
#define I2C_ERROR_READ -5
|
||||||
|
|
||||||
|
|
||||||
|
#define I2C_IOCTL_CMD_SET_FREQ 0x01
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct i2c_driver i2c_driver;
|
||||||
|
struct i2c_driver
|
||||||
|
{
|
||||||
|
int8_t (*ioctl)(const i2c_driver* const me, uint8_t cmd, uint8_t arg);
|
||||||
|
int8_t (*read)(const i2c_driver* const me, uint8_t cmd_flags, uint8_t* buffer, uint8_t len);
|
||||||
|
int8_t (*write)(const i2c_driver* const me, uint8_t cmd_flags, const uint8_t* data, uint8_t len);
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_driver* i2c_open(void);
|
||||||
|
void i2c_close(i2c_driver* const me);
|
||||||
|
void i2c_reset(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* I2C_H_ */
|
73
platform/guhRF/dev/key.c
Normal file
73
platform/guhRF/dev/key.c
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 harald pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven KEY support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "key.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief This will intialize the KEY for button readings.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
key_init(void)
|
||||||
|
{
|
||||||
|
/* Enter is input w/pullup */
|
||||||
|
DDRF &= ~(1<<PINF1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief This will poll run key_task() to determine if a button has been pressed.
|
||||||
|
*
|
||||||
|
* \retval True if button is pressed
|
||||||
|
* \retval False if button is not pressed
|
||||||
|
*/
|
||||||
|
uint8_t
|
||||||
|
is_button(void)
|
||||||
|
{
|
||||||
|
/* Return true if button has been pressed. */
|
||||||
|
if ( PINF & (1<<PINF1) ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
50
platform/guhRF/dev/key.h
Normal file
50
platform/guhRF/dev/key.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Harald Pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven Key support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pixhlwe harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __KEY_H__
|
||||||
|
#define __KEY_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
void key_init(void);
|
||||||
|
uint8_t is_button(void);
|
||||||
|
|
||||||
|
#endif /* __KEY_H__ */
|
72
platform/guhRF/dev/led.c
Normal file
72
platform/guhRF/dev/led.c
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 harald pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides guhRF LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
* Bernhard Trinnes bernhard.trinnes@guh.guru
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup relay
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns the LED1 on.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
led1_off(void)
|
||||||
|
{
|
||||||
|
PORTE &= ~(1<<PINE5);
|
||||||
|
DDRE |= (1<<PINE5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns the LED1 off.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
led1_on(void)
|
||||||
|
{
|
||||||
|
PORTE |= (1<<PINE5);
|
||||||
|
DDRE |= (1<<PINE5);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
52
platform/guhRF/dev/led.h
Normal file
52
platform/guhRF/dev/led.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Harald Pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LED_H__
|
||||||
|
#define __LED_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/** @name LED Functions */
|
||||||
|
/** @{ */
|
||||||
|
void led1_on(void);
|
||||||
|
void led1_off(void);
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif /* __LED_H__ */
|
71
platform/guhRF/dev/leds-arch.c
Normal file
71
platform/guhRF/dev/leds-arch.c
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 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.
|
||||||
|
*
|
||||||
|
* $Id: leds-arch.c,v 1.1 2006/06/17 22:41:31 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Leds arch. for STK600-Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Paulo Louro <paulolouro@binarylabs.dk>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// WARNING : Blink function is disabled on the core leds.c file
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/leds.h"
|
||||||
|
#include "leds-arch.h"
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
leds_arch_init(void)
|
||||||
|
{
|
||||||
|
DDRE |= (1<<DDRE5); // Set pins as output since leds are mounted on the VDD bus
|
||||||
|
LEDS_OFF();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
unsigned char
|
||||||
|
leds_arch_get(void)
|
||||||
|
{
|
||||||
|
return ((LED_OUT & BIT_GREEN) ? 1 : 0);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
leds_arch_set(unsigned char leds)
|
||||||
|
{
|
||||||
|
if(leds & LEDS_GREEN) {
|
||||||
|
LED_GREEN_ON();
|
||||||
|
} else {
|
||||||
|
LED_GREEN_OFF();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
26
platform/guhRF/dev/leds-arch.h
Normal file
26
platform/guhRF/dev/leds-arch.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
guhRF Platform has just one green LED on PIN E5
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LEDS_ARCH_H__
|
||||||
|
#define __LEDS_ARCH_H__
|
||||||
|
|
||||||
|
#define LED_OUT PORTE
|
||||||
|
|
||||||
|
#define BIT_GREEN _BV(PE5)
|
||||||
|
|
||||||
|
#define LED_GREEN_OFF() LED_OUT &= ~BIT_GREEN
|
||||||
|
#define LED_GREEN_ON() LED_OUT |= BIT_GREEN
|
||||||
|
|
||||||
|
#define LED_GREEN_TOGGLE() LED_OUT ^= BIT_GREEN
|
||||||
|
|
||||||
|
#define LEDS_OFF() LED_OUT &= ~BIT_GREEN
|
||||||
|
#define LEDS_ON() LED_OUT |= BIT_GREEN
|
||||||
|
|
||||||
|
|
||||||
|
void leds_arch_init(void);
|
||||||
|
unsigned char leds_arch_get(void);
|
||||||
|
void leds_arch_set(unsigned char leds);
|
||||||
|
|
||||||
|
#endif /* __LEDS_ARCH_H__ */
|
102
platform/guhRF/dev/optriac-sensor.c
Normal file
102
platform/guhRF/dev/optriac-sensor.c
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.c,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* optriac sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "dev/optriac-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
const struct sensors_sensor optriac_sensor;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
static int optriac[2]={0,0};
|
||||||
|
static int optriacpin[8]={OPTRIAC_PIN_1,OPTRIAC_PIN_2};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return optriac[type];
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
pinMode(optriacpin[OPTRIAC_SENSOR_1], OUTPUT);
|
||||||
|
digitalWrite(optriacpin[OPTRIAC_SENSOR_1], LOW);
|
||||||
|
pinMode(optriacpin[OPTRIAC_SENSOR_2], OUTPUT);
|
||||||
|
digitalWrite(optriacpin[OPTRIAC_SENSOR_2], LOW);
|
||||||
|
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPTRIAC_SENSOR_1:
|
||||||
|
case OPTRIAC_SENSOR_2:
|
||||||
|
|
||||||
|
if(c==0){
|
||||||
|
digitalWrite(optriacpin[type], LOW);
|
||||||
|
optriac[type]=0;
|
||||||
|
}else{
|
||||||
|
digitalWrite(optriacpin[type], HIGH);
|
||||||
|
optriac[type]=1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(optriac_sensor, OPTRIAC_SENSOR, value, configure, status);
|
54
platform/guhRF/dev/optriac-sensor.h
Normal file
54
platform/guhRF/dev/optriac-sensor.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c), Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.h,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Servo sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __OPTRIAC_SENSOR_H__
|
||||||
|
#define __OPTRIAC_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor optriac_sensor;
|
||||||
|
|
||||||
|
#define OPTRIAC_SENSOR "TRIAC"
|
||||||
|
#define OPTRIAC_SENSOR_1 0
|
||||||
|
#define OPTRIAC_SENSOR_2 1
|
||||||
|
|
||||||
|
/* default pins Arduino-Merkurboard */
|
||||||
|
#define OPTRIAC_PIN_1 2
|
||||||
|
#define OPTRIAC_PIN_2 3
|
||||||
|
|
||||||
|
#endif /* __OPTRIAC_SENSOR_H__ */
|
218
platform/guhRF/dev/pins_arduino.h
Normal file
218
platform/guhRF/dev/pins_arduino.h
Normal file
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
pins_arduino.h - Pin definition functions for Arduino
|
||||||
|
Part of Arduino - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2014 Harald Pichler
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General
|
||||||
|
Public License along with this library; if not, write to the
|
||||||
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
$Id: wiring.h 249 2014-04-18 17:35:12Z pichler $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This version of pins_arduino.h is for the Merkur Dev Board r1
|
||||||
|
Harald Pichler 2014 Apr 18
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Pins_Arduino_h
|
||||||
|
#define Pins_Arduino_h
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#define NUM_DIGITAL_PINS 15
|
||||||
|
#define NUM_ANALOG_INPUTS 6
|
||||||
|
#define analogInputToDigitalPin(p) ((p < NUM_ANALOG_INPUTS) ? (p) + NUM_DIGITAL_PINS : -1)
|
||||||
|
#define digitalPinHasPWM(p) ((p) == 2 ||(p) == 3 ||(p) == 4 ||(p) == 14 )
|
||||||
|
|
||||||
|
// Dev board specific defines: RF RX and TX LEDs:
|
||||||
|
#define RXLED_DDR DDRB
|
||||||
|
#define RXLED_PORT PORTB
|
||||||
|
#define RXLED_POS PB6
|
||||||
|
|
||||||
|
#define TXLED_DDR DDRB
|
||||||
|
#define TXLED_PORT PORTB
|
||||||
|
#define TXLED_POS PB7
|
||||||
|
|
||||||
|
const static uint8_t SS = 10;
|
||||||
|
const static uint8_t MOSI = 11;
|
||||||
|
const static uint8_t MISO = 13;
|
||||||
|
const static uint8_t SCK = 12;
|
||||||
|
|
||||||
|
const static uint8_t SDA = 9;
|
||||||
|
const static uint8_t SCL = 8;
|
||||||
|
const static uint8_t LED = 4;
|
||||||
|
const static uint8_t LED1 = 4;
|
||||||
|
const static uint8_t LED2 = 5;
|
||||||
|
|
||||||
|
const static uint8_t A0 = 7;
|
||||||
|
const static uint8_t A1 = 6;
|
||||||
|
const static uint8_t A2 = 5;
|
||||||
|
const static uint8_t A3 = 4;
|
||||||
|
const static uint8_t A4 = 0;
|
||||||
|
const static uint8_t A5 = 1;
|
||||||
|
|
||||||
|
// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
|
||||||
|
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
|
||||||
|
// Pins: 10, 11, 12, 13, 14
|
||||||
|
|
||||||
|
#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 14)) || ? (&PCICR) : ((uint8_t *)0) )
|
||||||
|
|
||||||
|
#define digitalPinToPCICRbit(p) ( 0 )
|
||||||
|
|
||||||
|
#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 14)) ? (&PCMSK0) : ((uint8_t *)0) )
|
||||||
|
|
||||||
|
#define digitalPinToPCMSKbit(p) ( ((p) == 10) ? 6 : \
|
||||||
|
( ((p) == 11) ? 5 : \
|
||||||
|
( ((p) == 12) ? 1 : \
|
||||||
|
( ((p) == 13) ? 3 : \
|
||||||
|
( ((p) == 14) ? 7 : \
|
||||||
|
0 ) ) ) ) )
|
||||||
|
|
||||||
|
#ifdef ARDUINO_MAIN
|
||||||
|
|
||||||
|
const uint16_t PROGMEM port_to_mode_PGM[] = {
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&DDRB,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&DDRD,
|
||||||
|
(uint16_t)&DDRE,
|
||||||
|
(uint16_t)&DDRF,
|
||||||
|
(uint16_t)&DDRG,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM port_to_output_PGM[] = {
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&PORTB,
|
||||||
|
NOT_A_PORT,
|
||||||
|
(uint16_t)&PORTD,
|
||||||
|
(uint16_t)&PORTE,
|
||||||
|
(uint16_t)&PORTF,
|
||||||
|
(uint16_t)&PORTG,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
NOT_A_PORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM port_to_input_PGM[] = {
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
(uint16_t)&PINC,
|
||||||
|
(uint16_t)&PIND,
|
||||||
|
(uint16_t)&PINE,
|
||||||
|
(uint16_t)&PINF,
|
||||||
|
(uint16_t)&PING,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
NOT_A_PIN,
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
|
||||||
|
// PORTLIST
|
||||||
|
// -------------------------------------------
|
||||||
|
PE , // PE 1 ** 0 ** D0 / USART0_TX
|
||||||
|
PE , // PE 0 ** 1 ** D1 / USART0_RX
|
||||||
|
PE , // PE 3 ** 2 ** D2 / PWM
|
||||||
|
PE , // PE 4 ** 3 ** D3 / PWM
|
||||||
|
PE , // PE 5 ** 4 ** D4 / PWM / LED1 / LED
|
||||||
|
PE , // PE 6 ** 5 ** D5 / LED2
|
||||||
|
PD , // PD 3 ** 6 ** D6 / USART1_TX
|
||||||
|
PD , // PD 2 ** 7 ** D7 / USART1_RX
|
||||||
|
PD , // PD 0 ** 8 ** D8 / I2C_SCL
|
||||||
|
PD , // PD 1 ** 9 ** D9 / I2C_SDA
|
||||||
|
PB , // PB 0 ** 10 ** D10 / SPI_SSN
|
||||||
|
PB , // PB 2 ** 11 ** D11 / SPI_MOSI
|
||||||
|
PB , // PB 1 ** 12 ** D12 / SPI_SCK
|
||||||
|
PB , // PB 3 ** 13 ** D13 / SPI_MISO
|
||||||
|
PB , // PB 4 ** 14 ** D14 / PWM
|
||||||
|
PF , // PF 7 ** 15 ** A0 / D15
|
||||||
|
PF , // PF 6 ** 16 ** A1 / D16
|
||||||
|
PF , // PF 5 ** 17 ** A2 / D17
|
||||||
|
PF , // PF 4 ** 18 ** A3 / D18
|
||||||
|
PF , // PF 0 ** 19 ** A4 / D19
|
||||||
|
PF , // PF 1 ** 20 ** A5 / D20
|
||||||
|
// PB , // PB 6 ** 34 ** D34 / LED1 / LED / PWM
|
||||||
|
// PB , // PB 7 ** 35 ** D35 / LED2 / PWM
|
||||||
|
// PE , // PE 2 ** 2 ** D2
|
||||||
|
// PE , // PE 7 ** 7 ** D7
|
||||||
|
// PB , // PB 5 ** 8 ** D8 / PWM
|
||||||
|
// PG , // PG 0 ** 16 ** D16
|
||||||
|
// PG , // PG 1 ** 17 ** D17
|
||||||
|
// PG , // PG 2 ** 18 ** D18
|
||||||
|
// PG , // PG 5 ** 19 ** D19 / PWM
|
||||||
|
// PD , // PD 4 ** 22 ** D22
|
||||||
|
// PD , // PD 5 ** 23 ** D23
|
||||||
|
// PD , // PD 6 ** 24 ** D24
|
||||||
|
// PD , // PD 7 ** 25 ** D25
|
||||||
|
// PF , // PF 2 ** 28 ** A2 / D28
|
||||||
|
// PF , // PF 3 ** 29 ** A3 / D29
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
|
||||||
|
// PIN IN PORT
|
||||||
|
// -------------------------------------------
|
||||||
|
_BV( 1 ) , // PE 1 ** 0 ** USART0_TX
|
||||||
|
_BV( 0 ) , // PE 0 ** 1 ** USART0_RX
|
||||||
|
_BV( 3 ) , // PE 3 ** 2 ** D3 / PWM
|
||||||
|
_BV( 4 ) , // PE 4 ** 3 ** D4 / PWM
|
||||||
|
_BV( 5 ) , // PE 5 ** 4 ** D5 / PWM
|
||||||
|
_BV( 6 ) , // PE 6 ** 5 ** D6
|
||||||
|
_BV( 3 ) , // PD 3 ** 6 ** D21 / USART1_TX
|
||||||
|
_BV( 2 ) , // PD 2 ** 7 ** D20 / USART1_RX
|
||||||
|
_BV( 0 ) , // PD 0 ** 8 ** D15 / I2C_SCL
|
||||||
|
_BV( 1 ) , // PD 1 ** 9 ** D14 / I2C_SDA
|
||||||
|
_BV( 0 ) , // PB 0 ** 10 ** D10 / SPI_SSN
|
||||||
|
_BV( 2 ) , // PB 2 ** 11 ** D11 / SPI_MOSI
|
||||||
|
_BV( 1 ) , // PB 1 ** 12 ** D13 / SPI_SCK
|
||||||
|
_BV( 3 ) , // PB 3 ** 13 ** D12 / SPI_MISO
|
||||||
|
_BV( 4 ) , // PB 4 ** 14 ** D9 / PWM
|
||||||
|
_BV( 7 ) , // PF 7 ** 15 ** A0 / D33
|
||||||
|
_BV( 6 ) , // PF 6 ** 16 ** A1 / D32
|
||||||
|
_BV( 5 ) , // PF 5 ** 17 ** A2 / D31
|
||||||
|
_BV( 4 ) , // PF 4 ** 18 ** A3 / D30
|
||||||
|
_BV( 0 ) , // PF 0 ** 19 ** A4 / D26
|
||||||
|
_BV( 1 ) , // PF 1 ** 20 ** A5 / D27
|
||||||
|
// _BV( 2 ) , // PE 2 ** 2 ** D2
|
||||||
|
// _BV( 7 ) , // PE 7 ** 7 ** D7
|
||||||
|
// _BV( 5 ) , // PB 5 ** 8 ** D8 / PWM
|
||||||
|
// _BV( 0 ) , // PG 0 ** 16 ** D16
|
||||||
|
// _BV( 1 ) , // PG 1 ** 17 ** D17
|
||||||
|
// _BV( 2 ) , // PG 2 ** 18 ** D18
|
||||||
|
// _BV( 5 ) , // PG 5 ** 19 ** D19 / PWM
|
||||||
|
// _BV( 4 ) , // PD 4 ** 22 ** D22
|
||||||
|
// _BV( 5 ) , // PD 5 ** 23 ** D23
|
||||||
|
// _BV( 6 ) , // PD 6 ** 24 ** D24
|
||||||
|
// _BV( 7 ) , // PD 7 ** 25 ** D25
|
||||||
|
// _BV( 2 ) , // PF 2 ** 28 ** A2 / D28
|
||||||
|
// _BV( 3 ) , // PF 3 ** 29 ** A3 / D29
|
||||||
|
// _BV( 6 ) , // PB 6 ** 34 ** D34 / LED1 / LED / PWM
|
||||||
|
// _BV( 7 ) , // PB 7 ** 35 ** D35 / LED2 / PWM
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
85
platform/guhRF/dev/pir-sensor.c
Normal file
85
platform/guhRF/dev/pir-sensor.c
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/* Sensor routine */
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/pir-sensor.h"
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include "led.h" // debug
|
||||||
|
|
||||||
|
const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
|
static struct timer debouncetimer;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
struct sensors_sensor *sensors[1];
|
||||||
|
unsigned char sensors_flags[1];
|
||||||
|
|
||||||
|
#define PIR_BIT INTF6
|
||||||
|
#define PIR_CHECK_IRQ() (EIFR & PIR_BIT) ? 0 : 1
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
ISR(INT6_vect)
|
||||||
|
{
|
||||||
|
|
||||||
|
// leds_toggle(LEDS_YELLOW);
|
||||||
|
|
||||||
|
if(PIR_CHECK_IRQ()) {
|
||||||
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
// led1_on();
|
||||||
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
|
sensors_changed(&pir_sensor);
|
||||||
|
// led1_off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return (PORTE & _BV(PE6) ? 0 : 1) || !timer_expired(&debouncetimer);
|
||||||
|
//return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if (c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
// led1_on();
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
|
DDRE |= (0<<DDRE6); // Set pin as input
|
||||||
|
PORTE |= (1<<PORTE6); // Set port PORTE bint 6 with pullup resistor
|
||||||
|
EICRB |= (3<<ISC60); // For rising edge
|
||||||
|
EIMSK |= (1<<INT6); // Set int
|
||||||
|
enabled = 1;
|
||||||
|
sei();
|
||||||
|
// led1_off();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 0;
|
||||||
|
EIMSK &= ~(1<<INT6); // clear int
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;//(EIMSK & (1<<INT6) ? 0 : 1);//PIR_IRQ_ENABLED();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
|
||||||
|
value, configure, status);
|
||||||
|
|
48
platform/guhRF/dev/pir-sensor.h
Normal file
48
platform/guhRF/dev/pir-sensor.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* PIR sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PIR_SENSOR_H__
|
||||||
|
#define __PIR_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
|
#define PIR_SENSOR "PIR"
|
||||||
|
|
||||||
|
#endif /* __PIR_SENSOR_H__ */
|
109
platform/guhRF/dev/relay-sensor.c
Normal file
109
platform/guhRF/dev/relay-sensor.c
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: relay-sensor.c,v 1.0 2013/11/22 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* relay sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/relay.h"
|
||||||
|
#include "dev/relay-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
const struct sensors_sensor relay_sensor;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
static int relay[8]={0,0,0,0,0,0,0,0};
|
||||||
|
static int relaypin[8]={RELAY_PIN_1,RELAY_PIN_2,RELAY_PIN_3,RELAY_PIN_4,RELAY_PIN_5,RELAY_PIN_6,RELAY_PIN_7,RELAY_PIN_8};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return relay[type];
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_1]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_2]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_3]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_4]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_5]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_6]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_7]);
|
||||||
|
relay_init(relaypin[RELAY_SENSOR_8]);
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case RELAY_SENSOR_1:
|
||||||
|
case RELAY_SENSOR_2:
|
||||||
|
case RELAY_SENSOR_3:
|
||||||
|
case RELAY_SENSOR_4:
|
||||||
|
case RELAY_SENSOR_5:
|
||||||
|
case RELAY_SENSOR_6:
|
||||||
|
case RELAY_SENSOR_7:
|
||||||
|
case RELAY_SENSOR_8:
|
||||||
|
if(c==0){
|
||||||
|
relay_off(relaypin[type]);
|
||||||
|
relay[type]=0;
|
||||||
|
}else{
|
||||||
|
relay_on(relaypin[type]);
|
||||||
|
relay[type]=1;
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(relay_sensor, RELAY_SENSOR, value, configure, status);
|
66
platform/guhRF/dev/relay-sensor.h
Normal file
66
platform/guhRF/dev/relay-sensor.h
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c), Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: relay-sensor.h,v 1.0 2013/11/22 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Relay sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RELAY_SENSOR_H__
|
||||||
|
#define __RELAY_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor relay_sensor;
|
||||||
|
|
||||||
|
#define RELAY_SENSOR "RELAY"
|
||||||
|
#define RELAY_SENSOR_1 0
|
||||||
|
#define RELAY_SENSOR_2 1
|
||||||
|
#define RELAY_SENSOR_3 2
|
||||||
|
#define RELAY_SENSOR_4 3
|
||||||
|
#define RELAY_SENSOR_5 4
|
||||||
|
#define RELAY_SENSOR_6 5
|
||||||
|
#define RELAY_SENSOR_7 6
|
||||||
|
#define RELAY_SENSOR_8 7
|
||||||
|
|
||||||
|
/* default pins Arduino-Merkurboard */
|
||||||
|
#define RELAY_PIN_1 10
|
||||||
|
#define RELAY_PIN_2 11
|
||||||
|
#define RELAY_PIN_3 12
|
||||||
|
#define RELAY_PIN_4 13
|
||||||
|
#define RELAY_PIN_5 15
|
||||||
|
#define RELAY_PIN_6 16
|
||||||
|
#define RELAY_PIN_7 17
|
||||||
|
#define RELAY_PIN_8 18
|
||||||
|
|
||||||
|
#endif /* __RELAY_SENSOR_H__ */
|
76
platform/guhRF/dev/relay.c
Normal file
76
platform/guhRF/dev/relay.c
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 harald pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "relay.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \addtogroup relay
|
||||||
|
* \{
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief init RELAY PINS.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
relay_init(uint8_t pin)
|
||||||
|
{
|
||||||
|
pinMode(pin, OUTPUT);
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* \brief Turns the RELAY on.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
relay_on(uint8_t pin)
|
||||||
|
{
|
||||||
|
digitalWrite(pin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Turns the RELAY off
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
relay_off(uint8_t pin)
|
||||||
|
{
|
||||||
|
digitalWrite(pin, LOW);
|
||||||
|
}
|
54
platform/guhRF/dev/relay.h
Normal file
54
platform/guhRF/dev/relay.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012 Harald Pichler
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
*
|
||||||
|
* \brief
|
||||||
|
* This file provides Raven LED support.
|
||||||
|
*
|
||||||
|
* \author
|
||||||
|
* Harald Pichler harald@the-develop.net
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RELAY_H__
|
||||||
|
#define __RELAY_H__
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/** @name RELAY Functions */
|
||||||
|
/** @{ */
|
||||||
|
void relay_init(uint8_t pin);
|
||||||
|
void relay_on(uint8_t pin);
|
||||||
|
void relay_off(uint8_t pin);
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif /* __RELAY_H__ */
|
100
platform/guhRF/dev/servo-sensor.c
Normal file
100
platform/guhRF/dev/servo-sensor.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.c,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Servo sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/servo.h"
|
||||||
|
#include "dev/servo-sensor.h"
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
|
const struct sensors_sensor servo_sensor;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SERVO_SENSOR_A:
|
||||||
|
return servo_get(0);;
|
||||||
|
|
||||||
|
/* Total Solar Radiation. */
|
||||||
|
case SERVO_SENSOR_B:
|
||||||
|
return servo_get(1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if(c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
servo_init();
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
servo_off();
|
||||||
|
enabled = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SERVO_SENSOR_A:
|
||||||
|
servo_set(0,c);
|
||||||
|
break;
|
||||||
|
case SERVO_SENSOR_B:
|
||||||
|
servo_set(1,c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(servo_sensor, SERVO_SENSOR, value, configure, status);
|
50
platform/guhRF/dev/servo-sensor.h
Normal file
50
platform/guhRF/dev/servo-sensor.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c), Harald Pichler.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: servo-sensor.h,v 1.0 2013/02/20 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Servo sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVO_SENSOR_H__
|
||||||
|
#define __SERVO_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor servo_sensor;
|
||||||
|
|
||||||
|
#define SERVO_SENSOR "Servo"
|
||||||
|
#define SERVO_SENSOR_A 0
|
||||||
|
#define SERVO_SENSOR_B 1
|
||||||
|
|
||||||
|
#endif /* __SERVO_SENSOR_H__ */
|
152
platform/guhRF/dev/servo.c
Normal file
152
platform/guhRF/dev/servo.c
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007, 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Device driver for the Sensirion SHT1x/SHT7x family of humidity and
|
||||||
|
* temperature sensors.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dev/servo.h>
|
||||||
|
|
||||||
|
#define DEBUG 0
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#include <stdio.h>
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* servo device
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned int servoa=SERVO_INIT;
|
||||||
|
unsigned int servob=SERVO_INIT;
|
||||||
|
|
||||||
|
void
|
||||||
|
servo_init(void)
|
||||||
|
{
|
||||||
|
// Port E initialization
|
||||||
|
// Set Pin 3 and 4 to output mode for OCR1A and OCR2A
|
||||||
|
DDRE |= 1<<3 | 1<<4;
|
||||||
|
|
||||||
|
// Timer/Counter 3 initialization
|
||||||
|
// Clock source: System Clock
|
||||||
|
// Clock value: 2000.000 kHz
|
||||||
|
// Mode: Ph. & fr. cor. PWM top=ICR1
|
||||||
|
// OC3A output: Connected
|
||||||
|
// OC3B output: Connected
|
||||||
|
// OC3C output: Connected
|
||||||
|
// Noise Canceler: Off
|
||||||
|
// Input Capture on Falling Edge
|
||||||
|
// Timer3 Overflow Interrupt: Off
|
||||||
|
// Input Capture Interrupt: Off
|
||||||
|
// Compare A Match Interrupt: Off
|
||||||
|
// Compare B Match Interrupt: Off
|
||||||
|
// Compare C Match Interrupt: Off
|
||||||
|
|
||||||
|
/* TCCR3A = [COM3A1|COM3A0|COM3B1|COM3B0||FOC3A|FOC3B|WGM31|WGM30] */
|
||||||
|
/* 1 0 1 0 1 0 0 0 */
|
||||||
|
TCCR3A=0xA8;
|
||||||
|
/* TCCR3B = [ ICNC3| ICES3| -| WGM33||WGM32| CS32| CS31| CS30] */
|
||||||
|
/* 0 0 0 1 0 0 1 0 */
|
||||||
|
TCCR3B=0x12;
|
||||||
|
TCNT3H=0x00;
|
||||||
|
TCNT3L=0x00;
|
||||||
|
// ICR3 has a computed value of 20,000 - see the chip manual for how this
|
||||||
|
// value was derived.
|
||||||
|
// 20000 == 0x4e20 so that's what goes into the high and low byte of the ICR3 register
|
||||||
|
// alternatively, Codevision would let you just do ICR3 = 20000;
|
||||||
|
ICR3H=0x4E;
|
||||||
|
ICR3L=0x20;
|
||||||
|
|
||||||
|
// OCR3A will govern the steering servo, OCR3B will govern throttle
|
||||||
|
OCR3A = servoa; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
||||||
|
|
||||||
|
// OCR3A will govern the steering servo, OCR3B will govern throttle
|
||||||
|
OCR3B = servob; // set it to an initial position somewhere in the middle of the 1 to 2ms range
|
||||||
|
// start with motor off - no duty cycle at all
|
||||||
|
OCR3CH=0x00;
|
||||||
|
OCR3CL=0x00;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Power of device.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
servo_off(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* get servo position
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
servo_get(unsigned int i)
|
||||||
|
{
|
||||||
|
if(i==0)
|
||||||
|
return servoa;
|
||||||
|
if(i==1)
|
||||||
|
return servob;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Set servo position
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
servo_set(unsigned i,unsigned int j)
|
||||||
|
{
|
||||||
|
if(j > SERVO_MAX)
|
||||||
|
j=SERVO_MAX;
|
||||||
|
if(j < SERVO_MIN)
|
||||||
|
j=SERVO_MIN;
|
||||||
|
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
servoa=j;
|
||||||
|
OCR3A = servoa;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if(i==1)
|
||||||
|
{
|
||||||
|
servob=j;
|
||||||
|
OCR3B = servob;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
platform/guhRF/dev/servo.h
Normal file
44
platform/guhRF/dev/servo.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007, 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 SERVO_H
|
||||||
|
#define SERVO_H
|
||||||
|
|
||||||
|
#define SERVO_MIN 575
|
||||||
|
#define SERVO_MAX 2425
|
||||||
|
#define SERVO_INIT 1500
|
||||||
|
|
||||||
|
void servo_init(void);
|
||||||
|
void servo_off(void);
|
||||||
|
|
||||||
|
unsigned int servo_get(unsigned int i);
|
||||||
|
unsigned int servo_set(unsigned i,unsigned int j);
|
||||||
|
|
||||||
|
#endif /* SHT11_H */
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue