[Tinyos-beta-commits] CVS: tinyos-1.x/beta/STM25P/STM25P BlockStorageM.nc, 1.2, 1.3 HALSTM25PM.nc, 1.2, 1.3 SectorStorage.nc, 1.2, 1.3 StorageManagerM.nc, 1.4, 1.5

Jonathan Hui jwhui at users.sourceforge.net
Thu Mar 17 17:12:53 PST 2005


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

Modified Files:
	BlockStorageM.nc HALSTM25PM.nc SectorStorage.nc 
	StorageManagerM.nc 
Log Message:
- Simplified implementation.



Index: BlockStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockStorageM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** BlockStorageM.nc	15 Mar 2005 06:23:21 -0000	1.2
--- BlockStorageM.nc	18 Mar 2005 01:12:35 -0000	1.3
***************
*** 55,59 ****
    uint8_t client;
  
!   block_addr_t rwAddr, rwLen, curAddr;
    uint8_t* rwBuf;
    uint16_t crc;
--- 55,59 ----
    uint8_t client;
  
!   block_addr_t rwAddr, rwLen;
    uint8_t* rwBuf;
    uint16_t crc;
***************
*** 67,85 ****
    }
  
-   bool admitRequest(blockstorage_t blockId) {
-     if (state != S_IDLE)
-       return FALSE;
-     client = blockId;
-     return TRUE;
-   }
- 
-   result_t check(result_t result) {
-     if (result == FAIL) {
-       state = S_IDLE;
-       return FAIL;
-     }
-     return SUCCESS;
-   }
-   
    void signalDone(storage_result_t result) {
      uint8_t tmpState = state;
--- 67,70 ----
***************
*** 99,244 ****
    }
  
!   block_addr_t calcNumBytes() {
! 
!     block_addr_t pageOffset = curAddr % STORAGE_BLOCK_SIZE;
!     block_addr_t numBytes = STORAGE_BLOCK_SIZE - pageOffset;
!     block_addr_t bytesRemaining = rwAddr + rwLen - curAddr;
! 
!     if ( bytesRemaining < numBytes )
!       numBytes = bytesRemaining;
! 
!     return numBytes;
! 
!   }
! 
!   command result_t BlockRead.read[blockstorage_t blockId](block_addr_t addr, uint8_t* buf, block_addr_t len) {
  
!     block_addr_t lastBytes;
  
!     if (admitRequest(blockId) == FAIL)
        return FAIL;
  
      rwAddr = addr;
      rwBuf = buf;
      rwLen = len;
  
!     for ( curAddr = addr; curAddr < addr + len; curAddr += lastBytes, buf += lastBytes ) {
!       lastBytes = calcNumBytes();
!       if (call SectorStorage.read[blockId](curAddr, buf, lastBytes) == FAIL)
! 	return FAIL;
      }
  
!     if (post signalDoneTask() == SUCCESS) {
!       state = S_READ;
!       return SUCCESS;
      }
  
!     return FAIL;
  
    }
  
    command result_t BlockRead.verify[blockstorage_t blockId]() {
!     if (admitRequest(blockId) == FAIL)
!       return FAIL;
!     return FAIL;
    }
  
    command result_t BlockRead.computeCrc[blockstorage_t blockId](block_addr_t addr, block_addr_t len) {
! 
!     block_addr_t lastBytes;
! 
!     if (admitRequest(blockId) == FAIL)
!       return FAIL;
! 
!     rwAddr = addr;
!     rwLen = len;
!     
!     for ( curAddr = addr, crc = 0; curAddr < addr + len; curAddr += lastBytes ) {
!       lastBytes = calcNumBytes();
!       if (call SectorStorage.computeCrc[blockId](&crc, crc, curAddr, lastBytes) == FAIL)
! 	return FAIL;
!     }
! 
!     if (post signalDoneTask() == SUCCESS) {
!       state = S_CRC;
!       return SUCCESS;
!     }
! 
!     return FAIL;
! 
    }
  
    command result_t BlockWrite.erase[blockstorage_t blockId]() {
! 
!     if (admitRequest(blockId) == FAIL)
!       return FAIL;
! 
!     state = S_ERASE;
! 
!     rwAddr = call StorageManager.getVolumeSize[blockId]() - STORAGE_BLOCK_SIZE;
! 
!     return check(call SectorStorage.erase[blockId](rwAddr));
! 
    }
  
    command result_t BlockWrite.write[blockstorage_t blockId](block_addr_t addr, uint8_t* buf, block_addr_t len) {
! 
!     if (admitRequest(blockId) == FAIL)
!       return FAIL;
! 
!     curAddr = rwAddr = addr;
!     rwBuf = buf;
!     rwLen = len;
! 
!     state = S_WRITE;
! 
!     return check(call SectorStorage.write[blockId](rwAddr, rwBuf, calcNumBytes()));
! 
    }
    
    command result_t BlockWrite.commit[blockstorage_t blockId]() {
!     
!     if (admitRequest(blockId) == FAIL)
!       return FAIL;
!     
!     return FAIL;
!     
    }
    
    event void SectorStorage.writeDone[blockstorage_t blockId](storage_result_t result) {
! 
!     uint8_t* tmpBuf;
! 
!     curAddr += calcNumBytes();
! 
!     if ( result != STORAGE_OK
! 	 || curAddr >= rwAddr + rwLen ) {
!       signalDone(result);
!       return;
!     }
! 
!     tmpBuf = rwBuf + curAddr - rwAddr;
! 
!     if (call SectorStorage.write[blockId](curAddr, tmpBuf, calcNumBytes()) == FAIL)
!       signalDone(STORAGE_FAIL);
! 
    }
! 
    event void SectorStorage.eraseDone[blockstorage_t blockId](storage_result_t result) {
- 
-     if (result != STORAGE_OK) {
-       signalDone(result);
-       return;
-     }
- 
-     if ( rwAddr > 0 ) {
-       rwAddr -= STORAGE_BLOCK_SIZE;
-       if (call SectorStorage.erase[blockId](rwAddr) == FAIL)
- 	signalDone(STORAGE_FAIL);
-       return;
-     }
-     
      signalDone(result);
-     
    }
  
--- 84,163 ----
    }
  
!   result_t newRequest(uint8_t newState, blockstorage_t blockId, 
! 		      block_addr_t addr, uint8_t* buf, block_addr_t len) {
  
!     result_t result = FAIL;
  
!     if (state != S_IDLE)
        return FAIL;
  
+     client = blockId;
+ 
      rwAddr = addr;
      rwBuf = buf;
      rwLen = len;
  
!     state = newState;
!     switch(newState) {
!     case S_READ:
!       result = call SectorStorage.read[blockId](rwAddr, rwBuf, rwLen);
!       break;
!     case S_CRC:
!       result = call SectorStorage.computeCrc[blockId](&crc, 0, rwAddr, rwLen);
!       break;
!     case S_VERIFY:
!       break;
!     case S_WRITE:
!       result = call SectorStorage.write[blockId](rwAddr, rwBuf, rwLen);
!       break;
!     case S_ERASE:
!       result = call SectorStorage.erase[blockId](0, call StorageManager.getVolumeSize[blockId]());
!       break;
!     case S_COMMIT:
!       break;
      }
  
!     if (state == S_READ || state == S_CRC || state == S_VERIFY) {
!       if (result == SUCCESS) 
! 	result = post signalDoneTask();
      }
+     
+     if (result == FAIL)
+       state = S_IDLE;
  
!     return result;
  
    }
  
+   command result_t BlockRead.read[blockstorage_t blockId](block_addr_t addr, uint8_t* buf, block_addr_t len) {
+     return newRequest(S_READ, blockId, addr, buf, len);
+   }
+ 
    command result_t BlockRead.verify[blockstorage_t blockId]() {
!     return newRequest(S_VERIFY, blockId, 0, NULL, 0);
    }
  
    command result_t BlockRead.computeCrc[blockstorage_t blockId](block_addr_t addr, block_addr_t len) {
!     return newRequest(S_CRC, blockId, addr, NULL, len);
    }
  
    command result_t BlockWrite.erase[blockstorage_t blockId]() {
!     return newRequest(S_ERASE, blockId, 0, NULL, 0);
    }
  
    command result_t BlockWrite.write[blockstorage_t blockId](block_addr_t addr, uint8_t* buf, block_addr_t len) {
!     return newRequest(S_WRITE, blockId, addr, buf, len);
    }
    
    command result_t BlockWrite.commit[blockstorage_t blockId]() {
!     return newRequest(S_COMMIT, blockId, 0, NULL, 0);
    }
    
    event void SectorStorage.writeDone[blockstorage_t blockId](storage_result_t result) {
!     signalDone(result);
    }
!   
    event void SectorStorage.eraseDone[blockstorage_t blockId](storage_result_t result) {
      signalDone(result);
    }
  

Index: HALSTM25PM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25PM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HALSTM25PM.nc	15 Mar 2005 06:23:21 -0000	1.2
--- HALSTM25PM.nc	18 Mar 2005 01:12:50 -0000	1.3
***************
*** 45,54 ****
  
    stm25p_sig_t signature;
!   uint16_t crcScratch;
    uint8_t curCmd;
    volume_t curVolume;
- 
    storage_result_t signalResult;
-   uint8_t returnVal;
  
    void sendCmd(uint8_t cmd, stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
--- 45,52 ----
  
    stm25p_sig_t signature;
!   uint16_t returnVal;
    uint8_t curCmd;
    volume_t curVolume;
    storage_result_t signalResult;
  
    void sendCmd(uint8_t cmd, stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
***************
*** 146,150 ****
        break;
      case STM25P_CRC:
!       call HPLSTM25P.computeCrc(&crcScratch, len);
        break;
      }
--- 144,148 ----
        break;
      case STM25P_CRC:
!       call HPLSTM25P.computeCrc(&returnVal, len);
        break;
      }
***************
*** 226,233 ****
  
    command result_t HALSTM25P.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len) {
!     crcScratch = crc;
      if (newRequest(STM25P_CRC, volume, addr, NULL, len) == FAIL)
        return FAIL;
!     *crcResult = crcScratch;
      return SUCCESS;
    }
--- 224,231 ----
  
    command result_t HALSTM25P.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len) {
!     returnVal = crc;
      if (newRequest(STM25P_CRC, volume, addr, NULL, len) == FAIL)
        return FAIL;
!     *crcResult = returnVal;
      return SUCCESS;
    }

Index: SectorStorage.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/SectorStorage.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SectorStorage.nc	15 Mar 2005 06:23:21 -0000	1.2
--- SectorStorage.nc	18 Mar 2005 01:12:50 -0000	1.3
***************
*** 33,37 ****
    event void writeDone(storage_result_t result);
  
!   command result_t erase(stm25p_addr_t addr);
    event void eraseDone(storage_result_t result);
    
--- 33,37 ----
    event void writeDone(storage_result_t result);
  
!   command result_t erase(stm25p_addr_t addr, stm25p_addr_t len);
    event void eraseDone(storage_result_t result);
    

Index: StorageManagerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManagerM.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** StorageManagerM.nc	15 Mar 2005 07:24:18 -0000	1.4
--- StorageManagerM.nc	18 Mar 2005 01:12:50 -0000	1.5
***************
*** 217,226 ****
  
    command uint32_t StorageRemap.physicalAddr[volume_t volume](uint32_t volumeAddr) {
- 
      if (admitRequest(volume) == FAIL)
!       return FAIL;
! 
      return physicalAddr(volumeAddr);
- 
    }
  
--- 217,223 ----
  
    command uint32_t StorageRemap.physicalAddr[volume_t volume](uint32_t volumeAddr) {
      if (admitRequest(volume) == FAIL)
!       return STM25P_INVALID_ADDR;
      return physicalAddr(volumeAddr);
    }
  
***************
*** 234,241 ****
    }
  
!   stm25p_addr_t calcNumBytes() {
  
!     stm25p_addr_t pageOffset = rwAddr % STM25P_PAGE_SIZE;
!     stm25p_addr_t numBytes = STM25P_PAGE_SIZE - pageOffset;
      
      if ( rwLen < numBytes )
--- 231,238 ----
    }
  
!   stm25p_addr_t calcNumBytes(stm25p_addr_t blockSize) {
  
!     stm25p_addr_t pageOffset = (rwAddr % STORAGE_BLOCK_SIZE) % blockSize;
!     stm25p_addr_t numBytes = blockSize - pageOffset;
      
      if ( rwLen < numBytes )
***************
*** 248,255 ****
    command result_t SectorStorage.read[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
  
      if ( admitRequest(volume) == FAIL )
        return FAIL;
  
!     return call HALSTM25P.read(physicalAddr(addr), data, len);
  
    }
--- 245,264 ----
    command result_t SectorStorage.read[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
  
+     stm25p_addr_t lastBytes;
+ 
      if ( admitRequest(volume) == FAIL )
        return FAIL;
  
!     rwAddr = addr;
!     rwData = data;
!     rwLen = len;
! 
!     for ( ; rwLen > 0; rwAddr += lastBytes, rwData += lastBytes, rwLen -= lastBytes ) {
!       lastBytes = calcNumBytes(STORAGE_BLOCK_SIZE);
!       if (call HALSTM25P.read(physicalAddr(rwAddr), rwData, lastBytes) == FAIL)
! 	return FAIL;
!     }
!     
!     return SUCCESS;
  
    }
***************
*** 260,270 ****
        return FAIL;
  
      rwData = data;
      rwLen = len;
!     rwAddr = physicalAddr(addr);
! 
      state = S_WRITE;
  
!     if (call HALSTM25P.pageProgram(rwAddr, data, calcNumBytes()) == FAIL) {
        state = S_READY;
        return FAIL;
--- 269,279 ----
        return FAIL;
  
+     rwAddr = addr;
      rwData = data;
      rwLen = len;
!     
      state = S_WRITE;
  
!     if (call HALSTM25P.pageProgram(physicalAddr(rwAddr), data, calcNumBytes(STM25P_PAGE_SIZE)) == FAIL) {
        state = S_READY;
        return FAIL;
***************
*** 275,291 ****
    }
  
!   command result_t SectorStorage.erase[volume_t volume](stm25p_addr_t addr) {
! 
!     stm25p_addr_t sector = addr / STORAGE_BLOCK_SIZE;
  
      if ( admitRequest(volume) == FAIL )
        return FAIL;
  
!     rwAddr = STM25P_SECTOR_SIZE*(baseSector[volume]+sector) + STORAGE_BLOCK_SIZE;
!     rwLen = 0;
! 
      state = S_ERASE;
      
!     if (call HALSTM25P.sectorErase(rwAddr) == FAIL) {
        state = S_READY;
        return FAIL;
--- 284,298 ----
    }
  
!   command result_t SectorStorage.erase[volume_t volume](stm25p_addr_t addr, stm25p_addr_t len) {
  
      if ( admitRequest(volume) == FAIL )
        return FAIL;
  
!     rwAddr = addr;
!     rwLen = len;
!     
      state = S_ERASE;
      
!     if (call HALSTM25P.sectorErase(physicalAddr(rwAddr)) == FAIL) {
        state = S_READY;
        return FAIL;
***************
*** 298,305 ****
    command result_t SectorStorage.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len) {
  
      if ( admitRequest(volume) == FAIL )
        return FAIL;
  
!     return call HALSTM25P.computeCrc(crcResult, crc, physicalAddr(addr), len);
  
    }
--- 305,325 ----
    command result_t SectorStorage.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len) {
  
+     stm25p_addr_t lastBytes;
+ 
      if ( admitRequest(volume) == FAIL )
        return FAIL;
  
!     rwAddr = addr;
!     rwLen = len;
!     
!     for ( ; rwLen > 0; rwAddr += lastBytes, rwLen -= lastBytes ) {
!       lastBytes = calcNumBytes(STORAGE_BLOCK_SIZE);
!       if (call HALSTM25P.computeCrc(&crc, crc, physicalAddr(rwAddr), lastBytes) == FAIL)
! 	return FAIL;
!     }
! 
!     *crcResult = crc;
! 
!     return SUCCESS;
  
    }
***************
*** 326,330 ****
      }
  
!     lastBytes = calcNumBytes();
  
      rwAddr += lastBytes;
--- 346,353 ----
      }
  
!     if ( state == S_ERASE )
!       lastBytes = calcNumBytes(STORAGE_BLOCK_SIZE);
!     else
!       lastBytes = calcNumBytes(STM25P_PAGE_SIZE);
  
      rwAddr += lastBytes;
***************
*** 336,347 ****
        return;
      }
!     
!     if (call HALSTM25P.pageProgram(rwAddr, rwData, calcNumBytes()) == FAIL)
!       signalDone(STORAGE_FAIL);
!     
    }
  
    event void HALSTM25P.sectorEraseDone(result_t result) {
!     if (call HALSTM25P.pageProgram(rwAddr, (uint8_t*)&sectorTable, 
  				   sizeof(sectorTable)) == FAIL)
        signalDone(STORAGE_FAIL);
--- 359,377 ----
        return;
      }
! 
!     if (state == S_ERASE) {
!       if (call HALSTM25P.sectorErase(physicalAddr(rwAddr)) == FAIL)
! 	signalDone(STORAGE_FAIL);
!     }
!     else {
!       if (call HALSTM25P.pageProgram(physicalAddr(rwAddr), rwData, calcNumBytes(STM25P_PAGE_SIZE)) == FAIL)
! 	signalDone(STORAGE_FAIL);
!     }   
! 
    }
  
    event void HALSTM25P.sectorEraseDone(result_t result) {
!     stm25p_addr_t addr = rwAddr + calcNumBytes(STORAGE_BLOCK_SIZE) - 1;
!     if (call HALSTM25P.pageProgram(physicalAddr(addr)+1, (uint8_t*)&sectorTable, 
  				   sizeof(sectorTable)) == FAIL)
        signalDone(STORAGE_FAIL);



More information about the Tinyos-beta-commits mailing list