From 367c82a5ab95f05df85e05a0af019b72335f403d Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Wed, 21 Sep 2011 16:54:25 +0200 Subject: [PATCH 01/26] added compiler flags and macros for IAR and mspgcc 4.4.5 compilers --- cpu/msp430/Makefile.msp430 | 2 +- cpu/msp430/msp430def.h | 28 +++++++++++++++------------- platform/sky/Makefile.common | 2 +- platform/sky/platform-conf.h | 11 ----------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 70d2bcf77..8649233b0 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -82,7 +82,7 @@ ifdef WERROR CFLAGSWERROR=-Werror endif -CFLAGS += $(CFLAGSNO) +CFLAGS += $(CFLAGSNO) -fno-strict-aliasing ### These flags can reduce the code size and RAM usage with up to 10% diff --git a/cpu/msp430/msp430def.h b/cpu/msp430/msp430def.h index 2738b7ed7..f4614efcf 100644 --- a/cpu/msp430/msp430def.h +++ b/cpu/msp430/msp430def.h @@ -32,29 +32,31 @@ #ifndef MSP430DEF_H #define MSP430DEF_H -#if defined(__IAR_SYSTEMS_ICC__) || defined(__MSPGCC__) -#include -#if __MSPGCC__ -#include -#endif /* __MSPGCC__ */ -#else -#include -#include -#endif - #ifdef __IAR_SYSTEMS_ICC__ #include #include +#include #define dint() __disable_interrupt() #define eint() __enable_interrupt() #define __MSP430F1611__ 1 #define __MSP430__ 1 #define CC_CONF_INLINE #define BV(x) (1 << x) -#else -#define CC_CONF_INLINE inline + +#else /* __IAR_SYSTEMS_ICC__ */ + +#ifdef __MSPGCC__ +#include +#include +#else /* __MSPGCC__ */ +#include +#include #define MSP430_MEMCPY_WORKAROUND 1 -#endif +#endif /* __MSPGCC__ */ + +#define CC_CONF_INLINE inline + +#endif /* __IAR_SYSTEMS_ICC__ */ #ifdef HAVE_STDINT_H #include diff --git a/platform/sky/Makefile.common b/platform/sky/Makefile.common index ebfbea6e9..3a4510580 100644 --- a/platform/sky/Makefile.common +++ b/platform/sky/Makefile.common @@ -19,7 +19,7 @@ CFLAGS+=-Os -g endif ifdef IAR -CFLAGS+=-e --vla -Ohz --multiplier=16s --core=430 --double=32 +CFLAGS += -D__MSP430F1611__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32 CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430fn.h" $(CFLAGSWERROR) endif diff --git a/platform/sky/platform-conf.h b/platform/sky/platform-conf.h index 7c3eec2e0..a64057154 100644 --- a/platform/sky/platform-conf.h +++ b/platform/sky/platform-conf.h @@ -53,17 +53,6 @@ #define PLATFORM_HAS_BATTERY 1 #define PLATFORM_HAS_SHT11 1 -#ifdef __IAR_SYSTEMS_ICC__ -#define __MSP430F1611__ 1 -#define __MSP430__ 1 -#define CC_CONF_INLINE -#define BV(x) (1 << x) -#else -#define CC_CONF_INLINE inline -#define MSP430_MEMCPY_WORKAROUND 1 -#endif - - /* CPU target speed in Hz */ #define F_CPU 3900000uL /*2457600uL*/ From 05b10eb9cea91a28ef5503ed020e0e19b984a7af Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Wed, 21 Sep 2011 20:02:04 +0200 Subject: [PATCH 02/26] Initial WiSMote port based on code from Arago Systems. --- core/dev/cc2520.c | 926 ++++++++++++++++++++ core/dev/cc2520.h | 199 +++++ core/dev/cc2520_const.h | 215 +++++ cpu/msp430/Makefile.msp430 | 3 +- cpu/msp430/cc2520-arch-sfd.c | 80 ++ cpu/msp430/cc2520-arch-sfd.h | 38 + cpu/msp430/cc2520-arch.c | 85 ++ cpu/msp430/clock.c | 109 ++- cpu/msp430/dev/uart1.c | 91 +- cpu/msp430/msp430.c | 33 +- cpu/msp430/msp430def.h | 1 - cpu/msp430/rtimer-arch.c | 46 +- cpu/msp430/watchdog.c | 6 +- platform/sky/Makefile.common | 4 - platform/wismote/Makefile.wismote | 57 ++ platform/wismote/cfs-coffee-arch.h | 77 ++ platform/wismote/checkpoint-arch.c | 370 ++++++++ platform/wismote/contiki-conf.h | 210 +++++ platform/wismote/contiki-wismote-main.c | 470 ++++++++++ platform/wismote/contiki-wismote-platform.c | 42 + platform/wismote/dev/acc-sensor.c | 129 +++ platform/wismote/dev/acc-sensor.h | 48 + platform/wismote/dev/battery-sensor.c | 96 ++ platform/wismote/dev/button-sensor.c | 106 +++ platform/wismote/dev/ext-sensor.c | 105 +++ platform/wismote/dev/ext-sensor.h | 53 ++ platform/wismote/dev/i2c.c | 223 +++++ platform/wismote/dev/i2c.h | 48 + platform/wismote/dev/light-sensor.c | 89 ++ platform/wismote/dev/light-sensor.h | 51 ++ platform/wismote/dev/light.c | 127 +++ platform/wismote/dev/light.h | 41 + platform/wismote/dev/radio-sensor.c | 66 ++ platform/wismote/dev/sht11-arch.h | 52 ++ platform/wismote/dev/sht15.c | 320 +++++++ platform/wismote/dev/sht15.h | 65 ++ platform/wismote/dev/sky-sensors.c | 92 ++ platform/wismote/dev/sky-sensors.h | 46 + platform/wismote/dev/spi.h | 92 ++ platform/wismote/dev/xmem.c | 268 ++++++ platform/wismote/flash.c | 102 +++ platform/wismote/node-id.c | 72 ++ platform/wismote/node-id.h | 44 + platform/wismote/platform-conf.h | 207 +++++ platform/wismote/spix.c | 60 ++ 45 files changed, 5641 insertions(+), 23 deletions(-) create mode 100644 core/dev/cc2520.c create mode 100644 core/dev/cc2520.h create mode 100644 core/dev/cc2520_const.h create mode 100644 cpu/msp430/cc2520-arch-sfd.c create mode 100644 cpu/msp430/cc2520-arch-sfd.h create mode 100644 cpu/msp430/cc2520-arch.c create mode 100644 platform/wismote/Makefile.wismote create mode 100644 platform/wismote/cfs-coffee-arch.h create mode 100644 platform/wismote/checkpoint-arch.c create mode 100644 platform/wismote/contiki-conf.h create mode 100644 platform/wismote/contiki-wismote-main.c create mode 100644 platform/wismote/contiki-wismote-platform.c create mode 100644 platform/wismote/dev/acc-sensor.c create mode 100644 platform/wismote/dev/acc-sensor.h create mode 100644 platform/wismote/dev/battery-sensor.c create mode 100644 platform/wismote/dev/button-sensor.c create mode 100644 platform/wismote/dev/ext-sensor.c create mode 100644 platform/wismote/dev/ext-sensor.h create mode 100644 platform/wismote/dev/i2c.c create mode 100644 platform/wismote/dev/i2c.h create mode 100644 platform/wismote/dev/light-sensor.c create mode 100644 platform/wismote/dev/light-sensor.h create mode 100644 platform/wismote/dev/light.c create mode 100644 platform/wismote/dev/light.h create mode 100644 platform/wismote/dev/radio-sensor.c create mode 100644 platform/wismote/dev/sht11-arch.h create mode 100644 platform/wismote/dev/sht15.c create mode 100644 platform/wismote/dev/sht15.h create mode 100644 platform/wismote/dev/sky-sensors.c create mode 100644 platform/wismote/dev/sky-sensors.h create mode 100644 platform/wismote/dev/spi.h create mode 100644 platform/wismote/dev/xmem.c create mode 100644 platform/wismote/flash.c create mode 100644 platform/wismote/node-id.c create mode 100644 platform/wismote/node-id.h create mode 100644 platform/wismote/platform-conf.h create mode 100644 platform/wismote/spix.c diff --git a/core/dev/cc2520.c b/core/dev/cc2520.c new file mode 100644 index 000000000..f3e97a060 --- /dev/null +++ b/core/dev/cc2520.c @@ -0,0 +1,926 @@ +/* + * 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. + */ +/* + * This code is almost device independent and should be easy to port. + */ + +#include + +#include "contiki.h" + +#if defined(__AVR__) +#include +#endif + +#include "dev/leds.h" +#include "dev/spi.h" +#include "dev/cc2520.h" +#include "dev/cc2520_const.h" + +#include "net/packetbuf.h" +#include "net/rime/rimestats.h" +#include "net/netstack.h" + +#include "sys/timetable.h" + +#define WITH_SEND_CCA 1 + +#define FOOTER_LEN 2 + +#ifndef CC2520_CONF_CHECKSUM +#define CC2520_CONF_CHECKSUM 0 +#endif /* CC2520_CONF_CHECKSUM */ + +#ifndef CC2520_CONF_AUTOACK +#define CC2520_CONF_AUTOACK 0 +#endif /* CC2520_CONF_AUTOACK */ + +#if CC2520_CONF_CHECKSUM +#include "lib/crc16.h" +#define CHECKSUM_LEN 2 +#else +#define CHECKSUM_LEN 0 +#endif /* CC2520_CONF_CHECKSUM */ + +#define AUX_LEN (CHECKSUM_LEN + FOOTER_LEN) + + +#define FOOTER1_CRC_OK 0x80 +#define FOOTER1_CORRELATION 0x7f + +#define DEBUG 1 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +#define DEBUG_LEDS DEBUG +#undef LEDS_ON +#undef LEDS_OFF +#if DEBUG_LEDS +#define LEDS_ON(x) leds_on(x) +#define LEDS_OFF(x) leds_off(x) +#else +#define LEDS_ON(x) +#define LEDS_OFF(x) +#endif + +void cc2520_arch_init(void); + +/* XXX hack: these will be made as Chameleon packet attributes */ +rtimer_clock_t cc2520_time_of_arrival, cc2520_time_of_departure; + +int cc2520_authority_level_of_sender; + +int cc2520_packets_seen, cc2520_packets_read; + +static uint8_t volatile pending; + +#define BUSYWAIT_UNTIL(cond, max_time) \ + do { \ + rtimer_clock_t t0; \ + t0 = RTIMER_NOW(); \ + while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))); \ + } while(0) + +volatile uint8_t cc2520_sfd_counter; +volatile uint16_t cc2520_sfd_start_time; +volatile uint16_t cc2520_sfd_end_time; + +static volatile uint16_t last_packet_timestamp; +/*---------------------------------------------------------------------------*/ +PROCESS(cc2520_process, "CC2520 driver"); +/*---------------------------------------------------------------------------*/ + + +int cc2520_on(void); +int cc2520_off(void); + +static int cc2520_read(void *buf, unsigned short bufsize); + +static int cc2520_prepare(const void *data, unsigned short len); +static int cc2520_transmit(unsigned short len); +static int cc2520_send(const void *data, unsigned short len); + +static int cc2520_receiving_packet(void); +static int pending_packet(void); +static int cc2520_cca(void); +/* static int detected_energy(void); */ + +signed char cc2520_last_rssi; +uint8_t cc2520_last_correlation; + +const struct radio_driver cc2520_driver = + { + cc2520_init, + cc2520_prepare, + cc2520_transmit, + cc2520_send, + cc2520_read, + /* cc2520_set_channel, */ + /* detected_energy, */ + cc2520_cca, + cc2520_receiving_packet, + pending_packet, + cc2520_on, + cc2520_off, + + }; + +static uint8_t receive_on; + +static int channel; + +/*---------------------------------------------------------------------------*/ + +static void +getrxdata(void *buf, int len) +{ + CC2520_READ_FIFO_BUF(buf, len); +} +static void +getrxbyte(uint8_t *byte) +{ + CC2520_READ_FIFO_BYTE(*byte); +} +static void +flushrx(void) +{ + uint8_t dummy; + + CC2520_READ_FIFO_BYTE(dummy); + CC2520_STROBE(CC2520_INS_SFLUSHRX); + CC2520_STROBE(CC2520_INS_SFLUSHRX); +} +/*---------------------------------------------------------------------------*/ +static void strobe(uint8_t regname) +{ + CC2520_STROBE(regname); +} +/*---------------------------------------------------------------------------*/ +static unsigned int +status(void) +{ + uint8_t status; + CC2520_GET_STATUS(status); + return status; +} +/*---------------------------------------------------------------------------*/ +static uint8_t locked, lock_on, lock_off; + +static void +on(void) +{ + ENERGEST_ON(ENERGEST_TYPE_LISTEN); + CC2520_ENABLE_FIFOP_INT(); + strobe(CC2520_INS_SRXON); + //BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 100); + + receive_on = 1; +} +static void +off(void) +{ + /* PRINTF("off\n");*/ + receive_on = 0; + + /* Wait for transmission to end before turning radio off. */ + //BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); + //while(status() & BV(CC2520_TX_ACTIVE)); + + strobe(CC2520_INS_SRFOFF); + CC2520_DISABLE_FIFOP_INT(); + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); + + if(!CC2520_FIFOP_IS_1) { + flushrx(); + } +} +/*---------------------------------------------------------------------------*/ +#define GET_LOCK() locked++ +static void RELEASE_LOCK(void) { + if(locked == 1) { + if(lock_on) { + on(); + lock_on = 0; + } + if(lock_off) { + off(); + lock_off = 0; + } + } + locked--; +} +/*---------------------------------------------------------------------------*/ +static uint8_t +getreg(unsigned regname) +{ + uint8_t reg; + CC2520_READ_REG(regname, reg); + return reg; +} +/*---------------------------------------------------------------------------*/ +static void +setreg(unsigned regname, unsigned value) +{ + CC2520_WRITE_REG(regname, value); +} +/*---------------------------------------------------------------------------*/ +static void +set_txpower(uint8_t power) +{ + uint16_t reg; + + reg = getreg(CC2520_TXCTRL); + reg = (reg & 0xffe0) | (power & 0x1f); + setreg(CC2520_TXCTRL, reg); +} +/*---------------------------------------------------------------------------*/ +#define AUTOACK (1 << 4) +#define ADR_DECODE (1 << 11) +#define RXFIFO_PROTECTION (1 << 9) +#define CORR_THR(n) (((n) & 0x1f) << 6) +#define FIFOP_THR(n) ((n) & 0x7f) +#define RXBPF_LOCUR (1 << 13); +/*---------------------------------------------------------------------------*/ +int temp_data; +int +cc2520_init(void) +{ + unsigned stat1; + + { + int s = splhigh(); + cc2520_arch_init(); /* Initalize ports and SPI. */ + CC2520_DISABLE_FIFOP_INT(); + CC2520_FIFOP_INT_INIT(); + splx(s); + } + /* Turn on voltage regulator and reset. */ + SET_VREG_INACTIVE(); + clock_delay(250); + SET_VREG_ACTIVE(); + clock_delay(250); + SET_RESET_ACTIVE(); + clock_delay(127); + SET_RESET_INACTIVE(); + clock_delay(125); + strobe(CC2520_INS_SXOSCON); // Turn on the crystal oscillator. + clock_delay(125); + + stat1 = status(); + while(!(stat1 & 0x80)) + stat1 = status(); + + /* Change default values as recommended in the data sheet, */ + /* correlation threshold = 20, RX bandpass filter = 1.3uA.*/ + + setreg(CC2520_TXCTRL, 0x94); + setreg(CC2520_TXPOWER, 0x13); // Output power 1 dBm + + /* + + valeurs de TXPOWER + 0x03 -> -18 dBm + 0x2C -> -7 dBm + 0x88 -> -4 dBm + 0x81 -> -2 dBm + 0x32 -> 0 dBm + 0x13 -> 1 dBm + 0x32 -> 0 dBm + 0x13 -> 1 dBm + 0xAB -> 2 dBm + 0xF2 -> 3 dBm + 0xF7 -> 5 dBm + */ + setreg(CC2520_CCACTRL0, 0xF8); // CCA treshold -80dBm + + // Recommended RX settings + setreg(CC2520_MDMCTRL0, 0x84); // Controls modem + setreg(CC2520_MDMCTRL1, 0x14); // Controls modem + setreg(CC2520_RXCTRL, 0x3F); // Adjust currents in RX related analog modules + setreg(CC2520_FSCTRL, 0x5A); // Adjust currents in synthesizer. + setreg(CC2520_FSCAL1, 0x2B); // Adjust currents in VCO + setreg(CC2520_AGCCTRL1, 0x11); // Adjust target value for AGC control loop + setreg(CC2520_AGCCTRL2, 0xEB); + + // Disable filter on @ (remove if you want to address specific wismote) + setreg(CC2520_FRMFILT0, 0x00); + + // Disable external clock + setreg(CC2520_EXTCLOCK, 0x00); + + // Tune ADC performance + setreg(CC2520_ADCTEST0, 0x10); + setreg(CC2520_ADCTEST1, 0x0E); + setreg(CC2520_ADCTEST2, 0x03); + + // Set auto CRC on frame + setreg(CC2520_FRMCTRL0, 0x60); + setreg(CC2520_FIFOPCTRL, 0x0F); + + cc2520_set_pan_addr(0xbabe, 0x0000, NULL); + cc2520_set_channel(15); + + flushrx(); + + process_start(&cc2520_process, NULL); + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +cc2520_transmit(unsigned short payload_len) +{ + int i, txpower; + uint8_t total_len; +#if CC2520_CONF_CHECKSUM + uint16_t checksum; +#endif /* CC2520_CONF_CHECKSUM */ + + GET_LOCK(); +#if (DEBUG == 1) + P8OUT &= ~BIT6; // TODO LED FLASH for the debug on transmission +#endif + txpower = 0; + if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) { + /* Remember the current transmission power */ + txpower = cc2520_get_txpower(); + /* Set the specified transmission power */ + //TODOset_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1); + } + + total_len = payload_len + AUX_LEN; + + /* The TX FIFO can only hold one packet. Make sure to not overrun + * FIFO by waiting for transmission to start here and synchronizing + * with the CC2520_TX_ACTIVE check in cc2520_send. + * + * Note that we may have to wait up to 320 us (20 symbols) before + * transmission starts. + */ +#ifndef CC2520_CONF_SYMBOL_LOOP_COUNT +#error CC2520_CONF_SYMBOL_LOOP_COUNT needs to be set!!! +#else +#define LOOP_20_SYMBOLS CC2520_CONF_SYMBOL_LOOP_COUNT +#endif + +#if WITH_SEND_CCA + strobe(CC2520_INS_SRXON); + //BUSYWAIT_UNTIL(status() & BV(CC2520_TX_ACTIVE) , RTIMER_SECOND / 100); + strobe(CC2520_INS_STXONCCA); +#else /* WITH_SEND_CCA */ + strobe(CC2520_INS_STXON); +#endif /* WITH_SEND_CCA */ + for(i = LOOP_20_SYMBOLS; i > 0; i--) { + if(CC2520_SFD_IS_1) { + { + rtimer_clock_t sfd_timestamp; + sfd_timestamp = cc2520_sfd_start_time; + if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == + PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP) { + /* Write timestamp to last two bytes of packet in TXFIFO. */ + CC2520_WRITE_RAM(&sfd_timestamp, CC2520RAM_TXFIFO + payload_len - 1, 2); + } + } + + if(!(status() & BV(CC2520_TX_ACTIVE))) { + /* SFD went high but we are not transmitting. This means that + we just started receiving a packet, so we drop the + transmission. */ + RELEASE_LOCK(); + return RADIO_TX_COLLISION; + } + if(receive_on) { + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); + } + ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); + /* We wait until transmission has ended so that we get an + accurate measurement of the transmission time.*/ + //BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG0) & TX_FRM_DONE , RTIMER_SECOND / 100); + //BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); + +#ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS + ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2520_get_txpower()); +#endif + ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); + if(receive_on) { + ENERGEST_ON(ENERGEST_TYPE_LISTEN); + } else { + /* We need to explicitly turn off the radio, + * since STXON[CCA] -> TX_ACTIVE -> RX_ACTIVE */ + off(); + } + + if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) { + /* Restore the transmission power */ + set_txpower(txpower & 0xff); + } + + RELEASE_LOCK(); + if (getreg(CC2520_EXCFLAG0) & TX_FRM_DONE ) + return RADIO_TX_OK; + else + return RADIO_TX_COLLISION; + } + } + + /* If we are using WITH_SEND_CCA, we get here if the packet wasn't + transmitted because of other channel activity. */ + RIMESTATS_ADD(contentiondrop); + PRINTF("cc2520: do_send() transmission never started\n"); + + if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) { + /* Restore the transmission power */ + set_txpower(txpower & 0xff); + } + + RELEASE_LOCK(); + return RADIO_TX_COLLISION; +} +/*---------------------------------------------------------------------------*/ +static int +cc2520_prepare(const void *payload, unsigned short payload_len) +{ + uint8_t total_len; +#if CC2520_CONF_CHECKSUM + uint16_t checksum; +#endif /* CC2520_CONF_CHECKSUM */ + GET_LOCK(); + + PRINTF("cc2520: sending %d bytes\n", payload_len); + /*int i; + for(i = 0; i < payload_len;i++) + printf("%x",((uint8_t *) payload)[i]); + printf("\n");*/ + RIMESTATS_ADD(lltx); + + /* Wait for any previous transmission to finish. */ + /* while(status() & BV(CC2520_TX_ACTIVE));*/ + + /* Write packet to TX FIFO. */ + strobe(CC2520_INS_SFLUSHTX); + +#if CC2520_CONF_CHECKSUM + checksum = crc16_data(payload, payload_len, 0); +#endif /* CC2520_CONF_CHECKSUM */ + total_len = payload_len + AUX_LEN; + CC2520_WRITE_FIFO_BUF(&total_len, 1); + CC2520_WRITE_FIFO_BUF(payload, payload_len); +#if CC2520_CONF_CHECKSUM + CC2520_WRITE_FIFO_BUF(&checksum, CHECKSUM_LEN); +#endif /* CC2520_CONF_CHECKSUM */ + + RELEASE_LOCK(); + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +cc2520_send(const void *payload, unsigned short payload_len) +{ + + cc2520_prepare(payload, payload_len); + return cc2520_transmit(payload_len); +} +/*---------------------------------------------------------------------------*/ +int +cc2520_off(void) +{ + /* Don't do anything if we are already turned off. */ + if(receive_on == 0) { + return 1; + } + + /* If we are called when the driver is locked, we indicate that the + radio should be turned off when the lock is unlocked. */ + if(locked) { + /* ("Off when locked (%d)\n", locked);*/ + lock_off = 1; + return 1; + } + + GET_LOCK(); + /* If we are currently receiving a packet (indicated by SFD == 1), + we don't actually switch the radio off now, but signal that the + driver should switch off the radio once the packet has been + received and processed, by setting the 'lock_off' variable. */ + if(status() & BV(CC2520_TX_ACTIVE)) { + lock_off = 1; + } else { + off(); + } + RELEASE_LOCK(); + return 1; +} +/*---------------------------------------------------------------------------*/ +int +cc2520_on(void) +{ + if(receive_on) { + return 1; + } + if(locked) { + lock_on = 1; + return 1; + } + + GET_LOCK(); + on(); + RELEASE_LOCK(); + return 1; +} +/*---------------------------------------------------------------------------*/ +int +cc2520_get_channel(void) +{ + return channel; +} +/*---------------------------------------------------------------------------*/ +int +cc2520_set_channel(int c) +{ + uint16_t f; + + GET_LOCK(); + /* + * Subtract the base channel (11), multiply by 5, which is the + * channel spacing. 357 is 2405-2048 and 0x4000 is LOCK_THR = 1. + */ + + channel = c; + + f = MIN_CHANNEL + ((channel - MIN_CHANNEL) * CHANNEL_SPACING); + /* + * Writing RAM requires crystal oscillator to be stable. + */ + while(!(status() & (BV(CC2520_XOSC16M_STABLE)))); + + /* Wait for any transmission to end. */ + while(status() & BV(CC2520_TX_ACTIVE)); + + // Define radio channel (between 11 and 25) + setreg(CC2520_FREQCTRL, f ); + + /* If we are in receive mode, we issue an SRXON command to ensure + that the VCO is calibrated. */ + if(receive_on) { + strobe(CC2520_INS_SRXON); + } + + RELEASE_LOCK(); + return 1; +} +/*---------------------------------------------------------------------------*/ +void +cc2520_set_pan_addr(unsigned pan, + unsigned addr, + const uint8_t *ieee_addr) +{ + uint8_t tmp[2]; + + GET_LOCK(); + + /* + * Writing RAM requires crystal oscillator to be stable. + */ + //BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 10); + + tmp[0] = pan & 0xff; + tmp[1] = pan >> 8; + CC2520_WRITE_RAM(&tmp, CC2520RAM_PANID, 2); + + + tmp[0] = addr & 0xff; + tmp[1] = addr >> 8; + CC2520_WRITE_RAM(&tmp, CC2520RAM_SHORTADDR, 2); + /* + if(ieee_addr != NULL) { + uint8_t tmp_addr[8]; + // LSB first, MSB last for 802.15.4 addresses in CC2520 + for (f = 0; f < 8; f++) { + tmp_addr[7 - f] = ieee_addr[f]; + } + CC2520_WRITE_RAM(tmp_addr, CC2520RAM_IEEEADDR, 8); + }*/ + RELEASE_LOCK(); +} +/*---------------------------------------------------------------------------*/ +/* + * Interrupt leaves frame intact in FIFO. + */ +#if CC2520_TIMETABLE_PROFILING +#define cc2520_timetable_size 16 +TIMETABLE(cc2520_timetable); +TIMETABLE_AGGREGATE(aggregate_time, 10); +#endif /* CC2520_TIMETABLE_PROFILING */ +int +cc2520_interrupt(void) +{ + CC2520_CLEAR_FIFOP_INT(); + process_poll(&cc2520_process); +#if CC2520_TIMETABLE_PROFILING + timetable_clear(&cc2520_timetable); + TIMETABLE_TIMESTAMP(cc2520_timetable, "interrupt"); +#endif /* CC2520_TIMETABLE_PROFILING */ + + last_packet_timestamp = cc2520_sfd_start_time; + pending++; + cc2520_packets_seen++; + return 1; +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(cc2520_process, ev, data) +{ + int len; + PROCESS_BEGIN(); + + PRINTF("cc2520_process: started\n"); + + while(1) { + PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); +#if CC2520_TIMETABLE_PROFILING + TIMETABLE_TIMESTAMP(cc2520_timetable, "poll"); +#endif /* CC2520_TIMETABLE_PROFILING */ + + PRINTF("cc2520_process: calling receiver callback\n"); + + packetbuf_clear(); + packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp); + len = cc2520_read(packetbuf_dataptr(), PACKETBUF_SIZE); + + packetbuf_set_datalen(len); + + NETSTACK_RDC.input(); + flushrx(); +#if CC2520_TIMETABLE_PROFILING + TIMETABLE_TIMESTAMP(cc2520_timetable, "end"); + timetable_aggregate_compute_detailed(&aggregate_time, + &cc2520_timetable); + timetable_clear(&cc2520_timetable); +#endif /* CC2520_TIMETABLE_PROFILING */ + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +static int +cc2520_read(void *buf, unsigned short bufsize) +{ + uint8_t footer[2]; + uint8_t len; +#if CC2520_CONF_CHECKSUM + uint16_t checksum; +#endif /* CC2520_CONF_CHECKSUM */ + + if((!CC2520_FIFOP_IS_1) & !(getreg(CC2520_EXCFLAG1) & RX_FRM_DONE)) { + return 0; + } +#if (DEBUG == 1) + P2OUT &= ~BIT4; // TODO LED FLASH for the debug on reception +#endif + + //BUSYWAIT_UNTIL( (status() & BV(CC2520_RX_ACTIVE)) , RTIMER_SECOND / 100); + //BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG1) & RX_FRM_DONE , RTIMER_SECOND / 100); + /* if(!pending) { + return 0; + }*/ + + pending = 0; + + GET_LOCK(); + + cc2520_packets_read++; + + getrxbyte(&len); + + if(len > CC2520_MAX_PACKET_LEN) { + /* Oops, we must be out of sync. */ + flushrx(); + RIMESTATS_ADD(badsynch); + RELEASE_LOCK(); + return 0; + } + + if(len <= AUX_LEN) { + flushrx(); + RIMESTATS_ADD(tooshort); + RELEASE_LOCK(); + return 0; + } + + if(len - AUX_LEN > bufsize) { + flushrx(); + RIMESTATS_ADD(toolong); + RELEASE_LOCK(); + return 0; + } + + getrxdata(buf, len - AUX_LEN); + +#if CC2520_CONF_CHECKSUM + getrxdata(&checksum, CHECKSUM_LEN); +#endif /* CC2520_CONF_CHECKSUM */ + getrxdata(footer, FOOTER_LEN); + +#if CC2520_CONF_CHECKSUM + if(checksum != crc16_data(buf, len - AUX_LEN, 0)) { + PRINTF("checksum failed 0x%04x != 0x%04x\n", + checksum, crc16_data(buf, len - AUX_LEN, 0)); + } + + if(footer[1] & FOOTER1_CRC_OK && + checksum == crc16_data(buf, len - AUX_LEN, 0)) { +#else + if(footer[1] & FOOTER1_CRC_OK) { +#endif /* CC2520_CONF_CHECKSUM */ + cc2520_last_rssi = footer[0]; + cc2520_last_correlation = footer[1] & FOOTER1_CORRELATION; + + + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, cc2520_last_rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, cc2520_last_correlation); + + RIMESTATS_ADD(llrx); + + } else { + RIMESTATS_ADD(badcrc); + len = AUX_LEN; + } + + if(CC2520_FIFOP_IS_1) { + if(!CC2520_FIFO_IS_1) { + /* Clean up in case of FIFO overflow! This happens for every + * full length frame and is signaled by FIFOP = 1 and FIFO = + * 0. */ + flushrx(); + } else { + /* Another packet has been received and needs attention. */ + process_poll(&cc2520_process); + } + } + + RELEASE_LOCK(); + + if(len < AUX_LEN) { + return 0; + } + + return len - AUX_LEN; +} +/*---------------------------------------------------------------------------*/ +void +cc2520_set_txpower(uint8_t power) +{ + GET_LOCK(); + set_txpower(power); + RELEASE_LOCK(); +} +/*---------------------------------------------------------------------------*/ +int +cc2520_get_txpower(void) +{ + int power; + GET_LOCK(); + power = (int)(getreg(CC2520_TXCTRL) & 0x001f); + RELEASE_LOCK(); + return power; +} +/*---------------------------------------------------------------------------*/ +int +cc2520_rssi(void) +{ + int rssi; + int radio_was_off = 0; + + if(locked) { + return 0; + } + + GET_LOCK(); + + if(!receive_on) { + radio_was_off = 1; + cc2520_on(); + } + //BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); + + rssi = (int)((signed char)getreg(CC2520_RSSI)); + + if(radio_was_off) { + cc2520_off(); + } + RELEASE_LOCK(); + return rssi; +} +/*---------------------------------------------------------------------------*/ +/* +static int +detected_energy(void) +{ + return cc2520_rssi(); +} +*/ +/*---------------------------------------------------------------------------*/ +int +cc2520_cca_valid(void) +{ + int valid; + if(locked) { + return 1; + } + GET_LOCK(); + valid = !!(status() & BV(CC2520_RSSI_VALID)); + RELEASE_LOCK(); + return valid; +} +/*---------------------------------------------------------------------------*/ +static int +cc2520_cca(void) +{ + int cca; + int radio_was_off = 0; + + /* If the radio is locked by an underlying thread (because we are + being invoked through an interrupt), we preted that the coast is + clear (i.e., no packet is currently being transmitted by a + neighbor). */ + if(locked) { + return 1; + } + + GET_LOCK(); + if(!receive_on) { + radio_was_off = 1; + cc2520_on(); + } + + /* Make sure that the radio really got turned on. */ + if(!receive_on) { + RELEASE_LOCK(); + if(radio_was_off) { + cc2520_off(); + } + return 1; + } + + //BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); + + cca = CC2520_CCA_IS_1; + + if(radio_was_off) { + cc2520_off(); + } + RELEASE_LOCK(); + return cca; +} +/*---------------------------------------------------------------------------*/ +int +cc2520_receiving_packet(void) +{ + return CC2520_SFD_IS_1; +} +/*---------------------------------------------------------------------------*/ +static int +pending_packet(void) +{ + return CC2520_FIFOP_IS_1; +} +/*---------------------------------------------------------------------------*/ +void +cc2520_set_cca_threshold(int value) +{ + uint16_t shifted = value << 8; + GET_LOCK(); + setreg(CC2520_RSSI, shifted); + RELEASE_LOCK(); +} +/*---------------------------------------------------------------------------*/ diff --git a/core/dev/cc2520.h b/core/dev/cc2520.h new file mode 100644 index 000000000..b247f567b --- /dev/null +++ b/core/dev/cc2520.h @@ -0,0 +1,199 @@ +/* + * 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. + */ + +/** + * \file + * CC2520 driver header file + * \author + * Adam Dunkels + * Joakim Eriksson + */ + +#ifndef __CC2520_H__ +#define __CC2520_H__ + +#include "contiki.h" +#include "dev/spi.h" +#include "dev/radio.h" +#include "dev/cc2520_const.h" + +int cc2520_init(void); + +#define CC2520_MAX_PACKET_LEN 127 + +int cc2520_set_channel(int channel); +int cc2520_get_channel(void); + +void cc2520_set_pan_addr(unsigned pan, + unsigned addr, + const uint8_t *ieee_addr); + +extern signed char cc2520_last_rssi; +extern uint8_t cc2520_last_correlation; + +int cc2520_rssi(void); + +extern const struct radio_driver cc2520_driver; + +/** + * \param power Between 1 and 31. + */ +void cc2520_set_txpower(uint8_t power); +int cc2520_get_txpower(void); +#define CC2520_TXPOWER_MAX 31 +#define CC2520_TXPOWER_MIN 0 + +/** + * Interrupt function, called from the simple-cc2520-arch driver. + * + */ +int cc2520_interrupt(void); + +/* XXX hack: these will be made as Chameleon packet attributes */ +extern rtimer_clock_t cc2520_time_of_arrival, + cc2520_time_of_departure; +extern int cc2520_authority_level_of_sender; + +int cc2520_on(void); +int cc2520_off(void); + +void cc2520_set_cca_threshold(int value); + +/************************************************************************/ +/* Additional SPI Macros for the CC2520 */ +/************************************************************************/ +/* Send a strobe to the CC2520 */ +#define CC2520_STROBE(s) \ + do { \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE(s); \ + CC2520_SPI_DISABLE(); \ + } while (0) + +/* Write to a register in the CC2520 */ +/* Note: the SPI_WRITE(0) seems to be needed for getting the */ +/* write reg working on the Z1 / MSP430X platform */ +#define CC2520_WRITE_REG(adr,data) \ + do { \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE_FAST(CC2520_INS_MEMWR | ((adr>>8)&0xFF)); \ + SPI_WRITE_FAST(adr & 0xff); \ + SPI_WRITE_FAST((u8_t) data); \ + SPI_WAITFORTx_ENDED(); \ + CC2520_SPI_DISABLE(); \ + } while(0) + + +/* Read a register in the CC2520 */ +#define CC2520_READ_REG(adr,data) \ + do { \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE((CC2520_INS_MEMRD | ((adr>>8)&0xFF))); \ + SPI_WRITE((adr & 0xFF)); \ + SPI_READ(data); \ + data = SPI_RXBUF; \ + CC2520_SPI_DISABLE(); \ + } while(0) + +#define CC2520_READ_FIFO_BYTE(data) \ + do { \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE(CC2520_INS_RXBUF); \ + (void)SPI_RXBUF; \ + SPI_READ(data); \ + clock_delay(1); \ + CC2520_SPI_DISABLE(); \ + } while(0) + +#define CC2520_READ_FIFO_BUF(buffer,count) \ + do { \ + uint8_t i; \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE(CC2520_INS_RXBUF); \ + (void)SPI_RXBUF; \ + for(i = 0; i < (count); i++) { \ + SPI_READ(((uint8_t *)(buffer))[i]); \ + } \ + clock_delay(1); \ + CC2520_SPI_DISABLE(); \ + } while(0) + +#define CC2520_WRITE_FIFO_BUF(buffer,count) \ + do { \ + uint8_t i; \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE_FAST(CC2520_INS_TXBUF); \ + for(i = 0; i < (count); i++) { \ + SPI_WRITE_FAST(((uint8_t *)(buffer))[i]); \ + SPI_WAITFORTxREADY(); \ + } \ + SPI_WAITFORTx_ENDED(); \ + CC2520_SPI_DISABLE(); \ + } while(0) + +/* Write to RAM in the CC2520 */ +#define CC2520_WRITE_RAM(buffer,adr,count) \ + do { \ + uint8_t i; \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE_FAST(CC2520_INS_MEMWR | (((adr)>>8) & 0xFF)); \ + SPI_WRITE_FAST(((adr) & 0xFF)); \ + for(i = 0; i < (count); i++) { \ + SPI_WRITE_FAST(((uint8_t*)(buffer))[i]); \ + } \ + SPI_WAITFORTx_ENDED(); \ + CC2520_SPI_DISABLE(); \ + } while(0) + +/* Read from RAM in the CC2520 */ +#define CC2520_READ_RAM(buffer,adr,count) \ + do { \ + uint8_t i; \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE(CC2520_INS_MEMRD | (((adr)>>8) & 0xFF)); \ + SPI_WRITE(((adr) & 0xFF)); \ + SPI_RXBUF; \ + for(i = 0; i < (count); i++) { \ + SPI_READ(((uint8_t*)(buffer))[i]); \ + } \ + CC2520_SPI_DISABLE(); \ + } while(0) + +/* Read status of the CC2520 */ +#define CC2520_GET_STATUS(s) \ + do { \ + CC2520_SPI_ENABLE(); \ + SPI_WRITE(CC2520_INS_SNOP); \ + s = SPI_RXBUF; \ + CC2520_SPI_DISABLE(); \ + } while (0) + +#endif /* __CC2520_H__ */ diff --git a/core/dev/cc2520_const.h b/core/dev/cc2520_const.h new file mode 100644 index 000000000..c77d05d1a --- /dev/null +++ b/core/dev/cc2520_const.h @@ -0,0 +1,215 @@ +/* + * 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. + * + */ + +#ifndef CC2520_CONST_H +#define CC2520_CONST_H + +/* + * All constants are from the Chipcon cc2520 Data Sheet that at one + * point in time could be found at + * http://www.chipcon.com/files/cc2520_Data_Sheet_1_4.pdf + * + * The page numbers below refer to pages in this document. + */ + +/* Page 27. */ +enum cc2520_status_byte { + CC2520_XOSC16M_STABLE = 7, + CC2520_RSSI_VALID = 6, + CC2520_EXCEPTION_CHA = 5, + CC2520_EXCEPTION_CHB = 4, + CC2520_DPU_H = 3, + CC2520_DPU_L = 2, + CC2520_TX_ACTIVE = 1, + CC2520_RX_ACTIVE = 0, + +}; +#define TX_FRM_DONE 0x02 +#define RX_FRM_DONE 0x01 +#define RX_FRM_ABORTED 0x20 + +/* Page 27. */ +enum cc2520_memory_size { + CC2520_RAM_SIZE = 640, + CC2520_FIFO_SIZE = 128, +}; + +/* Page 29. */ +enum cc2520_address { + CC2520RAM_TXFIFO = 0x100, + CC2520RAM_RXFIFO = 0x180, + CC2520RAM_IEEEADDR = 0x3EA, + CC2520RAM_PANID = 0x3F2, + CC2520RAM_SHORTADDR = 0x3F4, +}; + +// IEEE 802.15.4 defined constants (2.4 GHz logical channels) +#define MIN_CHANNEL 11 // 2405 MHz +#define MAX_CHANNEL 26 // 2480 MHz +#define CHANNEL_SPACING 5 // MHz + +// FREG definitions (BSET/BCLR supported) +#define CC2520_FRMFILT0 0x000 +#define CC2520_FRMFILT1 0x001 +#define CC2520_SRCMATCH 0x002 +#define CC2520_SRCSHORTEN0 0x004 +#define CC2520_SRCSHORTEN1 0x005 +#define CC2520_SRCSHORTEN2 0x006 +#define CC2520_SRCEXTEN0 0x008 +#define CC2520_SRCEXTEN1 0x009 +#define CC2520_SRCEXTEN2 0x00A +#define CC2520_FRMCTRL0 0x00C +#define CC2520_FRMCTRL1 0x00D +#define CC2520_RXENABLE0 0x00E +#define CC2520_RXENABLE1 0x00F +#define CC2520_EXCFLAG0 0x010 +#define CC2520_EXCFLAG1 0x011 +#define CC2520_EXCFLAG2 0x012 +#define CC2520_EXCMASKA0 0x014 +#define CC2520_EXCMASKA1 0x015 +#define CC2520_EXCMASKA2 0x016 +#define CC2520_EXCMASKB0 0x018 +#define CC2520_EXCMASKB1 0x019 +#define CC2520_EXCMASKB2 0x01A +#define CC2520_EXCBINDX0 0x01C +#define CC2520_EXCBINDX1 0x01D +#define CC2520_EXCBINDY0 0x01E +#define CC2520_EXCBINDY1 0x01F +#define CC2520_GPIOCTRL0 0x020 +#define CC2520_GPIOCTRL1 0x021 +#define CC2520_GPIOCTRL2 0x022 +#define CC2520_GPIOCTRL3 0x023 +#define CC2520_GPIOCTRL4 0x024 +#define CC2520_GPIOCTRL5 0x025 +#define CC2520_GPIOPOLARITY 0x026 +#define CC2520_GPIOCTRL 0x028 +#define CC2520_DPUCON 0x02A +#define CC2520_DPUSTAT 0x02C +#define CC2520_FREQCTRL 0x02E +#define CC2520_FREQTUNE 0x02F +#define CC2520_TXPOWER 0x030 +#define CC2520_TXCTRL 0x031 +#define CC2520_FSMSTAT0 0x032 +#define CC2520_FSMSTAT1 0x033 +#define CC2520_FIFOPCTRL 0x034 +#define CC2520_FSMCTRL 0x035 +#define CC2520_CCACTRL0 0x036 +#define CC2520_CCACTRL1 0x037 +#define CC2520_RSSI 0x038 +#define CC2520_RSSISTAT 0x039 +#define CC2520_TXFIFO_BUF 0x03A +#define CC2520_RXFIRST 0x03C +#define CC2520_RXFIFOCNT 0x03E +#define CC2520_TXFIFOCNT 0x03F + +// SREG definitions (BSET/BCLR unsupported) +#define CC2520_CHIPID 0x040 +#define CC2520_VERSION 0x042 +#define CC2520_EXTCLOCK 0x044 +#define CC2520_MDMCTRL0 0x046 +#define CC2520_MDMCTRL1 0x047 +#define CC2520_FREQEST 0x048 +#define CC2520_RXCTRL 0x04A +#define CC2520_FSCTRL 0x04C +#define CC2520_FSCAL0 0x04E +#define CC2520_FSCAL1 0x04F +#define CC2520_FSCAL2 0x050 +#define CC2520_FSCAL3 0x051 +#define CC2520_AGCCTRL0 0x052 +#define CC2520_AGCCTRL1 0x053 +#define CC2520_AGCCTRL2 0x054 +#define CC2520_AGCCTRL3 0x055 +#define CC2520_ADCTEST0 0x056 +#define CC2520_ADCTEST1 0x057 +#define CC2520_ADCTEST2 0x058 +#define CC2520_MDMTEST0 0x05A +#define CC2520_MDMTEST1 0x05B +#define CC2520_DACTEST0 0x05C +#define CC2520_DACTEST1 0x05D +#define CC2520_ATEST 0x05E +#define CC2520_DACTEST2 0x05F +#define CC2520_PTEST0 0x060 +#define CC2520_PTEST1 0x061 +#define CC2520_RESERVED 0x062 +#define CC2520_DPUBIST 0x07A +#define CC2520_ACTBIST 0x07C +#define CC2520_RAMBIST 0x07E + +// Instruction implementation +#define CC2520_INS_SNOP 0x00 +#define CC2520_INS_IBUFLD 0x02 +#define CC2520_INS_SIBUFEX 0x03 +#define CC2520_INS_SSAMPLECCA 0x04 +#define CC2520_INS_SRES 0x0F +#define CC2520_INS_MEMRD 0x10 +#define CC2520_INS_MEMWR 0x20 +#define CC2520_INS_RXBUF 0x30 +#define CC2520_INS_RXBUFCP 0x38 +#define CC2520_INS_RXBUFMOV 0x32 +#define CC2520_INS_TXBUF 0x3A +#define CC2520_INS_TXBUFCP 0x3E +#define CC2520_INS_RANDOM 0x3C +#define CC2520_INS_SXOSCON 0x40 +#define CC2520_INS_STXCAL 0x41 +#define CC2520_INS_SRXON 0x42 +#define CC2520_INS_STXON 0x43 +#define CC2520_INS_STXONCCA 0x44 +#define CC2520_INS_SRFOFF 0x45 +#define CC2520_INS_SXOSCOFF 0x46 +#define CC2520_INS_SFLUSHRX 0x47 +#define CC2520_INS_SFLUSHTX 0x48 +#define CC2520_INS_SACK 0x49 +#define CC2520_INS_SACKPEND 0x4A +#define CC2520_INS_SNACK 0x4B +#define CC2520_INS_SRXMASKBITSET 0x4C +#define CC2520_INS_SRXMASKBITCLR 0x4D +#define CC2520_INS_RXMASKAND 0x4E +#define CC2520_INS_RXMASKOR 0x4F +#define CC2520_INS_MEMCP 0x50 +#define CC2520_INS_MEMCPR 0x52 +#define CC2520_INS_MEMXCP 0x54 +#define CC2520_INS_MEMXWR 0x56 +#define CC2520_INS_BCLR 0x58 +#define CC2520_INS_BSET 0x59 +#define CC2520_INS_CTR 0x60 +#define CC2520_INS_CBCMAC 0x64 +#define CC2520_INS_UCBCMAC 0x66 +#define CC2520_INS_CCM 0x68 +#define CC2520_INS_UCCM 0x6A +#define CC2520_INS_ECB 0x70 +#define CC2520_INS_ECBO 0x72 +#define CC2520_INS_ECBX 0x74 +#define CC2520_INS_ECBXO 0x76 +#define CC2520_INS_INC 0x78 +#define CC2520_INS_ABORT 0x7F +#define CC2520_INS_REGRD 0x80 +#define CC2520_INS_REGWR 0xC0 + +#endif /* CC2520_CONST_H */ diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 8649233b0..328089406 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -82,12 +82,13 @@ ifdef WERROR CFLAGSWERROR=-Werror endif -CFLAGS += $(CFLAGSNO) -fno-strict-aliasing +CFLAGS += $(CFLAGSNO) ### These flags can reduce the code size and RAM usage with up to 10% ifdef SMALL CFLAGS += -ffunction-sections +# CFLAGS += -fdata-sections LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__ endif # SMALL diff --git a/cpu/msp430/cc2520-arch-sfd.c b/cpu/msp430/cc2520-arch-sfd.c new file mode 100644 index 000000000..e24090d09 --- /dev/null +++ b/cpu/msp430/cc2520-arch-sfd.c @@ -0,0 +1,80 @@ +/* + * 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. + */ + +#include "contiki.h" +#include "dev/spi.h" +#include "dev/cc2520.h" + +extern volatile uint8_t cc2520_sfd_counter; +extern volatile uint16_t cc2520_sfd_start_time; +extern volatile uint16_t cc2520_sfd_end_time; + +/*---------------------------------------------------------------------------*/ +/* SFD interrupt for timestamping radio packets */ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=TIMERB1_VECTOR +__interrupt void +#else +interrupt(TIMERB1_VECTOR) +#endif +cc2520_timerb1_interrupt(void) +{ + int tbiv; + ENERGEST_ON(ENERGEST_TYPE_IRQ); + /* always read TBIV to clear IFG */ + tbiv = TBIV; + if(CC2520_SFD_IS_1) { + cc2520_sfd_counter++; + cc2520_sfd_start_time = TBCCR1; + } else { + cc2520_sfd_counter = 0; + cc2520_sfd_end_time = TBCCR1; + } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ +void +cc2520_arch_sfd_init(void) +{ + /* Need to select the special function! */ + P4SEL = BV(CC2520_SFD_PIN); + + /* start timer B - 32768 ticks per second */ + TBCTL = TBSSEL_1 | TBCLR; + + /* CM_3 = capture mode - capture on both edges */ + TBCCTL1 = CM_3 | CAP | SCS; + TBCCTL1 |= CCIE; + + /* Start Timer_B in continuous mode. */ + TBCTL |= MC1; + + TBR = RTIMER_NOW(); +} +/*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/cc2520-arch-sfd.h b/cpu/msp430/cc2520-arch-sfd.h new file mode 100644 index 000000000..ce6257ab2 --- /dev/null +++ b/cpu/msp430/cc2520-arch-sfd.h @@ -0,0 +1,38 @@ +/* + * 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. + */ +#ifndef CC2520_ARCH_SFD_H +#define CC2520_ARCH_SFD_H + +extern volatile uint8_t cc2520_arch_sfd_counter; +extern volatile uint16_t cc2520_arch_sfd_start_time; +extern volatile uint16_t cc2520_arch_sfd_end_time; + +void cc2520_arch_sfd_init(void); + +#endif /* CC2520_ARCH_SFD_H */ diff --git a/cpu/msp430/cc2520-arch.c b/cpu/msp430/cc2520-arch.c new file mode 100644 index 000000000..be73a9ab5 --- /dev/null +++ b/cpu/msp430/cc2520-arch.c @@ -0,0 +1,85 @@ +/* + * 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. + */ + +#include "contiki.h" +#include "contiki-net.h" + +#include "dev/spi.h" +#include "dev/cc2520.h" + +#ifdef CC2520_CONF_SFD_TIMESTAMPS +#define CONF_SFD_TIMESTAMPS CC2520_CONF_SFD_TIMESTAMPS +#endif /* CC2520_CONF_SFD_TIMESTAMPS */ + +#ifndef CONF_SFD_TIMESTAMPS +#define CONF_SFD_TIMESTAMPS 0 +#endif /* CONF_SFD_TIMESTAMPS */ + +#ifdef CONF_SFD_TIMESTAMPS +#include "cc2520-arch-sfd.h" +#endif + +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=CC2520_IRQ_VECTOR +__interrupt void +#else +interrupt(CC2520_IRQ_VECTOR) +#endif +cc2520_port1_interrupt(void) +{ + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + if(cc2520_interrupt()) { + LPM4_EXIT; + } + + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ +void +cc2520_arch_init(void) +{ + spi_init(); + + /* all input by default, set these as output */ + CC2520_CSN_PORT(DIR) |= BV(CC2520_CSN_PIN); + CC2520_VREG_PORT(DIR) |= BV(CC2520_VREG_PIN); + CC2520_RESET_PORT(DIR) |= BV(CC2520_RESET_PIN); + + P1DIR &= ~(BV(CC2520_FIFOP_PIN) | BV(CC2520_FIFO_PIN) | BV(CC2520_CCA_PIN)); + P2DIR &= ~(BV(CC2520_SFD_PIN)); + +#if CONF_SFD_TIMESTAMPS + cc2520_arch_sfd_init(); +#endif + + CC2520_SPI_DISABLE(); /* Unselect radio. */ +} +/*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/clock.c b/cpu/msp430/clock.c index fb54cbf73..06c737d2f 100644 --- a/cpu/msp430/clock.c +++ b/cpu/msp430/clock.c @@ -37,7 +37,7 @@ #include "sys/clock.h" #include "sys/etimer.h" #include "rtimer-arch.h" -#include "watchdog.h" +#include "dev/watchdog.h" #define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND) @@ -49,13 +49,68 @@ static volatile clock_time_t count = 0; /* last_tar is used for calculating clock_fine */ static volatile uint16_t last_tar = 0; /*---------------------------------------------------------------------------*/ +#if CONTIKI_TARGET_WISMOTE +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=TIMER1_A1_VECTOR +__interrupt void +#else +interrupt(TIMER1_A1_VECTOR) +#endif +timera1 (void) +{ + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + watchdog_start(); + + if(TA1IV == 2) { //CCR1 + + // HW timer bug fix: Interrupt handler called before TR==CCR. + // Occurrs when timer state is toggled between STOP and CONT. + while(TA1CTL & MC1 && TA1CCR1 - TA1R == 1); + + // Make sure interrupt time is futures + do { + TA1CCR1 += INTERVAL; + ++count; + + /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure + that the modulo operation below becomes a logical and and not + an expensive divide. Algorithm from Wikipedia: + http://en.wikipedia.org/wiki/Power_of_two */ +#if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 +#error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). +#error Change CLOCK_CONF_SECOND in contiki-conf.h. +#endif + if(count % CLOCK_CONF_SECOND == 0) { + ++seconds; + energest_flush(); + } + } while((TA1CCR1 - TA1R) > INTERVAL); + + last_tar = TA1R; + + if(etimer_pending() && + (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { + etimer_request_poll(); + LPM4_EXIT; + } + + } + /*if(process_nevents() >= 0) { + LPM4_EXIT; + }*/ + watchdog_stop(); + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +#else #ifdef __IAR_SYSTEMS_ICC__ #pragma vector=TIMERA1_VECTOR __interrupt void #else interrupt(TIMERA1_VECTOR) #endif -timera1 (void) { +timera1 (void) +{ ENERGEST_ON(ENERGEST_TYPE_IRQ); watchdog_start(); @@ -102,6 +157,7 @@ timera1 (void) { ENERGEST_OFF(ENERGEST_TYPE_IRQ); } +#endif /*---------------------------------------------------------------------------*/ clock_time_t clock_time(void) @@ -117,8 +173,13 @@ clock_time(void) void clock_set(clock_time_t clock, clock_time_t fclock) { +#if CONTIKI_TARGET_WISMOTE + TA1R = fclock; + TA1CCR1 = fclock + INTERVAL; +#else TAR = fclock; TACCR1 = fclock + INTERVAL; +#endif count = clock; } /*---------------------------------------------------------------------------*/ @@ -135,22 +196,58 @@ clock_fine(void) /* Assign last_tar to local varible that can not be changed by interrupt */ t = last_tar; /* perform calc based on t, TAR will not be changed during interrupt */ +#if CONTIKI_TARGET_WISMOTE + return (unsigned short) (TA1R - t); +#else return (unsigned short) (TAR - t); +#endif } /*---------------------------------------------------------------------------*/ void clock_init(void) { dint(); +#if CONTIKI_TARGET_WISMOTE + /* Select SMCLK (2.4576MHz), clear TAR */ + //TA1CTL = TASSEL1 | TACLR | ID_3; + /* Select ACLK clock, divide*/ + /* TA1CTL = TASSEL0 | TACLR | ID_1; */ + +#if INTERVAL==32768/CLOCK_SECOND + TA1CTL = TASSEL0 | TACLR; +#elif INTERVAL==16384/CLOCK_SECOND + TA1CTL = TASSEL0 | TACLR | ID_1; +#else +#error NEED TO UPDATE clock.c to match interval! +#endif + + /* Initialize ccr1 to create the X ms interval. */ + /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ + TA1CCTL1 = CCIE; + + /* Interrupt after X ms. */ + TA1CCR1 = INTERVAL; + + /* Start Timer_A in continuous mode. */ + TA1CTL |= MC1; +#else /* Select SMCLK (2.4576MHz), clear TAR */ /* TACTL = TASSEL1 | TACLR | ID_3; */ - + /* Select ACLK 32768Hz clock, divide by 2 */ /* TACTL = TASSEL0 | TACLR | ID_1;*/ /* Select ACLK 32768Hz clock */ + /* TACTL = TASSEL0 | TACLR; */ + +#if INTERVAL==32768/CLOCK_SECOND TACTL = TASSEL0 | TACLR; +#elif INTERVAL==16384/CLOCK_SECOND + TACTL = TASSEL0 | TACLR | ID_1; +#else +#error NEED TO UPDATE clock.c to match interval! +#endif /* Initialize ccr1 to create the X ms interval. */ /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ @@ -161,7 +258,7 @@ clock_init(void) /* Start Timer_A in continuous mode. */ TACTL |= MC1; - +#endif count = 0; /* Enable interrupts. */ @@ -221,6 +318,10 @@ clock_seconds(void) rtimer_clock_t clock_counter(void) { +#if CONTIKI_TARGET_WISMOTE + return TA1R; +#else return TAR; +#endif } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/dev/uart1.c b/cpu/msp430/dev/uart1.c index 5d8faaa81..cfc624bed 100644 --- a/cpu/msp430/dev/uart1.c +++ b/cpu/msp430/dev/uart1.c @@ -33,7 +33,6 @@ * Machine dependent MSP430 UART1 code. */ -#include #include "contiki.h" #include "sys/energest.h" #include "dev/uart1.h" @@ -93,7 +92,11 @@ handle_rxdma_timer(void *ptr) uint8_t uart1_active(void) { +#if CONTIKI_TARGET_WISMOTE + return rx_in_progress | transmitting; +#else return ((~ UTCTL1) & TXEPT) | rx_in_progress | transmitting; +#endif } /*---------------------------------------------------------------------------*/ void @@ -123,16 +126,21 @@ uart1_writeb(unsigned char c) /* Loop until the transmission buffer is available. */ /*while((IFG2 & UTXIFG1) == 0);*/ - TXBUF1 = ringbuf_get(&txbuf); + UCA1TXBUF = ringbuf_get(&txbuf); } #else /* TX_WITH_INTERRUPT */ +#if CONTIKI_TARGET_WISMOTE + while(!(UCA1IFG & UCTXIFG)); // USCI_A1 TX buffer ready? + UCA1TXBUF = c; +#else /* Loop until the transmission buffer is available. */ while((IFG2 & UTXIFG1) == 0); /* Transmit the data. */ TXBUF1 = c; +#endif #endif /* TX_WITH_INTERRUPT */ } /*---------------------------------------------------------------------------*/ @@ -143,6 +151,35 @@ uart1_writeb(unsigned char c) void uart1_init(unsigned long ubr) { +#if CONTIKI_TARGET_WISMOTE + P4DIR |= BIT5; + P4OUT |= BIT5 ; + P5SEL |= BIT6|BIT7; // P5.6,7 = USCI_A1 TXD/RXD + + P4SEL |= BIT7; + P4DIR |= BIT7; + + UCA1CTL1 |= UCSWRST; // **Put state machine in reset** + UCA1CTL1 |= UCSSEL_2; // SMCLK + UCA1BR0 = 139;//69; // Baudrate 57600 (see User's Guide) + UCA1BR1 = 0; // + UCA1MCTL |= UCBRS_2 + UCBRF_0; // Modulation UCBRFx=0 + UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** + + UCA1IE |= UCRXIE; + UCA1IFG &= ~UCRXIFG; + //UCA1IFG &= ~UCTXIFG; + + // UCA1TCTL1 |= URXSE; + + rx_in_progress = 0; + transmitting = 0; +#if TX_WITH_INTERRUPT + ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data)); + UCA1IE |= UCTXIE; + //UCA1IFG &= ~UCTXIFG; +#endif /* TX_WITH_INTERRUPT */ +#else /* RS232 */ P3DIR &= ~0x80; /* Select P37 for input (UART1RX) */ P3DIR |= 0x40; /* Select P36 for output (UART1TX) */ @@ -151,7 +188,7 @@ uart1_init(unsigned long ubr) UCTL1 = SWRST | CHAR; /* 8-bit character, UART mode */ #if 0 - U1RCTL &= ~URXEIE; /* even erroneous characters trigger interrupts */ + U1RCTL &= ~URXEIE; /* even erroneous characters trigger interrupts */ #endif UTCTL1 = SSEL1; /* UCLK = MCLK */ @@ -235,10 +272,52 @@ uart1_init(unsigned long ubr) msp430_add_lpm_req(MSP430_REQUIRE_LPM1); #endif /* RX_WITH_DMA */ +#endif } /*---------------------------------------------------------------------------*/ +#if CONTIKI_TARGET_WISMOTE +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=USCI_A1_VECTOR +__interrupt void +#else +interrupt(USCI_A1_VECTOR) +#endif +uart1_rx_interrupt(void) +{ + uint8_t c; + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + if(UCRXIFG & UCA1IFG) { + rx_in_progress = 0; + // Check status register for receive errors. + if(UCA1STAT & UCRXERR) { + c = UCA1RXBUF; // Clear error flags by forcing a dummy read. + } else { + c = UCA1RXBUF; + if(uart1_input_handler != NULL) { + if(uart1_input_handler(c)) { + LPM4_EXIT; + } + } + } + UCA1IFG &= ~UCRXIFG; + } +#if TX_WITH_INTERRUPT + if(UCTXIFG & UCA1IFG) { + if(ringbuf_elements(&txbuf) == 0) { + transmitting = 0; + } else { + UCA1TXBUF = ringbuf_get(&txbuf); + } + UCA1IFG &= ~UCTXIFG; + } +#endif + //UCA1IFG &= 0x00; + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +#else #if !RX_WITH_DMA #ifdef __IAR_SYSTEMS_ICC__ #pragma vector=UART1RX_VECTOR @@ -277,7 +356,12 @@ uart1_rx_interrupt(void) #endif /* !RX_WITH_DMA */ /*---------------------------------------------------------------------------*/ #if TX_WITH_INTERRUPT +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=UART1TX_VECTOR +__interrupt void +#else interrupt(UART1TX_VECTOR) +#endif uart1_tx_interrupt(void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); @@ -291,4 +375,5 @@ uart1_tx_interrupt(void) ENERGEST_OFF(ENERGEST_TYPE_IRQ); } #endif /* TX_WITH_INTERRUPT */ +#endif /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/msp430.c b/cpu/msp430/msp430.c index 1eff4e261..3f67bbd70 100644 --- a/cpu/msp430/msp430.c +++ b/cpu/msp430/msp430.c @@ -27,12 +27,9 @@ * SUCH DAMAGE. * * This file is part of the Contiki operating system. - * - * @(#)$Id: msp430.c,v 1.15 2011/01/05 13:36:38 joxe Exp $ */ #include "contiki.h" #include "dev/watchdog.h" -#include "net/uip.h" /* dco_required set to 1 will cause the CPU not to go into sleep modes where the DCO clock stopped */ @@ -69,13 +66,34 @@ w_memset(void *out, int value, size_t n) void msp430_init_dco(void) { - /* This code taken from the FU Berlin sources and reformatted. */ +#if CONTIKI_TARGET_WISMOTE + // Stop watchdog + WDTCTL = WDTPW + WDTHOLD; + + /** Configure XTAL **/ + P7SEL |= BIT0 + BIT1; // Activate XT1 + UCSCTL6 &= ~XT1OFF; // Set XT1 On + + UCSCTL6 |= XT1DRIVE_2 | XTS | XT2OFF; // Max drive strength, adjust + UCSCTL6 &= ~XT1DRIVE_1; + + do { + UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG); + // Clear XT2,XT1,DCO fault flags + SFRIFG1 &= ~OFIFG; // Clear fault flags + }while (SFRIFG1&OFIFG); // Test oscillator fault flag + + UCSCTL2 = FLLD0 + FLLD2; + UCSCTL5 |= DIVA__2 + DIVS__2+ DIVM__2;//DIVPA__32 + DIVA__32 + DIVS__2+ DIVM__2; + UCSCTL4 = SELA__DCOCLKDIV + SELS__XT1CLK + SELM__XT1CLK; // Set MCLCK = XT1/2 , SMCLK = XT1/2 , ACLK = XT1/2 + +#else + /* This code taken from the FU Berlin sources and reformatted. */ #define DELTA ((MSP430_CPU_SPEED) / (32768 / 8)) unsigned int compare, oldcapture = 0; unsigned int i; - BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK and SSMCLK. XT2 is off. */ @@ -119,6 +137,8 @@ msp430_init_dco(void) TACTL = 0; /* Stop Timer_A */ BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ + +#endif } /*---------------------------------------------------------------------------*/ @@ -234,6 +254,7 @@ msp430_cpu_init(void) * runtime. */ #if defined(__MSP430__) && defined(__GNUC__) +#define asmv(arg) __asm__ __volatile__(arg) void * sbrk(int incr) { @@ -286,6 +307,7 @@ splhigh_(void) /* #endif */ /* } */ /*---------------------------------------------------------------------------*/ +#if DCOSYNCH_CONF_ENABLED /* this code will always start the TimerB if not already started */ void msp430_sync_dco(void) { @@ -332,4 +354,5 @@ msp430_sync_dco(void) { } } } +#endif /* DCOSYNCH_CONF_ENABLED */ /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/msp430def.h b/cpu/msp430/msp430def.h index f4614efcf..b07a0514e 100644 --- a/cpu/msp430/msp430def.h +++ b/cpu/msp430/msp430def.h @@ -38,7 +38,6 @@ #include #define dint() __disable_interrupt() #define eint() __enable_interrupt() -#define __MSP430F1611__ 1 #define __MSP430__ 1 #define CC_CONF_INLINE #define BV(x) (1 << x) diff --git a/cpu/msp430/rtimer-arch.c b/cpu/msp430/rtimer-arch.c index fab65e418..50e6a2c76 100644 --- a/cpu/msp430/rtimer-arch.c +++ b/cpu/msp430/rtimer-arch.c @@ -39,7 +39,6 @@ */ #include "contiki.h" - #include "sys/energest.h" #include "sys/rtimer.h" #include "sys/process.h" @@ -54,13 +53,15 @@ #endif /*---------------------------------------------------------------------------*/ +#if CONTIKI_TARGET_WISMOTE #ifdef __IAR_SYSTEMS_ICC__ -#pragma vector=TIMERA0_VECTOR +#pragma vector=TIMER1_A0_VECTOR __interrupt void #else -interrupt(TIMERA0_VECTOR) +interrupt(TIMER1_A0_VECTOR) #endif -timera0 (void) { +timera0 (void) +{ ENERGEST_ON(ENERGEST_TYPE_IRQ); watchdog_start(); @@ -75,6 +76,30 @@ timera0 (void) { ENERGEST_OFF(ENERGEST_TYPE_IRQ); } +#else +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=TIMER1_A0_VECTOR +__interrupt void +#else +interrupt(TIMERA0_VECTOR) +#endif +timera0 (void) +{ + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + watchdog_start(); + + rtimer_run_next(); + + if(process_nevents() > 0) { + LPM4_EXIT; + } + + watchdog_stop(); + + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +#endif /*---------------------------------------------------------------------------*/ void rtimer_arch_init(void) @@ -82,7 +107,11 @@ rtimer_arch_init(void) dint(); /* CCR0 interrupt enabled, interrupt occurs when timer equals CCR0. */ +#if CONTIKI_TARGET_WISMOTE + TA1CCTL0 = CCIE; +#else TACCTL0 = CCIE; +#endif /* Enable interrupts. */ eint(); @@ -93,8 +122,13 @@ rtimer_arch_now(void) { rtimer_clock_t t1, t2; do { +#if CONTIKI_TARGET_WISMOTE + t1 = TA1R; + t2 = TA1R; +#else t1 = TAR; t2 = TAR; +#endif } while(t1 != t2); return t1; } @@ -104,6 +138,10 @@ rtimer_arch_schedule(rtimer_clock_t t) { PRINTF("rtimer_arch_schedule time %u\n", t); +#if CONTIKI_TARGET_WISMOTE + TA1CCR0 = t; +#else TACCR0 = t; +#endif } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/watchdog.c b/cpu/msp430/watchdog.c index 89e816fe0..6ac86994c 100644 --- a/cpu/msp430/watchdog.c +++ b/cpu/msp430/watchdog.c @@ -112,9 +112,13 @@ watchdog_init(void) initialization. */ counter = 0; watchdog_stop(); - +#if CONTIKI_TARGET_WISMOTE + SFRIFG1 &= ~WDTIFG; + SFRIE1 |= WDTIE; +#else IFG1 &= ~WDTIFG; IE1 |= WDTIE; +#endif } /*---------------------------------------------------------------------------*/ void diff --git a/platform/sky/Makefile.common b/platform/sky/Makefile.common index 3a4510580..066cad86b 100644 --- a/platform/sky/Makefile.common +++ b/platform/sky/Makefile.common @@ -14,10 +14,6 @@ ifdef UIP_CONF_IPV6 CFLAGS += -DWITH_UIP6=1 endif -ifdef GCC -CFLAGS+=-Os -g -endif - ifdef IAR CFLAGS += -D__MSP430F1611__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32 CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430fn.h" $(CFLAGSWERROR) diff --git a/platform/wismote/Makefile.wismote b/platform/wismote/Makefile.wismote new file mode 100644 index 000000000..cb5e620b8 --- /dev/null +++ b/platform/wismote/Makefile.wismote @@ -0,0 +1,57 @@ +CONTIKI_TARGET_SOURCEFILES += contiki-wismote-platform.c \ + sht11.c sht11-sensor.c light-sensor.c battery-sensor.c \ + button-sensor.c radio-sensor.c + +#ARCH=spi.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \ + cc2520.c cc2520-arch.c cc2520-arch-sfd.c \ + sky-sensors.c uip-ipchksum.c \ + checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c + +ARCH=spix.c i2c.c node-id.c sensors.c cfs-coffee.c sht15.c \ + cc2520.c cc2520-arch.c cc2520-arch-sfd.c \ + sky-sensors.c uip-ipchksum.c \ + checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c + + +CONTIKI_TARGET_DIRS = . dev apps net +ifndef CONTIKI_TARGET_MAIN +CONTIKI_TARGET_MAIN = contiki-wismote-main.c +endif + +ifdef UIP_CONF_IPV6 +CFLAGS += -DWITH_UIP6=1 +endif + +ifdef IAR +CFLAGS += -D__MSP430F5437__=1 -e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --data_model small --double=32 +else +SMALL=1 +endif + +CFLAGS += -D__MSP430X__ + +CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS) + +MCU=msp430x5437 +include $(CONTIKI)/cpu/msp430/Makefile.msp430 + +ifdef IAR +LDFLAGS += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80 +endif + +contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o} +# $(AR) rcf $@ $^ + +ifdef IAR +%.hex: %.$(TARGET) + mv $< $@ +else +%.hex: %.ihex + mv $< $@ +endif + +%.upload: %.hex + msp430flasher -n msp430x5437 -e ERASE_MAIN -w $< -v -z [VCC] + +%.upload-clean: %.hex + msp430flasher -n msp430x5437 -w $< -v -z [VCC] diff --git a/platform/wismote/cfs-coffee-arch.h b/platform/wismote/cfs-coffee-arch.h new file mode 100644 index 000000000..1381ac66e --- /dev/null +++ b/platform/wismote/cfs-coffee-arch.h @@ -0,0 +1,77 @@ +/* + * 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: + * 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 + * Coffee architecture-dependent header for the Tmote Sky platform. + * \author + * Nicolas Tsiftes + */ + +#ifndef CFS_COFFEE_ARCH_H +#define CFS_COFFEE_ARCH_H + +#include "contiki-conf.h" +#include "dev/xmem.h" +#include "dev/watchdog.h" + +/* Coffee configuration parameters. */ +#define COFFEE_SECTOR_SIZE 65536UL +#define COFFEE_PAGE_SIZE 256UL +#define COFFEE_START COFFEE_SECTOR_SIZE +#define COFFEE_SIZE (1024UL * 1024UL - COFFEE_START) +#define COFFEE_NAME_LENGTH 16 +#define COFFEE_MAX_OPEN_FILES 6 +#define COFFEE_FD_SET_SIZE 8 +#define COFFEE_LOG_TABLE_LIMIT 256 +#define COFFEE_DYN_SIZE 4*1024 +#define COFFEE_LOG_SIZE 1024 + +#define COFFEE_MICRO_LOGS 1 + +#define COFFEE_WATCHDOG_START() watchdog_start() +#define COFFEE_WATCHDOG_STOP() watchdog_stop() + +/* Flash operations. */ +#define COFFEE_WRITE(buf, size, offset) \ + xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) + +#define COFFEE_READ(buf, size, offset) \ + xmem_pread((char *)(buf), (size), COFFEE_START + (offset)) + +#define COFFEE_ERASE(sector) \ + xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE) + +/* Coffee types. */ +typedef int16_t coffee_page_t; + +#endif /* !COFFEE_ARCH_H */ diff --git a/platform/wismote/checkpoint-arch.c b/platform/wismote/checkpoint-arch.c new file mode 100644 index 000000000..12f71bb89 --- /dev/null +++ b/platform/wismote/checkpoint-arch.c @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2009, 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. + * + */ + +/** + * \file + * Checkpoint library implementation for the Tmote Sky platform. + * \author + * Fredrik Osterlind + */ + +#include "contiki.h" +#include "lib/checkpoint.h" + +#include "sys/rtimer.h" +#include "sys/mt.h" +#include "cfs/cfs.h" +#include "cfs/cfs-coffee.h" +#include "dev/leds.h" +#include "dev/watchdog.h" + +#include + +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +#define COMMAND_ROLLBACK 1 +#define COMMAND_CHECKPOINT 2 +#define COMMAND_TBR 3 + +#define DATA_AS_HEX 0 /* If false, store binary data */ + +#define INCLUDE_RAM 1 /* Less then 10240 bytes */ +#define INCLUDE_TIMERS 1 /* 16 bytes */ +#define INCLUDE_LEDS 1 /* 1 bytes */ + +/* 10kb memory */ +#define RAM_START 0x1100 +#define RAM_END 0x3900 + +#define STOP_TIMERS() TACTL &= ~(MC1); TBCTL &= ~(MC1); watchdog_stop(); +#define START_TIMERS() watchdog_start(); TACTL |= MC1; TBCTL |= MC1; + +static struct mt_thread checkpoint_thread; +static uint8_t preset_cmd; +static int preset_fd; + +typedef union { + unsigned char u8[2]; + unsigned short u16; +} word_union_t; + +/*---------------------------------------------------------------------------*/ +static void +write_byte(int fd, uint8_t c) +{ +#if DATA_AS_HEX + uint8_t hex[2]; + sprintf(hex, "%02x", c); + if(cfs_write(fd, hex, 2) != 2) { + printf("err #1\n"); + } +#else /* DATA_AS_HEX */ + if(cfs_write(fd, &c, 1) != 1) { + printf("err #2\n"); + } +#endif /* DATA_AS_HEX */ +}/*---------------------------------------------------------------------------*/ +#if 0 +static void +write_array(int fd, unsigned char *mem, uint16_t len) +{ +#if DATA_AS_HEX + int i; + for(i = 0; i < len; i++) { + write_byte(fd, mem[i]); + } +#else /* DATA_AS_HEX */ + cfs_write(fd, mem, len); +#endif /* DATA_AS_HEX */ +} +#endif /* 0 */ +/*---------------------------------------------------------------------------*/ +static void +write_word(int fd, uint16_t w) +{ + word_union_t tmp; + tmp.u16 = w; + write_byte(fd, tmp.u8[0]); + write_byte(fd, tmp.u8[1]); +} +/*---------------------------------------------------------------------------*/ +static uint8_t +read_byte(int fd) +{ +#if DATA_AS_HEX + uint8_t hex[2]; + + cfs_read(fd, hex, 2); + + if(hex[0] >= 'A' && hex[0] <= 'F') { + hex[0] = (hex[0] - 'A' + 0xa); + } else if(hex[0] >= 'a' && hex[0] <= 'f') { + hex[0] = (hex[0] - 'a' + 0xa); + } else { + hex[0] = (hex[0] - '0'); + } + if(hex[1] >= 'A' && hex[1] <= 'F') { + hex[1] = (hex[1] - 'A' + 0xa); + } else if(hex[1] >= 'a' && hex[1] <= 'f') { + hex[1] = (hex[1] - 'a' + 0xa); + } else { + hex[1] = (hex[1] - '0'); + } + return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f); +#else /* DATA_AS_HEX */ + uint8_t c; + cfs_read(fd, &c, 1); + return c; +#endif /* DATA_AS_HEX */ +} +/*---------------------------------------------------------------------------*/ +static uint16_t +read_word(int fd) +{ + word_union_t tmp; + tmp.u8[0] = read_byte(fd); + tmp.u8[1] = read_byte(fd); + return tmp.u16; +} +/*---------------------------------------------------------------------------*/ +static void +thread_checkpoint(int fd) +{ +#if INCLUDE_RAM + unsigned char *addr; + uint16_t size = 0; + unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack; + unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1; + unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size); + unsigned char *coffee_mem_end = coffee_mem_start + size - 1; +#endif /* INCLUDE_RAM */ + + /*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/ + /*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/ + + /* RAM */ +#if INCLUDE_RAM + for(addr = (unsigned char *)RAM_START; + addr < (unsigned char *)RAM_END; + addr++) { + + if((addr >= thread_mem_start && addr <= thread_mem_end)) { + /* Writing dummy memory */ + /*write_byte(fd, 1);*/ + continue; + } + + if((addr >= coffee_mem_start && addr <= coffee_mem_end)) { + /* Writing dummy memory */ + /*write_byte(fd, 2);*/ + continue; + } + + /* TODO Use write_array() */ + write_byte(fd, *addr); + + if(((int)addr % 512) == 0) { + PRINTF("."); + } + } + +#endif /* INCLUDE_RAM */ + + /* Timers */ +#if INCLUDE_TIMERS +/* write_word(fd, TACTL); + write_word(fd, TACCTL1); + write_word(fd, TACCR1); + write_word(fd, TAR); + + write_word(fd, TBCTL); + write_word(fd, TBCCTL1); + write_word(fd, TBCCR1); + write_word(fd, TBR);*/ +#endif /* INCLUDE_TIMERS */ + + /* LEDs */ +#if INCLUDE_LEDS + write_byte(fd, leds_arch_get()); +#endif /* INCLUDE_LEDS */ + + /* Radio */ + /* ADC */ + /* ... */ + + write_byte(fd, -1); /* Coffee padding byte */ +} +/*---------------------------------------------------------------------------*/ +static void +thread_rollback(int fd) +{ +#if INCLUDE_RAM + unsigned char *addr; + uint16_t size = 0; + unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack; + unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1; + unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size); + unsigned char *coffee_mem_end = coffee_mem_start + size - 1; +#endif /* INCLUDE_RAM */ + + /*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/ + /*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/ + + /* RAM */ +#if INCLUDE_RAM + for(addr = (unsigned char *)RAM_START; + addr < (unsigned char *)RAM_END; + addr++) { + if((addr >= thread_mem_start && addr <= thread_mem_end)) { + /* Ignoring incoming memory */ + /*read_byte(fd);*/ + continue; + } + + if((addr >= coffee_mem_start && addr <= coffee_mem_end)) { + /* Ignoring incoming memory */ + /*read_byte(fd);*/ + continue; + } + + *addr = read_byte(fd); + + if(((int)addr % 512) == 0) { + PRINTF("."); + } + } + +#endif /* INCLUDE_RAM */ + + /* Timers */ +#if INCLUDE_TIMERS +/* TACTL = read_word(fd); + TACCTL1 = read_word(fd); + TACCR1 = read_word(fd); + TAR = read_word(fd); + + TBCTL = read_word(fd); + TBCCTL1 = read_word(fd); + TBCCR1 = read_word(fd); + TBR = read_word(fd);*/ +#endif /* INCLUDE_TIMERS */ + + /* LEDs */ +#if INCLUDE_LEDS + leds_arch_set(read_byte(fd)); +#endif /* INCLUDE_LEDS */ + + /* Radio */ + /* ADC */ + /* ... */ + + read_byte(fd); /* Coffee padding byte */ +} +/*---------------------------------------------------------------------------*/ +static void +thread_loop(void *data) +{ + uint8_t cmd; + int fd; + + while(1) { + /* Store command and file descriptor on stack */ + cmd = preset_cmd; + fd = preset_fd; + + /* Handle command */ + if(cmd == COMMAND_ROLLBACK) { + PRINTF("Rolling back"); + thread_rollback(fd); + PRINTF(" done!\n"); + } else if(cmd == COMMAND_CHECKPOINT) { + PRINTF("Checkpointing"); + thread_checkpoint(fd); + PRINTF(" done!\n"); + } else if(cmd == COMMAND_TBR) { + PRINTF("Writing TBR"); + // write_word(fd, TBR); + PRINTF(" done!\n"); + } else { + printf("Error: unknown command: %u\n", cmd); + } + + /* Return to main Contiki thread */ + mt_yield(); + } +} +/*---------------------------------------------------------------------------*/ +int +checkpoint_arch_size() +{ + return 10258; +} +/*---------------------------------------------------------------------------*/ +void +checkpoint_arch_checkpoint(int fd) +{ +// STOP_TIMERS(); + + preset_cmd = COMMAND_CHECKPOINT; + preset_fd = fd; + mt_exec(&checkpoint_thread); + +// START_TIMERS(); +} +/*---------------------------------------------------------------------------*/ +void +checkpoint_arch_rollback(int fd) +{ + //STOP_TIMERS(); + + preset_cmd = COMMAND_ROLLBACK; + preset_fd = fd; + mt_exec(&checkpoint_thread); + + //START_TIMERS(); +} +/*---------------------------------------------------------------------------*/ +void +checkpoint_arch_init(void) +{ + mt_init(); + mt_start(&checkpoint_thread, thread_loop, NULL); + + /*mt_stop(&checkpoint_thread);*/ + /*mt_remove();*/ +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/contiki-conf.h b/platform/wismote/contiki-conf.h new file mode 100644 index 000000000..9b3b138cc --- /dev/null +++ b/platform/wismote/contiki-conf.h @@ -0,0 +1,210 @@ +/* -*- C -*- */ + +#ifndef CONTIKI_CONF_H +#define CONTIKI_CONF_H + +#include "platform-conf.h" + +#ifndef NETSTACK_CONF_MAC +/* #define NETSTACK_CONF_MAC csma_driver */ +#define NETSTACK_CONF_MAC nullmac_driver +#endif /* NETSTACK_CONF_MAC */ + +#ifndef NETSTACK_CONF_RDC +/* #define NETSTACK_CONF_RDC contikimac_driver */ +#define NETSTACK_CONF_RDC nullrdc_driver +#endif /* NETSTACK_CONF_RDC */ + +#ifndef NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE +#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8 +#endif /* NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE */ + +#ifndef NETSTACK_CONF_RADIO +#define NETSTACK_CONF_RADIO cc2520_driver +#endif /* NETSTACK_CONF_RADIO */ + +#ifndef NETSTACK_CONF_FRAMER +#define NETSTACK_CONF_FRAMER framer_802154 +#endif /* NETSTACK_CONF_FRAMER */ + +#ifndef CC2520_CONF_AUTOACK +#define CC2520_CONF_AUTOACK 1 +#endif /* CC2520_CONF_AUTOACK */ + + +#if WITH_UIP6 +/* Network setup for IPv6 */ +#define NETSTACK_CONF_NETWORK sicslowpan_driver + +/* Specify a minimum packet size for 6lowpan compression to be + enabled. This is needed for ContikiMAC, which needs packets to be + larger than a specified size, if no ContikiMAC header should be + used. */ +#define SICSLOWPAN_CONF_COMPRESSION_THRESHOLD 63 +#define CONTIKIMAC_CONF_WITH_CONTIKIMAC_HEADER 0 + +#define CXMAC_CONF_ANNOUNCEMENTS 0 +#define XMAC_CONF_ANNOUNCEMENTS 0 + +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 8 +#endif + +#else /* WITH_UIP6 */ + +/* Network setup for non-IPv6 (rime). */ + +#define NETSTACK_CONF_NETWORK rime_driver + +#define COLLECT_CONF_ANNOUNCEMENTS 1 +#define CXMAC_CONF_ANNOUNCEMENTS 0 +#define XMAC_CONF_ANNOUNCEMENTS 0 +#define CONTIKIMAC_CONF_ANNOUNCEMENTS 0 + +#define CONTIKIMAC_CONF_COMPOWER 1 +#define XMAC_CONF_COMPOWER 1 +#define CXMAC_CONF_COMPOWER 1 + +#ifndef COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS +#define COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS 32 +#endif /* COLLECT_NEIGHBOR_CONF_MAX_COLLECT_NEIGHBORS */ + +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 16 +#endif /* QUEUEBUF_CONF_NUM */ + +#ifndef TIMESYNCH_CONF_ENABLED +#define TIMESYNCH_CONF_ENABLED 0 +#endif /* TIMESYNCH_CONF_ENABLED */ + +#if TIMESYNCH_CONF_ENABLED +/* CC2520 SDF timestamps must be on if timesynch is enabled. */ +#undef CC2520_CONF_SFD_TIMESTAMPS +#define CC2520_CONF_SFD_TIMESTAMPS 1 +#endif /* TIMESYNCH_CONF_ENABLED */ + +#endif /* WITH_UIP6 */ + +#define PACKETBUF_CONF_ATTRS_INLINE 1 + +#ifndef RF_CHANNEL +#define RF_CHANNEL 26 +#endif /* RF_CHANNEL */ + +#define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0 + +#define IEEE802154_CONF_PANID 0xABCD + +#define SHELL_VARS_CONF_RAM_BEGIN 0x1100 +#define SHELL_VARS_CONF_RAM_END 0x2000 + +#define PROFILE_CONF_ON 0 +#define ENERGEST_CONF_ON 1 + +#define ELFLOADER_CONF_TEXT_IN_ROM 0 +#ifndef ELFLOADER_CONF_DATAMEMORY_SIZE +#define ELFLOADER_CONF_DATAMEMORY_SIZE 0x400 +#endif /* ELFLOADER_CONF_DATAMEMORY_SIZE */ +#ifndef ELFLOADER_CONF_TEXTMEMORY_SIZE +#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x800 +#endif /* ELFLOADER_CONF_TEXTMEMORY_SIZE */ + + +#define AODV_COMPLIANCE +#define AODV_NUM_RT_ENTRIES 32 + +#define WITH_ASCII 1 + +#define PROCESS_CONF_NUMEVENTS 8 +#define PROCESS_CONF_STATS 1 +/*#define PROCESS_CONF_FASTPOLL 4*/ + +#ifdef WITH_UIP6 + +#define RIMEADDR_CONF_SIZE 8 + +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 0 + +#define UIP_CONF_ROUTER 1 +#ifndef UIP_CONF_IPV6_RPL +#define UIP_CONF_IPV6_RPL 1 +#endif /* UIP_CONF_IPV6_RPL */ + +/* configure number of neighbors and routes */ +#ifndef UIP_CONF_DS6_NBR_NBU +#define UIP_CONF_DS6_NBR_NBU 30 +#endif /* UIP_CONF_DS6_NBR_NBU */ +#ifndef UIP_CONF_DS6_ROUTE_NBU +#define UIP_CONF_DS6_ROUTE_NBU 30 +#endif /* UIP_CONF_DS6_ROUTE_NBU */ + +#define UIP_CONF_ND6_SEND_RA 0 +#define UIP_CONF_ND6_REACHABLE_TIME 600000 +#define UIP_CONF_ND6_RETRANS_TIMER 10000 + +#define UIP_CONF_IPV6 1 +#ifndef UIP_CONF_IPV6_QUEUE_PKT +#define UIP_CONF_IPV6_QUEUE_PKT 0 +#endif /* UIP_CONF_IPV6_QUEUE_PKT */ +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_REASSEMBLY 0 +#define UIP_CONF_NETIF_MAX_ADDRESSES 3 +#define UIP_CONF_ND6_MAX_PREFIXES 3 +#define UIP_CONF_ND6_MAX_NEIGHBORS 4 +#define UIP_CONF_ND6_MAX_DEFROUTERS 2 +#define UIP_CONF_IP_FORWARD 0 +#ifndef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 240 +#endif + +#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0 +#define SICSLOWPAN_CONF_COMPRESSION_HC1 1 +#define SICSLOWPAN_CONF_COMPRESSION_HC01 2 +#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 +#ifndef SICSLOWPAN_CONF_FRAG +#define SICSLOWPAN_CONF_FRAG 1 +#define SICSLOWPAN_CONF_MAXAGE 8 +#endif /* SICSLOWPAN_CONF_FRAG */ +#define SICSLOWPAN_CONF_CONVENTIONAL_MAC 1 +#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2 +#ifndef SICSLOWPAN_CONF_MAX_MAC_TRANSMISSIONS +#define SICSLOWPAN_CONF_MAX_MAC_TRANSMISSIONS 5 +#endif /* SICSLOWPAN_CONF_MAX_MAC_TRANSMISSIONS */ +#else /* WITH_UIP6 */ +#define UIP_CONF_IP_FORWARD 1 +#define UIP_CONF_BUFFER_SIZE 108 +#endif /* WITH_UIP6 */ + +#define UIP_CONF_ICMP_DEST_UNREACH 1 + +#define UIP_CONF_DHCP_LIGHT +#define UIP_CONF_LLH_LEN 0 +#ifndef UIP_CONF_RECEIVE_WINDOW +#define UIP_CONF_RECEIVE_WINDOW 48 +#endif +#ifndef UIP_CONF_TCP_MSS +#define UIP_CONF_TCP_MSS 48 +#endif +#define UIP_CONF_MAX_CONNECTIONS 4 +#define UIP_CONF_MAX_LISTENPORTS 8 +#define UIP_CONF_UDP_CONNS 12 +#define UIP_CONF_FWCACHE_SIZE 30 +#define UIP_CONF_BROADCAST 1 +#define UIP_ARCH_IPCHKSUM 1 +#define UIP_CONF_UDP 1 +#define UIP_CONF_UDP_CHECKSUMS 1 +#define UIP_CONF_PINGADDRCONF 0 +#define UIP_CONF_LOGGING 0 + +#define UIP_CONF_TCP_SPLIT 0 + + + +/* include the project config */ +/* PROJECT_CONF_H might be defined in the project Makefile */ +#ifdef PROJECT_CONF_H +#include PROJECT_CONF_H +#endif /* PROJECT_CONF_H */ + +#endif /* CONTIKI_CONF_H */ diff --git a/platform/wismote/contiki-wismote-main.c b/platform/wismote/contiki-wismote-main.c new file mode 100644 index 000000000..5aff6d108 --- /dev/null +++ b/platform/wismote/contiki-wismote-main.c @@ -0,0 +1,470 @@ +/* + * 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. + * + */ + +#include "contiki.h" +#include +#include + +#include "dev/cc2520.h" +//#include "dev/ds2411.h" +#include "dev/leds.h" +#include "dev/serial-line.h" +#include "dev/slip.h" +#include "dev/uart1.h" +#include "dev/watchdog.h" +#include "dev/xmem.h" +#include "lib/random.h" +#include "net/netstack.h" +#include "net/mac/frame802154.h" + +#if WITH_UIP6 +#include "net/uip-ds6.h" +#endif /* WITH_UIP6 */ + +#include "net/rime.h" + +#include "node-id.h" +#include "sys/autostart.h" +#include "sys/profile.h" + +#if UIP_CONF_ROUTER + +#ifndef UIP_ROUTER_MODULE +#ifdef UIP_CONF_ROUTER_MODULE +#define UIP_ROUTER_MODULE UIP_CONF_ROUTER_MODULE +#else /* UIP_CONF_ROUTER_MODULE */ +#define UIP_ROUTER_MODULE rimeroute +#endif /* UIP_CONF_ROUTER_MODULE */ +#endif /* UIP_ROUTER_MODULE */ + +extern const struct uip_router UIP_ROUTER_MODULE; +#endif /* UIP_CONF_ROUTER */ + +#ifndef WITH_UIP +#define WITH_UIP 0 +#endif + +#if WITH_UIP +#include "net/uip.h" +#include "net/uip-fw.h" +#include "net/uip-fw-drv.h" +#include "net/uip-over-mesh.h" +static struct uip_fw_netif slipif = + {UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)}; +static struct uip_fw_netif meshif = + {UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)}; + +#endif /* WITH_UIP */ + +#define UIP_OVER_MESH_CHANNEL 8 +#if WITH_UIP +static uint8_t is_gateway; +#endif /* WITH_UIP */ + +#ifdef EXPERIMENT_SETUP +#include "experiment-setup.h" +#endif + +void init_platform(void); + +/*---------------------------------------------------------------------------*/ +#if 0 +int +force_float_inclusion() +{ + extern int __fixsfsi; + extern int __floatsisf; + extern int __mulsf3; + extern int __subsf3; + + return __fixsfsi + __floatsisf + __mulsf3 + __subsf3; +} +#endif +/*---------------------------------------------------------------------------*/ +void uip_log(char *msg) { puts(msg); } +/*---------------------------------------------------------------------------*/ +#ifndef RF_CHANNEL +#define RF_CHANNEL 26 +#endif +/*---------------------------------------------------------------------------*/ +#if 0 +void +force_inclusion(int d1, int d2) +{ + snprintf(NULL, 0, "%d", d1 % d2); +} +#endif +/*---------------------------------------------------------------------------*/ +#ifndef NODE_ID +#define NODE_ID 0x03 +#endif /* NODE_ID */ +static void +set_rime_addr(void) +{ + rimeaddr_t n_addr; + int i; + + memset(&n_addr, 0, sizeof(rimeaddr_t)); + + // Set node address +#if UIP_CONF_IPV6 + //memcpy(addr.u8, ds2411_id, sizeof(addr.u8)); + n_addr.u8[7] = NODE_ID & 0xff; + n_addr.u8[6] = NODE_ID >> 8; + + // n_addr.u8[7] = node_id & 0xff; + // n_addr.u8[6] = node_id >> 8; + +#else + /* if(node_id == 0) { + for(i = 0; i < sizeof(rimeaddr_t); ++i) { + addr.u8[i] = ds2411_id[7 - i]; + } + } else { + addr.u8[0] = node_id & 0xff; + addr.u8[1] = node_id >> 8; + }*/ + n_addr.u8[0] = NODE_ID >> 8; + n_addr.u8[1] = NODE_ID & 0xff; +#endif + + rimeaddr_set_node_addr(&n_addr); + printf("Rime started with address "); + for(i = 0; i < sizeof(n_addr.u8) - 1; i++) { + printf("%d.", n_addr.u8[i]); + } + printf("%d\n", n_addr.u8[i]); +} +/*---------------------------------------------------------------------------*/ +static void +print_processes(struct process * const processes[]) +{ + /* const struct process * const * p = processes;*/ + printf("Starting"); + while(*processes != NULL) { + printf(" '%s'", (*processes)->name); + processes++; + } + putchar('\n'); +} +/*--------------------------------------------------------------------------*/ +#if WITH_UIP +static void +set_gateway(void) +{ + if(!is_gateway) { + leds_on(LEDS_RED); + //printf("%d.%d: making myself the IP network gateway.\n\n", + // rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); + //printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n", + // uip_ipaddr_to_quad(&uip_hostaddr)); + uip_over_mesh_set_gateway(&rimeaddr_node_addr); + uip_over_mesh_make_announced_gateway(); + is_gateway = 1; + } +} +#endif /* WITH_UIP */ +/*---------------------------------------------------------------------------*/ +int +main(int argc, char **argv) +{ + /* + * Initalize hardware. + */ + + msp430_cpu_init(); + clock_init(); + leds_init(); + + leds_on(LEDS_ALL); + + uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ + +#if WITH_UIP + slip_arch_init(BAUD2UBR(115200)); +#endif /* WITH_UIP */ + + //ds2411_init(); + + /* XXX hack: Fix it so that the 802.15.4 MAC address is compatible + with an Ethernet MAC address - byte 0 (byte 2 in the DS ID) + cannot be odd. */ + //ds2411_id[2] &= 0xfe; + + //xmem_init(); + + rtimer_init(); + /* + * Hardware initialization done! + */ + + + /* Restore node id if such has been stored in external mem */ + //node_id_restore(); + + /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ +#ifdef IEEE_802154_MAC_ADDRESS + { + uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; + //memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr)); + //ds2411_id[7] = node_id & 0xff; + } +#endif + + //random_init(ds2411_id[0] + node_id); + + leds_off(LEDS_BLUE); + /* + * Initialize Contiki and our processes. + */ + process_init(); + process_start(&etimer_process, NULL); + + ctimer_init(); + + init_platform(); + + set_rime_addr(); + + cc2520_init(); + { + uint8_t longaddr[8]; + uint16_t shortaddr; + + shortaddr = (rimeaddr_node_addr.u8[0] << 8) + + rimeaddr_node_addr.u8[1]; + memset(longaddr, 0, sizeof(longaddr)); + rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr); + + printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", + longaddr[0], longaddr[1], longaddr[2], longaddr[3], + longaddr[4], longaddr[5], longaddr[6], longaddr[7]); + + cc2520_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); + } + cc2520_set_channel(RF_CHANNEL); + + printf(CONTIKI_VERSION_STRING " started. "); + if(node_id > 0) { + printf("Node id is set to %u.\n", node_id); + } else { + printf("Node id is not set.\n"); + } + +#if WITH_UIP6 + //memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); + + for(i =0;iipaddr.u8[i * 2], + lladdr->ipaddr.u8[i * 2 + 1]); + } + printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]); + } + + if(!UIP_CONF_IPV6_RPL) { + uip_ipaddr_t ipaddr; + int i; + uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); + printf("Tentative global IPv6 address "); + for(i = 0; i < 7; ++i) { + printf("%02x%02x:", + ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]); + } + printf("%02x%02x\n", + ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]); + } + +#else /* WITH_UIP6 */ + + NETSTACK_RDC.init(); + NETSTACK_MAC.init(); + NETSTACK_NETWORK.init(); + + printf("%s %s, channel check rate %lu Hz, radio channel %u\n", + NETSTACK_MAC.name, NETSTACK_RDC.name, + CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1: + NETSTACK_RDC.channel_check_interval()), + RF_CHANNEL); +#endif /* WITH_UIP6 */ + +#if !WITH_UIP && !WITH_UIP6 + uart1_set_input(serial_line_input_byte); + serial_line_init(); +#endif + +#if PROFILE_CONF_ON + profile_init(); +#endif /* PROFILE_CONF_ON */ + + leds_off(LEDS_GREEN); + +#if TIMESYNCH_CONF_ENABLED + timesynch_init(); + timesynch_set_authority_level((rimeaddr_node_addr.u8[0] << 4) + 16); +#endif /* TIMESYNCH_CONF_ENABLED */ + +#if WITH_UIP + process_start(&tcpip_process, NULL); + process_start(&uip_fw_process, NULL); /* Start IP output */ + process_start(&slip_process, NULL); + + slip_set_input_callback(set_gateway); + + { + uip_ipaddr_t hostaddr, netmask; + + uip_init(); + + uip_ipaddr(&hostaddr, 172,16, + rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); + uip_ipaddr(&netmask, 255,255,0,0); + uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); + + uip_sethostaddr(&hostaddr); + uip_setnetmask(&netmask); + uip_over_mesh_set_net(&hostaddr, &netmask); + /* uip_fw_register(&slipif);*/ + uip_over_mesh_set_gateway_netif(&slipif); + uip_fw_default(&meshif); + uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); + printf("uIP started with IP address %d.%d.%d.%d\n", + uip_ipaddr_to_quad(&hostaddr)); + } +#endif /* WITH_UIP */ + + energest_init(); + ENERGEST_ON(ENERGEST_TYPE_CPU); + + watchdog_start(); + + print_processes(autostart_processes); + autostart_start(autostart_processes); + + // LED Low Init + P2DIR |= BIT4;//TODO + P8DIR |= BIT6; + P2OUT |= BIT4; + P8OUT |= BIT6; + + /* + * This is the scheduler loop. + */ + while(1) { + + int r; +#if PROFILE_CONF_ON + profile_episode_start(); +#endif /* PROFILE_CONF_ON */ + do { + /* Reset watchdog. */ + watchdog_periodic(); + r = process_run(); + } while(r > 0); +#if PROFILE_CONF_ON + profile_episode_end(); +#endif /* PROFILE_CONF_ON */ + + /* + * Idle processing. + */ + int s = splhigh(); /* Disable interrupts. */ + /* uart1_active is for avoiding LPM3 when still sending or receiving */ + if(process_nevents() != 0 || uart1_active()) { + splx(s); /* Re-enable interrupts. */ + } else { + static unsigned long irq_energest = 0; + + /* Re-enable interrupts and go to sleep atomically. */ + ENERGEST_OFF(ENERGEST_TYPE_CPU); + ENERGEST_ON(ENERGEST_TYPE_LPM); + /* We only want to measure the processing done in IRQs when we + are asleep, so we discard the processing time done when we + were awake. */ + energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); + watchdog_stop(); + _BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This + statement will block + until the CPU is + woken up by an + interrupt that sets + the wake up flag. */ + + /* We get the current processing time for interrupts that was + done during the LPM and store it for next time around. */ + dint(); + irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); + eint(); + watchdog_start(); + ENERGEST_OFF(ENERGEST_TYPE_LPM); + ENERGEST_ON(ENERGEST_TYPE_CPU); + + /* P8OUT |= BIT6; */ + /* P2OUT |= BIT4; */ + } + } + + return 0; +} +/*---------------------------------------------------------------------------*/ +#if LOG_CONF_ENABLED +void +log_message(char *m1, char *m2) +{ + printf("%s%s\n", m1, m2); +} +#endif /* LOG_CONF_ENABLED */ diff --git a/platform/wismote/contiki-wismote-platform.c b/platform/wismote/contiki-wismote-platform.c new file mode 100644 index 000000000..4c9fcb5c3 --- /dev/null +++ b/platform/wismote/contiki-wismote-platform.c @@ -0,0 +1,42 @@ +/* + * 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. + * + * Author: Niclas Finne , Joakim Eriksson + */ + +#include "dev/button-sensor.h" + +SENSORS(&button_sensor); + +void +init_platform(void) +{ + process_start(&sensors_process, NULL); +} diff --git a/platform/wismote/dev/acc-sensor.c b/platform/wismote/dev/acc-sensor.c new file mode 100644 index 000000000..6817b7de6 --- /dev/null +++ b/platform/wismote/dev/acc-sensor.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: acc-sensor.c,v 1.6 2010/01/14 20:01:18 nifi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2005-11-01 + * Updated : $Date: 2010/01/14 20:01:18 $ + * $Revision: 1.6 $ + */ + +#include "dev/acc-sensor.h" + +const struct sensors_sensor acc_sensor; +static uint8_t active; + +/*---------------------------------------------------------------------------*/ +static void +activate(void) +{ + /* This assumes that some other sensor system already did setup the ADC + /* (in the case of the sky platform it is sensors_light_init that does it) + + P6SEL |= 0x70; + P6DIR = 0x00; + P6OUT = 0x00; + + P2DIR |= 0x48; + P2OUT |= 0x48; + + + /* stop converting immediately + ADC12CTL0 &= ~ENC; + ADC12CTL1 &= ~CONSEQ_3; + + /* Configure ADC12_2 to sample channel 11 (voltage) and use + /* the Vref+ as reference (SREF_1) since it is a stable reference + ADC12MCTL2 = (INCH_4 + SREF_1); + ADC12MCTL3 = (INCH_5 + SREF_1); + ADC12MCTL4 = (INCH_6 + SREF_1); + /* internal temperature can be read as value(3) + ADC12MCTL5 = (INCH_10 + SREF_1); + + ADC12CTL1 |= CONSEQ_3; + ADC12CTL0 |= ENC | ADC12SC; + + /* Irq_adc12_activate(&acc_sensor, 6, (INCH_11 + SREF_1)); */ + active = 1; +} +/*---------------------------------------------------------------------------*/ +static void +deactivate(void) +{ + /* irq_adc12_deactivate(&acc_sensor, 6); + acc_value = 0;*/ + active = 0; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ +/* + switch(type) { + case 0: + return ADC12MEM2; + case 1: + return ADC12MEM3; + case 2: + return ADC12MEM4; + case 3: + return ADC12MEM5; + }*/ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if (c) { + activate(); + } else { + deactivate(); + } + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch (type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return active; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(acc_sensor, ACC_SENSOR, + value, configure, status); diff --git a/platform/wismote/dev/acc-sensor.h b/platform/wismote/dev/acc-sensor.h new file mode 100644 index 000000000..b10ae214a --- /dev/null +++ b/platform/wismote/dev/acc-sensor.h @@ -0,0 +1,48 @@ +/* + * 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. + * + * $Id: acc-sensor.h,v 1.1 2009/01/15 21:06:02 adamdunkels Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2005-11-01 + * Updated : $Date: 2009/01/15 21:06:02 $ + * $Revision: 1.1 $ + */ + +#ifndef __ACC_SENSOR_H__ +#define __ACC_SENSOR_H__ + +#include "lib/sensors.h" + +extern const struct sensors_sensor acc_sensor; + +#define ACC_SENSOR "Acc" + +#endif /* __ACC_SENSOR_H__ */ diff --git a/platform/wismote/dev/battery-sensor.c b/platform/wismote/dev/battery-sensor.c new file mode 100644 index 000000000..d40ff7d35 --- /dev/null +++ b/platform/wismote/dev/battery-sensor.c @@ -0,0 +1,96 @@ +/* + * 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. + * + * $Id: battery-sensor.c,v 1.10 2010/02/03 20:30:07 nifi Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2005-11-01 + * Updated : $Date: 2010/02/03 20:30:07 $ + * $Revision: 1.10 $ + */ + +#include "dev/battery-sensor.h" +#include "dev/sky-sensors.h" + +const struct sensors_sensor battery_sensor; +static uint8_t active; +/*---------------------------------------------------------------------------*/ +static void +activate(void) +{ + /* Configure ADC12_2 to sample channel 11 (voltage) and use */ + /* the Vref+ as reference (SREF_1) since it is a stable reference */ +// ADC12MCTL2 = (INCH_11 + SREF_1); + +// sky_sensors_activate(0x80); + + active = 1; +} +/*---------------------------------------------------------------------------*/ +static void +deactivate(void) +{ +// sky_sensors_deactivate(0x80); + active = 0; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return 0;//ADC12MEM2/*battery_value*/; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if(c) { + activate(); + } else { + deactivate(); + } + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return active; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, + value, configure, status); diff --git a/platform/wismote/dev/button-sensor.c b/platform/wismote/dev/button-sensor.c new file mode 100644 index 000000000..0456356ba --- /dev/null +++ b/platform/wismote/dev/button-sensor.c @@ -0,0 +1,106 @@ +/* + * 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. + */ +#include "lib/sensors.h" +#include "dev/hwconf.h" +#include "dev/button-sensor.h" + +const struct sensors_sensor button_sensor; + +static struct timer debouncetimer; +static int status(int type); + +HWCONF_PIN(BUTTON, 2, 7); +HWCONF_IRQ(BUTTON, 2, 7); + +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=PORT2_VECTOR +__interrupt void +#else +interrupt(PORT2_VECTOR) +#endif + irq_p2(void) +{ + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + if(BUTTON_CHECK_IRQ()) { + if(timer_expired(&debouncetimer)) { + timer_set(&debouncetimer, CLOCK_SECOND / 4); + sensors_changed(&button_sensor); + LPM4_EXIT; + } + } + P2IFG = 0x00; + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + return BUTTON_READ() || !timer_expired(&debouncetimer); +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch (type) { + case SENSORS_ACTIVE: + if (c) { + if(!status(SENSORS_ACTIVE)) { + timer_set(&debouncetimer, 0); + BUTTON_IRQ_EDGE_SELECTD(); + + BUTTON_SELECT(); + BUTTON_MAKE_INPUT(); + + BUTTON_ENABLE_IRQ(); + } + } else { + BUTTON_DISABLE_IRQ(); + } + return 1; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch (type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return BUTTON_IRQ_ENABLED(); + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, + value, configure, status); diff --git a/platform/wismote/dev/ext-sensor.c b/platform/wismote/dev/ext-sensor.c new file mode 100644 index 000000000..42a8e7ed1 --- /dev/null +++ b/platform/wismote/dev/ext-sensor.c @@ -0,0 +1,105 @@ +/* + * 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. + * + * $Id: ext-sensor.c,v 1.3 2010/02/13 11:20:48 joxe Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Marcus Lundén, + * Jesper Karlsson + * Created : 2005-11-01 + * Updated : $Date: 2010/02/13 11:20:48 $ + * $Revision: 1.3 $ + */ + +#include "contiki.h" +#include "dev/ext-sensor.h" +#include "dev/sky-sensors.h" + +const struct sensors_sensor ext_sensor; +static uint8_t active; +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + /* ADC0 corresponds to the port under the logo, ADC1 to the port over the logo, + ADC2 and ADC3 corresponds to port on the JCreate bottom expansion port) + switch(type) { + case ADC0: + return ADC12MEM6; + case ADC1: + return ADC12MEM7; + case ADC2: + return ADC12MEM8; + case ADC3: + return ADC12MEM9; + }*/ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return active; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if(c) { + if(!status(SENSORS_ACTIVE)) { + /* SREF_1 is Vref+ + /* MemReg6 == P6.0/A0 == port "under" logo + ADC12MCTL6 = (INCH_0 + SREF_0); + /* MemReg7 == P6.1/A1 == port "over" logo + ADC12MCTL7 = (INCH_1 + SREF_0); + /* MemReg8 == P6.2/A2, bottom expansion port + ADC12MCTL8 = (INCH_2 + SREF_0); + /* MemReg9 == P6.1/A3, bottom expansion port, End Of (ADC-)Sequence + ADC12MCTL9 = (INCH_3 + SREF_0); + */ + sky_sensors_activate(0x0F); + active = 1; + } + } else { + sky_sensors_deactivate(0x0F); + active = 0; + } + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(ext_sensor, "Ext", + value, configure, status); diff --git a/platform/wismote/dev/ext-sensor.h b/platform/wismote/dev/ext-sensor.h new file mode 100644 index 000000000..8fed8b59f --- /dev/null +++ b/platform/wismote/dev/ext-sensor.h @@ -0,0 +1,53 @@ +/* + * 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. + * + * $Id: ext-sensor.h,v 1.2 2010/02/13 11:20:48 joxe Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Marcus Lundén + * Created : 2005-11-01 + * Updated : $Date: 2010/02/13 11:20:48 $ + * $Revision: 1.2 $ + */ + +#ifndef __EXT_SENSOR_H__ +#define __EXT_SENSOR_H__ + +#include "lib/sensors.h" + +#define ADC0 0 +#define ADC1 1 +#define ADC2 2 +#define ADC3 3 + +extern const struct sensors_sensor ext_sensor; + +#define EXT_SENSOR "Ext" + +#endif /* __EXT_SENSOR_H__ */ diff --git a/platform/wismote/dev/i2c.c b/platform/wismote/dev/i2c.c new file mode 100644 index 000000000..17a786d7a --- /dev/null +++ b/platform/wismote/dev/i2c.c @@ -0,0 +1,223 @@ +/* + * 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. + */ + +/* + * Small and portable implementation of a bit-banging I2C bus master. + * + * The code should port really easily to platforms other than the + * msp430 but has some hardcoded constants in it. + * + * More info at: + * http://i2c-bus.org/ + * http://www.esacademy.com/faq/i2c/ + */ + +#include +#include +#include + +#include "dev/i2c.h" + +/* + * On the Tmote sky access to I2C/SPI/UART0 must always be exclusive. + */ + +void i2c_enable(void); +void i2c_disable(void); +int i2c_start(void); +unsigned i2c_read(int send_ack); +int i2c_write(unsigned); +void i2c_stop(void); + +#define I2C_PxDIR P3DIR +#define I2C_PxIN P3IN +#define I2C_PxOUT P3OUT +#define I2C_PxSEL P3SEL +/* + * SDA == P3.1 + * SCL == P3.3 + */ +#define SDA 1 +#define SCL 3 + +#define SDA_0() (I2C_PxDIR |= BV(SDA)) /* SDA Output */ +#define SDA_1() (I2C_PxDIR &= ~BV(SDA)) /* SDA Input */ +#define SDA_IS_1 (I2C_PxIN & BV(SDA)) + +#define SCL_0() (I2C_PxDIR |= BV(SCL)) /* SCL Output */ +#define SCL_1() (I2C_PxDIR &= ~BV(SCL)) /* SCL Input */ +#define SCL_IS_1 (I2C_PxIN & BV(SCL)) + +/* + * Should avoid infinite looping while waiting for SCL_IS_1. xxx/bg + */ +#define SCL_WAIT_FOR_1() do{}while (!SCL_IS_1) + +#define delay_4_7us() do{ _NOP(); _NOP(); _NOP(); _NOP(); \ + _NOP(); _NOP(); _NOP(); _NOP(); \ + _NOP(); _NOP(); _NOP(); _NOP(); }while(0) + +#define delay_4us() do{ _NOP(); _NOP(); _NOP(); _NOP(); \ + _NOP(); _NOP(); _NOP(); _NOP(); \ + _NOP(); _NOP(); }while(0) + +static unsigned char old_pxsel, old_pxout, old_pxdir; + +/* + * Grab SDA and SCL pins for exclusive use but remember old + * configuration so that it may be restored when we are done. + */ +void +i2c_enable(void) +{ + unsigned char sda_scl = BV(SDA)|BV(SCL); + + old_pxsel = I2C_PxSEL & sda_scl; + old_pxout = I2C_PxOUT & sda_scl; + old_pxdir = I2C_PxDIR & sda_scl; + + spi_busy = 1; + + I2C_PxSEL &= ~sda_scl; + + I2C_PxOUT &= ~sda_scl; + + I2C_PxDIR |= BV(SCL); /* SCL Output */ + I2C_PxDIR &= ~BV(SDA); /* SDA Input */ +} + +/* + * Restore bus to what it was before i2c_enable. + * + */ +void +i2c_disable(void) +{ + unsigned char not_sda_scl = ~(BV(SDA)|BV(SCL)); + + I2C_PxDIR = (I2C_PxDIR & not_sda_scl) | old_pxdir; + I2C_PxOUT = (I2C_PxOUT & not_sda_scl) | old_pxout; + I2C_PxSEL = (I2C_PxSEL & not_sda_scl) | old_pxsel; + + spi_busy = 0; +} + +int +i2c_start(void) +{ + SDA_1(); + SCL_1(); +#if 1 + SCL_WAIT_FOR_1(); +#else + { + unsigned long n; + for (n = 0; n < 100000 && !SCL_IS_1; n++) + ; + if (!SCL_IS_1) + return -1; + } +#endif + delay_4_7us(); + SDA_0(); + delay_4us(); + SCL_0(); + return 0; +} + +void +i2c_stop(void) +{ + SDA_0(); + delay_4us(); + SCL_1(); + SCL_WAIT_FOR_1(); + SDA_1(); +} + +/* + * Return true if we received an ACK. + */ +int +i2c_write(unsigned _c) +{ + unsigned char c = _c; + unsigned long n; + int i; + int ret; + + for (i = 0; i < 8; i++, c <<= 1) { + if (c & 0x80) + SDA_1(); + else + SDA_0(); + SCL_1(); + SCL_WAIT_FOR_1(); + SCL_0(); + } + + SDA_1(); + SCL_1(); + ret = 0; /* Loop waiting for an ACK to arrive. */ + for (n = 0; n < 250000; n++) { + if (!SDA_IS_1) { + ret = 1; + break; + } + } + SCL_WAIT_FOR_1(); /* clock stretching? */ + SCL_0(); + + return ret; +} + +unsigned +i2c_read(int send_ack) +{ + int i; + unsigned char c = 0x00; + + SDA_1(); + for (i = 0; i < 8; i++) { + c <<= 1; + SCL_1(); + SCL_WAIT_FOR_1(); + if (SDA_IS_1) + c |= 0x1; + SCL_0(); + } + + if (send_ack) + SDA_0(); + SCL_1(); + SCL_WAIT_FOR_1(); + SCL_0(); + + return c; +} diff --git a/platform/wismote/dev/i2c.h b/platform/wismote/dev/i2c.h new file mode 100644 index 000000000..74cd361e2 --- /dev/null +++ b/platform/wismote/dev/i2c.h @@ -0,0 +1,48 @@ +/* + * 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. + + */ + +#ifndef I2C_H +#define I2C_H + +/* + * On the Tmote sky access to I2C/SPI/UART0 must always be exclusive. + */ +#define I2C_ENABLE() (i2c_enable()) +#define I2C_DISABLE() (i2c_disable()) + +void i2c_enable(void); +void i2c_disable(void); +int i2c_start(void); +void i2c_stop(void); + +int i2c_write(unsigned); +unsigned i2c_read(int send_ack); + +#endif /* I2C_H */ diff --git a/platform/wismote/dev/light-sensor.c b/platform/wismote/dev/light-sensor.c new file mode 100644 index 000000000..cb9814e26 --- /dev/null +++ b/platform/wismote/dev/light-sensor.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2005-2010, Swedish Institute of Computer Science + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +#include "contiki.h" +#include "lib/sensors.h" +#include "dev/sky-sensors.h" +#include "dev/light-sensor.h" + +const struct sensors_sensor light_sensor; + +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + /* switch(type) { */ + /* case LIGHT_SENSOR_PHOTOSYNTHETIC: */ + /* /\* Photosynthetically Active Radiation. *\/ */ + /* return ADC12MEM0; */ + /* case LIGHT_SENSOR_TOTAL_SOLAR: */ + /* /\* Total Solar Radiation. *\/ */ + /* return ADC12MEM1; */ + /* } */ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ +/* + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return (ADC12CTL0 & (ADC12ON + REFON)) == (ADC12ON + REFON); + } +*/ + return 0; +} + +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + switch(type) { + case SENSORS_ACTIVE: + if(c) { + if(!status(SENSORS_ACTIVE)) { + +// ADC12MCTL0 = (INCH_4 + SREF_0); // photodiode 1 (P64) +// ADC12MCTL1 = (INCH_5 + SREF_0); // photodiode 2 (P65) + + sky_sensors_activate(0x30); + } + } else { + sky_sensors_deactivate(0x30); + } + } + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(light_sensor, "Light", + value, configure, status); diff --git a/platform/wismote/dev/light-sensor.h b/platform/wismote/dev/light-sensor.h new file mode 100644 index 000000000..467fec667 --- /dev/null +++ b/platform/wismote/dev/light-sensor.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + * $Id: light-sensor.h,v 1.2 2010/01/14 20:23:02 adamdunkels Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne + * Created : 2010-01-08 + * Updated : $Date: 2010/01/14 20:23:02 $ + * $Revision: 1.2 $ + */ + +#ifndef __LIGHT_SENSOR_H__ +#define __LIGHT_SENSOR_H__ + +#include "lib/sensors.h" + +extern const struct sensors_sensor light_sensor; + +#define LIGHT_SENSOR_PHOTOSYNTHETIC 0 +#define LIGHT_SENSOR_TOTAL_SOLAR 1 + + +#endif /* __LIGHT-SENSOR_H__ */ diff --git a/platform/wismote/dev/light.c b/platform/wismote/dev/light.c new file mode 100644 index 000000000..ab7d708d0 --- /dev/null +++ b/platform/wismote/dev/light.c @@ -0,0 +1,127 @@ +/* + * 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: light.c,v 1.1 2006/08/02 14:44:46 bg- Exp $ + */ + +#include "contiki.h" +#include "dev/light.h" +#include + +/* + * Initialize periodic readings from the 2 photo diodes. The most + * recent readings will be stored in ADC internal registers/memory. + */ +void +sensors_light_init(void) +{ + P6SEL |= 0x30; + P6DIR = 0xff; + P6OUT = 0x00; + + /* Set up the ADC. */ + ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; // Setup ADC12, ref., sampling time + ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; // Use sampling timer, repeat-sequenc-of-channels + + ADC12MCTL0 = (INCH_4 + SREF_0); // photodiode 1 (P64) + ADC12MCTL1 = (INCH_5 + SREF_0); // photodiode 2 (P65) + + ADC12CTL0 |= ADC12ON + REFON; + + ADC12CTL0 |= ENC; // enable conversion + ADC12CTL0 |= ADC12SC; // sample & convert +} + +/* Photosynthetically Active Radiation. */ +unsigned +sensors_light1(void) +{ + return ADC12MEM0; +} + +/* Total Solar Radiation. */ +unsigned +sensors_light2(void) +{ + return ADC12MEM1; +} + +/* + * Most of this information taken from + * http://www.moteiv.com/community/Getting_Data_from_Tmote_Sky%27s_Sensors + * + * The Photosynthetically Active Radiation (PAR) sensor as well as the + * Total Solar Radiation (TSR) sensor uses the 2.5V reference voltage + * to produce the raw ADC value. + + * The voltage across each sensor is: + * + * VsensorPAR = ADCValuePAR/4096 * Vref (1a) + * VsensorTSR = ADCValueTSR/4096 * Vref (1b) + * where Vref = 2.5V + * + * This voltage creates a current through a resistor R=100KOhm and this + * current has a linear relationship with the light intensity in Lux. + * IPAR = VsensorPAR / 100,000 (2a) + * ITSR = VsensorTSR / 100,000 (2b) + * + * S1087 (PAR) lx = 1e6 * IPAR * 1000 (3a) + * S1087-01 (TSR) lx = 1e5 * ITSR * 1000 (3b) + * + * lxPAR = 10e9 * ADCValuePAR *(1/4096)* Vref * 10e-5 or + * lxPAR = 3125* ADCvaluePAR / 512 + * and + * lxTSR = 10e8 * ADCValueTSR *(1/4096)* Vref * 10e-5 or + * lxTSR = 625* ADCvalueTSR / 1024 +*/ + +#if 0 +/* Photosynthetically Active Radiation in Lux units. */ +unsigned +sensors_light1_lux(void) +{ + unsigned temp; + temp = (uint32_t)ADC12MEM0; + + temp = (temp*3125)>> 9; + return (uint16_t)(temp & 0xFFFF); +} + +/* Total Solar Radiation in Lux units. */ +unsigned +sensors_light2_lux(void) +{ + unsigned temp; + temp = (uint32_t)ADC12MEM1; + + temp = (temp*625)>> 10; + return (uint16_t)(temp & 0xFFFF); +} +#endif diff --git a/platform/wismote/dev/light.h b/platform/wismote/dev/light.h new file mode 100644 index 000000000..09423c628 --- /dev/null +++ b/platform/wismote/dev/light.h @@ -0,0 +1,41 @@ +/* + * 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: light.h,v 1.1 2006/08/02 14:44:46 bg- Exp $ + */ +#ifndef __LIGHT_H__ +#define __LIGHT_H__ + +void sensors_light_init(void); + +unsigned sensors_light1(void); +unsigned sensors_light2(void); + +#endif /* __LIGHT_H__ */ diff --git a/platform/wismote/dev/radio-sensor.c b/platform/wismote/dev/radio-sensor.c new file mode 100644 index 000000000..a12055730 --- /dev/null +++ b/platform/wismote/dev/radio-sensor.c @@ -0,0 +1,66 @@ +/* + * 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: radio-sensor.c,v 1.6 2010/01/14 20:01:19 nifi Exp $ + */ + +#include "lib/sensors.h" +#include "dev/cc2520.h" +#include "dev/radio-sensor.h" + +const struct sensors_sensor radio_sensor; + +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + switch(type) { + case RADIO_SENSOR_LAST_PACKET: + return cc2520_last_correlation; + case RADIO_SENSOR_LAST_VALUE: + default: + return cc2520_last_rssi; + } +} +/*---------------------------------------------------------------------------*/ +static int +configure(int type, int c) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return 0; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(radio_sensor, RADIO_SENSOR, + value, configure, status); diff --git a/platform/wismote/dev/sht11-arch.h b/platform/wismote/dev/sht11-arch.h new file mode 100644 index 000000000..8df629f65 --- /dev/null +++ b/platform/wismote/dev/sht11-arch.h @@ -0,0 +1,52 @@ +/* + * 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * Architecture-specific definitions for the SHT11 sensor on Tmote Sky. + * \author + * Niclas Finne + */ + +#ifndef SHT11_ARCH_H +#define SHT11_ARCH_H + +#define SHT11_ARCH_SDA 5 /* P1.5 */ +#define SHT11_ARCH_SCL 6 /* P1.6 */ +#define SHT11_ARCH_PWR 7 /* P1.7 */ + +#define SHT11_PxDIR P1DIR +#define SHT11_PxIN P1IN +#define SHT11_PxOUT P1OUT +#define SHT11_PxSEL P1SEL + +#endif diff --git a/platform/wismote/dev/sht15.c b/platform/wismote/dev/sht15.c new file mode 100644 index 000000000..6fa90a7e8 --- /dev/null +++ b/platform/wismote/dev/sht15.c @@ -0,0 +1,320 @@ +/* Copyright (c) 2009 ARAGO SYSTEMS + 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. +*/ +/* + $Id: v 0.1 2011/02/15 tchapelle Exp $ +*/ +#include "dev/sht15.h" + +/*********************************************************************************** +* @fn halMcuWaitUs +* +* @brief Busy wait function. Waits the specified number of microseconds. Use +* assumptions about number of clock cycles needed for the various +* instructions. The duration of one cycle depends on MCLK. In this HAL +* , it is set to 8 MHz, thus 8 cycles per usec. +* +* NB! This function is highly dependent on architecture and compiler! +* +* @param uint16 usec - number of microseconds delay +* +* @return none +*/ + +#pragma optimize=none +void halMcuWaitUs(uint16_t usec) // 5 cycles for calling +{ + // The least we can wait is 3 usec: + // ~1 usec for call, 1 for first compare and 1 for return + while(usec > 3) // 2 cycles for compare + { // 2 cycles for jump + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + nop(); // 1 cycles for nop + usec -= 2; // 1 cycles for optimized decrement + } +} // 4 cycles for returning + + +/** + SHT15/75 Driver + + !!! be advise that the SHT15 and SHT75 are not i2C compliant sensors + they are just designed to not disturb i2C devices on a 2 wire bus + this driver allow to drive the sensor with GPIO and delay +*/ + +/*********************************************************************************** +* @fn sht15_send_start +* +* @brief This function perform the start sequence asked by SHT15 and SHT75 +* +* +* +* @param none +* +* @return none +*/ +void sht15_send_start() +{ + // Sequence is to set data line to 1 then clock line to 1 + // then set data line to 0, clock line to 0 + // then set clock line to 1 and data line to 1 +// ___________ ________ +// data line : _____/ \___________/ +// ___________ ____________ +// clock line : _________/ \___/ + + DATA_OUT(); + DATA_SET(); + SCK_SET(); + DATA_CLR(); + SCK_CLR(); + SCK_SET(); + DATA_SET(); + SCK_CLR(); +} +/*********************************************************************************** +* @fn sht15_read16() +* +* @brief +* +* +* +* @param none +* +* @return uint16_t +*/ +uint16_t sht15_read16() +{ +uint16_t i; +DATA_IN(); + +SCK_CLR(); +uint16_t val = 0; + + for(i = 0; i < 18; i++) + { + if((i != 8) && (i != 17)) + { + SCK_SET(); + if(DATA_VAL()) + val |= 1; + + val <<= 1; + SCK_CLR(); + } + else if(i == 8) // Wait for first ACK from SHT15 + { + DATA_OUT(); + + DATA_CLR(); + + SCK_SET(); + SCK_CLR(); + + DATA_IN(); + } + else if(i == 17) // Wait for second ACK from SHT15 + { + DATA_OUT(); + + DATA_SET(); + + SCK_SET(); + SCK_CLR(); + } + } + return val; +} +/*********************************************************************************** +* @fn sht15_write8 +* +* @brief +* +* +* +* @param uint8 val +* +* @return none +*/ +void sht15_write8(uint8_t val) +{ + uint16_t i; + + DATA_OUT(); + + for(i = 0; i < 8; i++) + { + halMcuWaitUs(4); + SCK_CLR(); + + if(val & 0x80) + { + DATA_SET(); + } + else + { + DATA_CLR(); + } + val <<= 1; + + SCK_SET(); + } + + DATA_IN(); + + SCK_CLR(); + + while(DATA_VAL()); + + SCK_SET(); + SCK_CLR(); +} +/*********************************************************************************** +* @fn sht15_wait_measure +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_wait_measure() +{ + while(DATA_VAL()); +} +/*********************************************************************************** +* @fn sht15_init +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_init() +{ + // DATA and SCK lines are I/O + P3SEL &= ~BIT7; + P5SEL &= ~BIT4; + // Set SCK and DATA as output + DATA_OUT(); + SCK_OUT(); + DATA_SET(); + SCK_SET(); +} +/*********************************************************************************** +* @fn sht15_measure_temp +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_measure_temp() +{ + sht15_send_start(); + sht15_write8(3); +} +/*********************************************************************************** +* @fn sht15_measure_hum +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_measure_hum() +{ + sht15_send_start(); + sht15_write8(5); +} +/*********************************************************************************** +* @fn sht15_read_status +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_read_status() +{ + sht15_send_start(); + sht15_write8(7); +} +/*********************************************************************************** +* @fn sht15_write_status +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_write_status() +{ + sht15_send_start(); + sht15_write8(6); +} +/*********************************************************************************** +* @fn sht15_soft_reset +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_soft_reset() +{ + sht15_send_start(); + sht15_write8(30); +} diff --git a/platform/wismote/dev/sht15.h b/platform/wismote/dev/sht15.h new file mode 100644 index 000000000..dc438b27c --- /dev/null +++ b/platform/wismote/dev/sht15.h @@ -0,0 +1,65 @@ +/* Copyright (c) 2009 ARAGO SYSTEMS + 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. +*/ +/* + $Id: v 0.1 2011/02/15 tchapelle Exp $ +*/ + + +/** + SHT15/75 Driver + +!!! be advise that the SHT15 and SHT75 are not i2C compliant sensors + they are just designed to not disturb i2C devices on a 2 wire bus + this driver allow to drive the sensor with GPIO and delay +*/ +#include "contiki.h" + +#define DATA_OUT() P3DIR |= BIT7 +#define DATA_IN() P3DIR &= ~BIT7 +#define DATA_SET() P3OUT |= BIT7; halMcuWaitUs(10) +#define DATA_CLR() P3OUT &= ~BIT7; halMcuWaitUs(10) +#define DATA_VAL() (P3IN & BIT7) + +#define SCK_OUT() P5DIR |= BIT4 +#define SCK_SET() P5OUT |= BIT4; halMcuWaitUs(10) +#define SCK_CLR() P5OUT &= ~BIT4; halMcuWaitUs(10) + + +/*********************************************************************************** +* SHT15 functions +*/ +void sht15_init(); +void sht15_measure_temp(); +void sht15_measure_hum(); +void sht15_wait_measure(); +void sht15_read_status(); +void sht15_write_status(); +void sht15_soft_reset(); +uint16_t sht15_read16(); +void sht15_write8(uint8_t val); diff --git a/platform/wismote/dev/sky-sensors.c b/platform/wismote/dev/sky-sensors.c new file mode 100644 index 000000000..6279a4afd --- /dev/null +++ b/platform/wismote/dev/sky-sensors.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * $Id: sky-sensors.c,v 1.2 2010/02/06 18:28:26 joxe Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson + * Created : 2010-02-02 + * Updated : $Date: 2010/02/06 18:28:26 $ + * $Revision: 1.2 $ + */ + +#include "contiki.h" + +static uint8_t adc_on; +/*---------------------------------------------------------------------------*/ +void +sky_sensors_activate(uint8_t type) +{ + uint8_t pre = adc_on; + + adc_on |= type; + P6SEL |= type; + + if(pre == 0 && adc_on > 0) { + P6DIR = 0xff; + P6OUT = 0x00; + /* if nothing was started before, start up the ADC system */ + /* Set up the ADC. */ + /* ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; /\* Setup ADC12, ref., sampling time *\/ */ + /* ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; /\* Use sampling timer, repeat-sequenc-of-channels */ + /* /\* convert up to MEM4 *\/ */ + /* ADC12MCTL9 |= EOS; */ + + /* ADC12CTL0 |= ADC12ON + REFON; */ + /* ADC12CTL0 |= ENC; /\* enable conversion *\/ */ + /* ADC12CTL0 |= ADC12SC; /\* sample & convert *\/ */ + } +} +/*---------------------------------------------------------------------------*/ +void +sky_sensors_deactivate(uint8_t type) +{ + adc_on &= ~type; + + if(adc_on == 0) { + /* stop converting immediately, turn off reference voltage, etc. */ + /* wait for conversion to stop */ + + /* ADC12CTL0 &= ~ENC; */ + /* /\* need to remove CONSEQ_3 if not EOS is configured *\/ */ + /* ADC12CTL1 &= ~CONSEQ_3; */ + + /* while(ADC12CTL1 & ADC12BUSY); */ + + /* ADC12CTL0 = 0; */ + /* ADC12CTL1 = 0; */ + + /* P6DIR = 0x00; */ + /* P6OUT = 0x00; */ + /* P6SEL = 0x00; */ + } +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/dev/sky-sensors.h b/platform/wismote/dev/sky-sensors.h new file mode 100644 index 000000000..0ec18905d --- /dev/null +++ b/platform/wismote/dev/sky-sensors.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * $Id: sky-sensors.h,v 1.1 2010/02/02 20:59:45 joxe Exp $ + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson + * Created : 2010-02-02 + * Updated : $Date: 2010/02/02 20:59:45 $ + * $Revision: 1.1 $ + */ + +#ifndef __SKY_SENSORS_H__ +#define __SKY_SENSORS_H__ + +void sky_sensors_activate(uint8_t); +void sky_sensors_deactivate(uint8_t); + +#endif /* __SKY_SENSORS_H__ */ diff --git a/platform/wismote/dev/spi.h b/platform/wismote/dev/spi.h new file mode 100644 index 000000000..e083a3bca --- /dev/null +++ b/platform/wismote/dev/spi.h @@ -0,0 +1,92 @@ +/* + * 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. + */ + +/** + * \file + * Basic SPI macros + * \author + * Niclas Finne + * Joakim Eriksson + */ + +#ifndef __SPI_H__ +#define __SPI_H__ + +/* Define macros to use for checking SPI transmission status depending + on if it is possible to wait for TX buffer ready. This is possible + on for example MSP430 but not on AVR. */ +#ifdef SPI_WAITFORTxREADY +#define SPI_WAITFORTx_BEFORE() SPI_WAITFORTxREADY() +#define SPI_WAITFORTx_AFTER() +#define SPI_WAITFORTx_ENDED() SPI_WAITFOREOTx() +#else /* SPI_WAITFORTxREADY */ +#define SPI_WAITFORTx_BEFORE() +#define SPI_WAITFORTx_AFTER() SPI_WAITFOREOTx() +#define SPI_WAITFORTx_ENDED() +#endif /* SPI_WAITFORTxREADY */ + +extern unsigned char spi_busy; + +void spi_init(void); + +/* Write one character to SPI */ +#define SPI_WRITE(data) \ + do { \ + UCB0IFG &= ~UCRXIFG; \ + SPI_TXBUF = data; \ + SPI_WAITFORTxREADY(); \ + } while(0) + +/* Write one character to SPI - will not wait for end + useful for multiple writes with wait after final */ +#define SPI_WRITE_FAST(data) \ + do { \ + UCB0IFG &= ~UCRXIFG; \ + SPI_TXBUF = data; \ + SPI_WAITFORTxREADY(); \ + } while(0) + +/* Read one character from SPI */ +#define SPI_READ(data) \ + do { \ + UCB0IFG &= ~UCRXIFG; \ + SPI_TXBUF = 0; \ + SPI_WAITFORTxREADY(); \ + SPI_BUSY_WAIT(); \ + data = SPI_RXBUF; \ + } while(0) + +/* Flush the SPI read register */ +#define SPI_FLUSH() \ + do { \ + SPI_RXBUF; \ + SPI_RXBUF; \ + } while(0); + +#endif /* __SPI_H__ */ diff --git a/platform/wismote/dev/xmem.c b/platform/wismote/dev/xmem.c new file mode 100644 index 000000000..dc3b5c25f --- /dev/null +++ b/platform/wismote/dev/xmem.c @@ -0,0 +1,268 @@ +/* + * 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. + * + * @(#)$Id: xmem.c,v 1.10 2009/09/07 11:31:26 nifi Exp $ + */ + +/** + * \file + * Device driver for the ST M25P80 40MHz 1Mbyte external memory. + * \author + * Björn Grönvall + * + * Data is written bit inverted (~-operator) to flash so that + * unwritten data will read as zeros (UNIX style). + */ + +#include "contiki.h" +#include + +#include "dev/spi.h" +#include "dev/xmem.h" +#include "dev/watchdog.h" + +#if 0 +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) do {} while (0) +#endif + +#define SPI_FLASH_INS_WREN 0x06 +#define SPI_FLASH_INS_WRDI 0x04 +#define SPI_FLASH_INS_RDSR 0x05 +#define SPI_FLASH_INS_WRSR 0x01 +#define SPI_FLASH_INS_READ 0x03 +#define SPI_FLASH_INS_FAST_READ 0x0b +#define SPI_FLASH_INS_PP 0x02 +#define SPI_FLASH_INS_SE 0xd8 +#define SPI_FLASH_INS_BE 0xc7 +#define SPI_FLASH_INS_DP 0xb9 +#define SPI_FLASH_INS_RES 0xab +/*---------------------------------------------------------------------------*/ +static void +write_enable(void) +{ + int s; + + s = splhigh(); + SPI_FLASH_ENABLE(); + + //FASTSPI_TX(SPI_FLASH_INS_WREN); + //SPI_WAITFORTx_ENDED(); + + SPI_FLASH_DISABLE(); + splx(s); +} +/*---------------------------------------------------------------------------*/ +static unsigned +read_status_register(void) +{ + unsigned char u; + + int s; + + s = splhigh(); + SPI_FLASH_ENABLE(); + + //FASTSPI_TX(SPI_FLASH_INS_RDSR); + //SPI_WAITFORTx_ENDED(); + + //FASTSPI_CLEAR_RX(); + //FASTSPI_RX(u); + + SPI_FLASH_DISABLE(); + splx(s); + + return u; +} +/*---------------------------------------------------------------------------*/ +/* + * Wait for a write/erase operation to finish. + */ +static unsigned +wait_ready(void) +{ + unsigned u; + do { + u = read_status_register(); + } while(u & 0x01); /* WIP=1, write in progress */ + return u; +} +/*---------------------------------------------------------------------------*/ +/* + * Erase 64k bytes of data. It takes about 1s before WIP goes low! + */ +static void +erase_sector(unsigned long offset) +{ + int s; + wait_ready(); + + write_enable(); + + s = splhigh(); + SPI_FLASH_ENABLE(); + + //FASTSPI_TX(SPI_FLASH_INS_SE); + //FASTSPI_TX(offset >> 16); /* MSB */ + //FASTSPI_TX(offset >> 8); + //FASTSPI_TX(offset >> 0); /* LSB */ + //SPI_WAITFORTx_ENDED(); + + SPI_FLASH_DISABLE(); + splx(s); +} +/*---------------------------------------------------------------------------*/ +/* + * Initialize external flash *and* SPI bus! + */ +void +xmem_init(void) +{ + spi_init(); + + P4DIR |= BV(FLASH_CS) | BV(FLASH_HOLD) | BV(FLASH_PWR); + P4OUT |= BV(FLASH_PWR); /* P4.3 Output, turn on power! */ + + SPI_FLASH_DISABLE(); /* Unselect flash. */ + SPI_FLASH_UNHOLD(); +} +/*---------------------------------------------------------------------------*/ +int +xmem_pread(void *_p, int size, unsigned long offset) +{ + unsigned char *p = _p; + const unsigned char *end = p + size; + int s; + wait_ready(); + + ENERGEST_ON(ENERGEST_TYPE_FLASH_READ); + + s = splhigh(); + SPI_FLASH_ENABLE(); + + //FASTSPI_TX(SPI_FLASH_INS_READ); + //FASTSPI_TX(offset >> 16); /* MSB */ + //FASTSPI_TX(offset >> 8); + //FASTSPI_TX(offset >> 0); /* LSB */ + //SPI_WAITFORTx_ENDED(); + + //FASTSPI_CLEAR_RX(); + for(; p < end; p++) { + unsigned char u; + //FASTSPI_RX(u); + *p = ~u; + } + + SPI_FLASH_DISABLE(); + splx(s); + + ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ); + + return size; +} +/*---------------------------------------------------------------------------*/ +static const char * +program_page(unsigned long offset, const unsigned char *p, int nbytes) +{ + const unsigned char *end = p + nbytes; + int s; + + wait_ready(); + + write_enable(); + + s = splhigh(); + SPI_FLASH_ENABLE(); + + // FASTSPI_TX(SPI_FLASH_INS_PP); + //FASTSPI_TX(offset >> 16); /* MSB */ + //FASTSPI_TX(offset >> 8); + //FASTSPI_TX(offset >> 0); /* LSB */ + + for(; p < end; p++) { + //FASTSPI_TX(~*p); + } + //SPI_WAITFORTx_ENDED(); + + SPI_FLASH_DISABLE(); + splx(s); + + return p; +} +/*---------------------------------------------------------------------------*/ +int +xmem_pwrite(const void *_buf, int size, unsigned long addr) +{ + const unsigned char *p = _buf; + const unsigned long end = addr + size; + unsigned long i, next_page; + + ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE); + + for(i = addr; i < end;) { + next_page = (i | 0xff) + 1; + if(next_page > end) { + next_page = end; + } + p = program_page(i, p, next_page - i); + i = next_page; + } + + ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE); + + return size; +} +/*---------------------------------------------------------------------------*/ +int +xmem_erase(long size, unsigned long addr) +{ + unsigned long end = addr + size; + + if(size % XMEM_ERASE_UNIT_SIZE != 0) { + PRINTF("xmem_erase: bad size\n"); + return -1; + } + + if(addr % XMEM_ERASE_UNIT_SIZE != 0) { + PRINTF("xmem_erase: bad offset\n"); + return -1; + } + + watchdog_stop(); + + for (; addr < end; addr += XMEM_ERASE_UNIT_SIZE) { + erase_sector(addr); + } + + watchdog_start(); + + return size; +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/flash.c b/platform/wismote/flash.c new file mode 100644 index 000000000..774c33cf7 --- /dev/null +++ b/platform/wismote/flash.c @@ -0,0 +1,102 @@ +/** + * \file + * Functions for reading and writing flash ROM. + * \author Adam Dunkels + */ + +/* Copyright (c) 2004 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Adam Dunkels + * + */ + +#include "contiki.h" +#include "dev/flash.h" +#include "dev/watchdog.h" + +#define FLASH_TIMEOUT 30 +#define FLASH_REQ_TIMEOUT 150 + +static uint16_t sfrie; + +/*---------------------------------------------------------------------------*/ +void +flash_setup(void) +{ + /* disable all interrupts to protect CPU + during programming from system crash */ + dint(); + + /* Clear interrupt flag1. */ + SFRIFG1 = 0; + /* The IFG1 = 0; statement locks up contikimac - not sure if this + statement needs to be here at all. I've removed it for now, since + it seems to work, but leave this little note here in case someone + stumbles over this code at some point. */ + + /* Stop watchdog. */ + watchdog_stop(); + + /* disable all NMI-Interrupt sources */ + sfrie = SFRIE1; + SFRIE1 = 0x00; +} +/*---------------------------------------------------------------------------*/ +void +flash_done(void) +{ + /* Enable interrupts. */ + SFRIE1 = sfrie; + eint(); + watchdog_start(); +} +/*---------------------------------------------------------------------------*/ +void +flash_clear(unsigned short *ptr) +{ + uint8_t r; + FCTL3 = 0xA500; /* Lock = 0 */ + while(FCTL3 & 0x0001) r++; /* Wait for BUSY = 0, not needed + unless run from RAM */ + FCTL1 = 0xA502; /* ERASE = 1 */ + *ptr = 0; /* erase Flash segment */ + FCTL1 = 0xA500; /* ERASE = 0 automatically done?! */ + FCTL3 = 0xA510; /* Lock = 1 */ +} +/*---------------------------------------------------------------------------*/ +void +flash_write(unsigned short *ptr, unsigned short word) +{ + uint8_t r; + FCTL3 = 0xA500; /* Lock = 0 */ + while(FCTL3 & 0x0001) r++; /* Wait for BUSY = 0, not needed unless + run from RAM */ + FCTL1 = 0xA540; /* WRT = 1 */ + *ptr = word; /* program Flash word */ + FCTL1 = 0xA500; /* WRT = 0 */ + FCTL3 = 0xA510; /* Lock = 1 */ +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/node-id.c b/platform/wismote/node-id.c new file mode 100644 index 000000000..8cbecb1ae --- /dev/null +++ b/platform/wismote/node-id.c @@ -0,0 +1,72 @@ +/* + * 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 + */ + +#include "node-id.h" +#include "contiki-conf.h" +#include "dev/xmem.h" + +unsigned short node_id = 0; + +/*---------------------------------------------------------------------------*/ +void +node_id_restore(void) +{ + /* 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; + /* } */ +} +/*---------------------------------------------------------------------------*/ +void +node_id_burn(unsigned short id) +{ + /* 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); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/node-id.h b/platform/wismote/node-id.h new file mode 100644 index 000000000..592379fc9 --- /dev/null +++ b/platform/wismote/node-id.h @@ -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 + * + * $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__ */ diff --git a/platform/wismote/platform-conf.h b/platform/wismote/platform-conf.h new file mode 100644 index 000000000..98174bf00 --- /dev/null +++ b/platform/wismote/platform-conf.h @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/** + * \file + * Platform configuration for the wismote platform. + */ + +#ifndef __PLATFORM_CONF_H__ +#define __PLATFORM_CONF_H__ + +/* + * Definitions below are dictated by the hardware and not really + * changeable! + */ +/* Platform WISMOTE */ +#define WISMOTE 1 + +#define PLATFORM_HAS_LEDS 1 +#define PLATFORM_HAS_BUTTON 1 + +/* CPU target speed in Hz */ +#define F_CPU 16000000uL /*2457600uL*/ + +/* Our clock resolution, this is the same as Unix HZ. */ +#define CLOCK_CONF_SECOND 128UL + +#define BAUD2UBR(baud) ((F_CPU/baud)) + +#define CCIF +#define CLIF + +#define HAVE_STDINT_H +#include "msp430def.h" + + +/* Types for clocks and uip_stats */ +typedef unsigned short uip_stats_t; +typedef unsigned long clock_time_t; +typedef unsigned long off_t; + +/* the low-level radio driver */ +#define NETSTACK_CONF_RADIO cc2520_driver + +/* LED ports */ +#define LEDS_PxDIR P2DIR +#define LEDS_PxOUT P2OUT +#define LEDS_CONF_RED 0x10 +#define LEDS_CONF_GREEN 0 //0x20 +#define LEDS_CONF_YELLOW 0 //0x40 + +/* DCO speed resynchronization for more robust UART, etc. */ +#ifndef DCOSYNCH_CONF_ENABLED +#define DCOSYNCH_CONF_ENABLED 0 +#endif /* DCOSYNCH_CONF_ENABLED */ +#ifndef DCOSYNCH_CONF_PERIOD +#define DCOSYNCH_CONF_PERIOD 30 +#endif /* DCOSYNCH_CONF_PERIOD */ + +#define ROM_ERASE_UNIT_SIZE 512 +#define XMEM_ERASE_UNIT_SIZE (64*1024L) + + +#define CFS_CONF_OFFSET_TYPE long + + +/* Use the first 64k of external flash for node configuration */ +#define NODE_ID_XMEM_OFFSET (0 * XMEM_ERASE_UNIT_SIZE) + +/* Use the second 64k of external flash for codeprop. */ +#define EEPROMFS_ADDR_CODEPROP (1 * XMEM_ERASE_UNIT_SIZE) + +#define CFS_XMEM_CONF_OFFSET (2 * XMEM_ERASE_UNIT_SIZE) +#define CFS_XMEM_CONF_SIZE (1 * XMEM_ERASE_UNIT_SIZE) + +#define CFS_RAM_CONF_SIZE 4096 + +/* + * SPI bus configuration for the wismote + */ + +/* SPI input/output registers. */ +#define SPI_TXBUF UCB0TXBUF +#define SPI_RXBUF UCB0RXBUF + + /* USART0 Tx ready? */ +#define SPI_WAITFOREOTx() while (!(UCB0IFG & UCRXIFG)) + /* USART0 Rx ready? */ +#define SPI_WAITFOREORx() while (!(UCB0IFG & UCRXIFG)) + /* USART0 Tx buffer ready? */ +#define SPI_WAITFORTxREADY() while (!(UCB0IFG & UCRXIFG)) +#define SPI_BUSY_WAIT() while ((UCB0STAT & UCBUSY) == 1) + +#define SCK 1 /* P3.1 - Output: SPI Serial Clock (SCLK) */ +#define MOSI 2 /* P3.2 - Output: SPI Master out - slave in (MOSI) */ +#define MISO 3 /* P3.3 - Input: SPI Master in - slave out (MISO) */ + +/* + * SPI bus - M25P80 external flash configuration. + */ + +#define FLASH_PWR //3 /* P4.3 Output */ +#define FLASH_CS //4 /* P4.4 Output */ +#define FLASH_HOLD //7 /* P4.7 Output */ + +/* Enable/disable flash access to the SPI bus (active low). */ + +#define SPI_FLASH_ENABLE() //( P4OUT &= ~BV(FLASH_CS) ) +#define SPI_FLASH_DISABLE() //( P4OUT |= BV(FLASH_CS) ) + +#define SPI_FLASH_HOLD() // ( P4OUT &= ~BV(FLASH_HOLD) ) +#define SPI_FLASH_UNHOLD() //( P4OUT |= BV(FLASH_HOLD) ) + +/* + * SPI bus - CC2520 pin configuration. + */ + +#define CC2520_CONF_SYMBOL_LOOP_COUNT 800 + +/* P1.0 - Input: FIFOP from CC2520 */ +#define CC2520_FIFOP_PORT(type) P1##type +#define CC2520_FIFOP_PIN 6 +/* P1.3 - Input: FIFO from CC2520 */ +#define CC2520_FIFO_PORT(type) P1##type +#define CC2520_FIFO_PIN 5 +/* P1.4 - Input: CCA from CC2520 */ +#define CC2520_CCA_PORT(type) P1##type +#define CC2520_CCA_PIN 7 +/* P4.1 - Input: SFD from CC2520 */ +#define CC2520_SFD_PORT(type) P2##type +#define CC2520_SFD_PIN 0 +/* P4.2 - Output: SPI Chip Select (CS_N) */ +#define CC2520_CSN_PORT(type) P3##type +#define CC2520_CSN_PIN 0 +/* P4.5 - Output: VREG_EN to CC2520 */ +#define CC2520_VREG_PORT(type) P4##type +#define CC2520_VREG_PIN 3 +/* P4.6 - Output: RESET_N to CC2520 */ +#define CC2520_RESET_PORT(type) P4##type +#define CC2520_RESET_PIN 4 + +#define CC2520_IRQ_VECTOR PORT1_VECTOR + +/* Pin status.CC2520 */ +#define CC2520_FIFOP_IS_1 (!!(CC2520_FIFOP_PORT(IN) & BV(CC2520_FIFOP_PIN))) +#define CC2520_FIFO_IS_1 (!!(CC2520_FIFO_PORT(IN) & BV(CC2520_FIFO_PIN))) +#define CC2520_CCA_IS_1 (!!(CC2520_CCA_PORT(IN) & BV(CC2520_CCA_PIN))) +#define CC2520_SFD_IS_1 (!!(CC2520_SFD_PORT(IN) & BV(CC2520_SFD_PIN))) + +/* The CC2520 reset pin. */ +#define SET_RESET_INACTIVE() (CC2520_RESET_PORT(OUT) |= BV(CC2520_RESET_PIN)) +#define SET_RESET_ACTIVE() (CC2520_RESET_PORT(OUT) &= ~BV(CC2520_RESET_PIN)) + +/* CC2520 voltage regulator enable pin. */ +#define SET_VREG_ACTIVE() (CC2520_VREG_PORT(OUT) |= BV(CC2520_VREG_PIN)) +#define SET_VREG_INACTIVE() (CC2520_VREG_PORT(OUT) &= ~BV(CC2520_VREG_PIN)) + +/* CC2520 rising edge trigger for external interrupt 0 (FIFOP). */ +#define CC2520_FIFOP_INT_INIT() do { \ + CC2520_FIFOP_PORT(IES) &= ~BV(CC2520_FIFOP_PIN); \ + CC2520_CLEAR_FIFOP_INT(); \ + } while(0) + +/* FIFOP on external interrupt 0. */ +/* FIFOP on external interrupt 0. */ +#define CC2520_ENABLE_FIFOP_INT() do { P1IE |= BV(CC2520_FIFOP_PIN); } while (0) +#define CC2520_DISABLE_FIFOP_INT() do { P1IE &= ~BV(CC2520_FIFOP_PIN); } while (0) +#define CC2520_CLEAR_FIFOP_INT() do { P1IFG &= ~BV(CC2520_FIFOP_PIN); } while (0) + +/* + * Enables/disables CC2520 access to the SPI bus (not the bus). + * (Chip Select) + */ + + /* ENABLE CSn (active low) */ +#define CC2520_SPI_ENABLE() do{ UCB0CTL1 &= ~UCSWRST; clock_delay(5); P3OUT &= ~BIT0;clock_delay(5);}while(0) + /* DISABLE CSn (active low) */ +#define CC2520_SPI_DISABLE() do{clock_delay(5);UCB0CTL1 |= UCSWRST;clock_delay(1); P3OUT |= BIT0;clock_delay(5);}while(0) +#define CC2520_SPI_IS_ENABLED() ((CC2520_CSN_PORT(OUT) & BV(CC2520_CSN_PIN)) != BV(CC2520_CSN_PIN)) + +#endif /* __PLATFORM_CONF_H__ */ diff --git a/platform/wismote/spix.c b/platform/wismote/spix.c new file mode 100644 index 000000000..df0670b2b --- /dev/null +++ b/platform/wismote/spix.c @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#include "contiki.h" + +/* + * This is SPI initialization code for the MSP430X architecture. + * + */ + +unsigned char spi_busy = 0; + +/* + * Initialize SPI bus. + */ +void +spi_init(void) +{ + UCB0CTL1 |= UCSWRST; // Put state machine in reset + UCB0CTL1 = UCSSEL0 | UCSSEL1; // Select ACLK + UCB0CTL0 |= UCCKPH | UCSYNC | UCMSB | UCMST; // 3-pin, 8-bit SPI master, rising edge capture + + // 16 bit baud rate register + UCB0BR0 = 0x00; // MSB => 0 + UCB0BR1 = 0x08; // LSB => SMCLK / (UCxxBR0 + UCxxBR1 × 256) + + // Set MOSI and SCLK as OUT and MISO as IN ports + P3SEL |= ( BIT1 + BIT2 + BIT3 ); // Port3 = SPI peripheral + P3DIR |= ( BIT1 + BIT3 ); // MOSI and SCLK as Output + P3DIR &= ~BIT2; // Don't forget to configure MISO as Input + P3DIR |= BIT0; + + UCB0CTL1 &= ~UCSWRST; // Initialize USCI state machine +} From 6c5379606b5ba25a91600ed4c1749fa3015840de Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Wed, 21 Sep 2011 20:11:58 +0200 Subject: [PATCH 03/26] Set node_id, disabled watchdog for now --- platform/wismote/contiki-wismote-main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/wismote/contiki-wismote-main.c b/platform/wismote/contiki-wismote-main.c index 5aff6d108..e244b68ad 100644 --- a/platform/wismote/contiki-wismote-main.c +++ b/platform/wismote/contiki-wismote-main.c @@ -228,6 +228,7 @@ main(int argc, char **argv) /* Restore node id if such has been stored in external mem */ //node_id_restore(); + node_id = NODE_ID; /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ #ifdef IEEE_802154_MAC_ADDRESS @@ -279,10 +280,9 @@ main(int argc, char **argv) } #if WITH_UIP6 - //memcpy(&uip_lladdr.addr, ds2411_id, sizeof(uip_lladdr.addr)); - - for(i =0;i RIMEADDR_SIZE ? RIMEADDR_SIZE : UIP_LLADDR_LEN); /* Setup nullmac-like MAC for 802.15.4 */ /* sicslowpan_init(sicslowmac_init(&cc2520_driver)); */ @@ -391,6 +391,8 @@ main(int argc, char **argv) ENERGEST_ON(ENERGEST_TYPE_CPU); watchdog_start(); + /* Stop the watchdog */ + watchdog_stop(); print_processes(autostart_processes); autostart_start(autostart_processes); From 708f9d77d24039558b21127080a1e06808e89e89 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Wed, 21 Sep 2011 21:09:19 +0200 Subject: [PATCH 04/26] Corrected timing for higher CPU speed --- cpu/msp430/msp430.c | 35 +++++++++++++++++++++++++++++++- platform/wismote/platform-conf.h | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cpu/msp430/msp430.c b/cpu/msp430/msp430.c index 3f67bbd70..5a3c8226e 100644 --- a/cpu/msp430/msp430.c +++ b/cpu/msp430/msp430.c @@ -31,9 +31,11 @@ #include "contiki.h" #include "dev/watchdog.h" +#if DCOSYNCH_CONF_ENABLED /* dco_required set to 1 will cause the CPU not to go into sleep modes where the DCO clock stopped */ int msp430_dco_required; +#endif /* DCOSYNCH_CONF_ENABLED */ /*---------------------------------------------------------------------------*/ #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND @@ -66,7 +68,17 @@ w_memset(void *out, int value, size_t n) void msp430_init_dco(void) { -#if CONTIKI_TARGET_WISMOTE +#if CONTIKI_TARGET_WISMOTE && defined(__IAR_SYSTEMS_ICC__) + /* set to 8 MHz 244 * 32768 ? */ + /* set to 8 MHz 244 * 32768 (or 0x107a)? */ + __bis_SR_register(SCG0); + UCSCTL0 = 0x0000; + UCSCTL1 = DCORSEL_4; + + UCSCTL2 = 244 * 2; //0x107a; + UCSCTL4 = 0x33; /* instead of 0x44 that is DCO/2 */ + __bic_SR_register(SCG0); +#elif CONTIKI_TARGET_WISMOTE // Stop watchdog WDTCTL = WDTPW + WDTHOLD; @@ -213,17 +225,21 @@ static char *cur_break = (char *)&_end; void msp430_add_lpm_req(int req) { +#if DCOSYNCH_CONF_ENABLED if(req <= MSP430_REQUIRE_LPM1) { msp430_dco_required++; } +#endif /* DCOSYNCH_CONF_ENABLED */ } void msp430_remove_lpm_req(int req) { +#if DCOSYNCH_CONF_ENABLED if(req <= MSP430_REQUIRE_LPM1) { msp430_dco_required--; } +#endif /* DCOSYNCH_CONF_ENABLED */ } void @@ -240,7 +256,9 @@ msp430_cpu_init(void) } #endif +#if DCOSYNCH_CONF_ENABLED msp430_dco_required = 0; +#endif /* DCOSYNCH_CONF_ENABLED */ } /*---------------------------------------------------------------------------*/ @@ -307,6 +325,21 @@ splhigh_(void) /* #endif */ /* } */ /*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +int __low_level_init(void) +{ + /* turn off watchdog so that C-init will run */ + WDTCTL = WDTPW + WDTHOLD; + /* + * Return value: + * + * 1 - Perform data segment initialization. + * 0 - Skip data segment initialization. + */ + return 1; +} +#endif +/*---------------------------------------------------------------------------*/ #if DCOSYNCH_CONF_ENABLED /* this code will always start the TimerB if not already started */ void diff --git a/platform/wismote/platform-conf.h b/platform/wismote/platform-conf.h index 98174bf00..7d6ff5dd2 100644 --- a/platform/wismote/platform-conf.h +++ b/platform/wismote/platform-conf.h @@ -141,7 +141,7 @@ typedef unsigned long off_t; * SPI bus - CC2520 pin configuration. */ -#define CC2520_CONF_SYMBOL_LOOP_COUNT 800 +#define CC2520_CONF_SYMBOL_LOOP_COUNT 2604 /* 326us msp430X @ 16MHz */ /* P1.0 - Input: FIFOP from CC2520 */ #define CC2520_FIFOP_PORT(type) P1##type From 8aa1011c03e9475673262d550b297cc3f0fe8e1a Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 22 Sep 2011 13:03:49 +0200 Subject: [PATCH 05/26] Removed explicit specification of data model small for IAR compiler. Data model small is default and this will allow projects to override the data model --- platform/wismote/Makefile.wismote | 2 +- platform/z1/Makefile.common | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/wismote/Makefile.wismote b/platform/wismote/Makefile.wismote index cb5e620b8..a0efa14df 100644 --- a/platform/wismote/Makefile.wismote +++ b/platform/wismote/Makefile.wismote @@ -23,7 +23,7 @@ CFLAGS += -DWITH_UIP6=1 endif ifdef IAR -CFLAGS += -D__MSP430F5437__=1 -e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --data_model small --double=32 +CFLAGS += -D__MSP430F5437__=1 -e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --double=32 else SMALL=1 endif diff --git a/platform/z1/Makefile.common b/platform/z1/Makefile.common index 7164452e1..a3fa86c70 100644 --- a/platform/z1/Makefile.common +++ b/platform/z1/Makefile.common @@ -7,7 +7,7 @@ CFLAGS+=-Os -g endif ifdef IAR -CFLAGS+=-e --vla -Ohz --multiplier=16s --core=430X --data_model small --double=32 +CFLAGS+=-e --vla -Ohz --multiplier=16s --core=430X --double=32 endif CLEAN += symbols.c symbols.h From cd4be4927af0cb4e6395eef477b0bfee2e71d4ed Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 22 Sep 2011 16:43:59 +0200 Subject: [PATCH 06/26] Fixed quick dco sync to also work with mspgcc --- cpu/msp430/msp430.c | 51 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/cpu/msp430/msp430.c b/cpu/msp430/msp430.c index 5a3c8226e..26c816461 100644 --- a/cpu/msp430/msp430.c +++ b/cpu/msp430/msp430.c @@ -37,6 +37,9 @@ int msp430_dco_required; #endif /* DCOSYNCH_CONF_ENABLED */ +#if defined(__MSP430__) && defined(__GNUC__) +#define asmv(arg) __asm__ __volatile__(arg) +#endif /*---------------------------------------------------------------------------*/ #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND void * @@ -68,36 +71,25 @@ w_memset(void *out, int value, size_t n) void msp430_init_dco(void) { -#if CONTIKI_TARGET_WISMOTE && defined(__IAR_SYSTEMS_ICC__) - /* set to 8 MHz 244 * 32768 ? */ - /* set to 8 MHz 244 * 32768 (or 0x107a)? */ +#ifdef __MSP430X__ + +#ifdef __IAR_SYSTEMS_ICC__ __bis_SR_register(SCG0); +#else + asmv("bis %0, r2" : : "i" (SCG0)); +#endif + UCSCTL0 = 0x0000; UCSCTL1 = DCORSEL_4; - UCSCTL2 = 244 * 2; //0x107a; + UCSCTL2 = MSP430_CPU_SPEED / 32768; UCSCTL4 = 0x33; /* instead of 0x44 that is DCO/2 */ + +#ifdef __IAR_SYSTEMS_ICC__ __bic_SR_register(SCG0); -#elif CONTIKI_TARGET_WISMOTE - // Stop watchdog - WDTCTL = WDTPW + WDTHOLD; - - /** Configure XTAL **/ - P7SEL |= BIT0 + BIT1; // Activate XT1 - UCSCTL6 &= ~XT1OFF; // Set XT1 On - - UCSCTL6 |= XT1DRIVE_2 | XTS | XT2OFF; // Max drive strength, adjust - UCSCTL6 &= ~XT1DRIVE_1; - - do { - UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG); - // Clear XT2,XT1,DCO fault flags - SFRIFG1 &= ~OFIFG; // Clear fault flags - }while (SFRIFG1&OFIFG); // Test oscillator fault flag - - UCSCTL2 = FLLD0 + FLLD2; - UCSCTL5 |= DIVA__2 + DIVS__2+ DIVM__2;//DIVPA__32 + DIVA__32 + DIVS__2+ DIVM__2; - UCSCTL4 = SELA__DCOCLKDIV + SELS__XT1CLK + SELM__XT1CLK; // Set MCLCK = XT1/2 , SMCLK = XT1/2 , ACLK = XT1/2 +#else + asmv("bic %0, r2" : : "i" (SCG0)); +#endif #else /* This code taken from the FU Berlin sources and reformatted. */ @@ -206,6 +198,16 @@ init_ports(void) P6OUT = 0; #endif +#ifdef P7DIR + P7DIR = 0; + P7OUT = 0; +#endif + +#ifdef P8DIR + P8DIR = 0; + P8OUT = 0; +#endif + P1IE = 0; P2IE = 0; } @@ -272,7 +274,6 @@ msp430_cpu_init(void) * runtime. */ #if defined(__MSP430__) && defined(__GNUC__) -#define asmv(arg) __asm__ __volatile__(arg) void * sbrk(int incr) { From d1b22d40fa655734399eb79c0bf2970a9fcf1d20 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 22 Sep 2011 16:46:07 +0200 Subject: [PATCH 07/26] leds setup for WiSMote --- platform/wismote/contiki-wismote-main.c | 9 --- platform/wismote/leds-arch.c | 83 +++++++++++++++++++++++++ platform/wismote/platform-conf.h | 33 +++------- 3 files changed, 92 insertions(+), 33 deletions(-) create mode 100644 platform/wismote/leds-arch.c diff --git a/platform/wismote/contiki-wismote-main.c b/platform/wismote/contiki-wismote-main.c index e244b68ad..ab8cef083 100644 --- a/platform/wismote/contiki-wismote-main.c +++ b/platform/wismote/contiki-wismote-main.c @@ -397,12 +397,6 @@ main(int argc, char **argv) print_processes(autostart_processes); autostart_start(autostart_processes); - // LED Low Init - P2DIR |= BIT4;//TODO - P8DIR |= BIT6; - P2OUT |= BIT4; - P8OUT |= BIT6; - /* * This is the scheduler loop. */ @@ -454,9 +448,6 @@ main(int argc, char **argv) watchdog_start(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); - - /* P8OUT |= BIT6; */ - /* P2OUT |= BIT4; */ } } diff --git a/platform/wismote/leds-arch.c b/platform/wismote/leds-arch.c new file mode 100644 index 000000000..b168813b1 --- /dev/null +++ b/platform/wismote/leds-arch.c @@ -0,0 +1,83 @@ +/* + * 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. + * + */ + +/** + * \file + * Leds arch specific file for the WiSMote platform + * \author + * Niclas Finne + * Joakim Eriksson + */ + +#include "contiki.h" +#include "dev/leds.h" + +/*---------------------------------------------------------------------------*/ +void +leds_arch_init(void) +{ + P2DIR |= BIT4; + P2OUT |= BIT4; + P5OUT |= BIT2; + P5DIR |= BIT2; + P8DIR |= BIT6; + P8OUT |= BIT6; +} +/*---------------------------------------------------------------------------*/ +unsigned char +leds_arch_get(void) +{ + return ((P2OUT & BIT4) ? 0 : LEDS_GREEN) + | ((P5OUT & BIT2) ? 0 : LEDS_YELLOW) + | ((P8OUT & BIT6) ? 0 : LEDS_RED); +} +/*---------------------------------------------------------------------------*/ +void +leds_arch_set(unsigned char leds) +{ + if(leds & LEDS_GREEN) { + P2OUT &= ~BIT4; + } else { + P2OUT |= BIT4; + } + if(leds & LEDS_YELLOW) { + P5OUT &= ~BIT2; + } else { + P5OUT |= BIT2; + } + if(leds & LEDS_RED) { + P8OUT &= ~BIT6; + } else { + P8OUT |= BIT6; + } +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/platform-conf.h b/platform/wismote/platform-conf.h index 7d6ff5dd2..91d154a94 100644 --- a/platform/wismote/platform-conf.h +++ b/platform/wismote/platform-conf.h @@ -68,21 +68,6 @@ typedef unsigned long off_t; /* the low-level radio driver */ #define NETSTACK_CONF_RADIO cc2520_driver -/* LED ports */ -#define LEDS_PxDIR P2DIR -#define LEDS_PxOUT P2OUT -#define LEDS_CONF_RED 0x10 -#define LEDS_CONF_GREEN 0 //0x20 -#define LEDS_CONF_YELLOW 0 //0x40 - -/* DCO speed resynchronization for more robust UART, etc. */ -#ifndef DCOSYNCH_CONF_ENABLED -#define DCOSYNCH_CONF_ENABLED 0 -#endif /* DCOSYNCH_CONF_ENABLED */ -#ifndef DCOSYNCH_CONF_PERIOD -#define DCOSYNCH_CONF_PERIOD 30 -#endif /* DCOSYNCH_CONF_PERIOD */ - #define ROM_ERASE_UNIT_SIZE 512 #define XMEM_ERASE_UNIT_SIZE (64*1024L) @@ -143,25 +128,25 @@ typedef unsigned long off_t; #define CC2520_CONF_SYMBOL_LOOP_COUNT 2604 /* 326us msp430X @ 16MHz */ -/* P1.0 - Input: FIFOP from CC2520 */ -#define CC2520_FIFOP_PORT(type) P1##type -#define CC2520_FIFOP_PIN 6 -/* P1.3 - Input: FIFO from CC2520 */ +/* P1.6 - Input: FIFOP from CC2520 */ +#define CC2520_FIFOP_PORT(type) P1##type +#define CC2520_FIFOP_PIN 6 +/* P1.5 - Input: FIFO from CC2520 */ #define CC2520_FIFO_PORT(type) P1##type #define CC2520_FIFO_PIN 5 -/* P1.4 - Input: CCA from CC2520 */ +/* P1.7 - Input: CCA from CC2520 */ #define CC2520_CCA_PORT(type) P1##type #define CC2520_CCA_PIN 7 -/* P4.1 - Input: SFD from CC2520 */ +/* P2.0 - Input: SFD from CC2520 */ #define CC2520_SFD_PORT(type) P2##type #define CC2520_SFD_PIN 0 -/* P4.2 - Output: SPI Chip Select (CS_N) */ +/* P3.0 - Output: SPI Chip Select (CS_N) */ #define CC2520_CSN_PORT(type) P3##type #define CC2520_CSN_PIN 0 -/* P4.5 - Output: VREG_EN to CC2520 */ +/* P4.3 - Output: VREG_EN to CC2520 */ #define CC2520_VREG_PORT(type) P4##type #define CC2520_VREG_PIN 3 -/* P4.6 - Output: RESET_N to CC2520 */ +/* P4.4 - Output: RESET_N to CC2520 */ #define CC2520_RESET_PORT(type) P4##type #define CC2520_RESET_PIN 4 From b6fd166155fd6506f982f798e51a62312865ca00 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 23 Sep 2011 13:21:09 +0200 Subject: [PATCH 08/26] Removed obsolete CRC checksum handling and debug leds --- core/dev/cc2520.c | 106 ++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 78 deletions(-) diff --git a/core/dev/cc2520.c b/core/dev/cc2520.c index f3e97a060..9255f99a3 100644 --- a/core/dev/cc2520.c +++ b/core/dev/cc2520.c @@ -32,15 +32,8 @@ * This code is almost device independent and should be easy to port. */ -#include - #include "contiki.h" -#if defined(__AVR__) -#include -#endif - -#include "dev/leds.h" #include "dev/spi.h" #include "dev/cc2520.h" #include "dev/cc2520_const.h" @@ -50,28 +43,15 @@ #include "net/netstack.h" #include "sys/timetable.h" - -#define WITH_SEND_CCA 1 - -#define FOOTER_LEN 2 - -#ifndef CC2520_CONF_CHECKSUM -#define CC2520_CONF_CHECKSUM 0 -#endif /* CC2520_CONF_CHECKSUM */ +#include #ifndef CC2520_CONF_AUTOACK #define CC2520_CONF_AUTOACK 0 #endif /* CC2520_CONF_AUTOACK */ -#if CC2520_CONF_CHECKSUM -#include "lib/crc16.h" -#define CHECKSUM_LEN 2 -#else -#define CHECKSUM_LEN 0 -#endif /* CC2520_CONF_CHECKSUM */ - -#define AUX_LEN (CHECKSUM_LEN + FOOTER_LEN) +#define WITH_SEND_CCA 0 +#define FOOTER_LEN 2 #define FOOTER1_CRC_OK 0x80 #define FOOTER1_CORRELATION 0x7f @@ -84,10 +64,8 @@ #define PRINTF(...) #endif -#define DEBUG_LEDS DEBUG -#undef LEDS_ON -#undef LEDS_OFF -#if DEBUG_LEDS +#if 0 && DEBUG +#include "dev/leds.h" #define LEDS_ON(x) leds_on(x) #define LEDS_OFF(x) leds_off(x) #else @@ -299,8 +277,9 @@ cc2520_init(void) clock_delay(125); stat1 = status(); - while(!(stat1 & 0x80)) + while(!(stat1 & 0x80)) { stat1 = status(); + } /* Change default values as recommended in the data sheet, */ /* correlation threshold = 20, RX bandpass filter = 1.3uA.*/ @@ -361,26 +340,21 @@ cc2520_init(void) static int cc2520_transmit(unsigned short payload_len) { + uint16_t reg; int i, txpower; - uint8_t total_len; -#if CC2520_CONF_CHECKSUM - uint16_t checksum; -#endif /* CC2520_CONF_CHECKSUM */ GET_LOCK(); -#if (DEBUG == 1) - P8OUT &= ~BIT6; // TODO LED FLASH for the debug on transmission -#endif + + LEDS_ON(LEDS_RED); + txpower = 0; if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) { /* Remember the current transmission power */ txpower = cc2520_get_txpower(); /* Set the specified transmission power */ - //TODOset_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1); + set_txpower(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) - 1); } - total_len = payload_len + AUX_LEN; - /* The TX FIFO can only hold one packet. Make sure to not overrun * FIFO by waiting for transmission to start here and synchronizing * with the CC2520_TX_ACTIVE check in cc2520_send. @@ -446,11 +420,14 @@ cc2520_transmit(unsigned short payload_len) set_txpower(txpower & 0xff); } + reg = getreg(CC2520_EXCFLAG0); RELEASE_LOCK(); - if (getreg(CC2520_EXCFLAG0) & TX_FRM_DONE ) - return RADIO_TX_OK; - else - return RADIO_TX_COLLISION; + + if (reg & TX_FRM_DONE) { + return RADIO_TX_OK; + } else { + return RADIO_TX_COLLISION; + } } } @@ -472,9 +449,6 @@ static int cc2520_prepare(const void *payload, unsigned short payload_len) { uint8_t total_len; -#if CC2520_CONF_CHECKSUM - uint16_t checksum; -#endif /* CC2520_CONF_CHECKSUM */ GET_LOCK(); PRINTF("cc2520: sending %d bytes\n", payload_len); @@ -490,15 +464,9 @@ cc2520_prepare(const void *payload, unsigned short payload_len) /* Write packet to TX FIFO. */ strobe(CC2520_INS_SFLUSHTX); -#if CC2520_CONF_CHECKSUM - checksum = crc16_data(payload, payload_len, 0); -#endif /* CC2520_CONF_CHECKSUM */ - total_len = payload_len + AUX_LEN; + total_len = payload_len + FOOTER_LEN; CC2520_WRITE_FIFO_BUF(&total_len, 1); CC2520_WRITE_FIFO_BUF(payload, payload_len); -#if CC2520_CONF_CHECKSUM - CC2520_WRITE_FIFO_BUF(&checksum, CHECKSUM_LEN); -#endif /* CC2520_CONF_CHECKSUM */ RELEASE_LOCK(); return 0; @@ -685,7 +653,7 @@ PROCESS_THREAD(cc2520_process, ev, data) TIMETABLE_TIMESTAMP(cc2520_timetable, "end"); timetable_aggregate_compute_detailed(&aggregate_time, &cc2520_timetable); - timetable_clear(&cc2520_timetable); + timetable_clear(&cc2520_timetable); #endif /* CC2520_TIMETABLE_PROFILING */ } @@ -697,16 +665,11 @@ cc2520_read(void *buf, unsigned short bufsize) { uint8_t footer[2]; uint8_t len; -#if CC2520_CONF_CHECKSUM - uint16_t checksum; -#endif /* CC2520_CONF_CHECKSUM */ if((!CC2520_FIFOP_IS_1) & !(getreg(CC2520_EXCFLAG1) & RX_FRM_DONE)) { return 0; } -#if (DEBUG == 1) - P2OUT &= ~BIT4; // TODO LED FLASH for the debug on reception -#endif + LEDS_ON(LEDS_GREEN); // TODO LED FLASH for the debug on reception //BUSYWAIT_UNTIL( (status() & BV(CC2520_RX_ACTIVE)) , RTIMER_SECOND / 100); //BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG1) & RX_FRM_DONE , RTIMER_SECOND / 100); @@ -730,38 +693,25 @@ cc2520_read(void *buf, unsigned short bufsize) return 0; } - if(len <= AUX_LEN) { + if(len <= FOOTER_LEN) { flushrx(); RIMESTATS_ADD(tooshort); RELEASE_LOCK(); return 0; } - if(len - AUX_LEN > bufsize) { + if(len - FOOTER_LEN > bufsize) { flushrx(); RIMESTATS_ADD(toolong); RELEASE_LOCK(); return 0; } - getrxdata(buf, len - AUX_LEN); + getrxdata(buf, len - FOOTER_LEN); -#if CC2520_CONF_CHECKSUM - getrxdata(&checksum, CHECKSUM_LEN); -#endif /* CC2520_CONF_CHECKSUM */ getrxdata(footer, FOOTER_LEN); -#if CC2520_CONF_CHECKSUM - if(checksum != crc16_data(buf, len - AUX_LEN, 0)) { - PRINTF("checksum failed 0x%04x != 0x%04x\n", - checksum, crc16_data(buf, len - AUX_LEN, 0)); - } - - if(footer[1] & FOOTER1_CRC_OK && - checksum == crc16_data(buf, len - AUX_LEN, 0)) { -#else if(footer[1] & FOOTER1_CRC_OK) { -#endif /* CC2520_CONF_CHECKSUM */ cc2520_last_rssi = footer[0]; cc2520_last_correlation = footer[1] & FOOTER1_CORRELATION; @@ -773,7 +723,7 @@ cc2520_read(void *buf, unsigned short bufsize) } else { RIMESTATS_ADD(badcrc); - len = AUX_LEN; + len = FOOTER_LEN; } if(CC2520_FIFOP_IS_1) { @@ -790,11 +740,11 @@ cc2520_read(void *buf, unsigned short bufsize) RELEASE_LOCK(); - if(len < AUX_LEN) { + if(len < FOOTER_LEN) { return 0; } - return len - AUX_LEN; + return len - FOOTER_LEN; } /*---------------------------------------------------------------------------*/ void From 09082f02fe3fd0ca77af40fb205db83cb1fa427e Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 23 Sep 2011 13:22:18 +0200 Subject: [PATCH 09/26] Changed clock_delay to use the nop instruction --- cpu/msp430/clock.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cpu/msp430/clock.c b/cpu/msp430/clock.c index 06c737d2f..556fb6e82 100644 --- a/cpu/msp430/clock.c +++ b/cpu/msp430/clock.c @@ -272,17 +272,9 @@ clock_init(void) void clock_delay(unsigned int i) { - asm("add #-1, r15"); - asm("jnz $-2"); - /* - * This means that delay(i) will delay the CPU for CONST + 3x - * cycles. On a 2.4756 CPU, this means that each i adds 1.22us of - * delay. - * - * do { - * --i; - * } while(i > 0); - */ + while(i--) { + asm("nop"); + } } /*---------------------------------------------------------------------------*/ /** From f4f84ffca47715e09d6b4d9dfc25bc3d21b40ad0 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 23 Sep 2011 15:01:13 +0200 Subject: [PATCH 10/26] Updated SPI config for faster SPI, split msp430/clock/spi into separate versions for MSP430/MSP430X --- cpu/msp430/Makefile.msp430 | 6 +- cpu/msp430/cc2520-arch.c | 6 +- cpu/msp430/{ => f1xxx}/clock.c | 115 ++------- cpu/msp430/{ => f1xxx}/msp430.c | 46 +--- cpu/msp430/{ => f1xxx}/rtimer-arch.c | 41 +-- cpu/msp430/{ => f1xxx}/spi.c | 0 cpu/msp430/{ => f1xxx}/spix.c | 82 +++--- cpu/msp430/f5xxx/clock.c | 229 +++++++++++++++++ cpu/msp430/f5xxx/msp430.c | 238 ++++++++++++++++++ cpu/msp430/f5xxx/rtimer-arch.c | 107 ++++++++ {platform/wismote => cpu/msp430/f5xxx}/spix.c | 35 ++- cpu/msp430/rtimer-arch.h | 4 + platform/wismote/contiki-wismote-main.c | 2 - platform/wismote/platform-conf.h | 3 +- 14 files changed, 677 insertions(+), 237 deletions(-) rename cpu/msp430/{ => f1xxx}/clock.c (71%) rename cpu/msp430/{ => f1xxx}/msp430.c (91%) rename cpu/msp430/{ => f1xxx}/rtimer-arch.c (84%) rename cpu/msp430/{ => f1xxx}/spi.c (100%) rename cpu/msp430/{ => f1xxx}/spix.c (63%) create mode 100644 cpu/msp430/f5xxx/clock.c create mode 100644 cpu/msp430/f5xxx/msp430.c create mode 100644 cpu/msp430/f5xxx/rtimer-arch.c rename {platform/wismote => cpu/msp430/f5xxx}/spix.c (62%) diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 328089406..73dc45d98 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -11,7 +11,11 @@ CONTIKI_CPU=$(CONTIKI)/cpu/msp430 ### Define the source files we have in the MSP430 port -CONTIKI_CPU_DIRS = . dev +ifneq (,$(findstring msp430x5,$(MCU))) +CONTIKI_CPU_DIRS = ${addprefix f5xxx/,. dev} . dev +else +CONTIKI_CPU_DIRS = ${addprefix f1xxx/,. dev} . dev +endif MSP430 = msp430.c flash.c clock.c leds.c leds-arch.c \ watchdog.c lpm.c mtarch.c rtimer-arch.c diff --git a/cpu/msp430/cc2520-arch.c b/cpu/msp430/cc2520-arch.c index be73a9ab5..f6613dade 100644 --- a/cpu/msp430/cc2520-arch.c +++ b/cpu/msp430/cc2520-arch.c @@ -73,8 +73,10 @@ cc2520_arch_init(void) CC2520_VREG_PORT(DIR) |= BV(CC2520_VREG_PIN); CC2520_RESET_PORT(DIR) |= BV(CC2520_RESET_PIN); - P1DIR &= ~(BV(CC2520_FIFOP_PIN) | BV(CC2520_FIFO_PIN) | BV(CC2520_CCA_PIN)); - P2DIR &= ~(BV(CC2520_SFD_PIN)); + CC2520_FIFOP_PORT(DIR) &= ~(BV(CC2520_FIFOP_PIN)); + CC2520_FIFO_PORT(DIR) &= ~(BV(CC2520_FIFO_PIN)); + CC2520_CCA_PORT(DIR) &= ~(BV(CC2520_CCA_PIN)); + CC2520_SFD_PORT(DIR) &= ~(BV(CC2520_SFD_PIN)); #if CONF_SFD_TIMESTAMPS cc2520_arch_sfd_init(); diff --git a/cpu/msp430/clock.c b/cpu/msp430/f1xxx/clock.c similarity index 71% rename from cpu/msp430/clock.c rename to cpu/msp430/f1xxx/clock.c index 556fb6e82..5686f3fe9 100644 --- a/cpu/msp430/clock.c +++ b/cpu/msp430/f1xxx/clock.c @@ -27,11 +27,8 @@ * SUCH DAMAGE. * * This file is part of the Contiki operating system. - * - * @(#)$Id: clock.c,v 1.26 2010/12/16 22:50:21 adamdunkels Exp $ */ - #include "contiki.h" #include "sys/energest.h" #include "sys/clock.h" @@ -49,60 +46,6 @@ static volatile clock_time_t count = 0; /* last_tar is used for calculating clock_fine */ static volatile uint16_t last_tar = 0; /*---------------------------------------------------------------------------*/ -#if CONTIKI_TARGET_WISMOTE -#ifdef __IAR_SYSTEMS_ICC__ -#pragma vector=TIMER1_A1_VECTOR -__interrupt void -#else -interrupt(TIMER1_A1_VECTOR) -#endif -timera1 (void) -{ - ENERGEST_ON(ENERGEST_TYPE_IRQ); - - watchdog_start(); - - if(TA1IV == 2) { //CCR1 - - // HW timer bug fix: Interrupt handler called before TR==CCR. - // Occurrs when timer state is toggled between STOP and CONT. - while(TA1CTL & MC1 && TA1CCR1 - TA1R == 1); - - // Make sure interrupt time is futures - do { - TA1CCR1 += INTERVAL; - ++count; - - /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure - that the modulo operation below becomes a logical and and not - an expensive divide. Algorithm from Wikipedia: - http://en.wikipedia.org/wiki/Power_of_two */ -#if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 -#error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). -#error Change CLOCK_CONF_SECOND in contiki-conf.h. -#endif - if(count % CLOCK_CONF_SECOND == 0) { - ++seconds; - energest_flush(); - } - } while((TA1CCR1 - TA1R) > INTERVAL); - - last_tar = TA1R; - - if(etimer_pending() && - (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { - etimer_request_poll(); - LPM4_EXIT; - } - - } - /*if(process_nevents() >= 0) { - LPM4_EXIT; - }*/ - watchdog_stop(); - ENERGEST_OFF(ENERGEST_TYPE_IRQ); -} -#else #ifdef __IAR_SYSTEMS_ICC__ #pragma vector=TIMERA1_VECTOR __interrupt void @@ -118,7 +61,7 @@ timera1 (void) if(TAIV == 2) { /* HW timer bug fix: Interrupt handler called before TR==CCR. - * Occurrs when timer state is toggled between STOP and CONT. */ + * Occurs when timer state is toggled between STOP and CONT. */ while(TACTL & MC1 && TACCR1 - TAR == 1); /* Make sure interrupt time is future */ @@ -154,10 +97,9 @@ timera1 (void) }*/ watchdog_stop(); - + ENERGEST_OFF(ENERGEST_TYPE_IRQ); } -#endif /*---------------------------------------------------------------------------*/ clock_time_t clock_time(void) @@ -173,13 +115,8 @@ clock_time(void) void clock_set(clock_time_t clock, clock_time_t fclock) { -#if CONTIKI_TARGET_WISMOTE - TA1R = fclock; - TA1CCR1 = fclock + INTERVAL; -#else TAR = fclock; TACCR1 = fclock + INTERVAL; -#endif count = clock; } /*---------------------------------------------------------------------------*/ @@ -196,42 +133,14 @@ clock_fine(void) /* Assign last_tar to local varible that can not be changed by interrupt */ t = last_tar; /* perform calc based on t, TAR will not be changed during interrupt */ -#if CONTIKI_TARGET_WISMOTE - return (unsigned short) (TA1R - t); -#else return (unsigned short) (TAR - t); -#endif } /*---------------------------------------------------------------------------*/ void clock_init(void) { dint(); -#if CONTIKI_TARGET_WISMOTE - /* Select SMCLK (2.4576MHz), clear TAR */ - //TA1CTL = TASSEL1 | TACLR | ID_3; - /* Select ACLK clock, divide*/ - /* TA1CTL = TASSEL0 | TACLR | ID_1; */ - -#if INTERVAL==32768/CLOCK_SECOND - TA1CTL = TASSEL0 | TACLR; -#elif INTERVAL==16384/CLOCK_SECOND - TA1CTL = TASSEL0 | TACLR | ID_1; -#else -#error NEED TO UPDATE clock.c to match interval! -#endif - - /* Initialize ccr1 to create the X ms interval. */ - /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ - TA1CCTL1 = CCIE; - - /* Interrupt after X ms. */ - TA1CCR1 = INTERVAL; - - /* Start Timer_A in continuous mode. */ - TA1CTL |= MC1; -#else /* Select SMCLK (2.4576MHz), clear TAR */ /* TACTL = TASSEL1 | TACLR | ID_3; */ @@ -250,7 +159,7 @@ clock_init(void) #endif /* Initialize ccr1 to create the X ms interval. */ - /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ + /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR. */ TACCTL1 = CCIE; /* Interrupt after X ms. */ @@ -258,7 +167,7 @@ clock_init(void) /* Start Timer_A in continuous mode. */ TACTL |= MC1; -#endif + count = 0; /* Enable interrupts. */ @@ -293,7 +202,10 @@ clock_wait(int i) void clock_set_seconds(unsigned long sec) { - + int s; + s = splhigh(); + seconds = sec; + splx(s); } /*---------------------------------------------------------------------------*/ unsigned long @@ -310,10 +222,11 @@ clock_seconds(void) rtimer_clock_t clock_counter(void) { -#if CONTIKI_TARGET_WISMOTE - return TA1R; -#else - return TAR; -#endif + rtimer_clock_t t1, t2; + do { + t1 = TAR; + t2 = TAR; + } while(t1 != t2); + return t1; } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/msp430.c b/cpu/msp430/f1xxx/msp430.c similarity index 91% rename from cpu/msp430/msp430.c rename to cpu/msp430/f1xxx/msp430.c index 26c816461..eb0ca5515 100644 --- a/cpu/msp430/msp430.c +++ b/cpu/msp430/f1xxx/msp430.c @@ -28,18 +28,18 @@ * * This file is part of the Contiki operating system. */ + #include "contiki.h" #include "dev/watchdog.h" -#if DCOSYNCH_CONF_ENABLED /* dco_required set to 1 will cause the CPU not to go into sleep modes where the DCO clock stopped */ int msp430_dco_required; -#endif /* DCOSYNCH_CONF_ENABLED */ #if defined(__MSP430__) && defined(__GNUC__) #define asmv(arg) __asm__ __volatile__(arg) #endif + /*---------------------------------------------------------------------------*/ #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND void * @@ -71,27 +71,6 @@ w_memset(void *out, int value, size_t n) void msp430_init_dco(void) { -#ifdef __MSP430X__ - -#ifdef __IAR_SYSTEMS_ICC__ - __bis_SR_register(SCG0); -#else - asmv("bis %0, r2" : : "i" (SCG0)); -#endif - - UCSCTL0 = 0x0000; - UCSCTL1 = DCORSEL_4; - - UCSCTL2 = MSP430_CPU_SPEED / 32768; - UCSCTL4 = 0x33; /* instead of 0x44 that is DCO/2 */ - -#ifdef __IAR_SYSTEMS_ICC__ - __bic_SR_register(SCG0); -#else - asmv("bic %0, r2" : : "i" (SCG0)); -#endif - -#else /* This code taken from the FU Berlin sources and reformatted. */ #define DELTA ((MSP430_CPU_SPEED) / (32768 / 8)) @@ -109,8 +88,8 @@ msp430_init_dco(void) asm("nop"); } - CCTL2 = CCIS0 + CM0 + CAP; // Define CCR2, CAP, ACLK - TACTL = TASSEL1 + TACLR + MC1; // SMCLK, continous mode + CCTL2 = CCIS0 + CM0 + CAP; /* Define CCR2, CAP, ACLK */ + TACTL = TASSEL1 + TACLR + MC1; /* SMCLK, continous mode */ while(1) { @@ -141,15 +120,13 @@ msp430_init_dco(void) TACTL = 0; /* Stop Timer_A */ BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ - -#endif } /*---------------------------------------------------------------------------*/ - static void init_ports(void) { /* Turn everything off, device drivers enable what is needed. */ + /* All configured for digital I/O */ #ifdef P1SEL P1SEL = 0; @@ -227,21 +204,17 @@ static char *cur_break = (char *)&_end; void msp430_add_lpm_req(int req) { -#if DCOSYNCH_CONF_ENABLED if(req <= MSP430_REQUIRE_LPM1) { msp430_dco_required++; } -#endif /* DCOSYNCH_CONF_ENABLED */ } void msp430_remove_lpm_req(int req) { -#if DCOSYNCH_CONF_ENABLED if(req <= MSP430_REQUIRE_LPM1) { msp430_dco_required--; } -#endif /* DCOSYNCH_CONF_ENABLED */ } void @@ -258,14 +231,11 @@ msp430_cpu_init(void) } #endif -#if DCOSYNCH_CONF_ENABLED msp430_dco_required = 0; -#endif /* DCOSYNCH_CONF_ENABLED */ } /*---------------------------------------------------------------------------*/ #define STACK_EXTRA 32 -#define asmv(arg) __asm__ __volatile__(arg) /* * Allocate memory from the heap. Check that we don't collide with the @@ -357,13 +327,13 @@ msp430_sync_dco(void) { /* start the timer */ TBCTL |= MC1; - // wait for next Capture + /* wait for next Capture */ TBCCTL6 &= ~CCIFG; while(!(TBCCTL6 & CCIFG)); last = TBCCR6; TBCCTL6 &= ~CCIFG; - // wait for next Capture - and calculate difference + /* wait for next Capture - and calculate difference */ while(!(TBCCTL6 & CCIFG)); diff = TBCCR6 - last; @@ -381,7 +351,7 @@ msp430_sync_dco(void) { if(DCOCTL == 0xFF) { /* Did DCO role under? */ BCSCTL1--; } - } else if (DELTA_2 > diff) { + } else if(DELTA_2 > diff) { DCOCTL++; if(DCOCTL == 0x00) { /* Did DCO role over? */ BCSCTL1++; diff --git a/cpu/msp430/rtimer-arch.c b/cpu/msp430/f1xxx/rtimer-arch.c similarity index 84% rename from cpu/msp430/rtimer-arch.c rename to cpu/msp430/f1xxx/rtimer-arch.c index 50e6a2c76..9584ee4e7 100644 --- a/cpu/msp430/rtimer-arch.c +++ b/cpu/msp430/f1xxx/rtimer-arch.c @@ -39,6 +39,7 @@ */ #include "contiki.h" + #include "sys/energest.h" #include "sys/rtimer.h" #include "sys/process.h" @@ -53,32 +54,8 @@ #endif /*---------------------------------------------------------------------------*/ -#if CONTIKI_TARGET_WISMOTE #ifdef __IAR_SYSTEMS_ICC__ -#pragma vector=TIMER1_A0_VECTOR -__interrupt void -#else -interrupt(TIMER1_A0_VECTOR) -#endif -timera0 (void) -{ - ENERGEST_ON(ENERGEST_TYPE_IRQ); - - watchdog_start(); - - rtimer_run_next(); - - if(process_nevents() > 0) { - LPM4_EXIT; - } - - watchdog_stop(); - - ENERGEST_OFF(ENERGEST_TYPE_IRQ); -} -#else -#ifdef __IAR_SYSTEMS_ICC__ -#pragma vector=TIMER1_A0_VECTOR +#pragma vector=TIMERA0_VECTOR __interrupt void #else interrupt(TIMERA0_VECTOR) @@ -99,7 +76,6 @@ timera0 (void) ENERGEST_OFF(ENERGEST_TYPE_IRQ); } -#endif /*---------------------------------------------------------------------------*/ void rtimer_arch_init(void) @@ -107,11 +83,7 @@ rtimer_arch_init(void) dint(); /* CCR0 interrupt enabled, interrupt occurs when timer equals CCR0. */ -#if CONTIKI_TARGET_WISMOTE - TA1CCTL0 = CCIE; -#else TACCTL0 = CCIE; -#endif /* Enable interrupts. */ eint(); @@ -122,13 +94,8 @@ rtimer_arch_now(void) { rtimer_clock_t t1, t2; do { -#if CONTIKI_TARGET_WISMOTE - t1 = TA1R; - t2 = TA1R; -#else t1 = TAR; t2 = TAR; -#endif } while(t1 != t2); return t1; } @@ -138,10 +105,6 @@ rtimer_arch_schedule(rtimer_clock_t t) { PRINTF("rtimer_arch_schedule time %u\n", t); -#if CONTIKI_TARGET_WISMOTE - TA1CCR0 = t; -#else TACCR0 = t; -#endif } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/spi.c b/cpu/msp430/f1xxx/spi.c similarity index 100% rename from cpu/msp430/spi.c rename to cpu/msp430/f1xxx/spi.c diff --git a/cpu/msp430/spix.c b/cpu/msp430/f1xxx/spix.c similarity index 63% rename from cpu/msp430/spix.c rename to cpu/msp430/f1xxx/spix.c index 5e55d788b..0641b72ba 100644 --- a/cpu/msp430/spix.c +++ b/cpu/msp430/f1xxx/spix.c @@ -1,38 +1,39 @@ /* * Copyright (c) 2006, Swedish Institute of Computer Science - * All rights reserved. + * 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. + * 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 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: spix.c,v 1.1 2010/08/24 16:23:20 joxe Exp $ */ #include "contiki.h" + /* * This is SPI initialization code for the MSP430X architecture. - * + * */ unsigned char spi_busy = 0; @@ -47,29 +48,30 @@ spi_init(void) //if (spi_inited) //return; - // Initalize ports for communication with SPI units. + // Initalize ports for communication with SPI units. - UCB0CTL1 |= UCSWRST; //reset usci - UCB0CTL1 |= UCSSEL_2; //smclk while usci is reset - UCB0CTL0 = ( UCMSB | UCMST | UCSYNC | UCCKPL); // MSB-first 8-bit, Master, Synchronous, 3 pin SPI master, no ste, watch-out for clock-phase UCCKPH + UCB0CTL1 |= UCSWRST; //reset usci + UCB0CTL1 |= UCSSEL_2; //smclk while usci is reset + UCB0CTL0 = ( UCMSB | UCMST | UCSYNC | UCCKPL); // MSB-first 8-bit, Master, Synchronous, 3 pin SPI master, no ste, watch-out for clock-phase UCCKPH - UCB0BR1 = 0x00; - UCB0BR0 = 0x02; + UCB0BR1 = 0x00; + UCB0BR0 = 0x02; -// UCB0MCTL = 0; // Dont need modulation control. +// UCB0MCTL = 0; // Dont need modulation control. - P3SEL |= BV(SCK) | BV(MOSI) | BV(MISO); // Select Peripheral functionality - P3DIR |= BV(SCK) | BV(MISO); // Configure as outputs(SIMO,CLK). + P3SEL |= BV(SCK) | BV(MOSI) | BV(MISO); // Select Peripheral functionality + P3DIR |= BV(SCK) | BV(MISO); // Configure as outputs(SIMO,CLK). - //ME1 |= USPIE0; // Module enable ME1 --> U0ME? xxx/bg - - // Clear pending interrupts before enable!!! + //ME1 |= USPIE0; // Module enable ME1 --> U0ME? xxx/bg + + // Clear pending interrupts before enable!!! IFG2 &= ~UCB0RXIFG; IFG2 &= ~UCB0TXIFG; - UCB0CTL1 &= ~UCSWRST; // Remove RESET before enabling interrupts - //Enable UCB0 Interrupts + /* UCB0IE &= ~UCRXIFG; */ + /* UCB0IE &= ~UCTXIFG; */ + UCB0CTL1 &= ~UCSWRST; // Remove RESET before enabling interrupts + + //Enable UCB0 Interrupts //IE2 |= UCB0TXIE; // Enable USCI_B0 TX Interrupts //IE2 |= UCB0RXIE; // Enable USCI_B0 RX Interrupts } - - diff --git a/cpu/msp430/f5xxx/clock.c b/cpu/msp430/f5xxx/clock.c new file mode 100644 index 000000000..403799311 --- /dev/null +++ b/cpu/msp430/f5xxx/clock.c @@ -0,0 +1,229 @@ +/* + * 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. + */ + +#include "contiki.h" +#include "sys/energest.h" +#include "sys/clock.h" +#include "sys/etimer.h" +#include "rtimer-arch.h" +#include "dev/watchdog.h" + +#define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND) + +#define MAX_TICKS (~((clock_time_t)0) / 2) + +static volatile unsigned long seconds; + +static volatile clock_time_t count = 0; +/* last_tar is used for calculating clock_fine, last_ccr might be better? */ +static volatile uint16_t last_tar = 0; +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=TIMER1_A1_VECTOR +__interrupt void +#else +interrupt(TIMER1_A1_VECTOR) +#endif +timera1 (void) +{ + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + /* watchdog_start(); */ + + if(TA1IV == 2) { + + /* HW timer bug fix: Interrupt handler called before TR==CCR. + * Occurs when timer state is toggled between STOP and CONT. */ + while(TA1CTL & MC1 && TA1CCR1 - TA1R == 1); + + /* Make sure interrupt time is future */ + do { + TA1CCR1 += INTERVAL; + ++count; + + /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure + that the modulo operation below becomes a logical and and not + an expensive divide. Algorithm from Wikipedia: + http://en.wikipedia.org/wiki/Power_of_two */ +#if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 +#error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). +#error Change CLOCK_CONF_SECOND in contiki-conf.h. +#endif + if(count % CLOCK_CONF_SECOND == 0) { + ++seconds; + energest_flush(); + } + } while((TA1CCR1 - TA1R) > INTERVAL); + + last_tar = TA1R; + + if(etimer_pending() && + (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { + etimer_request_poll(); + LPM4_EXIT; + } + + } + /* if(process_nevents() >= 0) { + LPM4_EXIT; + }*/ + + /* watchdog_stop(); */ + + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ +clock_time_t +clock_time(void) +{ + clock_time_t t1, t2; + do { + t1 = count; + t2 = count; + } while(t1 != t2); + return t1; +} +/*---------------------------------------------------------------------------*/ +void +clock_set(clock_time_t clock, clock_time_t fclock) +{ + TA1R = fclock; + TA1CCR1 = fclock + INTERVAL; + count = clock; +} +/*---------------------------------------------------------------------------*/ +int +clock_fine_max(void) +{ + return INTERVAL; +} +/*---------------------------------------------------------------------------*/ +unsigned short +clock_fine(void) +{ + unsigned short t; + /* Assign last_tar to local varible that can not be changed by interrupt */ + t = last_tar; + /* perform calc based on t, TAR will not be changed during interrupt */ + return (unsigned short) (TA1R - t); +} +/*---------------------------------------------------------------------------*/ +void +clock_init(void) +{ + dint(); + + /* Select SMCLK (2.4576MHz), clear TAR */ + /* TACTL = TASSEL1 | TACLR | ID_3; */ + + /* Select ACLK 32768Hz clock, divide by 2 */ +/* TA1CTL = TASSEL0 | TACLR | ID_1; */ + +#if INTERVAL==32768/CLOCK_SECOND + TA1CTL = TASSEL0 | TACLR; +#elif INTERVAL==16384/CLOCK_SECOND + TA1CTL = TASSEL0 | TACLR | ID_1; +#else +#error NEED TO UPDATE clock.c to match interval! +#endif + + /* Initialize ccr1 to create the X ms interval. */ + /* CCR1 interrupt enabled, interrupt occurs when timer equals CCR1. */ + TA1CCTL1 = CCIE; + + /* Interrupt after X ms. */ + TA1CCR1 = INTERVAL; + + /* Start Timer_A in continuous mode. */ + TA1CTL |= MC1; + + count = 0; + + /* Enable interrupts. */ + eint(); + +} +/*---------------------------------------------------------------------------*/ +/** + * Delay the CPU for a multiple of 2.83 us. + */ +void +clock_delay(unsigned int i) +{ + while(i--) { + asm("nop"); + } +} +/*---------------------------------------------------------------------------*/ +/** + * Wait for a multiple of 10 ms. + * + */ +void +clock_wait(int i) +{ + clock_time_t start; + + start = clock_time(); + while(clock_time() - start < (clock_time_t)i); +} +/*---------------------------------------------------------------------------*/ +void +clock_set_seconds(unsigned long sec) +{ + int s; + s = splhigh(); + seconds = sec; + splx(s); +} +/*---------------------------------------------------------------------------*/ +unsigned long +clock_seconds(void) +{ + unsigned long t1, t2; + do { + t1 = seconds; + t2 = seconds; + } while(t1 != t2); + return t1; +} +/*---------------------------------------------------------------------------*/ +rtimer_clock_t +clock_counter(void) +{ + rtimer_clock_t t1, t2; + do { + t1 = TA1R; + t2 = TA1R; + } while(t1 != t2); + return t1; +} +/*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/f5xxx/msp430.c b/cpu/msp430/f5xxx/msp430.c new file mode 100644 index 000000000..cc678ee36 --- /dev/null +++ b/cpu/msp430/f5xxx/msp430.c @@ -0,0 +1,238 @@ +/* + * 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. + */ +#include "contiki.h" +#include "dev/watchdog.h" + +/* dco_required set to 1 will cause the CPU not to go into + sleep modes where the DCO clock stopped */ +int msp430_dco_required; + +#if defined(__MSP430__) && defined(__GNUC__) +#define asmv(arg) __asm__ __volatile__(arg) +#endif +/*---------------------------------------------------------------------------*/ +void +msp430_init_dco(void) +{ +#ifdef __IAR_SYSTEMS_ICC__ + __bis_SR_register(SCG0); +#else + asmv("bis %0, r2" : : "i" (SCG0)); +#endif + + UCSCTL0 = 0x0000; + UCSCTL1 = DCORSEL_4; + + UCSCTL2 = MSP430_CPU_SPEED / 32768; + UCSCTL4 = 0x33; /* instead of 0x44 that is DCO/2 */ + +#ifdef __IAR_SYSTEMS_ICC__ + __bic_SR_register(SCG0); +#else + asmv("bic %0, r2" : : "i" (SCG0)); +#endif +} +/*---------------------------------------------------------------------------*/ + +static void +init_ports(void) +{ + /* Turn everything off, device drivers enable what is needed. */ + /* All configured for digital I/O */ +#ifdef P1SEL + P1SEL = 0; +#endif +#ifdef P2SEL + P2SEL = 0; +#endif +#ifdef P3SEL + P3SEL = 0; +#endif +#ifdef P4SEL + P4SEL = 0; +#endif +#ifdef P5SEL + P5SEL = 0; +#endif +#ifdef P6SEL + P6SEL = 0; +#endif + + /* All available inputs */ +#ifdef P1DIR + P1DIR = 0; + P1OUT = 0; +#endif +#ifdef P2DIR + P2DIR = 0; + P2OUT = 0; +#endif +#ifdef P3DIR + P3DIR = 0; + P3OUT = 0; +#endif +#ifdef P4DIR + P4DIR = 0; + P4OUT = 0; +#endif + +#ifdef P5DIR + P5DIR = 0; + P5OUT = 0; +#endif + +#ifdef P6DIR + P6DIR = 0; + P6OUT = 0; +#endif + +#ifdef P7DIR + P7DIR = 0; + P7OUT = 0; +#endif + +#ifdef P8DIR + P8DIR = 0; + P8OUT = 0; +#endif + + P1IE = 0; + P2IE = 0; +} +/*---------------------------------------------------------------------------*/ +/* msp430-ld may align _end incorrectly. Workaround in cpu_init. */ +#if defined(__MSP430__) && defined(__GNUC__) +extern int _end; /* Not in sys/unistd.h */ +static char *cur_break = (char *)&_end; +#endif + +/*---------------------------------------------------------------------------*/ +/* add/remove_lpm_req - for requiring a specific LPM mode. currently Contiki */ +/* jumps to LPM3 to save power, but DMA will not work if DCO is not clocked */ +/* so some modules might need to enter their LPM requirements */ +/* NOTE: currently only works with LPM1 (e.g. DCO) requirements. */ +/*---------------------------------------------------------------------------*/ +void +msp430_add_lpm_req(int req) +{ + if(req <= MSP430_REQUIRE_LPM1) { + msp430_dco_required++; + } +} + +void +msp430_remove_lpm_req(int req) +{ + if(req <= MSP430_REQUIRE_LPM1) { + msp430_dco_required--; + } +} + +void +msp430_cpu_init(void) +{ + dint(); + watchdog_init(); + init_ports(); + msp430_init_dco(); + eint(); +#if defined(__MSP430__) && defined(__GNUC__) + if((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug! */ + cur_break++; + } +#endif + + msp430_dco_required = 0; +} +/*---------------------------------------------------------------------------*/ + +#define STACK_EXTRA 32 + +/* + * Allocate memory from the heap. Check that we don't collide with the + * stack right now (some other routine might later). A watchdog might + * be used to check if cur_break and the stack pointer meet during + * runtime. + */ +#if defined(__MSP430__) && defined(__GNUC__) +void * +sbrk(int incr) +{ + char *stack_pointer; + + asmv("mov r1, %0" : "=r" (stack_pointer)); + stack_pointer -= STACK_EXTRA; + if(incr > (stack_pointer - cur_break)) + return (void *)-1; /* ENOMEM */ + + void *old_break = cur_break; + cur_break += incr; + /* + * If the stack was never here then [old_break .. cur_break] should + * be filled with zeros. + */ + return old_break; +} +#endif +/*---------------------------------------------------------------------------*/ +/* + * Mask all interrupts that can be masked. + */ +int +splhigh_(void) +{ + int sr; + /* Clear the GIE (General Interrupt Enable) flag. */ +#ifdef __IAR_SYSTEMS_ICC__ + sr = __get_SR_register(); + __bic_SR_register(GIE); +#else + asmv("mov r2, %0" : "=r" (sr)); + asmv("bic %0, r2" : : "i" (GIE)); +#endif + return sr & GIE; /* Ignore other sr bits. */ +} +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +int __low_level_init(void) +{ + /* turn off watchdog so that C-init will run */ + WDTCTL = WDTPW + WDTHOLD; + /* + * Return value: + * + * 1 - Perform data segment initialization. + * 0 - Skip data segment initialization. + */ + return 1; +} +#endif +/*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/f5xxx/rtimer-arch.c b/cpu/msp430/f5xxx/rtimer-arch.c new file mode 100644 index 000000000..910d76b9c --- /dev/null +++ b/cpu/msp430/f5xxx/rtimer-arch.c @@ -0,0 +1,107 @@ +/* + * 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. + */ + +/** + * \file + * MSP430-specific rtimer code for MSP430X + * \author + * Adam Dunkels + */ + +#include "contiki.h" +#include "sys/energest.h" +#include "sys/rtimer.h" +#include "sys/process.h" +#include "dev/watchdog.h" + +#define DEBUG 0 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=TIMER1_A0_VECTOR +__interrupt void +#else +interrupt(TIMER1_A0_VECTOR) +#endif +timera0 (void) +{ + ENERGEST_ON(ENERGEST_TYPE_IRQ); + + watchdog_start(); + + rtimer_run_next(); + + if(process_nevents() > 0) { + LPM4_EXIT; + } + + watchdog_stop(); + + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ +void +rtimer_arch_init(void) +{ + dint(); + + /* CCR0 interrupt enabled, interrupt occurs when timer equals CCR0. */ + TA1CCTL0 = CCIE; + + /* Enable interrupts. */ + eint(); +} +/*---------------------------------------------------------------------------*/ +rtimer_clock_t +rtimer_arch_now(void) +{ + rtimer_clock_t t1, t2; + do { + t1 = TA1R; + t2 = TA1R; + } while(t1 != t2); + return t1; +} +/*---------------------------------------------------------------------------*/ +void +rtimer_arch_schedule(rtimer_clock_t t) +{ + PRINTF("rtimer_arch_schedule time %u\n", t); + + TA1CCR0 = t; +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/spix.c b/cpu/msp430/f5xxx/spix.c similarity index 62% rename from platform/wismote/spix.c rename to cpu/msp430/f5xxx/spix.c index df0670b2b..b92ca0ec7 100644 --- a/platform/wismote/spix.c +++ b/cpu/msp430/f5xxx/spix.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Swedish Institute of Computer Science. + * Copyright (c) 2011, Swedish Institute of Computer Science * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,19 +42,28 @@ unsigned char spi_busy = 0; void spi_init(void) { - UCB0CTL1 |= UCSWRST; // Put state machine in reset - UCB0CTL1 = UCSSEL0 | UCSSEL1; // Select ACLK - UCB0CTL0 |= UCCKPH | UCSYNC | UCMSB | UCMST; // 3-pin, 8-bit SPI master, rising edge capture + // Initialize ports for communication with SPI units. - // 16 bit baud rate register - UCB0BR0 = 0x00; // MSB => 0 - UCB0BR1 = 0x08; // LSB => SMCLK / (UCxxBR0 + UCxxBR1 × 256) + UCB0CTL1 |= UCSWRST; //reset usci + UCB0CTL1 |= UCSSEL_2; //smclk while usci is reset + UCB0CTL0 = ( UCMSB | UCMST | UCSYNC | UCCKPL); // MSB-first 8-bit, Master, Synchronous, 3 pin SPI master, no ste, watch-out for clock-phase UCCKPH - // Set MOSI and SCLK as OUT and MISO as IN ports - P3SEL |= ( BIT1 + BIT2 + BIT3 ); // Port3 = SPI peripheral - P3DIR |= ( BIT1 + BIT3 ); // MOSI and SCLK as Output - P3DIR &= ~BIT2; // Don't forget to configure MISO as Input - P3DIR |= BIT0; + UCB0BR1 = 0x00; + UCB0BR0 = 0x02; - UCB0CTL1 &= ~UCSWRST; // Initialize USCI state machine +// UCB0MCTL = 0; // Dont need modulation control. + + P3SEL |= BV(SCK) | BV(MOSI) | BV(MISO); // Select Peripheral functionality + P3DIR |= BV(SCK) | BV(MISO); // Configure as outputs(SIMO,CLK). + + //ME1 |= USPIE0; // Module enable ME1 --> U0ME? xxx/bg + + // Clear pending interrupts before enable!!! + UCB0IE &= ~UCRXIFG; + UCB0IE &= ~UCTXIFG; + UCB0CTL1 &= ~UCSWRST; // Remove RESET before enabling interrupts + + //Enable UCB0 Interrupts + //IE2 |= UCB0TXIE; // Enable USCI_B0 TX Interrupts + //IE2 |= UCB0RXIE; // Enable USCI_B0 RX Interrupts } diff --git a/cpu/msp430/rtimer-arch.h b/cpu/msp430/rtimer-arch.h index d90d1e437..9faca1589 100644 --- a/cpu/msp430/rtimer-arch.h +++ b/cpu/msp430/rtimer-arch.h @@ -43,7 +43,11 @@ #include "sys/rtimer.h" +#ifdef RTIMER_CONF_SECOND +#define RTIMER_ARCH_SECOND RTIMER_CONF_SECOND +#else #define RTIMER_ARCH_SECOND (4096U*8) +#endif rtimer_clock_t rtimer_arch_now(void); diff --git a/platform/wismote/contiki-wismote-main.c b/platform/wismote/contiki-wismote-main.c index ab8cef083..f7a456f88 100644 --- a/platform/wismote/contiki-wismote-main.c +++ b/platform/wismote/contiki-wismote-main.c @@ -450,8 +450,6 @@ main(int argc, char **argv) ENERGEST_ON(ENERGEST_TYPE_CPU); } } - - return 0; } /*---------------------------------------------------------------------------*/ #if LOG_CONF_ENABLED diff --git a/platform/wismote/platform-conf.h b/platform/wismote/platform-conf.h index 91d154a94..e5b8b481c 100644 --- a/platform/wismote/platform-conf.h +++ b/platform/wismote/platform-conf.h @@ -46,10 +46,11 @@ #define PLATFORM_HAS_BUTTON 1 /* CPU target speed in Hz */ -#define F_CPU 16000000uL /*2457600uL*/ +#define F_CPU 16000000uL /* Our clock resolution, this is the same as Unix HZ. */ #define CLOCK_CONF_SECOND 128UL +#define RTIMER_CONF_SECOND (4096U*8) #define BAUD2UBR(baud) ((F_CPU/baud)) From a56793f401054b333a57ebf8bed3d5bb5d238e4b Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 23 Sep 2011 15:49:00 +0200 Subject: [PATCH 11/26] Fixed compiler warnings --- core/lib/sensors.c | 10 +++++----- core/lib/sensors.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/lib/sensors.c b/core/lib/sensors.c index 54bb204cf..85018552c 100644 --- a/core/lib/sensors.c +++ b/core/lib/sensors.c @@ -39,7 +39,7 @@ #include "lib/sensors.h" -extern struct sensors_sensor *sensors[]; +const extern struct sensors_sensor *sensors[]; extern unsigned char sensors_flags[]; #define FLAG_CHANGED 0x80 @@ -63,13 +63,13 @@ get_sensor_index(const struct sensors_sensor *s) return i; } /*---------------------------------------------------------------------------*/ -struct sensors_sensor * +const struct sensors_sensor * sensors_first(void) { return sensors[0]; } /*---------------------------------------------------------------------------*/ -struct sensors_sensor * +const struct sensors_sensor * sensors_next(const struct sensors_sensor *s) { return sensors[get_sensor_index(s) + 1]; @@ -82,7 +82,7 @@ sensors_changed(const struct sensors_sensor *s) process_poll(&sensors_process); } /*---------------------------------------------------------------------------*/ -struct sensors_sensor * +const struct sensors_sensor * sensors_find(const char *prefix) { int i; @@ -123,7 +123,7 @@ PROCESS_THREAD(sensors_process, ev, data) events = 0; for(i = 0; i < num_sensors; ++i) { if(sensors_flags[i] & FLAG_CHANGED) { - if(process_post(PROCESS_BROADCAST, sensors_event, sensors[i]) == PROCESS_ERR_OK) { + if(process_post(PROCESS_BROADCAST, sensors_event, (void *)sensors[i]) == PROCESS_ERR_OK) { PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event); } sensors_flags[i] &= ~FLAG_CHANGED; diff --git a/core/lib/sensors.h b/core/lib/sensors.h index 07955a924..6872ae9f1 100644 --- a/core/lib/sensors.h +++ b/core/lib/sensors.h @@ -60,9 +60,9 @@ struct sensors_sensor { int (* status) (int type); }; -struct sensors_sensor *sensors_find(const char *type); -struct sensors_sensor *sensors_next(const struct sensors_sensor *s); -struct sensors_sensor *sensors_first(void); +const struct sensors_sensor *sensors_find(const char *type); +const struct sensors_sensor *sensors_next(const struct sensors_sensor *s); +const struct sensors_sensor *sensors_first(void); void sensors_changed(const struct sensors_sensor *s); From 1a761ec3eb1d8a647713a29279f5aa83d8521c4f Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 27 Sep 2011 23:54:59 +0200 Subject: [PATCH 12/26] fixed compiler warning --- apps/rest-coap/coap-server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rest-coap/coap-server.c b/apps/rest-coap/coap-server.c index 62ff76870..2fb944325 100644 --- a/apps/rest-coap/coap-server.c +++ b/apps/rest-coap/coap-server.c @@ -422,7 +422,7 @@ handle_incoming_data(void) PRINTF("uip_datalen received %u \n",(u16_t)uip_datalen()); - char* data = uip_appdata + uip_ext_len; + char* data = (char *)uip_appdata + uip_ext_len; u16_t datalen = uip_datalen() - uip_ext_len; int data_size = 0; From cdfa8708e3b3e143fe35515e3ee5075534e3a08e Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 6 Oct 2011 14:05:57 +0200 Subject: [PATCH 13/26] * Added f2xxx for two series (for example z1) * f1xxx is baseline and always included * Cleaned up the names of uart and spi (no x in names) * Updated SPI configuration for WiSMote --- cpu/msp430/Makefile.msp430 | 8 +- cpu/msp430/f1xxx/clock.c | 2 +- cpu/msp430/{dev => f1xxx}/uart1.c | 86 +------------- cpu/msp430/{f1xxx/spix.c => f2xxx/spi.c} | 9 +- cpu/msp430/{dev/uart0x.c => f2xxx/uart0.c} | 0 cpu/msp430/{dev/uart1x.c => f2xxx/uart1.c} | 0 cpu/msp430/f5xxx/clock.c | 2 +- cpu/msp430/f5xxx/{spix.c => spi.c} | 0 cpu/msp430/f5xxx/uart0.c | 126 ++++++++++++++++++++ cpu/msp430/f5xxx/uart1.c | 131 +++++++++++++++++++++ platform/wismote/Makefile.wismote | 2 +- platform/wismote/contiki-wismote-main.c | 4 +- platform/wismote/dev/spi.h | 92 --------------- platform/wismote/platform-conf.h | 27 +++-- platform/z1/Makefile.common | 4 +- 15 files changed, 289 insertions(+), 204 deletions(-) rename cpu/msp430/{dev => f1xxx}/uart1.c (80%) rename cpu/msp430/{f1xxx/spix.c => f2xxx/spi.c} (93%) rename cpu/msp430/{dev/uart0x.c => f2xxx/uart0.c} (100%) rename cpu/msp430/{dev/uart1x.c => f2xxx/uart1.c} (100%) rename cpu/msp430/f5xxx/{spix.c => spi.c} (100%) create mode 100644 cpu/msp430/f5xxx/uart0.c create mode 100644 cpu/msp430/f5xxx/uart1.c delete mode 100644 platform/wismote/dev/spi.h diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 73dc45d98..687853bf6 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -12,11 +12,15 @@ CONTIKI_CPU=$(CONTIKI)/cpu/msp430 ### Define the source files we have in the MSP430 port ifneq (,$(findstring msp430x5,$(MCU))) -CONTIKI_CPU_DIRS = ${addprefix f5xxx/,. dev} . dev + CONTIKI_CPU_FAM_DIR = f5xxx else -CONTIKI_CPU_DIRS = ${addprefix f1xxx/,. dev} . dev + ifneq (,$(findstring msp430x2,$(MCU))) + CONTIKI_CPU_FAM_DIR = f2xxx + endif endif +CONTIKI_CPU_DIRS = $(CONTIKI_CPU_FAM_DIR) f1xxx . dev + MSP430 = msp430.c flash.c clock.c leds.c leds-arch.c \ watchdog.c lpm.c mtarch.c rtimer-arch.c UIPDRIVERS = me.c me_tabs.c slip.c crc16.c diff --git a/cpu/msp430/f1xxx/clock.c b/cpu/msp430/f1xxx/clock.c index 5686f3fe9..b133eaa6e 100644 --- a/cpu/msp430/f1xxx/clock.c +++ b/cpu/msp430/f1xxx/clock.c @@ -182,7 +182,7 @@ void clock_delay(unsigned int i) { while(i--) { - asm("nop"); + _NOP(); } } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/dev/uart1.c b/cpu/msp430/f1xxx/uart1.c similarity index 80% rename from cpu/msp430/dev/uart1.c rename to cpu/msp430/f1xxx/uart1.c index cfc624bed..f9bf8ce52 100644 --- a/cpu/msp430/dev/uart1.c +++ b/cpu/msp430/f1xxx/uart1.c @@ -92,11 +92,7 @@ handle_rxdma_timer(void *ptr) uint8_t uart1_active(void) { -#if CONTIKI_TARGET_WISMOTE - return rx_in_progress | transmitting; -#else return ((~ UTCTL1) & TXEPT) | rx_in_progress | transmitting; -#endif } /*---------------------------------------------------------------------------*/ void @@ -126,21 +122,16 @@ uart1_writeb(unsigned char c) /* Loop until the transmission buffer is available. */ /*while((IFG2 & UTXIFG1) == 0);*/ - UCA1TXBUF = ringbuf_get(&txbuf); + TXBUF1 = ringbuf_get(&txbuf); } #else /* TX_WITH_INTERRUPT */ -#if CONTIKI_TARGET_WISMOTE - while(!(UCA1IFG & UCTXIFG)); // USCI_A1 TX buffer ready? - UCA1TXBUF = c; -#else /* Loop until the transmission buffer is available. */ while((IFG2 & UTXIFG1) == 0); /* Transmit the data. */ TXBUF1 = c; -#endif #endif /* TX_WITH_INTERRUPT */ } /*---------------------------------------------------------------------------*/ @@ -151,35 +142,6 @@ uart1_writeb(unsigned char c) void uart1_init(unsigned long ubr) { -#if CONTIKI_TARGET_WISMOTE - P4DIR |= BIT5; - P4OUT |= BIT5 ; - P5SEL |= BIT6|BIT7; // P5.6,7 = USCI_A1 TXD/RXD - - P4SEL |= BIT7; - P4DIR |= BIT7; - - UCA1CTL1 |= UCSWRST; // **Put state machine in reset** - UCA1CTL1 |= UCSSEL_2; // SMCLK - UCA1BR0 = 139;//69; // Baudrate 57600 (see User's Guide) - UCA1BR1 = 0; // - UCA1MCTL |= UCBRS_2 + UCBRF_0; // Modulation UCBRFx=0 - UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine** - - UCA1IE |= UCRXIE; - UCA1IFG &= ~UCRXIFG; - //UCA1IFG &= ~UCTXIFG; - - // UCA1TCTL1 |= URXSE; - - rx_in_progress = 0; - transmitting = 0; -#if TX_WITH_INTERRUPT - ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data)); - UCA1IE |= UCTXIE; - //UCA1IFG &= ~UCTXIFG; -#endif /* TX_WITH_INTERRUPT */ -#else /* RS232 */ P3DIR &= ~0x80; /* Select P37 for input (UART1RX) */ P3DIR |= 0x40; /* Select P36 for output (UART1TX) */ @@ -271,53 +233,8 @@ uart1_init(unsigned long ubr) msp430_add_lpm_req(MSP430_REQUIRE_LPM1); #endif /* RX_WITH_DMA */ - -#endif } - - /*---------------------------------------------------------------------------*/ -#if CONTIKI_TARGET_WISMOTE -#ifdef __IAR_SYSTEMS_ICC__ -#pragma vector=USCI_A1_VECTOR -__interrupt void -#else -interrupt(USCI_A1_VECTOR) -#endif -uart1_rx_interrupt(void) -{ - uint8_t c; - ENERGEST_ON(ENERGEST_TYPE_IRQ); - - if(UCRXIFG & UCA1IFG) { - rx_in_progress = 0; - // Check status register for receive errors. - if(UCA1STAT & UCRXERR) { - c = UCA1RXBUF; // Clear error flags by forcing a dummy read. - } else { - c = UCA1RXBUF; - if(uart1_input_handler != NULL) { - if(uart1_input_handler(c)) { - LPM4_EXIT; - } - } - } - UCA1IFG &= ~UCRXIFG; - } -#if TX_WITH_INTERRUPT - if(UCTXIFG & UCA1IFG) { - if(ringbuf_elements(&txbuf) == 0) { - transmitting = 0; - } else { - UCA1TXBUF = ringbuf_get(&txbuf); - } - UCA1IFG &= ~UCTXIFG; - } -#endif - //UCA1IFG &= 0x00; - ENERGEST_OFF(ENERGEST_TYPE_IRQ); -} -#else #if !RX_WITH_DMA #ifdef __IAR_SYSTEMS_ICC__ #pragma vector=UART1RX_VECTOR @@ -375,5 +292,4 @@ uart1_tx_interrupt(void) ENERGEST_OFF(ENERGEST_TYPE_IRQ); } #endif /* TX_WITH_INTERRUPT */ -#endif /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/f1xxx/spix.c b/cpu/msp430/f2xxx/spi.c similarity index 93% rename from cpu/msp430/f1xxx/spix.c rename to cpu/msp430/f2xxx/spi.c index 0641b72ba..122983bd8 100644 --- a/cpu/msp430/f1xxx/spix.c +++ b/cpu/msp430/f2xxx/spi.c @@ -25,8 +25,6 @@ * 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: spix.c,v 1.1 2010/08/24 16:23:20 joxe Exp $ */ #include "contiki.h" @@ -43,12 +41,7 @@ unsigned char spi_busy = 0; void spi_init(void) { - //static unsigned char spi_inited = 0; - - //if (spi_inited) - //return; - - // Initalize ports for communication with SPI units. + // Initialize ports for communication with SPI units. UCB0CTL1 |= UCSWRST; //reset usci UCB0CTL1 |= UCSSEL_2; //smclk while usci is reset diff --git a/cpu/msp430/dev/uart0x.c b/cpu/msp430/f2xxx/uart0.c similarity index 100% rename from cpu/msp430/dev/uart0x.c rename to cpu/msp430/f2xxx/uart0.c diff --git a/cpu/msp430/dev/uart1x.c b/cpu/msp430/f2xxx/uart1.c similarity index 100% rename from cpu/msp430/dev/uart1x.c rename to cpu/msp430/f2xxx/uart1.c diff --git a/cpu/msp430/f5xxx/clock.c b/cpu/msp430/f5xxx/clock.c index 403799311..49d693dde 100644 --- a/cpu/msp430/f5xxx/clock.c +++ b/cpu/msp430/f5xxx/clock.c @@ -179,7 +179,7 @@ void clock_delay(unsigned int i) { while(i--) { - asm("nop"); + _NOP(); } } /*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/f5xxx/spix.c b/cpu/msp430/f5xxx/spi.c similarity index 100% rename from cpu/msp430/f5xxx/spix.c rename to cpu/msp430/f5xxx/spi.c diff --git a/cpu/msp430/f5xxx/uart0.c b/cpu/msp430/f5xxx/uart0.c new file mode 100644 index 000000000..7c1e26b31 --- /dev/null +++ b/cpu/msp430/f5xxx/uart0.c @@ -0,0 +1,126 @@ +/* + * 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. + */ + +/* + * Yet another machine dependent MSP430X UART0 code. + * IF2, etc. can not be used here... need to abstract to some macros + * later. + */ + +#include "contiki.h" +#include +#include "sys/energest.h" +#include "dev/uart0.h" +#include "dev/watchdog.h" + +static int (*uart0_input_handler)(unsigned char c); + +static volatile uint8_t transmitting; + +/*---------------------------------------------------------------------------*/ +uint8_t +uart0_active(void) +{ + return (UCA0STAT & UCBUSY) | transmitting; +} +/*---------------------------------------------------------------------------*/ +void +uart0_set_input(int (*input)(unsigned char c)) +{ + uart0_input_handler = input; +} +/*---------------------------------------------------------------------------*/ +void +uart0_writeb(unsigned char c) +{ + watchdog_periodic(); + /* Loop until the transmission buffer is available. */ + while((UCA0STAT & UCBUSY)); + + /* Transmit the data. */ + UCA0TXBUF = c; +} +/*---------------------------------------------------------------------------*/ +/** + * Initalize the RS232 port. + * + */ +void +uart0_init(unsigned long ubr) +{ + /* RS232 */ + UCA0CTL1 |= UCSWRST; /* Hold peripheral in reset state */ + UCA0CTL1 |= UCSSEL_2; /* CLK = SMCLK */ + + ubr = (MSP430_CPU_SPEED / ubr); + UCA0BR0 = ubr & 0xff; + UCA0BR1 = (ubr >> 8) & 0xff; + UCA0MCTL = UCBRS_3; /* Modulation UCBRSx = 3 */ + P3DIR &= ~0x20; /* P3.5 = USCI_A0 RXD as input */ + P3DIR |= 0x10; /* P3.4 = USCI_A0 TXD as output */ + P3SEL |= 0x30; /* P3.4,5 = USCI_A0 TXD/RXD */ + + /*UCA0CTL1 &= ~UCSWRST;*/ /* Initialize USCI state machine */ + + transmitting = 0; + + /* XXX Clear pending interrupts before enable */ + UCA0IE &= ~UCRXIFG; + UCA0IE &= ~UCTXIFG; + + UCA0CTL1 &= ~UCSWRST; /* Initialize USCI state machine **before** enabling interrupts */ + UCA0IE |= UCRXIE; /* Enable UCA0 RX interrupt */ +} +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=USCI_A0_VECTOR +__interrupt void +#else +interrupt(USCI_A0_VECTOR) +#endif +uart0_rx_interrupt(void) +{ + uint8_t c; + + ENERGEST_ON(ENERGEST_TYPE_IRQ); + if (UCA0IV == 2) { + if(UCA0STAT & UCRXERR) { + c = UCA0RXBUF; /* Clear error flags by forcing a dummy read. */ + } else { + c = UCA0RXBUF; + if(uart0_input_handler != NULL) { + if(uart0_input_handler(c)) { + LPM4_EXIT; + } + } + } + } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ diff --git a/cpu/msp430/f5xxx/uart1.c b/cpu/msp430/f5xxx/uart1.c new file mode 100644 index 000000000..f8e6d6a68 --- /dev/null +++ b/cpu/msp430/f5xxx/uart1.c @@ -0,0 +1,131 @@ +/* + * 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. + */ + +/* + * Yet another machine dependent MSP430X UART0 code. + * IF2, etc. can not be used here... need to abstract to some macros + * later. + */ + +#include "contiki.h" +#include +#include "sys/energest.h" +#include "dev/uart1.h" +#include "dev/watchdog.h" + +static int (*uart1_input_handler)(unsigned char c); + +static volatile uint8_t transmitting; + +/*---------------------------------------------------------------------------*/ +uint8_t +uart1_active(void) +{ + return (UCA1STAT & UCBUSY) | transmitting; +} +/*---------------------------------------------------------------------------*/ +void +uart1_set_input(int (*input)(unsigned char c)) +{ + uart1_input_handler = input; +} +/*---------------------------------------------------------------------------*/ +void +uart1_writeb(unsigned char c) +{ + watchdog_periodic(); + /* Loop until the transmission buffer is available. */ + while((UCA1STAT & UCBUSY)); + + /* Transmit the data. */ + UCA1TXBUF = c; +} +/*---------------------------------------------------------------------------*/ +/** + * Initalize the RS232 port. + * + */ +void +uart1_init(unsigned long ubr) +{ + /* RS232 */ + UCA1CTL1 |= UCSWRST; /* Hold peripheral in reset state */ + UCA1CTL1 |= UCSSEL_2; /* CLK = SMCLK */ + + ubr = (MSP430_CPU_SPEED / ubr); + UCA1BR0 = ubr & 0xff; + UCA1BR1 = (ubr >> 8) & 0xff; + /* UCA1MCTL |= UCBRS_2 + UCBRF_0; // Modulation UCBRFx=0 */ + UCA1MCTL = UCBRS_3; /* Modulation UCBRSx = 3 */ + + P4DIR |= BIT5; + P4OUT |= BIT5 ; + P5SEL |= BIT6|BIT7; // P5.6,7 = USCI_A1 TXD/RXD + + P4SEL |= BIT7; + P4DIR |= BIT7; + + /*UCA1CTL1 &= ~UCSWRST;*/ /* Initialize USCI state machine */ + + transmitting = 0; + + /* XXX Clear pending interrupts before enable */ + UCA1IE &= ~UCRXIFG; + UCA1IE &= ~UCTXIFG; + + UCA1CTL1 &= ~UCSWRST; /* Initialize USCI state machine **before** enabling interrupts */ + UCA1IE |= UCRXIE; /* Enable UCA1 RX interrupt */ +} +/*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +#pragma vector=USCI_A1_VECTOR +__interrupt void +#else +interrupt(USCI_A1_VECTOR) +#endif +uart1_rx_interrupt(void) +{ + uint8_t c; + + ENERGEST_ON(ENERGEST_TYPE_IRQ); + if (UCA1IV == 2) { + if(UCA1STAT & UCRXERR) { + c = UCA1RXBUF; /* Clear error flags by forcing a dummy read. */ + } else { + c = UCA1RXBUF; + if(uart1_input_handler != NULL) { + if(uart1_input_handler(c)) { + LPM4_EXIT; + } + } + } + } + ENERGEST_OFF(ENERGEST_TYPE_IRQ); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/wismote/Makefile.wismote b/platform/wismote/Makefile.wismote index a0efa14df..f469fa27a 100644 --- a/platform/wismote/Makefile.wismote +++ b/platform/wismote/Makefile.wismote @@ -7,7 +7,7 @@ CONTIKI_TARGET_SOURCEFILES += contiki-wismote-platform.c \ sky-sensors.c uip-ipchksum.c \ checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c -ARCH=spix.c i2c.c node-id.c sensors.c cfs-coffee.c sht15.c \ +ARCH=spi.c i2c.c node-id.c sensors.c cfs-coffee.c sht15.c \ cc2520.c cc2520-arch.c cc2520-arch-sfd.c \ sky-sensors.c uip-ipchksum.c \ checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c diff --git a/platform/wismote/contiki-wismote-main.c b/platform/wismote/contiki-wismote-main.c index f7a456f88..180b472d5 100644 --- a/platform/wismote/contiki-wismote-main.c +++ b/platform/wismote/contiki-wismote-main.c @@ -205,10 +205,10 @@ main(int argc, char **argv) leds_on(LEDS_ALL); - uart1_init(BAUD2UBR(115200)); /* Must come before first printf */ + uart1_init(115200); /* Must come before first printf */ #if WITH_UIP - slip_arch_init(BAUD2UBR(115200)); + slip_arch_init(115200); #endif /* WITH_UIP */ //ds2411_init(); diff --git a/platform/wismote/dev/spi.h b/platform/wismote/dev/spi.h deleted file mode 100644 index e083a3bca..000000000 --- a/platform/wismote/dev/spi.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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. - */ - -/** - * \file - * Basic SPI macros - * \author - * Niclas Finne - * Joakim Eriksson - */ - -#ifndef __SPI_H__ -#define __SPI_H__ - -/* Define macros to use for checking SPI transmission status depending - on if it is possible to wait for TX buffer ready. This is possible - on for example MSP430 but not on AVR. */ -#ifdef SPI_WAITFORTxREADY -#define SPI_WAITFORTx_BEFORE() SPI_WAITFORTxREADY() -#define SPI_WAITFORTx_AFTER() -#define SPI_WAITFORTx_ENDED() SPI_WAITFOREOTx() -#else /* SPI_WAITFORTxREADY */ -#define SPI_WAITFORTx_BEFORE() -#define SPI_WAITFORTx_AFTER() SPI_WAITFOREOTx() -#define SPI_WAITFORTx_ENDED() -#endif /* SPI_WAITFORTxREADY */ - -extern unsigned char spi_busy; - -void spi_init(void); - -/* Write one character to SPI */ -#define SPI_WRITE(data) \ - do { \ - UCB0IFG &= ~UCRXIFG; \ - SPI_TXBUF = data; \ - SPI_WAITFORTxREADY(); \ - } while(0) - -/* Write one character to SPI - will not wait for end - useful for multiple writes with wait after final */ -#define SPI_WRITE_FAST(data) \ - do { \ - UCB0IFG &= ~UCRXIFG; \ - SPI_TXBUF = data; \ - SPI_WAITFORTxREADY(); \ - } while(0) - -/* Read one character from SPI */ -#define SPI_READ(data) \ - do { \ - UCB0IFG &= ~UCRXIFG; \ - SPI_TXBUF = 0; \ - SPI_WAITFORTxREADY(); \ - SPI_BUSY_WAIT(); \ - data = SPI_RXBUF; \ - } while(0) - -/* Flush the SPI read register */ -#define SPI_FLUSH() \ - do { \ - SPI_RXBUF; \ - SPI_RXBUF; \ - } while(0); - -#endif /* __SPI_H__ */ diff --git a/platform/wismote/platform-conf.h b/platform/wismote/platform-conf.h index e5b8b481c..c2a7e6be0 100644 --- a/platform/wismote/platform-conf.h +++ b/platform/wismote/platform-conf.h @@ -39,8 +39,6 @@ * Definitions below are dictated by the hardware and not really * changeable! */ -/* Platform WISMOTE */ -#define WISMOTE 1 #define PLATFORM_HAS_LEDS 1 #define PLATFORM_HAS_BUTTON 1 @@ -52,7 +50,7 @@ #define CLOCK_CONF_SECOND 128UL #define RTIMER_CONF_SECOND (4096U*8) -#define BAUD2UBR(baud) ((F_CPU/baud)) +#define BAUD2UBR(baud) (baud) #define CCIF #define CLIF @@ -96,16 +94,25 @@ typedef unsigned long off_t; #define SPI_RXBUF UCB0RXBUF /* USART0 Tx ready? */ -#define SPI_WAITFOREOTx() while (!(UCB0IFG & UCRXIFG)) +#define SPI_WAITFOREOTx() while ((UCB0STAT & UCBUSY) != 0) /* USART0 Rx ready? */ -#define SPI_WAITFOREORx() while (!(UCB0IFG & UCRXIFG)) +#define SPI_WAITFOREORx() while ((UCB0IFG & UCRXIFG) == 0) /* USART0 Tx buffer ready? */ -#define SPI_WAITFORTxREADY() while (!(UCB0IFG & UCRXIFG)) -#define SPI_BUSY_WAIT() while ((UCB0STAT & UCBUSY) == 1) +#define SPI_WAITFORTxREADY() while ((UCB0IFG & UCTXIFG) == 0) +/* /\* USART0 Tx ready? *\/ */ +/* #define SPI_WAITFOREOTx() while (!(UCB0IFG & UCRXIFG)) */ +/* /\* USART0 Rx ready? *\/ */ +/* #define SPI_WAITFOREORx() while (!(UCB0IFG & UCRXIFG)) */ +/* /\* USART0 Tx buffer ready? *\/ */ +/* #define SPI_WAITFORTxREADY() while (!(UCB0IFG & UCRXIFG)) */ +/* #define SPI_BUSY_WAIT() while ((UCB0STAT & UCBUSY) == 1) */ -#define SCK 1 /* P3.1 - Output: SPI Serial Clock (SCLK) */ -#define MOSI 2 /* P3.2 - Output: SPI Master out - slave in (MOSI) */ -#define MISO 3 /* P3.3 - Input: SPI Master in - slave out (MISO) */ +#define MOSI 1 /* P3.1 - Output: SPI Master out - slave in (MOSI) */ +#define MISO 2 /* P3.2 - Input: SPI Master in - slave out (MISO) */ +#define SCK 3 /* P3.3 - Output: SPI Serial Clock (SCLK) */ +/* #define SCK 1 /\* P3.1 - Output: SPI Serial Clock (SCLK) *\/ */ +/* #define MOSI 2 /\* P3.2 - Output: SPI Master out - slave in (MOSI) *\/ */ +/* #define MISO 3 /\* P3.3 - Input: SPI Master in - slave out (MISO) *\/ */ /* * SPI bus - M25P80 external flash configuration. diff --git a/platform/z1/Makefile.common b/platform/z1/Makefile.common index a3fa86c70..c2629b07e 100644 --- a/platform/z1/Makefile.common +++ b/platform/z1/Makefile.common @@ -16,9 +16,9 @@ CLEAN += symbols.c symbols.h ARCH=msp430.c leds.c watchdog.c xmem.c \ - spix.c cc2420.c cc2420-aes.c cc2420-arch.c cc2420-arch-sfd.c\ + spi.c cc2420.c cc2420-aes.c cc2420-arch.c cc2420-arch-sfd.c\ node-id.c sensors.c button-sensor.c cfs-coffee.c \ - radio-sensor.c uart0x.c uart0-putchar.c uip-ipchksum.c \ + radio-sensor.c uart0.c uart0-putchar.c uip-ipchksum.c \ checkpoint-arch.c slip.c slip_uart0.c \ z1-phidgets.c sht11.c sht11-sensor.c light-sensor.c \ battery-sensor.c sky-sensors.c tmp102.c temperature-sensor.c From f4f35973d1edcef252574e643203a8713d3a3775 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 6 Oct 2011 19:19:34 +0200 Subject: [PATCH 14/26] Fixed some configuration problems and support for AUTOACK --- core/dev/cc2520.c | 132 +++++++++++++++++----------------------- core/dev/cc2520.h | 3 +- core/dev/cc2520_const.h | 7 ++- 3 files changed, 61 insertions(+), 81 deletions(-) diff --git a/core/dev/cc2520.c b/core/dev/cc2520.c index 9255f99a3..8d5ebb2e7 100644 --- a/core/dev/cc2520.c +++ b/core/dev/cc2520.c @@ -49,19 +49,19 @@ #define CC2520_CONF_AUTOACK 0 #endif /* CC2520_CONF_AUTOACK */ -#define WITH_SEND_CCA 0 +#define WITH_SEND_CCA 1 #define FOOTER_LEN 2 #define FOOTER1_CRC_OK 0x80 #define FOOTER1_CORRELATION 0x7f -#define DEBUG 1 -#if DEBUG #include +#define DEBUG 0 +#if DEBUG #define PRINTF(...) printf(__VA_ARGS__) #else -#define PRINTF(...) +#define PRINTF(...) do {} while (0) #endif #if 0 && DEBUG @@ -82,8 +82,6 @@ int cc2520_authority_level_of_sender; int cc2520_packets_seen, cc2520_packets_read; -static uint8_t volatile pending; - #define BUSYWAIT_UNTIL(cond, max_time) \ do { \ rtimer_clock_t t0; \ @@ -132,7 +130,6 @@ const struct radio_driver cc2520_driver = pending_packet, cc2520_on, cc2520_off, - }; static uint8_t receive_on; @@ -161,7 +158,8 @@ flushrx(void) CC2520_STROBE(CC2520_INS_SFLUSHRX); } /*---------------------------------------------------------------------------*/ -static void strobe(uint8_t regname) +static void +strobe(uint8_t regname) { CC2520_STROBE(regname); } @@ -179,11 +177,12 @@ static uint8_t locked, lock_on, lock_off; static void on(void) { - ENERGEST_ON(ENERGEST_TYPE_LISTEN); CC2520_ENABLE_FIFOP_INT(); strobe(CC2520_INS_SRXON); - //BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 100); + BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 100); + + ENERGEST_ON(ENERGEST_TYPE_LISTEN); receive_on = 1; } static void @@ -193,12 +192,11 @@ off(void) receive_on = 0; /* Wait for transmission to end before turning radio off. */ - //BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); - //while(status() & BV(CC2520_TX_ACTIVE)); + BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); strobe(CC2520_INS_SRFOFF); CC2520_DISABLE_FIFOP_INT(); - ENERGEST_OFF(ENERGEST_TYPE_LISTEN); if(!CC2520_FIFOP_IS_1) { flushrx(); @@ -221,7 +219,7 @@ static void RELEASE_LOCK(void) { } /*---------------------------------------------------------------------------*/ static uint8_t -getreg(unsigned regname) +getreg(uint16_t regname) { uint8_t reg; CC2520_READ_REG(regname, reg); @@ -229,7 +227,7 @@ getreg(unsigned regname) } /*---------------------------------------------------------------------------*/ static void -setreg(unsigned regname, unsigned value) +setreg(uint16_t regname, uint8_t value) { CC2520_WRITE_REG(regname, value); } @@ -237,26 +235,19 @@ setreg(unsigned regname, unsigned value) static void set_txpower(uint8_t power) { - uint16_t reg; - - reg = getreg(CC2520_TXCTRL); - reg = (reg & 0xffe0) | (power & 0x1f); - setreg(CC2520_TXCTRL, reg); + setreg(CC2520_TXPOWER, power); } /*---------------------------------------------------------------------------*/ -#define AUTOACK (1 << 4) -#define ADR_DECODE (1 << 11) -#define RXFIFO_PROTECTION (1 << 9) +#define AUTOCRC (1 << 6) +#define AUTOACK (1 << 5) +#define FRAME_MAX_VERSION ((1 << 3) | (1 << 2)) +#define FRAME_FILTER_ENABLE (1 << 0) #define CORR_THR(n) (((n) & 0x1f) << 6) #define FIFOP_THR(n) ((n) & 0x7f) -#define RXBPF_LOCUR (1 << 13); /*---------------------------------------------------------------------------*/ -int temp_data; int cc2520_init(void) { - unsigned stat1; - { int s = splhigh(); cc2520_arch_init(); /* Initalize ports and SPI. */ @@ -264,22 +255,21 @@ cc2520_init(void) CC2520_FIFOP_INT_INIT(); splx(s); } - /* Turn on voltage regulator and reset. */ + SET_VREG_INACTIVE(); clock_delay(250); + /* Turn on voltage regulator and reset. */ SET_VREG_ACTIVE(); clock_delay(250); SET_RESET_ACTIVE(); clock_delay(127); SET_RESET_INACTIVE(); clock_delay(125); - strobe(CC2520_INS_SXOSCON); // Turn on the crystal oscillator. + /* Turn on the crystal oscillator. */ + strobe(CC2520_INS_SXOSCON); clock_delay(125); - stat1 = status(); - while(!(stat1 & 0x80)) { - stat1 = status(); - } + BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 100); /* Change default values as recommended in the data sheet, */ /* correlation threshold = 20, RX bandpass filter = 1.3uA.*/ @@ -313,9 +303,6 @@ cc2520_init(void) setreg(CC2520_AGCCTRL1, 0x11); // Adjust target value for AGC control loop setreg(CC2520_AGCCTRL2, 0xEB); - // Disable filter on @ (remove if you want to address specific wismote) - setreg(CC2520_FRMFILT0, 0x00); - // Disable external clock setreg(CC2520_EXTCLOCK, 0x00); @@ -324,12 +311,22 @@ cc2520_init(void) setreg(CC2520_ADCTEST1, 0x0E); setreg(CC2520_ADCTEST2, 0x03); - // Set auto CRC on frame - setreg(CC2520_FRMCTRL0, 0x60); - setreg(CC2520_FIFOPCTRL, 0x0F); + /* Set auto CRC on frame. */ +#if CC2520_CONF_AUTOACK + setreg(CC2520_FRMCTRL0, AUTOCRC | AUTOACK); + setreg(CC2520_FRMFILT0, FRAME_MAX_VERSION|FRAME_FILTER_ENABLE); +#else + /* setreg(CC2520_FRMCTRL0, 0x60); */ + setreg(CC2520_FRMCTRL0, AUTOCRC); + /* Disable filter on @ (remove if you want to address specific wismote) */ + setreg(CC2520_FRMFILT0, 0x00); +#endif /* CC2520_CONF_AUTOACK */ - cc2520_set_pan_addr(0xbabe, 0x0000, NULL); - cc2520_set_channel(15); + /* Set FIFOP threshold to maximum .*/ + setreg(CC2520_FIFOPCTRL, FIFOP_THR(0x7F)); + + cc2520_set_pan_addr(0xffff, 0x0000, NULL); + cc2520_set_channel(26); flushrx(); @@ -340,13 +337,11 @@ cc2520_init(void) static int cc2520_transmit(unsigned short payload_len) { - uint16_t reg; int i, txpower; + uint8_t reg; GET_LOCK(); - LEDS_ON(LEDS_RED); - txpower = 0; if(packetbuf_attr(PACKETBUF_ATTR_RADIO_TXPOWER) > 0) { /* Remember the current transmission power */ @@ -370,7 +365,7 @@ cc2520_transmit(unsigned short payload_len) #if WITH_SEND_CCA strobe(CC2520_INS_SRXON); - //BUSYWAIT_UNTIL(status() & BV(CC2520_TX_ACTIVE) , RTIMER_SECOND / 100); + BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID) , RTIMER_SECOND / 10); strobe(CC2520_INS_STXONCCA); #else /* WITH_SEND_CCA */ strobe(CC2520_INS_STXON); @@ -401,7 +396,7 @@ cc2520_transmit(unsigned short payload_len) /* We wait until transmission has ended so that we get an accurate measurement of the transmission time.*/ //BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG0) & TX_FRM_DONE , RTIMER_SECOND / 100); - //BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); + BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); #ifdef ENERGEST_CONF_LEVELDEVICE_LEVELS ENERGEST_OFF_LEVEL(ENERGEST_TYPE_TRANSMIT,cc2520_get_txpower()); @@ -475,7 +470,6 @@ cc2520_prepare(const void *payload, unsigned short payload_len) static int cc2520_send(const void *payload, unsigned short payload_len) { - cc2520_prepare(payload, payload_len); return cc2520_transmit(payload_len); } @@ -491,7 +485,7 @@ cc2520_off(void) /* If we are called when the driver is locked, we indicate that the radio should be turned off when the lock is unlocked. */ if(locked) { - /* ("Off when locked (%d)\n", locked);*/ + /* printf("Off when locked (%d)\n", locked);*/ lock_off = 1; return 1; } @@ -543,20 +537,19 @@ cc2520_set_channel(int c) * Subtract the base channel (11), multiply by 5, which is the * channel spacing. 357 is 2405-2048 and 0x4000 is LOCK_THR = 1. */ - channel = c; f = MIN_CHANNEL + ((channel - MIN_CHANNEL) * CHANNEL_SPACING); /* * Writing RAM requires crystal oscillator to be stable. */ - while(!(status() & (BV(CC2520_XOSC16M_STABLE)))); + BUSYWAIT_UNTIL((status() & (BV(CC2520_XOSC16M_STABLE))), RTIMER_SECOND / 10); /* Wait for any transmission to end. */ - while(status() & BV(CC2520_TX_ACTIVE)); + BUSYWAIT_UNTIL(!(status() & BV(CC2520_TX_ACTIVE)), RTIMER_SECOND / 10); - // Define radio channel (between 11 and 25) - setreg(CC2520_FREQCTRL, f ); + /* Define radio channel (between 11 and 25) */ + setreg(CC2520_FREQCTRL, f); /* If we are in receive mode, we issue an SRXON command to ensure that the VCO is calibrated. */ @@ -580,7 +573,7 @@ cc2520_set_pan_addr(unsigned pan, /* * Writing RAM requires crystal oscillator to be stable. */ - //BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 10); + BUSYWAIT_UNTIL(status() & (BV(CC2520_XOSC16M_STABLE)), RTIMER_SECOND / 10); tmp[0] = pan & 0xff; tmp[1] = pan >> 8; @@ -590,15 +583,15 @@ cc2520_set_pan_addr(unsigned pan, tmp[0] = addr & 0xff; tmp[1] = addr >> 8; CC2520_WRITE_RAM(&tmp, CC2520RAM_SHORTADDR, 2); - /* if(ieee_addr != NULL) { + int f; uint8_t tmp_addr[8]; // LSB first, MSB last for 802.15.4 addresses in CC2520 for (f = 0; f < 8; f++) { tmp_addr[7 - f] = ieee_addr[f]; } CC2520_WRITE_RAM(tmp_addr, CC2520RAM_IEEEADDR, 8); - }*/ + } RELEASE_LOCK(); } /*---------------------------------------------------------------------------*/ @@ -621,7 +614,6 @@ cc2520_interrupt(void) #endif /* CC2520_TIMETABLE_PROFILING */ last_packet_timestamp = cc2520_sfd_start_time; - pending++; cc2520_packets_seen++; return 1; } @@ -644,11 +636,10 @@ PROCESS_THREAD(cc2520_process, ev, data) packetbuf_clear(); packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp); len = cc2520_read(packetbuf_dataptr(), PACKETBUF_SIZE); - packetbuf_set_datalen(len); NETSTACK_RDC.input(); - flushrx(); + /* flushrx(); */ #if CC2520_TIMETABLE_PROFILING TIMETABLE_TIMESTAMP(cc2520_timetable, "end"); timetable_aggregate_compute_detailed(&aggregate_time, @@ -666,18 +657,9 @@ cc2520_read(void *buf, unsigned short bufsize) uint8_t footer[2]; uint8_t len; - if((!CC2520_FIFOP_IS_1) & !(getreg(CC2520_EXCFLAG1) & RX_FRM_DONE)) { + if(!CC2520_FIFOP_IS_1) { return 0; } - LEDS_ON(LEDS_GREEN); // TODO LED FLASH for the debug on reception - - //BUSYWAIT_UNTIL( (status() & BV(CC2520_RX_ACTIVE)) , RTIMER_SECOND / 100); - //BUSYWAIT_UNTIL(getreg(CC2520_EXCFLAG1) & RX_FRM_DONE , RTIMER_SECOND / 100); - /* if(!pending) { - return 0; - }*/ - - pending = 0; GET_LOCK(); @@ -708,7 +690,6 @@ cc2520_read(void *buf, unsigned short bufsize) } getrxdata(buf, len - FOOTER_LEN); - getrxdata(footer, FOOTER_LEN); if(footer[1] & FOOTER1_CRC_OK) { @@ -758,9 +739,9 @@ cc2520_set_txpower(uint8_t power) int cc2520_get_txpower(void) { - int power; + uint8_t power; GET_LOCK(); - power = (int)(getreg(CC2520_TXCTRL) & 0x001f); + power = getreg(CC2520_TXPOWER); RELEASE_LOCK(); return power; } @@ -781,7 +762,7 @@ cc2520_rssi(void) radio_was_off = 1; cc2520_on(); } - //BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); + BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); rssi = (int)((signed char)getreg(CC2520_RSSI)); @@ -842,7 +823,7 @@ cc2520_cca(void) return 1; } - //BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); + BUSYWAIT_UNTIL(status() & BV(CC2520_RSSI_VALID), RTIMER_SECOND / 100); cca = CC2520_CCA_IS_1; @@ -868,9 +849,8 @@ pending_packet(void) void cc2520_set_cca_threshold(int value) { - uint16_t shifted = value << 8; GET_LOCK(); - setreg(CC2520_RSSI, shifted); + setreg(CC2520_CCACTRL0, value & 0xff); RELEASE_LOCK(); } /*---------------------------------------------------------------------------*/ diff --git a/core/dev/cc2520.h b/core/dev/cc2520.h index b247f567b..234329d82 100644 --- a/core/dev/cc2520.h +++ b/core/dev/cc2520.h @@ -106,7 +106,7 @@ void cc2520_set_cca_threshold(int value); CC2520_SPI_ENABLE(); \ SPI_WRITE_FAST(CC2520_INS_MEMWR | ((adr>>8)&0xFF)); \ SPI_WRITE_FAST(adr & 0xff); \ - SPI_WRITE_FAST((u8_t) data); \ + SPI_WRITE_FAST((uint8_t) data); \ SPI_WAITFORTx_ENDED(); \ CC2520_SPI_DISABLE(); \ } while(0) @@ -119,7 +119,6 @@ void cc2520_set_cca_threshold(int value); SPI_WRITE((CC2520_INS_MEMRD | ((adr>>8)&0xFF))); \ SPI_WRITE((adr & 0xFF)); \ SPI_READ(data); \ - data = SPI_RXBUF; \ CC2520_SPI_DISABLE(); \ } while(0) diff --git a/core/dev/cc2520_const.h b/core/dev/cc2520_const.h index c77d05d1a..c89a3a24b 100644 --- a/core/dev/cc2520_const.h +++ b/core/dev/cc2520_const.h @@ -51,9 +51,10 @@ enum cc2520_status_byte { CC2520_RX_ACTIVE = 0, }; -#define TX_FRM_DONE 0x02 -#define RX_FRM_DONE 0x01 -#define RX_FRM_ABORTED 0x20 +#define TX_FRM_DONE 0x02 +#define RX_FRM_DONE 0x01 +#define RX_FRM_ABORTED 0x20 +#define RX_FRM_UNDERFLOW 0x20 /* Page 27. */ enum cc2520_memory_size { From 8e59df78e271fe615e88eef4aed53908799bb122 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Fri, 7 Oct 2011 15:29:43 +0200 Subject: [PATCH 15/26] Autoenable RX after TX + removed exception check --- core/dev/cc2520.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/core/dev/cc2520.c b/core/dev/cc2520.c index 8d5ebb2e7..ec1442ea9 100644 --- a/core/dev/cc2520.c +++ b/core/dev/cc2520.c @@ -321,7 +321,8 @@ cc2520_init(void) /* Disable filter on @ (remove if you want to address specific wismote) */ setreg(CC2520_FRMFILT0, 0x00); #endif /* CC2520_CONF_AUTOACK */ - + /* SET_RXENMASK_ON_TX */ + setreg(CC2520_FRMCTRL1, 1); /* Set FIFOP threshold to maximum .*/ setreg(CC2520_FIFOPCTRL, FIFOP_THR(0x7F)); @@ -338,7 +339,6 @@ static int cc2520_transmit(unsigned short payload_len) { int i, txpower; - uint8_t reg; GET_LOCK(); @@ -415,14 +415,9 @@ cc2520_transmit(unsigned short payload_len) set_txpower(txpower & 0xff); } - reg = getreg(CC2520_EXCFLAG0); RELEASE_LOCK(); - if (reg & TX_FRM_DONE) { - return RADIO_TX_OK; - } else { - return RADIO_TX_COLLISION; - } + return RADIO_TX_OK; } } From 866bc91e5aab6020311b16e240d823f0786fffe0 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 18 Oct 2011 15:48:42 +0200 Subject: [PATCH 16/26] enabled nullrdc autoack support --- platform/wismote/contiki-conf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/wismote/contiki-conf.h b/platform/wismote/contiki-conf.h index 9b3b138cc..b8d4a6fda 100644 --- a/platform/wismote/contiki-conf.h +++ b/platform/wismote/contiki-conf.h @@ -31,6 +31,7 @@ #define CC2520_CONF_AUTOACK 1 #endif /* CC2520_CONF_AUTOACK */ +#define NULLRDC_CONF_802154_AUTOACK 1 #if WITH_UIP6 /* Network setup for IPv6 */ From 013571ed3f700232fb945062cedc220500262214 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 15 Nov 2011 12:19:19 +0100 Subject: [PATCH 17/26] * Removed __MSP430X__ (already defined by newer mspgcc4) * Commented out pragma not supported by mspgcc --- platform/wismote/Makefile.wismote | 2 -- platform/wismote/dev/sht15.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/platform/wismote/Makefile.wismote b/platform/wismote/Makefile.wismote index f469fa27a..c3ead6982 100644 --- a/platform/wismote/Makefile.wismote +++ b/platform/wismote/Makefile.wismote @@ -28,8 +28,6 @@ else SMALL=1 endif -CFLAGS += -D__MSP430X__ - CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS) MCU=msp430x5437 diff --git a/platform/wismote/dev/sht15.c b/platform/wismote/dev/sht15.c index 6fa90a7e8..0d9467e02 100644 --- a/platform/wismote/dev/sht15.c +++ b/platform/wismote/dev/sht15.c @@ -46,7 +46,7 @@ * @return none */ -#pragma optimize=none +/* #pragma optimize=none */ void halMcuWaitUs(uint16_t usec) // 5 cycles for calling { // The least we can wait is 3 usec: From 987b57b015ed60275fa30ca8fa9a13b23777079d Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 17 Nov 2011 14:44:20 +0100 Subject: [PATCH 18/26] moved macros to implementation file, end-of-line normalization, code style --- platform/wismote/dev/sht15.c | 650 ++++++++++++++++++----------------- platform/wismote/dev/sht15.h | 119 +++---- 2 files changed, 384 insertions(+), 385 deletions(-) diff --git a/platform/wismote/dev/sht15.c b/platform/wismote/dev/sht15.c index 0d9467e02..6ea50e96c 100644 --- a/platform/wismote/dev/sht15.c +++ b/platform/wismote/dev/sht15.c @@ -1,320 +1,330 @@ -/* Copyright (c) 2009 ARAGO SYSTEMS - 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. -*/ -/* - $Id: v 0.1 2011/02/15 tchapelle Exp $ -*/ -#include "dev/sht15.h" - -/*********************************************************************************** -* @fn halMcuWaitUs -* -* @brief Busy wait function. Waits the specified number of microseconds. Use -* assumptions about number of clock cycles needed for the various -* instructions. The duration of one cycle depends on MCLK. In this HAL -* , it is set to 8 MHz, thus 8 cycles per usec. -* -* NB! This function is highly dependent on architecture and compiler! -* -* @param uint16 usec - number of microseconds delay -* -* @return none -*/ - -/* #pragma optimize=none */ -void halMcuWaitUs(uint16_t usec) // 5 cycles for calling -{ - // The least we can wait is 3 usec: - // ~1 usec for call, 1 for first compare and 1 for return - while(usec > 3) // 2 cycles for compare - { // 2 cycles for jump - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - nop(); // 1 cycles for nop - usec -= 2; // 1 cycles for optimized decrement - } -} // 4 cycles for returning - - -/** - SHT15/75 Driver - - !!! be advise that the SHT15 and SHT75 are not i2C compliant sensors - they are just designed to not disturb i2C devices on a 2 wire bus - this driver allow to drive the sensor with GPIO and delay -*/ - -/*********************************************************************************** -* @fn sht15_send_start -* -* @brief This function perform the start sequence asked by SHT15 and SHT75 -* -* -* -* @param none -* -* @return none -*/ -void sht15_send_start() -{ - // Sequence is to set data line to 1 then clock line to 1 - // then set data line to 0, clock line to 0 - // then set clock line to 1 and data line to 1 -// ___________ ________ -// data line : _____/ \___________/ -// ___________ ____________ -// clock line : _________/ \___/ - - DATA_OUT(); - DATA_SET(); - SCK_SET(); - DATA_CLR(); - SCK_CLR(); - SCK_SET(); - DATA_SET(); - SCK_CLR(); -} -/*********************************************************************************** -* @fn sht15_read16() -* -* @brief -* -* -* -* @param none -* -* @return uint16_t -*/ -uint16_t sht15_read16() -{ -uint16_t i; -DATA_IN(); - -SCK_CLR(); -uint16_t val = 0; - - for(i = 0; i < 18; i++) - { - if((i != 8) && (i != 17)) - { - SCK_SET(); - if(DATA_VAL()) - val |= 1; - - val <<= 1; - SCK_CLR(); - } - else if(i == 8) // Wait for first ACK from SHT15 - { - DATA_OUT(); - - DATA_CLR(); - - SCK_SET(); - SCK_CLR(); - - DATA_IN(); - } - else if(i == 17) // Wait for second ACK from SHT15 - { - DATA_OUT(); - - DATA_SET(); - - SCK_SET(); - SCK_CLR(); - } - } - return val; -} -/*********************************************************************************** -* @fn sht15_write8 -* -* @brief -* -* -* -* @param uint8 val -* -* @return none -*/ -void sht15_write8(uint8_t val) -{ - uint16_t i; - - DATA_OUT(); - - for(i = 0; i < 8; i++) - { - halMcuWaitUs(4); - SCK_CLR(); - - if(val & 0x80) - { - DATA_SET(); - } - else - { - DATA_CLR(); - } - val <<= 1; - - SCK_SET(); - } - - DATA_IN(); - - SCK_CLR(); - - while(DATA_VAL()); - - SCK_SET(); - SCK_CLR(); -} -/*********************************************************************************** -* @fn sht15_wait_measure -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_wait_measure() -{ - while(DATA_VAL()); -} -/*********************************************************************************** -* @fn sht15_init -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_init() -{ - // DATA and SCK lines are I/O - P3SEL &= ~BIT7; - P5SEL &= ~BIT4; - // Set SCK and DATA as output - DATA_OUT(); - SCK_OUT(); - DATA_SET(); - SCK_SET(); -} -/*********************************************************************************** -* @fn sht15_measure_temp -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_measure_temp() -{ - sht15_send_start(); - sht15_write8(3); -} -/*********************************************************************************** -* @fn sht15_measure_hum -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_measure_hum() -{ - sht15_send_start(); - sht15_write8(5); -} -/*********************************************************************************** -* @fn sht15_read_status -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_read_status() -{ - sht15_send_start(); - sht15_write8(7); -} -/*********************************************************************************** -* @fn sht15_write_status -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_write_status() -{ - sht15_send_start(); - sht15_write8(6); -} -/*********************************************************************************** -* @fn sht15_soft_reset -* -* @brief -* -* -* -* @param none -* -* @return none -*/ -void sht15_soft_reset() -{ - sht15_send_start(); - sht15_write8(30); -} +/* Copyright (c) 2009 ARAGO SYSTEMS + 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. +*/ +#include "dev/sht15.h" + +#define DATA_OUT() P3DIR |= BIT7 +#define DATA_IN() P3DIR &= ~BIT7 +#define DATA_SET() P3OUT |= BIT7; halMcuWaitUs(10) +#define DATA_CLR() P3OUT &= ~BIT7; halMcuWaitUs(10) +#define DATA_VAL() (P3IN & BIT7) + +#define SCK_OUT() P5DIR |= BIT4 +#define SCK_SET() P5OUT |= BIT4; halMcuWaitUs(10) +#define SCK_CLR() P5OUT &= ~BIT4; halMcuWaitUs(10) + + +/*********************************************************************************** +* @fn halMcuWaitUs +* +* @brief Busy wait function. Waits the specified number of microseconds. Use +* assumptions about number of clock cycles needed for the various +* instructions. The duration of one cycle depends on MCLK. In this HAL +* , it is set to 8 MHz, thus 8 cycles per usec. +* +* NB! This function is highly dependent on architecture and compiler! +* +* @param uint16 usec - number of microseconds delay +* +* @return none +*/ + +/* #pragma optimize=none */ +void +halMcuWaitUs(uint16_t usec) /* 5 cycles for calling */ +{ + /* The least we can wait is 3 usec: */ + /* ~1 usec for call, 1 for first compare and 1 for return */ + while(usec > 3) /* 2 cycles for compare */ + { /* 2 cycles for jump */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + nop(); /* 1 cycles for nop */ + usec -= 2; /* 1 cycles for optimized decrement */ + } +} /* 4 cycles for returning */ + + +/** + SHT15/75 Driver + + !!! be advise that the SHT15 and SHT75 are not i2C compliant sensors + they are just designed to not disturb i2C devices on a 2 wire bus + this driver allow to drive the sensor with GPIO and delay +*/ + +/*********************************************************************************** +* @fn sht15_send_start +* +* @brief This function perform the start sequence asked by SHT15 and SHT75 +* +* +* +* @param none +* +* @return none +*/ +void +sht15_send_start(void) +{ + /* Sequence is to set data line to 1 then clock line to 1 + then set data line to 0, clock line to 0 + then set clock line to 1 and data line to 1 + ___________ ________ + data line : _____/ \___________/ + ___________ ____________ + clock line : _________/ \___/ + */ + + DATA_OUT(); + DATA_SET(); + SCK_SET(); + DATA_CLR(); + SCK_CLR(); + SCK_SET(); + DATA_SET(); + SCK_CLR(); +} +/*********************************************************************************** +* @fn sht15_read16() +* +* @brief +* +* +* +* @param none +* +* @return uint16_t +*/ +uint16_t +sht15_read16(void) +{ + uint16_t i; + DATA_IN(); + + SCK_CLR(); + uint16_t val = 0; + + for(i = 0; i < 18; i++) { + if((i != 8) && (i != 17)) { + SCK_SET(); + if(DATA_VAL()) { + val |= 1; + } + + val <<= 1; + SCK_CLR(); + } else if(i == 8) { /* Wait for first ACK from SHT15 */ + DATA_OUT(); + + DATA_CLR(); + + SCK_SET(); + SCK_CLR(); + + DATA_IN(); + } else if(i == 17) { /* Wait for second ACK from SHT15 */ + DATA_OUT(); + + DATA_SET(); + + SCK_SET(); + SCK_CLR(); + } + } + return val; +} +/*********************************************************************************** +* @fn sht15_write8 +* +* @brief +* +* +* +* @param uint8 val +* +* @return none +*/ +void +sht15_write8(uint8_t val) +{ + uint16_t i; + + DATA_OUT(); + + for(i = 0; i < 8; i++) { + halMcuWaitUs(4); + SCK_CLR(); + + if(val & 0x80) { + DATA_SET(); + } else { + DATA_CLR(); + } + val <<= 1; + + SCK_SET(); + } + + DATA_IN(); + + SCK_CLR(); + + while(DATA_VAL()); + + SCK_SET(); + SCK_CLR(); +} +/*********************************************************************************** +* @fn sht15_wait_measure +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void +sht15_wait_measure(void) +{ + while(DATA_VAL()); +} +/*********************************************************************************** +* @fn sht15_init +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void +sht15_init(void) +{ + /* DATA and SCK lines are I/O */ + P3SEL &= ~BIT7; + P5SEL &= ~BIT4; + /* Set SCK and DATA as output */ + DATA_OUT(); + SCK_OUT(); + DATA_SET(); + SCK_SET(); +} +/*********************************************************************************** +* @fn sht15_measure_temp +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void +sht15_measure_temp(void) +{ + sht15_send_start(); + sht15_write8(3); +} +/*********************************************************************************** +* @fn sht15_measure_hum +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void sht15_measure_hum() +{ + sht15_send_start(); + sht15_write8(5); +} +/*********************************************************************************** +* @fn sht15_read_status +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void +sht15_read_status() +{ + sht15_send_start(); + sht15_write8(7); +} +/*********************************************************************************** +* @fn sht15_write_status +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void +sht15_write_status(void) +{ + sht15_send_start(); + sht15_write8(6); +} +/*********************************************************************************** +* @fn sht15_soft_reset +* +* @brief +* +* +* +* @param none +* +* @return none +*/ +void +sht15_soft_reset(void) +{ + sht15_send_start(); + sht15_write8(30); +} diff --git a/platform/wismote/dev/sht15.h b/platform/wismote/dev/sht15.h index dc438b27c..065a3d7a5 100644 --- a/platform/wismote/dev/sht15.h +++ b/platform/wismote/dev/sht15.h @@ -1,65 +1,54 @@ -/* Copyright (c) 2009 ARAGO SYSTEMS - 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. -*/ -/* - $Id: v 0.1 2011/02/15 tchapelle Exp $ -*/ - - -/** - SHT15/75 Driver - -!!! be advise that the SHT15 and SHT75 are not i2C compliant sensors - they are just designed to not disturb i2C devices on a 2 wire bus - this driver allow to drive the sensor with GPIO and delay -*/ -#include "contiki.h" - -#define DATA_OUT() P3DIR |= BIT7 -#define DATA_IN() P3DIR &= ~BIT7 -#define DATA_SET() P3OUT |= BIT7; halMcuWaitUs(10) -#define DATA_CLR() P3OUT &= ~BIT7; halMcuWaitUs(10) -#define DATA_VAL() (P3IN & BIT7) - -#define SCK_OUT() P5DIR |= BIT4 -#define SCK_SET() P5OUT |= BIT4; halMcuWaitUs(10) -#define SCK_CLR() P5OUT &= ~BIT4; halMcuWaitUs(10) - - -/*********************************************************************************** -* SHT15 functions -*/ -void sht15_init(); -void sht15_measure_temp(); -void sht15_measure_hum(); -void sht15_wait_measure(); -void sht15_read_status(); -void sht15_write_status(); -void sht15_soft_reset(); -uint16_t sht15_read16(); -void sht15_write8(uint8_t val); +/* Copyright (c) 2009 ARAGO SYSTEMS + 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. +*/ +/* + $Id: v 0.1 2011/02/15 tchapelle Exp $ +*/ + + +/** + SHT15/75 Driver + +!!! be advise that the SHT15 and SHT75 are not i2C compliant sensors + they are just designed to not disturb i2C devices on a 2 wire bus + this driver allow to drive the sensor with GPIO and delay +*/ +#include "contiki.h" + +/*********************************************************************************** +* SHT15 functions +*/ +void sht15_init(); +void sht15_measure_temp(); +void sht15_measure_hum(); +void sht15_wait_measure(); +void sht15_read_status(); +void sht15_write_status(); +void sht15_soft_reset(); +uint16_t sht15_read16(); +void sht15_write8(uint8_t val); From eba64bdc5e73b20cbd6893aedbc295e402227540 Mon Sep 17 00:00:00 2001 From: Nicolas Tsiftes Date: Mon, 21 Nov 2011 16:14:22 +0100 Subject: [PATCH 19/26] Be more explicit with the relationship between inheritance between MSP430 families. --- cpu/msp430/Makefile.msp430 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 687853bf6..b907ea328 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -11,15 +11,21 @@ CONTIKI_CPU=$(CONTIKI)/cpu/msp430 ### Define the source files we have in the MSP430 port -ifneq (,$(findstring msp430x5,$(MCU))) - CONTIKI_CPU_FAM_DIR = f5xxx +ifneq (,$(findstring msp430x1,$(MCU))) + CONTIKI_CPU_FAM_DIR = f1xxx else - ifneq (,$(findstring msp430x2,$(MCU))) - CONTIKI_CPU_FAM_DIR = f2xxx + ifneq (,$(findstring msp430x5,$(MCU))) + CONTIKI_CPU_FAM_DIR = f5xxx + else + ifneq (,$(findstring msp430x2,$(MCU))) + CONTIKI_CPU_FAM_DIR = f2xxx f1xxx + else + ${error Unhandled MSP430 family: "$(MCU)"} + endif endif endif -CONTIKI_CPU_DIRS = $(CONTIKI_CPU_FAM_DIR) f1xxx . dev +CONTIKI_CPU_DIRS = $(CONTIKI_CPU_FAM_DIR) . dev MSP430 = msp430.c flash.c clock.c leds.c leds-arch.c \ watchdog.c lpm.c mtarch.c rtimer-arch.c From 8e1e12dfd3f182965e66c3406e9608128927819a Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 15 Dec 2011 15:17:09 +0100 Subject: [PATCH 20/26] Ignore SMALL when using IAR compiler --- cpu/msp430/Makefile.msp430 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index b907ea328..2aea9ad78 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -101,9 +101,11 @@ CFLAGS += $(CFLAGSNO) ### These flags can reduce the code size and RAM usage with up to 10% ifdef SMALL +ifndef IAR CFLAGS += -ffunction-sections # CFLAGS += -fdata-sections LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__ +endif # !IAR endif # SMALL From 8aaa9d14b72cddac694865f1808768f0130da672 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Mon, 19 Dec 2011 18:03:55 +0100 Subject: [PATCH 21/26] minor code cleanup --- platform/wismote/dev/acc-sensor.c | 15 ++++++--------- platform/wismote/dev/acc-sensor.h | 4 ---- platform/wismote/dev/button-sensor.c | 28 ++++++++++++++-------------- platform/wismote/dev/ext-sensor.c | 17 ++++++++--------- platform/wismote/dev/ext-sensor.h | 4 ---- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/platform/wismote/dev/acc-sensor.c b/platform/wismote/dev/acc-sensor.c index 6817b7de6..15ea5fd82 100644 --- a/platform/wismote/dev/acc-sensor.c +++ b/platform/wismote/dev/acc-sensor.c @@ -26,14 +26,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: acc-sensor.c,v 1.6 2010/01/14 20:01:18 nifi Exp $ - * * ----------------------------------------------------------------- * * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne * Created : 2005-11-01 - * Updated : $Date: 2010/01/14 20:01:18 $ - * $Revision: 1.6 $ */ #include "dev/acc-sensor.h" @@ -101,15 +97,15 @@ value(int type) } /*---------------------------------------------------------------------------*/ static int -configure(int type, int c) +configure(int type, int value) { - switch(type) { - case SENSORS_ACTIVE: - if (c) { + if(type == SENSORS_ACTIVE) { + if(value) { activate(); } else { deactivate(); } + return 1; } return 0; } @@ -121,8 +117,9 @@ status(int type) case SENSORS_ACTIVE: case SENSORS_READY: return active; + default: + return 0; } - return 0; } /*---------------------------------------------------------------------------*/ SENSORS_SENSOR(acc_sensor, ACC_SENSOR, diff --git a/platform/wismote/dev/acc-sensor.h b/platform/wismote/dev/acc-sensor.h index b10ae214a..89df783a8 100644 --- a/platform/wismote/dev/acc-sensor.h +++ b/platform/wismote/dev/acc-sensor.h @@ -26,14 +26,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: acc-sensor.h,v 1.1 2009/01/15 21:06:02 adamdunkels Exp $ - * * ----------------------------------------------------------------- * * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne * Created : 2005-11-01 - * Updated : $Date: 2009/01/15 21:06:02 $ - * $Revision: 1.1 $ */ #ifndef __ACC_SENSOR_H__ diff --git a/platform/wismote/dev/button-sensor.c b/platform/wismote/dev/button-sensor.c index 0456356ba..51bf38c2f 100644 --- a/platform/wismote/dev/button-sensor.c +++ b/platform/wismote/dev/button-sensor.c @@ -51,12 +51,10 @@ interrupt(PORT2_VECTOR) { ENERGEST_ON(ENERGEST_TYPE_IRQ); - if(BUTTON_CHECK_IRQ()) { - if(timer_expired(&debouncetimer)) { - timer_set(&debouncetimer, CLOCK_SECOND / 4); - sensors_changed(&button_sensor); - LPM4_EXIT; - } + if(BUTTON_CHECK_IRQ() && timer_expired(&debouncetimer)) { + timer_set(&debouncetimer, CLOCK_SECOND / 4); + sensors_changed(&button_sensor); + LPM4_EXIT; } P2IFG = 0x00; ENERGEST_OFF(ENERGEST_TYPE_IRQ); @@ -69,11 +67,14 @@ value(int type) } /*---------------------------------------------------------------------------*/ static int -configure(int type, int c) +configure(int type, int value) { - switch (type) { - case SENSORS_ACTIVE: - if (c) { + if(type == SENSORS_ACTIVE) { + if(value == 0) { + /* Deactivate button sensor */ + BUTTON_DISABLE_IRQ(); + } else { + /* Activate button sensor */ if(!status(SENSORS_ACTIVE)) { timer_set(&debouncetimer, 0); BUTTON_IRQ_EDGE_SELECTD(); @@ -83,8 +84,6 @@ configure(int type, int c) BUTTON_ENABLE_IRQ(); } - } else { - BUTTON_DISABLE_IRQ(); } return 1; } @@ -94,12 +93,13 @@ configure(int type, int c) static int status(int type) { - switch (type) { + switch(type) { case SENSORS_ACTIVE: case SENSORS_READY: return BUTTON_IRQ_ENABLED(); + default: + return 0; } - return 0; } /*---------------------------------------------------------------------------*/ SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, diff --git a/platform/wismote/dev/ext-sensor.c b/platform/wismote/dev/ext-sensor.c index 42a8e7ed1..a957e5232 100644 --- a/platform/wismote/dev/ext-sensor.c +++ b/platform/wismote/dev/ext-sensor.c @@ -26,15 +26,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ext-sensor.c,v 1.3 2010/02/13 11:20:48 joxe Exp $ - * * ----------------------------------------------------------------- * * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Marcus Lundén, * Jesper Karlsson * Created : 2005-11-01 - * Updated : $Date: 2010/02/13 11:20:48 $ - * $Revision: 1.3 $ */ #include "contiki.h" @@ -66,11 +62,12 @@ static int status(int type) { switch(type) { - case SENSORS_ACTIVE: - case SENSORS_READY: - return active; + case SENSORS_ACTIVE: + case SENSORS_READY: + return active; + default: + return 0; } - return 0; } /*---------------------------------------------------------------------------*/ static int @@ -97,8 +94,10 @@ configure(int type, int c) sky_sensors_deactivate(0x0F); active = 0; } + return 1; + default: + return 0; } - return 0; } /*---------------------------------------------------------------------------*/ SENSORS_SENSOR(ext_sensor, "Ext", diff --git a/platform/wismote/dev/ext-sensor.h b/platform/wismote/dev/ext-sensor.h index 8fed8b59f..e9248144d 100644 --- a/platform/wismote/dev/ext-sensor.h +++ b/platform/wismote/dev/ext-sensor.h @@ -26,14 +26,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ext-sensor.h,v 1.2 2010/02/13 11:20:48 joxe Exp $ - * * ----------------------------------------------------------------- * * Author : Marcus Lundén * Created : 2005-11-01 - * Updated : $Date: 2010/02/13 11:20:48 $ - * $Revision: 1.2 $ */ #ifndef __EXT_SENSOR_H__ From fd81a0d3935b8ab9f65a77660a9eae5685f91bc6 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Mon, 19 Dec 2011 18:13:40 +0100 Subject: [PATCH 22/26] Minor cleanup (avoid setting some compiler flags twice) --- cpu/msp430/Makefile.msp430 | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 2aea9ad78..c38800417 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -39,6 +39,11 @@ CONTIKI_TARGET_SOURCEFILES += $(MSP430) \ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) ### Compiler definitions + +ifdef WERROR +CFLAGSWERROR=-Werror +endif + ifdef IAR CC = icc430 LD = xlink @@ -47,7 +52,6 @@ AR = xar OBJCOPY = ielftool STRIP = strip - ifndef IAR_PATH # This works with cygwin... IAR_BIN_PATH = $(shell dirname "`which $(CC)`") @@ -87,27 +91,22 @@ NM = msp430-nm OBJCOPY = msp430-objcopy STRIP = msp430-strip BSL = msp430-bsl +ifndef CFLAGSNO CFLAGSNO = -Wall -mmcu=$(MCU) -g $(CFLAGSWERROR) -CFLAGS += $(CFLAGSNO) -Os -fno-strict-aliasing +endif +CFLAGS += -Os -fno-strict-aliasing LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map -endif - -ifdef WERROR -CFLAGSWERROR=-Werror -endif - -CFLAGS += $(CFLAGSNO) - ### These flags can reduce the code size and RAM usage with up to 10% ifdef SMALL -ifndef IAR CFLAGS += -ffunction-sections # CFLAGS += -fdata-sections LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__ -endif # !IAR endif # SMALL +endif # IAR + +CFLAGS += $(CFLAGSNO) PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)} From 3daa822f892a5403322b3ddb52815b395fc9412c Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Mon, 19 Dec 2011 19:35:07 +0100 Subject: [PATCH 23/26] Moved configuration of memcpy workaround to cpu (only needed for an older version of mspgcc) --- cpu/msp430/msp430def.h | 19 ++----------------- platform/esb/contiki-conf.h | 1 - platform/jcreate/platform-jcreate-conf.h | 1 - .../sentilla-usb/platform-sentilla-usb-conf.h | 1 - platform/z1/platform-conf.h | 1 - platform/z1sp/platform-conf.h | 1 - 6 files changed, 2 insertions(+), 22 deletions(-) diff --git a/cpu/msp430/msp430def.h b/cpu/msp430/msp430def.h index b07a0514e..7f95473c7 100644 --- a/cpu/msp430/msp430def.h +++ b/cpu/msp430/msp430def.h @@ -50,7 +50,9 @@ #else /* __MSPGCC__ */ #include #include +#if !defined(MSP430_MEMCPY_WORKAROUND) && (__GNUC__ < 4) #define MSP430_MEMCPY_WORKAROUND 1 +#endif #endif /* __MSPGCC__ */ #define CC_CONF_INLINE inline @@ -110,26 +112,9 @@ spl_t splhigh_(void); void *w_memcpy(void *out, const void *in, size_t n); #define memcpy(dest, src, count) w_memcpy(dest, src, count) -/* #define memcpy(dest, src, count) do { \ */ -/* if(count == 2) { \ */ -/* *((uint8_t *)dest) = *((uint8_t *)src); \ */ -/* *((uint8_t *)dest + 1) = *((uint8_t *)src + 1); \ */ -/* } else { \ */ -/* memcpy(dest, src, count); \ */ -/* } \ */ -/* } while(0) */ - void *w_memset(void *out, int value, size_t n); #define memset(dest, value, count) w_memset(dest, value, count) -/* #define memset(dest, value, count) do { \ */ -/* if(count == 2) { \ */ -/* *((uint8_t *)dest) = (uint8_t)value; \ */ -/* *((uint8_t *)dest + 1) = (uint8_t)value; \ */ -/* } else { \ */ -/* memset(dest, value, count); \ */ -/* } \ */ -/* } while(0) */ #endif /* memcpy */ #endif /* __GNUC__ && __MSP430__ && MSP430_MEMCPY_WORKAROUND */ diff --git a/platform/esb/contiki-conf.h b/platform/esb/contiki-conf.h index 15a17989c..a577b7fe0 100644 --- a/platform/esb/contiki-conf.h +++ b/platform/esb/contiki-conf.h @@ -18,7 +18,6 @@ #define BV(x) (1 << x) #else #define CC_CONF_INLINE inline -#define MSP430_MEMCPY_WORKAROUND 1 #endif #define HAVE_STDINT_H diff --git a/platform/jcreate/platform-jcreate-conf.h b/platform/jcreate/platform-jcreate-conf.h index 7845301dd..620127f6b 100644 --- a/platform/jcreate/platform-jcreate-conf.h +++ b/platform/jcreate/platform-jcreate-conf.h @@ -63,7 +63,6 @@ #define CC_CONF_INLINE inline #define HAVE_STDINT_H -#define MSP430_MEMCPY_WORKAROUND 1 #include "msp430def.h" diff --git a/platform/sentilla-usb/platform-sentilla-usb-conf.h b/platform/sentilla-usb/platform-sentilla-usb-conf.h index 68e52d646..67bbee5a7 100644 --- a/platform/sentilla-usb/platform-sentilla-usb-conf.h +++ b/platform/sentilla-usb/platform-sentilla-usb-conf.h @@ -62,7 +62,6 @@ #define CC_CONF_INLINE inline #define HAVE_STDINT_H -#define MSP430_MEMCPY_WORKAROUND 1 #include "msp430def.h" diff --git a/platform/z1/platform-conf.h b/platform/z1/platform-conf.h index 496f49295..a8f4ce19a 100644 --- a/platform/z1/platform-conf.h +++ b/platform/z1/platform-conf.h @@ -73,7 +73,6 @@ #define CLIF #define HAVE_STDINT_H -#define MSP430_MEMCPY_WORKAROUND 1 #include "msp430def.h" /* XXX Temporary place for defines that are lacking in mspgcc4's gpio.h */ diff --git a/platform/z1sp/platform-conf.h b/platform/z1sp/platform-conf.h index 063811eff..c25d822d9 100644 --- a/platform/z1sp/platform-conf.h +++ b/platform/z1sp/platform-conf.h @@ -62,7 +62,6 @@ #define CC_CONF_INLINE inline #define HAVE_STDINT_H -#define MSP430_MEMCPY_WORKAROUND 1 #include "msp430def.h" /* XXX Temporary place for defines that are lacking in mspgcc4's gpio.h */ From 9ffcd538682075505752093fe3b9359238ab3102 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 20 Dec 2011 18:35:55 +0100 Subject: [PATCH 24/26] Fixed compiler warning (with IAR compiler) --- cpu/msp430/leds-arch.c | 12 +++++------- platform/sentilla-usb/leds-arch.c | 9 ++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cpu/msp430/leds-arch.c b/cpu/msp430/leds-arch.c index e53a9bb17..fe63d8ae4 100644 --- a/cpu/msp430/leds-arch.c +++ b/cpu/msp430/leds-arch.c @@ -29,14 +29,10 @@ * This file is part of the Configurable Sensor Network Application * Architecture for sensor nodes running the Contiki operating system. * - * $Id: leds-arch.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $ - * * ----------------------------------------------------------------- * * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne * Created : 2005-11-03 - * Updated : $Date: 2006/06/17 22:41:21 $ - * $Revision: 1.1 $ */ #include "contiki.h" @@ -53,9 +49,11 @@ leds_arch_init(void) unsigned char leds_arch_get(void) { - return ((LEDS_PxOUT & LEDS_CONF_RED) ? 0 : LEDS_RED) - | ((LEDS_PxOUT & LEDS_CONF_GREEN) ? 0 : LEDS_GREEN) - | ((LEDS_PxOUT & LEDS_CONF_YELLOW) ? 0 : LEDS_YELLOW); + unsigned char leds; + leds = LEDS_PxOUT; + return ((leds & LEDS_CONF_RED) ? 0 : LEDS_RED) + | ((leds & LEDS_CONF_GREEN) ? 0 : LEDS_GREEN) + | ((leds & LEDS_CONF_YELLOW) ? 0 : LEDS_YELLOW); } /*---------------------------------------------------------------------------*/ void diff --git a/platform/sentilla-usb/leds-arch.c b/platform/sentilla-usb/leds-arch.c index b4e90afd2..6430f76d6 100644 --- a/platform/sentilla-usb/leds-arch.c +++ b/platform/sentilla-usb/leds-arch.c @@ -28,7 +28,6 @@ * * This file is part of the Contiki operating system. * - * $Id: leds-arch.c,v 1.1 2010/08/25 19:57:33 nifi Exp $ */ /** @@ -43,8 +42,6 @@ #include "contiki-conf.h" #include "dev/leds.h" -#include - /*---------------------------------------------------------------------------*/ void leds_arch_init(void) @@ -56,8 +53,10 @@ leds_arch_init(void) unsigned char leds_arch_get(void) { - return ((LEDS_PxOUT & LEDS_CONF_RED) ? 0 : LEDS_RED) - | ((LEDS_PxOUT & LEDS_CONF_GREEN) ? 0 : LEDS_GREEN); + unsigned char leds; + leds = LEDS_PxOUT; + return ((leds & LEDS_CONF_RED) ? 0 : LEDS_RED) + | ((leds & LEDS_CONF_GREEN) ? 0 : LEDS_GREEN); } /*---------------------------------------------------------------------------*/ void From f3db12c19d607941b8f793ed1c145ecefd1b1ddd Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Thu, 22 Dec 2011 13:22:24 +0100 Subject: [PATCH 25/26] MSP430 setup for f2xxx based on Z1 --- {platform/z1 => cpu/msp430/f2xxx}/msp430.c | 125 ++++++++------------- 1 file changed, 45 insertions(+), 80 deletions(-) rename {platform/z1 => cpu/msp430/f2xxx}/msp430.c (77%) diff --git a/platform/z1/msp430.c b/cpu/msp430/f2xxx/msp430.c similarity index 77% rename from platform/z1/msp430.c rename to cpu/msp430/f2xxx/msp430.c index 920783940..31ae2861e 100644 --- a/platform/z1/msp430.c +++ b/cpu/msp430/f2xxx/msp430.c @@ -27,20 +27,15 @@ * SUCH DAMAGE. * * This file is part of the Contiki operating system. - * - * @(#)$Id: msp430.c,v 1.1 2010/08/24 16:26:38 joxe Exp $ */ #include "contiki.h" +#include "dev/watchdog.h" -#ifndef __IAR_SYSTEMS_ICC__ +#if defined(__MSP430__) && defined(__GNUC__) #define asmv(arg) __asm__ __volatile__(arg) #endif -#include "msp430def.h" -#include "dev/watchdog.h" -#include "net/uip.h" - /*---------------------------------------------------------------------------*/ #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND void * @@ -83,11 +78,12 @@ msp430_init_dco(void) } /*BCSCTL1 |= XT2OFF; // Make sure XT2 is off */ - /* BCSCTL2 = 0x00; // MCLK = DCOCLK/1 */ + /* BCSCTL2 = 0x00; // MCLK = DCOCLK/1 */ /* SMCLK = DCOCLK/1 */ /* DCO Internal Resistor */ } /*---------------------------------------------------------------------------*/ + /*---------------------------------------------------------------------------*/ /* Start CPU with full speed (? good or bad?) and go downwards */ /*---------------------------------------------------------------------------*/ @@ -142,69 +138,13 @@ msp430_quick_synch_dco(void) { /* vals[current_bit] = diff; */ /* should we keep the bit cleared or not ? */ - if (diff < DELTA_2) { /* DCO is too slow - fewer ticks than desired */ + if(diff < DELTA_2) { /* DCO is too slow - fewer ticks than desired */ /* toggle bit again to get it back to one */ dco_reg = dco_reg ^ (1 << current_bit); } } } /*---------------------------------------------------------------------------*/ -void -msp430_init_dco_old(void) /*Enric NOT IN USE, RIGHT NOW */ -{ - /* This code taken from the FU Berlin sources and reformatted. */ -#define DELTA ((MSP430_CPU_SPEED) / (32768 / 8)) - - unsigned int compare, oldcapture = 0; - unsigned int i; - - - BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK - and SSMCLK. XT2 is off. */ - - BCSCTL2 = 0x00; /* Init FLL to desired frequency using the 32762Hz - crystal DCO frquenzy = 2,4576 MHz */ - - BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */ - for(i = 0xffff; i > 0; i--) { /* Delay for XTAL to settle */ - asm("nop"); - } - - CCTL2 = CCIS0 + CM0 + CAP; /* Define CCR2, CAP, ACLK */ - TACTL = TASSEL1 + TACLR + MC1; // SMCLK, continous mode - - - while(1) { - - while((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured! */ - CCTL2 &= ~CCIFG; /* Capture occured, clear flag */ - compare = CCR2; /* Get current captured SMCLK */ - compare = compare - oldcapture; /* SMCLK difference */ - oldcapture = CCR2; /* Save current captured SMCLK */ - - if(DELTA == compare) { - break; /* if equal, leave "while(1)" */ - } else if(DELTA < compare) { /* DCO is too fast, slow it down */ - DCOCTL--; - if(DCOCTL == 0xFF) { /* Did DCO role under? */ - BCSCTL1--; - } - } else { /* -> Select next lower RSEL */ - DCOCTL++; - if(DCOCTL == 0x00) { /* Did DCO role over? */ - BCSCTL1++; - } - /* -> Select next higher RSEL */ - } - } - - CCTL2 = 0; /* Stop CCR2 function */ - TACTL = 0; /* Stop Timer_A */ - - BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */ -} -/*---------------------------------------------------------------------------*/ - static void init_ports(void) { @@ -258,12 +198,22 @@ init_ports(void) P6OUT = 0; #endif +#ifdef P7DIR + P7DIR = 0; + P7OUT = 0; +#endif + +#ifdef P8DIR + P8DIR = 0; + P8OUT = 0; +#endif + P1IE = 0; P2IE = 0; } /*---------------------------------------------------------------------------*/ /* msp430-ld may align _end incorrectly. Workaround in cpu_init. */ -#ifdef __GNUC__ +#if defined(__MSP430__) && defined(__GNUC__) extern int _end; /* Not in sys/unistd.h */ static char *cur_break = (char *)&_end; #endif @@ -276,7 +226,7 @@ msp430_cpu_init(void) init_ports(); msp430_quick_synch_dco(); eint(); -#ifdef __GNUC__ +#if defined(__MSP430__) && defined(__GNUC__) if((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug! */ cur_break++; } @@ -284,8 +234,6 @@ msp430_cpu_init(void) } /*---------------------------------------------------------------------------*/ -#define STACK_EXTRA 32 - /*---------------------------------------------------------------------------*/ /* * Mask all interrupts that can be masked. @@ -308,17 +256,33 @@ splhigh_(void) /* * Restore previous interrupt mask. */ -void -splx_(int sr) -{ -#ifdef __IAR_SYSTEMS_ICC__ - __bis_SR_register(sr); -#else - /* If GIE was set, restore it. */ - asmv("bis %0, r2" : : "r" (sr)); -#endif -} +/* void */ +/* splx_(int sr) */ +/* { */ +/* #ifdef __IAR_SYSTEMS_ICC__ */ +/* __bis_SR_register(sr); */ +/* #else */ +/* /\* If GIE was set, restore it. *\/ */ +/* asmv("bis %0, r2" : : "r" (sr)); */ +/* #endif */ +/* } */ /*---------------------------------------------------------------------------*/ +#ifdef __IAR_SYSTEMS_ICC__ +int __low_level_init(void) +{ + /* turn off watchdog so that C-init will run */ + WDTCTL = WDTPW + WDTHOLD; + /* + * Return value: + * + * 1 - Perform data segment initialization. + * 0 - Skip data segment initialization. + */ + return 1; +} +#endif +/*---------------------------------------------------------------------------*/ +#if DCOSYNCH_CONF_ENABLED /* this code will always start the TimerB if not already started */ void msp430_sync_dco(void) { @@ -358,11 +322,12 @@ msp430_sync_dco(void) { if(DCOCTL == 0xFF) { /* Did DCO role under? */ BCSCTL1--; } - } else if (DELTA_2 > diff) { + } else if(DELTA_2 > diff) { DCOCTL++; if(DCOCTL == 0x00) { /* Did DCO role over? */ BCSCTL1++; } } } +#endif /* DCOSYNCH_CONF_ENABLED */ /*---------------------------------------------------------------------------*/ From 9d261eec56434cb9baea0bd6445e38d2b5d6a381 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Mon, 9 Jan 2012 18:06:30 +0100 Subject: [PATCH 26/26] Use NETSTACK_RDC_* instead of NETSTACK_CONF_RDC_* --- core/net/rime/collect.c | 4 ++-- core/net/rime/rime.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/net/rime/collect.c b/core/net/rime/collect.c index f6b43ab5e..f51ba3a54 100644 --- a/core/net/rime/collect.c +++ b/core/net/rime/collect.c @@ -44,7 +44,7 @@ */ #include "contiki.h" - +#include "net/netstack.h" #include "net/rime.h" #include "net/rime/collect.h" #include "net/rime/collect-neighbor.h" @@ -126,7 +126,7 @@ struct ack_msg { full, incoming packets are dropped instead of being forwarded. */ #define MAX_MAC_REXMITS 2 #define MAX_ACK_MAC_REXMITS 5 -#define REXMIT_TIME CLOCK_SECOND * 32 / NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE +#define REXMIT_TIME CLOCK_SECOND * 32 / NETSTACK_RDC_CHANNEL_CHECK_RATE #define FORWARD_PACKET_LIFETIME_BASE REXMIT_TIME * 2 #define MAX_SENDING_QUEUE 3 * QUEUEBUF_NUM / 4 #define MIN_AVAILABLE_QUEUE_ENTRIES 4 diff --git a/core/net/rime/rime.c b/core/net/rime/rime.c index b64be1c5c..24ce008b5 100644 --- a/core/net/rime/rime.c +++ b/core/net/rime/rime.c @@ -72,7 +72,7 @@ const struct mac_driver *rime_mac; #ifdef RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME #define BROADCAST_ANNOUNCEMENT_BUMP_TIME RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME #else /* RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME */ -#define BROADCAST_ANNOUNCEMENT_BUMP_TIME CLOCK_SECOND * 32 / NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE +#define BROADCAST_ANNOUNCEMENT_BUMP_TIME CLOCK_SECOND * 32 / NETSTACK_RDC_CHANNEL_CHECK_RATE #endif /* RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME */ #ifdef RIME_CONF_BROADCAST_ANNOUNCEMENT_MIN_TIME