Skip to content

Commit 5321a75

Browse files
Merge pull request #4849 from ARMmbed/nanomesh_memory
Allow using of malloc() for reserving the Nanostack's heap.
2 parents d10d5af + a2c4426 commit 5321a75

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ An example of the configuration file:
3434
| Parameter name | Value | Description |
3535
| --------------- | ------------- | ----------- |
3636
| heap-size | number [0-0xfffe] | Nanostack's internal heap size |
37+
| use-malloc-for-heap | `false` or `true` | Use `malloc()` for reserving the internal heap. Default: `false` |
3738

3839
### Thread related configuration parameters
3940

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed_lib.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "mbed-mesh-api",
33
"config": {
44
"heap-size": 32500,
5+
"use-malloc-for-heap": false,
56
"6lowpan-nd-channel-mask": "(1<<12)",
67
"6lowpan-nd-channel-page": 0,
78
"6lowpan-nd-channel": 12,

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/mesh_system.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include <stdlib.h>
1718
#include "eventOS_scheduler.h"
1819
#include "eventOS_event.h"
1920
#include "net_interface.h"
@@ -22,13 +23,18 @@
2223
#include "platform/arm_hal_timer.h"
2324
#include "ns_hal_init.h"
2425
#include "include/mesh_system.h"
26+
#include "mbed_assert.h"
2527
// For tracing we need to define flag, have include and define group
2628
#define HAVE_DEBUG 1
2729
#include "ns_trace.h"
2830
#define TRACE_GROUP "m6-mesh-system"
2931

3032
/* Heap for NanoStack */
33+
#if !MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP
3134
static uint8_t app_stack_heap[MBED_CONF_MBED_MESH_API_HEAP_SIZE + 1];
35+
#else
36+
static uint8_t *app_stack_heap;
37+
#endif
3238
static bool mesh_initialized = false;
3339

3440
/*
@@ -55,6 +61,10 @@ static void mesh_system_heap_error_handler(heap_fail_t event)
5561
void mesh_system_init(void)
5662
{
5763
if (mesh_initialized == false) {
64+
#if MBED_CONF_MBED_MESH_API_USE_MALLOC_FOR_HEAP
65+
app_stack_heap = malloc(MBED_CONF_MBED_MESH_API_HEAP_SIZE+1);
66+
MBED_ASSERT(app_stack_heap);
67+
#endif
5868
ns_hal_init(app_stack_heap, MBED_CONF_MBED_MESH_API_HEAP_SIZE,
5969
mesh_system_heap_error_handler, NULL);
6070
eventOS_scheduler_mutex_wait();

0 commit comments

Comments
 (0)