updates
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal-eddystone by
Revision 32:ece16b5987dd, committed 2016-07-13
- Comitter:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:11 2016 +0100
- Parent:
- 31:87789e55bac7
- Child:
- 33:58453d751bca
- Commit message:
- Synchronized with git rev 36d9130b
Changed in this revision
--- a/inc/core/MicroBitSystemTimer.h Wed Jul 13 12:18:10 2016 +0100 +++ b/inc/core/MicroBitSystemTimer.h Wed Jul 13 12:18:11 2016 +0100 @@ -43,7 +43,7 @@ #include "MicroBitComponent.h" /** - * Initialises a system wide timer, used to drive the various components used in the runtime. + * Initialises the system wide timer. * * This must be called before any components register to receive periodic periodic callbacks. * @@ -70,26 +70,11 @@ int system_timer_get_period(); /** - * Updates the current time in microseconds, since power on. - * - * If the mbed Timer hasn't been initialised, it will be initialised - * on the first call to this function. - */ -inline void update_time(); - -/** * Determines the time since the device was powered on. * * @return the current time since power on in milliseconds */ -uint64_t system_timer_current_time(); - -/** - * Determines the time since the device was powered on. - * - * @return the current time since power on in microseconds - */ -uint64_t system_timer_current_time_us(); +unsigned long system_timer_current_time(); /** * Timer callback. Called from interrupt context, once per period.
--- a/inc/drivers/MicroBitStorage.h Wed Jul 13 12:18:10 2016 +0100 +++ b/inc/drivers/MicroBitStorage.h Wed Jul 13 12:18:11 2016 +0100 @@ -162,9 +162,13 @@ * * @param data a pointer to the beginning of the data to be persisted. * - * @return MICROBIT_OK on success, or MICROBIT_NO_RESOURCES if the storage page is full + * @param dataSize the size of the data to be persisted + * + * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if the key or size is too large, + * MICROBIT_NO_RESOURCES if the storage page is full */ - int put(const char* key, uint8_t* data); + int put(const char* key, uint8_t* data, int dataSize); + /** * Places a given key, and it's corresponding value into flash at the earliest @@ -174,9 +178,12 @@ * * @param data a pointer to the beginning of the data to be persisted. * - * @return MICROBIT_OK on success, or MICROBIT_NO_RESOURCES if the storage page is full + * @param dataSize the size of the data to be persisted + * + * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if the key or size is too large, + * MICROBIT_NO_RESOURCES if the storage page is full */ - int put(ManagedString key, uint8_t* data); + int put(ManagedString key, uint8_t* data, int dataSize); /** * Retreives a KeyValuePair identified by a given key.
--- a/inc/types/MicroBitEvent.h Wed Jul 13 12:18:10 2016 +0100 +++ b/inc/types/MicroBitEvent.h Wed Jul 13 12:18:11 2016 +0100 @@ -52,7 +52,7 @@ uint16_t source; // ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A. uint16_t value; // Component specific code indicating the cause of the event. - uint64_t timestamp; // Time at which the event was generated. us since power on. + uint32_t timestamp; // Time at which the event was generated. ms since power on. /** * Constructor.
--- a/source/bluetooth/MicroBitBLEManager.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/bluetooth/MicroBitBLEManager.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -99,7 +99,7 @@ if(memcmp(attribStore.sys_attrs[deviceID].sys_attr, attrib.sys_attr, len) != 0) { attribStore.sys_attrs[deviceID] = attrib; - manager->storage->put(key, (uint8_t *)&attribStore); + manager->storage->put(key, (uint8_t *)&attribStore, sizeof(attribStore)); } } }
--- a/source/bluetooth/MicroBitButtonService.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/bluetooth/MicroBitButtonService.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -45,8 +45,8 @@ GattCharacteristic buttonADataCharacteristic(MicroBitButtonAServiceDataUUID, (uint8_t *)&buttonADataCharacteristicBuffer, 0, sizeof(buttonADataCharacteristicBuffer), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); - GattCharacteristic buttonBDataCharacteristic(MicroBitButtonBServiceDataUUID, (uint8_t *)&buttonADataCharacteristicBuffer, 0, - sizeof(buttonADataCharacteristicBuffer), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); + GattCharacteristic buttonBDataCharacteristic(MicroBitButtonBServiceDataUUID, (uint8_t *)&buttonBDataCharacteristicBuffer, 0, + sizeof(buttonBDataCharacteristicBuffer), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); // Initialise our characteristic values. @@ -140,4 +140,4 @@ ; const uint8_t MicroBitButtonBServiceDataUUID[] = { 0xe9,0x5d,0xda,0x91,0x25,0x1d,0x47,0x0a,0xa0,0x62,0xfa,0x19,0x22,0xdf,0xa9,0xa8 -}; +}; \ No newline at end of file
--- a/source/core/MicroBitSystemTimer.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/core/MicroBitSystemTimer.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -42,21 +42,18 @@ * Time since power on. Measured in milliseconds. * When stored as an unsigned long, this gives us approx 50 days between rollover, which is ample. :-) */ -static uint64_t time_us = 0; +static unsigned long ticks = 0; static unsigned int tick_period = 0; // Array of components which are iterated during a system tick static MicroBitComponent* systemTickComponents[MICROBIT_SYSTEM_COMPONENTS]; // Periodic callback interrupt -static Ticker *ticker = NULL; - -// System timer. -static Timer *timer = NULL; +static Ticker *timer = NULL; /** - * Initialises a system wide timer, used to drive the various components used in the runtime. + * Initialises the system wide timer. * * This must be called before any components register to receive periodic periodic callbacks. * @@ -66,14 +63,8 @@ */ int system_timer_init(int period) { - if (ticker == NULL) - ticker = new Ticker(); - if (timer == NULL) - { - timer = new Timer(); - timer->start(); - } + timer = new Ticker(); return system_timer_set_period(period); } @@ -92,11 +83,11 @@ // If a timer is already running, ensure it is disabled before reconfiguring. if (tick_period) - ticker->detach(); + timer->detach(); // register a period callback to drive the scheduler and any other registered components. tick_period = period; - ticker->attach_us(system_timer_tick, period * 1000); + timer->attach_us(system_timer_tick, period * 1000); return MICROBIT_OK; } @@ -112,40 +103,13 @@ } /** - * Updates the current time in microseconds, since power on. - * - * If the mbed Timer hasn't been initialised, it will be initialised - * on the first call to this function. - */ -void update_time() -{ - // If we haven't been initialized, bring up the timer with the default period. - if (timer == NULL || ticker == NULL) - system_timer_init(SYSTEM_TICK_PERIOD_MS); - - time_us += timer->read_us(); - timer->reset(); -} - -/** * Determines the time since the device was powered on. * * @return the current time since power on in milliseconds */ -uint64_t system_timer_current_time() +unsigned long system_timer_current_time() { - return system_timer_current_time_us() / 1000; -} - -/** - * Determines the time since the device was powered on. - * - * @return the current time since power on in microseconds - */ -uint64_t system_timer_current_time_us() -{ - update_time(); - return time_us; + return ticks; } /** @@ -156,7 +120,8 @@ */ void system_timer_tick() { - update_time(); + // increment our real-time counter. + ticks += system_timer_get_period(); // Update any components registered for a callback for(int i = 0; i < MICROBIT_SYSTEM_COMPONENTS; i++) @@ -179,7 +144,7 @@ int i = 0; // If we haven't been initialized, bring up the timer with the default period. - if (timer == NULL || ticker == NULL) + if (timer == NULL) system_timer_init(SYSTEM_TICK_PERIOD_MS); while(systemTickComponents[i] != NULL && i < MICROBIT_SYSTEM_COMPONENTS)
--- a/source/drivers/MicroBitCompass.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/drivers/MicroBitCompass.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -703,7 +703,7 @@ void MicroBitCompass::setCalibration(CompassSample calibration) { if(this->storage != NULL) - this->storage->put(ManagedString("compassCal"), (uint8_t *)&calibration); + this->storage->put(ManagedString("compassCal"), (uint8_t *)&calibration, sizeof(CompassSample)); average = calibration; status |= MICROBIT_COMPASS_STATUS_CALIBRATED;
--- a/source/drivers/MicroBitStorage.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/drivers/MicroBitStorage.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -209,14 +209,22 @@ * * @param data a pointer to the beginning of the data to be persisted. * - * @return MICROBIT_OK on success, or MICROBIT_NO_RESOURCES if the storage page is full + * @param dataSize the size of the data to be persisted + * + * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if the key or size is too large, + * MICROBIT_NO_RESOURCES if the storage page is full */ -int MicroBitStorage::put(const char *key, uint8_t *data) +int MicroBitStorage::put(const char *key, uint8_t *data, int dataSize) { KeyValuePair pair = KeyValuePair(); - memcpy(pair.key, key, min(sizeof(pair.key), strlen(key))); - memcpy(pair.value, data, sizeof(pair.value)); + int keySize = strlen(key) + 1; + + if(keySize > (int)sizeof(pair.key) || dataSize > (int)sizeof(pair.value) || dataSize < 0) + return MICROBIT_INVALID_PARAMETER; + + memcpy(pair.key, key, keySize); + memcpy(pair.value, data, dataSize); //calculate our various offsets. uint32_t pg_size = NRF_FICR->CODEPAGESIZE; @@ -290,11 +298,14 @@ * * @param data a pointer to the beginning of the data to be persisted. * - * @return MICROBIT_OK on success, or MICROBIT_NO_RESOURCES if the storage page is full + * @param dataSize the size of the data to be persisted + * + * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if the key or size is too large, + * MICROBIT_NO_RESOURCES if the storage page is full */ -int MicroBitStorage::put(ManagedString key, uint8_t* data) +int MicroBitStorage::put(ManagedString key, uint8_t* data, int dataSize) { - return put((char *)key.toCharArray(), data); + return put((char *)key.toCharArray(), data, dataSize); } /**
--- a/source/drivers/MicroBitThermometer.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/drivers/MicroBitThermometer.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -245,7 +245,7 @@ int MicroBitThermometer::setOffset(int offset) { if(this->storage != NULL) - this->storage->put(ManagedString("tempCal"), (uint8_t *)&offset); + this->storage->put(ManagedString("tempCal"), (uint8_t *)&offset, sizeof(int)); this->offset = offset;
--- a/source/types/MicroBitEvent.cpp Wed Jul 13 12:18:10 2016 +0100 +++ b/source/types/MicroBitEvent.cpp Wed Jul 13 12:18:11 2016 +0100 @@ -58,7 +58,7 @@ { this->source = source; this->value = value; - this->timestamp = system_timer_current_time_us(); + this->timestamp = system_timer_current_time(); if(mode != CREATE_ONLY) this->fire(); @@ -71,7 +71,7 @@ { this->source = 0; this->value = 0; - this->timestamp = system_timer_current_time_us(); + this->timestamp = system_timer_current_time(); } /**