Merge pull request #2635 from vikrant-proxy/osdp-baud

net/osdp: support additional osdp baud rates
diff --git a/hw/bsp/nordic_pca10095/src/hal_bsp.c b/hw/bsp/nordic_pca10095/src/hal_bsp.c
index 23a7f2e..38e6dde 100644
--- a/hw/bsp/nordic_pca10095/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10095/src/hal_bsp.c
@@ -33,12 +33,18 @@
 /*
  * What memory to include in coredump.
  */
+#if !MYNEWT_VAL(COREDUMP_SKIP_UNUSED_HEAP)
 static const struct hal_bsp_mem_dump dump_cfg[] = {
     [0] = {
         .hbmd_start = &_ram_start,
         .hbmd_size = RAM_SIZE
     }
 };
+#else
+static struct hal_bsp_mem_dump dump_cfg[2];
+extern uint8_t __StackLimit;
+extern uint8_t __StackTop;
+#endif
 
 const struct hal_flash *
 hal_bsp_flash_dev(uint8_t id)
@@ -60,6 +66,15 @@
 const struct hal_bsp_mem_dump *
 hal_bsp_core_dump(int *area_cnt)
 {
+#if MYNEWT_VAL(COREDUMP_SKIP_UNUSED_HEAP)
+    /* Interrupt stack first */
+    dump_cfg[0].hbmd_start = &__StackLimit;
+    dump_cfg[0].hbmd_size = &__StackTop - &__StackLimit;
+    /* RAM from _ram_start to end of used heap */
+    dump_cfg[1].hbmd_start = &_ram_start;
+    dump_cfg[1].hbmd_size = (uint8_t *)_sbrk(0) - &_ram_start;
+#endif
+
     *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
     return dump_cfg;
 }
diff --git a/hw/bsp/nordic_pca10095/syscfg.yml b/hw/bsp/nordic_pca10095/syscfg.yml
index 25b462f..a3a09de 100644
--- a/hw/bsp/nordic_pca10095/syscfg.yml
+++ b/hw/bsp/nordic_pca10095/syscfg.yml
@@ -30,6 +30,13 @@
             When enabled Network Core of nRF5340 is started on init.
        value: 0
 
+    COREDUMP_SKIP_UNUSED_HEAP:
+        description: >
+            Store whole RAM in crash dump.
+            When 1 only part of heap that was used will be dumped, that
+            can reduce size of crash dump.
+        value: 0
+
 syscfg.vals:
     # Set default pins for peripherals
     UART_0_PIN_TX: 20
diff --git a/hw/bsp/nordic_pca10095_net/src/hal_bsp.c b/hw/bsp/nordic_pca10095_net/src/hal_bsp.c
index e0b1845..2c3445d 100644
--- a/hw/bsp/nordic_pca10095_net/src/hal_bsp.c
+++ b/hw/bsp/nordic_pca10095_net/src/hal_bsp.c
@@ -34,12 +34,18 @@
 /*
  * What memory to include in coredump.
  */
+#if !MYNEWT_VAL(COREDUMP_SKIP_UNUSED_HEAP)
 static const struct hal_bsp_mem_dump dump_cfg[] = {
     [0] = {
         .hbmd_start = &_ram_start,
         .hbmd_size = RAM_SIZE
     }
 };
+#else
+static struct hal_bsp_mem_dump dump_cfg[2];
+extern uint8_t __StackLimit;
+extern uint8_t __StackTop;
+#endif
 
 const struct hal_flash *
 hal_bsp_flash_dev(uint8_t id)
@@ -62,6 +68,15 @@
 const struct hal_bsp_mem_dump *
 hal_bsp_core_dump(int *area_cnt)
 {
+#if MYNEWT_VAL(COREDUMP_SKIP_UNUSED_HEAP)
+    /* Interrupt stack first */
+    dump_cfg[0].hbmd_start = &__StackLimit;
+    dump_cfg[0].hbmd_size = &__StackTop - &__StackLimit;
+    /* RAM from _ram_start to end of used heap */
+    dump_cfg[1].hbmd_start = &_ram_start;
+    dump_cfg[1].hbmd_size = (uint8_t *)_sbrk(0) - &_ram_start;
+#endif
+
     *area_cnt = sizeof(dump_cfg) / sizeof(dump_cfg[0]);
     return dump_cfg;
 }
diff --git a/hw/bsp/nordic_pca10095_net/syscfg.yml b/hw/bsp/nordic_pca10095_net/syscfg.yml
index 1952147..dcb3a56 100644
--- a/hw/bsp/nordic_pca10095_net/syscfg.yml
+++ b/hw/bsp/nordic_pca10095_net/syscfg.yml
@@ -21,6 +21,13 @@
         description: 'Set to indicate that BSP has NRF5340 NET'
         value: 1
 
+    COREDUMP_SKIP_UNUSED_HEAP:
+        description: >
+            Store whole RAM in crash dump.
+            When 1 only part of heap that was used will be dumped, that
+            can reduce size of crash dump.
+        value: 0
+
 syscfg.vals:
     # Set default pins for peripherals
     UART_0_PIN_TX: 20
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index 32aea9e..b54f65b 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -34,11 +34,17 @@
     const struct hal_flash *hf;
     uint8_t i;
     int rc = 0;
+    const uint8_t max_id = MYNEWT_VAL(HAL_FLASH_MAX_DEVICE_COUNT) ? MYNEWT_VAL(HAL_FLASH_MAX_DEVICE_COUNT) : 0xFF;
 
-    for (i = 0; ; i++) {
+    for (i = 0; i < max_id; i++) {
         hf = hal_bsp_flash_dev(i);
         if (!hf) {
-            break;
+            if (MYNEWT_VAL(HAL_FLASH_MAX_DEVICE_COUNT) == 0) {
+                /* Max device count not set, stop at first NULL value returned */
+                break;
+            } else {
+                continue;
+            }
         }
         if (hf->hf_itf->hff_init(hf)) {
             rc = SYS_EIO;
diff --git a/hw/hal/syscfg.yml b/hw/hal/syscfg.yml
index 381609f..2d14012 100644
--- a/hw/hal/syscfg.yml
+++ b/hw/hal/syscfg.yml
@@ -47,6 +47,11 @@
             If set HAL provides standard implementation of _sbrk function.
             It also provides _sbrkInit function that sets up heap space for malloc.
         value: 1
+    HAL_FLASH_MAX_DEVICE_COUNT:
+        description: >
+            If set to zero, flash device ids have continues numbers 0,1,2,...
+            If set to value > 0. Device ID can be any number <0, HAL_FLASH_MAX_DEVICE_ID].
+        value: 0
 syscfg.vals.OS_DEBUG_MODE:
     HAL_FLASH_VERIFY_WRITES: 1
     HAL_FLASH_VERIFY_ERASES: 1