Compare commits
	
		
			26 Commits
		
	
	
		
			618ddaaa1b
			...
			develop
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | fdab57142a | ||
|  | 787fa94e91 | ||
|  | e460a4f695 | ||
|  | a183ad4858 | ||
|  | dfd94b647c | ||
|  | d0ff3defa1 | ||
|  | 7d228d67cc | ||
|  | 7838ed0448 | ||
|  | 6d42dd2ba1 | ||
|  | 0ec735adde | ||
| aed65401f5 | |||
| 686eff6269 | |||
| 0d61cd598c | |||
| 980eb2b376 | |||
| 5a85e1da8d | |||
| 9eb4f64b73 | |||
| 544df31a1b | |||
|  | 31e1f22c59 | ||
|  | c0335b38a4 | ||
|  | f8077db299 | ||
|  | 367c7178c0 | ||
|  | 394f4febff | ||
|  | a887c91775 | ||
|  | d176856326 | ||
| 98f3a32a68 | |||
| 171c43b653 | 
| @@ -15,3 +15,4 @@ 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 --suppress=unusedFunction --inline-suppr -i mbed-os --std=c++14 --error-exitcode=1 |         entry: cppcheck --enable=all --suppress=missingInclude --suppress=missingIncludeSystem --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 = 3; |         constexpr uint64_t kDeltaUs = 4; | ||||||
|         constexpr std::chrono::microseconds kMaxExpectedJitter(2); |         constexpr std::chrono::microseconds kMaxExpectedJitter(3); | ||||||
|         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 - kMinGear; | static constexpr uint8_t kMinGearSize = kMaxGearSize - kMaxGear; | ||||||
|  |  | ||||||
| // 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,10 +25,9 @@ | |||||||
| #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" | ||||||
| @@ -81,7 +80,9 @@ 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; |     mbed::Callback<void()> _cbOnReset = NULL; | ||||||
| #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::kMinGearSize; |     uint8_t _gearSize    = bike_computer::kMaxGearSize; | ||||||
|  |  | ||||||
| #if defined(MBED_TEST_MODE) | #if defined(MBED_TEST_MODE) | ||||||
|     mbed::Callback<void()> _cb; |     mbed::Callback<void()> _cb; | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								main.cpp
									
									
									
									
									
								
							| @@ -7,8 +7,9 @@ | |||||||
|  |  | ||||||
| #include "mbed.h"        // NOLINT | #include "mbed.h"        // NOLINT | ||||||
| #include "mbed_trace.h"  // NOLINT | #include "mbed_trace.h"  // NOLINT | ||||||
| // #include "static_scheduling_with_event/bike_system.hpp" | // #include "static_scheduling/bike_system.hpp" | ||||||
| #include "multi_tasking/bike_system.hpp" | #include "static_scheduling_with_event/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" | ||||||
| @@ -21,11 +22,12 @@ int main() { | |||||||
|  |  | ||||||
|     // static_scheduling::BikeSystem bikeSystem; |     // static_scheduling::BikeSystem bikeSystem; | ||||||
|     // bikeSystem.start(); |     // bikeSystem.start(); | ||||||
|     // static_scheduling_with_event::BikeSystem bikeSystem; |  | ||||||
|     // bikeSystem.start(); |  | ||||||
|  |  | ||||||
|     multi_tasking::BikeSystem bikeSystem; |     static_scheduling_with_event::BikeSystem bikeSystem; | ||||||
|     bikeSystem.start(); |     bikeSystem.start(); | ||||||
|  |  | ||||||
|  |     // multi_tasking::BikeSystem bikeSystem; | ||||||
|  |     // bikeSystem.start(); | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif  // MBED_TEST_MODE | #endif  // MBED_TEST_MODE | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								mbed-os-bootloader/.clang-format
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								mbed-os-bootloader/.clang-format
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | --- | ||||||
|  | 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
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								mbed-os-bootloader/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | .build | ||||||
|  | .mbed | ||||||
|  | projectfiles | ||||||
|  | *.py* | ||||||
|  | mbed-os | ||||||
|  | BUILD | ||||||
|  | !BUILD/DISCO_H747I/GCC_ARM/mbed-os-bootloader.bin | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								mbed-os-bootloader/.mbedignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								mbed-os-bootloader/.mbedignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | 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/* | ||||||
							
								
								
									
										26
									
								
								mbed-os-bootloader/.pre-commit-config.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								mbed-os-bootloader/.pre-commit-config.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | 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.
										
									
								
							
							
								
								
									
										35
									
								
								mbed-os-bootloader/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								mbed-os-bootloader/main.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | #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
									
								
								mbed-os-bootloader/mbed-os.lib
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								mbed-os-bootloader/mbed-os.lib
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | https://github.com/ARMmbed/mbed-os.git#17dc3dc2e6e2817a8bd3df62f38583319f0e4fed | ||||||
							
								
								
									
										28
									
								
								mbed-os-bootloader/mbed_app.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								mbed-os-bootloader/mbed_app.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | { | ||||||
|  |     "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": 6144 |       "value": 8192 | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   "target_overrides": { |   "target_overrides": { | ||||||
| @@ -19,7 +19,9 @@ | |||||||
|     }, |     }, | ||||||
|     "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,27 +39,16 @@ | |||||||
|  |  | ||||||
| namespace multi_tasking { | namespace multi_tasking { | ||||||
|  |  | ||||||
| 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 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::kMinGearSize; |     uint8_t _currentGearSize = bike_computer::kMaxGearSize; | ||||||
|     ////////////////////////////////////////////////////////////// |     ////////////////////////////////////////////////////////////// | ||||||
|  |  | ||||||
|     // data member that represents the device for manipulating the pedal rotation |     // data member that represents the device for manipulating the pedal rotation | ||||||
|   | |||||||
| @@ -61,7 +61,10 @@ 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() { | ||||||
| @@ -205,29 +208,18 @@ void BikeSystem::speedDistanceTask() { | |||||||
|         _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime); |         _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::temperatureTask() { | void BikeSystem::displayTask1() { | ||||||
|     auto taskStartTime = _timer.elapsed_time(); |     auto taskStartTime = _timer.elapsed_time(); | ||||||
|  |  | ||||||
|     tr_warn("Tick1 %" PRIu64, _timer.elapsed_time().count()); |     _displayDevice.displayGear(_currentGear); | ||||||
|  |     _displayDevice.displaySpeed(_currentSpeed); | ||||||
|     // no need to protect access to data members (single threaded) |     _displayDevice.displayDistance(_traveledDistance); | ||||||
|     _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>( | ||||||
|         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 < |  | ||||||
|     //    kTemperatureTaskComputationTime) { |  | ||||||
|     //        elapsedTime = _timer.elapsed_time() - taskStartTime; |  | ||||||
|     //    } |  | ||||||
|  |  | ||||||
|     _taskLogger.logPeriodAndExecutionTime( |     _taskLogger.logPeriodAndExecutionTime( | ||||||
|         _timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime); |         _timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::resetTask() { | void BikeSystem::resetTask() { | ||||||
| @@ -243,27 +235,17 @@ 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(); | ||||||
|  |  | ||||||
|     _displayDevice.displayGear(_currentGear); |     // no need to protect access to data members (single threaded) | ||||||
|     _displayDevice.displaySpeed(_currentSpeed); |     _currentTemperature = _sensorDevice.readTemperature(); | ||||||
|     _displayDevice.displayDistance(_traveledDistance); |  | ||||||
|  |  | ||||||
|     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 < |  | ||||||
|     //    kDisplayTask1ComputationTime) { |  | ||||||
|     //        elapsedTime = _timer.elapsed_time() - taskStartTime; |  | ||||||
|     //    } |  | ||||||
|  |  | ||||||
|     _taskLogger.logPeriodAndExecutionTime( |     _taskLogger.logPeriodAndExecutionTime( | ||||||
|         _timer, advembsof::TaskLogger::kDisplayTask1Index, taskStartTime); |         _timer, advembsof::TaskLogger::kTemperatureTaskIndex, taskStartTime); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::displayTask2() { | void BikeSystem::displayTask2() { | ||||||
| @@ -274,13 +256,6 @@ 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::kMinGearSize; |     uint8_t _currentGearSize = bike_computer::kMaxGearSize; | ||||||
|     // 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) {} | PedalDevice::PedalDevice(Timer& timer) : _timer(timer), _pedalRotationTime(0) {} | ||||||
|  |  | ||||||
| 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,7 +43,8 @@ namespace static_scheduling { | |||||||
|  |  | ||||||
| static constexpr std::chrono::microseconds kTaskRunTime = 100000us; | static constexpr std::chrono::microseconds kTaskRunTime = 100000us; | ||||||
|  |  | ||||||
| ResetDevice::ResetDevice(Timer& timer) : _timer(timer), _resetButton(PUSH_BUTTON) { | ResetDevice::ResetDevice(Timer& timer) | ||||||
|  |     : _resetButton(PUSH_BUTTON), _timer(timer), _pressTime(0) { | ||||||
|     _resetButton.rise(callback(this, &ResetDevice::onRise)); |     _resetButton.rise(callback(this, &ResetDevice::onRise)); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -67,7 +67,10 @@ 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() { | ||||||
| @@ -176,21 +179,18 @@ void BikeSystem::speedDistanceTask() { | |||||||
|         _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime); |         _timer, advembsof::TaskLogger::kSpeedTaskIndex, taskStartTime); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::temperatureTask() { | void BikeSystem::displayTask1() { | ||||||
|     auto taskStartTime = _timer.elapsed_time(); |     auto taskStartTime = _timer.elapsed_time(); | ||||||
|  |  | ||||||
|     // tr_warn("Tick1 %" PRIu64, _timer.elapsed_time().count()); |     _displayDevice.displayGear(_currentGear); | ||||||
|  |     _displayDevice.displaySpeed(_currentSpeed); | ||||||
|     // no need to protect access to data members (single threaded) |     _displayDevice.displayDistance(_traveledDistance); | ||||||
|     _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>( | ||||||
|         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::resetTask() { | void BikeSystem::resetTask() { | ||||||
| @@ -208,18 +208,17 @@ void BikeSystem::resetTask() { | |||||||
|         _timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime); |         _timer, advembsof::TaskLogger::kResetTaskIndex, taskStartTime); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BikeSystem::displayTask1() { | void BikeSystem::temperatureTask() { | ||||||
|     auto taskStartTime = _timer.elapsed_time(); |     auto taskStartTime = _timer.elapsed_time(); | ||||||
|  |  | ||||||
|     _displayDevice.displayGear(_currentGear); |     // no need to protect access to data members (single threaded) | ||||||
|     _displayDevice.displaySpeed(_currentSpeed); |     _currentTemperature = _sensorDevice.readTemperature(); | ||||||
|     _displayDevice.displayDistance(_traveledDistance); |  | ||||||
|  |  | ||||||
|     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::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::kMinGearSize; |     uint8_t _currentGearSize = bike_computer::kMaxGearSize; | ||||||
|     // 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; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user