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 endTimers[MAX_CYLINDER_COUNT][2];
#if EFI_ENGINE_CONTROL && EFI_PROD_CODE
static void endAveraging(MapAverager* arg);
#if EFI_ENGINE_CONTROL && EFI_PROD_CODE
static size_t currentMapAverager = 0;
static void startAveraging(scheduling_s *endAveragingScheduling) {

View File

@ -17,7 +17,7 @@
#include "gpio/gpio_ext.h"
#include "gpio/drv8860.h"
#if (BOARD_DRV8860_COUNT > 0)
#if EFI_PROD_CODE && (BOARD_DRV8860_COUNT > 0)
/*==========================================================================*/
/* Driver local definitions. */
@ -90,7 +90,7 @@ static const char* drv8860_pin_names[DRV8860_OUTPUTS] = {
void Drv8860::spi_send(uint16_t tx) {
SPIDriver *spi = cfg->spi_bus;
/* Acquire ownership of the bus. */
spiAcquireBus(spi);
/* Setup transfer parameters. */
@ -200,7 +200,7 @@ int Drv8860::writePad(size_t pin, int value) {
o_state &= ~(1 << pin);
/* TODO: unlock */
wake_driver();
return 0;
}

View File

@ -25,7 +25,7 @@
#include "gpio/gpio_ext.h"
#include "gpio/tle6240.h"
#if (BOARD_TLE6240_COUNT > 0)
#if defined(BOARD_TLE6240_COUNT) && (BOARD_TLE6240_COUNT > 0)
/*
* TODO list:
@ -378,7 +378,7 @@ int Tle6240::writePad(unsigned int pin, int value)
{
chibios_rt::CriticalSectionLocker csl;
if (value)
o_state |= (1 << pin);
else

View File

@ -2,7 +2,7 @@
#include "gpio/gpio_ext.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_CFG 0x01

View File

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

View File

@ -11,6 +11,7 @@ static StoredValueSensor flexFuelTemp(SensorType::FuelTemperature, MS2NT(500));
static FlexConverter converter;
static Biquad flexTempFilter;
#if EFI_PROD_CODE
static Timer flexFreq, flexPulse;
@ -53,10 +54,9 @@ static void flexCallback(efitick_t nowNt, bool value) {
static Gpio flexPin = Gpio::Unassigned;
static void flexExtiCallback(void*, efitick_t nowNt) {
#if EFI_PROD_CODE
flexCallback(nowNt, efiReadPin(flexPin) ^ engineConfiguration->flexSensorInverted);
#endif
}
#endif
// 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) {
return;
}
#endif
flexPin = engineConfiguration->flexSensorPin;
#endif
// 0.01 means filter bandwidth of ~1hz with ~100hz sensor
flexTempFilter.configureLowpass(1, 0.01f);
@ -98,13 +98,13 @@ void deInitFlexSensor() {
flexSensor.unregister();
flexFuelTemp.unregister();
#if EFI_PROD_CODE
if (!isBrainPinValid(flexPin)) {
return;
}
#if EFI_PROD_CODE
efiExtiDisablePin(flexPin);
#endif
flexPin = Gpio::Unassigned;
#endif
}

View File

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

View File

@ -6,9 +6,40 @@
*/
#include "pch.h"
#include "mpu_util.h"
// 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.
uint32_t getTimeNowLowerNt(void) {
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
CANDriver* detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
static bool isValidCanTxPin(brain_pin_e) { return true; }
static bool isValidCanRxPin(brain_pin_e) { return true; }
static void canHwInfo(CANDriver*) { return; }
bool isValidCanTxPin(brain_pin_e);
bool isValidCanRxPin(brain_pin_e);
void canHwInfo(CANDriver*);
#endif // HAL_USE_CAN
static bool allowFlashWhileRunning() { return true; }
static void causeHardFault() { }
bool allowFlashWhileRunning() ;
void causeHardFault() ;
// Reset Cause
@ -24,12 +24,8 @@ typedef enum {
Reset_Cause_Option_Byte, // Option byte load reset
} Reset_Cause_t;
static Reset_Cause_t getMCUResetCause() {
return Reset_Cause_Unknown;
}
Reset_Cause_t getMCUResetCause() ;
static const char *getMCUResetCause(Reset_Cause_t) {
return "Unknown";
}
const char *getMCUResetCause(Reset_Cause_t);
#include "sim_watchdog.h"

View File

@ -21,10 +21,10 @@
// we use 'int' for compatibility with addConsoleActionI()
// 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
static void setWatchdogResetPeriod(int resetMs) { }
void setWatchdogResetPeriod(int resetMs);
// A reset is done only if enough time has passed since the last reset.
static void tryResetWatchdog() { }
void tryResetWatchdog();