Add flash driver to NRF51 dev kit BSP.

Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/63c94764
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/63c94764
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/63c94764

Branch: refs/heads/master
Commit: 63c94764b66ccc2635af3a818cad57dfb050ae1f
Parents: dc9f9c8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Feb 2 14:40:55 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Feb 2 14:40:55 2016 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51dk/include/bsp/bsp.h               |  2 +
 hw/bsp/nrf51dk/src/hal_bsp.c                   | 13 +++++
 hw/bsp/nrf51dk/src/os_bsp.c                    | 53 +++++++++++++++++++++
 hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h |  3 ++
 4 files changed, 71 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/63c94764/hw/bsp/nrf51dk/include/bsp/bsp.h
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/include/bsp/bsp.h b/hw/bsp/nrf51dk/include/bsp/bsp.h
index cefef1c..a152c9c 100644
--- a/hw/bsp/nrf51dk/include/bsp/bsp.h
+++ b/hw/bsp/nrf51dk/include/bsp/bsp.h
@@ -34,6 +34,8 @@ extern "C" {
 /* UART info */
 #define CONSOLE_UART    0
 
+int bsp_imgr_current_slot(void);
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/63c94764/hw/bsp/nrf51dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/hal_bsp.c b/hw/bsp/nrf51dk/src/hal_bsp.c
index 7c7d2c0..7294ff5 100644
--- a/hw/bsp/nrf51dk/src/hal_bsp.c
+++ b/hw/bsp/nrf51dk/src/hal_bsp.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <stdint.h>
+#include <stddef.h>
 #include "mcu/nrf51_hal.h"
 
 static const struct nrf51_uart_cfg uart_cfg = {
@@ -27,3 +28,15 @@ const struct nrf51_uart_cfg *bsp_uart_config(void)
 {
     return &uart_cfg;
 }
+
+const struct hal_flash *
+bsp_flash_dev(uint8_t id)
+{
+    /*
+     * Internal flash mapped to id 0.
+     */
+    if (id != 0) {
+        return NULL;
+    }
+    return &nrf51_flash_dev;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/63c94764/hw/bsp/nrf51dk/src/os_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/src/os_bsp.c b/hw/bsp/nrf51dk/src/os_bsp.c
index 833cfb9..54e9d04 100644
--- a/hw/bsp/nrf51dk/src/os_bsp.c
+++ b/hw/bsp/nrf51dk/src/os_bsp.c
@@ -13,9 +13,58 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <hal/flash_map.h>
+
+static struct flash_area bsp_flash_areas[] = {
+#if 0
+    [FLASH_AREA_BOOTLOADER] = {
+        .fa_flash_id = 0,       /* internal flash */
+        .fa_off = 0x08000000,   /* beginning */
+        .fa_size = (32 * 1024)
+    },
+#endif
+    /* 2 * 16K and 1*64K sectors here */
+    [FLASH_AREA_IMAGE_0] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x00000000,
+        .fa_size = (232 * 1024)
+    }
+#if 0
+    [FLASH_AREA_IMAGE_1] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x00042000,
+        .fa_size = (232 * 1024)
+    },
+    [FLASH_AREA_IMAGE_SCRATCH] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x0007c000,
+        .fa_size = (4 * 1024)
+    },
+    [FLASH_AREA_NFFS] = {
+        .fa_flash_id = 0,
+        .fa_off = 0x0007d000,
+        .fa_size = (12 * 1024)
+    }
+#endif
+};
+
 void *_sbrk(int incr);
 void _close(int fd);
 
+/*
+ * Returns the flash map slot where the currently active image is located.
+ * If executing from internal flash from fixed location, that slot would
+ * be easy to find.
+ * If images are in external flash, and copied to RAM for execution, then
+ * this routine would have to figure out which one of those slots is being
+ * used.
+ */
+int
+bsp_imgr_current_slot(void)
+{
+    return FLASH_AREA_IMAGE_0;
+}
+
 void
 os_bsp_init(void)
 {
@@ -24,4 +73,8 @@ os_bsp_init(void)
      */
     _sbrk(0);
     _close(0);
+
+    flash_area_init(bsp_flash_areas,
+      sizeof(bsp_flash_areas) / sizeof(bsp_flash_areas[0]));
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/63c94764/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h 
b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
index 46f4737..bc7197c 100755
--- a/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
+++ b/hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_hal.h
@@ -43,6 +43,9 @@ struct nrf51_uart_cfg {
 };
 const struct nrf51_uart_cfg *bsp_uart_config(void);
 
+struct hal_flash;
+extern const struct hal_flash nrf51_flash_dev;
+
 #ifdef __cplusplus
 }
 #endif

Reply via email to