X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Flib%2Fnet%2FDeluge%2FDelugeMetadataP.nc;h=f10b3144b1c0481de8c390bbde06a3d0f1f4b159;hb=62b84950912c1c033c401fb0b2a1efaceec78280;hp=6c2fa37573ca9e8f852203a6da521d2923f91a25;hpb=a887d42035d66e33374c484606bbb11cafec6c31;p=tinyos-2.x.git diff --git a/tos/lib/net/Deluge/DelugeMetadataP.nc b/tos/lib/net/Deluge/DelugeMetadataP.nc index 6c2fa375..f10b3144 100644 --- a/tos/lib/net/Deluge/DelugeMetadataP.nc +++ b/tos/lib/net/Deluge/DelugeMetadataP.nc @@ -24,6 +24,8 @@ * @author Chieh-Jan Mike Liang */ +#include "imgNum2volumeId.h" + module DelugeMetadataP { provides interface DelugeMetadata[uint8_t client]; @@ -48,16 +50,17 @@ implementation DelugeIdent ident; uint8_t state; - uint8_t currentImage; + uint8_t currentVolume; + uint8_t currentImageIdx; uint8_t currentPage; nx_uint16_t currentCrc; uint8_t currentClient; void nextImage() { - if (currentImage < DELUGE_NUM_VOLUMES) { + if (currentImageIdx < DELUGE_NUM_VOLUMES) { state = S_READ_IDENT; - call BlockRead.read[currentImage](0, &ident, sizeof(ident)); + call BlockRead.read[currentVolume](0, &ident, sizeof(ident)); } else { signal storageReady(); state = S_READY; @@ -82,7 +85,8 @@ implementation // CRC and check it against the corresponding value from the CRCs // block. state = S_READ_IDENT; - currentImage = 0; + currentImageIdx = 0; + currentVolume = _imgNum2volumeId[currentImageIdx]; nextImage(); } @@ -110,16 +114,16 @@ implementation if (ident.uidhash != DELUGE_INVALID_UID) { currentPage = 0; state = S_READ_CRC; - call BlockRead.read[currentImage](calcCrcAddr(), ¤tCrc, sizeof(currentCrc)); + call BlockRead.read[currentVolume](calcCrcAddr(), ¤tCrc, sizeof(currentCrc)); } else { - currentImage++; + currentImageIdx++; nextImage(); } } break; case S_READ_CRC: state = S_CRC; - call BlockRead.computeCrc[currentImage](calcPageAddr(), DELUGE_BYTES_PER_PAGE, 0); + call BlockRead.computeCrc[currentVolume](calcPageAddr(), DELUGE_BYTES_PER_PAGE, 0); break; } } @@ -131,14 +135,15 @@ implementation if (crc != currentCrc) { // printf("%04x %04x\n", crc, currentCrc); // invalidate the image by erasing it - call BlockWrite.erase[currentImage](); + call BlockWrite.erase[currentVolume](); } else { currentPage++; if (currentPage < ident.numPgs) { state = S_READ_CRC; - call BlockRead.read[currentImage](calcCrcAddr(), ¤tCrc, sizeof(currentCrc)); + call BlockRead.read[currentVolume](calcCrcAddr(), ¤tCrc, sizeof(currentCrc)); } else { - currentImage++; + currentImageIdx++; + currentVolume = _imgNum2volumeId[currentImageIdx]; nextImage(); } } @@ -157,7 +162,8 @@ implementation signal BlockWrite.eraseDone[imgNum](error); break; case S_CRC: - currentImage++; + currentImageIdx++; + currentVolume = _imgNum2volumeId[currentImageIdx]; nextImage(); break; }