]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Make tosboot compliant with TEP3.
authorrazvanm <razvanm>
Wed, 23 Sep 2009 18:29:20 +0000 (18:29 +0000)
committerrazvanm <razvanm>
Wed, 23 Sep 2009 18:29:20 +0000 (18:29 +0000)
29 files changed:
tos/lib/tosboot/Makefile
tos/lib/tosboot/TOSBoot.h [deleted file]
tos/lib/tosboot/TOSBoot.nc [deleted file]
tos/lib/tosboot/TOSBootM.nc [deleted file]
tos/lib/tosboot/TosBoot.h [new file with mode: 0644]
tos/lib/tosboot/TosBootC.nc [new file with mode: 0644]
tos/lib/tosboot/TosBootP.nc [new file with mode: 0644]
tos/lib/tosboot/avr/InternalFlashC.nc
tos/lib/tosboot/avr/ProgFlashC.nc [new file with mode: 0644]
tos/lib/tosboot/avr/ProgFlashM.nc [deleted file]
tos/lib/tosboot/epic/ExtFlashC.nc
tos/lib/tosboot/epic/ExtFlashM.nc [deleted file]
tos/lib/tosboot/epic/ExtFlashP.nc [new file with mode: 0644]
tos/lib/tosboot/iris/ProgFlashC.nc [new file with mode: 0644]
tos/lib/tosboot/iris/ProgFlashM.nc [deleted file]
tos/lib/tosboot/m16c62p/ProgFlashC.nc [new file with mode: 0644]
tos/lib/tosboot/m16c62p/ProgFlashM.nc [deleted file]
tos/lib/tosboot/msp430/HPLUSART0M.nc [deleted file]
tos/lib/tosboot/msp430/HPLUSARTControl.nc [deleted file]
tos/lib/tosboot/msp430/HplUsart0C.nc [new file with mode: 0644]
tos/lib/tosboot/msp430/HplUsartControl.nc [new file with mode: 0644]
tos/lib/tosboot/msp430/ProgFlashC.nc [new file with mode: 0644]
tos/lib/tosboot/msp430/ProgFlashM.nc [deleted file]
tos/lib/tosboot/msp430f1611/PluginC.nc
tos/lib/tosboot/msp430f1611/PowerOffC.nc [new file with mode: 0644]
tos/lib/tosboot/msp430f1611/PowerOffM.nc [deleted file]
tos/lib/tosboot/stm25p/ExtFlashC.nc
tos/lib/tosboot/stm25p/ExtFlashM.nc [deleted file]
tos/lib/tosboot/stm25p/ExtFlashP.nc [new file with mode: 0644]

index 605bbbb40527e539f62684ee01276976dc442fff..cebcf9cb5b3922b9cf3f429f2c7e993bfb0e430b 100644 (file)
@@ -28,7 +28,7 @@
 # @author Jonathan Hui <jwhui@cs.berkeley.edu>
 #
 
-COMPONENT=TOSBoot
+COMPONENT=TosBootC
 TINYOS_NP=
 
 PFLAGS += -DNESC_BUILD_BINARY
diff --git a/tos/lib/tosboot/TOSBoot.h b/tos/lib/tosboot/TOSBoot.h
deleted file mode 100644 (file)
index d490a62..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __TOSBOOT_H__
-#define __TOSBOOT_H__
-
-#include "TOSBoot_platform.h"
-
-#endif
diff --git a/tos/lib/tosboot/TOSBoot.nc b/tos/lib/tosboot/TOSBoot.nc
deleted file mode 100644 (file)
index 9bd5c2b..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-includes Deluge;
-includes DelugePageTransfer;
-includes TOSBoot;
-
-configuration TOSBoot {
-}
-implementation {
-
-  components
-    TOSBootM,
-    ExecC,
-    ExtFlashC,
-    HardwareC,
-    InternalFlashC as IntFlash,
-    LedsC,
-    PluginC,
-    ProgFlashM as ProgFlash,
-    VoltageC;
-
-  TOSBootM.SubInit -> ExtFlashC;
-  TOSBootM.SubControl -> ExtFlashC.StdControl;
-  TOSBootM.SubControl -> PluginC;
-
-  TOSBootM.Exec -> ExecC;
-  TOSBootM.ExtFlash -> ExtFlashC;
-  TOSBootM.Hardware -> HardwareC;
-  TOSBootM.IntFlash -> IntFlash;
-  TOSBootM.Leds -> LedsC;
-  TOSBootM.ProgFlash -> ProgFlash;
-  TOSBootM.Voltage -> VoltageC;
-
-}
diff --git a/tos/lib/tosboot/TOSBootM.nc b/tos/lib/tosboot/TOSBootM.nc
deleted file mode 100644 (file)
index b24b176..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * "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."
- *
- * Copyright (c) 2007 Johns Hopkins University.
- * All rights reserved.
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
- * @author Razvan Musaloiu-E. <razvanm@cs.jhu.edu>
- */
-
-includes crc;
-includes hardware;
-
-module TOSBootM {
-  uses {
-    interface Exec;
-    interface ExtFlash;
-    interface Hardware;
-    interface InternalFlash as IntFlash;
-    interface Leds;
-    interface ProgFlash;
-    interface StdControl as SubControl;
-    interface Init as SubInit;
-    interface Voltage;
-  }
-}
-implementation {
-
-  enum {
-    LEDS_LOWBATT = 1,
-    LEDS_GESTURE = 7,
-  };
-
-  enum {
-    R_SUCCESS,
-    R_INVALID_IMAGE_ERROR,
-    R_PROGRAMMING_ERROR,
-  };
-
-  void startupLeds() {
-
-    uint8_t  output = 0x7;
-    uint8_t  i;
-
-    for (i = 3; i; i--, output >>= 1 )
-      call Leds.glow(output, output >> 1);
-
-  }
-
-  in_flash_addr_t extFlashReadAddr() {
-    in_flash_addr_t result = 0;
-    int8_t  i;
-    for ( i = 3; i >= 0; i-- )
-      result |= ((in_flash_addr_t)call ExtFlash.readByte() & 0xff) << (i*8);
-    return result;
-  }
-
-  bool verifyBlock(ex_flash_addr_t crcAddr, ex_flash_addr_t startAddr, uint16_t len)
-  {
-    uint16_t crcTarget, crcTmp;
-
-    // read crc
-    call ExtFlash.startRead(crcAddr);
-    crcTarget = (uint16_t)(call ExtFlash.readByte() & 0xff) << 8;
-    crcTarget |= (uint16_t)(call ExtFlash.readByte() & 0xff);
-    call ExtFlash.stopRead();
-
-    // compute crc
-    call ExtFlash.startRead(startAddr);
-    for ( crcTmp = 0; len; len-- )
-      crcTmp = crcByte(crcTmp, call ExtFlash.readByte());
-    call ExtFlash.stopRead();
-
-    return crcTarget == crcTmp;
-  }
-
-  bool verifyImage(ex_flash_addr_t startAddr) {
-    uint32_t addr;
-    uint8_t  numPgs;
-    uint8_t  i;
-
-
-    if (!verifyBlock(startAddr + offsetof(DelugeIdent,crc),
-                    startAddr, offsetof(DelugeIdent,crc)))
-      return FALSE;
-
-    // read size of image
-    call ExtFlash.startRead(startAddr + offsetof(DelugeIdent,numPgs));
-    numPgs = call ExtFlash.readByte();
-    call ExtFlash.stopRead();
-
-    if (numPgs == 0 || numPgs == 0xff)
-      return FALSE;
-
-    startAddr += DELUGE_IDENT_SIZE;
-    addr = DELUGE_CRC_BLOCK_SIZE;
-
-    for ( i = 0; i < numPgs; i++ ) {
-      if (!verifyBlock(startAddr + i*sizeof(uint16_t),
-                      startAddr + addr, DELUGE_BYTES_PER_PAGE)) {
-       return FALSE;
-      }
-      addr += DELUGE_BYTES_PER_PAGE;
-    }
-
-    return TRUE;
-  }
-
-  error_t programImage(ex_flash_addr_t startAddr) {
-    uint8_t  buf[TOSBOOT_INT_PAGE_SIZE];
-    uint32_t pageAddr, newPageAddr;
-    in_flash_addr_t intAddr;
-    in_flash_addr_t secLength;
-    ex_flash_addr_t curAddr;
-
-    if (!verifyImage(startAddr))
-      return R_INVALID_IMAGE_ERROR;
-
-    curAddr = startAddr + DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE;
-
-    call ExtFlash.startRead(curAddr);
-
-    intAddr = extFlashReadAddr();
-    secLength = extFlashReadAddr();
-    curAddr = curAddr + 8;
-
-#if defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC)
-    if (intAddr != TOSBOOT_END) {
-#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS)
-    if (intAddr != 0) {
-#elif defined(PLATFORM_MULLE)
-    if (intAddr != 0xA0000) {
-#else
-  #error "Target platform is not currently supported by Deluge T2"
-#endif
-      call ExtFlash.stopRead();
-      return R_INVALID_IMAGE_ERROR;
-    }
-
-    call ExtFlash.stopRead();
-
-    while ( secLength ) {
-
-      pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
-
-      call ExtFlash.startRead(curAddr);
-      // fill in ram buffer for internal program flash sector
-      do {
-
-       // check if secLength is all ones
-       if ( secLength == 0xffffffff ) {
-         call ExtFlash.stopRead();
-         return FAIL;
-       }
-
-       buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte();
-       intAddr++; curAddr++;
-
-       if ( --secLength == 0 ) {
-         intAddr = extFlashReadAddr();
-         secLength = extFlashReadAddr();
-         curAddr = curAddr + 8;
-       }
-
-       newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
-
-      } while ( pageAddr == newPageAddr && secLength );
-      call ExtFlash.stopRead();
-
-      call Leds.set(pageAddr);
-
-      // write out page
-      if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf,
-                              TOSBOOT_INT_PAGE_SIZE) == FAIL) {
-       return R_PROGRAMMING_ERROR;
-      }
-    }
-
-    return R_SUCCESS;
-
-  }
-
-  void runApp() {
-    call SubControl.stop();
-    call Exec.exec();
-  }
-
-  void startupSequence() {
-
-    BootArgs args;
-
-    // check voltage and make sure flash can be programmed
-    //   if not, just run the app, can't check for gestures
-    //   if we can't write to the internal flash anyway
-    if ( !call Voltage.okToProgram() ) {
-      // give user some time and count down LEDs
-      call Leds.flash(LEDS_LOWBATT);
-      startupLeds();
-      runApp();
-    }
-
-    // get current value of counter
-    call IntFlash.read((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
-
-    // increment gesture counter, see if it exceeds threshold
-    if ( ++args.gestureCount >= TOSBOOT_GESTURE_MAX_COUNT - 1 ) {
-      // gesture has been detected, display receipt of gesture on LEDs
-      call Leds.flash(LEDS_GESTURE);
-
-      // load golden image from flash
-      // if the golden image is invalid, forget about reprogramming
-      // if an error happened during reprogramming, reboot and try again
-      //   not much else we can do :-/
-      if (programImage(TOSBOOT_GOLDEN_IMG_ADDR) == R_PROGRAMMING_ERROR) {
-       call Hardware.reboot();
-      }
-    }
-    else {
-      // update gesture counter
-      call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
-      if ( !args.noReprogram ) {
-       // if an error happened during reprogramming, reboot and try again
-       //   after two tries, try programming the golden image
-       if (programImage(args.imageAddr) == R_PROGRAMMING_ERROR) {
-         call Hardware.reboot();
-       }
-      }
-    }
-
-    // give user some time and count down LEDs
-    startupLeds();
-
-    // reset counter and reprogramming flag
-    args.gestureCount = 0xff;
-    args.noReprogram = TRUE;
-    call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
-
-    runApp();
-
-  }
-
-  int main() @C() @spontaneous() {
-
-    __nesc_disable_interrupt();
-
-    TOSH_SET_PIN_DIRECTIONS();
-    call Hardware.init();
-
-    call SubInit.init();
-    call SubControl.start();
-
-    startupSequence();
-
-    return 0;
-
-  }
-
-}
diff --git a/tos/lib/tosboot/TosBoot.h b/tos/lib/tosboot/TosBoot.h
new file mode 100644 (file)
index 0000000..d490a62
--- /dev/null
@@ -0,0 +1,33 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __TOSBOOT_H__
+#define __TOSBOOT_H__
+
+#include "TOSBoot_platform.h"
+
+#endif
diff --git a/tos/lib/tosboot/TosBootC.nc b/tos/lib/tosboot/TosBootC.nc
new file mode 100644 (file)
index 0000000..8317250
--- /dev/null
@@ -0,0 +1,62 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+#include <Deluge.h>
+#include <DelugePageTransfer.h>
+#include "TosBoot.h"
+
+configuration TosBootC {
+}
+implementation {
+
+  components
+    TosBootP,
+    ExecC,
+    ExtFlashC,
+    HardwareC,
+    InternalFlashC as IntFlash,
+    LedsC,
+    PluginC,
+    ProgFlashC as ProgFlash,
+    VoltageC;
+
+  TosBootP.SubInit -> ExtFlashC;
+  TosBootP.SubControl -> ExtFlashC.StdControl;
+  TosBootP.SubControl -> PluginC;
+
+  TosBootP.Exec -> ExecC;
+  TosBootP.ExtFlash -> ExtFlashC;
+  TosBootP.Hardware -> HardwareC;
+  TosBootP.IntFlash -> IntFlash;
+  TosBootP.Leds -> LedsC;
+  TosBootP.ProgFlash -> ProgFlash;
+  TosBootP.Voltage -> VoltageC;
+
+}
diff --git a/tos/lib/tosboot/TosBootP.nc b/tos/lib/tosboot/TosBootP.nc
new file mode 100644 (file)
index 0000000..9340772
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * "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."
+ *
+ * Copyright (c) 2007 Johns Hopkins University.
+ * All rights reserved.
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ * @author Razvan Musaloiu-E. <razvanm@cs.jhu.edu>
+ */
+
+#include "crc.h"
+#include <hardware.h>
+
+module TosBootP {
+  uses {
+    interface Exec;
+    interface ExtFlash;
+    interface Hardware;
+    interface InternalFlash as IntFlash;
+    interface Leds;
+    interface ProgFlash;
+    interface StdControl as SubControl;
+    interface Init as SubInit;
+    interface Voltage;
+  }
+}
+implementation {
+
+  enum {
+    LEDS_LOWBATT = 1,
+    LEDS_GESTURE = 7,
+  };
+
+  enum {
+    R_SUCCESS,
+    R_INVALID_IMAGE_ERROR,
+    R_PROGRAMMING_ERROR,
+  };
+
+  void startupLeds() {
+
+    uint8_t  output = 0x7;
+    uint8_t  i;
+
+    for (i = 3; i; i--, output >>= 1 )
+      call Leds.glow(output, output >> 1);
+
+  }
+
+  in_flash_addr_t extFlashReadAddr() {
+    in_flash_addr_t result = 0;
+    int8_t  i;
+    for ( i = 3; i >= 0; i-- )
+      result |= ((in_flash_addr_t)call ExtFlash.readByte() & 0xff) << (i*8);
+    return result;
+  }
+
+  bool verifyBlock(ex_flash_addr_t crcAddr, ex_flash_addr_t startAddr, uint16_t len)
+  {
+    uint16_t crcTarget, crcTmp;
+
+    // read crc
+    call ExtFlash.startRead(crcAddr);
+    crcTarget = (uint16_t)(call ExtFlash.readByte() & 0xff) << 8;
+    crcTarget |= (uint16_t)(call ExtFlash.readByte() & 0xff);
+    call ExtFlash.stopRead();
+
+    // compute crc
+    call ExtFlash.startRead(startAddr);
+    for ( crcTmp = 0; len; len-- )
+      crcTmp = crcByte(crcTmp, call ExtFlash.readByte());
+    call ExtFlash.stopRead();
+
+    return crcTarget == crcTmp;
+  }
+
+  bool verifyImage(ex_flash_addr_t startAddr) {
+    uint32_t addr;
+    uint8_t  numPgs;
+    uint8_t  i;
+
+
+    if (!verifyBlock(startAddr + offsetof(DelugeIdent,crc),
+                    startAddr, offsetof(DelugeIdent,crc)))
+      return FALSE;
+
+    // read size of image
+    call ExtFlash.startRead(startAddr + offsetof(DelugeIdent,numPgs));
+    numPgs = call ExtFlash.readByte();
+    call ExtFlash.stopRead();
+
+    if (numPgs == 0 || numPgs == 0xff)
+      return FALSE;
+
+    startAddr += DELUGE_IDENT_SIZE;
+    addr = DELUGE_CRC_BLOCK_SIZE;
+
+    for ( i = 0; i < numPgs; i++ ) {
+      if (!verifyBlock(startAddr + i*sizeof(uint16_t),
+                      startAddr + addr, DELUGE_BYTES_PER_PAGE)) {
+       return FALSE;
+      }
+      addr += DELUGE_BYTES_PER_PAGE;
+    }
+
+    return TRUE;
+  }
+
+  error_t programImage(ex_flash_addr_t startAddr) {
+    uint8_t  buf[TOSBOOT_INT_PAGE_SIZE];
+    uint32_t pageAddr, newPageAddr;
+    in_flash_addr_t intAddr;
+    in_flash_addr_t secLength;
+    ex_flash_addr_t curAddr;
+
+    if (!verifyImage(startAddr))
+      return R_INVALID_IMAGE_ERROR;
+
+    curAddr = startAddr + DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE;
+
+    call ExtFlash.startRead(curAddr);
+
+    intAddr = extFlashReadAddr();
+    secLength = extFlashReadAddr();
+    curAddr = curAddr + 8;
+
+#if defined(PLATFORM_TELOSB) || defined (PLATFORM_EPIC)
+    if (intAddr != TOSBOOT_END) {
+#elif defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS)
+    if (intAddr != 0) {
+#elif defined(PLATFORM_MULLE)
+    if (intAddr != 0xA0000) {
+#else
+  #error "Target platform is not currently supported by Deluge T2"
+#endif
+      call ExtFlash.stopRead();
+      return R_INVALID_IMAGE_ERROR;
+    }
+
+    call ExtFlash.stopRead();
+
+    while ( secLength ) {
+
+      pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
+
+      call ExtFlash.startRead(curAddr);
+      // fill in ram buffer for internal program flash sector
+      do {
+
+       // check if secLength is all ones
+       if ( secLength == 0xffffffff ) {
+         call ExtFlash.stopRead();
+         return FAIL;
+       }
+
+       buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte();
+       intAddr++; curAddr++;
+
+       if ( --secLength == 0 ) {
+         intAddr = extFlashReadAddr();
+         secLength = extFlashReadAddr();
+         curAddr = curAddr + 8;
+       }
+
+       newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
+
+      } while ( pageAddr == newPageAddr && secLength );
+      call ExtFlash.stopRead();
+
+      call Leds.set(pageAddr);
+
+      // write out page
+      if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf,
+                              TOSBOOT_INT_PAGE_SIZE) == FAIL) {
+       return R_PROGRAMMING_ERROR;
+      }
+    }
+
+    return R_SUCCESS;
+
+  }
+
+  void runApp() {
+    call SubControl.stop();
+    call Exec.exec();
+  }
+
+  void startupSequence() {
+
+    BootArgs args;
+
+    // check voltage and make sure flash can be programmed
+    //   if not, just run the app, can't check for gestures
+    //   if we can't write to the internal flash anyway
+    if ( !call Voltage.okToProgram() ) {
+      // give user some time and count down LEDs
+      call Leds.flash(LEDS_LOWBATT);
+      startupLeds();
+      runApp();
+    }
+
+    // get current value of counter
+    call IntFlash.read((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
+
+    // increment gesture counter, see if it exceeds threshold
+    if ( ++args.gestureCount >= TOSBOOT_GESTURE_MAX_COUNT - 1 ) {
+      // gesture has been detected, display receipt of gesture on LEDs
+      call Leds.flash(LEDS_GESTURE);
+
+      // load golden image from flash
+      // if the golden image is invalid, forget about reprogramming
+      // if an error happened during reprogramming, reboot and try again
+      //   not much else we can do :-/
+      if (programImage(TOSBOOT_GOLDEN_IMG_ADDR) == R_PROGRAMMING_ERROR) {
+       call Hardware.reboot();
+      }
+    }
+    else {
+      // update gesture counter
+      call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
+      if ( !args.noReprogram ) {
+       // if an error happened during reprogramming, reboot and try again
+       //   after two tries, try programming the golden image
+       if (programImage(args.imageAddr) == R_PROGRAMMING_ERROR) {
+         call Hardware.reboot();
+       }
+      }
+    }
+
+    // give user some time and count down LEDs
+    startupLeds();
+
+    // reset counter and reprogramming flag
+    args.gestureCount = 0xff;
+    args.noReprogram = TRUE;
+    call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
+
+    runApp();
+
+  }
+
+  int main() @C() @spontaneous() {
+
+    __nesc_disable_interrupt();
+
+    TOSH_SET_PIN_DIRECTIONS();
+    call Hardware.init();
+
+    call SubInit.init();
+    call SubControl.start();
+
+    startupSequence();
+
+    return 0;
+
+  }
+
+}
index 558f24266024e77eb23037b4e3382d94a47c174f..3b8803eb44c6ba3dbfede3dd346b2040017bd2ca 100644 (file)
@@ -28,7 +28,7 @@
  * @author Jonathan Hui <jwhui@cs.berkeley.edu>
  */
 
-includes InternalFlash;
+#include <InternalFlash.h>
 
 module InternalFlashC {
   provides interface InternalFlash;
diff --git a/tos/lib/tosboot/avr/ProgFlashC.nc b/tos/lib/tosboot/avr/ProgFlashC.nc
new file mode 100644 (file)
index 0000000..a3796ee
--- /dev/null
@@ -0,0 +1,65 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+module ProgFlashC {
+  provides {
+    interface ProgFlash;
+  }
+}
+
+implementation {
+
+#include <avr/boot.h>
+
+  command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) {
+
+    uint16_t* wordBuf = (uint16_t*)buf;
+    uint32_t i;
+
+    if ( addr + len > TOSBOOT_START )
+      return FAIL;    
+
+    boot_page_erase_safe( addr );
+    while( boot_rww_busy() )
+      boot_rww_enable_safe();
+    
+    for ( i = 0; i < len; i += 2 )
+      boot_page_fill_safe( addr + i, *wordBuf++ );
+
+    boot_page_write_safe( addr );
+    
+    while ( boot_rww_busy() )
+      boot_rww_enable_safe();
+    
+    return SUCCESS;
+    
+  }
+
+}
diff --git a/tos/lib/tosboot/avr/ProgFlashM.nc b/tos/lib/tosboot/avr/ProgFlashM.nc
deleted file mode 100644 (file)
index 898ebc6..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-module ProgFlashM {
-  provides {
-    interface ProgFlash;
-  }
-}
-
-implementation {
-
-#include <avr/boot.h>
-
-  command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) {
-
-    uint16_t* wordBuf = (uint16_t*)buf;
-    uint32_t i;
-
-    if ( addr + len > TOSBOOT_START )
-      return FAIL;    
-
-    boot_page_erase_safe( addr );
-    while( boot_rww_busy() )
-      boot_rww_enable_safe();
-    
-    for ( i = 0; i < len; i += 2 )
-      boot_page_fill_safe( addr + i, *wordBuf++ );
-
-    boot_page_write_safe( addr );
-    
-    while ( boot_rww_busy() )
-      boot_rww_enable_safe();
-    
-    return SUCCESS;
-    
-  }
-
-}
index 9f7d5347d81edba56debc8bc18fdf6ef2453db41..34ada4e1008db21374c2b154f607b5563ec60fa3 100644 (file)
@@ -39,13 +39,13 @@ configuration ExtFlashC {
 implementation {
 
   components 
-    ExtFlashM,
-    HPLUSART0M;
+    ExtFlashP,
+    HplUsart0C;
 
-  Init = ExtFlashM;
-  StdControl = ExtFlashM;
-  ExtFlash = ExtFlashM;
+  Init = ExtFlashP;
+  StdControl = ExtFlashP;
+  ExtFlash = ExtFlashP;
 
-  ExtFlashM.USARTControl -> HPLUSART0M;
+  ExtFlashP.UsartControl -> HplUsart0C;
 
 }
diff --git a/tos/lib/tosboot/epic/ExtFlashM.nc b/tos/lib/tosboot/epic/ExtFlashM.nc
deleted file mode 100644 (file)
index a80ecab..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- * @author Razvan Musaloiu-E. <razvanm@cs.jhu.edu>
- */
-
-module ExtFlashM {
-  provides {
-    interface StdControl;
-    interface Init;
-    interface ExtFlash;
-  }
-  uses {
-    interface HPLUSARTControl as USARTControl;
-  }
-}
-
-implementation {
-
-  uint32_t addr;
-
-  command error_t Init.init() {
-    TOSH_MAKE_FLASH_CS_OUTPUT();
-    TOSH_SET_FLASH_CS_PIN();
-    call USARTControl.setModeSPI();
-    return SUCCESS;
-  }
-
-  command error_t StdControl.start() { 
-    return SUCCESS; 
-  }
-
-  command error_t StdControl.stop() { 
-    call USARTControl.disableSPI();
-    return SUCCESS; 
-  }
-
-  command void ExtFlash.startRead(uint32_t newAddr) {
-
-    uint8_t cmd[4];
-    uint8_t i;
-    uint32_t page = newAddr / 512;
-    uint32_t offset = newAddr % 512;
-
-    addr = newAddr;
-
-    cmd[0] = 0x03;
-    cmd[1] = page >> 6;
-    cmd[2] = (page << 2) | (offset >> 8);
-    cmd[3] = offset;
-
-    TOSH_CLR_FLASH_CS_PIN();
-
-    for ( i = 0; i < sizeof(cmd); i++ ) {
-      call USARTControl.tx(cmd[i]);
-      while(call USARTControl.isTxEmpty() != SUCCESS);
-    }
-  }
-
-  command uint8_t ExtFlash.readByte() {
-    if (!(addr & 0x1ff)) {
-      call ExtFlash.stopRead();
-      call ExtFlash.startRead(addr);
-    }
-    addr++;
-    call USARTControl.rx();
-    call USARTControl.tx(0);
-    while(call USARTControl.isRxIntrPending() != SUCCESS);
-    return call USARTControl.rx();
-  }
-
-  command void ExtFlash.stopRead() {
-    TOSH_SET_FLASH_CS_PIN();
-  }
-
-}
diff --git a/tos/lib/tosboot/epic/ExtFlashP.nc b/tos/lib/tosboot/epic/ExtFlashP.nc
new file mode 100644 (file)
index 0000000..621ead1
--- /dev/null
@@ -0,0 +1,98 @@
+// $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 <jwhui@cs.berkeley.edu>
+ * @author Razvan Musaloiu-E. <razvanm@cs.jhu.edu>
+ */
+
+module ExtFlashP {
+  provides {
+    interface StdControl;
+    interface Init;
+    interface ExtFlash;
+  }
+  uses {
+    interface HplUsartControl as UsartControl;
+  }
+}
+
+implementation {
+
+  uint32_t addr;
+
+  command error_t Init.init() {
+    TOSH_MAKE_FLASH_CS_OUTPUT();
+    TOSH_SET_FLASH_CS_PIN();
+    call UsartControl.setModeSPI();
+    return SUCCESS;
+  }
+
+  command error_t StdControl.start() { 
+    return SUCCESS; 
+  }
+
+  command error_t StdControl.stop() { 
+    call UsartControl.disableSPI();
+    return SUCCESS; 
+  }
+
+  command void ExtFlash.startRead(uint32_t newAddr) {
+
+    uint8_t cmd[4];
+    uint8_t i;
+    uint32_t page = newAddr / 512;
+    uint32_t offset = newAddr % 512;
+
+    addr = newAddr;
+
+    cmd[0] = 0x03;
+    cmd[1] = page >> 6;
+    cmd[2] = (page << 2) | (offset >> 8);
+    cmd[3] = offset;
+
+    TOSH_CLR_FLASH_CS_PIN();
+
+    for ( i = 0; i < sizeof(cmd); i++ ) {
+      call UsartControl.tx(cmd[i]);
+      while(call UsartControl.isTxEmpty() != SUCCESS);
+    }
+  }
+
+  command uint8_t ExtFlash.readByte() {
+    if (!(addr & 0x1ff)) {
+      call ExtFlash.stopRead();
+      call ExtFlash.startRead(addr);
+    }
+    addr++;
+    call UsartControl.rx();
+    call UsartControl.tx(0);
+    while(call UsartControl.isRxIntrPending() != SUCCESS);
+    return call UsartControl.rx();
+  }
+
+  command void ExtFlash.stopRead() {
+    TOSH_SET_FLASH_CS_PIN();
+  }
+
+}
diff --git a/tos/lib/tosboot/iris/ProgFlashC.nc b/tos/lib/tosboot/iris/ProgFlashC.nc
new file mode 100644 (file)
index 0000000..3861a53
--- /dev/null
@@ -0,0 +1,65 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+#include <avr/boot.h>
+
+module ProgFlashC {
+  provides {
+    interface ProgFlash;
+  }
+}
+
+implementation {
+
+
+  command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) {
+
+    uint16_t* wordBuf = (uint16_t*)buf;
+    uint32_t i;
+
+    if ( addr + len > TOSBOOT_START )
+      return FAIL;
+
+    boot_page_erase( addr );
+    while( boot_rww_busy() )
+      boot_rww_enable();
+
+    for ( i = 0; i < len; i += 2 )
+      boot_page_fill( addr + i, *wordBuf++ );
+
+    boot_page_write( addr );
+
+    while ( boot_rww_busy() )
+      boot_rww_enable();
+
+    return SUCCESS;
+
+  }
+
+}
diff --git a/tos/lib/tosboot/iris/ProgFlashM.nc b/tos/lib/tosboot/iris/ProgFlashM.nc
deleted file mode 100644 (file)
index 34c6018..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-#include <avr/boot.h>
-
-module ProgFlashM {
-  provides {
-    interface ProgFlash;
-  }
-}
-
-implementation {
-
-
-  command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) {
-
-    uint16_t* wordBuf = (uint16_t*)buf;
-    uint32_t i;
-
-    if ( addr + len > TOSBOOT_START )
-      return FAIL;
-
-    boot_page_erase( addr );
-    while( boot_rww_busy() )
-      boot_rww_enable();
-
-    for ( i = 0; i < len; i += 2 )
-      boot_page_fill( addr + i, *wordBuf++ );
-
-    boot_page_write( addr );
-
-    while ( boot_rww_busy() )
-      boot_rww_enable();
-
-    return SUCCESS;
-
-  }
-
-}
diff --git a/tos/lib/tosboot/m16c62p/ProgFlashC.nc b/tos/lib/tosboot/m16c62p/ProgFlashC.nc
new file mode 100644 (file)
index 0000000..131171e
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009 Communication Group and Eislab at
+ * Lulea University of Technology
+ *
+ * Contact: Laurynas Riliskis, LTU
+ * Mail: laurynas.riliskis@ltu.se
+ * 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 Communication Group at Lulea University of Technology
+ *   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 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 STANFORD
+ * UNIVERSITY OR ITS 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.
+ */
+/**
+ * Wiring so that the ProgFlashP module gets access to the HplM16c62pFlashC
+ * module.
+ * 
+ * @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
+ */
+configuration ProgFlashC
+{
+  provides interface ProgFlash;
+}
+implementation
+{
+  components ProgFlashP, HplM16c62pFlashC;
+  
+  ProgFlashP.Flash -> HplM16c62pFlashC;
+  ProgFlash = ProgFlashP;
+}
\ No newline at end of file
diff --git a/tos/lib/tosboot/m16c62p/ProgFlashM.nc b/tos/lib/tosboot/m16c62p/ProgFlashM.nc
deleted file mode 100644 (file)
index 6466989..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2009 Communication Group and Eislab at
- * Lulea University of Technology
- *
- * Contact: Laurynas Riliskis, LTU
- * Mail: laurynas.riliskis@ltu.se
- * 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 Communication Group at Lulea University of Technology
- *   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 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 STANFORD
- * UNIVERSITY OR ITS 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.
- */
-/**
- * Wiring so that the ProgFlashP module gets access to the HplM16c62pFlashC
- * module.
- * 
- * @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
- */
-configuration ProgFlashM
-{
-  provides interface ProgFlash;
-}
-implementation
-{
-  components ProgFlashP, HplM16c62pFlashC;
-  
-  ProgFlashP.Flash -> HplM16c62pFlashC;
-  ProgFlash = ProgFlashP;
-}
\ No newline at end of file
diff --git a/tos/lib/tosboot/msp430/HPLUSART0M.nc b/tos/lib/tosboot/msp430/HPLUSART0M.nc
deleted file mode 100644 (file)
index 34e4422..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-module HPLUSART0M {
-  provides interface HPLUSARTControl;
-}
-implementation {
-
-  command void HPLUSARTControl.disableSPI() {
-    // USART0 SPI module disable
-    //ME1 &= ~USPIE0;
-
-    // set to PUC values
-    ME1 = 0;
-    U0CTL = 1;
-    U0TCTL = 1;
-    U0RCTL = 0;
-  }
-  
-  command void HPLUSARTControl.setModeSPI() {
-
-    //U0CTL = SWRST;
-
-    // 8-bit char, SPI-mode, USART as master
-    U0CTL = SWRST | CHAR | SYNC | MM;
-
-    // 3-pin + half-cycle delayed UCLK
-    U0TCTL |= STC + CKPH + SSEL_SMCLK; 
-
-    // as fast as possible
-    U0BR0 = 0x02;
-    U0BR1 = 0;
-
-    // enable SPI
-    ME1 |= USPIE0;
-
-    U0CTL &= ~SWRST;  
-    
-    // clear interrupts
-    IFG1 = 0;
-
-  }
-
-  command void HPLUSARTControl.disableI2C() {
-    /*
-    U0CTL = 1;
-    U0TCTL = 1;
-    I2CTCTL = 0;
-    */
-    U0CTL &= ~I2CEN;
-    U0CTL &= ~I2C;
-    I2CTCTL = 0;
-    call HPLUSARTControl.disableSPI();
-  }
-
-  command void HPLUSARTControl.setModeI2C() {
-   
-    // Recommended init procedure
-    U0CTL = I2C + SYNC + MST;
-
-    // use 1MHz SMCLK as the I2C reference
-    I2CTCTL |= I2CSSEL_2 | I2CTRX;
-
-    // Enable I2C
-    U0CTL |= I2CEN;
-
-    return;
-  }
-
-  command error_t HPLUSARTControl.isTxEmpty(){
-    if (U0TCTL & TXEPT) {
-      return SUCCESS;
-    }
-    return FAIL;
-  }
-  
-  command error_t HPLUSARTControl.isTxIntrPending(){
-    if (IFG1 & UTXIFG0){
-      IFG1 &= ~UTXIFG0;
-      return SUCCESS;
-    }
-    return FAIL;
-  }
-
-  command error_t HPLUSARTControl.isRxIntrPending(){
-    if (IFG1 & URXIFG0){
-      IFG1 &= ~URXIFG0;
-      return SUCCESS;
-    }
-    return FAIL;
-  }
-
-  command void HPLUSARTControl.tx(uint8_t data){
-    U0TXBUF = data;
-  }
-  
-  command uint8_t HPLUSARTControl.rx(){
-    return U0RXBUF;
-  }
-
-}
diff --git a/tos/lib/tosboot/msp430/HPLUSARTControl.nc b/tos/lib/tosboot/msp430/HPLUSARTControl.nc
deleted file mode 100644 (file)
index c0254b1..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-includes msp430usart;
-
-interface HPLUSARTControl {
-
-  command void disableSPI();
-  command void setModeSPI();
-  command void disableI2C();
-  command void setModeI2C();
-  command error_t isTxEmpty();
-  command error_t isTxIntrPending();
-  command error_t isRxIntrPending();
-  command void tx(uint8_t data);
-  command uint8_t rx();
-
-}
-
diff --git a/tos/lib/tosboot/msp430/HplUsart0C.nc b/tos/lib/tosboot/msp430/HplUsart0C.nc
new file mode 100644 (file)
index 0000000..e47ec50
--- /dev/null
@@ -0,0 +1,128 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+module HplUsart0C {
+  provides interface HplUsartControl;
+}
+implementation {
+
+  command void HplUsartControl.disableSPI() {
+    // USART0 SPI module disable
+    //ME1 &= ~USPIE0;
+
+    // set to PUC values
+    ME1 = 0;
+    U0CTL = 1;
+    U0TCTL = 1;
+    U0RCTL = 0;
+  }
+  
+  command void HplUsartControl.setModeSPI() {
+
+    //U0CTL = SWRST;
+
+    // 8-bit char, SPI-mode, USART as master
+    U0CTL = SWRST | CHAR | SYNC | MM;
+
+    // 3-pin + half-cycle delayed UCLK
+    U0TCTL |= STC + CKPH + SSEL_SMCLK; 
+
+    // as fast as possible
+    U0BR0 = 0x02;
+    U0BR1 = 0;
+
+    // enable SPI
+    ME1 |= USPIE0;
+
+    U0CTL &= ~SWRST;  
+    
+    // clear interrupts
+    IFG1 = 0;
+
+  }
+
+  command void HplUsartControl.disableI2C() {
+    /*
+    U0CTL = 1;
+    U0TCTL = 1;
+    I2CTCTL = 0;
+    */
+    U0CTL &= ~I2CEN;
+    U0CTL &= ~I2C;
+    I2CTCTL = 0;
+    call HplUsartControl.disableSPI();
+  }
+
+  command void HplUsartControl.setModeI2C() {
+   
+    // Recommended init procedure
+    U0CTL = I2C + SYNC + MST;
+
+    // use 1MHz SMCLK as the I2C reference
+    I2CTCTL |= I2CSSEL_2 | I2CTRX;
+
+    // Enable I2C
+    U0CTL |= I2CEN;
+
+    return;
+  }
+
+  command error_t HplUsartControl.isTxEmpty(){
+    if (U0TCTL & TXEPT) {
+      return SUCCESS;
+    }
+    return FAIL;
+  }
+  
+  command error_t HplUsartControl.isTxIntrPending(){
+    if (IFG1 & UTXIFG0){
+      IFG1 &= ~UTXIFG0;
+      return SUCCESS;
+    }
+    return FAIL;
+  }
+
+  command error_t HplUsartControl.isRxIntrPending(){
+    if (IFG1 & URXIFG0){
+      IFG1 &= ~URXIFG0;
+      return SUCCESS;
+    }
+    return FAIL;
+  }
+
+  command void HplUsartControl.tx(uint8_t data){
+    U0TXBUF = data;
+  }
+  
+  command uint8_t HplUsartControl.rx(){
+    return U0RXBUF;
+  }
+
+}
diff --git a/tos/lib/tosboot/msp430/HplUsartControl.nc b/tos/lib/tosboot/msp430/HplUsartControl.nc
new file mode 100644 (file)
index 0000000..02feb35
--- /dev/null
@@ -0,0 +1,46 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+#include <msp430usart.h>
+
+interface HplUsartControl {
+
+  command void disableSPI();
+  command void setModeSPI();
+  command void disableI2C();
+  command void setModeI2C();
+  command error_t isTxEmpty();
+  command error_t isTxIntrPending();
+  command error_t isRxIntrPending();
+  command void tx(uint8_t data);
+  command uint8_t rx();
+
+}
+
diff --git a/tos/lib/tosboot/msp430/ProgFlashC.nc b/tos/lib/tosboot/msp430/ProgFlashC.nc
new file mode 100644 (file)
index 0000000..2c87c6f
--- /dev/null
@@ -0,0 +1,70 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+module ProgFlashC {
+  provides {
+    interface ProgFlash;
+  }
+}
+
+implementation {
+
+  enum {
+    RESET_ADDR = 0xfffe,
+  };
+
+  command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, uint16_t len) {
+
+    volatile uint16_t *flashAddr = (uint16_t*)(uint16_t)addr;
+    uint16_t *wordBuf = (uint16_t*)buf;
+    uint16_t i = 0;
+
+    // len is 16 bits so it can't be larger than 0xffff
+    // make sure we can't wrap around
+    if (addr < (0xffff - (len >> 1))) {
+      FCTL2 = FWKEY + FSSEL1 + FN2;
+      FCTL3 = FWKEY;
+      FCTL1 = FWKEY + ERASE;
+      *flashAddr = 0;
+      FCTL1 = FWKEY + WRT;
+      for (i = 0; i < (len >> 1); i++, flashAddr++) {
+       if ((uint16_t)flashAddr != RESET_ADDR)
+         *flashAddr = wordBuf[i];
+       else
+         *flashAddr = TOSBOOT_START;
+      }
+      FCTL1 = FWKEY;
+      FCTL3 = FWKEY + LOCK;
+      return SUCCESS;
+    }
+    return FAIL;
+  }
+
+}
diff --git a/tos/lib/tosboot/msp430/ProgFlashM.nc b/tos/lib/tosboot/msp430/ProgFlashM.nc
deleted file mode 100644 (file)
index aa0adcc..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-module ProgFlashM {
-  provides {
-    interface ProgFlash;
-  }
-}
-
-implementation {
-
-  enum {
-    RESET_ADDR = 0xfffe,
-  };
-
-  command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, uint16_t len) {
-
-    volatile uint16_t *flashAddr = (uint16_t*)(uint16_t)addr;
-    uint16_t *wordBuf = (uint16_t*)buf;
-    uint16_t i = 0;
-
-    // len is 16 bits so it can't be larger than 0xffff
-    // make sure we can't wrap around
-    if (addr < (0xffff - (len >> 1))) {
-      FCTL2 = FWKEY + FSSEL1 + FN2;
-      FCTL3 = FWKEY;
-      FCTL1 = FWKEY + ERASE;
-      *flashAddr = 0;
-      FCTL1 = FWKEY + WRT;
-      for (i = 0; i < (len >> 1); i++, flashAddr++) {
-       if ((uint16_t)flashAddr != RESET_ADDR)
-         *flashAddr = wordBuf[i];
-       else
-         *flashAddr = TOSBOOT_START;
-      }
-      FCTL1 = FWKEY;
-      FCTL3 = FWKEY + LOCK;
-      return SUCCESS;
-    }
-    return FAIL;
-  }
-
-}
index 860b2486282b6c230716d6c069c3721048f56e3e..738bcae58ca62af5f864b5f09589fe0f4f98bd9e 100644 (file)
@@ -36,11 +36,11 @@ configuration PluginC {
 
 implementation {
 
-  components ExtFlashC, LedsC, PowerOffM;
+  components ExtFlashC, LedsC, PowerOffC;
 
-  StdControl = PowerOffM;
+  StdControl = PowerOffC;
 
-  PowerOffM.Leds -> LedsC;
-  PowerOffM.SubControl -> ExtFlashC;
+  PowerOffC.Leds -> LedsC;
+  PowerOffC.SubControl -> ExtFlashC;
 
 }
diff --git a/tos/lib/tosboot/msp430f1611/PowerOffC.nc b/tos/lib/tosboot/msp430f1611/PowerOffC.nc
new file mode 100644 (file)
index 0000000..e998cc3
--- /dev/null
@@ -0,0 +1,85 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+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);
+
+    // 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/msp430f1611/PowerOffM.nc b/tos/lib/tosboot/msp430f1611/PowerOffM.nc
deleted file mode 100644 (file)
index 94d8dc3..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-module PowerOffM {
-  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);
-
-    // if user button is pressed, power down
-    if (!TOSH_READ_USERINT_PIN())
-      haltsystem();
-
-    return SUCCESS;
-
-  }
-
-  command error_t StdControl.stop() {
-    return SUCCESS;
-  }
-
-}
index 9f7d5347d81edba56debc8bc18fdf6ef2453db41..34ada4e1008db21374c2b154f607b5563ec60fa3 100644 (file)
@@ -39,13 +39,13 @@ configuration ExtFlashC {
 implementation {
 
   components 
-    ExtFlashM,
-    HPLUSART0M;
+    ExtFlashP,
+    HplUsart0C;
 
-  Init = ExtFlashM;
-  StdControl = ExtFlashM;
-  ExtFlash = ExtFlashM;
+  Init = ExtFlashP;
+  StdControl = ExtFlashP;
+  ExtFlash = ExtFlashP;
 
-  ExtFlashM.USARTControl -> HPLUSART0M;
+  ExtFlashP.UsartControl -> HplUsart0C;
 
 }
diff --git a/tos/lib/tosboot/stm25p/ExtFlashM.nc b/tos/lib/tosboot/stm25p/ExtFlashM.nc
deleted file mode 100644 (file)
index b9909b2..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-// $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 <jwhui@cs.berkeley.edu>
- */
-
-module ExtFlashM {
-  provides {
-    interface StdControl;
-    interface Init;
-    interface ExtFlash;
-  }
-  uses {
-    interface HPLUSARTControl as USARTControl;
-  }
-}
-
-implementation {
-
-  command error_t Init.init() {
-    TOSH_MAKE_FLASH_HOLD_OUTPUT();
-    TOSH_MAKE_FLASH_CS_OUTPUT();
-    TOSH_SET_FLASH_HOLD_PIN();
-    call USARTControl.setModeSPI();
-    return SUCCESS;
-  }
-
-  command error_t StdControl.start() { 
-    return SUCCESS; 
-  }
-
-  command error_t StdControl.stop() { 
-
-    TOSH_CLR_FLASH_CS_PIN();
-    
-    call USARTControl.tx(0xb9);
-    while(call USARTControl.isTxEmpty() != SUCCESS);
-
-    TOSH_SET_FLASH_CS_PIN();
-
-    call USARTControl.disableSPI();
-
-    return SUCCESS; 
-
-  }
-
-  void powerOnFlash() {
-
-    uint8_t i;
-
-    TOSH_CLR_FLASH_CS_PIN();
-
-    // command byte + 3 dummy bytes + signature
-    for ( i = 0; i < 5; i++ ) {
-      call USARTControl.tx(0xab);
-      while(call USARTControl.isTxIntrPending() != SUCCESS);
-    }
-    
-    TOSH_SET_FLASH_CS_PIN();
-
-  }
-
-  command void ExtFlash.startRead(uint32_t addr) {
-
-    uint8_t i;
-    
-    powerOnFlash();
-    
-    TOSH_CLR_FLASH_CS_PIN();
-    
-    // add command byte to address
-    addr |= (uint32_t)0x3 << 24;
-
-    // address
-    for ( i = 4; i > 0; i-- ) {
-      call USARTControl.tx((addr >> (i-1)*8) & 0xff);
-      while(call USARTControl.isTxIntrPending() != SUCCESS);
-    }    
-
-  }
-
-  command uint8_t ExtFlash.readByte() {
-    call USARTControl.rx();
-    call USARTControl.tx(0);
-    while(call USARTControl.isRxIntrPending() != SUCCESS);
-    return call USARTControl.rx();
-  }
-
-  command void ExtFlash.stopRead() {
-    TOSH_SET_FLASH_CS_PIN();
-  }
-
-}
diff --git a/tos/lib/tosboot/stm25p/ExtFlashP.nc b/tos/lib/tosboot/stm25p/ExtFlashP.nc
new file mode 100644 (file)
index 0000000..f1a6217
--- /dev/null
@@ -0,0 +1,114 @@
+// $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 <jwhui@cs.berkeley.edu>
+ */
+
+module ExtFlashP {
+  provides {
+    interface StdControl;
+    interface Init;
+    interface ExtFlash;
+  }
+  uses {
+    interface HplUsartControl as UsartControl;
+  }
+}
+
+implementation {
+
+  command error_t Init.init() {
+    TOSH_MAKE_FLASH_HOLD_OUTPUT();
+    TOSH_MAKE_FLASH_CS_OUTPUT();
+    TOSH_SET_FLASH_HOLD_PIN();
+    call UsartControl.setModeSPI();
+    return SUCCESS;
+  }
+
+  command error_t StdControl.start() { 
+    return SUCCESS; 
+  }
+
+  command error_t StdControl.stop() { 
+
+    TOSH_CLR_FLASH_CS_PIN();
+    
+    call UsartControl.tx(0xb9);
+    while(call UsartControl.isTxEmpty() != SUCCESS);
+
+    TOSH_SET_FLASH_CS_PIN();
+
+    call UsartControl.disableSPI();
+
+    return SUCCESS; 
+
+  }
+
+  void powerOnFlash() {
+
+    uint8_t i;
+
+    TOSH_CLR_FLASH_CS_PIN();
+
+    // command byte + 3 dummy bytes + signature
+    for ( i = 0; i < 5; i++ ) {
+      call UsartControl.tx(0xab);
+      while(call UsartControl.isTxIntrPending() != SUCCESS);
+    }
+    
+    TOSH_SET_FLASH_CS_PIN();
+
+  }
+
+  command void ExtFlash.startRead(uint32_t addr) {
+
+    uint8_t i;
+    
+    powerOnFlash();
+    
+    TOSH_CLR_FLASH_CS_PIN();
+    
+    // add command byte to address
+    addr |= (uint32_t)0x3 << 24;
+
+    // address
+    for ( i = 4; i > 0; i-- ) {
+      call UsartControl.tx((addr >> (i-1)*8) & 0xff);
+      while(call UsartControl.isTxIntrPending() != SUCCESS);
+    }    
+
+  }
+
+  command uint8_t ExtFlash.readByte() {
+    call UsartControl.rx();
+    call UsartControl.tx(0);
+    while(call UsartControl.isRxIntrPending() != SUCCESS);
+    return call UsartControl.rx();
+  }
+
+  command void ExtFlash.stopRead() {
+    TOSH_SET_FLASH_CS_PIN();
+  }
+
+}