From 85a26dc8e144910e1fd549ad4173c2d40accb40c Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Thu, 8 Oct 2015 14:37:35 +0100 Subject: [PATCH] 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 . 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. --- inc/MicroBit.h | 8 ++++++++ inc/MicroBitConfig.h | 10 ++++++++++ module.json | 4 ++-- source/CMakeLists.txt | 14 ++++++++++++++ source/MicroBit.cpp | 18 +++++++++++++++--- source/MicroBitSuperMain.cpp | 4 ++++ 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/inc/MicroBit.h b/inc/MicroBit.h index d7ad736..fd13fb0 100644 --- a/inc/MicroBit.h +++ b/inc/MicroBit.h @@ -225,6 +225,14 @@ class MicroBit */ unsigned long systemTime(); + /** + * Determine the version of the micro:bit runtime currently in use. + * + * @return A textual description of the currentlt executing micro:bit runtime. + * TODO: handle overflow case. + */ + char *systemVersion(); + /** * Triggers a microbit panic where an infinite loop will occur swapping between the panicFace and statusCode if provided. * diff --git a/inc/MicroBitConfig.h b/inc/MicroBitConfig.h index c2cdcdd..235b90e 100644 --- a/inc/MicroBitConfig.h +++ b/inc/MicroBitConfig.h @@ -243,6 +243,16 @@ #define MICROBIT_HEAP_DBG 0 #endif +// Versioning options. +// We use semantic versioning (http://semver.org/) to identify differnet versions of the micro:bit runtime. +// Where possible we use yotta (an ARM mbed build tool) to help us track versions. +// if this isn't available, it can be defined manually as a configuration option. +// +#ifndef MICROBIT_DAL_VERSION +#define MICROBIT_DAL_VERSION "unknown" +#endif + + // // Helper macro used by the micro:bit runtime to determine if a boolean configuration option is set. // diff --git a/module.json b/module.json index 2f59f22..9d3f5fe 100644 --- a/module.json +++ b/module.json @@ -1,10 +1,10 @@ { "name": "microbit-dal", - "version": "0.0.1", + "version": "1.2.1", "license": "Apache2", "description": "The runtime library for the BBC micro:bit, developed by Lancaster University", "keywords": ["mbed-classic", "microbit", "runtime", "library", "lancaster", "University"], - "author": "James Devine ", + "author": "Joe Finney ", "homepage": "https://developer.mbed.org/teams/Lancaster-University/code/microbit/", "dependencies":{ "mbed-classic": "~0.0.4", diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index abb249c..94a5e2d 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -32,10 +32,24 @@ set(YOTTA_AUTO_MICROBIT-DAL_CPP_FILES "MemberFunctionCallback.cpp" ) +execute_process(WORKING_DIRECTORY "../../yotta_modules/${PROJECT_NAME}" COMMAND "git" "log" "--pretty=format:%h" "-n" "1" OUTPUT_VARIABLE git_hash) +execute_process(WORKING_DIRECTORY "../../yotta_modules/${PROJECT_NAME}" COMMAND "git" "rev-parse" "--abbrev-ref" "HEAD" OUTPUT_VARIABLE git_branch OUTPUT_STRIP_TRAILING_WHITESPACE) + +if (${git_branch} STREQUAL "master") + set(MICROBIT_DAL_VERSION_STRING "${YOTTA_MICROBIT_DAL_VERSION_STRING}") +else() + set(MICROBIT_DAL_VERSION_STRING "${YOTTA_MICROBIT_DAL_VERSION_STRING}-${git_branch}-g${git_hash}") +endif() + +set(MICROBIT_DAL_VERSION_FLAGS "-DMICROBIT_DAL_VERSION=\\\"${MICROBIT_DAL_VERSION_STRING}\\\"") + +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MICROBIT_DAL_VERSION_FLAGS}") + if (YOTTA_CFG_MICROBIT_CONFIGFILE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${YOTTA_FORCE_INCLUDE_FLAG} \"${YOTTA_CFG_MICROBIT_CONFIGFILE}\"") endif () + if(CMAKE_COMPILER_IS_GNUCC) file(REMOVE "CortexContextSwitch.s") configure_file("CortexContextSwitch.s.gcc" "CortexContextSwitch.s" COPYONLY) diff --git a/source/MicroBit.cpp b/source/MicroBit.cpp index 8868374..a38b0e7 100644 --- a/source/MicroBit.cpp +++ b/source/MicroBit.cpp @@ -4,10 +4,10 @@ char MICROBIT_BLE_DEVICE_NAME[] = "BBC MicroBit [xxxxx]"; #if CONFIG_ENABLED(MICROBIT_BLE_ENABLED) && CONFIG_ENABLED(MICROBIT_BLE_DEVICE_INFORMATION_SERVICE) const char MICROBIT_BLE_MANUFACTURER[] = "The Cast of W1A"; -const char MICROBIT_BLE_MODEL[] = "Microbit SB2"; +const char MICROBIT_BLE_MODEL[] = "micro:bit"; const char MICROBIT_BLE_SERIAL[] = "SN1"; const char MICROBIT_BLE_HARDWARE_VERSION[] = "0.2"; -const char MICROBIT_BLE_FIRMWARE_VERSION[] = "1.1"; +const char MICROBIT_BLE_FIRMWARE_VERSION[] = MICROBIT_DAL_VERSION; const char MICROBIT_BLE_SOFTWARE_VERSION[] = "1.0"; #endif @@ -340,7 +340,7 @@ void MicroBit::removeIdleComponent(MicroBitComponent *component) { int i = 0; - while(idleThreadComponents[i] != component && i < MICROBIT_IDLE_COMPONENTS) + while(idleThreadComponents[i] != component && i < MICROBIT_IDLE_COMPONENTS) i++; if(i == MICROBIT_IDLE_COMPONENTS) @@ -360,6 +360,18 @@ unsigned long MicroBit::systemTime() return ticks; } + +/** + * Determine the version of the micro:bit runtime currently in use. + * + * @return A textual description of the currentlt executing micro:bit runtime. + * TODO: handle overflow case. + */ +char *MicroBit::systemVersion() +{ + return MICROBIT_DAL_VERSION; +} + /** * Triggers a microbit panic where an infinite loop will occur swapping between the panicFace and statusCode if provided. * diff --git a/source/MicroBitSuperMain.cpp b/source/MicroBitSuperMain.cpp index 3bbae4c..47fd4a8 100644 --- a/source/MicroBitSuperMain.cpp +++ b/source/MicroBitSuperMain.cpp @@ -16,12 +16,16 @@ int main() #if CONFIG_ENABLED(MICROBIT_DBG) pc.baud(115200); + // For diagnostics. Gives time to open the console window. :-) for (int i=3; i>0; i--) { pc.printf("=== SUPERMAIN: Starting in %d ===\n", i); wait(1.0); } + + pc.printf("micro:bit runtime DAL version %s\n", MICROBIT_DAL_VERSION); + #endif // Bring up our nested heap allocator.