[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/Deluge Deluge.h, 1.2, 1.3 DelugeC.nc, 1.1, 1.2 DelugeDataRead.nc, 1.1, 1.2 DelugeDataWrite.nc, 1.1, 1.2 DelugeM.nc, 1.2, 1.3 DelugeMetadata.h, 1.1, 1.2 DelugeMetadata.nc, 1.1, 1.2 DelugeMetadataC.nc, 1.1, 1.2 DelugeMetadataM.nc, 1.2, 1.3 DelugeMetadataRead.nc, 1.1, 1.2 DelugeMetadataWrite.nc, 1.1, 1.2 DelugeMsgs.h, 1.1, 1.2 DelugePageTransfer.nc, 1.1, 1.2 DelugePageTransferC.nc, 1.2, 1.3 DelugePageTransferM.nc, 1.2, 1.3 DelugeStorage.nc, 1.1, 1.2 DelugeStorageC.nc, 1.2, 1.3 DelugeStorageM.nc, 1.2, 1.3 NetProg.h, 1.1, 1.2 NetProgC.nc, 1.1, 1.2 NetProgM.nc, 1.1, 1.2

Jonathan Hui jwhui at users.sourceforge.net
Fri Nov 26 10:59:16 PST 2004


Update of /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19824/Deluge

Modified Files:
	Deluge.h DelugeC.nc DelugeDataRead.nc DelugeDataWrite.nc 
	DelugeM.nc DelugeMetadata.h DelugeMetadata.nc 
	DelugeMetadataC.nc DelugeMetadataM.nc DelugeMetadataRead.nc 
	DelugeMetadataWrite.nc DelugeMsgs.h DelugePageTransfer.nc 
	DelugePageTransferC.nc DelugePageTransferM.nc DelugeStorage.nc 
	DelugeStorageC.nc DelugeStorageM.nc NetProg.h NetProgC.nc 
	NetProgM.nc 
Log Message:
- All features currently planned for Deluge 2.0 are now implemented.

- On startup, Deluge searches the flash for complete and partially
complete images. Any partially complete images will be recovered,
allowing the user to resume an injection.

- All CRC checks now implemented and enabled. CRC checks on: (i)
deluge metadata (e.g. version number, etc.), (ii) entire pages, and
(iii) the reboot command itself. All CRCs are generated by the PC
only, thus minimizing the chance that a misbehaving node will
propagate corrupt data.

- Auto-detection of TOSBase node. Eliminates the need of the '-t'
option at the command line (which is very easy to forget).

- Auto-detection of identical images. When a user tries to inject an
identical image, Deluge will resume the injection if the image is
incomplete, or notify the user that the image is already in the
network if it is already complete.

- Works well on 2 nodes: (i) both with Deluge, (ii) one TOSBase, one
Deluge.



Index: Deluge.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/Deluge.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Deluge.h	23 Nov 2004 02:54:05 -0000	1.2
--- Deluge.h	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  #ifndef __DELUGE_H__
***************
*** 16,25 ****
    DELUGE_FAILED_SEND_DELAY          = 16,
    DELUGE_MIN_DELAY                  = 16,
    DELUGE_MAX_REQ_DELAY              = (0x1 << (DELUGE_MIN_ADV_PERIOD_LOG2-1)),
    DELUGE_NACK_TIMEOUT               = (DELUGE_MAX_REQ_DELAY >> 0x1),
    DELUGE_MAX_IMAGE_SIZE             = ((uint32_t)128*(uint32_t)1024),
!   DELUGE_PAGE_SIZE                  = 1024,
!   DELUGE_MAX_PAGES                  = DELUGE_MAX_IMAGE_SIZE/DELUGE_PAGE_SIZE,
!   DELUGE_CRC_SIZE                   = 2,
    DELUGE_CRC_BLOCK_SIZE             = DELUGE_MAX_PAGES*DELUGE_CRC_SIZE,
    DELUGE_FACTORY_IMAGE_NUM          = 0x0,
--- 45,61 ----
    DELUGE_FAILED_SEND_DELAY          = 16,
    DELUGE_MIN_DELAY                  = 16,
+   DELUGE_PKTS_PER_PAGE              = 48,
+   DELUGE_PKT_PAYLOAD_SIZE           = 23,
+   DELUGE_DATA_Q_SIZE                = 2,
+   DELUGE_DATA_OFFSET                = 128,
+   DELUGE_IDENT_SIZE                 = 128,
+   DELUGE_INVALID_ADDR               = ((uint32_t)0x7fffffff),
    DELUGE_MAX_REQ_DELAY              = (0x1 << (DELUGE_MIN_ADV_PERIOD_LOG2-1)),
    DELUGE_NACK_TIMEOUT               = (DELUGE_MAX_REQ_DELAY >> 0x1),
+   DELUGE_BYTES_PER_PAGE             = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
+   DELUGE_PKT_BITVEC_SIZE            = (((DELUGE_PKTS_PER_PAGE-1) / 8) + 1),
    DELUGE_MAX_IMAGE_SIZE             = ((uint32_t)128*(uint32_t)1024),
!   DELUGE_MAX_PAGES                  = 128,
!   DELUGE_CRC_SIZE                   = sizeof(uint16_t),
    DELUGE_CRC_BLOCK_SIZE             = DELUGE_MAX_PAGES*DELUGE_CRC_SIZE,
    DELUGE_FACTORY_IMAGE_NUM          = 0x0,
***************
*** 31,37 ****
    DELUGE_IMAGE1_VOLUME              = unique("FlashVolume"),
    DELUGE_IMAGE2_VOLUME              = unique("FlashVolume"),
-   DELUGE_DATA_OFFSET                = 128,
-   DELUGE_IDENT_SIZE                 = 128,
-   DELUGE_INVALID_ADDR               = ((uint32_t)0x7fffffff),
  };
  
--- 67,70 ----
***************
*** 59,63 ****
  } DelugeNodeDesc;
  
- #define IFLASH_GVNUM_ADDR 0x56
- 
  #endif
--- 92,94 ----

Index: DelugeC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeC.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeC.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,8 ****
  
  includes BitVecUtils;
  includes Deluge;
  includes DelugeMetadata;
- includes DelugePageTransfer;
  includes DelugeMsgs;
  
  configuration DelugeC {
--- 1,38 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  includes BitVecUtils;
+ includes crc;
  includes Deluge;
  includes DelugeMetadata;
  includes DelugeMsgs;
+ includes NetProg;
  
  configuration DelugeC {

Index: DelugeDataRead.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeDataRead.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeDataRead.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeDataRead.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  includes BlockStorage;
***************
*** 9,11 ****
--- 38,43 ----
    event result_t readDone(result_t result);
  
+   command result_t verify(imgnum_t imgNum, pgnum_t addr);
+   event result_t verifyDone(result_t result);
+ 
  }

Index: DelugeDataWrite.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeDataWrite.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeDataWrite.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeDataWrite.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  interface DelugeDataWrite {

Index: DelugeM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugeM.nc	23 Nov 2004 02:54:05 -0000	1.2
--- DelugeM.nc	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  module DelugeM {
***************
*** 74,78 ****
    command result_t StdControl.init() {
      result_t result;
!     call IFlash.read((uint16_t*)IFLASH_GVNUM_ADDR, &nodeDesc.vNum, sizeof(nodeDesc.vNum));
      result = call Leds.init();
      result = rcombine(call SubStdControl.init(), result);
--- 103,107 ----
    command result_t StdControl.init() {
      result_t result;
!     call IFlash.read((uint16_t*)IFLASH_NODE_DESC_ADDR, &nodeDesc, sizeof(nodeDesc));
      result = call Leds.init();
      result = rcombine(call SubStdControl.init(), result);
***************
*** 83,87 ****
    command result_t StdControl.start() {
      result_t result;
-     nodeDesc.imgNum = call NetProg.getExecutingImgNum();
      result = call SubStdControl.start();
      result = rcombine(call MetadataControl.start(), result);
--- 112,115 ----
***************
*** 150,160 ****
      }
  
!     if (advTimers[minTimer].newAdvs > 0
! 	&& !call PageTransfer.isTransferring())
        advTimers[minTimer].newAdvs--;
  
      if (rebootDelay > 0) {
        if (rebootDelay == 1) {
- 	call IFlash.write((uint16_t*)IFLASH_GVNUM_ADDR, &nodeDesc.vNum, sizeof(nodeDesc.vNum));
  	call NetProg.programImgAndReboot(nodeDesc.imgNum); // SHOULD NOT RETURN!
  	// XXX: WHAT DO WE DO HERE?
--- 178,188 ----
      }
  
!     if (call PageTransfer.isTransferring())
!       advTimers[minTimer].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;
!     else if (advTimers[minTimer].newAdvs > 0)
        advTimers[minTimer].newAdvs--;
  
      if (rebootDelay > 0) {
        if (rebootDelay == 1) {
  	call NetProg.programImgAndReboot(nodeDesc.imgNum); // SHOULD NOT RETURN!
  	// XXX: WHAT DO WE DO HERE?
***************
*** 178,181 ****
--- 206,220 ----
    }
  
+   bool isNodeDescValid(DelugeNodeDesc* tmpNodeDesc) {
+     uint8_t* tmp = (uint8_t*)tmpNodeDesc;
+     uint16_t crc = 0;
+     uint8_t i;
+     
+     for ( i = 0; i < 4; i++ )
+       crc = crcByte(crc, tmp[i]);
+     
+     return ((crc == tmpNodeDesc->crc) || (tmpNodeDesc->vNum == DELUGE_INVALID_VNUM));
+   }
+ 
    event TOS_MsgPtr ReceiveAdvMsg.receive(TOS_MsgPtr pMsg) {
      
***************
*** 187,190 ****
--- 226,233 ----
        return pMsg;
  
+     if (!call Metadata.isImgDescValid(&(rxAdvMsg->imgDesc))
+ 	|| !isNodeDescValid(&rxAdvMsg->nodeDesc))
+       return pMsg;
+ 
      if (rxAdvMsg->type == DELUGE_ADV_PC) {
        // adv message from PC
***************
*** 216,220 ****
        // notify page transfer of more data
        if (advTimers[imgNum-1].newAdvs == 0)
! 	call PageTransfer.dataAvailable(rxAdvMsg->sourceAddr);
        break;
      case DELUGE_IMGDESC_OLDER:
--- 259,263 ----
        // notify page transfer of more data
        if (advTimers[imgNum-1].newAdvs == 0)
! 	call PageTransfer.dataAvailable(rxAdvMsg->sourceAddr, imgNum);
        break;
      case DELUGE_IMGDESC_OLDER:
***************
*** 236,239 ****
--- 279,283 ----
        call Leds.yellowOn();
        nodeDesc = rxAdvMsg->nodeDesc;
+       call IFlash.write((uint16_t*)IFLASH_NODE_DESC_ADDR, &nodeDesc, sizeof(nodeDesc));
        advTimers[imgNum-1].periodLog2 = DELUGE_MIN_ADV_PERIOD_LOG2;
        rebootDelay = DELUGE_REBOOT_DELAY;
***************
*** 275,284 ****
    event result_t PageTransfer.receivedPage(imgnum_t imgNum, pgnum_t pgNum) {
      call Metadata.receivedPage(imgNum, pgNum);
      advTimers[imgNum-1].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;    
      advTimers[imgNum-1].periodLog2 = DELUGE_MIN_ADV_PERIOD_LOG2;
      setupAdvTimer(imgNum-1);
      startTimer();
!     setNextPage();
      return SUCCESS;
    }
  
--- 319,341 ----
    event result_t PageTransfer.receivedPage(imgnum_t imgNum, pgnum_t pgNum) {
      call Metadata.receivedPage(imgNum, pgNum);
+     return SUCCESS;
+   }
+ 
+   event result_t Metadata.receivedPageDone(result_t result) {
+ 
+     imgnum_t imgNum;
+ 
+     setNextPage();
+ 
+     imgNum = call PageTransfer.getWorkingImage();
+ 
      advTimers[imgNum-1].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;    
      advTimers[imgNum-1].periodLog2 = DELUGE_MIN_ADV_PERIOD_LOG2;
      setupAdvTimer(imgNum-1);
+ 
      startTimer();
! 
      return SUCCESS;
+ 
    }
  

Index: DelugeMetadata.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadata.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeMetadata.h	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeMetadata.h	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  #ifndef __DELUGE_METADATA_H__

Index: DelugeMetadata.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadata.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeMetadata.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeMetadata.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,6 ****
--- 1,36 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  interface DelugeMetadata {
  
    command bool isComplete(imgnum_t imgNum);
+   command bool isImgDescValid(DelugeImgDesc* tmpImgDesc);
  
    command result_t setupNewImage(DelugeImgDesc* imgDesc);
***************
*** 13,16 ****
--- 43,47 ----
  
    command result_t receivedPage(imgnum_t imgNum, pgnum_t pgNum);
+   event result_t receivedPageDone(result_t result);
  
  }

Index: DelugeMetadataC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeMetadataC.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeMetadataC.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,4 ****
--- 1,34 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  includes BlockStorage;
+ includes crc;
  
  configuration DelugeMetadataC {
***************
*** 18,21 ****
--- 48,52 ----
    Metadata = DelugeMetadataM;
  
+   DelugeMetadataM.DataRead -> Storage.DataRead[unique("DelugeDataRead")];
    DelugeMetadataM.DataWrite -> Storage.DataWrite[unique("DelugeDataWrite")];
    DelugeMetadataM.MetadataRead -> Storage.MetadataRead[unique("DelugeMetadataRead")];

Index: DelugeMetadataM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugeMetadataM.nc	23 Nov 2004 02:54:05 -0000	1.2
--- DelugeMetadataM.nc	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  module DelugeMetadataM {
***************
*** 6,9 ****
--- 35,39 ----
    }
    uses {
+     interface DelugeDataRead as DataRead;
      interface DelugeDataWrite as DataWrite;
      interface DelugeMetadataRead as MetadataRead;
***************
*** 24,30 ****
      S_INIT,
      S_IDLE,
      S_READ_IMG_DESC,
      S_WRITE_IMG_DESC,
!     S_ERASE_IMG_DESC,
    };
  
--- 54,63 ----
      S_INIT,
      S_IDLE,
+     S_VERIFY,
+     S_ERASE_IMAGE,
      S_READ_IMG_DESC,
+     S_FIND_INCOMPLETE_PAGE,
      S_WRITE_IMG_DESC,
!     S_SETUP_NEW_IMAGE,
    };
  
***************
*** 34,38 ****
  
      switch(state) {
!     case S_ERASE_IMG_DESC:
        result = call DataWrite.erase(curImage);
        break;
--- 67,71 ----
  
      switch(state) {
!     case S_SETUP_NEW_IMAGE: case S_ERASE_IMAGE:
        result = call DataWrite.erase(curImage);
        break;
***************
*** 43,46 ****
--- 76,83 ----
        result = call MetadataWrite.write(curImage, &(imgDesc[curImage]));
        break;
+     case S_FIND_INCOMPLETE_PAGE:
+     case S_VERIFY:
+       result = call DataRead.verify(curImage, imgDesc[curImage].numPgsComplete);
+       break;
      }
  
***************
*** 90,93 ****
--- 127,143 ----
    }
  
+   command bool Metadata.isImgDescValid[uint8_t id](DelugeImgDesc* tmpImgDesc) {
+ 
+     uint8_t* tmp = (uint8_t*)tmpImgDesc;
+     uint16_t crc = 0;
+     uint8_t i;
+     
+     for ( i = 0; i < 4; i++ )
+       crc = crcByte(crc, tmp[i]);
+     
+     return (crc == tmpImgDesc->crc);
+ 
+   }
+ 
    command bool Metadata.isComplete[uint8_t id](imgnum_t imgNum) {
      if (state == S_IDLE
***************
*** 109,126 ****
    command result_t Metadata.receivedPage[uint8_t id](imgnum_t imgNum, pgnum_t pgNum) {
  
!     if (imgNum >= DELUGE_NUM_IMAGES)
        return FAIL;
  
!     // increment numPgsComplete
!     if (imgDesc[imgNum].numPgsComplete < imgDesc[imgNum].numPgs
! 	&& imgDesc[imgNum].numPgsComplete == pgNum)
!       imgDesc[imgNum].numPgsComplete++;
  
!     // if image is complete, write out numPgsComplete
!     if (imgDesc[imgNum].numPgsComplete == imgDesc[imgNum].numPgs) {
!       state = S_WRITE_IMG_DESC;
!       curImage = imgNum;
!       if (call MetadataWrite.write(curImage, &(imgDesc[curImage])) == FAIL)
  	post retry();
      }
  
--- 159,228 ----
    command result_t Metadata.receivedPage[uint8_t id](imgnum_t imgNum, pgnum_t pgNum) {
  
!     if (state != S_IDLE
! 	|| imgNum >= DELUGE_NUM_IMAGES
! 	|| imgDesc[imgNum].numPgsComplete >= imgDesc[imgNum].numPgs
! 	|| imgDesc[imgNum].numPgsComplete != pgNum)
        return FAIL;
  
!     state = S_VERIFY;
!     client = id;
!     curImage = imgNum;
  
!     if (call DataRead.verify(curImage, pgNum) == FAIL)
!       post retry();
! 
!     return SUCCESS;
! 
!   }
! 
!   result_t readNextMetadata() {
!     curImage++;
!     if (curImage < DELUGE_NUM_IMAGES) {
!       if (call MetadataRead.read(curImage, &(imgDesc[curImage])) == FAIL)
! 	post retry();
!       return SUCCESS;
!     }
!     
!     // all done, signal that metadata is ready
!     state = S_IDLE;
!     return signal SplitControl.startDone();
!   }
! 
!   event result_t DataRead.verifyDone(result_t result) {
! 
!     switch(state) {
!     case S_FIND_INCOMPLETE_PAGE:
! 
!       if (result == FAIL) {
! 	state = S_READ_IMG_DESC;
! 	return readNextMetadata();
!       }
! 
!       imgDesc[curImage].numPgsComplete++;
!       if (call DataRead.verify(curImage, imgDesc[curImage].numPgsComplete) == FAIL)
  	post retry();
+ 
+       break;
+ 
+     case S_VERIFY:
+ 
+       if (result == FAIL) {
+ 	imgDesc[curImage].numPgsComplete = 0;
+ 	state = S_ERASE_IMAGE;
+ 	if (call DataWrite.erase(curImage) == FAIL)
+ 	  post retry();
+ 	return SUCCESS;
+       }
+       
+       // increment numPgsComplete
+       imgDesc[curImage].numPgsComplete++;
+       
+       // if image is complete, write out numPgsComplete?
+       
+       state = S_IDLE;
+       signal Metadata.receivedPageDone[client](SUCCESS);
+       
+       break;
+ 
      }
  
***************
*** 131,134 ****
--- 233,238 ----
    command result_t Metadata.setupNewImage[uint8_t id](DelugeImgDesc* newImgDesc) {
  
+     imgnum_t imgNum = newImgDesc->imgNum;
+ 
      if (state != S_IDLE
  	|| newImgDesc->imgNum >= DELUGE_NUM_IMAGES)
***************
*** 137,144 ****
      client = id;
  
!     memcpy(&(imgDesc[newImgDesc->imgNum]), newImgDesc, sizeof(DelugeImgDesc));
!     imgDesc[newImgDesc->imgNum].numPgsComplete = 0;
  
!     state = S_ERASE_IMG_DESC;
      curImage = newImgDesc->imgNum;
      if (call DataWrite.erase(curImage) == FAIL)
--- 241,249 ----
      client = id;
  
!     memcpy(&(imgDesc[imgNum]), newImgDesc, sizeof(DelugeImgDesc));
!     if (imgNum != DELUGE_FACTORY_IMAGE_NUM)
!       imgDesc[imgNum].numPgsComplete = 0;
  
!     state = S_SETUP_NEW_IMAGE;
      curImage = newImgDesc->imgNum;
      if (call DataWrite.erase(curImage) == FAIL)
***************
*** 182,222 ****
    event result_t MetadataRead.readDone(result_t result) {
  
!     if (imgDesc[curImage].vNum == DELUGE_INVALID_VNUM) {
        imgDesc[curImage].imgNum = curImage;
        imgDesc[curImage].numPgs = 0;
        imgDesc[curImage].crc = 0;
        imgDesc[curImage].numPgsComplete = 0;
      }
  
      if (state == S_READ_IMG_DESC) {
!       curImage++;
!       if (curImage < DELUGE_NUM_IMAGES) {
! 	if (call MetadataRead.read(curImage, &(imgDesc[curImage])) == FAIL)
! 	  post retry();
! 	return SUCCESS;
!       }
      }
  
!     state = S_IDLE;
! 
!     return signal SplitControl.startDone();
  
    }
  
    event result_t DataWrite.eraseDone(result_t result) {
!     state = S_IDLE;
!     return signal Metadata.setupNewImageDone[client](result);
    }
    
    event result_t MetadataWrite.writeDone(result_t result) {
      state = S_IDLE;
      return SUCCESS;
    }
  
    event result_t DataWrite.writeDone(result_t result) { return SUCCESS; }
! 
!   default event result_t Metadata.setupNewImageDone[uint8_t id](result_t result) {
!     return SUCCESS; 
!   }
  
  }
--- 287,338 ----
    event result_t MetadataRead.readDone(result_t result) {
  
!     if (imgDesc[curImage].numPgsComplete == DELUGE_INVALID_PGNUM
! 	|| !call Metadata.isImgDescValid[client](&imgDesc[curImage])) {
        imgDesc[curImage].imgNum = curImage;
+       imgDesc[curImage].vNum = DELUGE_INVALID_VNUM;
        imgDesc[curImage].numPgs = 0;
        imgDesc[curImage].crc = 0;
        imgDesc[curImage].numPgsComplete = 0;
+       return readNextMetadata();
      }
  
      if (state == S_READ_IMG_DESC) {
!       state = S_FIND_INCOMPLETE_PAGE;
!       if (call DataRead.verify(curImage, imgDesc[curImage].numPgsComplete) == FAIL)
! 	post retry();
!       return SUCCESS;
      }
  
!     return SUCCESS;
  
    }
  
    event result_t DataWrite.eraseDone(result_t result) {
!     switch(state) {
!     case S_ERASE_IMAGE: 
!       state = S_IDLE;
!       return signal Metadata.receivedPageDone[client](FAIL);
!     case S_SETUP_NEW_IMAGE:
!       if (call MetadataWrite.write(curImage, &(imgDesc[curImage])) == FAIL)
! 	post retry();
!       return SUCCESS;
!     }
!     return FAIL;
    }
    
    event result_t MetadataWrite.writeDone(result_t result) {
+     uint8_t tmpState = state;
      state = S_IDLE;
+     switch(tmpState) {
+     case S_SETUP_NEW_IMAGE:
+       return signal Metadata.setupNewImageDone[client](result);
+     }
      return SUCCESS;
    }
  
+   event result_t DataRead.readDone(result_t result) { return SUCCESS; }
    event result_t DataWrite.writeDone(result_t result) { return SUCCESS; }
!   default event result_t Metadata.setupNewImageDone[uint8_t id](result_t result) { return SUCCESS; }
!   default event result_t Metadata.receivedPageDone[uint8_t id](result_t result) { return SUCCESS; }
  
  }

Index: DelugeMetadataRead.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataRead.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeMetadataRead.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeMetadataRead.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  interface DelugeMetadataRead {

Index: DelugeMetadataWrite.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataWrite.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeMetadataWrite.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeMetadataWrite.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  interface DelugeMetadataWrite {

Index: DelugeMsgs.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMsgs.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeMsgs.h	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeMsgs.h	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  #ifndef __DELUGE_MSGS_H__
***************
*** 5,9 ****
  #include "Deluge.h"
  #include "DelugeMetadata.h"
- #include "DelugePageTransfer.h"
  
  enum {
--- 34,37 ----

Index: DelugePageTransfer.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugePageTransfer.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugePageTransfer.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugePageTransfer.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  interface DelugePageTransfer {
***************
*** 5,9 ****
    command pgnum_t  getWorkingPage();
    command bool     isTransferring();
!   command result_t dataAvailable(uint16_t sourceAddr);
    event   result_t receivedPage(imgnum_t imgNum, pgnum_t pgNum);
  }
--- 34,38 ----
    command pgnum_t  getWorkingPage();
    command bool     isTransferring();
!   command result_t dataAvailable(uint16_t sourceAddr, imgnum_t imgNum);
    event   result_t receivedPage(imgnum_t imgNum, pgnum_t pgNum);
  }

Index: DelugePageTransferC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugePageTransferC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugePageTransferC.nc	23 Nov 2004 02:54:05 -0000	1.2
--- DelugePageTransferC.nc	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  configuration DelugePageTransferC {

Index: DelugePageTransferM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugePageTransferM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugePageTransferM.nc	23 Nov 2004 02:54:05 -0000	1.2
--- DelugePageTransferM.nc	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  module DelugePageTransferM {
***************
*** 123,129 ****
    }
  
!   command result_t PageTransfer.dataAvailable(uint16_t sourceAddr) {
  
!     if (workingImgNum == DELUGE_INVALID_IMGNUM)
        return FAIL;
  
--- 152,159 ----
    }
  
!   command result_t PageTransfer.dataAvailable(uint16_t sourceAddr, imgnum_t imgNum) {
  
!     if (workingImgNum == DELUGE_INVALID_IMGNUM
! 	|| workingImgNum != imgNum)
        return FAIL;
  
***************
*** 143,149 ****
    }
  
!   uint32_t calcOffset(pgnum_t pgNum, uint8_t pktNum) {
!     return (uint32_t)pgNum*(uint32_t)DELUGE_BYTES_PER_PAGE
!       + (uint32_t)pktNum*(uint32_t)DELUGE_PKT_PAYLOAD_SIZE;
    }
    
--- 173,179 ----
    }
  
!   block_addr_t calcOffset(pgnum_t pgNum, uint8_t pktNum) {
!     return (block_addr_t)pgNum*(block_addr_t)DELUGE_BYTES_PER_PAGE
!       + (block_addr_t)pktNum*(block_addr_t)DELUGE_PKT_PAYLOAD_SIZE;
    }
    
***************
*** 157,161 ****
      TOS_MsgPtr pMsgBuf = call SharedMsgBuf.getMsgBuf();
      DelugeDataMsg* pDataMsg = (DelugeDataMsg*)(pMsgBuf->data);
!     uint32_t offset;
      uint16_t nextPkt;
  
--- 187,191 ----
      TOS_MsgPtr pMsgBuf = call SharedMsgBuf.getMsgBuf();
      DelugeDataMsg* pDataMsg = (DelugeDataMsg*)(pMsgBuf->data);
!     block_addr_t offset;
      uint16_t nextPkt;
  
***************
*** 351,360 ****
        }
  
-       if (dataQLen >= DELUGE_DATA_Q_SIZE) {
- 	call Leds.set(0x5);
- 	while(1);
-       }
- 	
- 
        if (dataQLen < DELUGE_DATA_Q_SIZE
  	  && rxDataMsg->pgNum == workingPgNum
--- 381,384 ----
***************
*** 424,435 ****
    }
  
- /*
-   task void checkCrc() {
-     if (call StableStore.checkCrc(workingImgNum, workingPgNum,
- 				  receivedData.data) == FAIL)
-       post checkCrc();
-   }
- */  
- 
    event result_t DataWrite.writeDone(result_t result) {
  
--- 448,451 ----
***************
*** 452,455 ****
--- 468,472 ----
        imgnum_t tmpImgNum = workingImgNum;
        pgnum_t  tmpPgNum = workingPgNum;
+       
        workingImgNum = DELUGE_INVALID_IMGNUM;
        workingPgNum = DELUGE_INVALID_PGNUM;
***************
*** 457,464 ****
        signal PageTransfer.receivedPage(tmpImgNum, tmpPgNum);
        dbg(DBG_USR1, "DELUGE: RECEIVED_PAGE(pgNum=%d)\n", tmpPgNum);
- /*
-       if (call StableStore.checkCrc(workingImgNum, workingPgNum, dataQ[dataQHead].data) == FAIL)
-       post checkCrc();
- */
      }
      
--- 474,477 ----
***************
*** 467,470 ****
--- 480,485 ----
    }
  
+   event result_t DataRead.verifyDone(result_t result) { return SUCCESS; }
+ 
    event result_t SendReqMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
  
***************
*** 508,511 ****
--- 523,527 ----
    event result_t DataWrite.eraseDone(result_t result) { return SUCCESS; }
    event result_t Metadata.setupNewImageDone(result_t result) { return SUCCESS; }
+   event result_t Metadata.receivedPageDone(result_t result) { return SUCCESS; }
  
    event result_t SharedMsgBuf.bufFree() { return SUCCESS; }

Index: DelugeStorage.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeStorage.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DelugeStorage.nc	22 Nov 2004 05:30:57 -0000	1.1
--- DelugeStorage.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  interface DelugeStorage {

Index: DelugeStorageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeStorageC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugeStorageC.nc	23 Nov 2004 02:54:05 -0000	1.2
--- DelugeStorageC.nc	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  includes FlashVolume;

Index: DelugeStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeStorageM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DelugeStorageM.nc	23 Nov 2004 02:54:05 -0000	1.2
--- DelugeStorageM.nc	26 Nov 2004 18:59:10 -0000	1.3
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  module DelugeStorageM {
***************
*** 32,39 ****
--- 61,72 ----
      S_WRITE_DATA,
      S_ERASE_DATA,
+     S_READ_CRC,
+     S_COMPUTE_CRC,
    };
  
    uint8_t compID;
    uint8_t state;
+   pgnum_t page;
+   uint16_t crc;
  
    void actualSignal(result_t result) {
***************
*** 46,49 ****
--- 79,84 ----
      case S_READ_METADATA: signal MetadataRead.readDone[compID](result); break;
      case S_WRITE_METADATA: signal MetadataWrite.writeDone[compID](result); break;
+     case S_READ_CRC: case S_COMPUTE_CRC:
+       signal DataRead.verifyDone[compID](result); break;
      }
    }
***************
*** 85,89 ****
  
    command imgnum_t DelugeStorage.addr2ImgNum(uint32_t addr) {
!     return 0xffff;
    }
  
--- 120,128 ----
  
    command imgnum_t DelugeStorage.addr2ImgNum(uint32_t addr) {
!     uint8_t volume = call Image0Volume.physicalAddrToVolume(addr);
!     if (volume == FV_FACTORY_IMAGE)
!       return DELUGE_FACTORY_IMAGE_NUM;
!     else
!       return volume+1;
    }
  
***************
*** 115,122 ****
--- 154,186 ----
    }
  
+   result_t computeCrc(imgnum_t imgNum) {
+     
+     block_addr_t blockAddr;
+     block_addr_t len;
+     
+     if (page == 0) {
+       blockAddr = DELUGE_DATA_OFFSET + DELUGE_CRC_BLOCK_SIZE;
+       len = DELUGE_BYTES_PER_PAGE - DELUGE_CRC_BLOCK_SIZE;
+     }
+     else {
+       blockAddr = DELUGE_DATA_OFFSET + (block_addr_t)page*DELUGE_BYTES_PER_PAGE;
+       len = DELUGE_BYTES_PER_PAGE;
+     }
+ 
+     switch(imgNum) {
+     case 0: return call Image0Read.computeCrc(blockAddr, len);
+     case 1: return call Image1Read.computeCrc(blockAddr, len);
+     case 2: return call Image2Read.computeCrc(blockAddr, len);
+     }
+ 
+     return FAIL;
+ 
+   }
+ 
    result_t newRequest(uint8_t newState, uint8_t id, imgnum_t imgNum, 
  		      block_addr_t addr, void* buf, block_addr_t len) {
  
      result_t result;
+     block_addr_t crcAddr;
  
      if (state != S_IDLE)
***************
*** 139,142 ****
--- 203,211 ----
        result = erase(imgNum);
        break;
+     case S_READ_CRC:
+       page = addr;
+       crcAddr = DELUGE_DATA_OFFSET + sizeof(crc)*page;
+       result = read(imgNum, crcAddr, &crc, sizeof(crc));
+       break;
      default:
        result = FAIL;
***************
*** 166,169 ****
--- 235,242 ----
    }
    
+   command result_t DataRead.verify[uint8_t id](imgnum_t imgNum, pgnum_t pgNum) {
+     return newRequest(S_READ_CRC, id, imgNum, pgNum, NULL, 0);
+   }
+ 
    command result_t DataWrite.write[uint8_t id](imgnum_t imgNum, block_addr_t addr, 
  					       uint8_t* buf, block_addr_t length) {
***************
*** 175,221 ****
    }
  
    event result_t Image0Read.readDone(result_t result) {
!     signalDone(result);
      return SUCCESS;
    }
  
    event result_t Image0Write.writeDone(result_t result) {
!     signalDone(result);
      return SUCCESS;
    }
  
    event result_t Image0Write.eraseDone(result_t result) { 
!     signalDone(result);
      return SUCCESS; 
    } 
  
    event result_t Image1Read.readDone(result_t result) {
!     signalDone(result);
      return SUCCESS;
    }
  
    event result_t Image1Write.writeDone(result_t result) {
!     signalDone(result);
      return SUCCESS;
    }
  
    event result_t Image1Write.eraseDone(result_t result) { 
!     signalDone(result);
      return SUCCESS; 
    } 
  
- 
    event result_t Image2Read.readDone(result_t result) {
!     signalDone(result);
      return SUCCESS;
    }
  
    event result_t Image2Write.writeDone(result_t result) {
!     signalDone(result);
      return SUCCESS;
    }
  
    event result_t Image2Write.eraseDone(result_t result) { 
!     signalDone(result);
      return SUCCESS; 
    } 
--- 248,321 ----
    }
  
+   void flashReqDone(imgnum_t imgNum, result_t result) {
+     switch(state) {
+     case S_READ_CRC:
+       state = S_COMPUTE_CRC;
+       if (computeCrc(imgNum) == FAIL)
+ 	signalDone(FAIL);
+       break;
+     default:
+       signalDone(result);
+       break;
+     }
+   }
+ 
    event result_t Image0Read.readDone(result_t result) {
!     flashReqDone(0, result);
!     return SUCCESS;
!   }
! 
!   event result_t Image0Read.computeCrcDone(result_t result, uint16_t crcResult) {
!     flashReqDone(0, (crc == crcResult) ? SUCCESS : FAIL);
      return SUCCESS;
    }
  
    event result_t Image0Write.writeDone(result_t result) {
!     flashReqDone(0, result);
      return SUCCESS;
    }
  
    event result_t Image0Write.eraseDone(result_t result) { 
!     flashReqDone(0, result);
      return SUCCESS; 
    } 
  
    event result_t Image1Read.readDone(result_t result) {
!     flashReqDone(1, result);
!     return SUCCESS;
!   }
! 
!   event result_t Image1Read.computeCrcDone(result_t result, uint16_t crcResult) {
!     flashReqDone(1, (crc == crcResult) ? SUCCESS : FAIL);
      return SUCCESS;
    }
  
    event result_t Image1Write.writeDone(result_t result) {
!     flashReqDone(1, result);
      return SUCCESS;
    }
  
    event result_t Image1Write.eraseDone(result_t result) { 
!     flashReqDone(1, result);
      return SUCCESS; 
    } 
  
    event result_t Image2Read.readDone(result_t result) {
!     flashReqDone(2, result);
!     return SUCCESS;
!   }
! 
!   event result_t Image2Read.computeCrcDone(result_t result, uint16_t crcResult) {
!     flashReqDone(2, (crc == crcResult) ? SUCCESS : FAIL);
      return SUCCESS;
    }
  
    event result_t Image2Write.writeDone(result_t result) {
!     flashReqDone(2, result);
      return SUCCESS;
    }
  
    event result_t Image2Write.eraseDone(result_t result) { 
!     flashReqDone(2, result);
      return SUCCESS; 
    } 
***************
*** 229,232 ****
--- 329,333 ----
  
    default event result_t DataRead.readDone[uint8_t id](result_t result) { return SUCCESS; }
+   default event result_t DataRead.verifyDone[uint8_t id](result_t result) { return SUCCESS; }
    default event result_t DataWrite.writeDone[uint8_t id](result_t result) { return SUCCESS; }
    default event result_t DataWrite.eraseDone[uint8_t id](result_t result) { return SUCCESS; }

Index: NetProg.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/NetProg.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetProg.h	22 Nov 2004 05:30:57 -0000	1.1
--- NetProg.h	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 34,40 ****
  #define __NETPROG_H__
  
! #define IFLASH_LOCALID_ADDR   0x50
! #define IFLASH_GROUPID_ADDR   0x52
! #define IFLASH_CHECKSUM_ADDR  0x54
  
  #define NETPROG_DISABLE_WDT()    WDTCTL = WDTPW + WDTHOLD;
--- 34,41 ----
  #define __NETPROG_H__
  
! #define IFLASH_LOCALID_ADDR   0x50 // 2 bytes
! #define IFLASH_GROUPID_ADDR   0x52 // 2 bytes
! #define IFLASH_CHECKSUM_ADDR  0x54 // 2 bytes
! #define IFLASH_NODE_DESC_ADDR 0x56 // 6 bytes
  
  #define NETPROG_DISABLE_WDT()    WDTCTL = WDTPW + WDTHOLD;

Index: NetProgC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/NetProgC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetProgC.nc	22 Nov 2004 05:30:57 -0000	1.1
--- NetProgC.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,8 ****
  
  includes NetProg;
  includes TOSBoot;
- #ifndef PLATFORM_PC
- includes InternalFlash;
- #endif
  
  configuration NetProgC {
--- 1,34 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  includes NetProg;
  includes TOSBoot;
  
  configuration NetProgC {
***************
*** 22,26 ****
  #ifndef PLATFORM_PC
    components InternalFlashC as IFlash;
!   NetProgM.IFlash -> IFlash;
  #endif
  
--- 48,52 ----
  #ifndef PLATFORM_PC
    components InternalFlashC as IFlash;
!   DelugeM.IFlash -> IFlash;
  #endif
  

Index: NetProgM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/NetProgM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NetProgM.nc	22 Nov 2004 05:30:57 -0000	1.1
--- NetProgM.nc	26 Nov 2004 18:59:10 -0000	1.2
***************
*** 1,2 ****
--- 1,31 ----
+ // $Id$
+ 
+ /*									tab:4
+  *
+  *
+  * "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 at cs.berkeley.edu>
+  */
  
  module NetProgM {
***************
*** 31,35 ****
   
      // grab addr, pid, and gid from internal flash
!     uint16_t addr, startPage;
      uint8_t group, sum;
      result_t result;
--- 60,65 ----
   
      // grab addr, pid, and gid from internal flash
!     uint16_t addr;
!     uint32_t curImageAddr;
      uint8_t group, sum;
      result_t result;
***************
*** 37,42 ****
      result = call MetadataControl.init();
  
! #ifndef PLATFORM_PC
!     call IFlash.read((uint16_t*)TOSBOOT_CUR_IMG_START_ADDR, &startPage, sizeof(startPage));
      call IFlash.read((uint16_t*)IFLASH_LOCALID_ADDR, &addr, sizeof(addr));
      call IFlash.read((uint8_t*)IFLASH_GROUPID_ADDR, &group, sizeof(group));
--- 67,71 ----
      result = call MetadataControl.init();
  
!     call IFlash.read((uint16_t*)TOSBOOT_CUR_IMG_START_ADDR, &curImageAddr, sizeof(curImageAddr));
      call IFlash.read((uint16_t*)IFLASH_LOCALID_ADDR, &addr, sizeof(addr));
      call IFlash.read((uint8_t*)IFLASH_GROUPID_ADDR, &group, sizeof(group));
***************
*** 50,59 ****
      }
  
!     imgNum = (startPage == 0xffff) ? DELUGE_INVALID_IMGNUM : 0;
!     //call Storage.flashPage2ImgNum(startPage);
! #else
!     imgNum = DELUGE_INVALID_IMGNUM;
! #endif
      return result;
    }
    
--- 79,86 ----
      }
  
!     imgNum = call Storage.addr2ImgNum(curImageAddr);
! 
      return result;
+ 
    }
    
***************
*** 119,122 ****
--- 146,150 ----
  
    event result_t Metadata.setupNewImageDone(result_t result) { return SUCCESS; }
+   event result_t Metadata.receivedPageDone(result_t result) { return SUCCESS; }
  
  }



More information about the Tinyos-beta-commits mailing list