mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sterl...@apache.org
Subject [31/50] incubator-mynewt-core git commit: WIP - offset in page
Date Tue, 24 Jan 2017 03:03:17 GMT
WIP - offset in page


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/46f19dcd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/46f19dcd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/46f19dcd

Branch: refs/heads/sensors_branch
Commit: 46f19dcd0f3c2fb1bc198ccb6871c38ddec1f1a9
Parents: 1d0b37b
Author: Fabio Utzig <utzig@utzig.org>
Authored: Mon Jan 2 20:47:29 2017 -0200
Committer: Fabio Utzig <utzig@utzig.org>
Committed: Fri Jan 20 07:27:40 2017 -0200

----------------------------------------------------------------------
 hw/drivers/flash/src/flash.c | 43 ++++++++++++++-------------------------
 1 file changed, 15 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/46f19dcd/hw/drivers/flash/src/flash.c
----------------------------------------------------------------------
diff --git a/hw/drivers/flash/src/flash.c b/hw/drivers/flash/src/flash.c
index b5b7caf..468f918 100644
--- a/hw/drivers/flash/src/flash.c
+++ b/hw/drivers/flash/src/flash.c
@@ -176,18 +176,6 @@ buffer_equal(struct flash_dev *dev)
     return ((read_status(dev) & STATUS_CMP) == 0);
 }
 
-static inline uint16_t
-page_address(uint32_t addr)
-{
-    return (uint16_t) addr / PAGE_SIZE;
-}
-
-static inline uint16_t
-block_address(uint32_t addr)
-{
-    return (uint16_t) addr % PAGE_SIZE;
-}
-
 /* FIXME: add timeout */
 static inline void
 wait_ready(struct flash_dev *dev)
@@ -238,19 +226,20 @@ flash_read(uint8_t flash_id, uint32_t addr, void *buf, size_t len)
     uint8_t val;
     uint32_t n;
     uint16_t page_count;
+    uint16_t page_index;
     uint16_t offset;
+    uint16_t amount;
 
     dev = cfg_dev(flash_id);
     if (!dev) {
         return -1;
     }
 
-    /* FIXME: when reading beyond the end of the page, it rolls back to the
-     * beginning of the same page...
-     */
-
     page_count = (len / (PAGE_SIZE + 1)) + 1;
-    offset = 0;
+    offset = addr % PAGE_SIZE;
+    if (len - offset >= PAGE_SIZE) {
+        page_count++;
+    }
 
     while (page_count--) {
         wait_ready(dev);
@@ -259,15 +248,15 @@ flash_read(uint8_t flash_id, uint32_t addr, void *buf, size_t len)
 
         hal_spi_tx_val(dev->spi_num, MEM_READ);
 
-        pa = page_address(addr);
-        ba = block_address(addr);
-
-        /* FIXME: not using BA9 (required to access more than 512 bytes on page) */
+        pa = addr / PAGE_SIZE;
+        ba = addr % PAGE_SIZE;
 
         /* < r, PA12-6 > */
         val = (pa >> 6) & ~0x80;
         hal_spi_tx_val(dev->spi_num, val);
 
+        /* FIXME: not using BA9 */
+
         /* < PA5-0, BA9-8 > */
         val = (pa << 2) | ((ba >> 8) & 1);
         hal_spi_tx_val(dev->spi_num, val);
@@ -281,13 +270,15 @@ flash_read(uint8_t flash_id, uint32_t addr, void *buf, size_t len)
         hal_spi_tx_val(dev->spi_num, 0xff);
         hal_spi_tx_val(dev->spi_num, 0xff);
 
-        for (n = 0; n < len; n++) {
+        amount = MIN
+        for (n = 0; n < amount; n++) {
             *((uint8_t *) buf + n) = hal_spi_tx_val(dev->spi_num, 0xff);
         }
 
         hal_gpio_write(dev->ss_pin, 1);
 
-        offset += PAGE_SIZE;
+        page_index += PAGE_SIZE;
+        addr = (addr + offset) & (PAGE_SIZE - 1);
     }
 
     return 0;
@@ -299,7 +290,6 @@ flash_write(uint8_t flash_id, uint32_t addr, const void *buf, size_t len)
     struct flash_dev *dev;
     uint16_t pa;
     //uint16_t bfa;
-    //uint8_t val;
     uint32_t n;
     int page_count;
     int offset;
@@ -310,16 +300,13 @@ flash_write(uint8_t flash_id, uint32_t addr, const void *buf, size_t
len)
     }
 
     /* FIXME: calculation is assuming that addr starts at offset 0 in page */
+    addr % PAGE_SIZE
     page_count = (len / (PAGE_SIZE + 1)) + 1;
 
     if (!page_count) {
         return 0;
     }
 
-    /* FIXME: when reading beyond the end of the page, it rolls back to the
-     * beginning of the same page...
-     */
-
     offset = 0;
     while (page_count-- >= 0) {
         wait_ready(dev);


Mime
View raw message