From a246434cd8090fc8571e59adf8125961ccd20a90 Mon Sep 17 00:00:00 2001 From: razvanm Date: Wed, 27 Jun 2007 20:04:57 +0000 Subject: [PATCH] This commit from Chieh-Jan (Mike) Liang fixes the following issues: - 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 | 25 ++--- tos/lib/net/Deluge/DelugeP.nc | 2 +- .../FlashVolumeManager/FlashVolumeManagerC.nc | 19 ++-- .../FlashVolumeManager/FlashVolumeManagerP.nc | 94 ++++++++++--------- tos/lib/net/Deluge/ObjectTransferC.nc | 13 +-- tos/lib/net/Deluge/ObjectTransferP.nc | 23 ++++- tos/lib/net/Deluge/extra/NetProgC.nc | 4 + tos/lib/net/Deluge/extra/NetProgM.nc | 17 +++- 8 files changed, 117 insertions(+), 80 deletions(-) diff --git a/tos/lib/net/Deluge/DelugeC.nc b/tos/lib/net/Deluge/DelugeC.nc index f27d9070..caea5305 100644 --- a/tos/lib/net/Deluge/DelugeC.nc +++ b/tos/lib/net/Deluge/DelugeC.nc @@ -25,31 +25,32 @@ */ #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; diff --git a/tos/lib/net/Deluge/DelugeP.nc b/tos/lib/net/Deluge/DelugeP.nc index 81020484..d49bac41 100644 --- a/tos/lib/net/Deluge/DelugeP.nc +++ b/tos/lib/net/Deluge/DelugeP.nc @@ -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 diff --git a/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerC.nc b/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerC.nc index f05d8310..12e7779e 100644 --- a/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerC.nc +++ b/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerC.nc @@ -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 } diff --git a/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc b/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc index e5705277..78cda769 100644 --- a/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc +++ b/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc @@ -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 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; } } diff --git a/tos/lib/net/Deluge/ObjectTransferC.nc b/tos/lib/net/Deluge/ObjectTransferC.nc index 9db303eb..bbf6c05d 100644 --- a/tos/lib/net/Deluge/ObjectTransferC.nc +++ b/tos/lib/net/Deluge/ObjectTransferC.nc @@ -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; diff --git a/tos/lib/net/Deluge/ObjectTransferP.nc b/tos/lib/net/Deluge/ObjectTransferP.nc index fec6cd29..ed9da3de 100644 --- a/tos/lib/net/Deluge/ObjectTransferP.nc +++ b/tos/lib/net/Deluge/ObjectTransferP.nc @@ -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) {} } diff --git a/tos/lib/net/Deluge/extra/NetProgC.nc b/tos/lib/net/Deluge/extra/NetProgC.nc index 255d2c9b..ccbbf2a9 100644 --- a/tos/lib/net/Deluge/extra/NetProgC.nc +++ b/tos/lib/net/Deluge/extra/NetProgC.nc @@ -54,4 +54,8 @@ implementation { components LedsC; NetProgM.Leds -> LedsC; + + components CC2420ControlP, ActiveMessageAddressC; + NetProgM.CC2420Config -> CC2420ControlP; + NetProgM.setAmAddress -> ActiveMessageAddressC; } diff --git a/tos/lib/net/Deluge/extra/NetProgM.nc b/tos/lib/net/Deluge/extra/NetProgM.nc index 93bed42c..ab122f4d 100644 --- a/tos/lib/net/Deluge/extra/NetProgM.nc +++ b/tos/lib/net/Deluge/extra/NetProgM.nc @@ -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; } } -- 2.39.2