- switch (srpkt->msg_type) {
- case SERIALMSG_ERASE: // === Erases a volume ===
- state = S_ERASE;
- error = call BlockWrite.erase[img_num]();
- break;
- case SERIALMSG_WRITE: // === Writes to a volume ===
- state = S_WRITE;
- memcpy(buffer, srpkt->data, srpkt->len);
- error = call BlockWrite.write[img_num](srpkt->offset,
- buffer,
- srpkt->len);
- break;
- case SERIALMSG_READ: // === Reads a portion of a volume ===
- state = S_READ;
- error = call BlockRead.read[img_num](srpkt->offset,
- serialMsg_payload->data,
- srpkt->len);
- break;
- case SERIALMSG_CRC: // === Computes CRC over a portion of a volume ===
- state = S_CRC;
- error = call BlockRead.computeCrc[img_num](srpkt->offset,
- srpkt->len, 0);
- break;
- case SERIALMSG_ADDR: // === Gets the physical starting address of a volume ===
- *(nx_uint32_t*)(&serialMsg_payload->data) =
- (uint32_t)call DelugeStorage.getPhysicalAddress[img_num](0);
- sendReply(SUCCESS, sizeof(SerialReplyPacket) + 4);
- break;
-#ifdef DELUGE
- case SERIALMSG_REPROG: // === Reboots and reprograms ===
- state = S_REPROG;
- sendReply(SUCCESS, sizeof(SerialReplyPacket));
- img_num_reboot = img_num;
- call Timer.startOneShot(1024);
- break;
- case SERIALMSG_DISS: // === Starts disseminating a volume ===
- signal Notify.notify(img_num); // Notifies Deluge to start disseminate
- sendReply(SUCCESS, sizeof(SerialReplyPacket));
- break;
+ if (imgNum != NON_DELUGE_VOLUME) {
+ error = SUCCESS;
+ // We ask for a reservation only for erase and write.
+ switch (request->cmd) {
+ case CMD_ERASE:
+ case CMD_WRITE:
+ if (!call Resource.isOwner()) {
+ error = call Resource.immediateRequest();
+ }
+ }
+ if (error == SUCCESS) {
+ call Leds.led1On();
+ call TimeoutTimer.startOneShot(2*1024);
+ currentImgNum = imgNum;
+ switch (request->cmd) {
+ case CMD_ERASE: // === Erases a volume ===
+ state = S_ERASE;
+#if defined(PLATFORM_MICAZ) || defined(PLATFORM_IRIS) || defined(PLATFORM_EPIC)
+ error = FAIL;
+#else
+ error = call BlockWrite.erase[imgNum]();