[Tinyos-2-commits] CVS: tinyos-2.x/tos/chips/at45db
ConfigStorageP.nc, 1.1.2.6, 1.1.2.7
David Gay
idgay at users.sourceforge.net
Wed Jun 7 16:11:29 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/chips/at45db
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv6542/tos/chips/at45db
Modified Files:
Tag: tinyos-2_0_devel-BRANCH
ConfigStorageP.nc
Log Message:
update config volume spec, interface, implementation to reflect decision
to read data as of last commit
Index: ConfigStorageP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/chips/at45db/Attic/ConfigStorageP.nc,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -d -r1.1.2.6 -r1.1.2.7
*** ConfigStorageP.nc 2 Jun 2006 17:37:36 -0000 1.1.2.6
--- ConfigStorageP.nc 7 Jun 2006 23:11:27 -0000 1.1.2.7
***************
*** 71,80 ****
/* Bit n is true if client n is using upper block */
! uint8_t flipped[(N + 7) / 8];
uint8_t client = NO_CLIENT;
at45page_t nextPage;
! void setFlip(uint8_t id, bool flip);
/* ------------------------------------------------------------------ */
--- 71,93 ----
/* Bit n is true if client n is using upper block */
! uint8_t flipState[(N + 7) / 8];
uint8_t client = NO_CLIENT;
at45page_t nextPage;
! void setFlip(uint8_t id, bool flip) {
! if (flip)
! flipState[id >> 3] |= 1 << (id & 7);
! else
! flipState[id >> 3] &= ~(1 << (id & 7));
! }
!
! bool flipped(uint8_t id) {
! return call BConfig.flipped[id]();
! }
!
! void flip(uint8_t id) {
! setFlip(id, !flipped(id));
! }
/* ------------------------------------------------------------------ */
***************
*** 131,137 ****
return;
}
! /* both halves bad, just declare success and use the current half :-)
! (we did need to verify to find the end-of-block) */
state[id] = S_INVALID;
}
signal Mount.mountDone[id](SUCCESS);
--- 144,150 ----
return;
}
! /* both halves bad, just declare success and use the current half... */
state[id] = S_INVALID;
+ lowVersion[id] = highVersion[id] = 0;
}
signal Mount.mountDone[id](SUCCESS);
***************
*** 146,149 ****
--- 159,164 ----
if (state[id] < S_CLEAN)
return EOFF;
+ if (state[id] == S_INVALID) // nothing to read
+ return FAIL;
return call BlockRead.read[id](addr + sizeof(uint32_t), buf, len);
***************
*** 160,165 ****
command error_t ConfigStorage.write[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len) {
/* 1: If first write:
! copy to other half, increment version number, and flip.
! 2: Write to current half using BlockWrite */
if (state[id] < S_CLEAN)
--- 175,180 ----
command error_t ConfigStorage.write[uint8_t id](storage_addr_t addr, void* buf, storage_len_t len) {
/* 1: If first write:
! copy to other half with incremented version number
! 2: Write to other half using BlockWrite */
if (state[id] < S_CLEAN)
***************
*** 172,176 ****
command int BConfig.writeHook[uint8_t id]() {
! if (state[id] != S_CLEAN) // no work if dirty or invalid
return FALSE;
--- 187,192 ----
command int BConfig.writeHook[uint8_t id]() {
! flip(id); /* We write to the non-current half... */
! if (state[id] != S_CLEAN) // no copy if dirty or invalid
return FALSE;
***************
*** 190,195 ****
uint32_t *version;
! // Set version number
! if (call BConfig.flipped[client]())
{
lowVersion[client] = highVersion[client] + 1;
--- 206,211 ----
uint32_t *version;
! // Update the version number of the half indicated by flipped()
! if (!flipped(client))
{
lowVersion[client] = highVersion[client] + 1;
***************
*** 210,217 ****
to = from = signal BConfig.remap[client](--nextPage);
! if (call BConfig.flipped[client]())
! to -= npages;
else
! to += npages;
call At45db.copyPage(from, to);
--- 226,233 ----
to = from = signal BConfig.remap[client](--nextPage);
! if (flipped(client))
! from -= npages;
else
! from += npages;
call At45db.copyPage(from, to);
***************
*** 221,228 ****
void copyWriteDone(error_t error) {
if (error == SUCCESS)
! {
! setFlip(client, !call BConfig.flipped[client]());
! state[client] = S_DIRTY;
! }
writeContinue(error);
}
--- 237,241 ----
void copyWriteDone(error_t error) {
if (error == SUCCESS)
! state[client] = S_DIRTY;
writeContinue(error);
}
***************
*** 236,239 ****
--- 249,253 ----
void writeWriteDone(uint8_t id, storage_addr_t addr, void* buf, storage_len_t len, error_t error) {
+ flip(id); // flip back to current half
signal ConfigStorage.writeDone[id](addr - sizeof(uint32_t), buf, len, error);
}
***************
*** 246,252 ****
/* Call BlockWrite.commit */
/* Could special-case attempt to commit clean block */
if (state[id] < S_CLEAN)
return EOFF;
! return call BlockWrite.commit[id]();
}
--- 260,271 ----
/* Call BlockWrite.commit */
/* Could special-case attempt to commit clean block */
+ error_t ok;
+
if (state[id] < S_CLEAN)
return EOFF;
! ok = call BlockWrite.commit[id]();
! if (ok == SUCCESS)
! flip(id); // switch to new block for commit
! return ok;
}
***************
*** 254,257 ****
--- 273,278 ----
if (error == SUCCESS)
state[id] = S_CLEAN;
+ else
+ flip(id); // revert to old block
signal ConfigStorage.commitDone[id](error);
}
***************
*** 284,296 ****
}
- void setFlip(uint8_t id, bool flip) {
- if (flip)
- flipped[id >> 3] |= 1 << (id & 7);
- else
- flipped[id >> 3] &= ~(1 << (id & 7));
- }
-
inline command int BConfig.flipped[uint8_t id]() {
! return (flipped[id >> 3] & (1 << (id & 7))) != 0;
}
--- 305,310 ----
}
inline command int BConfig.flipped[uint8_t id]() {
! return (flipState[id >> 3] & (1 << (id & 7))) != 0;
}
More information about the Tinyos-2-commits
mailing list