only: better guards

This commit is contained in:
Andrey 2024-03-15 18:30:09 -06:00
parent 8ad092a08d
commit cd74860f37
10 changed files with 68 additions and 29 deletions

View File

@ -57,9 +57,9 @@ static int averagedMapBufIdx = 0;
static scheduling_s startTimers[MAX_CYLINDER_COUNT][2]; static scheduling_s startTimers[MAX_CYLINDER_COUNT][2];
static scheduling_s endTimers[MAX_CYLINDER_COUNT][2]; static scheduling_s endTimers[MAX_CYLINDER_COUNT][2];
#if EFI_ENGINE_CONTROL && EFI_PROD_CODE
static void endAveraging(MapAverager* arg); static void endAveraging(MapAverager* arg);
#if EFI_ENGINE_CONTROL && EFI_PROD_CODE
static size_t currentMapAverager = 0; static size_t currentMapAverager = 0;
static void startAveraging(scheduling_s *endAveragingScheduling) { static void startAveraging(scheduling_s *endAveragingScheduling) {

View File

@ -17,7 +17,7 @@
#include "gpio/gpio_ext.h" #include "gpio/gpio_ext.h"
#include "gpio/drv8860.h" #include "gpio/drv8860.h"
#if (BOARD_DRV8860_COUNT > 0) #if EFI_PROD_CODE && (BOARD_DRV8860_COUNT > 0)
/*==========================================================================*/ /*==========================================================================*/
/* Driver local definitions. */ /* Driver local definitions. */

View File

@ -25,7 +25,7 @@
#include "gpio/gpio_ext.h" #include "gpio/gpio_ext.h"
#include "gpio/tle6240.h" #include "gpio/tle6240.h"
#if (BOARD_TLE6240_COUNT > 0) #if defined(BOARD_TLE6240_COUNT) && (BOARD_TLE6240_COUNT > 0)
/* /*
* TODO list: * TODO list:

View File

@ -2,7 +2,7 @@
#include "gpio/gpio_ext.h" #include "gpio/gpio_ext.h"
#include "gpio/tle9104.h" #include "gpio/tle9104.h"
#if BOARD_TLE9104_COUNT > 0 #if defined(BOARD_TLE9104_COUNT) && BOARD_TLE9104_COUNT > 0
#define TLE9104_REG_CTRL 0x00 #define TLE9104_REG_CTRL 0x00
#define TLE9104_REG_CFG 0x01 #define TLE9104_REG_CFG 0x01

View File

@ -19,6 +19,8 @@
#include "drivers/gpio/tle9104.h" #include "drivers/gpio/tle9104.h"
#include "drivers/gpio/can_gpio.h" #include "drivers/gpio/can_gpio.h"
#if EFI_PROD_CODE
#if (BOARD_TLE6240_COUNT > 0) #if (BOARD_TLE6240_COUNT > 0)
// todo: migrate to TS or board config // todo: migrate to TS or board config
#ifndef TLE6240_RESET_PORT #ifndef TLE6240_RESET_PORT
@ -215,9 +217,11 @@ struct drv8860_config drv8860 = {
}; };
#endif /* (BOARD_DRV8860_COUNT > 0) */ #endif /* (BOARD_DRV8860_COUNT > 0) */
#endif // EFI_PROD_CODE
void initSmartGpio() { void initSmartGpio() {
startSmartCsPins(); startSmartCsPins();
#if EFI_PROD_CODE
#if (BOARD_TLE6240_COUNT > 0) #if (BOARD_TLE6240_COUNT > 0)
if (isBrainPinValid(engineConfiguration->tle6240_cs)) { if (isBrainPinValid(engineConfiguration->tle6240_cs)) {
tle6240.spi_config.ssport = getHwPort("tle6240 CS", engineConfiguration->tle6240_cs); tle6240.spi_config.ssport = getHwPort("tle6240 CS", engineConfiguration->tle6240_cs);
@ -295,12 +299,14 @@ void initSmartGpio() {
// No official boards have this IC // No official boards have this IC
#endif #endif
#endif // EFI_PROD_CODE
/* external chip init */ /* external chip init */
gpiochips_init(); gpiochips_init();
} }
void tle8888startup() { void tle8888startup() {
#if (BOARD_TLE8888_COUNT > 0) #if EFI_PROD_CODE && (BOARD_TLE8888_COUNT > 0)
static efitick_t tle8888CrankingResetTime = 0; static efitick_t tle8888CrankingResetTime = 0;
if (engineConfiguration->useTLE8888_cranking_hack && engine->rpmCalculator.isCranking()) { if (engineConfiguration->useTLE8888_cranking_hack && engine->rpmCalculator.isCranking()) {
@ -316,6 +322,7 @@ void tle8888startup() {
} }
void stopSmartCsPins() { void stopSmartCsPins() {
#if EFI_PROD_CODE
#if (BOARD_TLE8888_COUNT > 0) #if (BOARD_TLE8888_COUNT > 0)
efiSetPadUnused(activeConfiguration.tle8888_cs); efiSetPadUnused(activeConfiguration.tle8888_cs);
#endif /* BOARD_TLE8888_COUNT */ #endif /* BOARD_TLE8888_COUNT */
@ -336,9 +343,11 @@ void stopSmartCsPins() {
#if (BOARD_TLE9104_COUNT > 0) #if (BOARD_TLE9104_COUNT > 0)
// No official boards have this IC // No official boards have this IC
#endif #endif
#endif // EFI_PROD_CODE
} }
void startSmartCsPins() { void startSmartCsPins() {
#if EFI_PROD_CODE
#if (BOARD_TLE8888_COUNT > 0) #if (BOARD_TLE8888_COUNT > 0)
tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs, tle8888Cs.initPin("tle8888 CS", engineConfiguration->tle8888_cs,
engineConfiguration->tle8888_csPinMode); engineConfiguration->tle8888_csPinMode);
@ -376,4 +385,5 @@ void startSmartCsPins() {
// todo: use existing l9779_cs and l9779_csPinMode settings // todo: use existing l9779_cs and l9779_csPinMode settings
// todo: no official boards have this IC yet // todo: no official boards have this IC yet
#endif #endif
#endif // EFI_PROD_CODE
} }

View File

@ -11,6 +11,7 @@ static StoredValueSensor flexFuelTemp(SensorType::FuelTemperature, MS2NT(500));
static FlexConverter converter; static FlexConverter converter;
static Biquad flexTempFilter; static Biquad flexTempFilter;
#if EFI_PROD_CODE
static Timer flexFreq, flexPulse; static Timer flexFreq, flexPulse;
@ -53,10 +54,9 @@ static void flexCallback(efitick_t nowNt, bool value) {
static Gpio flexPin = Gpio::Unassigned; static Gpio flexPin = Gpio::Unassigned;
static void flexExtiCallback(void*, efitick_t nowNt) { static void flexExtiCallback(void*, efitick_t nowNt) {
#if EFI_PROD_CODE
flexCallback(nowNt, efiReadPin(flexPin) ^ engineConfiguration->flexSensorInverted); flexCallback(nowNt, efiReadPin(flexPin) ^ engineConfiguration->flexSensorInverted);
#endif
} }
#endif
// https://rusefi.com/forum/viewtopic.php?p=37452#p37452 // https://rusefi.com/forum/viewtopic.php?p=37452#p37452
@ -66,8 +66,8 @@ void initFlexSensor(bool isFirstTime) {
PAL_EVENT_MODE_BOTH_EDGES, flexExtiCallback, nullptr) < 0) { PAL_EVENT_MODE_BOTH_EDGES, flexExtiCallback, nullptr) < 0) {
return; return;
} }
#endif
flexPin = engineConfiguration->flexSensorPin; flexPin = engineConfiguration->flexSensorPin;
#endif
// 0.01 means filter bandwidth of ~1hz with ~100hz sensor // 0.01 means filter bandwidth of ~1hz with ~100hz sensor
flexTempFilter.configureLowpass(1, 0.01f); flexTempFilter.configureLowpass(1, 0.01f);
@ -98,13 +98,13 @@ void deInitFlexSensor() {
flexSensor.unregister(); flexSensor.unregister();
flexFuelTemp.unregister(); flexFuelTemp.unregister();
#if EFI_PROD_CODE
if (!isBrainPinValid(flexPin)) { if (!isBrainPinValid(flexPin)) {
return; return;
} }
#if EFI_PROD_CODE
efiExtiDisablePin(flexPin); efiExtiDisablePin(flexPin);
#endif
flexPin = Gpio::Unassigned; flexPin = Gpio::Unassigned;
#endif
} }

View File

@ -27,11 +27,13 @@
#define EFI_DYNO_VIEW FALSE #define EFI_DYNO_VIEW FALSE
#define EFI_ONBOARD_MEMS FALSE #define EFI_ONBOARD_MEMS FALSE
#define EFI_DAC FALSE #define EFI_DAC FALSE
#define EFI_POTENTIOMETER FALSE
#define EFI_PERF_METRICS FALSE
#define EFI_WIFI FALSE #define EFI_WIFI FALSE
#define EFI_BACKUP_SRAM FALSE #define EFI_BACKUP_SRAM FALSE
#define EFI_UART_GPS FALSE #define EFI_UART_GPS FALSE
#define EFI_HELLA_OIL FALSE #define EFI_HELLA_OIL FALSE
#define EFI_USE_OPENBLT FALSE #define USE_OPENBLT FALSE
#define EFI_BOOTLOADER FALSE #define EFI_BOOTLOADER FALSE
#define EFI_WS2812 FALSE #define EFI_WS2812 FALSE
#define EFI_MCP_3208 FALSE #define EFI_MCP_3208 FALSE

View File

@ -6,9 +6,40 @@
*/ */
#include "pch.h" #include "pch.h"
#include "mpu_util.h"
// Since all the time logic in the firmware is centered around this function, we only provide this // Since all the time logic in the firmware is centered around this function, we only provide this
// function in the firmware. It forces us to exercise the functions that build on this one. // function in the firmware. It forces us to exercise the functions that build on this one.
uint32_t getTimeNowLowerNt(void) { uint32_t getTimeNowLowerNt(void) {
return US2NT(chVTGetSystemTimeX() * (1000000 / CH_CFG_ST_FREQUENCY)); return US2NT(chVTGetSystemTimeX() * (1000000 / CH_CFG_ST_FREQUENCY));
} }
#if HAL_USE_CAN
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
bool isValidCanTxPin(brain_pin_e) { return true; }
bool isValidCanRxPin(brain_pin_e) { return true; }
void canHwInfo(CANDriver*) { return; }
#endif // HAL_USE_CAN
bool allowFlashWhileRunning() { return true; }
//void causeHardFault() { }
Reset_Cause_t getMCUResetCause() {
return Reset_Cause_Unknown;
}
const char *getMCUResetCause(Reset_Cause_t) {
return "Unknown";
}
// we use 'int' for compatibility with addConsoleActionI()
// can be called multiple times to change the timeout
void startWatchdog(int) { }
// Can be called for debug reasons to test the watchdog
void setWatchdogResetPeriod(int resetMs) { }
// A reset is done only if enough time has passed since the last reset.
void tryResetWatchdog() { }

View File

@ -2,13 +2,13 @@
#if HAL_USE_CAN #if HAL_USE_CAN
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx); CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
static bool isValidCanTxPin(brain_pin_e) { return true; } bool isValidCanTxPin(brain_pin_e);
static bool isValidCanRxPin(brain_pin_e) { return true; } bool isValidCanRxPin(brain_pin_e);
static void canHwInfo(CANDriver*) { return; } void canHwInfo(CANDriver*);
#endif // HAL_USE_CAN #endif // HAL_USE_CAN
static bool allowFlashWhileRunning() { return true; } bool allowFlashWhileRunning() ;
static void causeHardFault() { } void causeHardFault() ;
// Reset Cause // Reset Cause
@ -24,12 +24,8 @@ typedef enum {
Reset_Cause_Option_Byte, // Option byte load reset Reset_Cause_Option_Byte, // Option byte load reset
} Reset_Cause_t; } Reset_Cause_t;
static Reset_Cause_t getMCUResetCause() { Reset_Cause_t getMCUResetCause() ;
return Reset_Cause_Unknown;
}
static const char *getMCUResetCause(Reset_Cause_t) { const char *getMCUResetCause(Reset_Cause_t);
return "Unknown";
}
#include "sim_watchdog.h" #include "sim_watchdog.h"

View File

@ -21,10 +21,10 @@
// we use 'int' for compatibility with addConsoleActionI() // we use 'int' for compatibility with addConsoleActionI()
// can be called multiple times to change the timeout // can be called multiple times to change the timeout
static void startWatchdog(int = WATCHDOG_TIMEOUT_MS) { } void startWatchdog(int = WATCHDOG_TIMEOUT_MS);
// Can be called for debug reasons to test the watchdog // Can be called for debug reasons to test the watchdog
static void setWatchdogResetPeriod(int resetMs) { } void setWatchdogResetPeriod(int resetMs);
// A reset is done only if enough time has passed since the last reset. // A reset is done only if enough time has passed since the last reset.
static void tryResetWatchdog() { } void tryResetWatchdog();