Skip to content

Commit

Permalink
Changes from code review with Joe F (#10)
Browse files Browse the repository at this point in the history
* Movd MICROBIT_MODE_* defines to MicroBitConfig.h

* Search for embedded source and remove magic

* Fixed memcpy

* Change offset order

* Fixed memcpy for data
  • Loading branch information
microbit-sam authored Jun 4, 2018
1 parent 3413d54 commit 040f63b
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 487 deletions.
19 changes: 11 additions & 8 deletions inc/bluetooth/MicroBitBLEManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ DEALINGS IN THE SOFTWARE.
#define MICROBIT_BLE_STATUS_STORE_SYSATTR 0x02
#define MICROBIT_BLE_STATUS_DISCONNECT 0x04

#define MICROBIT_BLE_MODE_PAIRING 0x00
#define MICROBIT_BLE_MODE_APPLICATION 0x01

extern const int8_t MICROBIT_BLE_POWER_LEVEL[];

struct BLESysAttribute
Expand Down Expand Up @@ -150,7 +147,7 @@ class MicroBitBLEManager : MicroBitComponent
* @param enableBonding If true, the security manager enabled bonding.
*
* @code
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus);
* bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);
* @endcode
*/
void init(ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding);
Expand Down Expand Up @@ -293,10 +290,10 @@ class MicroBitBLEManager : MicroBitComponent

/**
* Get current BLE mode; application, pairing
* #define MICROBIT_BLE_MODE_PAIRING 0x00
* #define MICROBIT_BLE_MODE_APPLICATION 0x01
* #define MICROBIT_MODE_PAIRING 0x00
* #define MICROBIT_MODE_APPLICATION 0x01
*/
uint8_t getBLEMode();
uint8_t getCurrentMode();

private:
/**
Expand All @@ -320,7 +317,13 @@ class MicroBitBLEManager : MicroBitComponent
int pairingStatus;
ManagedString passKey;
ManagedString deviceName;
uint8_t bleMode = MICROBIT_BLE_MODE_APPLICATION;

/*
* Default to Application Mode
* This variable will be set to MICROBIT_MODE_PAIRING if pairingMode() is executed.
*/
uint8_t currentMode = MICROBIT_MODE_APPLICATION;

};

#endif
17 changes: 11 additions & 6 deletions inc/bluetooth/MicroBitPartialFlashingService.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 British Broadcasting Corporation.
This software is provided by Lancaster University by arrangement with the BBC.
This class has been written by Sam Kent for the Microbit Educational Foundation.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -41,6 +40,15 @@ DEALINGS IN THE SOFTWARE.

#define PARTIAL_FLASHING_VERSION 0x01

// BLE PF Control Codes
#define REGION_INFO 0x00
#define FLASH_DATA 0x01
#define END_OF_TRANSMISSION 0x02

// BLE Utilities
#define MICROBIT_STATUS 0xEE
#define MICROBIT_RESET 0xFF

// UUIDs for our service and characteristics
extern const uint8_t MicroBitPartialFlashingServiceUUID[];
extern const uint8_t MicroBitPartialFlashingServiceCharacteristicUUID[];
Expand Down Expand Up @@ -80,9 +88,6 @@ class MicroBitPartialFlashingService
*/
void partialFlashingEvent(MicroBitEvent e);

// The base address to write to. Bit masked: (0xFFFF0000 & region.endAddress) >> 16
uint8_t baseAddress = 0x3;

// Handles to access each characteristic when they are held by Soft Device.
GattAttribute::Handle_t partialFlashCharacteristicHandle;

Expand All @@ -98,7 +103,7 @@ class MicroBitPartialFlashingService
// Keep track of blocks of data
uint32_t block[16];
uint8_t blockNum = 0;
uint16_t offset = 0;
uint32_t offset = 0;

};

Expand Down
3 changes: 1 addition & 2 deletions inc/core/MicroBitComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ DEALINGS IN THE SOFTWARE.
#define MICROBIT_ID_MULTIBUTTON_ATTACH 31
#define MICROBIT_ID_SERIAL 32

#define MICROBIT_ID_PFLASH_NOTIFICATION 33
#define MICROBIT_ID_PAIRING_MODE 34
#define MICROBIT_ID_PARTIAL_FLASHING 33

#define MICROBIT_ID_MESSAGE_BUS_LISTENER 1021 // Message bus indication that a handler for a given ID has been registered.
#define MICROBIT_ID_NOTIFY_ONE 1022 // Notfication channel, for general purpose synchronisation
Expand Down
16 changes: 10 additions & 6 deletions inc/core/MicroBitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,9 @@ DEALINGS IN THE SOFTWARE.
#define BLE_BOND_DATA_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 18))
#endif

#ifndef MEMORY_MAP_PAGE
#define MEMORY_MAP_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 19))
#endif

// Scratch moved from page 19 to page 20
// MicroBitFileSystem uses DEFAULT_SCRATCH_PAGE to mark end of FileSystem
#ifndef DEFAULT_SCRATCH_PAGE
#define DEFAULT_SCRATCH_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 20))
#define DEFAULT_SCRATCH_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 19))
#endif

// Address of the end of the current program in FLASH memory.
Expand Down Expand Up @@ -441,6 +436,15 @@ extern uint32_t __etext;
#define MICROBIT_DAL_VERSION "unknown"
#endif

// micro:bit Modes
// The micro:bit may be in different states: running a user's application or into BLE pairing mode
// These modes can be representeded using these #defines
#ifndef MICROBIT_MODE_PAIRING
#define MICROBIT_MODE_PAIRING 0
#endif
#ifndef MICROBIT_MODE_APPLICATION
#define MICROBIT_MODE_APPLICATION 1
#endif

//
// Helper macro used by the micro:bit runtime to determine if a boolean configuration option is set.
Expand Down
16 changes: 8 additions & 8 deletions inc/drivers/MicroBitFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MicroBitFlash
* @return non-zero if erase required, zero otherwise.
*/
int need_erase(uint8_t* source, uint8_t* flash_addr, int len);

public:
/**
* Default constructor.
Expand All @@ -53,33 +53,33 @@ class MicroBitFlash
* Writes the given number of bytes to the address in flash specified.
* Neither address nor buffer need be word-aligned.
* @param address location in flash to write to.
* @param buffer location in memory to write from.
* @param buffer location in memory to write from.
* @length number of bytes to burn
* @param scratch_addr if specified, scratch page to use. Use default
* @param scratch_addr if specified, scratch page to use. Use default
* otherwise.
* @return non-zero on sucess, zero on error.
*
*
* Example:
* @code
* MicroBitFlash flash();
* uint32_t word = 0x01;
* flash.flash_write((uint8_t*)0x38000, &word, sizeof(word))
* @endcode
*/
int flash_write(void* address, void* buffer, int length,
int flash_write(void* address, void* buffer, int length,
void* scratch_addr = NULL);

/**
* Erase an entire page.
* @param page_address address of first word of page.
*/
uint8_t erase_page(uint32_t* page_address);
void erase_page(uint32_t* page_address);

/**
* Write to flash memory, assuming that a write is valid
* (using need_erase).
*
* @param page_address address of memory to write to.
*
* @param page_address address of memory to write to.
* Must be word aligned.
* @param buffer address to write from, must be word-aligned.
* @param len number of uint32_t words to write.
Expand Down
19 changes: 4 additions & 15 deletions inc/drivers/MicroBitMemoryMap.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 British Broadcasting Corporation.
This software is provided by Lancaster University by arrangement with the BBC.
This class has been written by Sam Kent for the Microbit Educational Foundation.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -31,8 +30,6 @@ DEALINGS IN THE SOFTWARE.
#include "ManagedString.h"
#include "ErrorNo.h"

#define MICROBIT_MEMORY_MAP_MAGIC 0xCA8E

#define NUMBER_OF_REGIONS 3

/**
Expand All @@ -56,32 +53,25 @@ class MicroBitMemoryMap
this->regionId = regionId;
this->startAddress = startAddress;
this->endAddress = endAddress;
memmove( this->hash, &hash, 8 );
memcpy( this->hash, hash, 8 );
}

Region(){
this->regionId = 0x0;
this->startAddress = 0x0;
this->endAddress = 0x0;
memset( this->hash, 0xDD, 8 );
memset( this->hash, 0x00, 8 );
}

};

struct MemoryMapStore
{
Region memoryMap[3];
Region memoryMap[NUMBER_OF_REGIONS];
};

uint8_t regionCount = 0;

/**
* Function to update the flash with the current MemoryMapStore
*
* @param memoryMapStore The memory map to write to flash
*/
void updateFlash(MemoryMapStore *store);

public:

MemoryMapStore memoryMapStore;
Expand Down Expand Up @@ -115,7 +105,6 @@ class MicroBitMemoryMap
/**
* Function to fetch hashes from PXT build
*
* @return int Boolean result of the search. 1 = Hashes Found; 0 = No Hash Found
*/
void findHashes();
};
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microbit-dal",
"version": "2.0.0-pf",
"version": "2.0.0-rc9",
"license": "MIT",
"description": "The runtime library for the BBC micro:bit, developed by Lancaster University",
"keywords": [
Expand Down
Loading

0 comments on commit 040f63b

Please sign in to comment.