microbit: Added support for configurable GATT table size

Updates to MicroBitConfig options and initialisaiton code of the BLE stack to
allow Soft Device's GATT table to be of a given size. If this size is smaller
then the default, the runtime will reclaim that that memory as heap storage.
This commit is contained in:
Joe Finney 2016-02-08 00:57:20 +00:00
parent 260c05782e
commit dda8598513
3 changed files with 30 additions and 8 deletions

View File

@ -49,6 +49,25 @@
#define MICROBIT_HEAP_REUSE_SD 1
#endif
// The lowest address of memory normally reserved for Soft Device that is safe to use as heap storage
#ifndef MICROBIT_SD_GATT_TABLE_SIZE
#define MICROBIT_SD_GATT_TABLE_SIZE 0x700
#endif
// The highest address of memory normally reserved for Soft Device that is safe to use as heap storage
#ifndef MICROBIT_HEAP_SD_LIMIT
#define MICROBIT_HEAP_SD_LIMIT 0x20002000
#endif
#ifndef MICROBIT_HEAP_SD_SIZE
#define MICROBIT_HEAP_SD_SIZE 0x400
#endif
#ifndef MICROBIT_HEAP_BASE_BLE_ENABLED
#define MICROBIT_HEAP_BASE_BLE_ENABLED (MICROBIT_HEAP_SD_LIMIT - MICROBIT_HEAP_SD_SIZE)
#endif
// The lowest address of memory that is safe to use as heap storage when BLE is DISABLED
// Used to define the base of the heap when MICROBIT_HEAP_REUSE_SD is defined.
#ifndef MICROBIT_HEAP_BASE_BLE_DISABLED
@ -62,10 +81,6 @@
#define MICROBIT_HEAP_BASE_BLE_ENABLED 0x20001C00
#endif
// The highest address of memory normally reserved for Soft Device that is safe to use as heap storage
#ifndef MICROBIT_HEAP_SD_LIMIT
#define MICROBIT_HEAP_SD_LIMIT 0x20002000
#endif
//
// Fiber scheduler configuration

View File

@ -125,6 +125,9 @@ void microbit_initialise_heap(HeapDefinition &heap)
int
microbit_create_sd_heap(HeapDefinition &heap)
{
heap.heap_start = 0;
heap.heap_end = 0;
#if CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD)
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
@ -137,10 +140,8 @@ microbit_create_sd_heap(HeapDefinition &heap)
heap.heap_end = (uint32_t *)MICROBIT_HEAP_SD_LIMIT;
#endif
microbit_initialise_heap(heap);
#else
heap.heap_start = 0;
heap.heap_end = 0;
if (heap.heap_end > heap.heap_start)
microbit_initialise_heap(heap);
#endif
return MICROBIT_OK;

View File

@ -13,9 +13,11 @@
#endif
#include "ble.h"
extern "C"
{
#include "device_manager.h"
uint32_t btle_set_gatt_table_size(uint32_t size);
}
/*
@ -177,6 +179,10 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
#endif
// Start the BLE stack.
#if CONFIG_ENABLED(MICROBIT_HEAP_REUSE_SD)
btle_set_gatt_table_size(MICROBIT_SD_GATT_TABLE_SIZE - (MICROBIT_HEAP_SD_LIMIT - MICROBIT_HEAP_BASE_BLE_ENABLED));
#endif
ble = new BLEDevice();
ble->init();