rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
main_loop.cpp
Go to the documentation of this file.
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"
9
11 : PeriodicController("MainLoop", PRIO_MAIN_LOOP, MAIN_LOOP_RATE)
12{
13}
14
15template <LoopPeriod TFlag>
17 if (m_cycleCounter % loopCounts<TFlag>() == 0) {
18 return TFlag;
19 } else {
20 return LoopPeriod::None;
21 }
22}
23
25 if (m_cycleCounter >= MAIN_LOOP_RATE) {
27 }
28
30 lp |= makePeriodFlag<LoopPeriod::Period1000hz>();
31 lp |= makePeriodFlag<LoopPeriod::Period500hz>();
32 lp |= makePeriodFlag<LoopPeriod::Period250hz>();
33 lp |= makePeriodFlag<LoopPeriod::Period200hz>();
34 lp |= makePeriodFlag<LoopPeriod::Period20hz>();
35
37
38 return lp;
39}
40
41void MainLoop::PeriodicTask(efitick_t nowNt) {
43
44 LoopPeriod currentLoopPeriod = makePeriodFlags();
45
46#if HAL_USE_ADC
47 if (currentLoopPeriod & ADC_UPDATE_RATE) {
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
68 // see test_periodic_thread_controller.cpp for explanation
69#if ! EFI_UNIT_TEST
70 mainLoop.start();
71#endif
72}
void adcInputsUpdateSubscribers(efitick_t nowNt)
LoopPeriod makePeriodFlag() const
Definition main_loop.cpp:16
LoopPeriod makePeriodFlags()
Definition main_loop.cpp:24
void PeriodicTask(efitick_t nowNt) override
Called periodically. Override this method to do work for your controller.
Definition main_loop.cpp:41
Base class for a controller that needs to run periodically to perform work.
void initMainLoop()
Definition main_loop.cpp:67
LoopPeriod
Definition main_loop.h:7
@ MainLoop
This file sets the thread priority for the threads running on rusEFI.