Default Operation
This page describes the default operation of the Movesense sensor firmware. However most of the functionality can be controlled by the Movesense API (either from firmware or over the BLE connection). Many of the details are also hardware dependent and the operation may be different in the future in different Movesense sensor hardware.
Boot-up
When the Movesense sensor is powered on, the following happens:
Bootloader
-
The bootloader checks the firmware image in the internal flash memory and compares it to the checksums in "bootloader settings" page. If the firmware does not match, the bootloader goes to the DFU mode. If the firmware is valid, the firmware application is started.
-
The DFU mode advertises as "DfuTarg" and waits for the BLE connection for 120 seconds. If the connection does not happen, the sensor resets.
Application bootup
In the beginning of the application start, the hardware is initialized and LED lit. If there is a contact in the HR-studs, the firmware waits to see if the "DFU recovery mode" sequence happens (contact for three seconds, start blinking the led and disconnect studs during one second). If it does, set sensor to DFU mode via reset.
After DFU mode detection is over, the rest of the Movesense framework is initialized, BLE enabled and threads created. After all that the "whiteboard::LaunchableModule"s are created as follows:
- Mandatory Modules are initialized (Acc, ECG, System etc.)
- Optional Modules are initialized (BleService, DataLogger, Logbook) based on OPTIONAL_CORE_MODULE -macros in App.cpp
-
Application specified modules are initialized based on MOVESENSE_PROVIDER_DEF -macros in App.cpp
-
Mandatory Modules are started
- Optional Modules are started
- Application specified modules are started
Default BLE operation
After the sensor is running, it stays by default in as low power consumption as possible. The BLE Advertising is enabled so that the BLE connection can be made to the sensor.
The advertising after bootup is sequenced to: - First 60s the sensor advertises with 100 ms interval ("Fast advertising") - After that the interval is changed to 500 ms to save energy
If connection is made to sensor, the advertising is disabled. After BLE disconnect the sequence is:
- First 1000ms the sensor does directed advertising to the sensor it was connected to with 100 ms interval.
- Next 60s the sensor advertises with 100 ms interval ("Fast advertising")
- After that the interval is changed to 500 ms to save energy
Default advertising packet content
The default advertising and scan packet contents in the current firmware are:
Advertise packet
- Flags section (Flags: 6)
- Services 16bit:
- whiteboard UUID
- (optional HRS id if optional HRS module is loaded)
Scan Response packet
- Complete Local Name
- "
"
NOTE: If the name in the Scan Response packet is changed by the firmware, you must set the new name also to the BLE stack so that it reflects in the "Device Name" -characteristics of the "Generic Access" -service. Otherwise the Mobile phone can show the old name when the connection is made.
UTC Time
The Movesense sensor keeps track of the UTC time set via the PUT /Time -API. Since the current sensor does not have a separate hardware RTC chip, the UTC time is lost when the device goes in to FullPowerOff system mode. Almost same power savings can be achieved by unsubscribing all sensor data and disabling BLE advertising (Low power IDLE mode) which will keep the device UTC time.
If a sensor experiences a software reset (error condition or commanded reset), the UTC time stays set but there is about +- 500ms loss of accuracy (if the sensor goes thru the full DFU recovery detection the time loss can be bigger).
Error cases and RESET
When the sensor experiences an error condition (HW fault, ASSERT or BLE stack error), the reset reason is written to RAM that is not initialized in next reset. This "Reset reason" string can be read with the following code after the bootup:
char buf[40];
if (faultcom_GetLastFaultStr(false, buf, sizeof(buf))) {
// Deal with error here
}
The format of the fault strings are:
ResetTypes can get following values:
- "HW": Hardware fault, such as accessing invalid address. The details are encoded in a tight format which is written out in RTT logs on bootup.
- "A": ASSERT. Includes filename and line
- "K": Kernel ASSERT
- "S": Stack corruption
- "W": Watch dog. Sensor firmware was stuck for over 30 seconds, infinite loops etc.
- "N": BLE stack error
It is a good idea to read these reset reasons and log them, so that the sensor failure cases can be followed in the field. You can either embed the information in your own service or use the /System/ResetReason API in DebugService.
Common Framework ASSERTs
The following list contains the typical framework ASSERTs and the reasons for them (Line numbers are from release 2.1):
- kernel.c:194 Memory allocation failed
- Request.cpp:33 Whiteboard request was not handled
- Request.cpp:49 Trying to copy handled request
- Request.cpp:52 Copying over unhandled request
- Array.h:94 index out of bounds
- Optional.h:46 & 53 Trying to get Optional that has no Value set
- ResourceProvider.cpp:190 returnResult with unknown datatype
- EventQueue.cpp:54 Queue overflow
- Whiteboard.cpp:528 Provider has not unregistered it's resources
- Whiteboard.cpp:568 registerProviderResources called from wrong thread
- Whiteboard.cpp:860 notification dispatch failed. Probably full queues
- StartupProvider.cpp:153 LaunchableModule with that name exists already