]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc
Check the image number against the DELUGE_NUM_VOLUMES. The bug was reported by David...
[tinyos-2.x.git] / tos / lib / net / Deluge / FlashVolumeManager / FlashVolumeManagerP.nc
index 138c6b02ec361cc5316a3fe3fec833d5f11c4515..56558c4214a17c8b14bf11c143a016a5e005de59 100644 (file)
@@ -29,7 +29,7 @@ generic module FlashVolumeManagerP()
   uses {
     interface BlockRead[uint8_t imgNum];
     interface BlockWrite[uint8_t imgNum];
-    interface Resource[uint8_t imgNum];
+    interface Resource;
     interface ArbiterInfo;
     interface AMSend as SerialAMSender;
     interface Receive as SerialAMReceiver;
@@ -87,6 +87,13 @@ implementation
     nx_uint32_t uidhash;
     nx_uint16_t nodeid;
   };
+
+  uint8_t imgNum2volumeId[] = {
+    VOLUME_GOLDENIMAGE,
+    VOLUME_DELUGE1,
+    VOLUME_DELUGE2,
+    VOLUME_DELUGE3
+  };
   
   void sendReply(error_t error, storage_len_t len)
   {
@@ -179,20 +186,7 @@ implementation
     }
 
     // Converts the image number that the user wants to the real image number
-    switch (request->imgNum) {
-      case 0:
-        imgNum = VOLUME_GOLDENIMAGE;
-        break;
-      case 1:
-        imgNum = VOLUME_DELUGE1;
-        break;
-      case 2:
-        imgNum = VOLUME_DELUGE2;
-        break;
-      case 3:
-        imgNum = VOLUME_DELUGE3;
-        break;
-    }
+    imgNum = request->imgNum < DELUGE_NUM_VOLUMES ? imgNum2volumeId[request->imgNum] : 0xFF;
     
     if (imgNum != 0xFF) {
       error = SUCCESS;
@@ -200,8 +194,8 @@ implementation
       switch (request->cmd) {
        case CMD_ERASE:
        case CMD_WRITE:
-         if (!call Resource.isOwner[imgNum]()) {
-           error = call Resource.immediateRequest[imgNum]();
+         if (!call Resource.isOwner()) {
+           error = call Resource.immediateRequest();
          }
       }
       if (error == SUCCESS) {
@@ -264,9 +258,9 @@ implementation
   event void TimeoutTimer.fired()
   {
     // Release the resource.
-    if (state == S_IDLE && call Resource.isOwner[currentImgNum]()) {
+    if (state == S_IDLE && call Resource.isOwner()) {
       call Leds.led1Off();
-      call Resource.release[currentImgNum]();
+      call Resource.release();
     }
     if (state == S_IDLE && !call ArbiterInfo.inUse()) {
       call Leds.led1Off();
@@ -274,7 +268,7 @@ implementation
   }
 
   event void SerialAMSender.sendDone(message_t* msg, error_t error) {}
-  event void Resource.granted[uint8_t imgNum]() {}
+  event void Resource.granted() {}
 
   default command error_t BlockWrite.write[uint8_t imgNum](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
   default command error_t BlockWrite.erase[uint8_t imgNum]() { return FAIL; }
@@ -282,7 +276,7 @@ implementation
   default command error_t BlockRead.read[uint8_t imgNum](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
   default command error_t BlockRead.computeCrc[uint8_t imgNum](storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
 
-  default async command error_t Resource.immediateRequest[uint8_t imgNum]() { return FAIL; }
-  default async command error_t Resource.release[uint8_t imgNum]() { return FAIL; }
-  default async command bool Resource.isOwner[uint8_t imgNum]() { return FAIL; }
+  default async command error_t Resource.immediateRequest() { return FAIL; }
+  default async command error_t Resource.release() { return FAIL; }
+  default async command bool Resource.isOwner() { return FAIL; }
 }