rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
controllers
core
main_loop.h
Go to the documentation of this file.
1
#pragma once
2
3
#define MAIN_LOOP_RATE 1000
4
5
void
initMainLoop
();
6
7
enum class
LoopPeriod
: uint8_t {
8
None
= 0,
9
Period1000hz
= 1 << 0,
10
Period500hz
= 1 << 1,
11
Period250hz
= 1 << 2,
12
Period200hz
= 1 << 3,
13
Period20hz
= 1 << 4,
14
};
15
16
inline
constexpr
LoopPeriod
&
operator|=
(
LoopPeriod
& a,
const
LoopPeriod
& b) {
17
a =
static_cast<
LoopPeriod
>
(
static_cast<
uint8_t
>
(a) |
static_cast<
uint8_t
>
(b));
18
return
a;
19
}
20
21
inline
constexpr
bool
operator&
(
LoopPeriod
a,
LoopPeriod
b) {
22
return
0 != (
static_cast<
uint8_t
>
(a) &
static_cast<
uint8_t
>
(b));
23
}
24
25
constexpr
int
hzForPeriod
(
LoopPeriod
p) {
26
switch
(p) {
27
case
LoopPeriod::None
:
return
0;
28
case
LoopPeriod::Period1000hz
:
return
1000;
29
case
LoopPeriod::Period500hz
:
return
500;
30
case
LoopPeriod::Period250hz
:
return
250;
31
case
LoopPeriod::Period200hz
:
return
200;
32
case
LoopPeriod::Period20hz
:
return
20;
33
}
34
35
return
0;
36
}
37
38
constexpr
float
loopPeriodMs
(
LoopPeriod
p) {
39
return
1000.0f /
hzForPeriod
(p);
40
}
41
42
#ifndef ADC_UPDATE_RATE
43
#define ADC_UPDATE_RATE LoopPeriod::Period500hz
44
#endif
45
46
#define ETB_UPDATE_RATE LoopPeriod::Period500hz
47
#define FAST_CALLBACK_RATE LoopPeriod::Period200hz
48
#define SLOW_CALLBACK_RATE LoopPeriod::Period20hz
49
50
#define FAST_CALLBACK_PERIOD_MS loopPeriodMs(FAST_CALLBACK_RATE)
51
#define SLOW_CALLBACK_PERIOD_MS loopPeriodMs(SLOW_CALLBACK_RATE)
LoopPeriod
LoopPeriod
Definition
main_loop.h:7
LoopPeriod::None
@ None
LoopPeriod::Period200hz
@ Period200hz
LoopPeriod::Period250hz
@ Period250hz
LoopPeriod::Period1000hz
@ Period1000hz
LoopPeriod::Period500hz
@ Period500hz
LoopPeriod::Period20hz
@ Period20hz
loopPeriodMs
constexpr float loopPeriodMs(LoopPeriod p)
Definition
main_loop.h:38
operator&
constexpr bool operator&(LoopPeriod a, LoopPeriod b)
Definition
main_loop.h:21
initMainLoop
void initMainLoop()
Definition
main_loop.cpp:67
hzForPeriod
constexpr int hzForPeriod(LoopPeriod p)
Definition
main_loop.h:25
operator|=
constexpr LoopPeriod & operator|=(LoopPeriod &a, const LoopPeriod &b)
Definition
main_loop.h:16
Generated on Sat Sep 27 2025 00:10:04 for rusEFI by
1.9.8