]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
deputy fixes
authoridgay <idgay>
Mon, 23 Jun 2008 18:53:14 +0000 (18:53 +0000)
committeridgay <idgay>
Mon, 23 Jun 2008 18:53:14 +0000 (18:53 +0000)
tos/chips/at45db/At45dbP.nc
tos/chips/at45db/BlockStorageP.nc
tos/chips/at45db/HplAt45dbByteC.nc

index 90b3d313b1434a89ccaa7129dac5c1ce2ea58e72..33c5ac5bd8e4811c3d2a42af324d107a4179de3f 100644 (file)
@@ -367,8 +367,9 @@ implementation
                  void * COUNT_NOK(n) reqdata, at45pageoffset_t n) {
     request = req;
 
-    reqBuf = reqdata;
+    reqBuf = NULL;
     reqBytes = n;
+    reqBuf = reqdata;
     reqPage = page;
     reqOffset = offset;
 
index 8045db39ea995474ac48ce80f79b04919a583842..063040c0eb857cbd12282aa688780db1576b31fb 100644 (file)
@@ -88,7 +88,7 @@ implementation
   };
 
   uint8_t client = NO_CLIENT;
-  storage_addr_t bytesRemaining;
+  storage_addr_t currentOffset;
 
   struct {
     /* The latest request made for this client, and it's arguments */
@@ -131,7 +131,7 @@ implementation
 
   void eraseStart();
   void syncStart();
-  void multipageStart(storage_len_t len, uint16_t crc);
+  void multipageStart(uint16_t crc);
 
   void startRequest() {
     switch (s[client].request)
@@ -143,16 +143,13 @@ implementation
        syncStart();
        break;
       default:
-       multipageStart(s[client].len, (uint16_t)s[client].buf);
+       multipageStart((uint16_t)s[client].buf);
       }
   }
 
   void endRequest(error_t result, uint16_t crc) {
     uint8_t c = client;
     uint8_t tmpState = s[c].request;
-    storage_addr_t actualLength = s[c].len - bytesRemaining;
-    storage_addr_t addr = s[c].addr - actualLength;
-    void *ptr = s[c].buf - actualLength;
     
     client = NO_CLIENT;
     s[c].request = R_IDLE;
@@ -161,16 +158,16 @@ implementation
     switch(tmpState)
       {
       case R_READ:
-       signal BlockRead.readDone[c](addr, ptr, actualLength, result);
+       signal BlockRead.readDone[c](s[c].addr, s[c].buf, currentOffset, result);
        break;
       case R_WRITE:
-       signal BlockWrite.writeDone[c](addr, ptr, actualLength, result);
+       signal BlockWrite.writeDone[c](s[c].addr, s[c].buf, currentOffset, result);
        break;
       case R_ERASE:
        signal BlockWrite.eraseDone[c](result);
        break;
       case R_CRC:
-       signal BlockRead.computeCrcDone[c](addr, actualLength, crc, result);
+       signal BlockRead.computeCrcDone[c](s[c].addr, currentOffset, crc, result);
        break;
       case R_SYNC:
        signal BlockWrite.syncDone[c](result);
@@ -191,8 +188,13 @@ implementation
 
     s[id].request = newState;
     s[id].addr = addr;
-    s[id].buf = buf;
+    /* With deputy, updating a buffer/length pair requires nulling-out the 
+       buffer first (setting the buffer first would fail if the new buffer
+       is shorter than the old, setting the length first would fail if the
+       new buffer is longer than the old) */
+    s[id].buf = NULL;
     s[id].len = len;
+    s[id].buf = buf;
 
     call Resource.request[id]();
 
@@ -230,49 +232,42 @@ implementation
   /* Multipage operations                                              */
   /* ------------------------------------------------------------------ */
 
-  void calcRequest(storage_addr_t addr, at45page_t *page,
-                  at45pageoffset_t *offset, at45pageoffset_t *count) {
-    *page = pageRemap(addr >> AT45_PAGE_SIZE_LOG2);
-    *offset = addr & ((1 << AT45_PAGE_SIZE_LOG2) - 1);
-    if (bytesRemaining < (1 << AT45_PAGE_SIZE_LOG2) - *offset)
-      *count = bytesRemaining;
-    else
-      *count = (1 << AT45_PAGE_SIZE_LOG2) - *offset;
-
-  }
-
   void multipageContinue(uint16_t crc) {
+    storage_addr_t remaining = s[client].len - currentOffset, addr;
     at45page_t page;
-    at45pageoffset_t offset, count;
-    uint8_t *buf = s[client].buf;
+    at45pageoffset_t pageOffset, count;
+    uint8_t *buf = s[client].buf + currentOffset;
 
-    if (bytesRemaining == 0)
+    if (remaining == 0)
       {
        endRequest(SUCCESS, crc);
        return;
       }
 
-    calcRequest(s[client].addr, &page, &offset, &count);
-    bytesRemaining -= count;
-    s[client].addr += count;
-    s[client].buf = buf + count;
+    addr = s[client].addr + currentOffset;
+    page = pageRemap(addr >> AT45_PAGE_SIZE_LOG2);
+    pageOffset = addr & ((1 << AT45_PAGE_SIZE_LOG2) - 1);
+    count = (1 << AT45_PAGE_SIZE_LOG2) - pageOffset;
+    if (remaining < count)
+      count = remaining;
 
     switch (s[client].request)
       {
       case R_WRITE:
-       call At45db.write(page, offset, buf, count);
+       call At45db.write(page, pageOffset, buf, count);
        break;
       case R_READ:
-       call At45db.read(page, offset, buf, count);
+       call At45db.read(page, pageOffset, buf, count);
        break;
       case R_CRC:
-       call At45db.computeCrc(page, offset, count, crc);
+       call At45db.computeCrc(page, pageOffset, count, crc);
        break;
       }
+    currentOffset += count;
   }
 
-  void multipageStart(storage_len_t len, uint16_t crc) {
-    bytesRemaining = len;
+  void multipageStart(uint16_t crc) {
+    currentOffset = 0;
     multipageContinue(crc);
   }
 
index 57557675af2da87a6b34bbc7441f41180b82d7f4..925f3128d5b318c6295edb508c429a4b0e2e5caa 100644 (file)
@@ -47,7 +47,7 @@ implementation
     P_ERASE
   };
   uint8_t status = P_IDLE;
-  uint8_t flashCmd[4];
+  uint8_t flashCmd[9];
   at45pageoffset_t dataCount;
   uint8_t * COUNT_NOK(dataCount) data;
   uint8_t dontCare;
@@ -180,8 +180,9 @@ implementation
     flashCmd[1] = reqPage >> (16 - sectorSizeLog2);
     flashCmd[2] = reqPage << (sectorSizeLog2 - 8) | reqOffset >> 8;
     flashCmd[3] = reqOffset; // low-order 8 bits
-    data = reqData;
+    data = NULL;
     dataCount = reqCount;
+    data = reqData;
     dontCare = reqDontCare;
 
     call Resource.request();