From 3220edb793307d86724e6c7d4c8622a6eb047576 Mon Sep 17 00:00:00 2001 From: rflury Date: Tue, 10 Nov 2009 07:03:34 +0000 Subject: [PATCH] Added DelugeT2 support for the tinynode platform. --- apps/tests/deluge/Blink/burn | 1 + support/make/tosboot.extra | 9 + .../BlockStorageManagerC.nc | 2 +- .../BlockStorageManagerP.nc | 4 +- tos/lib/net/Deluge/DelugePageTransfer.h | 2 + tos/lib/net/Deluge/extra/NetProgC.nc | 2 + tos/lib/net/Deluge/extra/NetProgM.nc | 7 +- .../Deluge/extra/tinynode/NetProg_platform.h | 39 +++++ tos/lib/net/Deluge/extra/tinynode/README | 15 ++ .../Deluge/extra/tinynode/ReprogramGuardC.nc | 13 ++ .../Deluge/extra/tinynode/ReprogramGuardP.nc | 18 ++ .../Deluge/extra/tinynode/TOSBoot_platform.h | 38 +++++ tos/lib/tosboot/Makefile | 9 + tos/lib/tosboot/TosBootP.nc | 2 +- tos/lib/tosboot/tinynode/ExecC.nc | 45 +++++ tos/lib/tosboot/tinynode/ExtFlashC.nc | 160 ++++++++++++++++++ tos/lib/tosboot/tinynode/PowerOffC.nc | 89 ++++++++++ tos/lib/tosboot/tinynode/README | 15 ++ tos/lib/tosboot/tinynode/TOSBoot_platform.h | 43 +++++ tos/lib/tosboot/tinynode/VoltageC.nc | 68 ++++++++ tos/lib/tosboot/tinynode/hardware.h | 84 +++++++++ 21 files changed, 660 insertions(+), 5 deletions(-) create mode 100644 tos/lib/net/Deluge/extra/tinynode/NetProg_platform.h create mode 100644 tos/lib/net/Deluge/extra/tinynode/README create mode 100644 tos/lib/net/Deluge/extra/tinynode/ReprogramGuardC.nc create mode 100644 tos/lib/net/Deluge/extra/tinynode/ReprogramGuardP.nc create mode 100644 tos/lib/net/Deluge/extra/tinynode/TOSBoot_platform.h create mode 100644 tos/lib/tosboot/tinynode/ExecC.nc create mode 100644 tos/lib/tosboot/tinynode/ExtFlashC.nc create mode 100644 tos/lib/tosboot/tinynode/PowerOffC.nc create mode 100644 tos/lib/tosboot/tinynode/README create mode 100644 tos/lib/tosboot/tinynode/TOSBoot_platform.h create mode 100644 tos/lib/tosboot/tinynode/VoltageC.nc create mode 100644 tos/lib/tosboot/tinynode/hardware.h diff --git a/apps/tests/deluge/Blink/burn b/apps/tests/deluge/Blink/burn index df748c38..fa4a3b1e 100755 --- a/apps/tests/deluge/Blink/burn +++ b/apps/tests/deluge/Blink/burn @@ -29,6 +29,7 @@ if [ ${PLATFORM} != 'micaz' -a \ ${PLATFORM} != 'telosb' -a \ ${PLATFORM} != 'iris' -a \ ${PLATFORM} != 'mulle' -a \ + ${PLATFORM} != 'tinynode' -a \ ${PLATFORM} != 'epic' ] then echo "\"${PLATFORM}\" is not a supported platform" diff --git a/support/make/tosboot.extra b/support/make/tosboot.extra index 12597267..ddb928c0 100644 --- a/support/make/tosboot.extra +++ b/support/make/tosboot.extra @@ -45,5 +45,14 @@ ifeq ($(BOOTLOADER),tosboot) AVR_FUSE_H ?= 0xda endif + ifeq ($(TARGETS),tinynode) + CFLAGS += -I$(DELUGE_EXTRA)/tinynode + CFLAGS += -I$(DELUGE_EXTRA) -I$(DELUGE_EXTRA)/msp430 -I$(DELUGE_EXTRA)/msp430f1611 + ifeq ($(filter docs,$(GOALS)),) + CFLAGS += -Wl,--section-start=.text=0x4a00,--defsym=_reset_vector__=0x4000 + endif + BOOTLOADER_IMG ?= $(TOSBOOT_DIR)/tinynode/main.ihex + endif + endif diff --git a/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerC.nc b/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerC.nc index 1631e735..d350aed9 100644 --- a/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerC.nc +++ b/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerC.nc @@ -69,7 +69,7 @@ implementation BlockStorageManagerP.SubStorageMap[VOLUME_DELUGE1] -> BlockStorageC_1; BlockStorageManagerP.SubStorageMap[VOLUME_DELUGE2] -> BlockStorageC_2; BlockStorageManagerP.SubStorageMap[VOLUME_DELUGE3] -> BlockStorageC_3; -#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC) || defined(PLATFORM_MULLE) +#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC) || defined(PLATFORM_MULLE) || defined(PLATFORM_TINYNODE) components At45dbStorageManagerC; BlockStorageManagerP.At45dbVolume -> At45dbStorageManagerC; #endif diff --git a/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerP.nc b/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerP.nc index 22d8fcd2..3c0e34e8 100644 --- a/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerP.nc +++ b/tos/lib/net/Deluge/BlockStorageManager/BlockStorageManagerP.nc @@ -37,7 +37,7 @@ generic module BlockStorageManagerP(uint8_t clients) interface VolumeId[uint8_t client]; #if defined(PLATFORM_TELOSB) interface StorageMap as SubStorageMap[volume_id_t volume_id]; -#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC) || defined(PLATFORM_MULLE) +#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC) || defined(PLATFORM_MULLE) || defined(PLATFORM_TINYNODE) interface At45dbVolume[volume_id_t volume_id]; #endif } @@ -180,7 +180,7 @@ implementation storage_addr_t p_addr = 0xFFFFFFFF; #if defined(PLATFORM_TELOSB) p_addr = call SubStorageMap.getPhysicalAddress[volume_id](addr); -#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC) || defined(PLATFORM_MULLE) +#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC) || defined(PLATFORM_MULLE) || defined(PLATFORM_TINYNODE) at45page_t page = call At45dbVolume.remap[volume_id]((addr >> AT45_PAGE_SIZE_LOG2)); at45pageoffset_t offset = addr & ((1 << AT45_PAGE_SIZE_LOG2) - 1); p_addr = page; diff --git a/tos/lib/net/Deluge/DelugePageTransfer.h b/tos/lib/net/Deluge/DelugePageTransfer.h index 8dc671a6..49ed1e99 100644 --- a/tos/lib/net/Deluge/DelugePageTransfer.h +++ b/tos/lib/net/Deluge/DelugePageTransfer.h @@ -37,6 +37,8 @@ #include "extra/micaz/TOSBoot_platform.h" #elif defined(PLATFORM_MULLE) #include "extra/mulle/TOSBoot_platform.h" +#elif defined(PLATFORM_TINYNODE) + #include "extra/tinynode/TOSBoot_platform.h" #else #error "Target platform is not currently supported by Deluge T2" #endif diff --git a/tos/lib/net/Deluge/extra/NetProgC.nc b/tos/lib/net/Deluge/extra/NetProgC.nc index da2b50e6..79bad765 100644 --- a/tos/lib/net/Deluge/extra/NetProgC.nc +++ b/tos/lib/net/Deluge/extra/NetProgC.nc @@ -56,6 +56,8 @@ implementation { components ActiveMessageAddressC; NetProgM.setAmAddress -> ActiveMessageAddressC; +#if !defined(PLATFORM_TINYNODE) components CC2420ControlP; NetProgM.CC2420Config -> CC2420ControlP; +#endif } diff --git a/tos/lib/net/Deluge/extra/NetProgM.nc b/tos/lib/net/Deluge/extra/NetProgM.nc index e77ebeed..fc054cff 100644 --- a/tos/lib/net/Deluge/extra/NetProgM.nc +++ b/tos/lib/net/Deluge/extra/NetProgM.nc @@ -40,7 +40,9 @@ module NetProgM { interface InternalFlash as IFlash; interface Crc; interface Leds; +#if !defined(PLATFORM_TINYNODE) interface CC2420Config; +#endif async command void setAmAddress(am_addr_t a); interface ReprogramGuard; } @@ -60,9 +62,10 @@ implementation { TOS_NODE_ID = bootArgs.address; call setAmAddress(bootArgs.address); } +#if !defined(PLATFORM_TINYNODE) call CC2420Config.setShortAddr(bootArgs.address); call CC2420Config.sync(); - +#endif return SUCCESS; } @@ -113,5 +116,7 @@ implementation { } } +#if !defined(PLATFORM_TINYNODE) event void CC2420Config.syncDone(error_t error) {} +#endif } diff --git a/tos/lib/net/Deluge/extra/tinynode/NetProg_platform.h b/tos/lib/net/Deluge/extra/tinynode/NetProg_platform.h new file mode 100644 index 00000000..8b80b524 --- /dev/null +++ b/tos/lib/net/Deluge/extra/tinynode/NetProg_platform.h @@ -0,0 +1,39 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +#ifndef __NETPROG_PLATFORM_H__ +#define __NETPROG_PLATFORM_H__ + +void netprog_reboot() { + WDTCTL = WDT_ARST_1_9; + while(1); +} + +#endif diff --git a/tos/lib/net/Deluge/extra/tinynode/README b/tos/lib/net/Deluge/extra/tinynode/README new file mode 100644 index 00000000..4b5cd7d2 --- /dev/null +++ b/tos/lib/net/Deluge/extra/tinynode/README @@ -0,0 +1,15 @@ +Deluge T2 for TinyNode +---------------------------------- + + +These files are needed by Deluge T2 to compile for the TinyNode platform. + +Note: + +Reprogramming fails if the voltage of the node is not above a given +threshold. Currently, this is set to 2.7V, which may be too high if +you run your mote on batteries. In this case, set the value of +VTHRESH in the ReprogramGaurdP.nc file to a different value. + +In case you wish not to test the voltage at all, modify ReprogramGuardP.nc +s.t. the command okToProgram() posts readDone with SUCCESS. \ No newline at end of file diff --git a/tos/lib/net/Deluge/extra/tinynode/ReprogramGuardC.nc b/tos/lib/net/Deluge/extra/tinynode/ReprogramGuardC.nc new file mode 100644 index 00000000..9f25e503 --- /dev/null +++ b/tos/lib/net/Deluge/extra/tinynode/ReprogramGuardC.nc @@ -0,0 +1,13 @@ +configuration ReprogramGuardC +{ + provides interface ReprogramGuard; +} + +implementation +{ + components ReprogramGuardP; + components new VoltageC(); + + ReprogramGuard = ReprogramGuardP; + ReprogramGuardP.Voltage -> VoltageC; +} diff --git a/tos/lib/net/Deluge/extra/tinynode/ReprogramGuardP.nc b/tos/lib/net/Deluge/extra/tinynode/ReprogramGuardP.nc new file mode 100644 index 00000000..2a3b010b --- /dev/null +++ b/tos/lib/net/Deluge/extra/tinynode/ReprogramGuardP.nc @@ -0,0 +1,18 @@ +module ReprogramGuardP { + provides interface ReprogramGuard; + uses interface Read as Voltage; +} + +implementation { + enum { + VTHRESH = 0xE66, // 2.7V + }; + + command error_t ReprogramGuard.okToProgram() { + return call Voltage.read(); + } + + event void Voltage.readDone(error_t result, uint16_t val) { + signal ReprogramGuard.okToProgramDone(result == SUCCESS && val > VTHRESH); + } +} diff --git a/tos/lib/net/Deluge/extra/tinynode/TOSBoot_platform.h b/tos/lib/net/Deluge/extra/tinynode/TOSBoot_platform.h new file mode 100644 index 00000000..87e17563 --- /dev/null +++ b/tos/lib/net/Deluge/extra/tinynode/TOSBoot_platform.h @@ -0,0 +1,38 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +/** + * @author Jonathan Hui + */ + +#ifndef __TOSBOOT_PLATFORM_H__ +#define __TOSBOOT_PLATFORM_H__ + +enum { + TOSBOOT_ARGS_ADDR = 0x70, // address of TOSBoot args in internal flash + TOSBOOT_GESTURE_MAX_COUNT = 3, // number of resets to force golden image + TOSBOOT_GOLDEN_IMG_ADDR = 0x0L, // address of the golden image in external flash + TOSBOOT_INT_PAGE_SIZE = 512L, // size of each internal program flash page +}; + +#endif diff --git a/tos/lib/tosboot/Makefile b/tos/lib/tosboot/Makefile index 1dcd46aa..3399b0ea 100644 --- a/tos/lib/tosboot/Makefile +++ b/tos/lib/tosboot/Makefile @@ -86,6 +86,15 @@ ifeq ($(MAKECMDGOALS),mulle) CFLAGS += -I../net/Deluge/extra/m16c62p endif +ifeq ($(MAKECMDGOALS),tinynode) + CFLAGS += -DTOSBOOT_START=0x4000 -DTOSBOOT_END=0x4a00 + CFLAGS += -Itinynode -Imsp430 -Imsp430f1611 -Iat45db -Ilib + CFLAGS += -I../net/Deluge + POST_BUILD_EXTRA_DEPS += strip_iv +endif + + + strip_iv: FORCE @echo " removing interrupt vector from binary" msp430-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.exe $(BUILDDIR)/main.ihex diff --git a/tos/lib/tosboot/TosBootP.nc b/tos/lib/tosboot/TosBootP.nc index 9340772c..83367056 100644 --- a/tos/lib/tosboot/TosBootP.nc +++ b/tos/lib/tosboot/TosBootP.nc @@ -145,7 +145,7 @@ implementation { secLength = extFlashReadAddr(); curAddr = curAddr + 8; -#if defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) +#if defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC) || defined (PLATFORM_TINYNODE) if (intAddr != TOSBOOT_END) { #elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) if (intAddr != 0) { diff --git a/tos/lib/tosboot/tinynode/ExecC.nc b/tos/lib/tosboot/tinynode/ExecC.nc new file mode 100644 index 00000000..0dee1824 --- /dev/null +++ b/tos/lib/tosboot/tinynode/ExecC.nc @@ -0,0 +1,45 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +/* + * @author Jonathan Hui + */ + +module ExecC { + provides { + interface Exec; + } +} + +implementation { + + command void Exec.exec() { + + //goto *(void*)(TOSBOOT_END); + + typedef void __attribute__((noreturn)) (*tosboot_exec)(); + ((tosboot_exec)TOSBOOT_END)(); + + } + +} diff --git a/tos/lib/tosboot/tinynode/ExtFlashC.nc b/tos/lib/tosboot/tinynode/ExtFlashC.nc new file mode 100644 index 00000000..859e0405 --- /dev/null +++ b/tos/lib/tosboot/tinynode/ExtFlashC.nc @@ -0,0 +1,160 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + * @author Roland Flury + */ + +module ExtFlashC { + provides { + interface Init; + interface StdControl; + interface ExtFlash; + } +} + +/** + * Simple reader module to access the Atmel at45db041 flash chip + */ +implementation { + + uint32_t addr; + + command error_t Init.init() { + + TOSH_SET_FLASH_CS_PIN(); // inverted, deselect by default + TOSH_MAKE_FLASH_CS_OUTPUT(); + + TOSH_CLR_FLASH_CLK_PIN(); + TOSH_MAKE_FLASH_CLK_OUTPUT(); + + TOSH_SET_FLASH_OUT_PIN(); + TOSH_MAKE_FLASH_OUT_OUTPUT(); + + TOSH_MAKE_FLASH_IN_INPUT(); + + TOSH_SET_FLASH_RESET_PIN(); // inverted + TOSH_MAKE_FLASH_RESET_OUTPUT(); + + return SUCCESS; + } + + command error_t StdControl.start() { return SUCCESS; } + command error_t StdControl.stop() { return SUCCESS; } + + /** + * Write a Byte over the SPI bus and receive a Byte + * + * upon calling this function, /CS must be CLR + */ + uint8_t SPIByte(uint8_t out) { + uint8_t in = 0; + uint8_t i; + + for ( i = 0; i < 8; i++, out <<= 1 ) { + // write bit + if (out & 0x80) { + TOSH_SET_FLASH_OUT_PIN(); + } else { + TOSH_CLR_FLASH_OUT_PIN(); + } + + // clock + TOSH_SET_FLASH_CLK_PIN(); + + // read bit + in <<= 1; + if (TOSH_READ_FLASH_IN_PIN()) { + in |= 1; + } + + // clock + TOSH_CLR_FLASH_CLK_PIN(); + } + + return in; + } + + + + /** + * Initializes the flash to read Byte after Byte starting + * from the given address. + * + * Subsequent calls to readByte() will return the Bytes + * starting from the specified address. + * + * stopRead() terminates this process and disables the Flash. + */ + command void ExtFlash.startRead(uint32_t newAddr) { + uint8_t cmdBuf[4]; + uint8_t i; + + // we're using "Waveform 1 - Inactive Clock Polarity Low" + // see p.7 of data sheet + TOSH_CLR_FLASH_CLK_PIN(); + TOSH_CLR_FLASH_CS_PIN(); // select the flash + + addr = newAddr; + + // we only use 256 Bytes per block (of 264 Bytes) + cmdBuf[0] = 0x52; // command for reading data starting at the following address + cmdBuf[1] = (addr >> 15) & 0xff; // 4 LSbits + cmdBuf[2] = (addr >> 7) & 0xfe; // 7 MSbits with the above 4 bits describe page to read + cmdBuf[3] = addr & 0xff; // Offset to Byte in page to read + + // transmit read command + for(i = 0; i < 4; i++) { + SPIByte(cmdBuf[i]); + } + // transmit 4 Bytes "don't care" as to spec + for(i = 0; i < 4; i++) { + SPIByte(0x0); + } + + // need to do one additional clock transition before reading + TOSH_SET_FLASH_CLK_PIN(); + TOSH_CLR_FLASH_CLK_PIN(); + } + + command uint8_t ExtFlash.readByte() { + uint8_t b = SPIByte(0); // write anything, read Byte + addr++; + if(0 == (addr & 0xFF)) { + // we've just read the last Byte from a page + // initialize the Flash to continue reading on the new page + call ExtFlash.stopRead(); + call ExtFlash.startRead(addr); + } + return b; + } + + command void ExtFlash.stopRead() { + TOSH_SET_FLASH_CS_PIN(); // disble Flash & tri-state the OUT-pin + } + +} diff --git a/tos/lib/tosboot/tinynode/PowerOffC.nc b/tos/lib/tosboot/tinynode/PowerOffC.nc new file mode 100644 index 00000000..a2302222 --- /dev/null +++ b/tos/lib/tosboot/tinynode/PowerOffC.nc @@ -0,0 +1,89 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2004 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +module PowerOffC { + provides { + interface Init; + interface StdControl; + } + uses { + interface Leds; + interface StdControl as SubControl; + } +} + +implementation { + + void haltsystem() { + + uint16_t _lpmreg; + + TOSH_SET_PIN_DIRECTIONS(); + + call SubControl.stop(); + + call Leds.glow(0x7, 0x0); + + _lpmreg = LPM4_bits; + _lpmreg |= SR_GIE; + + __asm__ __volatile__( "bis %0, r2" : : "m" ((uint16_t)_lpmreg) ); + + } + + command error_t Init.init() { + return SUCCESS; + } + + command error_t StdControl.start() { + + int i; + + // wait a short period for things to stabilize + for ( i = 0; i < 4; i++ ) { + wait(0xffff); + } + + // TinyNode: we don't have a user button + + // if user button is pressed, power down + //if (!TOSH_READ_USERINT_PIN()) { + //haltsystem(); + //} + + return SUCCESS; + + } + + command error_t StdControl.stop() { + return SUCCESS; + } + +} diff --git a/tos/lib/tosboot/tinynode/README b/tos/lib/tosboot/tinynode/README new file mode 100644 index 00000000..86792ef6 --- /dev/null +++ b/tos/lib/tosboot/tinynode/README @@ -0,0 +1,15 @@ +Deluge T2 for TinyNode +---------------------------------- + + +These files are needed by Deluge T2 to compile for the TinyNode platform. + +Note: + +Reprogramming fails if the voltage of the node is not above a given +threshold. Currently, this is set to 2.7V, which may be too high if +you run your mote on batteries. In this case, set the value of +VTHRESH in the hardware.h file to a different value. + +In case you wish not to test the voltage at all, modify VoltageC.nc +s.t. the command Voltage.okToProgram() returns always TRUE. \ No newline at end of file diff --git a/tos/lib/tosboot/tinynode/TOSBoot_platform.h b/tos/lib/tosboot/tinynode/TOSBoot_platform.h new file mode 100644 index 00000000..9bcc7767 --- /dev/null +++ b/tos/lib/tosboot/tinynode/TOSBoot_platform.h @@ -0,0 +1,43 @@ +// $Id$ + +/* + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + */ + +/** + * @author Jonathan Hui + */ + +#ifndef __TOSBOOT_PLATFORM_H__ +#define __TOSBOOT_PLATFORM_H__ + +enum { + TOSBOOT_ARGS_ADDR = 0x70, // address of TOSBoot args in internal flash + TOSBOOT_GESTURE_MAX_COUNT = 3, // number of resets to force golden image + TOSBOOT_GOLDEN_IMG_ADDR = 0x0L, // address of the golden image in external flash + TOSBOOT_INT_PAGE_SIZE = 512L, // size of each internal program flash page +}; + +enum { + DELUGE_MIN_ADV_PERIOD_LOG2 = 9, + DELUGE_QSIZE = 1, +}; + +#endif diff --git a/tos/lib/tosboot/tinynode/VoltageC.nc b/tos/lib/tosboot/tinynode/VoltageC.nc new file mode 100644 index 00000000..7a306108 --- /dev/null +++ b/tos/lib/tosboot/tinynode/VoltageC.nc @@ -0,0 +1,68 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2004 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + */ + +module VoltageC { + provides { + interface Voltage; + } +} + +implementation { + + command bool Voltage.okToProgram() { + + /** original code form the msp430 folder */ + int i; + + // Turn on and set up ADC12 with REF_1_5V + ADC12CTL0 = ADC12ON | SHT0_2 | REFON; + // Use sampling timer + ADC12CTL1 = SHP; + // Set up to sample voltage + ADC12MCTL0 = EOS | SREF_1 | INCH_11; + // Delay for reference start-up + for ( i=0; i<0x3600; i++ ); + + // Enable conversions + ADC12CTL0 |= ENC; + // Start conversion + ADC12CTL0 |= ADC12SC; + // Wait for completion + while ((ADC12IFG & BIT0) == 0); + + // Turn off ADC12 + ADC12CTL0 &= ~ENC; + ADC12CTL0 = 0; + + // Check if voltage is greater than 2.7V + return ( ADC12MEM0 > VTHRESH ); + } + +} diff --git a/tos/lib/tosboot/tinynode/hardware.h b/tos/lib/tosboot/tinynode/hardware.h new file mode 100644 index 00000000..4164dc41 --- /dev/null +++ b/tos/lib/tosboot/tinynode/hardware.h @@ -0,0 +1,84 @@ +// $Id$ + +/* + * + * + * "Copyright (c) 2000-2005 The Regents of the University of California. + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * @author Jonathan Hui + * @author Roland Flury + */ + +#ifndef __HARDWARE_H__ +#define __HARDWARE_H__ + +#include "msp430hardware.h" + +// internal flash is 16 bits in width +typedef uint16_t in_flash_addr_t; +// external flash is 32 bits in width +typedef uint32_t ex_flash_addr_t; + +void wait(uint16_t t) { + for(; t > 0; t--); +} +enum { + VTHRESH = 0xE66, // 2.7V - threshold for reprogramming the node, if voltage is below, don't reprogram +}; + +// LEDs +TOSH_ASSIGN_PIN(RED_LED2, 1, 5); // on tinynode +TOSH_ASSIGN_PIN(RED_LED, 1, 6); // external +TOSH_ASSIGN_PIN(GREEN_LED, 2, 3); +TOSH_ASSIGN_PIN(YELLOW_LED, 2, 4); + +// FLASH at45db041 +TOSH_ASSIGN_PIN(FLASH_CS, 4, 7); // inverted +TOSH_ASSIGN_PIN(FLASH_RESET, 4, 6); // inverted +TOSH_ASSIGN_PIN(FLASH_CLK, 3, 3); +TOSH_ASSIGN_PIN(FLASH_OUT, 3, 1); // MOSI - master OUT slave IN +TOSH_ASSIGN_PIN(FLASH_IN, 3, 2); // MISO - master IN slave OUT + +void TOSH_SET_PIN_DIRECTIONS(void) { + + // FLASH at45db041 + TOSH_SET_FLASH_CS_PIN(); // inverted + TOSH_MAKE_FLASH_CS_OUTPUT(); + TOSH_MAKE_FLASH_OUT_OUTPUT(); + TOSH_MAKE_FLASH_CLK_OUTPUT(); + TOSH_MAKE_FLASH_IN_INPUT(); + TOSH_SET_FLASH_RESET_PIN(); // inverted + TOSH_MAKE_FLASH_RESET_OUTPUT(); + + // LEDs + TOSH_CLR_RED_LED2_PIN(); + TOSH_CLR_RED_LED_PIN(); + TOSH_CLR_YELLOW_LED_PIN(); + TOSH_CLR_GREEN_LED_PIN(); + TOSH_MAKE_RED_LED2_OUTPUT(); + TOSH_MAKE_RED_LED_OUTPUT(); + TOSH_MAKE_YELLOW_LED_OUTPUT(); + TOSH_MAKE_GREEN_LED_OUTPUT(); +} + +#endif -- 2.39.2