[Tinyos-beta-commits] CVS: tinyos-1.x/beta/STM25P/STM25P
BlockRead.nc, 1.2, 1.3 BlockStorageM.nc, 1.3,
1.4 BlockWrite.nc, 1.2, 1.3 FlashWP.nc, 1.2, 1.3 FlashWPC.nc,
1.2, 1.3 FlashWPM.nc, 1.2, 1.3 FormatStorageC.nc, 1.2,
1.3 FormatStorageM.nc, 1.2, 1.3 HALSTM25P.h, 1.2,
1.3 HALSTM25P.nc, 1.2, 1.3 HALSTM25PC.nc, 1.2,
1.3 HALSTM25PM.nc, 1.4, 1.5 HPLSTM25P.nc, 1.2, 1.3 Mount.nc,
1.2, 1.3 SectorStorage.nc, 1.3, 1.4 StorageManager.nc, 1.2,
1.3 StorageManagerC.nc, 1.2, 1.3 StorageManagerM.nc, 1.5,
1.6 StorageRemap.nc, 1.2, 1.3
Jonathan Hui
jwhui at users.sourceforge.net
Tue May 17 13:44:52 PDT 2005
- Previous message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/TOSSIM-CC2420
HPLCC2420.c, NONE, 1.1 HPLCC2420.h, NONE, 1.1 HPLCC2420M.nc,
1.3, 1.4 README.txt, 1.1, 1.2 TimerJiffyAsyncC.nc, 1.1,
1.2 TimerJiffyAsyncM.nc, 1.1, 1.2 hardware.c, 1.1,
1.2 hardware.h, 1.2, 1.3
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/Deluge/TOSBoot
Leds.nc, NONE, 1.1 LedsC.nc, NONE, 1.1 crc.h, NONE,
1.1 Makefile, 1.3, 1.4 TOSBootExtFlash.nc, 1.2,
1.3 TOSBootM.nc, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18500
Modified Files:
BlockRead.nc BlockStorageM.nc BlockWrite.nc FlashWP.nc
FlashWPC.nc FlashWPM.nc FormatStorageC.nc FormatStorageM.nc
HALSTM25P.h HALSTM25P.nc HALSTM25PC.nc HALSTM25PM.nc
HPLSTM25P.nc Mount.nc SectorStorage.nc StorageManager.nc
StorageManagerC.nc StorageManagerM.nc StorageRemap.nc
Log Message:
- External flash chip goes to deep power mode after a specified
timeout.
- Removed spinning task loops for retry.
- Reduced code size by about 700 bytes.
- Changed buffer type in interface to void*.
Index: BlockRead.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockRead.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** BlockRead.nc 15 Mar 2005 06:23:21 -0000 1.2
--- BlockRead.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 30,35 ****
interface BlockRead {
! command result_t read(block_addr_t addr, uint8_t* buf, block_addr_t len);
! event void readDone(storage_result_t result, block_addr_t addr, uint8_t* buf, block_addr_t len);
command result_t verify();
--- 30,35 ----
interface BlockRead {
! command result_t read(block_addr_t addr, void* buf, block_addr_t len);
! event void readDone(storage_result_t result, block_addr_t addr, void* buf, block_addr_t len);
command result_t verify();
***************
*** 39,41 ****
--- 39,43 ----
event void computeCrcDone(storage_result_t result, uint16_t crc, block_addr_t addr, block_addr_t len);
+ command block_addr_t getSize();
+
}
Index: BlockStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockStorageM.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** BlockStorageM.nc 18 Mar 2005 01:12:35 -0000 1.3
--- BlockStorageM.nc 17 May 2005 20:44:49 -0000 1.4
***************
*** 56,60 ****
block_addr_t rwAddr, rwLen;
! uint8_t* rwBuf;
uint16_t crc;
--- 56,60 ----
block_addr_t rwAddr, rwLen;
! void* rwBuf;
uint16_t crc;
***************
*** 85,89 ****
result_t newRequest(uint8_t newState, blockstorage_t blockId,
! block_addr_t addr, uint8_t* buf, block_addr_t len) {
result_t result = FAIL;
--- 85,89 ----
result_t newRequest(uint8_t newState, blockstorage_t blockId,
! block_addr_t addr, void* buf, block_addr_t len) {
result_t result = FAIL;
***************
*** 98,102 ****
rwLen = len;
- state = newState;
switch(newState) {
case S_READ:
--- 98,101 ----
***************
*** 117,134 ****
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);
}
--- 116,137 ----
break;
}
!
! if (newState == S_READ || newState == S_CRC || newState == S_VERIFY) {
if (result == SUCCESS)
result = post signalDoneTask();
}
! if (result == SUCCESS)
! state = newState;
return result;
}
+
+ command uint32_t BlockRead.getSize[blockstorage_t blockId]() {
+ return call StorageManager.getVolumeSize[blockId]();
+ }
! command result_t BlockRead.read[blockstorage_t blockId](block_addr_t addr, void* buf, block_addr_t len) {
return newRequest(S_READ, blockId, addr, buf, len);
}
***************
*** 146,150 ****
}
! 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);
}
--- 149,153 ----
}
! command result_t BlockWrite.write[blockstorage_t blockId](block_addr_t addr, void* buf, block_addr_t len) {
return newRequest(S_WRITE, blockId, addr, buf, len);
}
***************
*** 162,169 ****
}
! 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) { ; }
default event void BlockWrite.commitDone[blockstorage_t blockId](storage_result_t result) { ; }
! default event void BlockRead.readDone[blockstorage_t blockId](storage_result_t result, block_addr_t addr, uint8_t* buf, block_addr_t len) { ; }
default event void BlockRead.verifyDone[blockstorage_t blockId](storage_result_t result) { ; }
default event void BlockRead.computeCrcDone[blockstorage_t blockId](storage_result_t result, uint16_t crcResult, block_addr_t addr, block_addr_t len) { ; }
--- 165,172 ----
}
! default event void BlockWrite.writeDone[blockstorage_t blockId](storage_result_t result, block_addr_t addr, void* buf, block_addr_t len) { ; }
default event void BlockWrite.eraseDone[blockstorage_t blockId](storage_result_t result) { ; }
default event void BlockWrite.commitDone[blockstorage_t blockId](storage_result_t result) { ; }
! default event void BlockRead.readDone[blockstorage_t blockId](storage_result_t result, block_addr_t addr, void* buf, block_addr_t len) { ; }
default event void BlockRead.verifyDone[blockstorage_t blockId](storage_result_t result) { ; }
default event void BlockRead.computeCrcDone[blockstorage_t blockId](storage_result_t result, uint16_t crcResult, block_addr_t addr, block_addr_t len) { ; }
Index: BlockWrite.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/BlockWrite.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** BlockWrite.nc 15 Mar 2005 06:23:21 -0000 1.2
--- BlockWrite.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 30,35 ****
interface BlockWrite {
! command result_t write(block_addr_t addr, uint8_t* buf, block_addr_t len);
! event void writeDone(storage_result_t result, block_addr_t addr, uint8_t* buf, block_addr_t len);
command result_t erase();
--- 30,35 ----
interface BlockWrite {
! command result_t write(block_addr_t addr, void* buf, block_addr_t len);
! event void writeDone(storage_result_t result, block_addr_t addr, void* buf, block_addr_t len);
command result_t erase();
Index: FlashWP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FlashWP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FlashWP.nc 15 Mar 2005 06:23:21 -0000 1.2
--- FlashWP.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 28,33 ****
interface FlashWP {
command result_t setWP();
! event result_t setWPDone(result_t result);
command result_t clrWP();
! event result_t clrWPDone(result_t result);
}
--- 28,33 ----
interface FlashWP {
command result_t setWP();
! event void setWPDone();
command result_t clrWP();
! event void clrWPDone();
}
Index: FlashWPC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FlashWPC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FlashWPC.nc 15 Mar 2005 06:23:21 -0000 1.2
--- FlashWPC.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 40,44 ****
FlashWP = FlashWPM;
! FlashWPM.HALSTM25P -> HALSTM25PC.HALSTM25P[0];
}
--- 40,44 ----
FlashWP = FlashWPM;
! FlashWPM.HALSTM25P -> HALSTM25PC.HALSTM25P[unique("HALSTM25P")];
}
Index: FlashWPM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FlashWPM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FlashWPM.nc 15 Mar 2005 06:23:21 -0000 1.2
--- FlashWPM.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 41,47 ****
enum {
! S_IDLE,
! S_CLR,
! S_SET,
};
--- 41,47 ----
enum {
! S_IDLE = 0xff,
! S_CLR = 0x00,
! S_SET = 0x84,
};
***************
*** 54,87 ****
command result_t StdControl.stop() { return SUCCESS; }
! command result_t FlashWP.clrWP() {
! state = S_CLR;
! if (call HALSTM25P.writeSR(0x0) == FAIL) {
! state = S_IDLE;
return FAIL;
! }
! return SUCCESS;
}
! command result_t FlashWP.setWP() {
! state = S_SET;
! if (call HALSTM25P.writeSR(0x84) == FAIL) {
! state = S_IDLE;
! return FAIL;
! }
! return SUCCESS;
}
! event void HALSTM25P.writeSRDone(result_t result) {
uint8_t tmpState = state;
state = S_IDLE;
switch(tmpState) {
! case S_CLR: signal FlashWP.clrWPDone(result); break;
! case S_SET: signal FlashWP.setWPDone(result); break;
}
}
! event void HALSTM25P.pageProgramDone(result_t result) { ; }
! event void HALSTM25P.sectorEraseDone(result_t result) { ; }
! event void HALSTM25P.bulkEraseDone(result_t result) { ; }
}
--- 54,93 ----
command result_t StdControl.stop() { return SUCCESS; }
! result_t newRequest(uint8_t newState) {
!
! result_t result;
!
! if (state != S_IDLE)
return FAIL;
!
! result = call HALSTM25P.writeSR(newState);
!
! if (result == SUCCESS)
! state = newState;
!
! return result;
!
}
! command result_t FlashWP.clrWP() {
! return newRequest(S_CLR);
}
! command result_t FlashWP.setWP() {
! return newRequest(S_SET);
! }
!
! event void HALSTM25P.writeSRDone() {
uint8_t tmpState = state;
state = S_IDLE;
switch(tmpState) {
! case S_CLR: signal FlashWP.clrWPDone(); break;
! case S_SET: signal FlashWP.setWPDone(); break;
}
}
! event void HALSTM25P.pageProgramDone() {}
! event void HALSTM25P.sectorEraseDone() {}
! event void HALSTM25P.bulkEraseDone() {}
}
Index: FormatStorageC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FormatStorageC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FormatStorageC.nc 15 Mar 2005 06:23:21 -0000 1.2
--- FormatStorageC.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 36,40 ****
implementation {
! components FormatStorageM, HALSTM25PC, Main;
FormatStorage = FormatStorageM;
--- 36,40 ----
implementation {
! components CrcC, FormatStorageM, HALSTM25PC, Main;
FormatStorage = FormatStorageM;
***************
*** 43,46 ****
--- 43,47 ----
Main.StdControl -> HALSTM25PC;
+ FormatStorageM.Crc -> CrcC;
FormatStorageM.HALSTM25P -> HALSTM25PC.HALSTM25P[unique("HALSTM25P")];
Index: FormatStorageM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/FormatStorageM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FormatStorageM.nc 15 Mar 2005 06:23:21 -0000 1.2
--- FormatStorageM.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 32,35 ****
--- 32,36 ----
}
uses {
+ interface Crc;
interface HALSTM25P;
}
***************
*** 39,43 ****
SectorTable sectorTable;
! volume_id_t curVolume;
uint8_t state;
--- 40,44 ----
SectorTable sectorTable;
! uint8_t curSector;
uint8_t state;
***************
*** 83,90 ****
}
! command result_t FormatStorage.allocate(volume_id_t id, storage_addr_t size) {
volume_id_t freeSectors;
! uint8_t curSector;
volume_id_t i;
--- 84,91 ----
}
! result_t allocate(volume_id_t id, storage_addr_t addr, storage_addr_t size) {
volume_id_t freeSectors;
! uint8_t base;
volume_id_t i;
***************
*** 92,110 ****
return FAIL;
// size must be a multiple of sector size
! if (size % STORAGE_BLOCK_SIZE)
return FAIL;
! 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)
return FAIL;
! // count number of free sectors
! if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID)
freeSectors++;
! else
freeSectors = 0;
}
--- 93,124 ----
return FAIL;
+ if (addr % STM25P_SECTOR_SIZE)
+ return FAIL;
+
// size must be a multiple of sector size
! if (size % STM25P_SECTOR_SIZE)
return FAIL;
! addr /= STM25P_SECTOR_SIZE;
! size /= STM25P_SECTOR_SIZE;
!
! // check if id is already taken
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
if (sectorTable.sector[i].volumeId == id)
return FAIL;
! }
!
! // count number of free sectors
! for ( i = addr, freeSectors = 0, base = addr; i < STM25P_NUM_SECTORS && freeSectors < size; i++ ) {
! if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID) {
freeSectors++;
! }
! else {
! // if trying to allocate fixed, return fail
! if (addr != 0)
! return FAIL;
freeSectors = 0;
+ base = i + 1;
+ }
}
***************
*** 113,188 ****
return FAIL;
! for ( i = 0, curSector = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID) {
! sectorTable.sector[i].volumeId = id;
! if (--size == 0)
! return SUCCESS;
! }
! }
! // something bad happened
! return FAIL;
}
! /**
! * Not implemented
! */
! command result_t FormatStorage.allocateFixed(volume_id_t id, storage_addr_t addr, storage_addr_t size) {
!
! volume_id_t freeSectors;
! uint8_t curSector;
! volume_id_t i;
!
! if (state != S_INIT)
! return FAIL;
!
! // addr must be a multiple of sector size
! if (addr % STM25P_SECTOR_SIZE)
! return FAIL;
!
! // size must be a multiple of storage block size
! if (size % STORAGE_BLOCK_SIZE)
! return FAIL;
!
! addr /= STM25P_SECTOR_SIZE;
! size /= STORAGE_BLOCK_SIZE;
!
! for ( i = addr, freeSectors = 0; i < STM25P_NUM_SECTORS; i++ ) {
! // check if sector is already taken
! if (sectorTable.sector[i].volumeId != STM25P_INVALID_VOLUME_ID)
! return FAIL;
! // count number of free sectors
! else
! freeSectors++;
! }
!
! // check if there are enough free sectors
! if (freeSectors < size)
! return FAIL;
!
! for ( i = addr, curSector = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (sectorTable.sector[i].volumeId == STM25P_INVALID_VOLUME_ID) {
! sectorTable.sector[i].volumeId = id;
! if (--size == 0)
! return SUCCESS;
! }
! }
!
! return FAIL;
}
uint16_t computeSectorTableCrc() {
!
! uint8_t* buf = (uint8_t*)§orTable;
! uint16_t crc;
! uint8_t i;
!
! for ( i = 0, crc = 0; i < sizeof(SectorTable) - 2; i++, buf++ )
! crc = crcByte(crc, *buf);
!
! return crc;
!
}
--- 127,148 ----
return FAIL;
! // allocate space
! for ( i = base; i < STM25P_NUM_SECTORS && size > 0; i++, size-- )
! sectorTable.sector[i].volumeId = id;
! return SUCCESS;
}
! command result_t FormatStorage.allocate(volume_id_t id, storage_addr_t size) {
! return allocate(id, 0, size);
! }
+ command result_t FormatStorage.allocateFixed(volume_id_t id, storage_addr_t addr, storage_addr_t size) {
+ return allocate(id, addr, size);
}
uint16_t computeSectorTableCrc() {
! return call Crc.crc16(§orTable, sizeof(SectorTable)-2);
}
***************
*** 193,201 ****
state = S_COMMIT;
! curVolume = 0;
sectorTable.crc = computeSectorTableCrc();
! if (call HALSTM25P.sectorErase(STM25P_SECTOR_SIZE*curVolume) == FAIL) {
state = S_INIT;
return FAIL;
--- 153,161 ----
state = S_COMMIT;
! curSector = 0;
sectorTable.crc = computeSectorTableCrc();
! if (call HALSTM25P.sectorErase(STM25P_SECTOR_SIZE*curSector) == FAIL) {
state = S_INIT;
return FAIL;
***************
*** 210,220 ****
stm25p_addr_t addr;
! addr = STM25P_SECTOR_SIZE*curVolume + STORAGE_BLOCK_SIZE;
if (call HALSTM25P.pageProgram(addr, (uint8_t*)§orTable,
! sizeof(sectorTable)) == FAIL) {
signalDone(STORAGE_FAIL);
- return;
- }
}
--- 170,182 ----
stm25p_addr_t addr;
! for ( ; curSector < STM25P_NUM_SECTORS
! && sectorTable.sector[curSector].volumeId != sectorTable.sector[curSector+1].volumeId ;
! curSector++ );
!
! addr = STM25P_SECTOR_SIZE*(curSector+1) - sizeof(sectorTable);
if (call HALSTM25P.pageProgram(addr, (uint8_t*)§orTable,
! sizeof(sectorTable)) == FAIL)
signalDone(STORAGE_FAIL);
}
***************
*** 227,238 ****
}
! curVolume++;
! if ( curVolume < STM25P_NUM_SECTORS ) {
! if (call HALSTM25P.sectorErase(STM25P_SECTOR_SIZE*curVolume) == FAIL)
signalDone(STORAGE_FAIL);
return;
}
! curVolume = 0;
writeVolumeMetadata();
--- 189,200 ----
}
! curSector++;
! if ( curSector < STM25P_NUM_SECTORS ) {
! if (call HALSTM25P.sectorErase(STM25P_SECTOR_SIZE*curSector) == FAIL)
signalDone(STORAGE_FAIL);
return;
}
! curSector = 0;
writeVolumeMetadata();
***************
*** 246,261 ****
}
! curVolume++;
! if ( curVolume < STM25P_NUM_SECTORS ) {
writeVolumeMetadata();
! return;
! }
!
! signalDone(STORAGE_OK);
}
! event void HALSTM25P.bulkEraseDone(result_t result) { ; }
! event void HALSTM25P.writeSRDone(result_t result) { ; }
}
--- 208,221 ----
}
! curSector++;
! if ( curSector < STM25P_NUM_SECTORS )
writeVolumeMetadata();
! else
! signalDone(STORAGE_OK);
}
! event void HALSTM25P.bulkEraseDone(result_t result) {}
! event void HALSTM25P.writeSRDone(result_t result) {}
}
Index: HALSTM25P.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25P.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HALSTM25P.h 15 Mar 2005 06:23:21 -0000 1.2
--- HALSTM25P.h 17 May 2005 20:44:49 -0000 1.3
***************
*** 34,39 ****
STM25P_PAGE_SIZE = 256,
STM25P_SECTOR_SIZE_LOG2 = 16,
! STM25P_SECTOR_SIZE = (uint32_t)1<<STM25P_SECTOR_SIZE_LOG2,
STM25P_NUM_SECTORS = 16,
};
--- 34,40 ----
STM25P_PAGE_SIZE = 256,
STM25P_SECTOR_SIZE_LOG2 = 16,
! STM25P_SECTOR_SIZE = 1L << STM25P_SECTOR_SIZE_LOG2,
STM25P_NUM_SECTORS = 16,
+ STM25P_POWEROFF_DELAY = 1024,
};
***************
*** 41,47 ****
--- 42,50 ----
STM25P_INVALID_SIG = 0xff,
STM25P_INVALID_VOLUME_ID = 0xff,
+ STM25P_INVALID_SECTOR = 0xff,
};
enum {
+ STM25P_CMD_SIZE = 1,
STM25P_ADDR_SIZE = 3,
STM25P_FR_DUMMY_BYTES = 1,
***************
*** 49,66 ****
};
! enum {
! // I, A, D, T, R
! STM25P_WREN = 0x06, // 1, 0, 0, 0, 0
! STM25P_WRDI = 0x04, // 1, 0, 0, 0, 0
! STM25P_RDSR = 0x05, // 1, 0, 0, 0, 1
! STM25P_WRSR = 0x01, // 1, 0, 0, 1, 0
! STM25P_READ = 0x03, // 1, 3, 0, 0, N
! STM25P_FAST_READ = 0x0b, // 1, 3, 1, 0, N
! STM25P_PP = 0x02, // 1, 3, 0, N, 0
! STM25P_SE = 0xd8, // 1, 3, 0, 0, 0
! STM25P_BE = 0xc7, // 1, 0, 0, 0, 0
! STM25P_DP = 0xb9, // 1, 0, 0, 0, 0
! STM25P_RES = 0xab, // 1, 0, 3, 0, 1
! STM25P_CRC = 0xff, // not really an instruction
};
--- 52,153 ----
};
! typedef struct stm25p_cmd_t {
! uint8_t cmd;
! uint8_t address : 2;
! uint8_t dummy : 2;
! bool transmit : 1;
! bool receive : 1;
! bool write : 1;
! bool reserved : 1;
! } stm25p_cmd_t;
!
! enum { // I, A, D, T, R
! STM25P_WREN = 0, // 1, 0, 0, 0, 0
! STM25P_WRDI = 1, // 1, 0, 0, 0, 0
! STM25P_RDSR = 2, // 1, 0, 0, 0, 1
! STM25P_WRSR = 3, // 1, 0, 0, 1, 0
! STM25P_READ = 4, // 1, 3, 0, 0, N
! STM25P_FAST_READ = 5, // 1, 3, 1, 0, N
! STM25P_PP = 6, // 1, 3, 0, N, 0
! STM25P_SE = 7, // 1, 3, 0, 0, 0
! STM25P_BE = 8, // 1, 0, 0, 0, 0
! STM25P_DP = 9, // 1, 0, 0, 0, 0
! STM25P_RES = 10, // 1, 0, 3, 0, 1
! STM25P_CRC = 11, // 1, 3, 0, 0, 1
! };
!
! static const stm25p_cmd_t STM25P_CMDS[12] = {
! { cmd : 0x06, // STM25P_WREN
! address : 0,
! dummy : 0,
! transmit : FALSE,
! receive : FALSE,
! write : FALSE },
! { cmd : 0x04, // STM25P_WRDI
! address : 0,
! dummy : 0,
! transmit : FALSE,
! receive : FALSE,
! write : FALSE },
! { cmd : 0x05, // STM25P_RDSR
! address : 0,
! dummy : 0,
! transmit : FALSE,
! receive : TRUE,
! write : FALSE },
! { cmd : 0x01, // STM25P_WRSR
! address : 0,
! dummy : 0,
! transmit : TRUE,
! receive : FALSE,
! write : TRUE },
! { cmd : 0x03, // STM25P_READ
! address : STM25P_ADDR_SIZE,
! dummy : 0,
! transmit : FALSE,
! receive : TRUE,
! write : FALSE },
! { cmd : 0x0b, // STM25P_FAST_READ
! address : STM25P_ADDR_SIZE,
! dummy : STM25P_FR_DUMMY_BYTES,
! transmit : FALSE,
! receive : TRUE,
! write : FALSE },
! { cmd : 0x02, // STM25P_PP
! address : STM25P_ADDR_SIZE,
! dummy : 0,
! transmit : TRUE,
! receive : FALSE,
! write : TRUE },
! { cmd : 0xd8, // STM25P_SE
! address : STM25P_ADDR_SIZE,
! dummy : 0,
! transmit : FALSE,
! receive : FALSE,
! write : TRUE },
! { cmd : 0xc7, // STM25P_BE
! address : 0,
! dummy : 0,
! transmit : FALSE,
! receive : FALSE,
! write : TRUE },
! { cmd : 0xb9, // STM25P_DP
! address : 0,
! dummy : 0,
! transmit : FALSE,
! receive : FALSE,
! write : FALSE },
! { cmd : 0xab, // STM25P_RES
! address : 0,
! dummy : 3,
! transmit : FALSE,
! receive : TRUE,
! write : FALSE },
! { cmd : 0x03, // STM25P_CRC
! address : STM25P_ADDR_SIZE,
! dummy : 0,
! transmit : FALSE,
! receive : TRUE,
! write : FALSE },
};
***************
*** 87,91 ****
enum {
! STORAGE_BLOCK_SIZE = STM25P_SECTOR_SIZE - sizeof(SectorTable),
};
--- 174,178 ----
enum {
! STORAGE_BLOCK_SIZE = STM25P_SECTOR_SIZE,
};
Index: HALSTM25P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25P.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HALSTM25P.nc 15 Mar 2005 06:23:21 -0000 1.2
--- HALSTM25P.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 30,48 ****
interface HALSTM25P {
! command result_t read(stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
! command result_t pageProgram(stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
! event void pageProgramDone(result_t result);
command result_t sectorErase(stm25p_addr_t addr);
! event void sectorEraseDone(result_t result);
command result_t bulkErase();
! event void bulkEraseDone(result_t result);
! command result_t readSR(uint8_t* value);
command result_t writeSR(uint8_t value);
! event void writeSRDone(result_t result);
command result_t computeCrc(uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len);
--- 30,48 ----
interface HALSTM25P {
! command result_t read(stm25p_addr_t addr, void* data, stm25p_addr_t len);
! command result_t pageProgram(stm25p_addr_t addr, void* data, stm25p_addr_t len);
! event void pageProgramDone();
command result_t sectorErase(stm25p_addr_t addr);
! event void sectorEraseDone();
command result_t bulkErase();
! event void bulkEraseDone();
! command result_t readSR(void* value);
command result_t writeSR(uint8_t value);
! event void writeSRDone();
command result_t computeCrc(uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len);
Index: HALSTM25PC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25PC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HALSTM25PC.nc 15 Mar 2005 06:23:21 -0000 1.2
--- HALSTM25PC.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 37,41 ****
implementation {
! components HALSTM25PM, HPLSTM25PC, LedsC as Leds;
StdControl = HALSTM25PM;
--- 37,41 ----
implementation {
! components HALSTM25PM, HPLSTM25PC, LedsC as Leds, TimerC;
StdControl = HALSTM25PM;
***************
*** 45,47 ****
--- 45,48 ----
HALSTM25PM.HPLSTM25P -> HPLSTM25PC;
HALSTM25PM.Leds -> Leds;
+ HALSTM25PM.Timer -> TimerC.Timer[unique("Timer")];
}
Index: HALSTM25PM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HALSTM25PM.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** HALSTM25PM.nc 26 Apr 2005 23:58:49 -0000 1.4
--- HALSTM25PM.nc 17 May 2005 20:44:49 -0000 1.5
***************
*** 34,53 ****
interface HPLSTM25P;
interface Leds;
}
}
implementation {
!
enum {
! S_POWEROFF, // deep power-down state
! S_POWERON, // awake state, no command in progress
};
volume_t curVolume;
stm25p_sig_t signature;
! uint16_t returnVal;
uint8_t curCmd;
! void sendCmd(uint8_t cmd, stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
command result_t StdControl.init() {
--- 34,54 ----
interface HPLSTM25P;
interface Leds;
+ interface Timer;
}
}
implementation {
!
enum {
! S_POWEROFF = 0xfe, // deep power-down state
! S_POWERON = 0xff, // awake state, no command in progress
};
volume_t curVolume;
stm25p_sig_t signature;
! uint16_t crcScratch;
uint8_t curCmd;
! void sendCmd(uint8_t cmd, stm25p_addr_t addr, void* data, stm25p_addr_t len);
command result_t StdControl.init() {
***************
*** 60,73 ****
command result_t StdControl.stop() { return SUCCESS; }
! void signalDone(result_t result) {
uint8_t tmpCmd = curCmd;
curCmd = S_POWERON;
switch(tmpCmd) {
! case STM25P_PP: signal HALSTM25P.pageProgramDone[curVolume](result); break;
! case STM25P_SE: signal HALSTM25P.sectorEraseDone[curVolume](result); break;
! case STM25P_BE: signal HALSTM25P.bulkEraseDone[curVolume](result); break;
! case STM25P_WRSR: signal HALSTM25P.writeSRDone[curVolume](result); break;
}
}
--- 61,78 ----
command result_t StdControl.stop() { return SUCCESS; }
! void signalDone() {
!
uint8_t tmpCmd = curCmd;
curCmd = S_POWERON;
+ call Timer.start(TIMER_ONE_SHOT, STM25P_POWEROFF_DELAY);
+
switch(tmpCmd) {
! case STM25P_PP: signal HALSTM25P.pageProgramDone[curVolume](); break;
! case STM25P_SE: signal HALSTM25P.sectorEraseDone[curVolume](); break;
! case STM25P_BE: signal HALSTM25P.bulkEraseDone[curVolume](); break;
! case STM25P_WRSR: signal HALSTM25P.writeSRDone[curVolume](); break;
}
+
}
***************
*** 78,138 ****
sendCmd(STM25P_RDSR, 0, &status, sizeof(status));
call HPLSTM25P.releaseBus();
! return (status & 0x1) ? TRUE : FALSE;
}
! // probably better to use a timer since write operations can take on
! // the order of seconds to complete
! task void checkWriteDone() {
! if (isWriting()) {
! if (post checkWriteDone() == FAIL)
! signalDone(STORAGE_FAIL);
! return;
! }
! signalDone(STORAGE_OK);
}
! void sendCmd(uint8_t cmd, stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
! uint8_t addrBytes[STM25P_ADDR_SIZE];
! stm25p_addr_t i;
! // start command
! switch(cmd) {
! case STM25P_CRC: call HPLSTM25P.beginCmd(STM25P_READ); break;
! default: call HPLSTM25P.beginCmd(cmd); break;
! }
! // address
! switch(cmd) {
! case STM25P_READ: case STM25P_FAST_READ: case STM25P_PP:
! case STM25P_SE: case STM25P_CRC:
! for ( i = 0; i < STM25P_ADDR_SIZE; i++ )
! addrBytes[i] = (addr >> ((STM25P_ADDR_SIZE-1-i)*8)) & 0xff;
! call HPLSTM25P.txBuf(addrBytes, STM25P_ADDR_SIZE);
! break;
! }
! // dummy bytes
! switch(cmd) {
! case STM25P_FAST_READ:
! call HPLSTM25P.txBuf(addrBytes, STM25P_FR_DUMMY_BYTES);
! break;
! case STM25P_RES:
! call HPLSTM25P.txBuf(addrBytes, STM25P_RES_DUMMY_BYTES);
! break;
! }
// data
! switch(cmd) {
! case STM25P_RDSR: case STM25P_READ: case STM25P_FAST_READ: case STM25P_RES:
! call HPLSTM25P.rxBuf(data, len);
! break;
! case STM25P_WRSR: case STM25P_PP:
call HPLSTM25P.txBuf(data, len);
- break;
- case STM25P_CRC:
- call HPLSTM25P.computeCrc(&returnVal, len);
- break;
- }
// end command
--- 83,135 ----
sendCmd(STM25P_RDSR, 0, &status, sizeof(status));
call HPLSTM25P.releaseBus();
! return !!(status & 0x1);
}
! void powerOff() {
! sendCmd(STM25P_DP, 0, NULL, 0);
! curCmd = S_POWEROFF;
}
! void powerOn() {
! sendCmd(STM25P_RES, 0, &signature, sizeof(signature));
! TOSH_uwait(2); // wait at least 1.8us to power on
! curCmd = S_POWERON;
! }
! event result_t Timer.fired() {
! if (curCmd == S_POWERON)
! powerOff();
! else if (isWriting())
! call Timer.start(TIMER_ONE_SHOT, 1);
! else
! signalDone();
! return SUCCESS;
! }
!
! void sendCmd(uint8_t cmd, stm25p_addr_t addr, void* data, stm25p_addr_t len) {
!
! uint8_t cmdBytes[2*STM25P_ADDR_SIZE + 1];
! uint8_t i;
!
! // begin command
! call HPLSTM25P.beginCmd();
!
! cmdBytes[0] = STM25P_CMDS[cmd].cmd;
!
! // command, address and dummy bytes
! for ( i = 0; i < STM25P_ADDR_SIZE; i++ )
! cmdBytes[i+1] = (addr >> ((STM25P_ADDR_SIZE-1-i)*8)) & 0xff;
! call HPLSTM25P.txBuf(cmdBytes, (STM25P_CMD_SIZE +
! STM25P_CMDS[cmd].address +
! STM25P_CMDS[cmd].dummy) );
// data
! if (STM25P_CMDS[cmd].receive)
! call HPLSTM25P.rxBuf(data, len, &crcScratch);
! else if (STM25P_CMDS[cmd].transmit)
call HPLSTM25P.txBuf(data, len);
// end command
***************
*** 141,200 ****
}
- void powerOff() {
- sendCmd(STM25P_DP, 0, NULL, 0);
- curCmd = S_POWEROFF;
- }
-
- void powerOn() {
- sendCmd(STM25P_RES, 0, &signature, sizeof(signature));
- TOSH_uwait(2); // wait at least 1.8us to power on
- curCmd = S_POWERON;
- }
-
result_t newRequest(uint8_t cmd, volume_t volume, stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
! // make sure flash is powered on
! if (curCmd == S_POWEROFF)
! 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;
! curVolume = volume;
curCmd = cmd;
!
! // enable writes if needed
! if (curCmd == STM25P_WRSR || curCmd == STM25P_PP || curCmd == STM25P_SE || curCmd == STM25P_BE)
sendCmd(STM25P_WREN, 0, NULL, 0);
!
// send command
sendCmd(curCmd, addr, data, len);
! call HPLSTM25P.releaseBus();
!
! // setup check for write done
! if (curCmd == STM25P_WRSR || curCmd == STM25P_PP || curCmd == STM25P_SE || curCmd == STM25P_BE) {
! if (post checkWriteDone() == FAIL) {
! curCmd = S_POWERON;
! return FAIL;
! }
! }
else {
curCmd = S_POWERON;
}
return SUCCESS;
}
! command result_t HALSTM25P.read[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
return newRequest(STM25P_READ, volume, addr, data, len);
}
! command result_t HALSTM25P.pageProgram[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
return newRequest(STM25P_PP, volume, addr, data, len);
}
--- 138,183 ----
}
result_t newRequest(uint8_t cmd, volume_t volume, stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
! if (curCmd != S_POWERON && curCmd != S_POWEROFF)
return FAIL;
!
! if (call HPLSTM25P.getBus() == FAIL)
return FAIL;
! call Timer.stop();
+ if (curCmd == S_POWEROFF)
+ powerOn();
+
+ curVolume = volume;
curCmd = cmd;
!
! // enable writes
! if (STM25P_CMDS[curCmd].write)
sendCmd(STM25P_WREN, 0, NULL, 0);
!
// send command
sendCmd(curCmd, addr, data, len);
! // post check for write done
! if (STM25P_CMDS[curCmd].write)
! call Timer.start(TIMER_ONE_SHOT, 1);
else {
curCmd = S_POWERON;
+ call Timer.start(TIMER_ONE_SHOT, STM25P_POWEROFF_DELAY);
}
+ call HPLSTM25P.releaseBus();
+
return SUCCESS;
}
! command result_t HALSTM25P.read[volume_t volume](stm25p_addr_t addr, void* data, stm25p_addr_t len) {
return newRequest(STM25P_READ, volume, addr, data, len);
}
! command result_t HALSTM25P.pageProgram[volume_t volume](stm25p_addr_t addr, void* data, stm25p_addr_t len) {
return newRequest(STM25P_PP, volume, addr, data, len);
}
***************
*** 208,212 ****
}
! command result_t HALSTM25P.readSR[volume_t volume](uint8_t* value) {
return newRequest(STM25P_RDSR, volume, 0, value, 1);
}
--- 191,195 ----
}
! command result_t HALSTM25P.readSR[volume_t volume](void* value) {
return newRequest(STM25P_RDSR, volume, 0, value, 1);
}
***************
*** 217,225 ****
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;
}
--- 200,208 ----
command result_t HALSTM25P.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc, stm25p_addr_t addr, stm25p_addr_t len) {
! result_t result;
! crcScratch = crc;
! result = newRequest(STM25P_CRC, volume, addr, NULL, len);
! *crcResult = crcScratch;
! return result;
}
***************
*** 228,235 ****
}
! default event void HALSTM25P.pageProgramDone[volume_t volume](result_t result) { ; }
! 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.writeSRDone[volume_t volume](result_t result) { ; }
}
--- 211,218 ----
}
! default event void HALSTM25P.pageProgramDone[volume_t volume]() {}
! default event void HALSTM25P.sectorEraseDone[volume_t volume]() {}
! default event void HALSTM25P.bulkEraseDone[volume_t volume]() {}
! default event void HALSTM25P.writeSRDone[volume_t volume]() {}
}
Index: HPLSTM25P.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/HPLSTM25P.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HPLSTM25P.nc 15 Mar 2005 06:23:21 -0000 1.2
--- HPLSTM25P.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 29,38 ****
async command result_t getBus();
async command result_t releaseBus();
! async command result_t beginCmd(uint8_t cmd);
async command result_t endCmd();
async command result_t hold();
async command result_t unhold();
! async command result_t txBuf(uint8_t* buf, stm25p_addr_t len);
! async command result_t rxBuf(uint8_t* buf, stm25p_addr_t len);
! async command result_t computeCrc(uint16_t* crcResult, stm25p_addr_t len);
}
--- 29,37 ----
async command result_t getBus();
async command result_t releaseBus();
! async command result_t beginCmd();
async command result_t endCmd();
async command result_t hold();
async command result_t unhold();
! async command result_t txBuf(void* buf, stm25p_addr_t len);
! async command result_t rxBuf(void* buf, stm25p_addr_t len, uint16_t* crc);
}
Index: Mount.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/Mount.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Mount.nc 15 Mar 2005 06:23:21 -0000 1.2
--- Mount.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 26,30 ****
*/
! includes Storage;
interface Mount {
--- 26,30 ----
*/
! includes HALSTM25P;
interface Mount {
Index: SectorStorage.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/SectorStorage.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** SectorStorage.nc 18 Mar 2005 01:12:50 -0000 1.3
--- SectorStorage.nc 17 May 2005 20:44:49 -0000 1.4
***************
*** 26,34 ****
*/
interface SectorStorage {
! command result_t read(stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
! command result_t write(stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len);
event void writeDone(storage_result_t result);
--- 26,36 ----
*/
+ includes HALSTM25P;
+
interface SectorStorage {
! command result_t read(stm25p_addr_t addr, void* data, stm25p_addr_t len);
! command result_t write(stm25p_addr_t addr, void* data, stm25p_addr_t len);
event void writeDone(storage_result_t result);
Index: StorageManager.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManager.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** StorageManager.nc 15 Mar 2005 06:23:21 -0000 1.2
--- StorageManager.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 26,29 ****
--- 26,31 ----
*/
+ includes HALSTM25P;
+
interface StorageManager {
command stm25p_addr_t getVolumeSize();
Index: StorageManagerC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManagerC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** StorageManagerC.nc 15 Mar 2005 06:23:21 -0000 1.2
--- StorageManagerC.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 26,29 ****
--- 26,31 ----
*/
+ includes HALSTM25P;
+
configuration StorageManagerC {
provides {
***************
*** 38,42 ****
implementation {
! components HALSTM25PC, StorageManagerM, LedsC;
StdControl = StorageManagerM;
--- 40,44 ----
implementation {
! components CrcC, HALSTM25PC, StorageManagerM, LedsC;
StdControl = StorageManagerM;
***************
*** 48,51 ****
--- 50,54 ----
StorageManager = StorageManagerM;
+ StorageManagerM.Crc -> CrcC;
StorageManagerM.HALSTM25P -> HALSTM25PC.HALSTM25P[unique("HALSTM25P")];
StorageManagerM.Leds -> LedsC;
Index: StorageManagerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/STM25P/STM25P/StorageManagerM.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** StorageManagerM.nc 18 Mar 2005 01:12:50 -0000 1.5
--- StorageManagerM.nc 17 May 2005 20:44:49 -0000 1.6
***************
*** 35,38 ****
--- 35,39 ----
}
uses {
+ interface Crc;
interface HALSTM25P;
interface Leds;
***************
*** 50,53 ****
--- 51,56 ----
S_READY,
S_MOUNT,
+ S_READ,
+ S_COMPUTE_CRC,
S_WRITE,
S_ERASE,
***************
*** 58,68 ****
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;
! uint8_t* rwData;
command result_t StdControl.init() {
--- 61,71 ----
SectorTable sectorTable;
uint8_t baseSector[NUM_VOLUMES];
volume_t clientVolume;
volume_id_t curVolumeId;
+ uint16_t crcScratch;
stm25p_addr_t rwAddr;
stm25p_addr_t rwLen;
! void* rwData;
command result_t StdControl.init() {
***************
*** 74,78 ****
for ( i = 0; i < STM25P_NUM_SECTORS; i++ )
sectorTable.sector[i].volumeId = STM25P_INVALID_VOLUME_ID;
!
return SUCCESS;
--- 77,84 ----
for ( i = 0; i < STM25P_NUM_SECTORS; i++ )
sectorTable.sector[i].volumeId = STM25P_INVALID_VOLUME_ID;
!
! for ( i = 0; i < NUM_VOLUMES; i++ )
! baseSector[i] = STM25P_INVALID_SECTOR;
!
return SUCCESS;
***************
*** 85,96 ****
command result_t StdControl.stop() {
return SUCCESS;
! }
!
! bool admitRequest(volume_t volume) {
! if (state != S_READY)
! return FALSE;
! clientVolume = volume;
! return TRUE;
! }
void signalDone(storage_result_t result) {
--- 91,95 ----
command result_t StdControl.stop() {
return SUCCESS;
! }
void signalDone(storage_result_t result) {
***************
*** 108,121 ****
uint16_t computeSectorTableCrc() {
!
! uint8_t* buf = (uint8_t*)§orTable;
! uint16_t crc;
! uint8_t i;
!
! for ( i = 0, crc = 0; i < sizeof(SectorTable) - 2; i++, buf++ )
! crc = crcByte(crc, *buf);
!
! return crc;
!
}
--- 107,111 ----
uint16_t computeSectorTableCrc() {
! return call Crc.crc16(§orTable, sizeof(SectorTable)-2);
}
***************
*** 125,143 ****
// 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);
}
--- 115,127 ----
// find base sector
! for ( i = 0; i < STM25P_NUM_SECTORS; i++ ) {
! if (sectorTable.sector[i].volumeId == curVolumeId) {
! baseSector[clientVolume] = i;
! signalDone(STORAGE_OK);
! return;
! }
}
! signalDone(STORAGE_FAIL);
}
***************
*** 147,150 ****
--- 131,169 ----
}
+ stm25p_addr_t physicalAddr(stm25p_addr_t volumeAddr) {
+ return STM25P_SECTOR_SIZE*baseSector[clientVolume] + volumeAddr;
+ }
+
+ stm25p_addr_t calcNumBytes() {
+
+ uint32_t numBytes;
+
+ if ( state == S_MOUNT )
+ return STM25P_SECTOR_SIZE;
+ else if ( state == S_WRITE )
+ numBytes = STM25P_PAGE_SIZE - (rwAddr % STM25P_PAGE_SIZE);
+ else
+ numBytes = STM25P_SECTOR_SIZE - (rwAddr % STM25P_SECTOR_SIZE);
+
+ if ( rwLen < numBytes )
+ numBytes = rwLen;
+
+ return numBytes;
+
+ }
+
+ result_t continueOp() {
+ stm25p_addr_t pAddr = physicalAddr(rwAddr);
+
+ switch(state) {
+ case S_READ: return call HALSTM25P.read(pAddr, rwData, rwLen);
+ case S_COMPUTE_CRC: return call HALSTM25P.computeCrc(&crcScratch, crcScratch, pAddr, rwLen);
+ case S_MOUNT: pAddr = rwAddr;
+ case S_ERASE: return call HALSTM25P.sectorErase(pAddr);
+ case S_WRITE: return call HALSTM25P.pageProgram(pAddr, rwData, calcNumBytes());
+ }
+ return FAIL;
+ }
+
result_t formatFlash() {
***************
*** 159,170 ****
sectorTable.crc = computeSectorTableCrc();
! rwAddr = STORAGE_BLOCK_SIZE;
!
! if (call HALSTM25P.sectorErase(rwAddr) == FAIL) {
! state = S_NEVER_USED;
! return FAIL;
! }
! return SUCCESS;
}
--- 178,185 ----
sectorTable.crc = computeSectorTableCrc();
! rwAddr = 0;
! rwLen = STM25P_SECTOR_SIZE*STM25P_NUM_SECTORS;
! return continueOp();
}
***************
*** 172,177 ****
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;
--- 187,193 ----
command result_t Mount.mount[volume_t volume](volume_id_t volumeID) {
! stm25p_addr_t addr = 0;
! result_t result;
!
if (state != S_READY && state != S_NEVER_USED)
return FAIL;
***************
*** 184,190 ****
// 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())
--- 200,207 ----
// if never used, find valid sector table
! for ( addr = STM25P_SECTOR_SIZE - sizeof(SectorTable);
! addr < STM25P_SECTOR_SIZE*STM25P_NUM_SECTORS;
! addr += STM25P_SECTOR_SIZE ) {
! if (call HALSTM25P.read(addr, §orTable, sizeof(SectorTable)) == FAIL)
return FAIL;
if (sectorTable.crc == computeSectorTableCrc())
***************
*** 192,222 ****
}
- // 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) {
! state = S_MOUNT;
! return SUCCESS;
}
! return FAIL;
!
! }
- 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;
}
command uint32_t StorageRemap.physicalAddr[volume_t volume](uint32_t volumeAddr) {
! if (admitRequest(volume) == FAIL)
return STM25P_INVALID_ADDR;
return physicalAddr(volumeAddr);
}
--- 209,237 ----
}
}
+
+ state = S_MOUNT;
// continue with mount operation
! if ( addr < STM25P_SECTOR_SIZE*STM25P_NUM_SECTORS ) {
! result = post mount();
! if (!result)
! state = S_READY;
! }
! // if flash has no valid sector tables, format it
! else {
! result = formatFlash();
! if (result == FAIL)
! state = S_NEVER_USED;
}
! return result;
}
command uint32_t StorageRemap.physicalAddr[volume_t volume](uint32_t volumeAddr) {
! if (baseSector[volume] == STM25P_INVALID_SECTOR)
return STM25P_INVALID_ADDR;
+ clientVolume = volume;
return physicalAddr(volumeAddr);
}
***************
*** 224,386 ****
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 blockSize) {
!
! stm25p_addr_t pageOffset = (rwAddr % STORAGE_BLOCK_SIZE) % blockSize;
! stm25p_addr_t numBytes = blockSize - pageOffset;
! if ( rwLen < numBytes )
! numBytes = rwLen;
! return numBytes;
! }
!
! 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;
! }
!
! command result_t SectorStorage.write[volume_t volume](stm25p_addr_t addr, uint8_t* data, stm25p_addr_t len) {
! if ( admitRequest(volume) == FAIL )
! 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;
- }
! return SUCCESS;
}
! 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;
! }
! return SUCCESS;
}
! 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;
}
! event void HALSTM25P.pageProgramDone(result_t result) {
!
! stm25p_addr_t lastBytes;
!
! if ( result != STORAGE_OK ) {
! signalDone(result);
! return;
! }
!
! 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;
! }
! if ( state == S_ERASE )
! lastBytes = calcNumBytes(STORAGE_BLOCK_SIZE);
! else
! lastBytes = calcNumBytes(STM25P_PAGE_SIZE);
! rwAddr += lastBytes;
! rwData += lastBytes;
! rwLen -= lastBytes;
! if ( rwLen == 0 ) {
! signalDone(result);
! 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*)§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) { ; }
}
--- 239,349 ----
command stm25p_addr_t StorageManager.getVolumeSize[volume_t volume]() {
! uint8_t i = baseSector[volume];
! uint8_t tmpVolumeId = sectorTable.sector[i].volumeId;
! if (baseSector[volume] == STM25P_INVALID_SECTOR)
! return STM25P_INVALID_ADDR;
! for ( ; i < STM25P_NUM_SECTORS && sectorTable.sector[i].volumeId == tmpVolumeId; i++ );
! return STM25P_SECTOR_SIZE*(i-baseSector[volume]);
! }
! result_t newRequest(uint8_t newState, volume_t volume,
! stm25p_addr_t addr, void* data, stm25p_addr_t len) {
! result_t result;
! if (state != S_READY)
! return FALSE;
! state = newState;
! clientVolume = volume;
rwAddr = addr;
rwData = data;
rwLen = len;
! result = continueOp();
!
! if (result == FAIL || state == S_READ || state == S_COMPUTE_CRC)
state = S_READY;
! return result;
}
! command result_t SectorStorage.read[volume_t volume](stm25p_addr_t addr, void* data, stm25p_addr_t len) {
! return newRequest(S_READ, volume, addr, data, len);
! }
! command result_t SectorStorage.write[volume_t volume](stm25p_addr_t addr, void* data, stm25p_addr_t len) {
! return newRequest(S_WRITE, volume, addr, data, len);
! }
! command result_t SectorStorage.erase[volume_t volume](stm25p_addr_t addr, stm25p_addr_t len) {
! return newRequest(S_ERASE, volume, addr, NULL, 0);
! }
+ command result_t SectorStorage.computeCrc[volume_t volume](uint16_t* crcResult, uint16_t crc,
+ stm25p_addr_t addr, stm25p_addr_t len) {
+ result_t result;
+ crcScratch = crc;
+ result = newRequest(S_COMPUTE_CRC, volume, addr, NULL, len);
+ *crcResult = crcScratch;
+ return result;
}
! void pageProgramDone() {
stm25p_addr_t lastBytes;
! lastBytes = calcNumBytes();
! rwAddr += lastBytes;
! rwData += lastBytes;
! rwLen -= lastBytes;
! if ( rwLen == 0 ) {
! if (state == S_MOUNT)
! actualMount();
! else
! signalDone(STORAGE_OK);
! return;
}
! if (continueOp() == FAIL)
! signalDone(STORAGE_FAIL);
}
! event void HALSTM25P.pageProgramDone() {
! pageProgramDone();
! }
! event void HALSTM25P.sectorEraseDone() {
! uint8_t sector = rwAddr / STM25P_SECTOR_SIZE;
! if (state != S_MOUNT)
! sector += baseSector[clientVolume];
! if ( sector == STM25P_NUM_SECTORS - 1 ||
! sectorTable.sector[sector].volumeId != sectorTable.sector[sector+1].volumeId ) {
! stm25p_addr_t addr = STM25P_SECTOR_SIZE*(sector+1) - sizeof(SectorTable);
! if (call HALSTM25P.pageProgram(addr, §orTable, sizeof(SectorTable)) == FAIL)
signalDone(STORAGE_FAIL);
}
else {
! pageProgramDone();
! }
}
! event void HALSTM25P.bulkEraseDone() {}
! event void HALSTM25P.writeSRDone() {}
! default event void Mount.mountDone[volume_t volume](storage_result_t result, volume_id_t id) {}
! default event void SectorStorage.eraseDone[volume_t volume](result_t result) {}
! 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.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** StorageRemap.nc 15 Mar 2005 06:23:21 -0000 1.2
--- StorageRemap.nc 17 May 2005 20:44:49 -0000 1.3
***************
*** 26,29 ****
--- 26,31 ----
*/
+ includes HALSTM25P;
+
interface StorageRemap {
command uint32_t physicalAddr(uint32_t volumeAddr);
- Previous message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/TOSSIM-CC2420
HPLCC2420.c, NONE, 1.1 HPLCC2420.h, NONE, 1.1 HPLCC2420M.nc,
1.3, 1.4 README.txt, 1.1, 1.2 TimerJiffyAsyncC.nc, 1.1,
1.2 TimerJiffyAsyncM.nc, 1.1, 1.2 hardware.c, 1.1,
1.2 hardware.h, 1.2, 1.3
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/Deluge/TOSBoot
Leds.nc, NONE, 1.1 LedsC.nc, NONE, 1.1 crc.h, NONE,
1.1 Makefile, 1.3, 1.4 TOSBootExtFlash.nc, 1.2,
1.3 TOSBootM.nc, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-beta-commits
mailing list