making code more testable

This commit is contained in:
Andrey 2021-07-14 22:37:05 -04:00
parent b5f92e6722
commit 122ef9f637
7 changed files with 31 additions and 25 deletions

View File

@ -40,8 +40,10 @@ EXTERN_ENGINE;
PrimaryChannelThread() : TunerstudioThread("Primary TS Channel") { }
TsChannelBase* setupChannel() {
#if EFI_PROD_CODE
efiSetPadMode("Primary Channel RX", EFI_CONSOLE_RX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
efiSetPadMode("Primary Channel TX", EFI_CONSOLE_TX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
#endif /* EFI_PROD_CODE */
primaryChannel.start(CONFIG(uartConsoleSerialSpeed));
@ -67,8 +69,10 @@ EXTERN_ENGINE;
SecondaryChannelThread() : TunerstudioThread("Secondary TS Channel") { }
TsChannelBase* setupChannel() {
#if EFI_PROD_CODE
efiSetPadMode("Secondary Channel RX", engineConfiguration->binarySerialRxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
efiSetPadMode("Secondary Channel TX", engineConfiguration->binarySerialTxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
#endif /* EFI_PROD_CODE */
secondaryChannel.start(CONFIG(uartConsoleSerialSpeed));

View File

@ -692,7 +692,7 @@ void startIdleThread(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
DISPLAY_TEXT(Manual_idle_control);
/* DISPLAY_ENDIF */
#if ! EFI_UNIT_TEST
#if EFI_PROD_CODE
// this is neutral/no gear switch input. on Miata it's wired both to clutch pedal and neutral in gearbox
// this switch is not used yet
if (isBrainPinValid(CONFIG(clutchDownPin))) {
@ -711,11 +711,12 @@ void startIdleThread(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
if (isBrainPinValid(engineConfiguration->brakePedalPin)) {
#if EFI_PROD_CODE
efiSetPadMode("brake pedal switch", engineConfiguration->brakePedalPin,
getInputMode(engineConfiguration->brakePedalPinMode));
#endif /* EFI_PROD_CODE */
}
#endif /* EFI_PROD_CODE */
#if ! EFI_UNIT_TEST
addConsoleAction("idleinfo", showIdleInfo);

View File

@ -50,8 +50,10 @@ void AdcSubscription::SubscribeSensor(FunctionalSensor &sensor,
return;
}
#if EFI_PROD_CODE
// Enable the input pin
efiSetPadMode(name, getAdcChannelBrainPin(name, channel), PAL_MODE_INPUT_ANALOG);
#endif /* EFI_PROD_CODE */
// if 0, default to the board's divider coefficient
if (voltsPerAdcVolt == 0) {

View File

@ -9,7 +9,6 @@
#include "global.h"
#if EFI_PROD_CODE
#include "os_access.h"
#include "trigger_input.h"
#include "servo.h"
@ -31,7 +30,10 @@
#include "sensor_chart.h"
#include "serial_hw.h"
#if EFI_PROD_CODE
#include "mpu_util.h"
#endif /* EFI_PROD_CODE */
#include "mmc_card.h"
#include "AdcConfiguration.h"
@ -137,8 +139,6 @@ SPIDriver * getSpiDevice(spi_device_e spiDevice) {
}
#endif
#if EFI_PROD_CODE
#define TPS_IS_SLOW -1
static int fastMapSampleIndex;
@ -299,7 +299,7 @@ void stopSpi(spi_device_e device) {
* todo: maybe start invoking this method on ECU start so that peripheral start-up initialization and restart are unified?
*/
void applyNewHardwareSettings(void) {
void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
/**
* All 'stop' methods need to go before we begin starting pins.
*
@ -427,7 +427,7 @@ void applyNewHardwareSettings(void) {
#if EFI_IDLE_CONTROL
if (isIdleHardwareRestartNeeded()) {
initIdleHardware();
initIdleHardware(PASS_ENGINE_PARAMETER_SIGNATURE);
}
#endif
@ -439,7 +439,7 @@ void applyNewHardwareSettings(void) {
startBoostPin();
#endif
#if EFI_EMULATE_POSITION_SENSORS
startTriggerEmulatorPins();
startTriggerEmulatorPins(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_EMULATE_POSITION_SENSORS */
#if EFI_LOGIC_ANALYZER
startLogicAnalyzerPins();
@ -451,6 +451,7 @@ void applyNewHardwareSettings(void) {
adcConfigListener(engine);
}
#if EFI_PROD_CODE
void setBor(int borValue) {
efiPrintf("setting BOR to %d", borValue);
BOR_Set((BOR_Level_t)borValue);
@ -460,9 +461,10 @@ void setBor(int borValue) {
void showBor(void) {
efiPrintf("BOR=%d", (int)BOR_Get());
}
#endif /* EFI_PROD_CODE */
// This function initializes hardware that can do so before configuration is loaded
void initHardwareNoConfig() {
void initHardwareNoConfig(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
efiAssertVoid(CUSTOM_IH_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "init h");
efiAssertVoid(CUSTOM_EC_NULL, engineConfiguration!=NULL, "engineConfiguration");
@ -483,10 +485,12 @@ void initHardwareNoConfig() {
*/
initPrimaryPins();
#if EFI_PROD_CODE
// it's important to initialize this pretty early in the game before any scheduling usages
initSingleTimerExecutorHardware();
initSingleTimerExecutorHardware(PASS_ENGINE_PARAMETER_SIGNATURE);
initRtc();
#endif /* EFI_PROD_CODE */
#if EFI_INTERNAL_FLASH
initFlash();
@ -502,7 +506,7 @@ void initHardwareNoConfig() {
#endif // EFI_FILE_LOGGING
}
void initHardware() {
void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_HD44780_LCD
lcd_HD44780_init();
if (hasFirmwareError())
@ -531,7 +535,7 @@ void initHardware() {
initSpiModules(engineConfiguration);
#endif /* HAL_USE_SPI */
#if BOARD_EXT_GPIOCHIPS > 0
#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
// initSmartGpio depends on 'initSpiModules'
initSmartGpio(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif
@ -605,10 +609,6 @@ void initHardware() {
efiPrintf("initHardware() OK!");
}
#endif /* EFI_PROD_CODE */
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
#if HAL_USE_SPI
// this is F4 implementation but we will keep it here for now for simplicity
int getSpiPrescaler(spi_speed_e speed, spi_device_e device) {

View File

@ -44,17 +44,18 @@ brain_pin_e getSckPin(spi_device_e device);
#ifdef __cplusplus
#if EFI_PROD_CODE
#include "engine.h"
#include "debounce.h"
void applyNewHardwareSettings(void);
void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// Initialize hardware that doesn't require configuration to be loaded
void initHardwareNoConfig();
void initHardwareNoConfig(DECLARE_ENGINE_PARAMETER_SIGNATURE);
// Initialize hardware with configuration loaded
void initHardware();
void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#if EFI_PROD_CODE
#include "debounce.h"
#endif /* EFI_PROD_CODE */

View File

@ -19,11 +19,11 @@
}
#if EFI_GPIO_HARDWARE
EXTERNC void efiSetPadMode(const char *msg, brain_pin_e pin, iomode_t mode);
EXTERNC void efiSetPadModeWithoutOwnershipAcquisition(const char *msg, brain_pin_e brainPin, iomode_t mode);
EXTERNC void efiSetPadUnused(brain_pin_e brainPin);
#if EFI_GPIO_HARDWARE
EXTERNC bool efiReadPin(brain_pin_e pin);
EXTERNC iomode_t getInputMode(pin_input_mode_e mode);

View File

@ -24,8 +24,6 @@
#include "eficonsole.h"
#endif /* __cplusplus */
#define efiSetPadMode(msg, brainPin, mode) {}
#define hasOsPanicError() (FALSE)
#define US_TO_NT_MULTIPLIER 100