Skip to content

Commit

Permalink
Allocated memory for the PFS buffer dynamically. Saves 60 bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-sam committed Oct 4, 2018
1 parent 94fa768 commit f42d1a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion inc/bluetooth/MicroBitPartialFlashingService.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class MicroBitPartialFlashingService
uint8_t blockPacketCount = 0;

// Keep track of blocks of data
uint32_t block[16];
// uint32_t block[16]; // Replaced with pointer, memory allocated when PFS is used
uint32_t *block = NULL;
uint8_t blockNum = 0;
uint32_t offset = 0;

Expand Down
7 changes: 6 additions & 1 deletion source/bluetooth/MicroBitPartialFlashingService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ DEALINGS IN THE SOFTWARE.
MicroBitPartialFlashingService::MicroBitPartialFlashingService(BLEDevice &_ble, EventModel &_messageBus) :
ble(_ble), messageBus(_messageBus)
{

// Set up partial flashing characteristic
uint8_t initCharacteristicValue = 0x00;
GattCharacteristic partialFlashCharacteristic(MicroBitPartialFlashingServiceCharacteristicUUID, &initCharacteristicValue, sizeof(initCharacteristicValue),
20, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);

// Set default security requirements
partialFlashCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);

// Create Partial Flashing Service
GattCharacteristic *characteristics[] = {&partialFlashCharacteristic};
GattService service(MicroBitPartialFlashingServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic*) );
Expand Down Expand Up @@ -200,6 +200,11 @@ void MicroBitPartialFlashingService::flashData(uint8_t *data)

packetCount++;

// Reallocate block
if(block == NULL) {
(uint32_t*) malloc(16 * sizeof(uint32_t));
}

// Add to block
memcpy(block + (4*blockNum), data + 4, 16);

Expand Down

0 comments on commit f42d1a1

Please sign in to comment.