]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
This commit from Chieh-Jan (Mike) Liang fixes the following issues:
authorrazvanm <razvanm>
Wed, 27 Jun 2007 20:04:57 +0000 (20:04 +0000)
committerrazvanm <razvanm>
Wed, 27 Jun 2007 20:04:57 +0000 (20:04 +0000)
- DelugeStorage is no longer included when DELUGE flag is not defined.
- Fix a problem related to the way MicaZ storage driver allocates volumes in reverse order than the one defined in XML file. The symptom here is that --diss command will disseminate the wrong volume.
- Fix the problem of not changing local node ID properly. The problem was reported by Ryan Stinnett.
- After a page is received and written to flash, sync the flash (especially for AT45DB).

tos/lib/net/Deluge/DelugeC.nc
tos/lib/net/Deluge/DelugeP.nc
tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerC.nc
tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc
tos/lib/net/Deluge/ObjectTransferC.nc
tos/lib/net/Deluge/ObjectTransferP.nc
tos/lib/net/Deluge/extra/NetProgC.nc
tos/lib/net/Deluge/extra/NetProgM.nc

index f27d9070be4c547aa809047f2f0fd25a9359bb73..caea53054376d40f23b2df9519fb0a9057243e01 100644 (file)
  */
 
 #include "Deluge.h"
+#include "StorageVolumes.h"
 
 configuration DelugeC {}
 
 implementation
 {
   components DelugeStorageC;
-
+  
 #ifdef DELUGE_BASESTATION
   components SerialStarterC;
   components new FlashVolumeManagerC(0xAB);
-
+  
   DelugeP.ReprogNotify -> FlashVolumeManagerC;
-  FlashVolumeManagerC.BlockRead[0] -> DelugeStorageC.BlockRead[0];
-  FlashVolumeManagerC.BlockWrite[0] -> DelugeStorageC.BlockWrite[0];
-  FlashVolumeManagerC.DelugeStorage[0] -> DelugeStorageC.DelugeStorage[0];
-  FlashVolumeManagerC.BlockRead[1] -> DelugeStorageC.BlockRead[1];
-  FlashVolumeManagerC.BlockWrite[1] -> DelugeStorageC.BlockWrite[1];
-  FlashVolumeManagerC.DelugeStorage[1] -> DelugeStorageC.DelugeStorage[1];
+  FlashVolumeManagerC.BlockRead[VOLUME_DELUGE0] -> DelugeStorageC.BlockRead[VOLUME_DELUGE0];
+  FlashVolumeManagerC.BlockWrite[VOLUME_DELUGE0] -> DelugeStorageC.BlockWrite[VOLUME_DELUGE0];
+  FlashVolumeManagerC.DelugeStorage[VOLUME_DELUGE0] -> DelugeStorageC.DelugeStorage[VOLUME_DELUGE0];
+  FlashVolumeManagerC.BlockRead[VOLUME_DELUGE1] -> DelugeStorageC.BlockRead[VOLUME_DELUGE1];
+  FlashVolumeManagerC.BlockWrite[VOLUME_DELUGE1] -> DelugeStorageC.BlockWrite[VOLUME_DELUGE1];
+  FlashVolumeManagerC.DelugeStorage[VOLUME_DELUGE1] -> DelugeStorageC.DelugeStorage[VOLUME_DELUGE1];
 #endif
   
   components ObjectTransferC;
-  ObjectTransferC.BlockRead[0] -> DelugeStorageC.BlockRead[0];
-  ObjectTransferC.BlockWrite[0] -> DelugeStorageC.BlockWrite[0];
-  ObjectTransferC.BlockRead[1] -> DelugeStorageC.BlockRead[1];
-  ObjectTransferC.BlockWrite[1] -> DelugeStorageC.BlockWrite[1];
+  ObjectTransferC.BlockRead[VOLUME_DELUGE0] -> DelugeStorageC.BlockRead[VOLUME_DELUGE0];
+  ObjectTransferC.BlockWrite[VOLUME_DELUGE0] -> DelugeStorageC.BlockWrite[VOLUME_DELUGE0];
+  ObjectTransferC.BlockRead[VOLUME_DELUGE1] -> DelugeStorageC.BlockRead[VOLUME_DELUGE1];
+  ObjectTransferC.BlockWrite[VOLUME_DELUGE1] -> DelugeStorageC.BlockWrite[VOLUME_DELUGE1];
   
   components new DisseminatorC(DelugeDissemination, 0xDE00), DisseminationC;
   components ActiveMessageC;
index 81020484e06fc9f0fe626c7a1e240810a646e376..d49bac4133f3cc716caccf3205bb6e40d4ec2b29 100644 (file)
@@ -73,7 +73,7 @@ implementation
       
       delugeDis.uid = imgDesc->uid;
       delugeDis.vNum = imgDesc->vNum;
-      delugeDis.imgNum = imgDesc->imgNum;
+      delugeDis.imgNum = img_num;
       delugeDis.size = imgDesc->size;
       
       call DisseminationUpdate.change(&delugeDis);   // Disseminates image information
index f05d8310aae5f05a8873572eff6ec62cc5a7e814..12e7779eadc6028df86c2472ff35d58b4998f336 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "AM.h"
+#include "StorageVolumes.h"
 
 generic configuration FlashVolumeManagerC(am_id_t AMId)
 {
@@ -34,7 +35,9 @@ generic configuration FlashVolumeManagerC(am_id_t AMId)
   uses {
     interface BlockRead[uint8_t img_num];
     interface BlockWrite[uint8_t img_num];
+#ifdef DELUGE
     interface DelugeStorage[uint8_t img_num];
+#endif
   }
 }
 
@@ -45,21 +48,21 @@ implementation
              new FlashVolumeManagerP(),
              NoLedsC, LedsC;
   
-  FlashVolumeManagerP.BlockRead[0] = BlockRead[0];
-  FlashVolumeManagerP.BlockWrite[0] = BlockWrite[0];
-  FlashVolumeManagerP.DelugeStorage[0] = DelugeStorage[0];
-  FlashVolumeManagerP.BlockRead[1] = BlockRead[1];
-  FlashVolumeManagerP.BlockWrite[1] = BlockWrite[1];
-  FlashVolumeManagerP.DelugeStorage[1] = DelugeStorage[1];
+  FlashVolumeManagerP.BlockRead[VOLUME_DELUGE0] = BlockRead[VOLUME_DELUGE0];
+  FlashVolumeManagerP.BlockWrite[VOLUME_DELUGE0] = BlockWrite[VOLUME_DELUGE0];
+  FlashVolumeManagerP.BlockRead[VOLUME_DELUGE1] = BlockRead[VOLUME_DELUGE1];
+  FlashVolumeManagerP.BlockWrite[VOLUME_DELUGE1] = BlockWrite[VOLUME_DELUGE1];
   FlashVolumeManagerP.SerialAMSender -> SerialAMSenderC;
   FlashVolumeManagerP.SerialAMReceiver -> SerialAMReceiverC;
-  FlashVolumeManagerP.Leds -> LedsC;
+  FlashVolumeManagerP.Leds -> NoLedsC;
 
 #ifdef DELUGE  
   components NetProgC, new TimerMilliC();
+  
   FlashVolumeManagerP.NetProg -> NetProgC;
   FlashVolumeManagerP.Timer -> TimerMilliC;
-  
+  FlashVolumeManagerP.DelugeStorage[VOLUME_DELUGE0] = DelugeStorage[VOLUME_DELUGE0];
+  FlashVolumeManagerP.DelugeStorage[VOLUME_DELUGE1] = DelugeStorage[VOLUME_DELUGE1];
   Notify = FlashVolumeManagerP.Notify;
 #endif
 }
index e57052770c004166c088cee82c10741edb949d47..78cda769888c97aca3f55b72ba0abd8c036b6bee 100644 (file)
@@ -34,14 +34,14 @@ generic module FlashVolumeManagerP()
   uses {
     interface BlockRead[uint8_t img_num];
     interface BlockWrite[uint8_t img_num];
-    interface DelugeStorage[uint8_t img_num];
-    interface AMSend as SerialAMSender;
-    interface Receive as SerialAMReceiver;
-    interface Leds;
 #ifdef DELUGE
+    interface DelugeStorage[uint8_t img_num];
     interface NetProg;
     interface Timer<TMilli> as Timer;
 #endif
+    interface AMSend as SerialAMSender;
+    interface Receive as SerialAMReceiver;
+    interface Leds;
   }
 }
 
@@ -153,46 +153,50 @@ implementation
         break;
     }
     
-    switch (srpkt->msg_type) {
-      case SERIALMSG_ERASE:    // === Erases a volume ===
-        state = S_ERASE;
-        error = call BlockWrite.erase[img_num]();
-        break;
-      case SERIALMSG_WRITE:    // === Writes to a volume ===
-        state = S_WRITE;
-        memcpy(buffer, srpkt->data, srpkt->len);
-        error = call BlockWrite.write[img_num](srpkt->offset,
-                                                      buffer,
+    if (img_num != 0xFF) {
+      switch (srpkt->msg_type) {
+        case SERIALMSG_ERASE:    // === Erases a volume ===
+          state = S_ERASE;
+          error = call BlockWrite.erase[img_num]();
+          break;
+        case SERIALMSG_WRITE:    // === Writes to a volume ===
+          state = S_WRITE;
+          memcpy(buffer, srpkt->data, srpkt->len);
+          error = call BlockWrite.write[img_num](srpkt->offset,
+                                                        buffer,
+                                                        srpkt->len);
+          break;
+        case SERIALMSG_READ:     // === Reads a portion of a volume ===
+          state = S_READ;
+          error = call BlockRead.read[img_num](srpkt->offset,
+                                                      serialMsg_payload->data,
                                                       srpkt->len);
-        break;
-      case SERIALMSG_READ:     // === Reads a portion of a volume ===
-        state = S_READ;
-        error = call BlockRead.read[img_num](srpkt->offset,
-                                                    serialMsg_payload->data,
-                                                    srpkt->len);
-        break;
-      case SERIALMSG_CRC:      // === Computes CRC over a portion of a volume ===
-        state = S_CRC;
-        error = call BlockRead.computeCrc[img_num](srpkt->offset,
-                                                          srpkt->len, 0);
-        break;
-      case SERIALMSG_ADDR:     // === Gets the physical starting address of a volume ===
-       *(nx_uint32_t*)(&serialMsg_payload->data) =
-                             (uint32_t)call DelugeStorage.getPhysicalAddress[img_num](0);
-       sendReply(SUCCESS, sizeof(SerialReplyPacket) + 4);
-        break;
-#ifdef DELUGE
-      case SERIALMSG_REPROG:   // === Reboots and reprograms ===
-        state = S_REPROG;
-        sendReply(SUCCESS, sizeof(SerialReplyPacket));
-        img_num_reboot = img_num;
-       call Timer.startOneShot(1024);
-       break;
-      case SERIALMSG_DISS:     // === Starts disseminating a volume ===
-       signal Notify.notify(img_num);   // Notifies Deluge to start disseminate
-       sendReply(SUCCESS, sizeof(SerialReplyPacket));
-       break;
-#endif
+          break;
+        case SERIALMSG_CRC:      // === Computes CRC over a portion of a volume ===
+          state = S_CRC;
+          error = call BlockRead.computeCrc[img_num](srpkt->offset,
+                                                            srpkt->len, 0);
+          break;
+  #ifdef DELUGE
+        case SERIALMSG_ADDR:     // === Gets the physical starting address of a volume ===
+          *(nx_uint32_t*)(&serialMsg_payload->data) =
+                                  (uint32_t)call DelugeStorage.getPhysicalAddress[img_num](0);
+          sendReply(SUCCESS, sizeof(SerialReplyPacket) + 4);
+          break;
+        case SERIALMSG_REPROG:   // === Reboots and reprograms ===
+          state = S_REPROG;
+          sendReply(SUCCESS, sizeof(SerialReplyPacket));
+          img_num_reboot = img_num;
+          call Timer.startOneShot(1024);
+          break;
+        case SERIALMSG_DISS:     // === Starts disseminating a volume ===
+          signal Notify.notify(img_num);   // Notifies Deluge to start disseminate
+          sendReply(SUCCESS, sizeof(SerialReplyPacket));
+          break;
+  #endif
+      }
+    } else {
+      error = FAIL;
     }
     
     // If a split-phase operation fails when being requested, signals the failure now
@@ -213,6 +217,8 @@ implementation
   
   command error_t Notify.enable() { return SUCCESS; }
   command error_t Notify.disable() { return SUCCESS; }
+  
+  default command storage_addr_t DelugeStorage.getPhysicalAddress[uint8_t img_num](storage_addr_t addr) { return 0; }
 #endif
 
   default command error_t BlockWrite.write[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
@@ -220,6 +226,4 @@ implementation
   default command error_t BlockWrite.sync[uint8_t img_num]() { return FAIL; }
   default command error_t BlockRead.read[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
   default command error_t BlockRead.computeCrc[uint8_t img_num](storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
-
-  default command storage_addr_t DelugeStorage.getPhysicalAddress[uint8_t img_num](storage_addr_t addr) { return 0; }
 }
index 9db303eb974a15474ca9189b135c2cb2fb653658..bbf6c05d30169d4d99aea81c1dff94ca0143b632 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 #include "DelugePageTransfer.h"
+#include "StorageVolumes.h"
 
 configuration ObjectTransferC
 {
@@ -40,10 +41,10 @@ implementation
   components ObjectTransferP, DelugePageTransferC;
   
   ObjectTransfer = ObjectTransferP;
-  BlockRead[0] = DelugePageTransferC.BlockRead[0];
-  BlockWrite[0] = DelugePageTransferC.BlockWrite[0];
-  BlockRead[1] = DelugePageTransferC.BlockRead[1];
-  BlockWrite[1] = DelugePageTransferC.BlockWrite[1];
+  BlockRead[VOLUME_DELUGE0] = DelugePageTransferC.BlockRead[VOLUME_DELUGE0];
+  BlockWrite[VOLUME_DELUGE0] = DelugePageTransferC.BlockWrite[VOLUME_DELUGE0];
+  BlockRead[VOLUME_DELUGE1] = DelugePageTransferC.BlockRead[VOLUME_DELUGE1];
+  BlockWrite[VOLUME_DELUGE1] = DelugePageTransferC.BlockWrite[VOLUME_DELUGE1];
   ObjectTransferP.DelugePageTransfer -> DelugePageTransferC.DelugePageTransfer;
   
   components CrcP;
@@ -64,8 +65,8 @@ implementation
   DelugePageTransferC.ReceiveDataMsg -> ReceiveDataMsg;
   DelugePageTransferC.AMPacket -> SendDataMsg;
   
-  ObjectTransferP.BlockWrite[0] = BlockWrite[0];
-  ObjectTransferP.BlockWrite[1] = BlockWrite[1];
+  ObjectTransferP.BlockWrite[VOLUME_DELUGE0] = BlockWrite[VOLUME_DELUGE0];
+  ObjectTransferP.BlockWrite[VOLUME_DELUGE1] = BlockWrite[VOLUME_DELUGE1];
   
   components MainC, LedsC, NoLedsC;
   ObjectTransferP.Leds -> NoLedsC;
index fec6cd29e16fd2c0c668398ef5810bdc55c0eb4a..ed9da3ded7e76cc49e186710a1ce0a4a4c89f199 100644 (file)
@@ -55,6 +55,7 @@ implementation
   // States
   enum {
     S_ERASE,
+    S_SYNC,
     S_INITIALIZING_PUB,
     S_INITIALIZING_RECV,
     S_STARTED,
@@ -110,7 +111,8 @@ implementation
       resetTimer();
     } else {
       call DelugePageTransfer.setWorkingPage(DELUGE_INVALID_OBJID, DELUGE_INVALID_PGNUM);
-      post signalObjRecvDone();
+      state = S_SYNC;
+      call BlockWrite.sync[cont_receive_img_num]();
     }
   }
   
@@ -150,7 +152,6 @@ implementation
       if (call SendAdvMsg.send(addr, &pMsgBuf, sizeof(DelugeAdvMsg)) == SUCCESS) {
         //dbg(DBG_USR1, "DELUGE: Sent ADV_MSG(imgNum=%d)\n", imgDesc->imgNum);
 //call StatsCollector.msg_bcastReq();
-call Leds.led0Toggle();
         isBusy_pMsgBuf = TRUE;
       }
     }
@@ -215,7 +216,7 @@ call Leds.led0Toggle();
     cont_receive_new_size = new_size;
     cont_receive_img_num = img_num;
     
-    error = call BlockWrite.erase[img_num]();
+    error = call BlockWrite.erase[cont_receive_img_num]();
     if (error == SUCCESS) {
       state = S_ERASE;
     }
@@ -246,8 +247,19 @@ call Leds.led0Toggle();
         setNextPage();
       } else {
         call DelugePageTransfer.setWorkingPage(curObjDesc.objid, curObjDesc.numPgsComplete);
-        post signalObjRecvDone();
+        state = S_SYNC;
+        call BlockWrite.sync[cont_receive_img_num]();
+      }
+    }
+  }
+  
+  event void BlockWrite.syncDone[uint8_t img_num](error_t error)
+  {
+    if (state == S_SYNC) {
+      if (error != SUCCESS) {
+        call Leds.led2On();
       }
+      post signalObjRecvDone();
     }
   }
   
@@ -326,6 +338,8 @@ call Leds.led0Toggle();
   }
   
   default command error_t BlockWrite.erase[uint8_t img_num]() { return FAIL; }
+  default command error_t BlockWrite.sync[uint8_t img_num]() { return FAIL; }
+  
   event void BlockWrite.writeDone[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
   event void BlockWrite.eraseDone[uint8_t img_num](error_t error)
   {
@@ -333,5 +347,4 @@ call Leds.led0Toggle();
       cont_receive();
     }
   }
-  event void BlockWrite.syncDone[uint8_t img_num](error_t error) {}
 }
index 255d2c9b7d72592f2db4f8892c78fee3a34d98f4..ccbbf2a9d8fdfb0c28ccc0a7bea07b2f6942d1b0 100644 (file)
@@ -54,4 +54,8 @@ implementation {
   
   components LedsC;
   NetProgM.Leds -> LedsC;
+  
+  components CC2420ControlP, ActiveMessageAddressC;
+  NetProgM.CC2420Config -> CC2420ControlP;
+  NetProgM.setAmAddress -> ActiveMessageAddressC;
 }
index 93bed42cc8ec49aa145b1717e863e78e9d5cd87b..ab122f4d1ccf3bf88e70db5b77ec82b26eb3aed0 100644 (file)
@@ -42,6 +42,8 @@ module NetProgM {
     interface Crc;
     interface DelugeMetadata;
     interface Leds;
+    interface CC2420Config;
+    async command void setAmAddress(am_addr_t a);
   }
 }
 
@@ -76,13 +78,20 @@ implementation {
 
     if (tosInfo.crc == computeTosInfoCrc(&tosInfo)) {
       // TOS_AM_GROUP is not a variable in T2
-      //      TOS_AM_GROUP = tosInfo.groupId;
-      atomic TOS_NODE_ID = tosInfo.addr;
+      //   TOS_AM_GROUP = tosInfo.groupId;
+      
+      // Updates local node ID
+      atomic {
+        TOS_NODE_ID = tosInfo.addr;
+        call setAmAddress(tosInfo.addr);
+      }
+      call CC2420Config.setShortAddr(tosInfo.addr);
+      call CC2420Config.sync();
     }
     else {
       writeTOSinfo();
     }
+    
     return SUCCESS;
   }
   
@@ -123,6 +132,8 @@ implementation {
     return FAIL;
   }
 
+  event void CC2420Config.syncDone(error_t error) {}
+
   default command storage_addr_t DelugeStorage.getPhysicalAddress[uint8_t img_num](storage_addr_t addr) { return 0xFFFFFFFF; }
 
 }