[Tinyos-beta-commits]
CVS: tinyos-1.x/beta/Deluge/Deluge DelugeM.nc, 1.22,
1.23 DelugeMetadataM.nc, 1.19, 1.20 DelugeStorage.nc, 1.4,
1.5 DelugeStorageM.nc, 1.9, 1.10 NetProgM.nc, 1.8, 1.9
Jonathan Hui
jwhui at users.sourceforge.net
Wed Jun 29 14:08:19 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32766
Modified Files:
DelugeM.nc DelugeMetadataM.nc DelugeStorage.nc
DelugeStorageM.nc NetProgM.nc
Log Message:
Added support for rebooting to the Golden Image even if the deluge
images do not mount properly. This is possible since the address of
the golden image in external flash is known and fixed for each flash
chip.
Index: DelugeM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeM.nc,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** DelugeM.nc 27 Jun 2005 18:01:11 -0000 1.22
--- DelugeM.nc 29 Jun 2005 21:08:12 -0000 1.23
***************
*** 53,57 ****
enum {
! DELUGE_NUM_TIMERS = DELUGE_NUM_IMAGES-1,
};
--- 53,57 ----
enum {
! DELUGE_NUM_TIMERS = DELUGE_NUM_IMAGES,
};
***************
*** 71,83 ****
uint8_t findMinTimer() {
- uint32_t minDelay = advTimers[0].timer;
uint8_t minTimer = 0;
uint8_t i;
for ( i = 1; i < DELUGE_NUM_TIMERS; i++ ) {
! if (advTimers[i].timer < minDelay)
minTimer = i;
}
!
return minTimer;
--- 71,82 ----
uint8_t findMinTimer() {
uint8_t minTimer = 0;
uint8_t i;
for ( i = 1; i < DELUGE_NUM_TIMERS; i++ ) {
! if (advTimers[i].timer < advTimers[minTimer].timer)
minTimer = i;
}
!
return minTimer;
***************
*** 93,97 ****
minTimer = findMinTimer();
!
call Timer.stop();
call Timer.start(TIMER_ONE_SHOT, advTimers[minTimer].timer);
--- 92,96 ----
minTimer = findMinTimer();
!
call Timer.stop();
call Timer.start(TIMER_ONE_SHOT, advTimers[minTimer].timer);
***************
*** 123,130 ****
if (imgDesc->numPgs != imgDesc->numPgsComplete) {
call PageTransfer.setWorkingPage(i, imgDesc->numPgsComplete);
! if (i > 0) {
! advTimers[i-1].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;
! resetTimer(i-1);
! }
call Leds.redOff();
return;
--- 122,127 ----
if (imgDesc->numPgs != imgDesc->numPgsComplete) {
call PageTransfer.setWorkingPage(i, imgDesc->numPgsComplete);
! advTimers[i].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;
! resetTimer(i);
call Leds.redOff();
return;
***************
*** 138,142 ****
--- 135,141 ----
command result_t StdControl.init() {
+
result_t result;
+
state = S_DISABLED;
#ifndef PLATFORM_PC
***************
*** 146,170 ****
result = rcombine(call PageTransferControl.init(), result);
result = rcombine(call MetadataControl.init(), result);
- return result;
- }
-
- void realStart() {
-
- uint8_t i;
! if (state != S_INITIALIZING)
! return;
!
! state = S_ENABLED;
!
! for ( i = 0; i < DELUGE_NUM_TIMERS; i++ )
! resetTimer(i);
!
! setNextPage();
}
command result_t StdControl.start() {
result_t result;
result = call PageTransferControl.start();
--- 145,157 ----
result = rcombine(call PageTransferControl.init(), result);
result = rcombine(call MetadataControl.init(), result);
! return result;
}
command result_t StdControl.start() {
+
result_t result;
+ uint8_t i;
result = call PageTransferControl.start();
***************
*** 173,180 ****
if (!call Metadata.started())
call MetadataControl.start();
! else
! realStart();
return result;
}
--- 160,173 ----
if (!call Metadata.started())
call MetadataControl.start();
! else {
! state = S_ENABLED;
! setNextPage();
! }
!
! for ( i = 0; i < DELUGE_NUM_TIMERS; i++ )
! resetTimer(i);
return result;
+
}
***************
*** 182,185 ****
--- 175,179 ----
if (state == S_ENABLED)
state = S_DISABLED;
+ call Timer.stop();
return call PageTransferControl.stop();
}
***************
*** 190,194 ****
event result_t MetadataControl.startDone() {
! realStart();
return SUCCESS;
}
--- 184,189 ----
event result_t MetadataControl.startDone() {
! state = S_ENABLED;
! setNextPage();
return SUCCESS;
}
***************
*** 227,231 ****
if (!advTimers[minTimer].overheard)
! sendAdvMsg(minTimer+1, TOS_BCAST_ADDR);
if (call PageTransfer.isTransferring())
--- 222,226 ----
if (!advTimers[minTimer].overheard)
! sendAdvMsg(minTimer, TOS_BCAST_ADDR);
if (call PageTransfer.isTransferring())
***************
*** 271,277 ****
bool isEqual = FALSE;
! if (rxAdvMsg->version != DELUGE_VERSION
! || !call Metadata.isImgDescValid(&(rxAdvMsg->imgDesc))
! || !isNodeDescValid(&rxAdvMsg->nodeDesc))
return pMsg;
--- 266,271 ----
bool isEqual = FALSE;
! if ( rxAdvMsg->version != DELUGE_VERSION
! || !isNodeDescValid(&rxAdvMsg->nodeDesc) )
return pMsg;
***************
*** 289,329 ****
}
! if (state != S_ENABLED)
! return pMsg;
! // don't listen to advertisements about the golden image
! // unless it's from the PC and source address is TOS_UART_ADDR
! if (imgNum != DELUGE_GOLDEN_IMAGE_NUM
! || (rxAdvMsg->type == DELUGE_ADV_PC && rxAdvMsg->sourceAddr == TOS_UART_ADDR)) {
! if (cmpImgDesc->vNum != curImgDesc->vNum) {
! // image is newer
! if (curImgDesc->vNum == DELUGE_INVALID_VNUM
! || (cmpImgDesc->vNum != DELUGE_INVALID_VNUM
! && (cmpImgDesc->vNum - curImgDesc->vNum) > 0))
! call Metadata.setupNewImage(&(rxAdvMsg->imgDesc));
! }
! // image is larger
! else if (cmpImgDesc->numPgsComplete > curImgDesc->numPgsComplete) {
! if (imgNum == DELUGE_GOLDEN_IMAGE_NUM
! || advTimers[imgNum-1].newAdvs == 0)
! call PageTransfer.dataAvailable(rxAdvMsg->sourceAddr, imgNum);
! }
! // image is smaller
! else if (cmpImgDesc->numPgsComplete < curImgDesc->numPgsComplete) {
! if (imgNum != DELUGE_GOLDEN_IMAGE_NUM)
! advTimers[imgNum-1].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;
! }
! // image is the same
! else {
! if (imgNum == DELUGE_GOLDEN_IMAGE_NUM)
! imgNum = 1;
! advTimers[imgNum-1].overheard = 1;
! isEqual = TRUE;
! }
!
! if (!isEqual || rxAdvMsg->nodeDesc.vNum != nodeDesc.vNum) {
! if (imgNum == DELUGE_GOLDEN_IMAGE_NUM)
! imgNum = 1;
! resetTimer(imgNum-1);
}
}
--- 283,321 ----
}
! // don't do anything with the image descriptor if it is corrupt
! // or if the images have not been mounted
! if ( call Metadata.isImgDescValid(&(rxAdvMsg->imgDesc))
! && state == S_ENABLED ) {
! // don't listen to advertisements about the golden image
! // unless it's from the PC and source address is TOS_UART_ADDR
! if (imgNum != DELUGE_GOLDEN_IMAGE_NUM
! || (rxAdvMsg->type == DELUGE_ADV_PC && rxAdvMsg->sourceAddr == TOS_UART_ADDR)) {
!
! if (cmpImgDesc->vNum != curImgDesc->vNum) {
! // image is newer
! if (curImgDesc->vNum == DELUGE_INVALID_VNUM
! || (cmpImgDesc->vNum != DELUGE_INVALID_VNUM
! && (cmpImgDesc->vNum - curImgDesc->vNum) > 0))
! call Metadata.setupNewImage(&(rxAdvMsg->imgDesc));
! }
! // image is larger
! else if (cmpImgDesc->numPgsComplete > curImgDesc->numPgsComplete) {
! if (advTimers[imgNum].newAdvs == 0)
! call PageTransfer.dataAvailable(rxAdvMsg->sourceAddr, imgNum);
! }
! // image is smaller
! else if (cmpImgDesc->numPgsComplete < curImgDesc->numPgsComplete) {
! advTimers[imgNum].newAdvs = DELUGE_NUM_NEWDATA_ADVS_REQUIRED;
! }
! // image is the same
! else {
! advTimers[imgNum].overheard = 1;
! isEqual = TRUE;
! }
!
! if ( !isEqual )
! resetTimer(imgNum);
!
}
}
***************
*** 332,345 ****
&& rxAdvMsg->nodeDesc.vNum != DELUGE_INVALID_VNUM
&& call Metadata.isComplete(rxAdvMsg->nodeDesc.imgNum)) {
- imgnum_t tmpImgNum = (imgNum > 0) ? imgNum : 1;
call Leds.yellowOn();
nodeDesc = rxAdvMsg->nodeDesc;
rebootDelay = DELUGE_REBOOT_DELAY;
! resetTimer(tmpImgNum-1);
if (rxAdvMsg->sourceAddr == TOS_UART_ADDR
|| rxAdvMsg->type == DELUGE_ADV_PC)
! sendAdvMsg(tmpImgNum, rxAdvMsg->sourceAddr);
}
return pMsg;
--- 324,339 ----
&& rxAdvMsg->nodeDesc.vNum != DELUGE_INVALID_VNUM
&& call Metadata.isComplete(rxAdvMsg->nodeDesc.imgNum)) {
call Leds.yellowOn();
nodeDesc = rxAdvMsg->nodeDesc;
rebootDelay = DELUGE_REBOOT_DELAY;
! resetTimer(imgNum);
if (rxAdvMsg->sourceAddr == TOS_UART_ADDR
|| rxAdvMsg->type == DELUGE_ADV_PC)
! sendAdvMsg(imgNum, rxAdvMsg->sourceAddr);
}
+ if ( rxAdvMsg->nodeDesc.vNum != nodeDesc.vNum )
+ resetTimer(imgNum);
+
return pMsg;
***************
*** 356,361 ****
event void PageTransfer.suppressMsgs(imgnum_t imgNum) {
! if (imgNum != DELUGE_GOLDEN_IMAGE_NUM)
! advTimers[imgNum-1].overheard = 1;
}
--- 350,354 ----
event void PageTransfer.suppressMsgs(imgnum_t imgNum) {
! advTimers[imgNum].overheard = 1;
}
Index: DelugeMetadataM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataM.nc,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** DelugeMetadataM.nc 29 Jun 2005 01:07:13 -0000 1.19
--- DelugeMetadataM.nc 29 Jun 2005 21:08:14 -0000 1.20
***************
*** 74,78 ****
command result_t SplitControl.start() {
! call Timer.start(TIMER_ONE_SHOT, 32);
return SUCCESS;
}
--- 74,79 ----
command result_t SplitControl.start() {
! if ( state == S_INIT )
! call Timer.start(TIMER_ONE_SHOT, 32);
return SUCCESS;
}
***************
*** 178,181 ****
--- 179,183 ----
imgDesc[curImage].numPgs = 0;
imgDesc[curImage].numPgsComplete = 0;
+ imgDesc[curImage].crc = call Crc.crc16(&imgDesc[curImage], 8);
scanNextImage();
return;
***************
*** 255,265 ****
command bool Metadata.isImgDescValid[uint8_t id](DelugeImgDesc* tmpImgDesc) {
! return (tmpImgDesc->crc == call Crc.crc16(tmpImgDesc, 8));
}
command bool Metadata.isComplete[uint8_t id](imgnum_t imgNum) {
! return ( imgDesc[imgNum].numPgs == imgDesc[imgNum].numPgsComplete
! && imgDesc[imgNum].numPgs != DELUGE_INVALID_PGNUM
! && imgDesc[imgNum].numPgs );
}
--- 257,269 ----
command bool Metadata.isImgDescValid[uint8_t id](DelugeImgDesc* tmpImgDesc) {
! return ( tmpImgDesc->crc == call Crc.crc16(tmpImgDesc, 8)
! && tmpImgDesc->crc != 0 );
}
command bool Metadata.isComplete[uint8_t id](imgnum_t imgNum) {
! return ( (imgDesc[imgNum].numPgs == imgDesc[imgNum].numPgsComplete
! && imgDesc[imgNum].numPgs != DELUGE_INVALID_PGNUM
! && imgDesc[imgNum].numPgs )
! || imgNum == DELUGE_GOLDEN_IMAGE_NUM );
}
Index: DelugeStorage.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeStorage.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** DelugeStorage.nc 11 Mar 2005 21:46:38 -0000 1.4
--- DelugeStorage.nc 29 Jun 2005 21:08:15 -0000 1.5
***************
*** 29,32 ****
--- 29,34 ----
*/
+ includes TOSBoot;
+
interface DelugeStorage {
command result_t loadImages();
Index: DelugeStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeStorageM.nc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** DelugeStorageM.nc 17 May 2005 20:55:48 -0000 1.9
--- DelugeStorageM.nc 29 Jun 2005 21:08:15 -0000 1.10
***************
*** 127,130 ****
--- 127,132 ----
command uint32_t DelugeStorage.imgNum2Addr(imgnum_t imgNum) {
+ if (imgNum == DELUGE_GOLDEN_IMAGE_NUM)
+ return TOSBOOT_GOLDEN_IMG_ADDR;
return call StorageRemap.physicalAddr[DELUGE_IMAGES[imgNum].imageNum](0);
}
Index: NetProgM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/NetProgM.nc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** NetProgM.nc 27 Jun 2005 18:01:12 -0000 1.8
--- NetProgM.nc 29 Jun 2005 21:08:15 -0000 1.9
***************
*** 110,131 ****
command result_t NetProg.programImgAndReboot(imgnum_t newImgNum) {
- if (call Metadata.isComplete(newImgNum)) {
#ifndef PLATFORM_PC
! uint32_t imageAddr;
! uint8_t flags;
! atomic {
! NETPROG_DISABLE_WDT();
! writeTOSinfo();
!
! imageAddr = call Storage.imgNum2Addr(newImgNum);
! call IFlash.write((uint16_t*)TOSBOOT_NEW_IMG_START_ADDR, &imageAddr, sizeof(imageAddr));
! call IFlash.read((uint8_t*)TOSBOOT_FLAGS_ADDR, &flags, sizeof(flags));
! flags &= ~TOSBOOT_REPROGRAM;
! call IFlash.write((uint8_t*)TOSBOOT_FLAGS_ADDR, &flags, sizeof(flags));
!
! // reboot
! NETPROG_ACTUAL_REBOOT();
! }
#endif
}
--- 110,129 ----
command result_t NetProg.programImgAndReboot(imgnum_t newImgNum) {
#ifndef PLATFORM_PC
! uint32_t imageAddr;
! uint8_t flags;
!
! atomic {
! NETPROG_DISABLE_WDT();
! writeTOSinfo();
! imageAddr = call Storage.imgNum2Addr(newImgNum);
! call IFlash.write((uint16_t*)TOSBOOT_NEW_IMG_START_ADDR, &imageAddr, sizeof(imageAddr));
! call IFlash.read((uint8_t*)TOSBOOT_FLAGS_ADDR, &flags, sizeof(flags));
! flags &= ~TOSBOOT_REPROGRAM;
! call IFlash.write((uint8_t*)TOSBOOT_FLAGS_ADDR, &flags, sizeof(flags));
!
! // reboot
! NETPROG_ACTUAL_REBOOT();
#endif
}
More information about the Tinyos-beta-commits
mailing list