diff --git a/Makefile.base b/Makefile.base index 641eaf56cd..0b860294f9 100644 --- a/Makefile.base +++ b/Makefile.base @@ -17,6 +17,10 @@ ifeq ($(BOARD),wsn430-v1_3b) INCLUDES += -I$(RIOTBOARD)/wsn430-v1_3b/include/ INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ endif +ifeq ($(BOARD),wsn430-v1_4) + INCLUDES += -I$(RIOTBOARD)/wsn430-v1_4/include/ + INCLUDES += -I$(RIOTBOARD)/wsn430-common/include/ +endif ifeq ($(BOARD),chronos) INCLUDES += -I$(RIOTBOARD)/chronos/include/ INCLUDES += -I$(RIOTBOARD)/chronos/drivers/include/ diff --git a/wsn430-common/board_config.c b/wsn430-common/board_config.c index f22e513b20..4e9bc0b69c 100644 --- a/wsn430-common/board_config.c +++ b/wsn430-common/board_config.c @@ -1,3 +1,10 @@ +/** + * board-config.c. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + #include #include #include diff --git a/wsn430-common/board_init.c b/wsn430-common/board_init.c index b7b523cf76..d89657017b 100644 --- a/wsn430-common/board_init.c +++ b/wsn430-common/board_init.c @@ -2,8 +2,8 @@ * board_init.c - Implementation of functions to init board. * Copyright (C) 2013 Milan Babel * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ #include "cpu.h" @@ -49,7 +49,7 @@ static void msb_ports_init(void) // Port 1: GDO, Flash, BSL TX P1SEL = 0x02; // Port1 Select: 00000010 = 0x02 P1OUT = 0x00; // Port1 Output: 00000000 = 0x00 - P1DIR = 0xE7; // Port1 Direction: 11100111 = 0xE7 + P1DIR = 0x87; // Port1 Direction: 10000111 = 0x87 // Port 2: GPIO, BSL RX, 1wire P2SEL = 0x04; // Port2 Select: 00000100 = 0x04 diff --git a/wsn430-common/include/board-conf.h b/wsn430-common/include/board-conf.h index e85c3128f2..7ebf0e03e6 100644 --- a/wsn430-common/include/board-conf.h +++ b/wsn430-common/include/board-conf.h @@ -1,3 +1,10 @@ +/** + * board-conf.h. + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + #ifndef BOARD_CONF_H #define BOARD_CONF_H diff --git a/wsn430-v1_3b/driver_cc110x.c b/wsn430-v1_3b/driver_cc110x.c index 39ca90bb15..89669e64f7 100644 --- a/wsn430-v1_3b/driver_cc110x.c +++ b/wsn430-v1_3b/driver_cc110x.c @@ -1,9 +1,10 @@ /* * driver_cc110x.c - Implementation of the board dependent cc1100 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will * Copyright (C) 2013 Milan Babel * - * This source code is licensed under the GNU General Public License, - * Version 3. See the file LICENSE for more details. + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. */ #include diff --git a/wsn430-v1_3b/include/board.h b/wsn430-v1_3b/include/board.h index ad864e132e..ee09d10169 100644 --- a/wsn430-v1_3b/include/board.h +++ b/wsn430-v1_3b/include/board.h @@ -1,5 +1,35 @@ -#ifndef _MSB_BOARD_H -#define _MSB_BOARD_H +/** + * board.h - wsn430-v1_3b Board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _WSN_BOARD_H +#define _WSN_BOARD_H + +/** + * @defgroup wsn430-v1_3b Senslab WSN430 v1.3b + * @ingroup wsn430 + * +

Compontents

+\li MSP430 +\li CC1100 + +* @{ +*/ + +/** + * @file + * @brief wsn430-v1_3b Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Milan Babel + * @version $Revision$ + * + * @note $Id$ + */ //MSB430 core #define MSP430_INITIAL_CPU_SPEED 800000uL @@ -28,4 +58,4 @@ #include /** @} */ -#endif // _MSB_BOARD_H +#endif // _WSN_BOARD_H diff --git a/wsn430-v1_4/Makefile b/wsn430-v1_4/Makefile new file mode 100644 index 0000000000..1bc4eca767 --- /dev/null +++ b/wsn430-v1_4/Makefile @@ -0,0 +1,36 @@ +SRC = $(wildcard *.c) +BINDIR = bin/ +OBJ = $(SRC:%.c=$(BINDIR)%.o)## defines +export ARCH = wsn430-v1_4_base.a + +DEP = $(SRC:%.c=$(BINDIR)%.d) + +INCLUDES += -I${RIOTBASE}/core/include/ +INCLUDES += -Iinclude/ -I$(RIOTBOARD)/wsn430-common/include/ +INCLUDES += -I$(RIOTBASE)/cpu/msp430-common/include/ -I$(RIOTBASE)/cpu/msp430x16x/include/ +INCLUDES += -I$(RIOTBASE)/drivers/cc2420/include/ -I$(RIOTBASE)/sys/include +#INCLUDES += -I/usr/msp430/include/ + +all: $(BINDIR)$(ARCH) + $(MAKE) -C ../wsn430-common + +$(BINDIR)$(ARCH): $(OBJ) + $(AR) rcs $(BINDIR)$(ARCH) $(OBJ) + +# pull in dependency info for *existing* .o files +-include $(OBJ:.o=.d) + +# compile and generate dependency info +$(BINDIR)%.o: %.c + mkdir -p $(BINDIR) + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -c $*.c -o $(BINDIR)$*.o + $(CC) $(CFLAGS) $(INCLUDES) $(BOARDINCLUDE) $(PROJECTINCLUDE) $(CPUINCLUDE) -MM $*.c > $(BINDIR)$*.d + @printf "$(BINDIR)"|cat - $(BINDIR)$*.d > /tmp/riot_out && mv /tmp/riot_out $(BINDIR)$*.d + +# remove compilation products +clean: + $(MAKE) -C ../wsn430-common clean + rm -f $(BINDIR)$(ARCH) $(OBJ) $(DEP) + @if [ -d $(BINDIR) ] ; \ + then rmdir $(BINDIR) ; \ + fi \ No newline at end of file diff --git a/wsn430-v1_4/Makefile.dep b/wsn430-v1_4/Makefile.dep new file mode 100644 index 0000000000..52516208bc --- /dev/null +++ b/wsn430-v1_4/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += msp430_common \ No newline at end of file diff --git a/wsn430-v1_4/Makefile.include b/wsn430-v1_4/Makefile.include new file mode 100644 index 0000000000..366d6cbcc8 --- /dev/null +++ b/wsn430-v1_4/Makefile.include @@ -0,0 +1,3 @@ +include $(RIOTBOARD)/$(BOARD)/Makefile.dep + +include $(RIOTBOARD)/wsn430-common/Makefile.include \ No newline at end of file diff --git a/wsn430-v1_4/driver_cc2420.c b/wsn430-v1_4/driver_cc2420.c new file mode 100644 index 0000000000..c653c9ba3a --- /dev/null +++ b/wsn430-v1_4/driver_cc2420.c @@ -0,0 +1,213 @@ + /* + * driver_cc2420.c - Implementation of the board dependent cc2420 functions. + * Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#include + +#include +#include +#include +#include + +#include + +#define CC2420_RESETn_PIN 0x80 +#define CC2420_VREGEN_PIN 0x01 + +#define CC2420_GDO0_PIN 0x08 +#define CC2420_GDO2_PIN 0x10 +#define CC2420_SFD_PIN 0x20 +#define CC2420_CCA_PIN 0x40 + +#define CC2420_GDO0 (P1IN & CC2420_GDO0_PIN) // read serial I/O (GDO0) +#define CC2420_GDO2 (P1IN & CC2420_GDO2_PIN) // read serial I/O (GDO2) +#define CC2420_SFD (P1IN & CC2420_SFD_PIN) // read serial I/0 (SFD) +#define CC2420_CCA (P1IN & CC2420_CCA_PIN) // read serial I/O (CCA) + + +#define CC2420_CS_LOW (P4OUT &= ~0x04) +#define CC2420_CS_HIGH (P4OUT |= 0x04) + +#define CC2420_GDO1_LOW_COUNT (2700) // loop count (timeout ~ 500 us) to wait +#define CC2420_GDO1_LOW_RETRY (100) // max. retries for GDO1 to go low + +volatile int abort_count; +volatile int retry_count = 0; + +void cc2420_reset(void) +{ + P3OUT |= CC2420_VREGEN_PIN; + P1OUT &= ~CC2420_RESETn_PIN; + hwtimer_wait(500); + P1OUT |= CC2420_RESETn_PIN; +} + +void cc2420_gdo0_enable(void) +{ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ + P1IE |= CC2420_GDO0_PIN; /* Enable interrupt for GDO0 */ +} + +void cc2420_gdo0_disable(void) +{ + P1IE &= ~CC2420_GDO0_PIN; /* Disable interrupt for GDO0 */ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ +} + +void cc2420_gdo2_enable(void) +{ + P1IFG &= ~CC2420_GDO2_PIN; /* Clear IFG for GDO2 */ + P1IE |= CC2420_GDO2_PIN; /* Enable interrupt for GDO2 */ +} + +void cc2420_gdo2_disable(void) +{ + P1IE &= ~CC2420_GDO2_PIN; /* Disable interrupt for GDO2 */ + P1IFG &= ~CC2420_GDO2_PIN; /* Clear IFG for GDO2 */ +} + +void cc2420_before_send(void) +{ + // Disable SFD interrupt before sending packet + // However this is not used atm +} + +void cc2420_after_send(void) +{ + // Enable SFD interrupt after sending packet + // However this is not used atm +} + + +int cc2420_get_gdo0(void) +{ + return CC2420_GDO0; +} + +int cc2420_get_gdo2(void) +{ + return CC2420_GDO2; +} + +int cc2420_get_sfd(void) +{ + return CC2420_SFD; +} + +void cc2420_spi_cs(void) +{ + CC2420_CS_LOW; +} + +uint8_t cc2420_txrx(uint8_t data) +{ + /* Ensure TX Buf is empty */ + long c = 0; + IFG2 &= ~UTXIFG1; + IFG2 &= ~URXIFG1; + U1TXBUF = data; + while(!(IFG2 & UTXIFG1)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + /* Wait for Byte received */ + c = 0; + while(!(IFG2 & URXIFG1)) { + if (c++ == 1000000) { + puts("cc2420_txrx alarm()"); + } + } + return U1RXBUF; +} + + +void cc2420_spi_select(void) +{ + CC2420_CS_LOW; +} + +void cc2420_spi_unselect(void) { + CC2420_CS_HIGH; +} + +void cc2420_init_interrupts(void) +{ + unsigned int state = disableIRQ(); /* Disable all interrupts */ + P1SEL = 0x00; /* must be <> 1 to use interrupts */ + P1IES |= CC2420_GDO2_PIN; /* Enables external interrupt on falling edge (for GDO2) */ + P1IE |= CC2420_GDO2_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_GDO2_PIN; /* Clears the interrupt flag */ + P1IES |= CC2420_SFD_PIN; /* Enables external interrupt on falling edge (for GDO2) */ + P1IE |= CC2420_SFD_PIN; /* Enable interrupt */ + P1IFG &= ~CC2420_SFD_PIN; /* Clears the interrupt flag */ + P1IE &= ~CC2420_GDO0_PIN; /* Disable interrupt for GDO0 */ + P1IFG &= ~CC2420_GDO0_PIN; /* Clear IFG for GDO0 */ + restoreIRQ(state); /* Enable all interrupts */ +} + +void cc2420_spi_init(void) +{ + // Switch off async UART + while(!(U1TCTL & TXEPT)); // Wait for empty UxTXBUF register + IE2 &= ~(URXIE1 + UTXIE1); // Disable USART1 receive&transmit interrupt + ME2 &= ~(UTXE1 + URXE1); + P5DIR |= 0x0A; // output for CLK and SIMO + P5DIR &= ~(0x04); // input for SOMI + P5SEL |= 0x0E; // Set pins as SPI + + // Keep peripheral in reset state + U1CTL = SWRST; + + // 8-bit SPI Master 3-pin mode, with SMCLK as clock source + // CKPL works also, but not CKPH+CKPL or none of them!! + U1CTL |= CHAR + SYNC + MM; + U1TCTL = CKPH + SSEL1 + SSEL0 + STC; + + // Ignore clockrate argument for now, just use clock source/2 + // SMCLK = 8 MHz + U1BR0 = 0x02; // Ensure baud rate >= 2 + U1BR1 = 0x00; + U1MCTL = 0x00; // No modulation + U1RCTL = 0x00; // Reset Receive Control Register + + // Enable SPI mode + ME2 |= USPIE1; + + // Release for operation + U1CTL &= ~SWRST; +} + +/* + * CC1100 receive interrupt + */ +interrupt (PORT1_VECTOR) __attribute__ ((naked)) cc2420_isr(void){ + __enter_isr(); + /* Check IFG */ + if ((P1IFG & CC2420_GDO2_PIN) != 0) { + puts("rx interrupt"); + P1IFG &= ~CC2420_GDO2_PIN; + cc2420_rx_irq(); + } + else if ((P1IFG & CC2420_GDO0_PIN) != 0) { + cc2420_rxoverflow_irq(); + puts("[CC2420] rxfifo overflow"); + //P1IE &= ~CC2420_GDO0_PIN; // Disable interrupt for GDO0 + P1IFG &= ~CC2420_GDO0_PIN; // Clear IFG for GDO0 + } else if ((P1IFG & CC2420_SFD_PIN) != 0) { + puts("sfd interrupt"); + P1IFG &= ~CC2420_SFD_PIN; + cc2420_switch_to_rx(); + } + + else { + puts("cc2420_isr(): unexpected IFG!"); + /* Should not occur - only GDO1 and GDO2 interrupts are enabled */ + } + __exit_isr(); +} diff --git a/wsn430-v1_4/include/board.h b/wsn430-v1_4/include/board.h new file mode 100644 index 0000000000..3cb86d1366 --- /dev/null +++ b/wsn430-v1_4/include/board.h @@ -0,0 +1,61 @@ +/** + * board.h - wsn430-v1_4 Board. + * Copyright (C) 2013 Milan Babel + * + * This source code is licensed under the GNU Lesser General Public License, + * Version 2. See the file LICENSE for more details. + */ + +#ifndef _WSN_BOARD_H +#define _WSN_BOARD_H + +/** + * @defgroup wsn430-v1_4 Senslab WSN430 v1.4 + * @ingroup wsn430 + * +

Compontents

+\li MSP430 +\li CC2420 + +* @{ +*/ + +/** + * @file + * @brief wsn430-v1_4 Board + * + * @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project + * @author Milan Babel + * @version $Revision$ + * + * @note $Id$ + */ + +//MSB430 core +#define MSP430_INITIAL_CPU_SPEED 800000uL +#define MSP430_HAS_DCOR 0 +#define MSP430_HAS_EXTERNAL_CRYSTAL 1 + +/* LEDs ports MSB430 */ +#define LEDS_PxDIR P5DIR +#define LEDS_PxOUT P5OUT +#define LEDS_CONF_RED 0x04 +#define LEDS_CONF_GREEN 0x05 +#define LEDS_CONF_BLUE 0x06 + +#define LED_RED_ON LEDS_PxOUT &=~LEDS_CONF_RED +#define LED_RED_OFF LEDS_PxOUT |= LEDS_CONF_RED +#define LED_RED_TOGGLE LEDS_PxOUT ^= LEDS_CONF_RED + +#define LED_GREEN_ON LEDS_PxOUT &=~LEDS_CONF_GREEN +#define LED_GREEN_OFF LEDS_PxOUT |= LEDS_CONF_GREEN +#define LED_GREEN_TOGGLE LEDS_PxOUT ^= LEDS_CONF_GREEN + +#define LED_BLUE_ON LEDS_PxOUT &=~LEDS_CONF_BLUE +#define LED_BLUE_OFF LEDS_PxOUT |= LEDS_CONF_BLUE +#define LED_BLUE_TOGGLE LEDS_PxOUT ^= LEDS_CONF_BLUE + +#include + +/** @} */ +#endif // _WSN_BOARD_H