Skip to content

Commit

Permalink
pxt 6.x updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Juri committed Sep 11, 2020
1 parent 8de341a commit dcd61f4
Show file tree
Hide file tree
Showing 26 changed files with 798 additions and 213 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
build
.yotta.json
.vscode
yotta_modules
yotta_targets
*.swp
*~
Makefile
.idea
*.iml
.vscode
6 changes: 0 additions & 6 deletions .yotta.json

This file was deleted.

91 changes: 42 additions & 49 deletions inc/core/MicroBitComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,54 +36,47 @@ und Björn Eberhardt GbR by arrangement with Calliope GbR.
// Enumeration of core components.
#define MICROBIT_ID_BUTTON_A 1
#define MICROBIT_ID_BUTTON_B 2
#define MICROBIT_ID_BUTTON_RESET 3
#define MICROBIT_ID_ACCELEROMETER 4
#define MICROBIT_ID_COMPASS 5
#define MICROBIT_ID_DISPLAY 6

//EDGE connector events
#ifdef TARGET_NRF51_CALLIOPE
#define MICROBIT_IO_PINS 21
#else
#define MICROBIT_IO_PINS 20
#endif

#define MICROBIT_ID_IO_P0 7 //P0 is the left most pad (ANALOG/DIGITAL) (CM: P1)
#define MICROBIT_ID_IO_P1 8 //P1 is the middle pad (ANALOG/DIGITAL) (CM: P2)
#define MICROBIT_ID_IO_P2 9 //P2 is the right most pad (ANALOG/DIGITAL) (CM: analog/tx)
#define MICROBIT_ID_IO_P3 10 //COL1 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P4 11 //BTN_A
#define MICROBIT_ID_IO_P5 12 //COL2 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P6 13 //ROW2
#define MICROBIT_ID_IO_P7 14 //ROW1
#define MICROBIT_ID_IO_P8 15 //PIN 18 (CM: analog/tx)
#define MICROBIT_ID_IO_P9 16 //ROW3
#define MICROBIT_ID_IO_P10 17 //COL3 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P11 18 //BTN_B
#define MICROBIT_ID_IO_P12 19 //PIN 20 (CM: P0)
#define MICROBIT_ID_IO_P13 20 //SCK
#define MICROBIT_ID_IO_P14 21 //MISO
#define MICROBIT_ID_IO_P15 22 //MOSI
#define MICROBIT_ID_IO_P16 23 //PIN 16 (CM: P3)
#define MICROBIT_ID_IO_P19 24 //SCL
#define MICROBIT_ID_IO_P20 25 //SDA
#define MICROBIT_ID_BUTTON_AB 3 // Button A+B multibutton
#define MICROBIT_ID_BUTTON_RESET 4
#define MICROBIT_ID_ACCELEROMETER 5
#define MICROBIT_ID_COMPASS 6
#define MICROBIT_ID_DISPLAY 7
#define MICROBIT_ID_THERMOMETER 8
#define MICROBIT_ID_RADIO 9
#define MICROBIT_ID_RADIO_DATA_READY 10
#define MICROBIT_ID_MULTIBUTTON_ATTACH 11
#define MICROBIT_ID_SERIAL 12
#define MICROBIT_ID_GESTURE 13 // Gesture events

#define MICROBIT_ID_IO_P0 100 //P0 is the left most pad (ANALOG/DIGITAL) (CM: P1)
#define MICROBIT_ID_IO_P1 101 //P1 is the middle pad (ANALOG/DIGITAL) (CM: P2)
#define MICROBIT_ID_IO_P2 102 //P2 is the right most pad (ANALOG/DIGITAL) (CM: analog/tx)
#define MICROBIT_ID_IO_P3 103 //COL1 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P4 104 //BTN_A
#define MICROBIT_ID_IO_P5 105 //COL2 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P6 106 //ROW2
#define MICROBIT_ID_IO_P7 107 //ROW1
#define MICROBIT_ID_IO_P8 108 //PIN 18 (CM: analog/tx)
#define MICROBIT_ID_IO_P9 109 //ROW3
#define MICROBIT_ID_IO_P10 110 //COL3 (ANALOG/DIGITAL)
#define MICROBIT_ID_IO_P11 111 //BTN_B
#define MICROBIT_ID_IO_P12 112 //PIN 20 (CM: P0)
#define MICROBIT_ID_IO_P13 113 //SCK
#define MICROBIT_ID_IO_P14 114 //MISO
#define MICROBIT_ID_IO_P15 115 //MOSI
#define MICROBIT_ID_IO_P16 116 //PIN 16 (CM: P3)
#define MICROBIT_ID_IO_P19 119 //SCL
#define MICROBIT_ID_IO_P20 120 //SDA
#ifdef TARGET_NRF51_CALLIOPE
#define MICROBIT_ID_IO_P21 50 // CM: analog microphone
#define MICROBIT_ID_IO_P21 121 // CM: analog microphone
#endif

#define MICROBIT_ID_BUTTON_AB 26 // Button A+B multibutton
#define MICROBIT_ID_GESTURE 27 // Gesture events

#define MICROBIT_ID_THERMOMETER 28
#define MICROBIT_ID_RADIO 29
#define MICROBIT_ID_RADIO_DATA_READY 30
#define MICROBIT_ID_MULTIBUTTON_ATTACH 31
#define MICROBIT_ID_SERIAL 32
#define MICROBIT_ID_IO_INT1 130 //INT1
#define MICROBIT_ID_IO_INT2 131 //INT2
#define MICROBIT_ID_IO_INT3 132 //INT3

#define MICROBIT_ID_IO_INT1 33 //INT1
#define MICROBIT_ID_IO_INT2 34 //INT2
#define MICROBIT_ID_IO_INT3 35 //INT3
#define MICROBIT_ID_PARTIAL_FLASHING 36
// System Softwarre components
#define MICROBIT_ID_PARTIAL_FLASHING 200

#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 All @@ -98,17 +91,17 @@ und Björn Eberhardt GbR by arrangement with Calliope GbR.
*
* All components should inherit from this class.
*
* If a component requires regular updates, then that component can be added to the
* If a component requires regular updates, then that component can be added to the
* to the systemTick and/or idleTick queues. This provides a simple, extensible mechanism
* for code that requires periodic/occasional background processing but does not warrant
* the complexity of maintaining its own thread.
* the complexity of maintaining its own thread.
*
* Two levels of support are available.
* Two levels of support are available.
*
* systemTick() provides a periodic callback during the
* micro:bit's system timer interrupt. This provides a guaranteed periodic callback, but in interrupt context
* and is suitable for code with lightweight processing requirements, but strict time constraints.
*
*
* idleTick() provides a periodic callback whenever the scheduler is idle. This provides occasional, callbacks
* in the main thread context, but with no guarantees of frequency. This is suitable for non-urgent background tasks.
*
Expand Down Expand Up @@ -145,7 +138,7 @@ class MicroBitComponent

/**
* The idle thread will call this member function once the component has been added to the array
* of idle components using fiber_add_idle_component.
* of idle components using fiber_add_idle_component.
*/
virtual void idleTick()
{
Expand Down
33 changes: 30 additions & 3 deletions inc/core/MicroBitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ DEALINGS IN THE SOFTWARE.

// Defines where in memory persistent data is stored.
#ifndef KEY_VALUE_STORE_PAGE
#define KEY_VALUE_STORE_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 17))
#define KEY_VALUE_STORE_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 17))
#endif

#ifndef BLE_BOND_DATA_PAGE
#ifndef BLE_BOND_DATA_PAGE
#define BLE_BOND_DATA_PAGE (PAGE_SIZE * (NRF_FICR->CODESIZE - 18))
#endif

Expand Down Expand Up @@ -154,6 +154,18 @@ extern uint32_t __etext;
#define MICROBIT_FIBER_USER_DATA 0
#endif

// Indicate get_fiber_list() API is supported
#ifndef MICROBIT_GET_FIBER_LIST_SUPPORTED
#define MICROBIT_GET_FIBER_LIST_SUPPORTED 1
#endif

// Maximum size of the FiberPool
// Defines the size that the pool of unused Fiber contexts is permitted to grow to. After this point, memory
// from unused Fiber contexts will be restored to the Heap Allocator.
#ifndef MICROBIT_FIBER_MAXIMUM_FIBER_POOL_SIZE
#define MICROBIT_FIBER_MAXIMUM_FIBER_POOL_SIZE 3
#endif

//
// Message Bus:
// Default behaviour for event handlers, if not specified in the listen() call
Expand All @@ -176,6 +188,21 @@ extern uint32_t __etext;
#define MESSAGE_BUS_LISTENER_MAX_QUEUE_DEPTH 10
#endif

//
// Define MESSAGE_BUS concurrency behaviour.
// Set to MESSAGE_BUS_CONCURRENT_LISTENERS to fire event handler
// concurrently when a given event is raised, and process events sequentially as they arrive (default micro:bit semantics).
// Set to MESSAGE_BUS_CONCURRENT_EVENTS to to fire event handlers sequentially for any given event, while still allowing
// concurrent processing of events.
//
//
// Permissable values are:
// 0: MESSAGE_BUS_CONCURRENT_LISTENERS
// 1: MESSAGE_BUS_CONCURRENT_EVENTS
//
#ifndef MESSAGE_BUS_CONCURRENCY_MODE
#define MESSAGE_BUS_CONCURRENCY_MODE MESSAGE_BUS_CONCURRENT_LISTENERS
#endif
//
// Core micro:bit services
//
Expand Down Expand Up @@ -436,7 +463,7 @@ extern uint32_t __etext;
// Should be <= MBFS_BLOCK_SIZE.
//
#ifndef MBFS_CACHE_SIZE
#define MBFS_CACHE_SIZE 0
#define MBFS_CACHE_SIZE 0
#endif

//
Expand Down
19 changes: 17 additions & 2 deletions inc/core/MicroBitFiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ DEALINGS IN THE SOFTWARE.
#define MICROBIT_FIBER_FLAG_CHILD 0x04
#define MICROBIT_FIBER_FLAG_DO_NOT_PAGE 0x08

#if CONFIG_ENABLED(MICROBIT_FIBER_USER_DATA)
#define HAS_THREAD_USER_DATA (currentFiber->user_data != NULL)
#else
#define HAS_THREAD_USER_DATA false
#endif

/**
* Thread Context for an ARM Cortex M0 core.
*
Expand Down Expand Up @@ -88,9 +94,11 @@ struct Fiber
uint32_t context; // Context specific information.
uint32_t flags; // Information about this fiber.
Fiber **queue; // The queue this fiber is stored on.
Fiber *next, *prev; // Position of this Fiber on the run queue.
Fiber *qnext; // Position of this Fiber on its queue.
Fiber *next; // Position of this Fiber in the global list of fibers.

#if CONFIG_ENABLED(MICROBIT_FIBER_USER_DATA)
void *user_data;
void *user_data; // Optional pointer to user defined data block.
#endif
};

Expand All @@ -114,6 +122,13 @@ void scheduler_init(EventModel &_messageBus);
*/
int fiber_scheduler_running();

/**
* Provides a list of all active fibers.
*
* @return A pointer to the head of the list of all active fibers.
*/
Fiber* get_fiber_list();

/**
* Exit point for all fibers.
*
Expand Down
4 changes: 2 additions & 2 deletions inc/core/MicroBitListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ DEALINGS IN THE SOFTWARE.

#include "mbed.h"
#include "MicroBitConfig.h"
#include "MicroBitLock.h"
#include "MicroBitEvent.h"
#include "MemberFunctionCallback.h"
#include "MicroBitConfig.h"

// MicroBitListener flags...
#define MESSAGE_BUS_LISTENER_PARAMETERISED 0x0001
Expand Down Expand Up @@ -67,7 +67,7 @@ struct MicroBitListener

MicroBitEvent evt;
MicroBitEventQueueItem *evt_queue;

MicroBitLock lock;
MicroBitListener *next;

/**
Expand Down
66 changes: 66 additions & 0 deletions inc/core/MicroBitLock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
The MIT License (MIT)
Copyright (c) 2016 British Broadcasting Corporation.
This software is provided by Lancaster University by arrangement with the BBC.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

/**
* A simple lock, mostly used for mutual exclusion.
*/

#ifndef MICROBIT_LOCK_H
#define MICROBIT_LOCK_H

#include "MicroBitConfig.h"

class Fiber;

class MicroBitLock
{
private:
bool locked;
Fiber *queue;

public:

/**
* Create a new lock that can be used for mutual exclusion and condition synchronisation.
*/
MicroBitLock();

/**
* Block the calling fiber until the lock is available
**/
void wait();

/**
* Release the lock, and signal to one waiting fiber to continue
*/
void notify();

/**
* Release the lock, and signal to all waiting fibers to continue
*/
void notifyAll();
};

#endif
Loading

0 comments on commit dcd61f4

Please sign in to comment.