diff --git a/README.md b/README.md index 73349c5..938c038 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,7 @@ Test sensor libraries : ```terminal mbed test -m DISCO_H747I -t GCC_ARM -n advdembsof_library-tests-sensors-hdc1000 --compile --run ``` + +# Some questions +## If you print CPU statistics at the end of every major cycle (in the super-loop), what CPU usage do you observe? How can you explain the observed CPU uptime? +We observe a 100% usage because on each CPU cycle it compare if time is done. \ No newline at end of file diff --git a/mbed_app.json b/mbed_app.json index 2f706a5..c42f542 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -14,6 +14,7 @@ "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 diff --git a/static_scheduling/bike_system.cpp b/static_scheduling/bike_system.cpp index b62ec22..8bdb6ea 100644 --- a/static_scheduling/bike_system.cpp +++ b/static_scheduling/bike_system.cpp @@ -54,13 +54,13 @@ static constexpr std::chrono::milliseconds kDisplayTask2Period = 1600ms; static constexpr std::chrono::milliseconds kDisplayTask2Delay = 1200ms; static constexpr std::chrono::milliseconds kDisplayTask2ComputationTime = 100ms; -// TODO: implement the constructor BikeSystem::BikeSystem() : _gearDevice(_timer), _pedalDevice(_timer), _resetDevice(_timer), - _speedometer(_timer) + _speedometer(_timer), + _cpuLogger(_timer) { } @@ -70,14 +70,10 @@ void BikeSystem::start() { init(); - // TODO: implement the super-loop based for implementing the appropriate schedule - // Done while (true) { auto startTime = _timer.elapsed_time(); - // TODO: implement calls to different tasks based on computed schedule - // Done - gearTask(); // 100ms : 0ms -> 100ms + gearTask(); // 100ms : 0ms -> 100ms speedDistanceTask(); // 200ms : 100ms -> 300ms displayTask1(); // 200ms : 300ms -> 500ms speedDistanceTask(); // 200ms : 500ms -> 700ms @@ -106,6 +102,10 @@ void BikeSystem::start() { break; } + #if !defined(MBED_TEST_MODE) + _cpuLogger.printStats(); + #endif + } } @@ -144,7 +144,8 @@ void BikeSystem::gearTask() { _currentGearSize = _gearDevice.getCurrentGearSize(); _taskLogger.logPeriodAndExecutionTime( - _timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime); + _timer, advembsof::TaskLogger::kGearTaskIndex, taskStartTime + ); } void BikeSystem::speedDistanceTask() { @@ -159,7 +160,8 @@ void BikeSystem::speedDistanceTask() { _traveledDistance = _speedometer.getDistance(); _taskLogger.logPeriodAndExecutionTime( - _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime); + _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime + ); } void BikeSystem::temperatureTask() { diff --git a/static_scheduling/bike_system.hpp b/static_scheduling/bike_system.hpp index 445ccad..8a1ccc6 100644 --- a/static_scheduling/bike_system.hpp +++ b/static_scheduling/bike_system.hpp @@ -27,6 +27,7 @@ // from advembsof #include "display_device.hpp" #include "task_logger.hpp" +#include "cpu_logger.hpp" // from common #include "sensor_device.hpp" @@ -93,6 +94,9 @@ class BikeSystem { // used for logging task info advembsof::TaskLogger _taskLogger; + + // cpu logger to measure cpu usage + advembsof::CPULogger _cpuLogger; }; } // namespace static_scheduling \ No newline at end of file