diff --git a/boards/common/wsn430/Makefile.features b/boards/common/wsn430/Makefile.features new file mode 100644 index 0000000000000000000000000000000000000000..6d1b3acb462b0120b429fba1676466f20bb65649 --- /dev/null +++ b/boards/common/wsn430/Makefile.features @@ -0,0 +1,10 @@ +# Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_gpio +FEATURES_PROVIDED += periph_timer +FEATURES_PROVIDED += periph_spi +FEATURES_PROVIDED += periph_uart + +# The board MPU family (used for grouping by the CI system) +FEATURES_MCU_GROUP = msp430 + +-include $(RIOTCPU)/msp430fxyz/Makefile.features diff --git a/boards/common/wsn430/Makefile.include b/boards/common/wsn430/Makefile.include index 3d197451b76c4b326e03f300790113373d375bb1..8bf601afa24a350a8bec28e8dbbc0e79f3598ee6 100644 --- a/boards/common/wsn430/Makefile.include +++ b/boards/common/wsn430/Makefile.include @@ -1,17 +1,18 @@ -## the cpu to build for +# select the used CPU export CPU = msp430fxyz export CPU_MODEL = msp430f1611 -# set default port depending on operating system +# include this module in the build +USEMODULE += boards_common_wsn430 +# use common wsn430 includes +export INCLUDES += -I$(RIOTBOARD)/common/wsn430/include + +# configure the serial interface PORT_LINUX ?= /dev/ttyUSB0 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*))) -# setup serial terminal include $(RIOTMAKE)/tools/serial.inc.mk -# setup flash tool +# configure the flash tool export OFLAGS = -O ihex export FLASHER = mspdebug export FFLAGS = -d $(PORT) -j uif "prog $(HEXFILE)" - -# include common wsn430 includes -export INCLUDES += -I$(RIOTBOARD)/common/wsn430/include diff --git a/boards/common/wsn430/board_init.c b/boards/common/wsn430/board_init.c index 1792308d73a34e50189199e847f848507b6e1232..521e248f2fd329fc7bdf726fbe6fccb91151a757 100644 --- a/boards/common/wsn430/board_init.c +++ b/boards/common/wsn430/board_init.c @@ -1,6 +1,6 @@ /* - * board_init.c - Implementation of functions to init board. * Copyright (C) 2013 Milan Babel <babel@inf.fu-berlin.de> + * 2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -15,103 +15,76 @@ * @brief Board initialization for WSN430 * * @author Milan Babel <babel@inf.fu-berlin.de> + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> * * @} */ #include "cpu.h" #include "irq.h" -#include "board.h" -#include "msp430.h" -#include "debug.h" +#include "assert.h" #include "uart_stdio.h" +#include "periph_conf.h" -static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED; - -void msp430_init_dco(void); - -typedef enum { - MCLK_2MHZ_SCLK_1MHZ = 1000002uL, - MCLK_4MHZ_SCLK_1MHZ = 1000004uL, - MCLK_8MHZ_SCLK_1MHZ = 1000008uL, - MCLK_8MHZ_SCLK_8MHZ = 8000000uL -}speed_t; +enum { + MCLK_2MHZ_SCLK_1MHZ = (SELM_2 | DIVM_2 | SELS | DIVS_3), + MCLK_4MHZ_SCLK_1MHZ = (SELM_2 | DIVM_1 | SELS | DIVS_3), + MCLK_8MHZ_SCLK_1MHZ = (SELM_2 | SELS | DIVS_3), + MCLK_8MHZ_SCLK_8MHZ = (SELM_2 | SELS), +}; 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 = 0x87; // Port1 Direction: 10000111 = 0x87 + /* Port 1: GDO, Flash, BSL TX */ + P1SEL = 0x02; /* Port1 Select: 00000010 = 0x02 */ + P1OUT = 0x00; /* Port1 Output: 00000000 = 0x00 */ + P1DIR = 0x87; /* Port1 Direction: 10000111 = 0x87 */ - // Port 2: GPIO, BSL RX, 1wire - P2SEL = 0x04; // Port2 Select: 00000100 = 0x04 - P2OUT = 0x00; // Port2 Output: 00000000 = 0x00 - P2DIR = 0xFF; // Port2 Direction: 11111111 = 0xFF + /* Port 2: GPIO, BSL RX, 1wire */ + P2SEL = 0x04; /* Port2 Select: 00000100 = 0x04 */ + P2OUT = 0x00; /* Port2 Output: 00000000 = 0x00 */ + P2DIR = 0xFF; /* Port2 Direction: 11111111 = 0xFF */ - // Port 3: UART - P3SEL = 0xFE; // Port3 Select: 11111110 = 0xFE - P3OUT = 0x00; // Port3 Output: 00000000 = 0x00 - P3DIR = 0xFF; // Port3 Direction: 11111111 = 0xFF + /* Port 3: UART */ + P3SEL = 0xFE; /* Port3 Select: 11111110 = 0xFE */ + P3OUT = 0x00; /* Port3 Output: 00000000 = 0x00 */ + P3DIR = 0xFF; /* Port3 Direction: 11111111 = 0xFF */ - // Port 4: CS - P4SEL = 0x00; // Port4 Select: 00000000 = 0x00 - P4OUT = 0x14; // Port4 Output: 00010100 = 0x14 - P4DIR = 0xFF; // Port4 Direction: 11111111 = 0xFF + /* Port 4: CS */ + P4SEL = 0x00; /* Port4 Select: 00000000 = 0x00 */ + P4OUT = 0x14; /* Port4 Output: 00010100 = 0x14 */ + P4DIR = 0xFF; /* Port4 Direction: 11111111 = 0xFF */ - // Port 5: SPI, LED - P5SEL = 0x0E; // Port5 Select: 00001110 = 0x0E - P5OUT = 0x70; // Port5 Output: 01110000 = 0x70 - P5DIR = 0x70; // Port5 Direction: 01110000 = 0x70 + /* Port 5: SPI, LED */ + P5SEL = 0x0E; /* Port5 Select: 00001110 = 0x0E */ + P5OUT = 0x70; /* Port5 Output: 01110000 = 0x70 */ + P5DIR = 0x70; /* Port5 Direction: 01110000 = 0x70 */ - P6SEL = 0xFF; // Port6 Select: 11111111 = 0xFF - P6OUT = 0x00; // Port6 Output: 00000000 = 0x00 - P6DIR = 0xFF; // Port6 Direction: 11111000 = 0xF8 + P6SEL = 0xFF; /* Port6 Select: 11111111 = 0xFF */ + P6OUT = 0x00; /* Port6 Output: 00000000 = 0x00 */ + P6DIR = 0xFF; /* Port6 Direction: 11111000 = 0xF8 */ } -void msp430_set_cpu_speed(uint32_t speed) -{ - irq_disable(); - __msp430_cpu_speed = speed; - msp430_init_dco(); - irq_enable(); -} - -/*---------------------------------------------------------------------------*/ -void msp430_init_dco(void) +static void msp430_init_cpuclk(uint8_t speed) { - /*----------------------- use external oszillator -------------------------*/ - uint16_t i; - - // Stop watchdog - WDTCTL = WDTPW + WDTHOLD; - - BCSCTL1 = RSEL2; - - // Wait for xtal to stabilize - do { - IFG1 &= ~OFIFG; // Clear oscillator fault flag - for (i = 0xFF; i > 0; i--); // Time for flag to set - } - while ((IFG1 & OFIFG) != 0); // Oscillator fault flag still set? - switch (__msp430_cpu_speed) { - case MCLK_2MHZ_SCLK_1MHZ: - BCSCTL2 = (SELM_2 | DIVM_2) | (SELS | DIVS_3); - break; - case MCLK_4MHZ_SCLK_1MHZ: - BCSCTL2 = (SELM_2 | DIVM_1) | (SELS | DIVS_3); - break; - case MCLK_8MHZ_SCLK_1MHZ: - BCSCTL2 = SELM_2 | (SELS | DIVS_3); - break; - default: - BCSCTL2 = SELM_2 + SELS; // MCLK and SMCLK = XT2 (safe) - break; - } + /* stop watchdog */ + WDTCTL = WDTPW + WDTHOLD; + BCSCTL1 = RSEL2; + + /* wait for XTAL to stabilize */ + do { + /* clear oscillator fault flag */ + IFG1 &= ~OFIFG; + /* time for flag to set */ + for (uint16_t i = 0xFF; i > 0; i--) {} + } while ((IFG1 & OFIFG) != 0); + + /* apply clock config */ + BCSCTL2 = speed; } void board_init(void) @@ -119,7 +92,10 @@ void board_init(void) msp430_cpu_init(); msb_ports_init(); - msp430_set_cpu_speed(MCLK_8MHZ_SCLK_8MHZ); + /* initialize CPU clock */ + unsigned state = irq_disable(); + msp430_init_cpuclk(CLOCK_MODE); + irq_restore(state); /* initialize STDIO over UART */ uart_stdio_init(); diff --git a/boards/common/wsn430/include/board_common.h b/boards/common/wsn430/include/board.h similarity index 87% rename from boards/common/wsn430/include/board_common.h rename to boards/common/wsn430/include/board.h index cbcef903b7d3966468df6086741dab34ec9366ac..bc6a6714d5ffb42177a9ea2d95bd9189f0db950f 100644 --- a/boards/common/wsn430/include/board_common.h +++ b/boards/common/wsn430/include/board.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2013 Milan Babel <babel@inf.fu-berlin.de> - * 2016 Freie Universität Berlin + * 2015-2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -8,9 +8,9 @@ */ /** - * @defgroup boards_common_wsn430 WSN430 common + * @defgroup boards_common_wsn430 Shared WSN430 files * @ingroup boards_common - * @brief Shared files and configuration for all WSN430 based boards. + * @brief Common files for WSN430 based boards * @{ * * @file @@ -21,8 +21,10 @@ * */ -#ifndef BOARD_COMMON_H -#define BOARD_COMMON_H +#ifndef BOARD_H +#define BOARD_H + +#include "cpu.h" #ifdef __cplusplus extern "C" { @@ -71,5 +73,5 @@ extern "C" { } #endif -#endif /* BOARD_COMMON_H */ +#endif /* BOARD_H */ /** @} */ diff --git a/boards/common/wsn430/include/periph_conf.h b/boards/common/wsn430/include/periph_conf.h index e0f32a5e43e6069cecfad8f3fdc6ff3510f6f11e..ff36261d9033f214d090dde194b2648cc83e4a63 100644 --- a/boards/common/wsn430/include/periph_conf.h +++ b/boards/common/wsn430/include/periph_conf.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2014 INRIA - * 2015 Freie Universität Berlin + * 2015,2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser General * Public License v2.1. See the file LICENSE in the top level directory for more @@ -12,10 +12,10 @@ * @{ * * @file - * @brief WSN30 peripheral configuration + * @brief WSN430 peripheral configuration * * @author Oliver Hahm <oliver.hahm@inria.fr> - * Hauke Petersen <hauke.petersen@fu-berlin.de> + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> */ #ifndef PERIPH_CONF_H @@ -29,10 +29,9 @@ extern "C" { * @name Clock configuration * @{ */ -/** @todo Move all clock configuration code here from the board.h */ -#define CLOCK_CORECLOCK (8000000U) - -#define CLOCK_CMCLK CLOCK_CORECLOCK /* no divider programmed */ +#define CLOCK_CORECLOCK (8000000UL) +#define CLOCK_MODE (MCLK_8MHZ_SCLK_8MHZ) +#define CLOCK_CMCLK (CLOCK_CORECLOCK) /* no divider programmed */ /** @} */ /** @@ -92,3 +91,4 @@ extern "C" { #endif #endif /* PERIPH_CONF_H */ +/** @} */ diff --git a/boards/wsn430-v1_3b/Makefile b/boards/wsn430-v1_3b/Makefile index 77db0c19088c99699cd48562d89b7733acd6c217..3bf2d5cd3c8e680a2565d74e771f9a2f20531005 100644 --- a/boards/wsn430-v1_3b/Makefile +++ b/boards/wsn430-v1_3b/Makefile @@ -1,5 +1,4 @@ MODULE = board - DIRS = $(RIOTBOARD)/common/wsn430 include $(RIOTBASE)/Makefile.base diff --git a/boards/wsn430-v1_3b/Makefile.features b/boards/wsn430-v1_3b/Makefile.features index 6d1b3acb462b0120b429fba1676466f20bb65649..41bb7f28639d1ab56fa117e5b57ae9f762a6307a 100644 --- a/boards/wsn430-v1_3b/Makefile.features +++ b/boards/wsn430-v1_3b/Makefile.features @@ -1,10 +1 @@ -# Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio -FEATURES_PROVIDED += periph_timer -FEATURES_PROVIDED += periph_spi -FEATURES_PROVIDED += periph_uart - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = msp430 - --include $(RIOTCPU)/msp430fxyz/Makefile.features +include $(RIOTBOARD)/common/wsn430/Makefile.features diff --git a/boards/wsn430-v1_3b/Makefile.include b/boards/wsn430-v1_3b/Makefile.include index 54a6472f9a8e250d0150d5f0d54afe1a17504ae8..e63bf64dd294081af0513227fe6f23fde2e1dba5 100644 --- a/boards/wsn430-v1_3b/Makefile.include +++ b/boards/wsn430-v1_3b/Makefile.include @@ -1,2 +1 @@ -USEMODULE += boards_common_wsn430 include $(RIOTBOARD)/common/wsn430/Makefile.include diff --git a/boards/wsn430-v1_3b/include/board.h b/boards/wsn430-v1_3b/include/board.h deleted file mode 100644 index 3836c71056006ca2714ec3a78a26777dadcc1677..0000000000000000000000000000000000000000 --- a/boards/wsn430-v1_3b/include/board.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2013 Milan Babel <babel@inf.fu-berlin.de> - * 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup boards_wsn430-v1_3b WSN430 v1.3b - * @ingroup boards - * @brief Support for the Senslab WSN430 v1.3b board - * - * <h2>Compontents</h2> - * \li MSP430 - * \li CC1100 - * - * @{ - * - * @file - * @brief Basic definitions for the Senslab WSN430 v1.3b board - * - * @author Milan Babel <babel@inf.fu-berlin.de> - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - */ - -#ifndef BOARD_H -#define BOARD_H - -#include "board_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Define the CPU model for the <msp430.h> - */ -#ifndef __MSP430F1611__ -#define __MSP430F1611__ -#endif - -/** - * @name CPU core configuration - * @{ - */ -/** @todo Move this to the periph_conf.h */ -#define MSP430_INITIAL_CPU_SPEED 800000uL -#define F_CPU MSP430_INITIAL_CPU_SPEED -#define F_RC_OSCILLATOR 32768 -#define MSP430_HAS_DCOR 0 -#define MSP430_HAS_EXTERNAL_CRYSTAL 1 -/** @} */ - -#ifdef __cplusplus -} -#endif - -#include <msp430x16x.h> - -/** @} */ -#endif /* BOARD_H */ diff --git a/boards/wsn430-v1_4/Makefile b/boards/wsn430-v1_4/Makefile index 77db0c19088c99699cd48562d89b7733acd6c217..3bf2d5cd3c8e680a2565d74e771f9a2f20531005 100644 --- a/boards/wsn430-v1_4/Makefile +++ b/boards/wsn430-v1_4/Makefile @@ -1,5 +1,4 @@ MODULE = board - DIRS = $(RIOTBOARD)/common/wsn430 include $(RIOTBASE)/Makefile.base diff --git a/boards/wsn430-v1_4/Makefile.features b/boards/wsn430-v1_4/Makefile.features index 6d1b3acb462b0120b429fba1676466f20bb65649..41bb7f28639d1ab56fa117e5b57ae9f762a6307a 100644 --- a/boards/wsn430-v1_4/Makefile.features +++ b/boards/wsn430-v1_4/Makefile.features @@ -1,10 +1 @@ -# Put defined MCU peripherals here (in alphabetical order) -FEATURES_PROVIDED += periph_gpio -FEATURES_PROVIDED += periph_timer -FEATURES_PROVIDED += periph_spi -FEATURES_PROVIDED += periph_uart - -# The board MPU family (used for grouping by the CI system) -FEATURES_MCU_GROUP = msp430 - --include $(RIOTCPU)/msp430fxyz/Makefile.features +include $(RIOTBOARD)/common/wsn430/Makefile.features diff --git a/boards/wsn430-v1_4/Makefile.include b/boards/wsn430-v1_4/Makefile.include index 54a6472f9a8e250d0150d5f0d54afe1a17504ae8..e63bf64dd294081af0513227fe6f23fde2e1dba5 100644 --- a/boards/wsn430-v1_4/Makefile.include +++ b/boards/wsn430-v1_4/Makefile.include @@ -1,2 +1 @@ -USEMODULE += boards_common_wsn430 include $(RIOTBOARD)/common/wsn430/Makefile.include diff --git a/boards/wsn430-v1_4/include/board.h b/boards/wsn430-v1_4/include/board.h deleted file mode 100644 index 9771516bc3185799cafc4b4707c68ace48ca1b8e..0000000000000000000000000000000000000000 --- a/boards/wsn430-v1_4/include/board.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2013 Milan Babel <babel@inf.fu-berlin.de> - * 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @defgroup boards_wsn430-v1_4 WSN430 v1.4 - * @ingroup boards - * @brief Support for the Senslab WSN430 v1.4 board - * - * <h2>Compontents</h2> - * \li MSP430 - * \li CC2420 - * - * @{ - * - * @file - * @brief Basic definitions for the Senslab WSN430 v1.4 board - * - * @author Milan Babel <babel@inf.fu-berlin.de> - * @author Hauke Petersen <hauke.petersen@fu-berlin.de> - */ - -#ifndef BOARD_H -#define BOARD_H - -#include "board_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Define the CPU model for the <msp430.h> - */ -#ifndef __MSP430F1611__ -#define __MSP430F1611__ -#endif - -/** - * @name CPU core configuration - * @{ - */ -/** @todo Move this to the periph_conf.h */ -#define MSP430_INITIAL_CPU_SPEED 800000uL -#define F_CPU MSP430_INITIAL_CPU_SPEED -#define F_RC_OSCILLATOR 32768 -#define MSP430_HAS_DCOR 0 -#define MSP430_HAS_EXTERNAL_CRYSTAL 1 -/** @} */ - -#ifdef __cplusplus -} -#endif - -#include <msp430x16x.h> - -/** @} */ -#endif /* BOARD_H */