* @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
*/
+#include "imgNum2volumeId.h"
+
module DelugeMetadataP
{
provides interface DelugeMetadata[uint8_t client];
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;
{
return DELUGE_IDENT_SIZE + currentPage * sizeof(uint16_t);
}
-
+
uint32_t calcPageAddr()
{
return DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE + currentPage * DELUGE_BYTES_PER_PAGE;
// CRC and check it against the corresponding value from the CRCs
// block.
state = S_READ_IDENT;
- currentImage = 0;
- nextImage();
+ currentImageIdx = 0;
+ currentVolume = _imgNum2volumeId[currentImageIdx];
+ nextImage();
}
command error_t DelugeMetadata.read[uint8_t client](uint8_t imgNum)
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++;
+ currentVolume = _imgNum2volumeId[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;
}
}
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();
}
}
signal BlockWrite.eraseDone[imgNum](error);
break;
case S_CRC:
- currentImage++;
+ currentImageIdx++;
+ currentVolume = _imgNum2volumeId[currentImageIdx];
nextImage();
break;
}