Compare commits
No commits in common. "fdab57142a5cfc8b71008462e39aed05660b3bef" and "618ddaaa1b19e1aa19e45e3ee5fe6010c71d8b6d" have entirely different histories.
fdab57142a
...
618ddaaa1b
@ -14,5 +14,4 @@ mbed-os/features/FEATURE_BOOTLOADER/*
|
|||||||
mbed-os/features/frameworks/mbed-client-cli/*
|
mbed-os/features/frameworks/mbed-client-cli/*
|
||||||
mbed-os/features/frameworks/COMPONENT_FPGA_CI_TEST_SHIELD/*
|
mbed-os/features/frameworks/COMPONENT_FPGA_CI_TEST_SHIELD/*
|
||||||
mbed-os/platform/randlib/*
|
mbed-os/platform/randlib/*
|
||||||
mbed-os/storage/kvstore/*
|
mbed-os/storage/kvstore/*
|
||||||
mbed-os-bootloader/*
|
|
@ -22,5 +22,5 @@ repos:
|
|||||||
- id: cppcheck
|
- id: cppcheck
|
||||||
name: cppcheck
|
name: cppcheck
|
||||||
require_serial: true
|
require_serial: true
|
||||||
entry: cppcheck --enable=all --suppress=missingInclude --suppress=missingIncludeSystem --inline-suppr -i mbed-os --std=c++14 --error-exitcode=1
|
entry: cppcheck --enable=all --suppress=missingInclude --suppress=missingIncludeSystem --suppress=unusedFunction --inline-suppr -i mbed-os --std=c++14 --error-exitcode=1
|
||||||
language: system
|
language: system
|
||||||
|
@ -261,8 +261,8 @@ static void test_reset_multi_tasking_bike_system() {
|
|||||||
TEST_ASSERT_TRUE(responseTime.count() <= kMaxExpectedResponseTime.count());
|
TEST_ASSERT_TRUE(responseTime.count() <= kMaxExpectedResponseTime.count());
|
||||||
|
|
||||||
// jitter of 20us is accepted
|
// jitter of 20us is accepted
|
||||||
constexpr uint64_t kDeltaUs = 4;
|
constexpr uint64_t kDeltaUs = 3;
|
||||||
constexpr std::chrono::microseconds kMaxExpectedJitter(3);
|
constexpr std::chrono::microseconds kMaxExpectedJitter(2);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
auto jitter = responseTime - lastResponseTime;
|
auto jitter = responseTime - lastResponseTime;
|
||||||
tr_info("Reset task: jitter is %lld usecs\n", std::abs(jitter.count()));
|
tr_info("Reset task: jitter is %lld usecs\n", std::abs(jitter.count()));
|
||||||
|
@ -36,7 +36,7 @@ static constexpr uint8_t kMaxGear = 9;
|
|||||||
// smallest gear (= 1) corresponds to a gear size of 20
|
// smallest gear (= 1) corresponds to a gear size of 20
|
||||||
// when the gear increases, the gear size descreases
|
// when the gear increases, the gear size descreases
|
||||||
static constexpr uint8_t kMaxGearSize = 20;
|
static constexpr uint8_t kMaxGearSize = 20;
|
||||||
static constexpr uint8_t kMinGearSize = kMaxGearSize - kMaxGear;
|
static constexpr uint8_t kMinGearSize = kMaxGearSize - kMinGear;
|
||||||
|
|
||||||
// pedal related constants
|
// pedal related constants
|
||||||
// When compiling and linking with gcc, we get a link error when using static
|
// When compiling and linking with gcc, we get a link error when using static
|
||||||
|
@ -25,9 +25,10 @@
|
|||||||
#include "speedometer.hpp"
|
#include "speedometer.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstddef>
|
|
||||||
#include <ratio>
|
#include <ratio>
|
||||||
|
|
||||||
|
#include "static_scheduling/gear_device.hpp"
|
||||||
|
|
||||||
// from disco_h747i/wrappers
|
// from disco_h747i/wrappers
|
||||||
#include "joystick.hpp"
|
#include "joystick.hpp"
|
||||||
#include "mbed_trace.h"
|
#include "mbed_trace.h"
|
||||||
@ -80,9 +81,7 @@ float Speedometer::getDistance() {
|
|||||||
|
|
||||||
void Speedometer::reset() {
|
void Speedometer::reset() {
|
||||||
#if defined(MBED_TEST_MODE)
|
#if defined(MBED_TEST_MODE)
|
||||||
if (_cbOnReset != NULL) {
|
_cbOnReset();
|
||||||
_cbOnReset();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->_totalDistanceMutex.lock();
|
this->_totalDistanceMutex.lock();
|
||||||
|
@ -55,7 +55,7 @@ class Speedometer {
|
|||||||
float getTraySize() const;
|
float getTraySize() const;
|
||||||
std::chrono::milliseconds getCurrentPedalRotationTime() const;
|
std::chrono::milliseconds getCurrentPedalRotationTime() const;
|
||||||
void setOnResetCallback(mbed::Callback<void()> cb);
|
void setOnResetCallback(mbed::Callback<void()> cb);
|
||||||
mbed::Callback<void()> _cbOnReset = NULL;
|
mbed::Callback<void()> _cbOnReset;
|
||||||
#endif // defined(MBED_TEST_MODE)
|
#endif // defined(MBED_TEST_MODE)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -80,7 +80,7 @@ class Speedometer {
|
|||||||
float _currentSpeed = 0.0f;
|
float _currentSpeed = 0.0f;
|
||||||
Mutex _totalDistanceMutex;
|
Mutex _totalDistanceMutex;
|
||||||
float _totalDistance = 0.0f;
|
float _totalDistance = 0.0f;
|
||||||
uint8_t _gearSize = bike_computer::kMaxGearSize;
|
uint8_t _gearSize = bike_computer::kMinGearSize;
|
||||||
|
|
||||||
#if defined(MBED_TEST_MODE)
|
#if defined(MBED_TEST_MODE)
|
||||||
mbed::Callback<void()> _cb;
|
mbed::Callback<void()> _cb;
|
||||||
|
14
main.cpp
14
main.cpp
@ -7,9 +7,8 @@
|
|||||||
|
|
||||||
#include "mbed.h" // NOLINT
|
#include "mbed.h" // NOLINT
|
||||||
#include "mbed_trace.h" // NOLINT
|
#include "mbed_trace.h" // NOLINT
|
||||||
// #include "static_scheduling/bike_system.hpp"
|
// #include "static_scheduling_with_event/bike_system.hpp"
|
||||||
#include "static_scheduling_with_event/bike_system.hpp"
|
#include "multi_tasking/bike_system.hpp"
|
||||||
// #include "multi_tasking/bike_system.hpp"
|
|
||||||
|
|
||||||
#if defined(MBED_CONF_MBED_TRACE_ENABLE)
|
#if defined(MBED_CONF_MBED_TRACE_ENABLE)
|
||||||
#define TRACE_GROUP "MAIN"
|
#define TRACE_GROUP "MAIN"
|
||||||
@ -22,12 +21,11 @@ int main() {
|
|||||||
|
|
||||||
// static_scheduling::BikeSystem bikeSystem;
|
// static_scheduling::BikeSystem bikeSystem;
|
||||||
// bikeSystem.start();
|
// bikeSystem.start();
|
||||||
|
// static_scheduling_with_event::BikeSystem bikeSystem;
|
||||||
static_scheduling_with_event::BikeSystem bikeSystem;
|
|
||||||
bikeSystem.start();
|
|
||||||
|
|
||||||
// multi_tasking::BikeSystem bikeSystem;
|
|
||||||
// bikeSystem.start();
|
// bikeSystem.start();
|
||||||
|
|
||||||
|
multi_tasking::BikeSystem bikeSystem;
|
||||||
|
bikeSystem.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MBED_TEST_MODE
|
#endif // MBED_TEST_MODE
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
BasedOnStyle: Google
|
|
||||||
IndentWidth: 4
|
|
||||||
---
|
|
||||||
Language: Cpp
|
|
||||||
ColumnLimit: 90
|
|
||||||
AlignConsecutiveAssignments: true
|
|
||||||
DerivePointerAlignment: false
|
|
||||||
PointerAlignment: Left
|
|
||||||
BinPackArguments: false
|
|
||||||
BinPackParameters: false
|
|
||||||
IndentAccessModifiers: false
|
|
8
mbed-os-bootloader/.gitignore
vendored
8
mbed-os-bootloader/.gitignore
vendored
@ -1,8 +0,0 @@
|
|||||||
.build
|
|
||||||
.mbed
|
|
||||||
projectfiles
|
|
||||||
*.py*
|
|
||||||
mbed-os
|
|
||||||
BUILD
|
|
||||||
!BUILD/DISCO_H747I/GCC_ARM/mbed-os-bootloader.bin
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
|||||||
mbed-os/drivers/device_key/*
|
|
||||||
mbed-os/drivers/source/usb/USBMSD.cpp
|
|
||||||
mbed-os/drivers/source/SFDP.cpp
|
|
||||||
mbed-os/connectivity/cellular/*
|
|
||||||
mbed-os/connectivity/drivers/*
|
|
||||||
mbed-os/connectivity/FEATURE_BLE/*
|
|
||||||
mbed-os/connectivity/libraries/*
|
|
||||||
mbed-os/connectivity/lorawan/*
|
|
||||||
mbed-os/connectivity/lwipstack/*
|
|
||||||
mbed-os/connectivity/nanostack/*
|
|
||||||
mbed-os/connectivity/netsocket/*
|
|
||||||
mbed-os/connectivity/nfc/*
|
|
||||||
mbed-os/features/FEATURE_BOOTLOADER/*
|
|
||||||
mbed-os/features/frameworks/mbed-client-cli/*
|
|
||||||
mbed-os/features/frameworks/COMPONENT_FPGA_CI_TEST_SHIELD/*
|
|
||||||
mbed-os/platform/randlib/*
|
|
||||||
mbed-os/storage/kvstore/*
|
|
@ -1,26 +0,0 @@
|
|||||||
files: ^main.cpp
|
|
||||||
repos:
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v4.3.0
|
|
||||||
hooks:
|
|
||||||
- id: check-yaml
|
|
||||||
args: [--allow-multiple-documents]
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: trailing-whitespace
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
|
||||||
rev: "v14.0.6"
|
|
||||||
hooks:
|
|
||||||
- id: clang-format
|
|
||||||
- repo: https://github.com/cpplint/cpplint
|
|
||||||
rev: "1.6.1"
|
|
||||||
hooks:
|
|
||||||
- id: cpplint
|
|
||||||
name: cpplint
|
|
||||||
entry: cpplint --linelength=90 --filter=-build/include_subdir,-whitespace/indent,-build/namespaces,-build/c++11
|
|
||||||
- repo: local
|
|
||||||
hooks:
|
|
||||||
- id: cppcheck
|
|
||||||
name: cppcheck
|
|
||||||
require_serial: true
|
|
||||||
entry: cppcheck --enable=all --suppress=missingInclude --inline-suppr -i mbed-os --std=c++14 --error-exitcode=1
|
|
||||||
language: system
|
|
Binary file not shown.
@ -1,35 +0,0 @@
|
|||||||
#include "mbed.h"
|
|
||||||
|
|
||||||
#include "mbed_trace.h"
|
|
||||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
|
||||||
#define TRACE_GROUP "bootloader"
|
|
||||||
#endif // MBED_CONF_MBED_TRACE_ENABLE
|
|
||||||
|
|
||||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
|
||||||
static UnbufferedSerial g_uart(CONSOLE_TX, CONSOLE_RX);
|
|
||||||
|
|
||||||
// Function that directly outputs to an unbuffered serial port in blocking mode.
|
|
||||||
static void boot_debug(const char *s) {
|
|
||||||
size_t len = strlen(s);
|
|
||||||
g_uart.write(s, len);
|
|
||||||
g_uart.write("\r\n", 2);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
#if MBED_CONF_MBED_TRACE_ENABLE
|
|
||||||
mbed_trace_init();
|
|
||||||
mbed_trace_print_function_set(boot_debug);
|
|
||||||
#endif // MBED_CONF_MBED_TRACE_ENABLE
|
|
||||||
|
|
||||||
tr_debug("BikeComputer bootloader\r\n");
|
|
||||||
|
|
||||||
// at this stage we directly branch to the main application
|
|
||||||
void *sp = *((void **) POST_APPLICATION_ADDR + 0); // NOLINT(readability/casting)
|
|
||||||
void *pc = *((void **) POST_APPLICATION_ADDR + 1); // NOLINT(readability/casting)
|
|
||||||
tr_debug("Starting application at address 0x%08x (sp 0x%08x, pc 0x%08x)\r\n", POST_APPLICATION_ADDR, (uint32_t) sp, (uint32_t) pc);
|
|
||||||
|
|
||||||
mbed_start_application(POST_APPLICATION_ADDR);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
https://github.com/ARMmbed/mbed-os.git#17dc3dc2e6e2817a8bd3df62f38583319f0e4fed
|
|
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"macros": [
|
|
||||||
"MBED_CONF_MBED_TRACE_FEA_IPV6=0"
|
|
||||||
],
|
|
||||||
"config": {
|
|
||||||
"main-stack-size": {
|
|
||||||
"value": 4096
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"target_overrides": {
|
|
||||||
"*": {
|
|
||||||
"mbed-trace.enable": false,
|
|
||||||
"platform.stdio-convert-newlines": true,
|
|
||||||
"platform.stdio-baud-rate": 115200,
|
|
||||||
"platform.default-serial-baud-rate": 115200,
|
|
||||||
"platform.stdio-buffered-serial": true,
|
|
||||||
"platform.all-stats-enabled": true,
|
|
||||||
"target.printf_lib":"minimal-printf",
|
|
||||||
"platform.minimal-printf-enable-floating-point": true,
|
|
||||||
"platform.minimal-printf-set-floating-point-max-decimals": 2
|
|
||||||
},
|
|
||||||
"DISCO_H747I": {
|
|
||||||
"target.restrict_size": "0x20000",
|
|
||||||
"mbed-trace.enable": true,
|
|
||||||
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
"macros": ["MBED_CONF_MBED_TRACE_FEA_IPV6=0"],
|
"macros": ["MBED_CONF_MBED_TRACE_FEA_IPV6=0"],
|
||||||
"config": {
|
"config": {
|
||||||
"main-stack-size": {
|
"main-stack-size": {
|
||||||
"value": 8192
|
"value": 6144
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
@ -19,9 +19,7 @@
|
|||||||
},
|
},
|
||||||
"DISCO_H747I": {
|
"DISCO_H747I": {
|
||||||
"mbed-trace.enable": true,
|
"mbed-trace.enable": true,
|
||||||
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
|
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG"
|
||||||
"target.bootloader_img": "./mbed-os-bootloader/BUILD/DISCO_H747I/GCC_ARM/mbed-os-bootloader.bin",
|
|
||||||
"target.app_offset": "0x20000"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,16 +39,27 @@
|
|||||||
|
|
||||||
namespace multi_tasking {
|
namespace multi_tasking {
|
||||||
|
|
||||||
static constexpr std::chrono::milliseconds kGearTaskComputationTime = 100ms;
|
static constexpr std::chrono::milliseconds kGearTaskPeriod = 800ms;
|
||||||
|
static constexpr std::chrono::milliseconds kGearTaskDelay = 0ms;
|
||||||
|
static constexpr std::chrono::milliseconds kGearTaskComputationTime = 100ms;
|
||||||
|
static constexpr std::chrono::milliseconds kSpeedDistanceTaskPeriod = 400ms;
|
||||||
|
static constexpr std::chrono::milliseconds kSpeedDistanceTaskDelay = 0ms; // 0 or 100ms
|
||||||
static constexpr std::chrono::milliseconds kSpeedDistanceTaskComputationTime = 200ms;
|
static constexpr std::chrono::milliseconds kSpeedDistanceTaskComputationTime = 200ms;
|
||||||
static constexpr std::chrono::milliseconds kDisplayTask1Period = 1600ms;
|
static constexpr std::chrono::milliseconds kDisplayTask1Period = 1600ms;
|
||||||
static constexpr std::chrono::milliseconds kDisplayTask1Delay = 300ms;
|
static constexpr std::chrono::milliseconds kDisplayTask1Delay = 300ms;
|
||||||
static constexpr std::chrono::milliseconds kDisplayTask1ComputationTime = 200ms;
|
static constexpr std::chrono::milliseconds kDisplayTask1ComputationTime = 200ms;
|
||||||
|
static constexpr std::chrono::milliseconds kResetTaskPeriod = 800ms;
|
||||||
|
static constexpr std::chrono::milliseconds kResetTaskDelay = 700ms;
|
||||||
|
static constexpr std::chrono::milliseconds kResetTaskComputationTime = 100ms;
|
||||||
static constexpr std::chrono::milliseconds kTemperatureTaskPeriod = 1600ms;
|
static constexpr std::chrono::milliseconds kTemperatureTaskPeriod = 1600ms;
|
||||||
static constexpr std::chrono::milliseconds kTemperatureTaskDelay = 1100ms;
|
static constexpr std::chrono::milliseconds kTemperatureTaskDelay = 1100ms;
|
||||||
static constexpr std::chrono::milliseconds kTemperatureTaskComputationTime = 100ms;
|
static constexpr std::chrono::milliseconds kTemperatureTaskComputationTime = 100ms;
|
||||||
|
static constexpr std::chrono::milliseconds kDisplayTask2Period = 1600ms;
|
||||||
|
static constexpr std::chrono::milliseconds kDisplayTask2Delay = 1200ms;
|
||||||
|
static constexpr std::chrono::milliseconds kDisplayTask2ComputationTime = 100ms;
|
||||||
static constexpr std::chrono::milliseconds kCPUTaskPeriod = 1600ms;
|
static constexpr std::chrono::milliseconds kCPUTaskPeriod = 1600ms;
|
||||||
static constexpr std::chrono::milliseconds kCPUTaskDelay = 0ms;
|
static constexpr std::chrono::milliseconds kCPUTaskDelay = 0ms;
|
||||||
|
static constexpr std::chrono::milliseconds kCPUTaskComputationTime = 0ms;
|
||||||
|
|
||||||
BikeSystem::BikeSystem()
|
BikeSystem::BikeSystem()
|
||||||
: _timer(),
|
: _timer(),
|
||||||
|
@ -138,7 +138,7 @@ class BikeSystem {
|
|||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// shared resources between the main thread and the isr thread
|
// shared resources between the main thread and the isr thread
|
||||||
uint8_t _currentGear = bike_computer::kMinGear;
|
uint8_t _currentGear = bike_computer::kMinGear;
|
||||||
uint8_t _currentGearSize = bike_computer::kMaxGearSize;
|
uint8_t _currentGearSize = bike_computer::kMinGearSize;
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// data member that represents the device for manipulating the pedal rotation
|
// data member that represents the device for manipulating the pedal rotation
|
||||||
|
@ -61,10 +61,7 @@ BikeSystem::BikeSystem()
|
|||||||
: _gearDevice(_timer),
|
: _gearDevice(_timer),
|
||||||
_pedalDevice(_timer),
|
_pedalDevice(_timer),
|
||||||
_resetDevice(_timer),
|
_resetDevice(_timer),
|
||||||
_displayDevice(),
|
|
||||||
_speedometer(_timer),
|
_speedometer(_timer),
|
||||||
_sensorDevice(),
|
|
||||||
_taskLogger(),
|
|
||||||
_cpuLogger(_timer) {}
|
_cpuLogger(_timer) {}
|
||||||
|
|
||||||
void BikeSystem::start() {
|
void BikeSystem::start() {
|
||||||
@ -208,18 +205,29 @@ void BikeSystem::speedDistanceTask() {
|
|||||||
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
|
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::displayTask1() {
|
void BikeSystem::temperatureTask() {
|
||||||
auto taskStartTime = _timer.elapsed_time();
|
auto taskStartTime = _timer.elapsed_time();
|
||||||
|
|
||||||
_displayDevice.displayGear(_currentGear);
|
tr_warn("Tick1 %" PRIu64, _timer.elapsed_time().count());
|
||||||
_displayDevice.displaySpeed(_currentSpeed);
|
|
||||||
_displayDevice.displayDistance(_traveledDistance);
|
// no need to protect access to data members (single threaded)
|
||||||
|
_currentTemperature = _sensorDevice.readTemperature();
|
||||||
|
|
||||||
|
tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
|
||||||
|
|
||||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||||
|
|
||||||
|
// simulate task computation by waiting for the required task computation time
|
||||||
|
|
||||||
|
// std::chrono::microseconds elapsedTime =
|
||||||
|
// std::chrono::microseconds::zero(); while (elapsedTime <
|
||||||
|
// kTemperatureTaskComputationTime) {
|
||||||
|
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||||
|
// }
|
||||||
|
|
||||||
_taskLogger.logPeriodAndExecutionTime(
|
_taskLogger.logPeriodAndExecutionTime(
|
||||||
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
|
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::resetTask() {
|
void BikeSystem::resetTask() {
|
||||||
@ -235,17 +243,27 @@ void BikeSystem::resetTask() {
|
|||||||
_taskLogger.logPeriodAndExecutionTime(
|
_taskLogger.logPeriodAndExecutionTime(
|
||||||
_timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime);
|
_timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime);
|
||||||
}
|
}
|
||||||
void BikeSystem::temperatureTask() {
|
|
||||||
|
void BikeSystem::displayTask1() {
|
||||||
auto taskStartTime = _timer.elapsed_time();
|
auto taskStartTime = _timer.elapsed_time();
|
||||||
|
|
||||||
// no need to protect access to data members (single threaded)
|
_displayDevice.displayGear(_currentGear);
|
||||||
_currentTemperature = _sensorDevice.readTemperature();
|
_displayDevice.displaySpeed(_currentSpeed);
|
||||||
|
_displayDevice.displayDistance(_traveledDistance);
|
||||||
|
|
||||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||||
|
|
||||||
|
// simulate task computation by waiting for the required task computation time
|
||||||
|
|
||||||
|
// std::chrono::microseconds elapsedTime =
|
||||||
|
// std::chrono::microseconds::zero(); while (elapsedTime <
|
||||||
|
// kDisplayTask1ComputationTime) {
|
||||||
|
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||||
|
// }
|
||||||
|
|
||||||
_taskLogger.logPeriodAndExecutionTime(
|
_taskLogger.logPeriodAndExecutionTime(
|
||||||
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
|
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::displayTask2() {
|
void BikeSystem::displayTask2() {
|
||||||
@ -256,6 +274,13 @@ void BikeSystem::displayTask2() {
|
|||||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
kDisplayTask2ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||||
|
|
||||||
|
// simulate task computation by waiting for the required task computation time
|
||||||
|
|
||||||
|
// std::chrono::microseconds elapsedTime =
|
||||||
|
// std::chrono::microseconds::zero(); while (elapsedTime <
|
||||||
|
// kDisplayTask2ComputationTime) {
|
||||||
|
// elapsedTime = _timer.elapsed_time() - taskStartTime;
|
||||||
|
// }
|
||||||
_taskLogger.logPeriodAndExecutionTime(
|
_taskLogger.logPeriodAndExecutionTime(
|
||||||
_timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime);
|
_timer, advembsof::TaskLogger::kDisplayTask2Index, taskStartTime);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ class BikeSystem {
|
|||||||
// data member that represents the device for manipulating the gear
|
// data member that represents the device for manipulating the gear
|
||||||
GearDevice _gearDevice;
|
GearDevice _gearDevice;
|
||||||
uint8_t _currentGear = bike_computer::kMinGear;
|
uint8_t _currentGear = bike_computer::kMinGear;
|
||||||
uint8_t _currentGearSize = bike_computer::kMaxGearSize;
|
uint8_t _currentGearSize = bike_computer::kMinGearSize;
|
||||||
// data member that represents the device for manipulating the pedal rotation
|
// data member that represents the device for manipulating the pedal rotation
|
||||||
// speed/time
|
// speed/time
|
||||||
PedalDevice _pedalDevice;
|
PedalDevice _pedalDevice;
|
||||||
|
@ -37,7 +37,7 @@ namespace static_scheduling {
|
|||||||
|
|
||||||
static constexpr std::chrono::microseconds kTaskRunTime = 200000us;
|
static constexpr std::chrono::microseconds kTaskRunTime = 200000us;
|
||||||
|
|
||||||
PedalDevice::PedalDevice(Timer& timer) : _timer(timer), _pedalRotationTime(0) {}
|
PedalDevice::PedalDevice(Timer& timer) : _timer(timer) {}
|
||||||
|
|
||||||
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
|
std::chrono::milliseconds PedalDevice::getCurrentRotationTime() {
|
||||||
std::chrono::microseconds initialTime = _timer.elapsed_time();
|
std::chrono::microseconds initialTime = _timer.elapsed_time();
|
||||||
|
@ -46,9 +46,9 @@ class PedalDevice {
|
|||||||
void decreaseRotationSpeed();
|
void decreaseRotationSpeed();
|
||||||
|
|
||||||
// data members
|
// data members
|
||||||
Timer& _timer;
|
|
||||||
std::chrono::milliseconds _pedalRotationTime =
|
std::chrono::milliseconds _pedalRotationTime =
|
||||||
bike_computer::kInitialPedalRotationTime;
|
bike_computer::kInitialPedalRotationTime;
|
||||||
|
Timer& _timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace static_scheduling
|
} // namespace static_scheduling
|
||||||
|
@ -43,8 +43,7 @@ namespace static_scheduling {
|
|||||||
|
|
||||||
static constexpr std::chrono::microseconds kTaskRunTime = 100000us;
|
static constexpr std::chrono::microseconds kTaskRunTime = 100000us;
|
||||||
|
|
||||||
ResetDevice::ResetDevice(Timer& timer)
|
ResetDevice::ResetDevice(Timer& timer) : _timer(timer), _resetButton(PUSH_BUTTON) {
|
||||||
: _resetButton(PUSH_BUTTON), _timer(timer), _pressTime(0) {
|
|
||||||
_resetButton.rise(callback(this, &ResetDevice::onRise));
|
_resetButton.rise(callback(this, &ResetDevice::onRise));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +67,7 @@ BikeSystem::BikeSystem()
|
|||||||
: _gearDevice(),
|
: _gearDevice(),
|
||||||
_pedalDevice(),
|
_pedalDevice(),
|
||||||
_resetDevice(callback(this, &BikeSystem::onReset)),
|
_resetDevice(callback(this, &BikeSystem::onReset)),
|
||||||
_displayDevice(),
|
|
||||||
_speedometer(_timer),
|
_speedometer(_timer),
|
||||||
_sensorDevice(),
|
|
||||||
_taskLogger(),
|
|
||||||
_cpuLogger(_timer) {}
|
_cpuLogger(_timer) {}
|
||||||
|
|
||||||
void BikeSystem::start() {
|
void BikeSystem::start() {
|
||||||
@ -179,18 +176,21 @@ void BikeSystem::speedDistanceTask() {
|
|||||||
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
|
_timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::displayTask1() {
|
void BikeSystem::temperatureTask() {
|
||||||
auto taskStartTime = _timer.elapsed_time();
|
auto taskStartTime = _timer.elapsed_time();
|
||||||
|
|
||||||
_displayDevice.displayGear(_currentGear);
|
// tr_warn("Tick1 %" PRIu64, _timer.elapsed_time().count());
|
||||||
_displayDevice.displaySpeed(_currentSpeed);
|
|
||||||
_displayDevice.displayDistance(_traveledDistance);
|
// no need to protect access to data members (single threaded)
|
||||||
|
_currentTemperature = _sensorDevice.readTemperature();
|
||||||
|
|
||||||
|
// tr_warn("Tick2 %" PRIu64, _timer.elapsed_time().count());
|
||||||
|
|
||||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||||
|
|
||||||
_taskLogger.logPeriodAndExecutionTime(
|
_taskLogger.logPeriodAndExecutionTime(
|
||||||
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
|
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::resetTask() {
|
void BikeSystem::resetTask() {
|
||||||
@ -208,17 +208,18 @@ void BikeSystem::resetTask() {
|
|||||||
_timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime);
|
_timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::temperatureTask() {
|
void BikeSystem::displayTask1() {
|
||||||
auto taskStartTime = _timer.elapsed_time();
|
auto taskStartTime = _timer.elapsed_time();
|
||||||
|
|
||||||
// no need to protect access to data members (single threaded)
|
_displayDevice.displayGear(_currentGear);
|
||||||
_currentTemperature = _sensorDevice.readTemperature();
|
_displayDevice.displaySpeed(_currentSpeed);
|
||||||
|
_displayDevice.displayDistance(_traveledDistance);
|
||||||
|
|
||||||
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
ThisThread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
kTemperatureTaskComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
kDisplayTask1ComputationTime - (_timer.elapsed_time() - taskStartTime)));
|
||||||
|
|
||||||
_taskLogger.logPeriodAndExecutionTime(
|
_taskLogger.logPeriodAndExecutionTime(
|
||||||
_timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime);
|
_timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BikeSystem::displayTask2() {
|
void BikeSystem::displayTask2() {
|
||||||
|
@ -85,7 +85,7 @@ class BikeSystem {
|
|||||||
// data member that represents the device for manipulating the gear
|
// data member that represents the device for manipulating the gear
|
||||||
GearDevice _gearDevice;
|
GearDevice _gearDevice;
|
||||||
uint8_t _currentGear = bike_computer::kMinGear;
|
uint8_t _currentGear = bike_computer::kMinGear;
|
||||||
uint8_t _currentGearSize = bike_computer::kMaxGearSize;
|
uint8_t _currentGearSize = bike_computer::kMinGearSize;
|
||||||
// data member that represents the device for manipulating the pedal rotation
|
// data member that represents the device for manipulating the pedal rotation
|
||||||
// speed/time
|
// speed/time
|
||||||
PedalDevice _pedalDevice;
|
PedalDevice _pedalDevice;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user