You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/10/29 20:12:59 UTC

[mynewt-core] 01/03: sys/flash_map: Add flash_area_find_idx() function

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 80970ae5a0e24ced90b89111c621a907e4b88eea
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Oct 28 12:34:38 2019 -0700

    sys/flash_map: Add flash_area_find_idx() function
    
    This is an internal utility function that will simplify an upcoming
    feature (inclusion of non-overlapping default flash areas).
---
 sys/flash_map/src/flash_map.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/sys/flash_map/src/flash_map.c b/sys/flash_map/src/flash_map.c
index 88c11e5..b1b2f99 100644
--- a/sys/flash_map/src/flash_map.c
+++ b/sys/flash_map/src/flash_map.c
@@ -31,25 +31,41 @@
 const struct flash_area *flash_map;
 int flash_map_entries;
 
-int
-flash_area_open(uint8_t id, const struct flash_area **fap)
+static int
+flash_area_find_idx(uint8_t id)
 {
-    const struct flash_area *area;
     int i;
 
     if (flash_map == NULL) {
-        return SYS_EACCES;
+        return -1;
     }
 
     for (i = 0; i < flash_map_entries; i++) {
-        area = flash_map + i;
-        if (area->fa_id == id) {
-            *fap = area;
-            return 0;
+        if (flash_map[i].fa_id == id) {
+            return i;
         }
     }
 
-    return SYS_ENOENT;
+    return -1;
+}
+
+int
+flash_area_open(uint8_t id, const struct flash_area **fap)
+{
+    int idx;
+
+    if (flash_map == NULL) {
+        return SYS_EACCES;
+    }
+
+    idx = flash_area_find_idx(id);
+    if (idx == -1) {
+        return SYS_ENOENT;
+    }
+
+    *fap = &flash_map[idx];
+
+    return 0;
 }
 
 int