- 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).
*/
#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;
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
*/
#include "AM.h"
+#include "StorageVolumes.h"
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
}
}
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
}
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;
}
}
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
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; }
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; }
}
*/
#include "DelugePageTransfer.h"
+#include "StorageVolumes.h"
configuration ObjectTransferC
{
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;
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;
// States
enum {
S_ERASE,
+ S_SYNC,
S_INITIALIZING_PUB,
S_INITIALIZING_RECV,
S_STARTED,
resetTimer();
} else {
call DelugePageTransfer.setWorkingPage(DELUGE_INVALID_OBJID, DELUGE_INVALID_PGNUM);
- post signalObjRecvDone();
+ state = S_SYNC;
+ call BlockWrite.sync[cont_receive_img_num]();
}
}
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;
}
}
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;
}
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();
}
}
}
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)
{
cont_receive();
}
}
- event void BlockWrite.syncDone[uint8_t img_num](error_t error) {}
}
components LedsC;
NetProgM.Leds -> LedsC;
+
+ components CC2420ControlP, ActiveMessageAddressC;
+ NetProgM.CC2420Config -> CC2420ControlP;
+ NetProgM.setAmAddress -> ActiveMessageAddressC;
}
interface Crc;
interface DelugeMetadata;
interface Leds;
+ interface CC2420Config;
+ async command void setAmAddress(am_addr_t a);
}
}
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;
}
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; }
}