| 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<int>(int, int, int):
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 time.
bool 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.
|
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 | // DBC bit numbers | |||
| 131 | // byte 0 7 6 5 4 3 2 1 0 | |||
| 132 | // byte 1 15 14 13 12 11 10 9 8 | |||
| 133 | // byte 2 23 22 21 20 19 18 17 16 | |||
| 134 | // byte 3 31 30 29 28 27 26 25 24 | |||
| 135 | // byte 4 39 38 37 36 35 34 33 32 | |||
| 136 | // byte 5 47 46 45 44 43 42 41 40 | |||
| 137 | // byte 6 55 54 53 52 51 50 49 48 | |||
| 138 | // byte 7 63 62 61 60 57 58 57 56 | |||
| 139 | ||||
| 140 | // Intel byte order, bitIndex is the least significant bit of the value | |||
| 141 | // DBC sample: 0|16@1+ | |||
| 142 | uint32_t getBitRangeLsb(const uint8_t data[], int bitIndex, int bitWidth); | |||
| 143 | void setBitRangeLsb(uint8_t data[], int totalBitIndex, int bitWidth, uint32_t value); | |||
| 144 | ||||
| 145 | // Motorola byte order, bitIndex is the least significant bit of the value | |||
| 146 | // not used in DBC | |||
| 147 | uint32_t getBitRangeMsb(const uint8_t data[], int bitIndex, int bitWidth); | |||
| 148 | void setBitRangeMsb(uint8_t data[], int totalBitIndex, int bitWidth, uint32_t value); | |||
| 149 | ||||
| 150 | // Motorola byte order, bitIndex is the most significant bit of the value | |||
| 151 | // DBC sample: 7|16@0+ | |||
| 152 | uint32_t getBitRangeMoto(const uint8_t data[], int bitIndex, int bitWidth); | |||
| 153 | void setBitRangeMoto(uint8_t data[], int totalBitIndex, int bitWidth, uint32_t value); | |||
| 154 | ||||
| 155 | // convert bitIndex from LSB to MSB style | |||
| 156 | int motorolaMagicFromDbc(int b, int length); | |||
| 157 |