Commit Graph

122 Commits

Author SHA1 Message Date
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 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 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 8bf318e2b4 By-adress comparison operators for ManagedType. 2015-08-24 16:12:18 -07:00
Jonathan Protzenko aabd954d67 Also define a non-operator version of () for style purposes. 2015-08-24 11:17:38 -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 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 c4656ca855 Add a missing operator to ManagedType. 2015-08-18 17:49:08 -07:00
Jonathan Protzenko 6e65c33e88 Expose PinName for PWM purposes. 2015-08-14 15:51:16 -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 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