|
| 1 | +#include "AppConfig.h" |
| 2 | +#include "Logger.h" |
| 3 | +#include "mbed.h" |
| 4 | + |
| 5 | +Thread periodic_10s_thread(osPriorityHigh); |
| 6 | +Thread periodic_1s_thread(osPriorityHigh2); |
| 7 | +Thread periodic_100ms_thread(osPriorityHigh4); |
| 8 | +Thread periodic_10ms_thread(osPriorityHigh6); |
| 9 | +Thread periodic_1ms_thread(osPriorityRealtime); |
| 10 | + |
| 11 | +void periodic_10s(void) { |
| 12 | + auto startTime = Kernel::Clock::now(); |
| 13 | + for (Module* module : gModules) { |
| 14 | + module->periodic_10s(); |
| 15 | + } |
| 16 | + |
| 17 | + auto nextStartTime = startTime + 10s; |
| 18 | + if (Kernel::Clock::now() > nextStartTime) { |
| 19 | + Utility::logger << "Periodic 10s task failed to hit the deadline!\n"; |
| 20 | + } |
| 21 | + ThisThread::sleep_until(nextStartTime); |
| 22 | +} |
| 23 | + |
| 24 | +void periodic_1s(void) { |
| 25 | + auto startTime = Kernel::Clock::now(); |
| 26 | + for (Module* module : gModules) { |
| 27 | + module->periodic_1s(); |
| 28 | + } |
| 29 | + |
| 30 | + auto nextStartTime = startTime + 1s; |
| 31 | + if (Kernel::Clock::now() > nextStartTime) { |
| 32 | + Utility::logger << "Periodic 1s task failed to hit the deadline!\n"; |
| 33 | + } |
| 34 | + ThisThread::sleep_until(nextStartTime); |
| 35 | +} |
| 36 | + |
| 37 | +void periodic_100ms(void) { |
| 38 | + auto startTime = Kernel::Clock::now(); |
| 39 | + for (Module* module : gModules) { |
| 40 | + module->periodic_100ms(); |
| 41 | + } |
| 42 | + |
| 43 | + auto nextStartTime = startTime + 100ms; |
| 44 | + if (Kernel::Clock::now() > nextStartTime) { |
| 45 | + Utility::logger << "Periodic 100ms task failed to hit the deadline!\n"; |
| 46 | + } |
| 47 | + ThisThread::sleep_until(nextStartTime); |
| 48 | +} |
| 49 | + |
| 50 | +void periodic_10ms(void) { |
| 51 | + auto startTime = Kernel::Clock::now(); |
| 52 | + for (Module* module : gModules) { |
| 53 | + module->periodic_10ms(); |
| 54 | + } |
| 55 | + |
| 56 | + auto nextStartTime = startTime + 10ms; |
| 57 | + if (Kernel::Clock::now() > nextStartTime) { |
| 58 | + Utility::logger << "Periodic 10ms task failed to hit the deadline!\n"; |
| 59 | + } |
| 60 | + ThisThread::sleep_until(nextStartTime); |
| 61 | +} |
| 62 | + |
| 63 | +void periodic_1ms(void) { |
| 64 | + auto startTime = Kernel::Clock::now(); |
| 65 | + for (Module* module : gModules) { |
| 66 | + module->periodic_1ms(); |
| 67 | + } |
| 68 | + |
| 69 | + auto nextStartTime = startTime + 1ms; |
| 70 | + if (Kernel::Clock::now() > nextStartTime) { |
| 71 | + Utility::logger << "Periodic 1ms task failed to hit the deadline!\n"; |
| 72 | + } |
| 73 | + ThisThread::sleep_until(nextStartTime); |
| 74 | +} |
| 75 | + |
| 76 | +int main() { |
| 77 | + periodic_1ms_thread.start(periodic_1ms); |
| 78 | + periodic_10ms_thread.start(periodic_10ms); |
| 79 | + periodic_100ms_thread.start(periodic_100ms); |
| 80 | + periodic_1s_thread.start(periodic_1s); |
| 81 | + periodic_10s_thread.start(periodic_10s); |
| 82 | + |
| 83 | + while (true) { |
| 84 | + } |
| 85 | +} |
0 commit comments