diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/README.md b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/README.md index 24aed7d7a9..eb50e73fb9 100644 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/README.md +++ b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/README.md @@ -34,6 +34,7 @@ An example of the configuration file: | Parameter name | Value | Description | | --------------- | ------------- | ----------- | | heap-size | number [0-0xfffe] | Nanostack's internal heap size | +| use-malloc-for-heap | `false` or `true` | Use `malloc()` for reserving the internal heap. Default: `false` | ### Thread related configuration parameters diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json index d668e2261d..c9401e662c 100644 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json +++ b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json @@ -2,6 +2,7 @@ "name": "mbed-mesh-api", "config": { "heap-size": 32500, + "use-malloc-for-heap": false, "6lowpan-nd-channel-mask": "(1<<12)", "6lowpan-nd-channel-page": 0, "6lowpan-nd-channel": 12, diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/mesh_system.c b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/mesh_system.c index a9505ad434..c87d7d3772 100644 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/mesh_system.c +++ b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/mesh_system.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include "eventOS_scheduler.h" #include "eventOS_event.h" #include "net_interface.h" @@ -22,13 +23,18 @@ #include "platform/arm_hal_timer.h" #include "ns_hal_init.h" #include "include/mesh_system.h" +#include "mbed_assert.h" // For tracing we need to define flag, have include and define group #define HAVE_DEBUG 1 #include "ns_trace.h" #define TRACE_GROUP "m6-mesh-system" /* Heap for NanoStack */ +#if !MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP static uint8_t app_stack_heap[MBED_CONF_MBED_MESH_API_HEAP_SIZE + 1]; +#else +static uint8_t *app_stack_heap; +#endif static bool mesh_initialized = false; /* @@ -55,6 +61,10 @@ static void mesh_system_heap_error_handler(heap_fail_t event) void mesh_system_init(void) { if (mesh_initialized == false) { +#if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP + app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE+1); + MBED_ASSERT(app_stack_heap); +#endif ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE, mesh_system_heap_error_handler, NULL); eventOS_scheduler_mutex_wait();