[Tinyos-beta-commits] CVS: tinyos-1.x/beta/STM25P/STM25P
LogStorageM.nc, 1.3, 1.4
Jonathan Hui
jwhui at users.sourceforge.net
Mon May 23 10:35:47 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4126
Modified Files:
LogStorageM.nc
Log Message:
- Sync tested and works.
- Slightly reduced code size.
Index: LogStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/LogStorageM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** LogStorageM.nc 20 May 2005 21:23:41 -0000 1.3
--- LogStorageM.nc 23 May 2005 17:35:45 -0000 1.4
***************
*** 146,151 ****
event void ActualMount.mountDone[logstorage_t logId](storage_result_t result, volume_id_t id) {
! stm25p_addr_t volumeSize = call StorageManager.getVolumeSize[client]();
! stm25p_addr_t curAddr;
volumeId = id;
--- 146,151 ----
event void ActualMount.mountDone[logstorage_t logId](storage_result_t result, volume_id_t id) {
! uint8_t numSectors = call StorageManager.getNumSectors[logId]();
! uint8_t curSector;
volumeId = id;
***************
*** 156,161 ****
curWriteCookie = 0;
curReadCookie = LOG_MAX_COOKIE;
! for ( curAddr = 0; curAddr < volumeSize; curAddr += STM25P_SECTOR_SIZE ) {
!
if (call SectorStorage.read[client](curAddr, §orHeader, sizeof(sectorHeader))
== FAIL) {
--- 156,162 ----
curWriteCookie = 0;
curReadCookie = LOG_MAX_COOKIE;
!
! for ( curSector = 0; curSector < numSectors; curSector++ ) {
! stm25p_addr_t curAddr = curSector * STM25P_SECTOR_SIZE;
if (call SectorStorage.read[client](curAddr, §orHeader, sizeof(sectorHeader))
== FAIL) {
***************
*** 251,257 ****
log_cookie_t newReadCookie;
! log_len_t newReadBlockLen;
! stm25p_addr_t volumeSize = call StorageManager.getVolumeSize[logId]();
! stm25p_addr_t sectorCookie = cookie & ~(STM25P_SECTOR_SIZE-1);
if (admitRequest(logId) == FAIL)
--- 252,257 ----
log_cookie_t newReadCookie;
! uint8_t numSectors = call StorageManager.getNumSectors[logId]();
! uint8_t curSector;
if (admitRequest(logId) == FAIL)
***************
*** 259,300 ****
// look for the sector we want
! for ( newReadCookie = 0;
! newReadCookie < volumeSize && newReadCookie != sectorCookie;
! newReadCookie += STM25P_SECTOR_SIZE ) {
if (call SectorStorage.read[logId](newReadCookie, §orHeader,
sizeof(sectorHeader)) == FAIL)
return FAIL;
}
// couldn't find the sector we want
! if ( newReadCookie >= volumeSize )
return FAIL;
// scan through
! while ( newReadCookie < cookie ) {
! if (advanceCookie(&newReadCookie) == FAIL)
return FAIL;
// if block header is valid
if ( ~blockHeader.flags & LOG_BLOCK_VALID )
! newReadBlockLen = blockHeader.length;
// if block header is for block that is currently being written
else if ( curReadCookie >= curWriteCookie - curWriteBlockPos )
! newReadBlockLen = curWriteBlockPos;
// advance pointers
! if ( newReadCookie + newReadBlockLen > cookie ) {
! newReadBlockLen = blockHeader.length - newReadCookie;
! newReadCookie = cookie;
}
else {
! newReadCookie += blockHeader.length;
}
}
- curReadCookie = newReadCookie;
- curReadBlockLen = newReadBlockLen;
-
if (post signalDoneTask() == SUCCESS) {
state = S_SEEK;
--- 259,300 ----
// look for the sector we want
! for ( curSector = 0; curSector < numSectors; curSector++ ) {
! newReadCookie = curSector * STM25P_SECTOR_SIZE;
if (call SectorStorage.read[logId](newReadCookie, §orHeader,
sizeof(sectorHeader)) == FAIL)
return FAIL;
+ if (newReadCookie == (cookie & ~(STM25P_SECTOR_SIZE-1)))
+ break;
}
// couldn't find the sector we want
! if ( curSector >= numSectors )
return FAIL;
+ curReadCookie = newReadCookie;
+
// scan through
! while ( curReadCookie < cookie ) {
! if (advanceCookie(&curReadCookie) == FAIL)
return FAIL;
// if block header is valid
if ( ~blockHeader.flags & LOG_BLOCK_VALID )
! curReadBlockLen = blockHeader.length;
// if block header is for block that is currently being written
else if ( curReadCookie >= curWriteCookie - curWriteBlockPos )
! curReadBlockLen = curWriteBlockPos;
// advance pointers
! if ( curReadCookie + curReadBlockLen > cookie ) {
! curReadBlockLen = blockHeader.length - curReadCookie;
! curReadCookie = cookie;
}
else {
! curReadCookie += blockHeader.length;
}
}
if (post signalDoneTask() == SUCCESS) {
state = S_SEEK;
***************
*** 334,340 ****
if ( curWriteBlockPos >= LOG_BLOCK_MAX_LENGTH
|| ( curWriteBlockPos && !(curWriteCookie % STM25P_SECTOR_SIZE) ) ) {
- call Leds.yellowToggle();
blockHeader.length = curWriteBlockPos;
! blockHeader.flags = ~(LOG_BLOCK_VALID + LOG_BLOCK_ALLOCATED);
state = S_COMMIT_BLOCK_HEADER;
addr = curWriteCookie - curWriteBlockPos;
--- 334,339 ----
if ( curWriteBlockPos >= LOG_BLOCK_MAX_LENGTH
|| ( curWriteBlockPos && !(curWriteCookie % STM25P_SECTOR_SIZE) ) ) {
blockHeader.length = curWriteBlockPos;
! blockHeader.flags = ~( LOG_BLOCK_VALID | LOG_BLOCK_ALLOCATED );
state = S_COMMIT_BLOCK_HEADER;
addr = curWriteCookie - curWriteBlockPos;
***************
*** 355,359 ****
else if ( !curWriteBlockPos ) {
blockHeader.length = LOG_BLOCK_LENGTH_MASK;
! blockHeader.flags = ~(LOG_BLOCK_ALLOCATED);
state = S_INIT_BLOCK_HEADER;
addr = curWriteCookie;
--- 354,358 ----
else if ( !curWriteBlockPos ) {
blockHeader.length = LOG_BLOCK_LENGTH_MASK;
! blockHeader.flags = ~( LOG_BLOCK_ALLOCATED );
state = S_INIT_BLOCK_HEADER;
addr = curWriteCookie;
***************
*** 364,370 ****
// write data
else {
// check for sector boundary
- lastLen = rwLen;
tmp = STM25P_SECTOR_SIZE - (curWriteCookie % STM25P_SECTOR_SIZE);
if ( tmp < lastLen )
--- 363,370 ----
// write data
else {
+
+ lastLen = rwLen;
// check for sector boundary
tmp = STM25P_SECTOR_SIZE - (curWriteCookie % STM25P_SECTOR_SIZE);
if ( tmp < lastLen )
***************
*** 395,400 ****
curLen = 0;
- state = S_APPEND;
-
if (appendData() == FAIL) {
state = S_IDLE;
--- 395,398 ----
***************
*** 442,450 ****
event void SectorStorage.writeDone[logstorage_t logId](storage_result_t result) {
!
! if (state != S_COMMIT_BLOCK_HEADER
! && state != S_SYNC)
curWriteCookie += lastLen;
!
if (result != STORAGE_OK) {
signalDone(result);
--- 440,447 ----
event void SectorStorage.writeDone[logstorage_t logId](storage_result_t result) {
!
! if (state != S_COMMIT_BLOCK_HEADER && state != S_SYNC)
curWriteCookie += lastLen;
!
if (result != STORAGE_OK) {
signalDone(result);
More information about the Tinyos-beta-commits
mailing list