Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /** | |||
2 | * @file efilib.h | |||
3 | * | |||
4 | * @date Feb 21, 2014 | |||
5 | * @author Andrey Belomutskiy, (c) 2012-2020 | |||
6 | */ | |||
7 | ||||
8 | #pragma once | |||
9 | ||||
10 | #include "unused.h" | |||
11 | #include "efi_quote.h" | |||
12 | #include <stdint.h> | |||
13 | ||||
14 | #include <rusefi/arrays.h> | |||
15 | ||||
16 | int djb2lowerCase(const char *str); | |||
17 | ||||
18 | #define _MAX_FILLER 11 | |||
19 | ||||
20 | // http://en.wikipedia.org/wiki/Endianness | |||
21 | ||||
22 | 10 | inline uint16_t SWAP_UINT16(uint16_t x) | ||
23 | { | |||
24 | 10 | return ((x << 8) | (x >> 8)); | ||
25 | } | |||
26 | ||||
27 | 4 | inline uint32_t SWAP_UINT32(uint32_t x) | ||
28 | { | |||
29 | 4 | return (((x >> 24) & 0x000000ff) | ((x << 8) & 0x00ff0000) | | ||
30 | 4 | ((x >> 8) & 0x0000ff00) | ((x << 24) & 0xff000000)); | ||
31 | } | |||
32 | ||||
33 | #define BIT(n) (UINT32_C(1) << (n)) | |||
34 | ||||
35 | // also known as 'HUMAN_INDEX' | |||
36 | #define HUMAN_OFFSET 1 | |||
37 | ||||
38 | // human-readable IDs start from 1 while computer-readable indices start from 0 | |||
39 | #define ID2INDEX(id) ((id) - HUMAN_OFFSET) | |||
40 | ||||
41 | // number of milliseconds in one period of given frequency (per second) | |||
42 | #define frequency2periodMs(freq) ((1000.0f) / (freq)) | |||
43 | ||||
44 | // number of microseconds in one period of given frequency (per second) | |||
45 | #define frequency2periodUs(freq) ((1000000.0f) / (freq)) | |||
46 | ||||
47 | const char * boolToString(bool value); | |||
48 | ||||
49 | char * efiTrim(char *param); | |||
50 | int efiPow10(int param); | |||
51 | ||||
52 | /** | |||
53 | * Rounds value to specified precision. | |||
54 | * @param precision some pow of 10 value - for example, 100 for two digit precision | |||
55 | */ | |||
56 | float efiRound(float value, float precision); | |||
57 | ||||
58 | // sometimes known as 'itoa' | |||
59 | char* itoa10(char *p, int num); | |||
60 | ||||
61 | /** | |||
62 | * clamps value into the [0, 100] range | |||
63 | */ | |||
64 | #define clampPercentValue(x) (clampF(0, x, 100)) | |||
65 | ||||
66 | // Currently used by air-interp. tCharge mode (see EngineState::updateTChargeK()). | |||
67 | float limitRateOfChange(float newValue, float oldValue, float incrLimitPerSec, float decrLimitPerSec, float secsPassed); | |||
68 | ||||
69 | bool isPhaseInRange(float test, float current, float next); | |||
70 | ||||
71 | #include <cstddef> | |||
72 | #include <cstring> | |||
73 | ||||
74 | #define IS_NEGATIVE_ZERO(value) (__builtin_signbit(value) && value==0) | |||
75 | #define fixNegativeZero(value) (IS_NEGATIVE_ZERO(value) ? 0 : value) | |||
76 | ||||
77 | #define assertIsInBounds(length, array, msg) criticalAssertVoid(std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg) | |||
78 | ||||
79 | #define assertIsInBoundsWithResult(length, array, msg, failedResult) efiAssert(ObdCode::OBD_PCM_Processor_Fault, std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg, failedResult) | |||
80 | ||||
81 | template <typename T> | |||
82 | 1398 | bool isInRange(T min, T val, T max) { | ||
83 |
8/8bool isInRange<float>(float, float, float):
✓ Branch 0 taken 1076 times.
✓ Branch 1 taken 317 times.
✓ Branch 2 taken 742 times.
✓ Branch 3 taken 334 times.
bool isInRange<int>(int, int, int):
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
|
1398 | return val >= min && val <= max; | |
84 | } | |||
85 | ||||
86 | 8 | inline constexpr size_t operator-(Gpio a, Gpio b) { | ||
87 | 8 | return (size_t)a - (size_t)b; | ||
88 | } | |||
89 | ||||
90 | 5 | inline constexpr Gpio operator-(Gpio a, size_t b) { | ||
91 | 5 | return (Gpio)((size_t)a - b); | ||
92 | } | |||
93 | ||||
94 | 46 | inline constexpr Gpio operator+(Gpio a, size_t b) { | ||
95 | 46 | return (Gpio)((size_t)a + b); | ||
96 | } | |||
97 | ||||
98 | inline constexpr Gpio operator+(size_t a, Gpio b) { | |||
99 | // addition is commutative, just use the other operator | |||
100 | return b + a; | |||
101 | } | |||
102 | ||||
103 | namespace efi | |||
104 | { | |||
105 | template <class _Ty> | |||
106 | struct remove_reference { | |||
107 | using type = _Ty; | |||
108 | }; | |||
109 | ||||
110 | template <class _Ty> | |||
111 | struct remove_reference<_Ty&> { | |||
112 | using type = _Ty; | |||
113 | }; | |||
114 | ||||
115 | template <class _Ty> | |||
116 | struct remove_reference<_Ty&&> { | |||
117 | using type = _Ty; | |||
118 | }; | |||
119 | ||||
120 | template <class _Ty> | |||
121 | using remove_reference_t = typename remove_reference<_Ty>::type; | |||
122 | ||||
123 | // FUNCTION TEMPLATE move | |||
124 | template <class _Ty> | |||
125 | constexpr remove_reference_t<_Ty>&& move(_Ty&& _Arg) noexcept { | |||
126 | return static_cast<remove_reference_t<_Ty>&&>(_Arg); | |||
127 | } | |||
128 | } | |||
129 | ||||
130 | int getBitRangeLsb(const uint8_t data[], int bitIndex, int bitWidth); | |||
131 | /** | |||
132 | for instance DBC 8|16@0 | |||
133 | */ | |||
134 | int getBitRangeMsb(const uint8_t data[], int bitIndex, int bitWidth); | |||
135 | void setBitRangeMsb(uint8_t data[], int totalBitIndex, int bitWidth, int value); | |||
136 | ||||
137 | int motorolaMagicFromDbc(int b, int length); | |||
138 | int getBitRangeMoto(const uint8_t data[], int bitIndex, int bitWidth); | |||
139 | void setBitRangeMoto(uint8_t data[], int totalBitIndex, int bitWidth, int value); | |||
140 |