[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/Deluge DelugeStats.nc, NONE, 1.1 Deluge.h, 1.7, 1.8 DelugeM.nc, 1.14, 1.15 DelugeMetadata.nc, 1.5, 1.6 DelugeMetadataC.nc, 1.5, 1.6 DelugeMetadataM.nc, 1.13, 1.14 DelugePageTransferC.nc, 1.5, 1.6 DelugePageTransferM.nc, 1.8, 1.9

Jonathan Hui jwhui at users.sourceforge.net
Wed Apr 20 16:27:02 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28884

Modified Files:
	Deluge.h DelugeM.nc DelugeMetadata.nc DelugeMetadataC.nc 
	DelugeMetadataM.nc DelugePageTransferC.nc 
	DelugePageTransferM.nc 
Added Files:
	DelugeStats.nc 
Log Message:
- Added DelugeStats interface, allowing other components to query
deluge progress state.

- Some code cleanup that saves a teeny weeny bit of ROM.



--- NEW FILE: DelugeStats.nc ---

interface DelugeStats {

  command pgnum_t getNumPgs(imgnum_t imgNum);
  command pgnum_t getNumPgsComplete(imgnum_t imgNum);

}

Index: Deluge.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/Deluge.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Deluge.h	11 Mar 2005 21:46:37 -0000	1.7
--- Deluge.h	20 Apr 2005 23:26:59 -0000	1.8
***************
*** 50,59 ****
    DELUGE_DATA_OFFSET                = 128,
    DELUGE_IDENT_SIZE                 = 128,
!   DELUGE_INVALID_ADDR               = ((uint32_t)0x7fffffff),
!   DELUGE_MAX_REQ_DELAY              = (0x1 << (DELUGE_MIN_ADV_PERIOD_LOG2-1)),
    DELUGE_NACK_TIMEOUT               = (DELUGE_MAX_REQ_DELAY >> 0x1),
    DELUGE_BYTES_PER_PAGE             = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
    DELUGE_PKT_BITVEC_SIZE            = (((DELUGE_PKTS_PER_PAGE-1) / 8) + 1),
!   DELUGE_MAX_IMAGE_SIZE             = ((uint32_t)128*(uint32_t)1024),
    DELUGE_MAX_PAGES                  = 128,
    DELUGE_CRC_SIZE                   = sizeof(uint16_t),
--- 50,59 ----
    DELUGE_DATA_OFFSET                = 128,
    DELUGE_IDENT_SIZE                 = 128,
!   DELUGE_INVALID_ADDR               = (0x7fffffffL),
!   DELUGE_MAX_REQ_DELAY              = (0x1L << (DELUGE_MIN_ADV_PERIOD_LOG2-1)),
    DELUGE_NACK_TIMEOUT               = (DELUGE_MAX_REQ_DELAY >> 0x1),
    DELUGE_BYTES_PER_PAGE             = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
    DELUGE_PKT_BITVEC_SIZE            = (((DELUGE_PKTS_PER_PAGE-1) / 8) + 1),
!   DELUGE_MAX_IMAGE_SIZE             = (128L*1024L),
    DELUGE_MAX_PAGES                  = 128,
    DELUGE_CRC_SIZE                   = sizeof(uint16_t),

Index: DelugeM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeM.nc,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** DelugeM.nc	18 Mar 2005 01:13:27 -0000	1.14
--- DelugeM.nc	20 Apr 2005 23:26:59 -0000	1.15
***************
*** 92,99 ****
  
      minTimer = findMinTimer();
!     
!     if (advTimers[minTimer].timer < 2)
!       advTimers[minTimer].timer += 2;
!     
      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);
***************
*** 104,108 ****
      uint8_t i;
      for ( i = 0; i < DELUGE_NUM_TIMERS; i++ ) {
!       if (advTimers[i].timer >= advTimers[minTimer].timer)
  	advTimers[i].timer -= advTimers[minTimer].timer;
      }
--- 101,105 ----
      uint8_t i;
      for ( i = 0; i < DELUGE_NUM_TIMERS; i++ ) {
!       if ((advTimers[i].timer - 2) >= advTimers[minTimer].timer)
  	advTimers[i].timer -= advTimers[minTimer].timer;
      }
***************
*** 116,126 ****
      for ( i = 0; i < DELUGE_NUM_IMAGES; i++ ) {
        call Metadata.getImgDesc(i, &imgDesc);
!       if (imgDesc.numPgs != imgDesc.numPgsComplete)
  	break;
      }
  
-     if (i < DELUGE_NUM_IMAGES)
-       call PageTransfer.setWorkingPage(i, imgDesc.numPgsComplete);
- 
    }
  
--- 113,122 ----
      for ( i = 0; i < DELUGE_NUM_IMAGES; i++ ) {
        call Metadata.getImgDesc(i, &imgDesc);
!       if (imgDesc.numPgs != imgDesc.numPgsComplete) {
! 	call PageTransfer.setWorkingPage(i, imgDesc.numPgsComplete);
  	break;
+       }
      }
  
    }
  
***************
*** 186,196 ****
  
    void sendAdvMsg(uint8_t imgNum, uint16_t addr) {
      if (!call SharedMsgBuf.isLocked()) {
-       TOS_MsgPtr pMsgBuf = call SharedMsgBuf.getMsgBuf();
-       DelugeAdvMsg* pMsg = (DelugeAdvMsg*)pMsgBuf->data;
        pMsg->sourceAddr = TOS_LOCAL_ADDRESS;
        pMsg->version = DELUGE_VERSION;
        pMsg->type = DELUGE_ADV_NORMAL;
!       pMsg->nodeDesc = nodeDesc;
        call Metadata.getImgDesc(imgNum, &(pMsg->imgDesc));
        if (call SendAdvMsg.send(addr, sizeof(DelugeAdvMsg), pMsgBuf) == SUCCESS) {
--- 182,194 ----
  
    void sendAdvMsg(uint8_t imgNum, uint16_t addr) {
+ 
+     TOS_MsgPtr pMsgBuf = call SharedMsgBuf.getMsgBuf();
+     DelugeAdvMsg* pMsg = (DelugeAdvMsg*)pMsgBuf->data;
+ 
      if (!call SharedMsgBuf.isLocked()) {
        pMsg->sourceAddr = TOS_LOCAL_ADDRESS;
        pMsg->version = DELUGE_VERSION;
        pMsg->type = DELUGE_ADV_NORMAL;
!       memcpy(&(pMsg->nodeDesc), &nodeDesc, sizeof(nodeDesc));
        call Metadata.getImgDesc(imgNum, &(pMsg->imgDesc));
        if (call SendAdvMsg.send(addr, sizeof(DelugeAdvMsg), pMsgBuf) == SUCCESS) {
***************
*** 199,202 ****
--- 197,201 ----
        }
      }
+ 
    }
  
***************
*** 224,233 ****
  
      if (rebootDelay > 0) {
!       if (rebootDelay == 1) {
  	call IFlash.write((uint16_t*)IFLASH_NODE_DESC_ADDR, &nodeDesc, sizeof(nodeDesc));
  	// will not return on SUCCESS
  	call NetProg.programImgAndReboot(nodeDesc.imgNum);
        }
-       rebootDelay--;
      }
      else if (advTimers[minTimer].newAdvs == 0
--- 223,231 ----
  
      if (rebootDelay > 0) {
!       if (!(--rebootDelay)) {
  	call IFlash.write((uint16_t*)IFLASH_NODE_DESC_ADDR, &nodeDesc, sizeof(nodeDesc));
  	// will not return on SUCCESS
  	call NetProg.programImgAndReboot(nodeDesc.imgNum);
        }
      }
      else if (advTimers[minTimer].newAdvs == 0
***************
*** 261,265 ****
      if (state != S_ENABLED)
        return pMsg;
! 
      if (rxAdvMsg->version != DELUGE_VERSION
  	|| !call Metadata.isImgDescValid(&(rxAdvMsg->imgDesc))
--- 259,263 ----
      if (state != S_ENABLED)
        return pMsg;
!     
      if (rxAdvMsg->version != DELUGE_VERSION
  	|| !call Metadata.isImgDescValid(&(rxAdvMsg->imgDesc))
***************
*** 315,319 ****
        setupAdvTimer(tmpImgNum-1);
        if (rxAdvMsg->sourceAddr == TOS_UART_ADDR
! 	  || rxAdvMsg->sourceAddr == TOS_BCAST_ADDR)
  	sendAdvMsg(imgNum, rxAdvMsg->sourceAddr);
      }
--- 313,317 ----
        setupAdvTimer(tmpImgNum-1);
        if (rxAdvMsg->sourceAddr == TOS_UART_ADDR
! 	  || rxAdvMsg->type == DELUGE_ADV_PC)
  	sendAdvMsg(imgNum, rxAdvMsg->sourceAddr);
      }

Index: DelugeMetadata.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadata.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DelugeMetadata.nc	18 Mar 2005 01:13:28 -0000	1.5
--- DelugeMetadata.nc	20 Apr 2005 23:26:59 -0000	1.6
***************
*** 37,41 ****
    command dm_cmp_t compareImgDesc(DelugeImgDesc* imgDesc);
    command imgvnum_t getVNum(imgnum_t imgNum);
-   command pgnum_t getNumPgsComplete(imgnum_t imgNum);
  
    command result_t setupNewImage(DelugeImgDesc* imgDesc);
--- 37,40 ----

Index: DelugeMetadataC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataC.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DelugeMetadataC.nc	18 Mar 2005 01:13:28 -0000	1.5
--- DelugeMetadataC.nc	20 Apr 2005 23:26:59 -0000	1.6
***************
*** 34,37 ****
--- 34,38 ----
  configuration DelugeMetadataC {
    provides {
+     interface DelugeStats;
      interface DelugeMetadata as Metadata[uint8_t id];
      interface SplitControl;
***************
*** 49,52 ****
--- 50,54 ----
  
    SplitControl = DelugeMetadataM;
+   DelugeStats = DelugeMetadataM;
    Metadata = DelugeMetadataM;
  

Index: DelugeMetadataM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugeMetadataM.nc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** DelugeMetadataM.nc	18 Mar 2005 01:13:28 -0000	1.13
--- DelugeMetadataM.nc	20 Apr 2005 23:26:59 -0000	1.14
***************
*** 33,36 ****
--- 33,37 ----
      interface SplitControl;
      interface DelugeMetadata as Metadata[uint8_t id];
+     interface DelugeStats;
    }
    uses {
***************
*** 237,241 ****
    }
  
!   command pgnum_t Metadata.getNumPgsComplete[uint8_t id](imgnum_t imgNum) {
      return imgDesc[imgNum].numPgsComplete;
    }
--- 238,246 ----
    }
  
!   command pgnum_t DelugeStats.getNumPgs(imgnum_t imgNum) {
!     return imgDesc[imgNum].numPgs;
!   }
! 
!   command pgnum_t DelugeStats.getNumPgsComplete(imgnum_t imgNum) {
      return imgDesc[imgNum].numPgsComplete;
    }

Index: DelugePageTransferC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugePageTransferC.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DelugePageTransferC.nc	9 Feb 2005 00:48:33 -0000	1.5
--- DelugePageTransferC.nc	20 Apr 2005 23:26:59 -0000	1.6
***************
*** 65,68 ****
--- 65,69 ----
    DelugePageTransferM.DataRead -> Storage.DataRead[unique("DelugeDataRead")];
    DelugePageTransferM.DataWrite -> Storage.DataWrite[unique("DelugeDataWrite")];
+   DelugePageTransferM.DelugeStats -> Metadata;
    DelugePageTransferM.Metadata -> Metadata.Metadata[unique("DelugeMetadata")];
    DelugePageTransferM.Random -> RandomLFSR;

Index: DelugePageTransferM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/Deluge/DelugePageTransferM.nc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** DelugePageTransferM.nc	18 Mar 2005 01:13:28 -0000	1.8
--- DelugePageTransferM.nc	20 Apr 2005 23:26:59 -0000	1.9
***************
*** 39,42 ****
--- 39,43 ----
      interface DelugeDataRead as DataRead;
      interface DelugeDataWrite as DataWrite;
+     interface DelugeStats;
      interface Leds;
      interface Random;
***************
*** 150,157 ****
    command result_t PageTransfer.dataAvailable(uint16_t sourceAddr, imgnum_t imgNum) {
  
!     if (workingImgNum == DELUGE_INVALID_IMGNUM
! 	|| workingImgNum != imgNum)
        return FAIL;
! 
      if (state == S_IDLE) {
        // currently idle, so request data from source
--- 151,157 ----
    command result_t PageTransfer.dataAvailable(uint16_t sourceAddr, imgnum_t imgNum) {
  
!     if (workingImgNum != imgNum)
        return FAIL;
!     
      if (state == S_IDLE) {
        // currently idle, so request data from source
***************
*** 162,166 ****
        // randomize request to prevent collision
        call ReqTimer.start(TIMER_ONE_SHOT, DELUGE_MIN_DELAY + 
! 			  call Random.rand() % DELUGE_MAX_REQ_DELAY);
      }
      
--- 162,166 ----
        // randomize request to prevent collision
        call ReqTimer.start(TIMER_ONE_SHOT, DELUGE_MIN_DELAY + 
! 			  (call Random.rand() % DELUGE_MAX_REQ_DELAY));
      }
      
***************
*** 199,203 ****
        // suppress request
        call ReqTimer.start(TIMER_ONE_SHOT, DELUGE_NACK_TIMEOUT +
! 			  call Random.rand() % DELUGE_NACK_TIMEOUT);
        vars.rx.suppressReq = FALSE;
        return;
--- 199,203 ----
        // suppress request
        call ReqTimer.start(TIMER_ONE_SHOT, DELUGE_NACK_TIMEOUT +
! 			  (call Random.rand() % DELUGE_NACK_TIMEOUT));
        vars.rx.suppressReq = FALSE;
        return;
***************
*** 246,284 ****
        return pMsg;
  
!     if (rxDataMsg->imgNum <= workingImgNum
! 	&& rxDataMsg->pgNum <= workingPgNum) {
!       
!       if (state == S_RECEIVING || state == S_RX_LOCKING) {
! 	// suppress next request since nodes are still sending
! 	vars.rx.suppressReq = TRUE;
!       }
! 
!       if (dataQLen < DELUGE_DATA_Q_SIZE
! 	  && rxDataMsg->vNum == call Metadata.getVNum(workingImgNum)
! 	  && rxDataMsg->imgNum == workingImgNum
! 	  && rxDataMsg->pgNum == workingPgNum
! 	  && BITVEC_GET(pktsToReceive, rxDataMsg->pktNum)) {
! 	// got a packet we need
! 	call Leds.set(rxDataMsg->pktNum);
  
! 	dbg(DBG_USR1, "DELUGE: SAVING(pgNum=%d,pktNum=%d)\n", 
! 	    rxDataMsg->pgNum,rxDataMsg->pktNum);
! 	
! 	// copy data
! 	dataQ[(dataQHead+dataQLen)%DELUGE_DATA_Q_SIZE].pktNum = rxDataMsg->pktNum;
! 	memcpy(dataQ[(dataQHead+dataQLen)%DELUGE_DATA_Q_SIZE].data, rxDataMsg->data, DELUGE_PKT_PAYLOAD_SIZE);
! 	dataQLen++;
! 	if (dataQLen == 1) {
! 	  if (post writeData() == FAIL) {
! 	    dataQLen = 0;
! 	    return pMsg;
! 	  }
  	}
- 
- 	// mark packet as received in request packet
- 	BITVEC_CLEAR(pktsToReceive, rxDataMsg->pktNum);
- 	if (state == S_RECEIVING)
- 	  BITVEC_CLEAR(pReqMsg->requestedPkts, rxDataMsg->pktNum);
        }
      }
  
--- 246,280 ----
        return pMsg;
  
!     if (state == S_RECEIVING || state == S_RX_LOCKING) {
!       // suppress next request since nodes are still sending
!       vars.rx.suppressReq = TRUE;
!     }
  
!     if (dataQLen < DELUGE_DATA_Q_SIZE
! 	&& rxDataMsg->vNum == call Metadata.getVNum(workingImgNum)
! 	&& rxDataMsg->imgNum == workingImgNum
! 	&& rxDataMsg->pgNum == workingPgNum
! 	&& BITVEC_GET(pktsToReceive, rxDataMsg->pktNum)) {
!       // got a packet we need
!       call Leds.set(rxDataMsg->pktNum);
!       
!       dbg(DBG_USR1, "DELUGE: SAVING(pgNum=%d,pktNum=%d)\n", 
! 	  rxDataMsg->pgNum,rxDataMsg->pktNum);
!       
!       // copy data
!       dataQ[(dataQHead+dataQLen)%DELUGE_DATA_Q_SIZE].pktNum = rxDataMsg->pktNum;
!       memcpy(dataQ[(dataQHead+dataQLen)%DELUGE_DATA_Q_SIZE].data, rxDataMsg->data, DELUGE_PKT_PAYLOAD_SIZE);
!       dataQLen++;
!       if (dataQLen == 1) {
! 	if (post writeData() == FAIL) {
! 	  dataQLen = 0;
! 	  return pMsg;
  	}
        }
+       
+       // mark packet as received in request packet
+       BITVEC_CLEAR(pktsToReceive, rxDataMsg->pktNum);
+       if (state == S_RECEIVING)
+ 	BITVEC_CLEAR(pReqMsg->requestedPkts, rxDataMsg->pktNum);
      }
  
***************
*** 288,291 ****
--- 284,288 ----
  
    void setupDataMsg() {
+ 
      TOS_MsgPtr pMsgBuf = call SharedMsgBuf.getMsgBuf();
      DelugeDataMsg* pDataMsg = (DelugeDataMsg*)(pMsgBuf->data);
***************
*** 330,335 ****
  
      DelugeReqMsg *rxReqMsg = (DelugeReqMsg*)(pMsg->data);
-     imgnum_t tmpImgNum;
-     pgnum_t  tmpPgNum;
      int i;
  
--- 327,330 ----
***************
*** 341,374 ****
  
      if (state == S_SENDING || state == S_TX_LOCKING) {
!       tmpImgNum = vars.tx.imgToSend;
!       tmpPgNum = vars.tx.pageToSend;
!     }
!     else {
!       tmpImgNum = workingImgNum;
!       tmpPgNum = workingPgNum;
!     }
! 
!     if (rxReqMsg->imgNum < tmpImgNum
! 	|| (rxReqMsg->imgNum == tmpImgNum
! 	    && (rxReqMsg->vNum - call Metadata.getVNum(tmpImgNum) > 0
! 		|| (rxReqMsg->vNum == call Metadata.getVNum(tmpImgNum)
! 		    && rxReqMsg->pgNum < tmpPgNum)))) {
!       if (state == S_SENDING || state == S_TX_LOCKING) {
  	changeState(S_IDLE);
  	memset(pktsToSend, 0x0, DELUGE_PKT_BITVEC_SIZE);
        }
      }
! 
!     if (rxReqMsg->dest != TOS_LOCAL_ADDRESS) {
!       if ((state == S_RECEIVING || state == S_RX_LOCKING)
! 	  && rxReqMsg->imgNum <= workingImgNum
! 	  && rxReqMsg->pgNum <= workingPgNum) {
! 	// suppress next request since similar request has been overheard
! 	vars.rx.suppressReq = TRUE;
        }
-       return pMsg;
      }
  
!     if (rxReqMsg->pgNum >= call Metadata.getNumPgsComplete(rxReqMsg->imgNum)
  	|| rxReqMsg->vNum != call Metadata.getVNum(rxReqMsg->imgNum)) {
        // don't have this page, ignore request
--- 336,360 ----
  
      if (state == S_SENDING || state == S_TX_LOCKING) {
!       if (rxReqMsg->imgNum < vars.tx.imgToSend
! 	  || (rxReqMsg->imgNum == vars.tx.imgToSend
! 	      && (rxReqMsg->vNum - call Metadata.getVNum(vars.tx.imgToSend) > 0
! 		  || (rxReqMsg->vNum == call Metadata.getVNum(vars.tx.imgToSend)
! 		      && rxReqMsg->pgNum < vars.tx.pageToSend)))) {
  	changeState(S_IDLE);
  	memset(pktsToSend, 0x0, DELUGE_PKT_BITVEC_SIZE);
        }
      }
!     else if (state == S_RECEIVING || state == S_RX_LOCKING) {
!       if (rxReqMsg->dest != TOS_LOCAL_ADDRESS) {
! 	if (rxReqMsg->imgNum <= workingImgNum
! 	    && rxReqMsg->pgNum <= workingPgNum) {
! 	  // suppress next request since similar request has been overheard
! 	  vars.rx.suppressReq = TRUE;
! 	}
! 	return pMsg;
        }
      }
  
!     if (rxReqMsg->pgNum >= call DelugeStats.getNumPgsComplete(rxReqMsg->imgNum)
  	|| rxReqMsg->vNum != call Metadata.getVNum(rxReqMsg->imgNum)) {
        // don't have this page, ignore request



More information about the Tinyos-beta-commits mailing list