[Tinyos-beta-commits] CVS: tinyos-1.x/beta/STM25P/STM25P
BlockRead.nc, 1.1, 1.2 BlockStorage.h, 1.1,
1.2 BlockStorageC.nc, 1.1, 1.2 BlockStorageM.nc, 1.1,
1.2 BlockWrite.nc, 1.1, 1.2 FlashWP.nc, 1.1, 1.2 FlashWPC.nc,
1.1, 1.2 FlashWPM.nc, 1.1, 1.2 FormatStorage.nc, 1.1,
1.2 FormatStorageC.nc, 1.1, 1.2 FormatStorageM.nc, 1.1,
1.2 HALSTM25P.h, 1.1, 1.2 HALSTM25P.nc, 1.1, 1.2 HALSTM25PC.nc,
1.1, 1.2 HALSTM25PM.nc, 1.1, 1.2 HPLSTM25P.nc, 1.1,
1.2 LogRead.nc, 1.1, 1.2 LogStorage.h, 1.1, 1.2 LogStorageC.nc,
1.1, 1.2 LogStorageM.nc, 1.1, 1.2 LogWrite.nc, 1.1,
1.2 Mount.nc, 1.1, 1.2 SectorStorage.nc, 1.1, 1.2 Storage.h,
1.1, 1.2 StorageManager.nc, 1.1, 1.2 StorageManagerC.nc, 1.1,
1.2 StorageManagerM.nc, 1.1, 1.2 StorageRemap.nc, 1.1,
1.2 Storage_chip.h, 1.1, 1.2
Jonathan Hui
jwhui at users.sourceforge.net
Mon Mar 14 22:23:29 PST 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21236/STM25P
Modified Files:
BlockRead.nc BlockStorage.h BlockStorageC.nc BlockStorageM.nc
BlockWrite.nc FlashWP.nc FlashWPC.nc FlashWPM.nc
FormatStorage.nc FormatStorageC.nc FormatStorageM.nc
HALSTM25P.h HALSTM25P.nc HALSTM25PC.nc HALSTM25PM.nc
HPLSTM25P.nc LogRead.nc LogStorage.h LogStorageC.nc
LogStorageM.nc LogWrite.nc Mount.nc SectorStorage.nc Storage.h
StorageManager.nc StorageManagerC.nc StorageManagerM.nc
StorageRemap.nc Storage_chip.h
Log Message:
- Flash is now formatted automatically to the default partitioning if
it is not formatted. Currently, the default configuration includes
only those pvolumes required for Deluge to function.
- Simplified storage implementation a bit.
Index: BlockRead.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockRead.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BlockRead.nc 11 Mar 2005 21:43:59 -0000 1.1
--- BlockRead.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: BlockStorage.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockStorage.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BlockStorage.h 11 Mar 2005 21:43:59 -0000 1.1
--- BlockStorage.h 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: BlockStorageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockStorageC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BlockStorageC.nc 11 Mar 2005 21:43:59 -0000 1.1
--- BlockStorageC.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: BlockStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockStorageM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BlockStorageM.nc 11 Mar 2005 21:43:59 -0000 1.1
--- BlockStorageM.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 99,107 ****
}
! block_addr_t calcNumBytes(block_addr_t addr) {
! block_addr_t pageOffset = addr % STORAGE_BLOCK_SIZE;
block_addr_t numBytes = STORAGE_BLOCK_SIZE - pageOffset;
! block_addr_t bytesRemaining = rwAddr + rwLen - addr;
if ( bytesRemaining < numBytes )
--- 99,107 ----
}
! 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 )
***************
*** 119,128 ****
return FAIL;
! curAddr = rwAddr = addr;
rwBuf = buf;
rwLen = len;
for ( curAddr = addr; curAddr < addr + len; curAddr += lastBytes, buf += lastBytes ) {
! lastBytes = calcNumBytes(curAddr);
if (call SectorStorage.read[blockId](curAddr, buf, lastBytes) == FAIL)
return FAIL;
--- 119,128 ----
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;
***************
*** 151,159 ****
return FAIL;
! curAddr = rwAddr = addr;
rwLen = len;
for ( curAddr = addr, crc = 0; curAddr < addr + len; curAddr += lastBytes ) {
! lastBytes = calcNumBytes(curAddr);
if (call SectorStorage.computeCrc[blockId](&crc, crc, curAddr, lastBytes) == FAIL)
return FAIL;
--- 151,159 ----
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;
***************
*** 178,215 ****
rwAddr = call StorageManager.getVolumeSize[blockId]() - STORAGE_BLOCK_SIZE;
! return check(call StorageManager.initSwap[blockId]());
!
! }
!
! event void StorageManager.initSwapDone[blockstorage_t blockId](storage_result_t result) {
!
! if (result != STORAGE_OK) {
! signalDone(result);
! return;
! }
!
! if (call StorageManager.commitSwap[blockId](rwAddr) == FAIL)
! signalDone(STORAGE_FAIL);
}
- event void StorageManager.commitSwapDone[blockstorage_t blockId](storage_result_t result) {
-
- if (result != STORAGE_OK) {
- signalDone(result);
- return;
- }
-
- if ( rwAddr > 0 ) {
- rwAddr -= STORAGE_BLOCK_SIZE;
- if (call StorageManager.initSwap[blockId]() == FAIL)
- signalDone(STORAGE_FAIL);
- return;
- }
-
- signalDone(result);
-
- }
-
command result_t BlockWrite.write[blockstorage_t blockId](block_addr_t addr, uint8_t* buf, block_addr_t len) {
--- 178,185 ----
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) {
***************
*** 223,227 ****
state = S_WRITE;
! return check(call SectorStorage.write[blockId](rwAddr, rwBuf, calcNumBytes(rwAddr)));
}
--- 193,197 ----
state = S_WRITE;
! return check(call SectorStorage.write[blockId](rwAddr, rwBuf, calcNumBytes()));
}
***************
*** 238,245 ****
event void SectorStorage.writeDone[blockstorage_t blockId](storage_result_t result) {
- block_addr_t lastBytes = calcNumBytes(curAddr);
uint8_t* tmpBuf;
! curAddr += lastBytes;
if ( result != STORAGE_OK
--- 208,214 ----
event void SectorStorage.writeDone[blockstorage_t blockId](storage_result_t result) {
uint8_t* tmpBuf;
! curAddr += calcNumBytes();
if ( result != STORAGE_OK
***************
*** 251,259 ****
tmpBuf = rwBuf + curAddr - rwAddr;
! if (call SectorStorage.write[blockId](curAddr, tmpBuf, calcNumBytes(curAddr)) == FAIL)
signalDone(STORAGE_FAIL);
}
default event void BlockWrite.writeDone[blockstorage_t blockId](storage_result_t result, block_addr_t addr, uint8_t* buf, block_addr_t len) { ; }
default event void BlockWrite.eraseDone[blockstorage_t blockId](storage_result_t result) { ; }
--- 220,246 ----
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);
+
+ }
+
default event void BlockWrite.writeDone[blockstorage_t blockId](storage_result_t result, block_addr_t addr, uint8_t* buf, block_addr_t len) { ; }
default event void BlockWrite.eraseDone[blockstorage_t blockId](storage_result_t result) { ; }
Index: BlockWrite.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockWrite.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BlockWrite.nc 11 Mar 2005 21:43:59 -0000 1.1
--- BlockWrite.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: FlashWP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FlashWP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FlashWP.nc 11 Mar 2005 21:43:59 -0000 1.1
--- FlashWP.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: FlashWPC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FlashWPC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FlashWPC.nc 11 Mar 2005 21:44:10 -0000 1.1
--- FlashWPC.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: FlashWPM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FlashWPM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FlashWPM.nc 11 Mar 2005 21:44:10 -0000 1.1
--- FlashWPM.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 84,88 ****
event void HALSTM25P.sectorEraseDone(result_t result) { ; }
event void HALSTM25P.bulkEraseDone(result_t result) { ; }
- event void HALSTM25P.readSRDone(result_t result, uint8_t val) { ; }
}
--- 84,87 ----
Index: FormatStorage.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FormatStorage.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FormatStorage.nc 11 Mar 2005 21:44:10 -0000 1.1
--- FormatStorage.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: FormatStorageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FormatStorageC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FormatStorageC.nc 11 Mar 2005 21:44:10 -0000 1.1
--- FormatStorageC.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: FormatStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FormatStorageM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FormatStorageM.nc 11 Mar 2005 21:44:10 -0000 1.1
--- FormatStorageM.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 78,82 ****
for ( i = 0; i < STM25P_NUM_SECTORS; i++ )
sectorTable.sector[i].volumeId = STM25P_INVALID_VOLUME_ID;
- sectorTable.version = 0;
return SUCCESS;
--- 78,81 ----
***************
*** 98,103 ****
size /= STORAGE_BLOCK_SIZE;
!
! for ( i = 0, freeSectors = 0; i < STM25P_NUM_SECTORS; i++ ) {
// check if id is already taken
if (sectorTable.sector[i].volumeId == id)
--- 97,102 ----
size /= STORAGE_BLOCK_SIZE;
!
! for ( i = 0, freeSectors = 0; i < STM25P_NUM_SECTORS && freeSectors < size; i++ ) {
// check if id is already taken
if (sectorTable.sector[i].volumeId == id)
***************
*** 106,109 ****
--- 105,110 ----
if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID)
freeSectors++;
+ else
+ freeSectors = 0;
}
***************
*** 115,120 ****
if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID) {
sectorTable.sector[i].volumeId = id;
- sectorTable.sector[i].sectorId = curSector++;
- sectorTable.sector[i].isFixed = FALSE;
if (--size == 0)
return SUCCESS;
--- 116,119 ----
***************
*** 166,171 ****
if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID) {
sectorTable.sector[i].volumeId = id;
- sectorTable.sector[i].sectorId = curSector++;
- sectorTable.sector[i].isFixed = TRUE;
if (--size == 0)
return SUCCESS;
--- 165,168 ----
***************
*** 260,264 ****
event void HALSTM25P.bulkEraseDone(result_t result) { ; }
- event void HALSTM25P.readSRDone(result_t result, uint8_t val) { ; }
event void HALSTM25P.writeSRDone(result_t result) { ; }
--- 257,260 ----
Index: HALSTM25P.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25P.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HALSTM25P.h 11 Mar 2005 21:44:10 -0000 1.1
--- HALSTM25P.h 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 71,81 ****
typedef struct {
volume_id_t volumeId;
- uint8_t sectorId : 7;
- bool isFixed : 1;
} SectorMetadata;
typedef struct {
SectorMetadata sector[STM25P_NUM_SECTORS];
- int16_t version;
uint16_t crc;
} SectorTable;
--- 71,78 ----
Index: HALSTM25P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25P.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HALSTM25P.nc 11 Mar 2005 21:44:10 -0000 1.1
--- HALSTM25P.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 41,46 ****
event void bulkEraseDone(result_t result);
! command result_t readSR();
! event void readSRDone(result_t result, uint8_t value);
command result_t writeSR(uint8_t value);
--- 41,45 ----
event void bulkEraseDone(result_t result);
! command result_t readSR(uint8_t* value);
command result_t writeSR(uint8_t value);
Index: HALSTM25PC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25PC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HALSTM25PC.nc 11 Mar 2005 21:44:10 -0000 1.1
--- HALSTM25PC.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: HALSTM25PM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25PM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HALSTM25PM.nc 11 Mar 2005 21:44:10 -0000 1.1
--- HALSTM25PM.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 71,79 ****
case STM25P_SE: signal HALSTM25P.sectorEraseDone[curVolume](signalResult); break;
case STM25P_BE: signal HALSTM25P.bulkEraseDone[curVolume](signalResult); break;
- case STM25P_RDSR: signal HALSTM25P.readSRDone[curVolume](signalResult, returnVal); break;
case STM25P_WRSR: signal HALSTM25P.writeSRDone[curVolume](signalResult); break;
}
}
void checkPost(bool result) {
if (result == FAIL) {
--- 71,82 ----
case STM25P_SE: signal HALSTM25P.sectorEraseDone[curVolume](signalResult); break;
case STM25P_BE: signal HALSTM25P.bulkEraseDone[curVolume](signalResult); break;
case STM25P_WRSR: signal HALSTM25P.writeSRDone[curVolume](signalResult); break;
}
}
+ task void signalDone() {
+ actualSignalDone();
+ }
+
void checkPost(bool result) {
if (result == FAIL) {
***************
*** 83,90 ****
}
- task void signalDone() {
- actualSignalDone();
- }
-
bool isWriting() {
uint8_t status;
--- 86,89 ----
***************
*** 173,179 ****
powerOn();
// make sure nothing else is in progress
else if (curCmd != S_POWERON)
return FAIL;
- // make sure we can get the bus
else if (call HPLSTM25P.getBus() == FAIL)
return FAIL;
--- 172,178 ----
powerOn();
// make sure nothing else is in progress
+ // make sure we can get the bus
else if (curCmd != S_POWERON)
return FAIL;
else if (call HPLSTM25P.getBus() == FAIL)
return FAIL;
***************
*** 218,223 ****
}
! command result_t HALSTM25P.readSR[volume_t volume]() {
! return newRequest(STM25P_RDSR, volume, 0, &returnVal, 1);
}
--- 217,222 ----
}
! command result_t HALSTM25P.readSR[volume_t volume](uint8_t* value) {
! return newRequest(STM25P_RDSR, volume, 0, value, 1);
}
***************
*** 241,245 ****
default event void HALSTM25P.sectorEraseDone[volume_t volume](result_t result) { ; }
default event void HALSTM25P.bulkEraseDone[volume_t volume](result_t result) { ; }
- default event void HALSTM25P.readSRDone[volume_t volume](result_t result, uint8_t val) { ; }
default event void HALSTM25P.writeSRDone[volume_t volume](result_t result) { ; }
--- 240,243 ----
Index: HPLSTM25P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HPLSTM25P.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** HPLSTM25P.nc 11 Mar 2005 21:44:10 -0000 1.1
--- HPLSTM25P.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: LogRead.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/LogRead.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LogRead.nc 11 Mar 2005 21:44:10 -0000 1.1
--- LogRead.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: LogStorage.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/LogStorage.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LogStorage.h 11 Mar 2005 21:44:11 -0000 1.1
--- LogStorage.h 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: LogStorageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/LogStorageC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LogStorageC.nc 11 Mar 2005 21:44:11 -0000 1.1
--- LogStorageC.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: LogStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/LogStorageM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LogStorageM.nc 11 Mar 2005 21:44:11 -0000 1.1
--- LogStorageM.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 206,214 ****
command result_t LogRead.seek[logstorage_t logId](log_cookie_t cookie) {
if (admitRequest(logId) == FAIL)
return FAIL;
! return FAIL;
}
--- 206,260 ----
command result_t LogRead.seek[logstorage_t logId](log_cookie_t cookie) {
+
+ log_cookie_t newReadCookie;
+ log_len_t newReadBlockLen;
+ uint8_t sector;
if (admitRequest(logId) == FAIL)
return FAIL;
+
+ sector = cookie / STORAGE_BLOCK_SIZE;
+
+ // read sector header
+ if (call SectorStorage.read[logId](sector, (uint8_t*)§orHeader,
+ sizeof(sectorHeader)) == FAIL)
+ return FAIL;
+ if (!~sectorHeader.cookie)
+ return FAIL;
+
+ newReadCookie = sectorHeader.cookie;
+
+ // scan through
+ newReadBlockLen = 0;
+ while ( newReadCookie < cookie ) {
+
+ // read block header
+ blockHeader.length = 0;
+ do {
+ newReadCookie += blockHeader.length;
+ if (call SectorStorage.read[logId](newReadCookie, (uint8_t*)&blockHeader,
+ sizeof(blockHeader)) == FAIL)
+ return FAIL;
+ } while ( (~blockHeader.flags) & LOG_BLOCK_ALLOCATED
+ && newReadCookie + blockHeader.length < cookie
+ && !( (~blockHeader.flags) & LOG_BLOCK_VALID ) );
+ newReadBlockLen = blockHeader.length - sizeof(LogBlockHeader);
+ newReadCookie += sizeof(LogBlockHeader);
+
+ // advance read cookie
+ if ( newReadCookie + newReadBlockLen > cookie ) {
+ newReadCookie = cookie;
+ newReadBlockLen -= cookie - newReadCookie;
+ }
+ else {
+ newReadCookie += newReadBlockLen;
+ }
+
+ }
! curReadCookie = newReadCookie;
! curReadBlockLen = newReadBlockLen;
!
! return SUCCESS;
}
***************
*** 223,227 ****
curWriteCookie = call StorageManager.getVolumeSize[logId]() - STORAGE_BLOCK_SIZE;
! if (call StorageManager.initSwap[logId]() == FAIL) {
state = S_IDLE;
return FAIL;
--- 269,273 ----
curWriteCookie = call StorageManager.getVolumeSize[logId]() - STORAGE_BLOCK_SIZE;
! if (call SectorStorage.erase[logId](curWriteCookie) == FAIL) {
state = S_IDLE;
return FAIL;
***************
*** 339,343 ****
return FAIL;
! return FAIL;
}
--- 385,402 ----
return FAIL;
! curLen = rwLen = 0;
! blockHeader.length = curWriteBlockPos;
! blockHeader.flags = ~(LOG_BLOCK_VALID + LOG_BLOCK_ALLOCATED);
! lastLen = sizeof(blockHeader);
!
! state = S_SYNC;
!
! if (call SectorStorage.write[client](curWriteCookie-curWriteBlockPos,
! (uint8_t*)&blockHeader, lastLen) == FAIL) {
! state = S_IDLE;
! return FAIL;
! }
!
! return SUCCESS;
}
***************
*** 347,364 ****
}
! event void StorageManager.initSwapDone[logstorage_t logId](storage_result_t result) {
!
! if (result != STORAGE_OK) {
! signalDone(result);
! return;
! }
!
! if (call StorageManager.commitSwap[logId](curWriteCookie) == FAIL)
! signalDone(STORAGE_FAIL);
!
! }
- event void StorageManager.commitSwapDone[logstorage_t logId](storage_result_t result) {
-
if (result != STORAGE_OK) {
signalDone(result);
--- 406,411 ----
}
! event void SectorStorage.eraseDone[logstorage_t logId](storage_result_t result) {
if (result != STORAGE_OK) {
signalDone(result);
***************
*** 369,373 ****
if ( curWriteCookie > 0 ) {
curWriteCookie -= STORAGE_BLOCK_SIZE;
! if (call StorageManager.initSwap[logId]() == FAIL)
signalDone(STORAGE_FAIL);
return;
--- 416,420 ----
if ( curWriteCookie > 0 ) {
curWriteCookie -= STORAGE_BLOCK_SIZE;
! if (call SectorStorage.erase[logId](curWriteCookie) == FAIL)
signalDone(STORAGE_FAIL);
return;
***************
*** 382,386 ****
event void SectorStorage.writeDone[logstorage_t logId](storage_result_t result) {
! if (state != S_COMMIT_BLOCK_HEADER)
curWriteCookie += lastLen;
--- 429,434 ----
event void SectorStorage.writeDone[logstorage_t logId](storage_result_t result) {
! if (state != S_COMMIT_BLOCK_HEADER
! && state != S_SYNC)
curWriteCookie += lastLen;
***************
*** 396,400 ****
curWriteBlockPos += lastLen;
break;
! case S_COMMIT_BLOCK_HEADER:
if (curReadCookie >= curWriteCookie-curWriteBlockPos)
curReadBlockLen = curWriteCookie-curReadCookie;
--- 444,449 ----
curWriteBlockPos += lastLen;
break;
! case S_COMMIT_BLOCK_HEADER:
! case S_SYNC:
if (curReadCookie >= curWriteCookie-curWriteBlockPos)
curReadBlockLen = curWriteCookie-curReadCookie;
Index: LogWrite.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/LogWrite.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LogWrite.nc 11 Mar 2005 21:44:11 -0000 1.1
--- LogWrite.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: Mount.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/Mount.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Mount.nc 11 Mar 2005 21:44:11 -0000 1.1
--- Mount.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: SectorStorage.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/SectorStorage.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SectorStorage.nc 11 Mar 2005 21:44:11 -0000 1.1
--- SectorStorage.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 32,35 ****
--- 32,38 ----
command result_t write(stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
event void writeDone(storage_result_t result);
+
+ command result_t erase(stm25p_addr_t addr);
+ event void eraseDone(storage_result_t result);
command result_t computeCrc(uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len);
Index: Storage.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/Storage.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Storage.h 11 Mar 2005 21:44:11 -0000 1.1
--- Storage.h 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: StorageManager.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManager.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** StorageManager.nc 11 Mar 2005 21:44:11 -0000 1.1
--- StorageManager.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 27,38 ****
interface StorageManager {
-
command stm25p_addr_t getVolumeSize();
-
- command result_t initSwap();
- event void initSwapDone(storage_result_t result);
-
- command result_t commitSwap(stm25p_addr_t addr);
- event void commitSwapDone(storage_result_t result);
-
}
--- 27,30 ----
Index: StorageManagerC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManagerC.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** StorageManagerC.nc 11 Mar 2005 21:44:11 -0000 1.1
--- StorageManagerC.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 29,33 ****
provides {
interface SectorStorage[volume_t volume];
- interface SectorStorage as Swap[volume_t volume];
interface Mount[volume_t volume];
interface StdControl;
--- 29,32 ----
***************
*** 45,49 ****
SectorStorage = StorageManagerM.SectorStorage;
- Swap = StorageManagerM.Swap;
Mount = StorageManagerM;
StorageRemap = StorageManagerM;
--- 44,47 ----
Index: StorageManagerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManagerM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** StorageManagerM.nc 11 Mar 2005 21:44:11 -0000 1.1
--- StorageManagerM.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 29,33 ****
provides {
interface SectorStorage[volume_t volume];
- interface SectorStorage as Swap[volume_t volume];
interface Mount[volume_t volume];
interface StdControl;
--- 29,32 ----
***************
*** 52,58 ****
S_MOUNT,
S_WRITE,
! S_SWAP_WRITE,
! S_INIT_SWAP,
! S_COMMIT_SWAP,
};
--- 51,55 ----
S_MOUNT,
S_WRITE,
! S_ERASE,
};
***************
*** 60,70 ****
SectorTable sectorTable;
! volume_id_t volumeMap[NUM_VOLUMES];
volume_t clientVolume;
volume_id_t curVolumeId;
!
! uint8_t swapSector;
! bool swapSectorIsFree;
!
stm25p_addr_t rwAddr;
stm25p_addr_t rwLen;
--- 57,65 ----
SectorTable sectorTable;
! uint8_t baseSector[NUM_VOLUMES];
! uint8_t boundSector[NUM_VOLUMES];
volume_t clientVolume;
volume_id_t curVolumeId;
!
stm25p_addr_t rwAddr;
stm25p_addr_t rwLen;
***************
*** 77,89 ****
state = S_NEVER_USED;
- swapSector = STM25P_NUM_SECTORS;
- swapSectorIsFree = TRUE;
-
for ( i = 0; i < STM25P_NUM_SECTORS; i++ )
sectorTable.sector[i].volumeId = STM25P_INVALID_VOLUME_ID;
- for ( i = 0; i < NUM_VOLUMES; i++ )
- volumeMap[i] = STM25P_INVALID_VOLUME_ID;
-
return SUCCESS;
--- 72,78 ----
***************
*** 111,119 ****
switch(tmpState) {
! case S_MOUNT: signal Mount.mountDone[clientVolume](result, volumeMap[clientVolume]); return;
! case S_WRITE: signal SectorStorage.writeDone[clientVolume](result); return;
! case S_SWAP_WRITE: signal Swap.writeDone[clientVolume](result); return;
! case S_INIT_SWAP: signal StorageManager.initSwapDone[clientVolume](result); return;
! case S_COMMIT_SWAP: signal StorageManager.commitSwapDone[clientVolume](result); return;
}
--- 100,106 ----
switch(tmpState) {
! case S_MOUNT: signal Mount.mountDone[clientVolume](result, curVolumeId); break;
! case S_WRITE: signal SectorStorage.writeDone[clientVolume](result); break;
! case S_ERASE: signal SectorStorage.eraseDone[clientVolume](result); break;
}
***************
*** 137,151 ****
volume_id_t i;
! storage_result_t result = STORAGE_FAIL;
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (sectorTable.sector[i].volumeId == curVolumeId) {
! volumeMap[clientVolume] = curVolumeId;
! result = STORAGE_OK;
! break;
! }
}
! signalDone(result);
}
--- 124,143 ----
volume_id_t i;
! // find base sector
! for ( i = 0; i < STM25P_NUM_SECTORS && sectorTable.sector[i].volumeId != curVolumeId; i++ );
! if (i == STM25P_NUM_SECTORS) {
! signalDone(STORAGE_FAIL);
! return;
}
+
+ baseSector[clientVolume] = i;
! // find bound sector
! for ( ; i < STM25P_NUM_SECTORS && sectorTable.sector[i].volumeId == curVolumeId; i++ );
!
! boundSector[clientVolume] = i;
!
! signalDone(STORAGE_OK);
}
***************
*** 155,213 ****
}
! command result_t Mount.mount[volume_t volume](volume_id_t volumeID) {
- int16_t newestVersion;
- uint8_t newestSector;
uint8_t i;
! if (state != S_READY && state != S_NEVER_USED)
! return FAIL;
! curVolumeId = volumeID;
! clientVolume = volume;
! // if already used, shortcut to checking metadata
! if (state == S_READY) {
! if (post mount() == SUCCESS) {
! state = S_MOUNT;
! return SUCCESS;
! }
return FAIL;
}
! // if never used, find newest sector table
! newestVersion = STM25P_INVALID_VERSION;
! newestSector = STM25P_NUM_SECTORS;
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (call HALSTM25P.read(STM25P_SECTOR_SIZE*i+STORAGE_BLOCK_SIZE,
! (uint8_t*)§orTable, sizeof(sectorTable)) == FAIL)
! return FAIL;
! if (sectorTable.version != STM25P_INVALID_VERSION
! && !sectorTable.sector[i].isFixed
! && sectorTable.crc == computeSectorTableCrc()
! && ((sectorTable.version - newestVersion) > 0
! || newestVersion == STM25P_INVALID_VERSION)) {
! newestVersion = sectorTable.version;
! newestSector = i;
! }
! }
! if (newestSector == STM25P_NUM_SECTORS)
return FAIL;
! // searched all sectors, load newest table
! if (call HALSTM25P.read(STM25P_SECTOR_SIZE*newestSector+STORAGE_BLOCK_SIZE,
! (uint8_t*)§orTable, sizeof(SectorTable)) == FAIL)
! return FAIL;
! // sector table loaded, find free sector for swap
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if ( sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID ) {
! swapSector = i;
! break;
}
- }
// continue with mount operation
if (post mount() == SUCCESS) {
--- 147,203 ----
}
! result_t formatFlash() {
uint8_t i;
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ )
! sectorTable.sector[i].volumeId = STM25P_INVALID_VOLUME_ID;
! sectorTable.sector[0].volumeId = 0xD0;
! sectorTable.sector[1].volumeId = 0xD1;
! sectorTable.sector[STM25P_NUM_SECTORS-1].volumeId = 0xDF;
! sectorTable.crc = computeSectorTableCrc();
!
! rwAddr = STORAGE_BLOCK_SIZE;
! if (call HALSTM25P.sectorErase(rwAddr) == FAIL) {
! state = S_NEVER_USED;
return FAIL;
}
! return SUCCESS;
! }
!
! command result_t Mount.mount[volume_t volume](volume_id_t volumeID) {
!
! uint8_t i;
!
! if (state != S_READY && state != S_NEVER_USED)
return FAIL;
! curVolumeId = volumeID;
! clientVolume = volume;
+ // if never used, look for partition table
+ if (state == S_NEVER_USED) {
! // if never used, find valid sector table
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (call HALSTM25P.read(STM25P_SECTOR_SIZE*i+STORAGE_BLOCK_SIZE,
! (uint8_t*)§orTable, sizeof(sectorTable)) == FAIL)
! return FAIL;
! if (sectorTable.crc == computeSectorTableCrc())
! break;
! }
!
! // if flash has no valid sector tables, format it
! if (i == STM25P_NUM_SECTORS) {
! state = S_MOUNT;
! return formatFlash();
}
+ }
+
// continue with mount operation
if (post mount() == SUCCESS) {
***************
*** 220,240 ****
}
! stm25p_addr_t physicalAddr(volume_t volume, uint32_t volumeAddr) {
!
stm25p_addr_t offset = volumeAddr % STORAGE_BLOCK_SIZE;
! uint8_t sector = volumeAddr / STORAGE_BLOCK_SIZE;
! volume_id_t i;
!
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (sectorTable.sector[i].volumeId == volumeMap[volume]
! && sectorTable.sector[i].sectorId == sector)
! break;
! }
!
! if ( i == STM25P_NUM_SECTORS )
! return STM25P_INVALID_ADDR;
!
! return STM25P_SECTOR_SIZE*i + offset;
!
}
--- 210,217 ----
}
! stm25p_addr_t physicalAddr(uint32_t volumeAddr) {
! stm25p_addr_t sector = volumeAddr / STORAGE_BLOCK_SIZE;
stm25p_addr_t offset = volumeAddr % STORAGE_BLOCK_SIZE;
! return STM25P_SECTOR_SIZE*(baseSector[clientVolume]+sector) + offset;
}
***************
*** 244,248 ****
return FAIL;
! return physicalAddr(volume, volumeAddr);
}
--- 221,225 ----
return FAIL;
! return physicalAddr(volumeAddr);
}
***************
*** 250,354 ****
command stm25p_addr_t StorageManager.getVolumeSize[volume_t volume]() {
- uint8_t maxSector;
- uint8_t i;
-
if (state == S_NEVER_USED || state == S_MOUNT)
! return FAIL;
!
! for ( i = 0, maxSector = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (sectorTable.sector[i].volumeId == volumeMap[volume]
! && sectorTable.sector[i].sectorId > maxSector)
! maxSector = sectorTable.sector[i].sectorId;
! }
!
! return STORAGE_BLOCK_SIZE * (maxSector+1);
!
! }
!
! command uint8_t StorageManager.initSwap[volume_t volume]() {
!
! if (admitRequest(volume) == FAIL)
! return FAIL;
!
! // check if swap is already in progress
! if (!swapSectorIsFree)
! return FAIL;
!
! state = S_INIT_SWAP;
!
! // erase new swap sector
! if (call HALSTM25P.sectorErase(STM25P_SECTOR_SIZE*swapSector) == FAIL) {
! state = S_READY;
! return FAIL;
! }
!
! swapSectorIsFree = FALSE;
!
! return SUCCESS;
!
! }
!
! command result_t StorageManager.commitSwap[volume_t volume](stm25p_addr_t addr) {
!
! uint8_t oldSector;
! uint8_t i;
!
! if (admitRequest(volume) == FAIL)
! return FAIL;
!
! if (swapSectorIsFree)
! return FAIL;
!
! // find sector to swap with
! oldSector = addr / STORAGE_BLOCK_SIZE;
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if ( sectorTable.sector[i].volumeId == volumeMap[volume]
! && sectorTable.sector[i].sectorId == oldSector ) {
! oldSector = i;
! break;
! }
! }
!
! if ( i == STM25P_NUM_SECTORS )
! return FAIL;
!
! state = S_COMMIT_SWAP;
!
! // if sector is fixed, just erase it
! if ( sectorTable.sector[oldSector].isFixed ) {
! if (call HALSTM25P.sectorErase(STM25P_SECTOR_SIZE*oldSector) == FAIL) {
! state = S_READY;
! return FAIL;
! }
! return SUCCESS;
! }
!
! // update sector table
! sectorTable.sector[swapSector] = sectorTable.sector[oldSector];
! sectorTable.sector[oldSector].volumeId = STM25P_INVALID_VOLUME_ID;
! do {
! sectorTable.version++;
! } while ( sectorTable.version == STM25P_INVALID_VERSION );
! sectorTable.crc = computeSectorTableCrc();
!
! // write new sector table
! rwAddr = STM25P_SECTOR_SIZE * swapSector + STORAGE_BLOCK_SIZE;
! if (call HALSTM25P.pageProgram(rwAddr, (uint8_t*)§orTable,
! sizeof(sectorTable)) == FAIL) {
! state = S_READY;
! sectorTable.sector[oldSector] = sectorTable.sector[swapSector];
! sectorTable.sector[swapSector].volumeId = STM25P_INVALID_VOLUME_ID;
! return FAIL;
! }
!
! swapSector = oldSector;
! return SUCCESS;
}
! stm25p_addr_t calcNumBytes(stm25p_addr_t addr) {
! stm25p_addr_t pageOffset = addr % STM25P_PAGE_SIZE;
stm25p_addr_t numBytes = STM25P_PAGE_SIZE - pageOffset;
--- 227,240 ----
command stm25p_addr_t StorageManager.getVolumeSize[volume_t volume]() {
if (state == S_NEVER_USED || state == S_MOUNT)
! return STM25P_INVALID_ADDR;
! return STORAGE_BLOCK_SIZE*(boundSector[volume]-baseSector[volume]);
}
! stm25p_addr_t calcNumBytes() {
! stm25p_addr_t pageOffset = rwAddr % STM25P_PAGE_SIZE;
stm25p_addr_t numBytes = STM25P_PAGE_SIZE - pageOffset;
***************
*** 365,369 ****
return FAIL;
! return call HALSTM25P.read(physicalAddr(volume, addr), data, len);
}
--- 251,255 ----
return FAIL;
! return call HALSTM25P.read(physicalAddr(addr), data, len);
}
***************
*** 376,386 ****
rwData = data;
rwLen = len;
! rwAddr = physicalAddr(volume, addr);
! if ( rwAddr == STM25P_INVALID_ADDR )
! return FAIL;
state = S_WRITE;
! if (call HALSTM25P.pageProgram(rwAddr, data, calcNumBytes(rwAddr)) == FAIL) {
state = S_READY;
return FAIL;
--- 262,270 ----
rwData = data;
rwLen = len;
! rwAddr = physicalAddr(addr);
state = S_WRITE;
! if (call HALSTM25P.pageProgram(rwAddr, data, calcNumBytes()) == FAIL) {
state = S_READY;
return FAIL;
***************
*** 391,432 ****
}
! 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(volume, addr), len);
!
! }
!
! command result_t Swap.read[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
! if ( admitRequest(volume) == FAIL || swapSectorIsFree )
return FAIL;
! return call HALSTM25P.read(STM25P_SECTOR_SIZE*swapSector+addr, data, len);
}
! command result_t Swap.write[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
! if ( admitRequest(volume) == FAIL || swapSectorIsFree )
return FAIL;
! rwData = data;
! rwLen = len;
! rwAddr = STM25P_SECTOR_SIZE*swapSector + addr;
! state = S_SWAP_WRITE;
!
! return call HALSTM25P.pageProgram(rwAddr, data, calcNumBytes(rwAddr));
!
! }
!
! command result_t Swap.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len) {
!
! if ( admitRequest(volume) == FAIL || swapSectorIsFree )
! return FAIL;
!
! return call HALSTM25P.computeCrc(crcResult, crc, STM25P_SECTOR_SIZE*swapSector+addr, len);
}
--- 275,303 ----
}
! command result_t SectorStorage.erase[volume_t volume](stm25p_addr_t addr) {
if ( admitRequest(volume) == FAIL )
return FAIL;
! rwAddr = physicalAddr(addr);
! rwLen = 0;
! state = S_ERASE;
!
! if (call HALSTM25P.sectorErase(rwAddr) == FAIL) {
! state = S_READY;
return FAIL;
+ }
! return SUCCESS;
}
! 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);
}
***************
*** 435,453 ****
stm25p_addr_t lastBytes;
- uint8_t oldSwapSector;
-
- if (state == S_COMMIT_SWAP) {
-
- if (result != STORAGE_OK) {
- oldSwapSector = rwAddr / STM25P_SECTOR_SIZE;
- sectorTable.sector[swapSector] = sectorTable.sector[oldSwapSector];
- sectorTable.sector[oldSwapSector].sectorId = STM25P_INVALID_VOLUME_ID;
- swapSector = oldSwapSector;
- }
- swapSectorIsFree = TRUE;
- signalDone(result);
- return;
-
- }
if ( result != STORAGE_OK ) {
--- 306,309 ----
***************
*** 456,460 ****
}
! lastBytes = calcNumBytes(rwAddr);
rwAddr += lastBytes;
--- 312,328 ----
}
! if ( state == S_MOUNT ) {
! rwAddr += STM25P_SECTOR_SIZE;
! if ( rwAddr < STM25P_SECTOR_SIZE*STM25P_NUM_SECTORS ) {
! if (call HALSTM25P.sectorErase(rwAddr) == FAIL)
! signalDone(STORAGE_FAIL);
! return;
! }
!
! actualMount();
! return;
! }
!
! lastBytes = calcNumBytes();
rwAddr += lastBytes;
***************
*** 467,471 ****
}
! if (call HALSTM25P.pageProgram(rwAddr, rwData, calcNumBytes(rwAddr)) == FAIL)
signalDone(STORAGE_FAIL);
--- 335,339 ----
}
! if (call HALSTM25P.pageProgram(rwAddr, rwData, calcNumBytes()) == FAIL)
signalDone(STORAGE_FAIL);
***************
*** 473,489 ****
event void HALSTM25P.sectorEraseDone(result_t result) {
! if (state == S_COMMIT_SWAP)
! swapSectorIsFree = TRUE;
! signalDone(result);
}
event void HALSTM25P.bulkEraseDone(result_t result) { ; }
- event void HALSTM25P.readSRDone(result_t result, uint8_t value) { ; }
event void HALSTM25P.writeSRDone(result_t result) { ; }
default event void Mount.mountDone[volume_t volume](storage_result_t result, volume_id_t id) { ; }
default event void SectorStorage.writeDone[volume_t volume](result_t result) { ; }
- default event void Swap.writeDone[volume_t volume](result_t result) { ; }
- default event void StorageManager.initSwapDone[volume_t volume](storage_result_t result) { ; }
}
--- 341,354 ----
event void HALSTM25P.sectorEraseDone(result_t result) {
! if (call HALSTM25P.pageProgram(rwAddr, (uint8_t*)§orTable,
! sizeof(sectorTable)) == FAIL)
! signalDone(STORAGE_FAIL);
}
event void HALSTM25P.bulkEraseDone(result_t result) { ; }
event void HALSTM25P.writeSRDone(result_t result) { ; }
default event void Mount.mountDone[volume_t volume](storage_result_t result, volume_id_t id) { ; }
default event void SectorStorage.writeDone[volume_t volume](result_t result) { ; }
}
Index: StorageRemap.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageRemap.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** StorageRemap.nc 11 Mar 2005 21:44:11 -0000 1.1
--- StorageRemap.nc 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:4
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:4
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
Index: Storage_chip.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/Storage_chip.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Storage_chip.h 11 Mar 2005 21:44:11 -0000 1.1
--- Storage_chip.h 15 Mar 2005 06:23:21 -0000 1.2
***************
*** 2,6 ****
/* tab:2
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 2,6 ----
/* tab:2
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
More information about the Tinyos-beta-commits
mailing list