| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Created by FDSoftware on 21/04/25. | |||
| 3 | // | |||
| 4 | ||||
| 5 | #include "pch.h" | |||
| 6 | #include "thread_priority.h" | |||
| 7 | #include "main_loop.h" | |||
| 8 | #include "main_loop_controller.h" | |||
| 9 | ||||
| 10 | 2 | MainLoop::MainLoop() | ||
| 11 | 2 | : PeriodicController("MainLoop", PRIO_MAIN_LOOP, MAIN_LOOP_RATE) | ||
| 12 | { | |||
| 13 | 2 | } | ||
| 14 | ||||
| 15 | template <LoopPeriod TFlag> | |||
| 16 | 29 | LoopPeriod MainLoop::makePeriodFlag() const { | ||
| 17 |
9/10LoopPeriod MainLoop::makePeriodFlag<(LoopPeriod)16>() const:
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 2 times.
LoopPeriod MainLoop::makePeriodFlag<(LoopPeriod)8>() const:
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
LoopPeriod MainLoop::makePeriodFlag<(LoopPeriod)4>() const:
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
LoopPeriod MainLoop::makePeriodFlag<(LoopPeriod)2>() const:
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
LoopPeriod MainLoop::makePeriodFlag<(LoopPeriod)1>() const:
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
29 | if (m_cycleCounter % loopCounts<TFlag>() == 0) { | |
| 18 | 22 | return TFlag; | ||
| 19 | } else { | |||
| 20 | 7 | return LoopPeriod::None; | ||
| 21 | } | |||
| 22 | } | |||
| 23 | ||||
| 24 | 5 | LoopPeriod MainLoop::makePeriodFlags() { | ||
| 25 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 4 times.
|
5 | if (m_cycleCounter >= MAIN_LOOP_RATE) { |
| 26 | 1 | m_cycleCounter = 0; | ||
| 27 | } | |||
| 28 | ||||
| 29 | 5 | LoopPeriod lp = LoopPeriod::None; | ||
| 30 |
1/1✓ Branch 2 taken 5 times.
|
5 | lp |= makePeriodFlag<LoopPeriod::Period1000hz>(); | |
| 31 |
1/1✓ Branch 2 taken 5 times.
|
5 | lp |= makePeriodFlag<LoopPeriod::Period500hz>(); | |
| 32 |
1/1✓ Branch 2 taken 5 times.
|
5 | lp |= makePeriodFlag<LoopPeriod::Period250hz>(); | |
| 33 |
1/1✓ Branch 2 taken 5 times.
|
5 | lp |= makePeriodFlag<LoopPeriod::Period200hz>(); | |
| 34 |
1/1✓ Branch 2 taken 5 times.
|
5 | lp |= makePeriodFlag<LoopPeriod::Period20hz>(); | |
| 35 | ||||
| 36 | 5 | m_cycleCounter++; | ||
| 37 | ||||
| 38 | 5 | return lp; | ||
| 39 | } | |||
| 40 | ||||
| 41 | ✗ | void MainLoop::PeriodicTask(efitick_t nowNt) { | ||
| 42 | ✗ | ScopePerf perf(PE::MainLoop); | ||
| 43 | ||||
| 44 | ✗ | LoopPeriod currentLoopPeriod = makePeriodFlags(); | ||
| 45 | ||||
| 46 | #if HAL_USE_ADC | |||
| 47 | if (currentLoopPeriod & ADC_UPDATE_RATE) { | |||
| 48 | adcInputsUpdateSubscribers(nowNt); | |||
| 49 | } | |||
| 50 | #endif // HAL_USE_ADC | |||
| 51 | ||||
| 52 | #if EFI_ELECTRONIC_THROTTLE_BODY | |||
| 53 | ✗ | if (currentLoopPeriod & ETB_UPDATE_RATE) { | ||
| 54 | // TODO: main_loop etb callback | |||
| 55 | } | |||
| 56 | #endif // EFI_ELECTRONIC_THROTTLE_BODY | |||
| 57 | ||||
| 58 | ✗ | if (currentLoopPeriod & SLOW_CALLBACK_RATE) { | ||
| 59 | //TODO: main_loop slow callback | |||
| 60 | } | |||
| 61 | ||||
| 62 | ✗ | if (currentLoopPeriod & FAST_CALLBACK_RATE) { | ||
| 63 | //TODO: main_loop fast callback | |||
| 64 | } | |||
| 65 | ✗ | } | ||
| 66 | ||||
| 67 | ✗ | void initMainLoop() { | ||
| 68 | // see test_periodic_thread_controller.cpp for explanation | |||
| 69 | #if ! EFI_UNIT_TEST | |||
| 70 | mainLoop.start(); | |||
| 71 | #endif | |||
| 72 | ✗ | } | ||
| 73 |