Commit Graph

347 Commits

Author SHA1 Message Date
Joe Finney 9d039fd9be microbit: BUGFIX Corrected length calculation for validation case
Incorreclty calculated payload bug also addressed here.
2016-02-03 14:41:45 +00:00
Joe Finney 5cb265c158 microbit: BUGFIX: Length field of datagram receive now correct
Datagram receive code incorrectly calculated the payload length, resulting in
packets being delivered to applications that were two bytes shorter than they
should be.
2016-02-03 14:35:12 +00:00
James Devine 41447b634d Merge pull request #89 from lancaster-university/ble-ccccd-persist
Basic Persistent Storage
2016-02-02 21:50:33 +00:00
James Devine 23d56edbdd microbit: integrated MicroBitStorage with MicroBitCompass
This commit introduces persistent storage for the compass between
device resets.

setCalibration now also stores the data in FLASH if it differs from
what it contains.

In source/MicroBitSuperMain.cpp, the data is restored if there is
persistent data available that is non-zero.

(i.e. x, y and z are NOT zero).

This ensures that users can code without interference from persistent
storage.
2016-02-02 21:24:40 +00:00
James Devine 4c9f32d79a microbit: added debug to MicroBitStorage
Added debug to make testing simpler and faster.
2016-02-02 21:24:40 +00:00
Joe Finney 5e7334b0bf microbit: integrated persistent storage for CCCD data.
There is an issue (https://github.com/bbc/microbit-extras/issues/2755)
whereby CCCD data is required to be persisted through device resets.

This commit integrates the new MicroBitStorage class, and persistently
stores this information in flash.

P.S. what a long night!
2016-02-02 21:24:40 +00:00
Joe Finney d1d78b9b35 microbit: added MicroBitStorage for Persistent data
Integrated simple 1K block buffer to host small amount of persistent
data and a 1K FLASH memory block located immediately below the FOTA/DFU
bootloader and APPDATA region that intended to hold core configuration
information, such as:

* BLE bonding information.
* Compass Calibration data.
* Thermometer Calibration data.

The block is resident at 0x0003B400 - 0x0003B800.
2016-02-02 21:22:49 +00:00
James Devine f546da66e8 microbit: improved appearance of greyscale
The impact of the pixels at lower values was  not distinct enough
this commit adds a blocking wait for the first two timings for
greyscale.

Additionally, this commit  modifies the timings const array to
take into account the time taken for renderGreyscale to execute.
2016-02-02 17:05:59 +00:00
James Devine 3596f3d842 microbit: update to greyscale mode
Floats were used as timings for the renderTimer in MicroBitDisplay.
Now timings are in us, and a direct called to renderTimer.attach_us
is now used.
2016-02-02 16:36:09 +00:00
James Devine 4cefd55ef5 microbit: updated the dal to use a higher resolution ticker.
Previously the DAL relied upon an implementation of a timer that
was very imprecise and lacked resolution, this commit adds a reference
to a frozen repo with us_ticker.c modifications, so that a higher resolution
timer is utilised.

This fixes #13 (finally), and also fixes lower brightness levels when using
DISPLAY_MODE_BLACK_AND_WHITE to not cause a device lockup.
2016-02-02 16:21:28 +00:00
James Devine 3fa9bb09c2 microbit: fixed an off by 10 bug
Missed a zero in a previous commit, that caused a system lockup due to
a missed timer event.

This commit also changes the minimum display brightness to 4, to also
minimise another feature that needs fixing in the future, where the
timer does not interrupt in the expected time frame.
2016-02-02 01:13:39 +00:00
James Devine a27b2314be microbit: modified the range of read() MicroBitLightSensor
Previously the range of MicrobitLightSensor read() was 0 - 100,
this didn't align with other APIs.

The new range is 0-255 which aligns with display brightness to give
a more consistent overall API.
2016-02-01 23:58:33 +00:00
Joe Finney e983b80b0b Merge branch 'master' into ble-bondtablepurge 2016-02-01 22:50:05 +00:00
Joe Finney e7132b0d13 microbit: Change to BLE bonding table replacement policy
Previous revisions of microbit-dal would handle the case of a bonding request
when the bond table was full by attempting to purge the bonding table on
demand. This suffered two flaws:

 1) Nordic's device manager does not support the purging of the bonding table
while a connection is active (including a pairing request).

 2) Some devices (e.g. Android 4.4.2 take two entries in the bonding table
when paired), thus making predictions of how 'full' the table is challenging.

This patch employs a simpler replacement policy. The maximum size of the bond
table has been increased to 6 (from 4). However, if the bond table contains 4
or more entries when entering pairing mode it will be purged in advance of any
pairing requetss being initiated.
2016-02-01 22:30:03 +00:00
James Devine 97c49d3279 Merge pull request #87 from lancaster-university/broadcast-radio
Adding Multicast peer-to-peer radio support MicroBitRadio!
2016-02-01 21:50:54 +00:00
James Devine 004b701419 Merge pull request #86 from lancaster-university/light-sensor
Adding MicroBitLightSensor to the DAL
2016-02-01 21:50:22 +00:00
James Devine 8150b2ac67 microbit: modified as per suggestions
* This commit fixes an exposed member variable
  that was not intended to be public 'tickPeriod'

* normalised the light level to return values between 0 - 100
2016-02-01 21:46:15 +00:00
Joe Finney 9026ca6e98 microbit: Optimisation of BLE mutex.
The BLE stack locks out the CPU for long periods of time when necessary. This
can be alleviated by eans of a flag that release the CPU between radio events.
(BLE_COMMON_OPT_RADIO_CPU_MUTEX).

This can cause issues from applications with tighter timing requirements.
This patch only enables this MUTEX when a BLE connection is active, rather
than automatically at startup. Therefore, application that do not actively use
BLE will not suffer this penalty.
2016-02-01 19:25:07 +00:00
Joe Finney 6838b38fc1 microbit: Remove redundant characteristics in BLE DeviceInformationService
The MANUFACTURER and HARDWARE_REVISION fields from this standard service have
been removed, as they carried no useful information.
2016-02-01 18:59:48 +00:00
Joe Finney 8bec31fe76 microbit: Additional validation on MicroBitRadio methods
MicroBitRadio methods that touch internal RADIO registers now ensure that
the BLE stack is not running before changing such registers.
2016-02-01 18:19:02 +00:00
Joe Finney d7aa95e867 microbit: minor updates to consistently use the MICROBIT_RADIO_HEADER_SIZE constant 2016-02-01 18:05:02 +00:00
Joe Finney 12c9ed246a microbit: Whitespace fixes 2016-02-01 17:54:33 +00:00
Joe Finney 420a73673d microbit: rename of MicroBitRadioEvent methods to align with MessageBus naming conventions. 2016-02-01 17:43:17 +00:00
Joe Finney 336c30f2ec microbit: Integrate Multicast peer to peer communications into MicroBit.cpp
- Added instance variable and constructor call in MircoBit.cpp
  - Added event definitions for RADIO related indications
2016-02-01 04:40:21 +00:00
Joe Finney d9d2343ab6 microbit: Add Multicast peer-to-peer radio capability
Integration of new radio mode that permits simple local area multicast communication
directly between micro:bits using the device's on board radio hardware.

It should be noted that this implementation build directly on the nrf51822
hardware. It is not a BLE protocol, and must (currently) be operated with BLE
disabled.

A standard on the wire configuration is defined, to promote future
interoperability between projects and languages. A lightweight
packet format is also defined and adhered to, so as to promote future
extensibility without sacrificing compatibility. The notion of groups is also
introduced, that enable multiple groups of children to work in the same area
without compromising each other's projects.

In adition to a low level packet radio driver, two higher level protocols are
defined that allow simple user datagram communication between micro:bits and
an EventBus protocol that allows the micro:bit's MessageBus to be extended to
other micro:bits.
2016-02-01 04:29:27 +00:00
Joe Finney e3a23988f6 microbit: Promote constants in MicroBitBLEManager to .h file
Moved configuration constants from .cpp to .h file, so that they can be reused
more easily from other code, such as the broadcast radio code.
2016-02-01 04:25:51 +00:00
James Devine 6b0e9cf489 microbit: integrated MicroBitLightSensor with MicroBitDisplay
Previously, to light sense a user would have to configure a
MicroBitLightSensor instance themselves, and flip the display mode
manually. This is difficult in languages that target our API.

This commit resolves that by adding a new method readLightLevel which
flips the display mode, and instantiates a light sensor.

When changing the mode, the tickSpeed is also modified to reduce
artefacts on the display.
2016-01-29 14:13:41 +00:00
James Devine 2049e63039 microbit: added MicroBitLightSensor
Added a new class called MicroBitLightSensor which interleaves sensing
with the display.

This class takes advantage of the previous commits which add a dynamic
system tick, and a new display mode for the display.

A future optimisation would be for the display to handle the instantion
of a light sensor when the display mode is changed!
2016-01-29 14:10:52 +00:00
James Devine 6e316dc741 microbit: added accessor/mutator for systemTick
This commit adds a mutator that dynamically reconfigures the
systemTicker to call systemTick at a different period to the default.

The accessor returns the current tick speed in milliseconds.

The accessor is now also used in scheduler_tick to keep timing as
accurate as possible.

MICROBIT_DISPLAY_REFRESH_PERIOD has now been removed, and replaced with
MICROBIT_DEFAULT_TICK_PERIOD.
2016-01-29 14:07:36 +00:00
James Devine 6f812aa474 microbit: added new display mode, and accessor
This commit introduces a new display mode,
DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE, where the 4th render in
every “frame” is dropped allowing for other components that use the
display to use this dropped frame for processing. This is in
preparation for Light Sensing on the 5x5 LED matrix.

An accessor has also been added to MicroBitDisplay to check the current
display mode!
2016-01-29 14:03:24 +00:00
James Devine 6939ad25d9 microbit: formatting changes to MicroBitFiber
Corrected whitespace in MicroBitFiber.
2016-01-29 13:57:34 +00:00
Joe Finney 0bbb5b9123 microbit: Code cleanup
Removal of debugging information and redundant algorithms.
2016-01-28 17:09:01 +00:00
Joe Finney 8756bbd103 WIP: Lower RAM footprint compass calibration
- moved to single precision floats
- optimised transpose/multiply operation
- optimisation of algorithm
2016-01-26 21:52:22 +00:00
Joe Finney e3fdc5a290 microbit: Support for bonding only available in pairing mode
Update to BLE initialisation code. Ability to initiate pairing is now
restricted to pairing mode.
2016-01-25 21:05:15 +00:00
Joe Finney 99d7231945 microbit: Persistance of BLE Service Chnaged metadata
BLE maintains metadata on its characterisitics, some of which record whether
or not a central device (phone/tablet) wishes to receive notifications when a
given BLE characteristic changes value. One such characterisitic is used as
part of a core BLE service to indicate of the BLE profile of a device has
changed.

IOS is heavily reliant on this feature, and expects the state of this metadata
to be persistent across device reboots. This patch ensures that this metadata
is always set to allow Service Changed indications to be propagated to central
devices.
2016-01-25 21:05:13 +00:00
Joe Finney 6a7436e5c7 Merge pull request #48 from remay/quiet-gcc-build
Tidy up gcc -Wall fixes

Thanks @remay!
2016-01-25 20:55:37 +00:00
Damien George 3160ba6268 Make MicroBit::seedRandom a public function with 2 variants.
seedRandom() seeds from the hardware RNG, whilst seedRandom(uint32_t)
seeds from the given 32-bit number.
2016-01-25 15:20:25 +00:00
Joe Finney a4c0915fff microbit: BUGFIX Prevent BLE Magnetometer service from initiating compass
calibration

MicroBitCompass initiates a calibration procedure on demand if a heading is
requested from an uncalibrated device. The BLE MagnetometerService also
attempts to retrieve a heading periodically, but it is not good behaviour to
initiate calibration as a response to this.

This patch introduces a check such that the BLE MagnetometerService will only
attempt to read heading data from a previously calibrated compass.
2016-01-19 00:32:02 +00:00
Joe Finney 4f1870fda9 Merge branch 'master' into ble-whitelisting 2016-01-17 00:44:35 +00:00
Joe Finney 13eb3c07e7 microbit: Add explicit service changed notification
BLE central devices (such as mobile phones/tablets) are permitted to cache the
list of services and characteristics provided by a BLE peripheral such as the
micro:bit. This was causing compatibility problems with IOS during FOTA
flashing, as the the list of BLE services may change after flashing.
2016-01-17 00:23:00 +00:00
Joe Finney 1c9ae30d1c microbit: Added basic bond table management
The Nordic BLE stack contains a fixed size bond table - a list of devices that
have paired with our device (in the case the micro:bit). The default mbed
wrapper around the nordic stack does not account for the case where the bond
table is full.

This patch implements basic bounds checking within the MicroBitBLEManager so
that this table cannot overrun. If a new device attempts to pair when the bond
table is full, the table is emptied prior to completing bonding.
2016-01-16 21:05:46 +00:00
Joe Finney e754ecf3aa microbit: Setting of default BLE transmission power level
Added configuration option in MicroBitConfig to allow the default power level
to be defined. Based on experiments undertaken by the BBC and subsequent policies defined by
the BBC's child protection panel, to is set by default it's lowest level (0),
in order to protect children's privacy.

It should be noted that this is 30dB below the device's default setting, so will
inevitably leave the device more susceptible to interference, and therefore
significantly reduce the reliability of the device. This will likely present
itself through increased packet loss, reduced thorughout, lost data and
connection drop outs. The normal BLE power level on commercial devices
translates to  power level of 6.

The author has witnessed an inability to connect to a micro:bit from a
distance of 40cm under domestic conditions using a Samsung S5 mini
running Android 4.4.2.
2016-01-16 17:29:46 +00:00
Joe Finney 07852b0cd6 microbit: Added support for BLE transmission power control
Added new method to MicroBitBLEManager to allow the radio transmission power
to be controlled. Provides a linear power level scale in the range 0..7.
2016-01-16 17:07:20 +00:00
Joe Finney f17151a0bf microbit: Added optional support for whitelisting and limited advertising
Added MicroBitConfig.h option to enable/disable whitelisting
Added MicroBitConfig.h option to enable/disable limited period advertising
Added support for limited period advertising
Minor code cleanups
2016-01-16 16:54:58 +00:00
James Devine b2484dcc97 microbit: patch for animation/scroll behaviour for images
See bbc/microbit-extras/issues/#1100 or lancaster-university/microbit-dal/issues/5 for full details.

Summary:

A stride of 0 would lock the calling fiber indefinitely, which was not the expected behaviour
for many people.

This update fixes this issue in both animate and scroll, returning immediately when there is
a stride of zero.
2016-01-14 12:56:58 +00:00
Robert May 098a2378e3 Merge lancaster-university/master and silence warnings. 2016-01-13 20:51:49 +01:00
James Devine acf6bf76eb microbit: further fixes to #73
issue #73 highlighted an issue whereby the destruction of an instance
registered as an idle or system component, would result in a hardfault.

This was due to not deregistering idle or system callbacks.

This patch has been applied to all components currently in use by the
idle or system callbacks.
2016-01-13 16:25:34 +00:00
James Devine 1cc814da60 microbit: further formatting corrections
Corrected trailing whitespace, and tabulated lines with no content for:

* MicroBitCompass.h (.cpp)
* MicroBitDisplay.h (.cpp)
* MicroBitMessageBus.h (.cpp)
2016-01-13 16:16:18 +00:00
James Devine d8240cfb74 microbit: formatting changes to MicroBitAccelerometer.h (.cpp)
Removed trailing whitespace, and tabulated lines with no content.
2016-01-13 16:01:51 +00:00
James Devine a209857007 microbit: fix for #74
Replaced newer struct-style initialisation of CompassSample in MicroBit.cpp
with the more traditional constructor-style initialisation, to enfore
C98 compliance.

Closes #74
2016-01-13 15:12:13 +00:00
James Devine 7b7998e4eb microbit: formatting changes to MicroBit.h (.cpp)
Removed trailing whitespace, and tabulated lines with no content.
2016-01-13 15:04:29 +00:00
James Devine 8d3f3affbd microbit: fix for #73
The destructor for MicroBitButton didn't take into account the fact that
an instance can be destructed after registering a callback. This would then
result in a HardFault if an instance was destructed.

A clear repro case was registering a Touch input on a pin (abstracted as a button)
and swapping to a DigitalIn.
2016-01-13 14:15:50 +00:00
James Devine d2df88417b microbit: whitespace changes to MicroBitButton.h and .cpp
Cleared the files of trailing whitespace, and tabulated lines
2016-01-13 14:07:10 +00:00
Joe Finney 90cf35a38a WIP: compiling but untested first cut at whitelisting code 2016-01-13 00:20:37 +00:00
James Devine 983e9e1ad3 microbit: added Servo API to MicroBitPin
* Added a number of #defines to MicroBitPin.h which ultimately lead to retabulation of the #defines

* Added two new instance methods:

	- setServoValue() which sets the default servo period (20ms) and accepts a value in the range
			  0 - 180, which maps to a duty cycle between 5% and 10% respectively. This
			  mapping is also configurable.

	- setServoPulseUs() which accepts a pulse width in microseconds, and maps it onto the PWM
			    channel.
2016-01-12 20:54:09 +00:00
James Devine 2650aaa569 microbit: MicroBitPin api additions
Based on the previous commit, the api for MicroBitPin
has two new accessor methods:

	* getAnalogPeriodUs
	* getAnalogPeriod

There are also whitespace changes in the MicroBitPin head file
as well as some minor textual changes.
2016-01-12 20:52:50 +00:00
James Devine 32c40cdc29 microbit: DynamicPwm fixes and additions
This commit introduces an initial draft fix
for a bug where it would take two "setPeriods" for the
PWM class to update to the expected value.

This commit also adds three new methods to a DynamicPwm instance:

	* write() -  which is a lightweight wrapper around PwmOut write,
	  so that the value can be trapped. The trapping of the value
	  is necessary for the bug fix.
	* getPeriod() - which returns the value of a static variable,
	  containing the current period shared across the pwm bus.
	* getValue() - which returns a scaled value in the range 0-1024
	  representing the current duty cycle.
2016-01-12 20:50:42 +00:00
James Devine 500f851991 microbit: whitespace corrections
Corrected additional whitespace on some lines of source/MicroBitPin.cpp
2016-01-12 20:50:42 +00:00
James Devine 643f408ed2 microbit: modified the behaviour of pwm allocation
Dynamic pwm previously didn't round robin transient pwm channels,
and would therefore bias towards the first transient channel it found.
This update ensures that there is now an equal opportunity for all
channels to be considered for redirection.
2016-01-12 20:50:42 +00:00
James Devine 68474c5e58 microbit: modified constructor for DynamicPwm
Previously there would be the possibility of the period being reset
each time a new DynamicPwm was instantiated. This has now been
removed from the constructor, and the comments have been updated
2016-01-12 20:50:42 +00:00
James Devine 6b1e020392 microbit: formatting corrections
There was some incorrect tabulation in a few lines of this file, this has now been corrected.
2016-01-12 20:50:42 +00:00
James Devine c04de3f93c Merge pull request #47 from remay/serial-baud
Remove unnecessary uBit.serial.baud() calls
2016-01-11 14:03:40 +00:00
Joe Finney 32961973bb microbit: Updates to MicroBitAccelerometer to use sample data accessor methods throughout.
All internal uses of accelerometer sample values now updated to access the
data via accessor methods. This now ensures consistent use irrespective of
the coordinate system used.
2016-01-09 19:32:30 +00:00
Joe Finney 0da7903e24 Merge branch 'master' into compass-autocalibration 2016-01-09 19:10:04 +00:00
Joe Finney db25d4c0c3 microbit: Further corrections to comment blocks 2016-01-09 18:47:15 +00:00
Joe Finney 0e7a6979da microbit: Comment Cleanup
corrections to comment blocks only.
2016-01-09 11:54:23 +00:00
Joe Finney 6916d506b8 microbit: Removed print funcitons from matrix class due to SRAM overhead of
native printf() call.

The Matrix4::print() function is useful, but non essential for most
applications, and the underlying printf() call required cost an
additional 1K of RAM on first use, which is currently above the budget for
micro:bit.
2016-01-09 10:25:26 +00:00
Joe Finney d51b1205f7 microbit: Added support for compass tilt compensation
An e-compass solution requires knowwlede two pieces of data to provide an
accurate heading:

  - Accurate calibration of the magnetometer hardware so that reliable
    measurements can be taken.
  - Knowledge of the pitch and roll of of device, so that the correct
    components of the X/Y and Z axis sensors of the magnetomer can be used
    to sense the magnetic field in a horizontal plane regardless of the tilt
    of the device.

This commit represent changes to the MicroBitAccelerometer and MicroBitCompass
classes to implemen tthese goals. More specifically, this commit provides:

 - The introduciton of an interactive calibration 'game', that can rapidly
   gather all the data required to calibrate the compass.

 - An improved calibration algorithm based on a Least Mean Squares approach of
   compass samples, as documened in Freescale Application Note AN4248.

 - The inclusion of a simple Matrix4 class to enable efficient Least Mean
   Squares implementation.

 - A change from asynchronous to synchronous calibration of the compass when
   first used. This is in repsonse to a feature request for this from users
   and high level languages using microbit-dal.

 - Support for detemrining tilt and roll angle in MicroBitAccelerometer

 - Support for multiple co-ordinate spaces in MicroBitAccelerometer and
   MicroBitCompass. Data can now be read in either RAW (unaltered) data.
   MICORBIT_SIMPLE_CARTESIAN (as used previously) or NORTH_EAST_DOWN
   (the industry convention in mobile phones, tablets and aviation)

 - Implementation of a tilt compensated algorithm, used when determining
   device heading.
2016-01-09 00:20:19 +00:00
Joe Finney 3416e54a36 microbit: increase sensitivity of freefall detection
Freefall now detected when the net force on the device drops below 0.4g,
rather than 0.2g as previously defined. This improves sensitivity, without
generating false positives under common use.

Also correction of minor typos / layout errors.
2016-01-05 16:23:47 +00:00
Joe Finney 17632adafa Merge branch 'master' into basic-gestures 2016-01-05 15:50:53 +00:00
Joe Finney d3587d888c microbit: code scrub of MicroBitAccelerometer gesture recognition code
- updated acceleration threshold event names to reflect numeric values e.g.
    GESTURE_3G, GESTURE_6G, GESTURE_8G.
  - Add scoping to elements of SimpleGesture enum.
  - Code scrub of code layout caused by editor with incorrect configuration.
  - rename of internal state variables and functions to better reflect use.
  - added clarification to some comments.
2016-01-05 15:44:57 +00:00
Joe Finney 55601f3e0e Merge branch 'master' into secure-ble 2016-01-05 01:25:52 +00:00
Joe Finney 6763a9ba6c Merge branch 'ble-disconnect-on-reset' of https://github.com/remay/microbit-dal into remay-ble-disconnect-on-reset 2016-01-05 00:13:26 +00:00
Joe Finney e1f75b2c4c microbit: Added read capability to MicroBitDFUService::ControlPoint characteristic
Whilst Android devices permit explicit initiation of the BLE pairing process,
IOS based devices are only  capable of implicit initiation of pairing based
on accessing a protected characteristic. Adding read capability to the
ControlPoint characteristic provides a safe and convenient way for IOS devices
to initiate pairing.
2016-01-04 23:41:22 +00:00
Joe Finney 7a71b58bd4 microbit: Revert explicit use of public addresses in pairing mode 2016-01-04 23:06:48 +00:00
Joe Finney 203246b975 WIP: Revert to public addresses pending further debug 2015-12-18 12:27:08 +00:00
Joe Finney c7ea0af6fe WIP: Analysing correct use of private resolvable addresses 2015-12-17 14:27:57 +00:00
Joe Finney 14831ac9b9 Updates to BLE 2.1.11 / ble-nrf51822 2.2.3
Minor amends:
  - bleDisconnectionCallback signature change
  - bleSetAdvertisingInterval now takes milliseconds as a parameter
  - event based invocation of DFU bootloader
2015-12-11 04:57:06 +00:00
Joe Finney 6d610f049a microbit: Updates to Pairing Mode to improve the user experience
More specifically:

- BLUEZONE mode renamed to PairingMode (by popular request).
- Added timeout of 90 seconds before automatic device reboot.
- Move from a scroll to a print based algorithm to improve the amount of time key is displayed fully.
- Added compulsory 'click to bond' button press.
- Improved response time of tick/cross being displayed.
2015-12-11 03:43:18 +00:00
Joe Finney 5a9f5d42bd microbit: Updates to enable anonymous advertising during normal operation
Changes to default BLE name. During normal operation, all micro:bits now have the same name: BBC micro:bit
When pairing mode (AKA BLUEZONE) is entered, device name details re appended as before, to give BBC micro:bit [<name>]

This is to provide a degree of anonymity to users, to make tracking of kids more difficult.
2015-12-11 02:09:31 +00:00
Joe Finney e042a55522 microbit: Added compile time option to enabe support for BLE private resolvable addresses.
Introduced MICROBIT_BLE_PRIVATE_ADDRESSES configuration option.
Disabled by default, as it did not resolve binds correctly on Android 4.4.2
2015-12-11 01:38:22 +00:00
Joe Finney 6f5ad99aa2 BUGFIX: Enabled BLE_COMMON_OPT_RADIO_CPU_MUTEX option
This option is now configured when the BLE stack is initialised. This ensures that SoftDevice is never
starved of CPU during periods of criticality. This does lock out the CPU for application use, but prevents
MIC failures caused by __disable_irq() operations (as found in the mbed Ticker API for example).
2015-12-11 01:16:48 +00:00
Joe Finney b6ca1365f7 microbit: Added explicit BLE disconnection requests on DFU and soft reset 2015-12-11 00:55:33 +00:00
Joe Finney 1e5d5c8dcf Updates to BLE 2.1.11 / ble-nrf51822 2.2.3
Minor amends:
  - bleDisconnectionCallback signature change
  - bleSetAdvertisingInterval now takes milliseconds as a parameter
  - event based invocation of DFU bootloader
2015-12-11 00:24:21 +00:00
Joe Finney 1b18ac8641 microbit: Added basic gesture recognition into MicroBitAccelerometer
The following postures of the device are now detected:
- TILT_UP
- TILT_DOWN
- TILT_LEFT
- TILT_RIGHT
- FACE_UP
- FACE_DOWN

In addition, the following gestures are inferred:

- NONE
- SHAKE
- FREEFALL
- WHEEE (>=3g)
- SICK (>=5g)
- UNCONSCIOUS (>=8g)

Events are now triggered on the MessageBus upon the transition from one posture/gesture to another,
and a synchronous getGesture() method is now also provided to interogate the last gesture recognised.

I should be noted that the default accelerator range of +/-2g will be insufficient to detect some of
the events noted above, and MicroBitAccelerometer::setRange() should be used to increase the range
if required.
2015-12-03 15:11:31 +00:00
Joe Finney f5cf8f2dd4 microbit: Minor optimisations to patch
- LFSR generated values in a subset of the range requested (rounded to the nearest lower power of 2).
   Corrected by increasing the number of bits usedby one, such that it now generated st least the power of 2 greater.

 - replaced enable/disable of interrupts with a local snapshot of randomValue. Much of the nordic software is sensitive to interrupt timings,
   so best avoided where possible. Chance of race condition is low, and effect is minimal (duplicate number returned).
2015-11-30 00:43:24 +00:00
Joe Finney 958136673f Merge branch 'fix-random' of https://github.com/remay/microbit-dal into remay-fix-random 2015-11-29 23:43:46 +00:00
Joe Finney ae93079a65 code cleanup 2015-11-25 21:21:04 +00:00
Joe Finney 6d1004fb28 Updates to DFU service to align with BLE standard BLE security
- Removed flashcode base authorization
- silenced unused parameter in MicroBitHeapAllocator
- bugfixed BLUEZONE mode so that sensor data is still available via BLE
2015-11-20 11:32:42 +00:00
Robert May 051575d911 Tidy up gcc -Wall fixes. 2015-11-18 23:13:57 +00:00
Robert May de681e68c3 Add diagnostic message to yotta/cmake output to remind us that we have silenced warnings. 2015-11-18 23:04:59 +00:00
Robert May 6c330079b1 Remove unnecessary uBit.serial.baud() calls
The serial baud rate is set duing construction of the uBit object.  We
don't need to do it again, and especially with fixed values that can't
be overridden.
2015-11-18 22:50:19 +00:00
Robert May 5333729644 Revert "Cchange random() to use libc srand()/rand()"
This reverts commit db5227872a.

return to using our own random implementation.
2015-11-18 15:50:44 +00:00
Robert May db5227872a Cchange random() to use libc srand()/rand()
Uisng libc's implementation is likely to be safer than rolling our own.  At least
the failure modes are well documented. (glibc's implementation of rand() is
actually not bad).
2015-11-18 14:15:17 +00:00
Robert May 1bb4377c8c Combine loops and fix max returned value. 2015-11-18 12:08:34 +00:00
Michal Moskal 845bf4838c Fix allocation size for ImageData (the header is 6, not 4 bytes long) 2015-11-17 15:57:19 -08:00
Robert May 901faaeec7 reset variable m in the correct place. 2015-11-17 18:51:10 +00:00
Robert May 892689c54a Fix Microbit::random() to be random
The LFSR used only provides 1 bit of random data each time it is cycled.
This implementation generates the minimum number of bits needed.  Further
it discards numbers that are bigger than required and re-calculates -
this keeps the distribution flat.
2015-11-17 18:33:34 +00:00
Joe Finney b44095f0c5 BUGFIX: String comparison operations
Corrected response of < and > operations where substrings are compared.
2015-11-17 17:20:30 +00:00
Joe Finney 9b5fa0fcfc minor bugfixes in MICROBIT_HEAP_DEBUG 2015-11-17 16:58:42 +00:00
Robert May 51ea69201e Disconnect BLE before hard reset
If BLE is connected when performing a hard reset, attempt to disconnect
first to allow the remote peer to handle the disconnect gracefully
without haing to wait for a supervision timeout.
2015-11-17 13:12:27 +00:00
Joe Finney ac381fa5dc microbit: Alpha version of standard BLE MITM passkey security
- refactored BLE funcitonality into BLEManager class.
- added security requirements standard BLE profile services.
- updated bluezone pairing process to use BLE passkey exchange.
2015-11-16 13:44:27 +00:00
Joe Finney 79c739674c first compiling build. 2015-11-15 14:31:44 +00:00
Joe Finney 6dca3ed8d4 microbit: pre-compilation backup only. 2015-11-13 20:38:37 +00:00
Michal Moskal 56a560e5bc Merge branch 'master' into flatstring
Conflicts:
	.gitignore
	inc/ErrorNo.h
	source/MicroBitDisplay.cpp
	source/MicroBitImage.cpp
2015-11-12 16:13:45 -08:00
Joe Finney ea51f396ca Added compatibility for builds under ARMCC 2015-11-08 18:04:17 +00:00
Joe Finney 435debffed Merge branch 'quiet-gcc-build' of https://github.com/remay/microbit-dal into remay-quiet-gcc-build 2015-11-08 13:50:33 +00:00
Joe Finney 13456c60c1 microbit: Removal of explicit Serial instance for debugging.
Debugging now runs via the standrad MicroBit::serial interface.
2015-11-01 23:42:53 +00:00
Joe Finney 1a65e4e7bc microbit: Added support for soft reset button in panic mode
Also recalibrated loop timers in MicroBitDisplay::Error(), as used by panic()...
strange these now seem off by several orders of magnitude.

TODO: Ensure CPU is running at correct internal frequency with an oscilloscope test...
2015-11-01 21:33:46 +00:00
Robert May b8083908a7 Correct warnings supression in more obvious way
Whilst a little more invasive change than the previous warnings
supression this is more correct and more obvious as to what's being done,
and what warnigns will remain in place for the rest of the comilation
unit.
2015-11-01 20:19:18 +00:00
Robert May 9591ef40dc Turn off -Wunused-parameter for include "nrf_soc.h"
Unfortunately we can't turn it off just while nrf_soc.h is being included
as the way the defines are used the compiler can't tell the parameters
are unused until the end of the compilation unit.  So we can't use the
more normal

as that pops the supression too early.

WARNING: including nrf_soc.h will turn off unused-function warnings for
the rest of the compilation unit - see included nrf_svc.h
2015-11-01 20:19:17 +00:00
Robert May 1a1a5976a8 Silence GCC -Wall 2015-11-01 20:19:17 +00:00
Robert May 3a8c72144f up the cmake version required to 2.8.12, which is required for target_compile_options. 2015-11-01 20:19:17 +00:00
Robert May a39ba7d4f7 Turn off GCC warnings when building the dependancies 2015-11-01 20:19:17 +00:00
Robert May b2d3417559 Fix build when $git_branch fails to be set correctly. 2015-11-01 20:19:17 +00:00
Joe Finney 194f19a428 Merge branch 'simplified-eventing' 2015-11-01 18:22:27 +00:00
Joe Finney 1b6d6038c1 Merge branch 'master' into tight-validation 2015-11-01 16:28:08 +00:00
Joe Finney 77af825df0 Merge branch 'master' into simplified-eventing 2015-11-01 16:27:15 +00:00
Joe Finney 39abf824dc microbit: More efficient handling of events
Removed unnecessary queing of item on the MessageBus, whilst maintaining causal ordering.
2015-11-01 15:16:27 +00:00
Joe Finney b2e9369771 microbit: BUGFIX DoS attacks on the MessageBus
- Enures an event listener is not deleted whilst a fiber is activiely processing a queue
 - Added support for resurrection of event listeners in cases where identical listeners are removed/added repetitively.
2015-11-01 12:59:52 +00:00
Joe Finney 84da6a4a09 microbit: Minor bug fixes and refinements
- Add maximum depth for event queues, to prevent buggy scripts causing total memory exhaustion.
  - Suppress generation of A/B click events when A+B click is generated
  - preservation of event ordering on messagebus for resursive event generation cases.
  - bugfix of message bus processing to prevent occasional dual processing of events
  - bugfix MicroBitDisplay to behave correctly when delay parameter is zero.
2015-10-31 10:27:38 +00:00
Joe Finney 0fa8296048 microbit: BUGFIX safe deletion of listeners
also correction to minor bu in MicroBitFiber that could conceivably send more
notifications that it should...
2015-10-29 00:08:33 +00:00
Joe Finney 1eeaeca2c6 microbit: BUGFIX - correct initialization of MicroBitListener
code now correctly initiailizes the evt_queue filed needed to prevent
lockup during event processing (understandably!).
2015-10-28 14:17:12 +00:00
Michal Moskal 3900962556 Remove specific panic codes for ref-counting. 2015-10-27 08:28:06 -07:00
Michal Moskal 59853855b0 Remove caching of getSerial(); use temporary for BLE init 2015-10-27 08:26:07 -07:00
Michal Moskal 6437e714fa Delete when ref-count goes to 1, not 2\! 2015-10-27 08:19:56 -07:00
Michal Moskal c1050df0d9 Make the image width/height 16 bit wide 2015-10-27 08:02:42 -07:00
Joe Finney 7f64a4c703 microbit: BUGFIX Corrected incorrect handling of MicroBitMessageBus::add return values. 2015-10-26 16:37:12 +00:00
Joe Finney 823a956d68 microbit: First cut at updates to provide tight validation within the runtime code, with a view to moving
NOP/clamping behaviour out of teh micro:bit runtime and into the glue layers of higher level
languages.

 - Updates to many functions to provide explicut return codes.
 - Updates to many functions to remove heuristic calidation (NOP/clamping/defaults)
 - Updates to ErrorNo.h to provide clearer return values, and place return values in a better scope
 - Updates to MicroBitDisplay to use enums where appropriate.
2015-10-25 21:51:33 +00:00
Michal Moskal 7b82f3e8eb Improve comments; cleanup 2015-10-25 13:09:24 -07:00
Michal Moskal 98ffcc1fd1 Add status panic codes for ref-count errors 2015-10-25 12:59:45 -07:00
Michal Moskal 85b4e45863 Order-of-initialization fix. 2015-10-25 11:38:00 -07:00
Michal Moskal d0b75c96d1 Add MicroBitImage::isReadOnly,clone.
Add MicroBitImage,ManagedString::leakData().
Work more on incr()/decr() protocol.
2015-10-25 10:03:14 -07:00
Michal Moskal 11c99d0b84 Make the reference count always odd to make it possible to distinguish it from a vtable 2015-10-25 08:30:05 -07:00
Michal Moskal 5df59c2f7e Remove VirtualRefCounted class; non-virtual <-> virtual casts are not no-ops. 2015-10-24 21:52:51 -07:00
Michal Moskal 4f82a6c37c Use RefCounted also for MicroBitImage. 2015-10-24 20:58:03 -07:00
Michal Moskal 9330b401d5 Move RefCounted class to a separate file 2015-10-24 20:30:15 -07:00
Michal Moskal 5a10bda561 First stab at more memory efficient strings 2015-10-24 19:34:04 -07:00
Michal Moskal 057158c9f3 Cache getSerial(); otherwise BLE information device initalization may crash 2015-10-24 19:28:36 -07:00
Joe Finney bfe1b4db53 microbit: some work on tightening the API return codes.
still work in progress.
2015-10-21 11:35:59 +01:00
Joe Finney 613f524bab microbit: BUGFIX: micro:bit not entering BLUEZONE mode cleanly
Fixed bug in GAP advertisement configuration.
2015-10-19 14:42:13 +01:00
Joe Finney 72e5a9a6a6 microbit: BUGFIX - post merge fixes
- MicroBitDisplay::scroll() timing bug
  - MicroBitDisplay::print() timing bug
  - MicroBitFiber wait/notify bug
2015-10-18 19:09:54 +01:00
Joe Finney 424b825185 Merge branch 'master' into simplified-eventing
Conflicts:
	inc/MicroBitMessageBus.h
2015-10-18 18:20:03 +01:00
Joe Finney 80f79f7faf Merge branch 'master' into ble-profile
Conflicts:
	source/CMakeLists.txt
	source/MicroBit.cpp
	source/MicroBitFiber.cpp
	source/MicroBitMessageBus.cpp
	source/MicroBitSuperMain.cpp
2015-10-18 17:54:37 +01:00
Joe Finney db3eccf6ff microbit: Final updates to BLE profile
Minor changes to BLE profile services (cleanup prior to merge with master branch):

  - Added temperature period characteristic to match design pattern of other sensors.
  - Updated endinaness of MicroBitLEDService Matrix to be more intuitive.
  - Cleaned up Microbit.cpp by removing unused reference to BLE services.
  - Exposed serial number and naming information thr BLE DeviceInformation and API.
  - Updated BLE advertisement period to be alightly more repsonsive (200ms vs 1000ms).
  - BUGFIX: micro:bit name is now always generated, regardless of BLE services.
  - BUGFIX: Scroll Period data length.
2015-10-18 14:46:42 +01:00
Joe Finney aca544677e microbit: Updates to enable queing of display animation calls
Updates to change the behaviour of the scroll/print/animate faily of function away
from being pre-emtive and instead prroviding queing behaviour.

Minor updates to provide complete sets of async equivalent operations

Updates to the scheduler to provide wait/notify/waitone semantics.
2015-10-17 20:35:16 +01:00
Joe Finney 068822ff12 Merge branch 'matrix-point-optimisation' of https://github.com/dpgeorge/microbit-dal into dpgeorge-matrix-point-optimisation 2015-10-14 09:38:13 +01:00
Joe Finney 2011886e64 microbot: Cleanup of #ifdef in MicroBitHeapAllocator
Removed compiler warning if MICROBIT_HEAP_REUSE_SD is not defined.
2015-10-09 16:58:10 +01:00
Joe Finney 6764c732ea microbit: BUGFIX to MicroBtDFU Service
- Updates to UI handling to avoid starving out the processor.
  - Clears screen before entering DFU bootloader
2015-10-09 01:14:36 +01:00
Joe Finney 122d885ee8 microbit: Updated Bluetooth device name from MicroBit to micro:bit to match brand guidelines 2015-10-09 00:03:01 +01:00
Joe Finney ce2cc57bf1 microbit: Optimisation of internal Message Bus listeners
All message bus listeners with the micro:bit runtie are non blocking, and safe to be called
in an interrupt context. As such, these have now all been declared MESSAGE_BUS_LISTENER_IMMEDIATE
which should mitigate all unbounded event queueing effects.
2015-10-08 23:49:14 +01:00
Joe Finney 1d76def8fa microbit: BLE service bugfixes
Updates to BLE interface to match specification following testing by Bluetooth SIG.

Accelerometer Period: now supports READ and WRITE
Magnetometer Period: now supports READ and WRITE
LED Matrix State: now supports READ and WRITE.

UUIDs of Temperature Service characteristic corrected.
2015-10-08 23:23:00 +01:00
Joe Finney 85a26dc8e1 microbit: Updates to enable semantic versioning of the micro:bit runtime DAL
More specifically, the build system now uses the semantic versioning meta-data
held in module.json to define a major.minor.patch version. Additionally, is the branch
being compiled is *not* the master branch, the version is appended with <branchname><githash>.

Specific updates:

- Updates to CMake files to expose this to the micro:bit runtime code.
- Addition of uBit.systemVersion() to expose this to application code.
- Displaying of version string over serial if MICROBIT_DBG is enabled.
- Distribution of version string over BLE via the firmware revision characteristic.
2015-10-08 14:37:35 +01:00
Joe Finney 2230e39340 microbit: BUGFIX: #1291 ManagedString(INT_MIN) does not work properly
Corner case error in serialization code for INT_MIN only - corrected.
2015-09-29 23:51:20 +01:00
Joe Finney 18236810a3 microbit: BLE Profile Beta 1
First functionally complete BLE profile, matching BLE speicfication v1.6.
More specifically, the following services are now functional:

  - AccelerometerService
  - MeganetometerService
  - EventService
  - TemperatureServide
  - IOPinService
  - DFUService
  - ButtonService
  - LEDService

Also, updates to underlying device drivers to enable greater configurability:

  - MicroBitCompass now supports variable sample rates and temperature sensing
  - MicroBitAccelerometer now supports variable sample rates and ranges
  - MicroBitThermometer introduced
  - MicroBitMessageBus adapted to permit enumeration and block removal of listeners

Finally, MicroBit DFU Service has been changed to the new UUIDs specificed in v1.6 of BLE spec.
2015-09-28 21:40:44 +01:00
Damien George 0dcb6834ec microbit: Use default constructor for MatrixPoint so data is ROMable.
Previous to this patch an explicit constructor was provided for creating
MatrixPoint instances, which meant that such objects could not be put in
ROM (since they needed to be constructed at runtime).

By using the defualt construction method for structs the MatrixPoint map
is now compiled into the rodata section, hence freeing up RAM.

Saves: 4 bytes data, 56 bytes bss, 148 bytes code.
2015-09-25 21:19:10 +01:00
Joe Finney 4314b68643 microbit: First implementation of Temperature Service 2015-09-23 22:15:44 +01:00
Joe Finney eb5ed28f74 microbit: First cut at MicroBitButtonService and microBitIOPinService
Strictly still development - untested code.
2015-09-22 16:13:08 +01:00
Joe Finney ef613e9d86 microbit: Added BLE Magnetometer service compilation, initialization and configuration options 2015-09-19 22:19:57 +01:00
Joe Finney 3cfc7ec6e7 microbit: Ammendments to ensure fiber is never pages out due to eventing and minor cleanups
- renamed fiber flag to be more general.
- renamed idle to idleFiber to be consistent with the rest of the code.
- factored content of idle() into a funciton to avoid dupication.
- added test case to MessageBus::process() to avoid forking fibers if not requested.
- removed fiber_allow_run_idle_within mutator in favour of exposing currentFiber, as a more general solution.
2015-09-19 21:44:58 +01:00
Joe Finney 1e71169550 microbit: First draft of Magnetometer BLE service 2015-09-19 21:03:36 +01:00
Joe Finney ae0e5611c3 microbit: First draft of reconfigurable frequencies of MicroBitCompass 2015-09-19 21:00:38 +01:00
Damien George 9ccdd25e9f microbit: Allow to run the idle task within the current fiber's stack.
If there is only 1 main fiber (plus the idle fiber) then enabling this
new feature for the main fiber (using fiber_allow_run_idle_within())
will mean that no heap is needed to swap the stack out.
2015-09-19 11:45:45 +01:00
Joe Finney 2c9f63902c microbit: Message Bus updates to support URGENT events queue optimisations
Added new URGENT listener type, that ensures immediate, non queuing delivery of events.
Introduced two-pass algorithm into message bus. Only events with an event listener are now
queued at ingress - this reduces unecessary memory usage for 'uninteresting' events.
2015-09-18 23:20:44 +01:00
Joe Finney 058f73ede1 microbit: Moved MicroBitDFUService UUIDs to match BLE profile specification 2015-09-18 18:48:27 +01:00
Joe Finney ec30695d7d microbit: BUGFIX MicroBit::reset() now operates correctly 2015-09-17 23:32:40 +01:00
Jonathan Protzenko 78ad8a1646 Small tweak for the new ignore function. 2015-09-16 12:08:09 -07:00
Jonathan Protzenko 3158445208 New setAnalogPeriodUs function.
Fixes bbc/microbit-extras#1389.
2015-09-16 11:52:25 -07:00
Joe Finney a17830030e microbit: HOTFIX: BLE Notification bug in MicroBitDFUService
Hotfix of a minor bug in the MicroBitDFU Service that prevented BLE notifications
from being sent on the FlashCode characterisitic. Needed as the Samsung companion
app is dependent on this functionality to enable BLE programmming of the micro:bit.
2015-09-15 17:03:36 +01:00
Joe Finney 037ef999eb microbit: Merge branch 'master' into ble-profile
Pulled in changes from MessageBusExtensions to support development of ble profiles.
2015-09-15 15:17:21 +01:00
Joe Finney ccd351a4ed microbit: Added explicit notify() operation to MicroBitDFUService 2015-09-15 14:34:25 +01:00
Joe Finney 3395f66d3d microbit: Added configurable event processing options into MicroBitEvent
Events in the micro:bit runtime are normally launched through making an instance
of the MicroBitEvent class. This update added configuration support to all the
code creating the MicroBitEvent decide if the newly created event should then be
automatically queued on the MessageBus or processed immediately by event handlers.
2015-09-12 11:34:16 +01:00
Joe Finney a875d5fccd microbit: Added configurable concurrency modes for MicroBitMessageBus handlers.
MessageBus handlers can now have one of four concurrency modes for the eventuality
of an event being raised whilst a previous event is still being processed. An additional
(optional) parameter is provided to the listen() functions to allow this to be selected
on a per event handler basis. The permissable options are:

MESSAGE_BUS_LISTENER_REENTRANT:
The event handler is fired with the new event, regardless of whether or not
a previous event is still be processed by that handler.

MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY:
The new event is queued until such a time as the previous event has completed
execution. The new event is then processed. This option does not preclude the
processing of the new event by other event handlers.

MESSAGE_BUS_LISTENER_DROP_IF_BUSY:
The new event is dropped, and will never be processed the the event handler.
This option does not preclude the processing of the new event by other event handlers.

MESSAGE_BUS_LISTENER_NONBLOCKING:
The event handler is self-declaring that it never blocks. This flag is used purely
for optimisation, as it permits direct execution of the event hadnelr without inducing
any overhead from the scheduler.

In addition, the following minor revisions were made in this release:

* Cleanup of the #include dependencies contained in the microbit-dal .h files
* Bugfix to the scheduler block on event matching code.
* Introduced a MICROBIT_ID_ALERT MessageBus channel, for general purpose eventing using nonces.
2015-09-11 16:39:38 +01:00
Joe Finney 51493092ff microbit: Added support to remove MicroBitListener event handlers. 2015-09-10 12:53:39 +01:00
Joe Finney 8ea2e953c8 microbit: Added C++ member function callback support into MicroBitMessageBus
Event callbacks can now be transparently added to any C++ member function
matching the MicroBitMessageBud signature:  void fn(MicroBitEvent e)
2015-09-10 00:04:27 +01:00
Joe Finney 609cb6f2d8 microbit: Added first draft of BLE Accelerometer service
n.b. this code is as yet untested.
2015-09-09 15:16:11 +01:00
Joe Finney 9ccf0a7688 microbit: Added configuration support for accelerometer sample rate and range
MicroBitAccelerometer now contans methods to allow dynamic selection of sample range
(from +/-2g to +/-8g) and sample frequency (up to 800Hz). The default settings and behaviour
remain consistent.
2015-09-08 23:16:15 +01:00
Joe Finney 380b999440 microbit: BUGFIX: read callbacks on working
Changes to MicroBitLEDService class to ensure matrixCharacteristic remains
persistent. Needed to allow mbed read callbacks.
2015-09-08 13:55:15 +01:00
Joe Finney 7e18131849 microbit: Added MicroBitLEDService
One of the standard services defiend with the Bluetooth SIG. Allows remote control
of the LED matrix display over BLE.
2015-09-07 17:09:17 +01:00
Joe Finney 574b408cd1 microbit: Code Structure Cleanup
Create subdirectories for assembler code and BLE specific functionality
2015-09-07 10:26:48 +01:00
Joe Finney 8e1a15c79f microbit: Added support for custom configuration files through yotta
A header file containing custom configuration options for the microbit:runtime can
now be defined through a yotaa configuration option.

For example, including the following inside a top level config.json file
will load configuration options from a file called "MicroBitCustomConfig.h" that is stored
alongside an application's main.cpp. Any options defined there will override the defaults
defined in microbit-dal/inc/MicroBitConfig.h :

{
   "microbit" :{
      "configfile" : "source/MicroBitCustomConfig.h"
   }
}
2015-09-04 00:08:20 +01:00
Joe Finney f616011ac1 microbit: Integrate support for transparent gcc compiles
Custom CMakefile added to microbit-dal to automatically assemble the correct
version of CortexContextSwitch.s accordiong to the current build target.
2015-09-02 18:54:31 +01:00
Joe Finney cbaec38d06 Merge branch 'gcc' 2015-09-02 18:40:26 +01:00
Joe Finney 6470b71b1d microbit: Conditional compilation on MicroBitConfig
All options defined in MicroBitConfig are now set IFF they already do not have a value.
This allows external configuration of these options much more cleanly. Additional macros
also defined to provide clean implementation for boolean configuration switches.

Also some minor bugfixes:

  - Correction of typo of "Microbit.h" => "MicroBit.h"
  - Fixed heap corruption bug on gcc as a result of a debug printf in an unsafe context.
2015-09-02 12:42:24 +01:00
Joe Finney 857a626ed0 microbit: Memory Optimisation Mega Update
This release contains a widespread set of updates and optimisations to the micro:bit
runtime, with a view to reducing the SRAM footprint of the whole system. This is to
provide as much usable HEAP storage for application programs as possible.

Specific updates and optimisations include:

  - Additional compilation flags to allow the core micro:bit runtime to be configured.
    These are defined in MicroBitConfig.h

  - A custom heap allocator. This is now included for two reasons:

    1) To provide a simple mechanism to to utilise both the mbed heap space and other memory
       regions (such as unused memory in the SoftDevice region) as a single virtual heap.
    2) To address some issues that have been noted that are attributable to heap fragmentation.
       The micro:bit heap allocator has a simple algorithm, but one that is chosen to respond
       well to the relativelt high 'heap churn' found in the micro:bit environment.

    All micro:bit components and user programs now use this heap allocator trasparently.

  - Updates to BLE services to remove persistent references to their GATT services. This consumes
    vast amounts SRAM, rather unecessarily. Instead only handles to the relevant GATT characteristics
    are now stored. This specifically includes:
      + MicroBitDFUService
      + MicroBitEventService
      + DeviceInformationService

  - Updates to the Fiber scheduler to save SRAM. More specifically:
      + Removed the need to hold an empty processor context to intialise fibers.
      + The IDLE fiber now runs without a stack
      + fiber stacks are now only created when a fiber is descheduled for the first time, thereby reducing heap churn.
      + the 'main' fiber is now recycled into the fiber_pool if it leaves app_main()
      + fibers created through invoke() now only maintains the necessary part of teh parent stack that is needed, thereby
        reducing the stack size of spawned fibers.

  - Updates to the Message Bus to reduce the overall memory footprint of processing events. More specifically:
      + Event handlers are now always called using invoke(), such that non-blocking event handlers no longer need
        a dedicated fiber to execute - thereby saving SRAM and processor time.
      + Processing of events from the event queue is now rate paced. Events only continue to be processed as long as there
        are no fibers on the run queue. i.e. event processing is no longer greedy, thereby reducing the number of fibers
        created on the runqueue.

  - Updates to BLUEZOENE code to bring up core BLE services even if they are not enabled by default. This allows
    programs that do not require BLE to operate to benefit from the full range of SRAM, whilst still allowing the
    device to be programmed over BLE.

  - Updates to the Soft Device initialisation configuration, reducing the size of the GATT table held in the top 1.8K
    of its 8K memory region to around 800 bytes. This is sufficient to run the default set of BLE services on the micro:bit
    so the additional memory is configured as HEAP storage by MicroBitHeapAllocator.

  - Minor changes to a range of components to integrate with the above changes.
    + rename of free() to release() in DynamicPWM to avoid namespace collision with MicroBitHeap free()
    + rename of fork_on_block to invoke() to enhance readbility.

  - Many code cleanups and updates to out of date comments.
2015-08-31 23:25:10 +01:00
Jonathan Protzenko e258a52c79 My CMake skills are weak... properly implement the GCC/ARMCC switch for the S
file.
2015-08-24 10:55:22 -07:00
Jonathan Protzenko 8491b558e0 CMake tweak 2015-08-24 10:49:25 -07:00
Jonathan Protzenko 63b62e533f A version of microbit-dal that builds with both gcc and armcc.
Check in the CMakeLists.txt with a custom hook so that the library can build
with both compilers regardless.
2015-08-24 10:33:30 -07:00
Joe Finney 42f43b2255 Merge branch 'master' of https://github.com/lancaster-university/microbit-dal 2015-08-19 23:48:36 +01:00
Joe Finney 0fec4ae87c microbit: BUGFIX - Input validation in MicroBitDisplay::setBrightness()
Updates to MicroBitDisplay::setBrightness() to perform a NOP for out of bound parameters.
This aligns the functionality of the runtime with the TD simulator.
2015-08-19 23:36:17 +01:00
Joe Finney 58d24ab0a8 microbit: Updated MicroBitMessageBus to use fork_on_block functionality
Updates the MicroBitMessageBus implementation to use fork_on_block() calls rather
than create_fiber() calls when servicing events. This provides greater optimisation
for non-blocking event handlers.

More specifically, this update:

 - Replaces calls to create_fiber() ith fork_on_block during event send operations.
 - Adds a queue of events, to ensure events generated from interrupt context are not serviced in interrupt context.
 - Registers a listener with the idle process to empty the event queue.
2015-08-19 23:35:45 +01:00
Joe Finney f4b8a1a272 microbit: Added fork_on_block functionality to fiber scheduler
The microbit fiber scheduler is often used to service event handlers by the microbit message bus.
This provides a very elegant decoupling of user code from system code, interrupt handlers and
also allows users to make blocking calls within event handlers. However, many event handlers are
non-blocking, so launching a dedicated fiber is wasteful in terms of time and SRAM.

This patch adds fork_on_block() to the scheduler. Inspired by the UNIX copy_on_write
technique, this optimisation is semantically equivalent to a create_fiber() call, but will first attempt
to execute the given function in the context of the currently running fiber, and *only* create a fiber
if the given code attempts a blocking operation.

More specifically, this update:

 - adds fork_on_block() functions for parameterised and non-parameterised functions.
 - adds fields to the fiber context to record the status of parent/child fibers.
 - adds optimised ASM functions to store and restore Cortex M0 register context.
 - adds a utility function to determine if the processor is executing in interrupt context.
 - updates to sleep() and wait_for_event() to handle fork_on_block semantics.
 - minor code optimsations within the scheduler.
2015-08-19 23:27:26 +01:00
Jonathan Protzenko 753d6965f5 New gcc branch 2015-08-14 15:07:35 -07:00
James Devine 3ef5901c5b microbit-dal: added a reset mechanism to uBit
Users can now call uBit.reset() to reset the device.
2015-08-14 16:51:45 +01:00
James Devine d7b3ba9dab microbit-dal: Fixed a bug on printing a character with a delay
Previously when a blocking print finished, the animatemode was not
reset, which meant sometimes there would be a race condition.
2015-08-14 01:06:41 +01:00
James Devine f8ebfc69fb microbit-dal: added #define to determine BLE usage
NO_BLE can now be defined to determine whether ble
will be brought up or not at initialisation of uBit.
This is especially useful for two new Yotta targets:
bbc-microbit-classic-gcc-nosd,
bbc-microbit-classic-armcc-nosd, which do not use
softdevice.
2015-08-13 00:49:48 +01:00
James Devine 538e1c48bd microbit-dal: Initial Commit
This is the first commit of the microbit-dal on GitHub.
This repository contains the runtime, which is a light
weight operating system developed by Lancaster University.
2015-08-12 11:53:41 +01:00