2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file efilib.h
|
|
|
|
*
|
|
|
|
* @date Feb 21, 2014
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2020-04-01 18:32:21 -07:00
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2022-09-15 19:12:49 -07:00
|
|
|
#ifdef __cplusplus
|
2022-09-15 18:27:20 -07:00
|
|
|
#include <rusefi/arrays.h>
|
2022-09-15 19:12:49 -07:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-08-09 20:03:58 -07:00
|
|
|
#define _MAX_FILLER 11
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
// http://en.wikipedia.org/wiki/Endianness
|
|
|
|
|
2021-07-04 15:03:17 -07:00
|
|
|
static inline uint16_t SWAP_UINT16(uint16_t x)
|
|
|
|
{
|
|
|
|
return ((x << 8) | (x >> 8));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t SWAP_UINT32(uint32_t x)
|
|
|
|
{
|
|
|
|
return (((x >> 24) & 0x000000ff) | ((x << 8) & 0x00ff0000) |
|
|
|
|
((x >> 8) & 0x0000ff00) | ((x << 24) & 0xff000000));
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-04-06 08:29:40 -07:00
|
|
|
#define BIT(n) (UINT32_C(1) << (n))
|
|
|
|
|
2021-11-14 13:29:46 -08:00
|
|
|
#define HUMAN_OFFSET 1
|
|
|
|
|
|
|
|
// human-readable IDs start from 1 while computer-readable indices start from 0
|
|
|
|
#define ID2INDEX(id) ((id) - HUMAN_OFFSET)
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
// number of milliseconds in one period of given frequency (per second)
|
|
|
|
#define frequency2periodMs(freq) ((1000.0f) / (freq))
|
|
|
|
|
|
|
|
// number of microseconds in one period of given frequency (per second)
|
|
|
|
#define frequency2periodUs(freq) ((1000000.0f) / (freq))
|
|
|
|
|
|
|
|
#define ERROR_CODE 311223344
|
|
|
|
|
2020-07-02 09:33:31 -07:00
|
|
|
#define Q(x) #x
|
|
|
|
#define QUOTE(x) Q(x)
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2017-03-29 18:07:26 -07:00
|
|
|
const char * boolToString(bool value);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
char * efiTrim(char *param);
|
2017-04-04 19:53:58 -07:00
|
|
|
int mytolower(const char c);
|
2015-07-10 06:01:56 -07:00
|
|
|
uint32_t efiStrlen(const char *param);
|
|
|
|
int efiPow10(int param);
|
|
|
|
bool startsWith(const char *line, const char *prefix);
|
|
|
|
int indexOf(const char *string, char ch);
|
|
|
|
float atoff(const char *string);
|
|
|
|
int atoi(const char *string);
|
|
|
|
|
|
|
|
#define UNUSED(x) (void)(x)
|
2022-07-16 21:16:22 -07:00
|
|
|
|
2017-12-10 07:19:05 -08:00
|
|
|
/**
|
|
|
|
* Rounds value to specified precision.
|
|
|
|
* @param precision some pow of 10 value - for example, 100 for two digit precision
|
|
|
|
*/
|
2015-07-10 06:01:56 -07:00
|
|
|
float efiRound(float value, float precision);
|
2022-07-16 21:16:22 -07:00
|
|
|
|
2022-01-03 00:31:57 -08:00
|
|
|
// sometimes known as 'itoa'
|
2015-07-10 06:01:56 -07:00
|
|
|
char* itoa10(char *p, int num);
|
|
|
|
|
2020-04-20 12:57:03 -07:00
|
|
|
/**
|
|
|
|
* clamps value into the [0, 100] range
|
|
|
|
*/
|
|
|
|
#define clampPercentValue(x) (clampF(0, x, 100))
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
bool strEqualCaseInsensitive(const char *str1, const char *str2);
|
|
|
|
bool strEqual(const char *str1, const char *str2);
|
|
|
|
|
2018-09-29 09:16:36 -07:00
|
|
|
// Currently used by air-interp. tCharge mode (see EngineState::updateTChargeK()).
|
|
|
|
float limitRateOfChange(float newValue, float oldValue, float incrLimitPerSec, float decrLimitPerSec, float secsPassed);
|
|
|
|
|
2022-09-20 03:19:51 -07:00
|
|
|
bool isPhaseInRange(float test, float current, float next);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2019-11-13 05:42:16 -08:00
|
|
|
|
2019-12-17 05:34:56 -08:00
|
|
|
#include <cstddef>
|
2021-05-20 17:00:32 -07:00
|
|
|
#include <cstring>
|
2019-12-17 05:34:56 -08:00
|
|
|
|
2020-12-04 20:59:21 -08:00
|
|
|
#define IS_NEGATIVE_ZERO(value) (__builtin_signbit(value) && value==0)
|
2020-06-18 20:29:08 -07:00
|
|
|
#define fixNegativeZero(value) (IS_NEGATIVE_ZERO(value) ? 0 : value)
|
2020-06-18 19:51:07 -07:00
|
|
|
|
2022-03-22 13:53:24 -07:00
|
|
|
#define assertIsInBounds(length, array, msg) efiAssertVoid(OBD_PCM_Processor_Fault, std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg)
|
2021-01-04 18:05:16 -08:00
|
|
|
|
2022-03-22 13:53:24 -07:00
|
|
|
#define assertIsInBoundsWithResult(length, array, msg, failedResult) efiAssert(OBD_PCM_Processor_Fault, std::is_unsigned_v<decltype(length)> && (length) < efi::size(array), msg, failedResult)
|
2021-01-04 19:13:59 -08:00
|
|
|
|
2021-12-30 08:39:04 -08:00
|
|
|
template <typename T>
|
|
|
|
bool isInRange(T min, T val, T max) {
|
|
|
|
return val >= min && val <= max;
|
|
|
|
}
|
|
|
|
|
2022-04-28 14:32:39 -07:00
|
|
|
static constexpr size_t operator-(Gpio a, Gpio b) {
|
|
|
|
return (size_t)a - (size_t)b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr Gpio operator-(Gpio a, size_t b) {
|
|
|
|
return (Gpio)((size_t)a - b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr Gpio operator+(Gpio a, size_t b) {
|
|
|
|
return (Gpio)((size_t)a + b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr Gpio operator+(size_t a, Gpio b) {
|
|
|
|
// addition is commutative, just use the other operator
|
|
|
|
return b + a;
|
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* __cplusplus */
|