rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
hellen_logic.h File Reference

Functions

void hellenWbo ()
 
void setHellenMegaEnPin (bool enableBoardOnStartUp=true)
 
void setHellenEnPin (Gpio pin, bool enableBoardOnStartUp=true)
 
void setHellen64MegaEnPin ()
 
bool isBoardWithPowerManagement ()
 
bool getHellenBoardEnabled ()
 
void hellenEnableEn (const char *msg="")
 
void hellenDisableEn (const char *msg="")
 
void hellenDisableEnSilently ()
 
void hellenBoardStandBy ()
 
void hellenMegaSdWithAccelerometer ()
 
void hellenMegaModule ()
 
void hellenMegaAccelerometerPreInitCS2Pin ()
 
void configureHellenCanTerminator ()
 
void setHellenCan ()
 
void setHellenCan2 ()
 
void setHellen64Can ()
 
void setHellenAnalogDividers ()
 
void setHellenVbatt ()
 
int detectHellenBoardId ()
 
void detectHellenBoardType ()
 
ObdCode boardGetAnalogDiagnostic ()
 
static void enableHellenSpi1 ()
 
static void setHellenSdCardSpi1Hardware ()
 
static void enableHellenSpi3 ()
 
static void setHellenSdCardSpi3NoCS ()
 
static void setAccelerometerSpi ()
 
static void setHellen64SdCardSpi ()
 
static void enableHellenSpi2 ()
 
void setHellenSdCardSpi2 ()
 
void setHellenSdCardSpi3 ()
 
void setDefaultHellenAtPullUps (float pullup=HELLEN_DEFAULT_AT_PULLUP)
 
void setHellenMMbaro ()
 

Function Documentation

◆ boardGetAnalogDiagnostic()

ObdCode boardGetAnalogDiagnostic ( )

Definition at line 228 of file hellen_common.cpp.

229{
230#ifdef DIAG_5VP_PIN
231 /* paranoid check */
232 if (!isBrainPinValid(DIAG_5VP_PIN)) {
233 /* Pin is not defined - return success */
234 return ObdCode::None;
235 }
236
238#else
239 return ObdCode::None;
240#endif
241}
bool efiReadPin(brain_pin_e pin)
Definition io_pins.cpp:89
@ OBD_ECM_VSS_OUTPUT_A_MALFUNCTION
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by analogGetDiagnostic(), boardGetAnalogInputDiagnostic(), and boardGetAnalogInputDiagnostic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configureHellenCanTerminator()

void configureHellenCanTerminator ( )

Definition at line 212 of file hellen_common.cpp.

212 {
213 static bool initialized = false;
214 static OutputPin terminatorControlPin;
215 if (!initialized) {
216 initialized = true;
217 terminatorControlPin.initPin("CAN-term", H_SPI3_CS); // todo: make this pin configurable
218 terminatorControlPin.setValue(engineConfiguration->boardUseCanTerminator);
219 }
220}
Single output pin reference and state.
Definition efi_output.h:49
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
Definition efi_gpio.cpp:711
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
static constexpr engine_configuration_s * engineConfiguration
static int initialized
Definition histogram.cpp:39

Referenced by hellen112_17_boardConfigOverrides(), and hellen_honda_k_boardConfigOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detectHellenBoardId()

int detectHellenBoardId ( )

Definition at line 308 of file hellen_board_id.cpp.

308 {
309 int boardId = -1;
310#if defined( HELLEN_BOARD_ID_PIN_1) && !defined(HW_HELLEN_SKIP_BOARD_TYPE)
311 efiPrintf("Starting Hellen Board ID detection...");
312 Timer t;
313 t.reset();
314
315 const int numPins = 2;
316 Gpio rPins[numPins] = { HELLEN_BOARD_ID_PIN_1, HELLEN_BOARD_ID_PIN_2};
317
318 // We start from the estimated capacitance, but the real one can be +-10%
319 float C = HELLEN_BOARD_ID_CAPACITOR;
320
321 // we need to find the resistor values connected to the mcu pins and to the capacitor.
322 float R[numPins] = { 0 };
323 int rIdx[numPins] = { 0 };
324
325 HellenBoardIdFinder<numPins> finder(rPins);
326
327 // init some ChibiOs objects
328 chSemObjectInit(&finder.state.boardId_wake, 0);
329
330 // R1 is the first, R2 is the second
331 for (int i = 0; i < numPins; i++) {
332#ifdef HELLEN_BOARD_ID_DEBUG
333 efiPrintf("*** Resistor R%d...", i + 1);
334#endif /* HELLEN_BOARD_ID_DEBUG */
335
336 float Tc1_us = 0, Tc2_us = 0;
337 // We need several measurements for each resistor to increase the precision.
338 // But if any of the measurements fails, then abort!
339 if (!finder.measureChargingTimesAveraged(i, Tc1_us, Tc2_us))
340 break;
341
342 // Now roughly estimate the resistor value using the approximate threshold voltage.
343 float Rest = finder.calcEstimatedResistance(Tc1_us, C);
344 // check if we are inside the range
345 if (Rest < 300.0f || Rest > 15000.0f) {
346 efiPrintf("* Unrealistic estimated resistor value (%f)! Aborting!", Rest);
347 break;
348 }
349
350 // for the first resistor, we test only "major" values because we don't know the exact capacitance yet
351 bool testOnlyMajorSeries = (i == 0);
352
353 float Rmeasured, newC;
354 // Now calculate the R and C
355 R[i] = finder.calc(Tc1_us, Tc2_us, Rest, C, testOnlyMajorSeries, &Rmeasured, &newC, &rIdx[i]);
356 C = newC;
357
358#ifdef HELLEN_BOARD_ID_DEBUG
359 efiPrintf("* R = %f, Rmeasured = %f, Rest = %f, Creal = %f", R[i], Rmeasured, Rest, C);
360#endif /* HELLEN_BOARD_ID_DEBUG */
361 }
362
363 // in case the process was aborted
364 for (size_t k = 0; k < numPins; k++) {
365 efiExtiDisablePin(rPins[k]);
366 // release the pins
367 palSetPadMode(getBrainPinPort(rPins[k]), getBrainPinIndex(rPins[k]), PAL_MODE_RESET);
368 }
369
370 float elapsed_Ms = t.getElapsedSeconds() * 1000;
371
372 // Check that all resistors were actually detected
373 bool allRValid = true;
374 for (size_t i = 0; i < numPins; i++) {
375 allRValid &= R[i] != 0;
376 }
377
378 // Decode board ID only if all resistors could be decoded, otherwise we return -1
379 if (allRValid) {
380 boardId = HELLEN_GET_BOARD_ID(rIdx[0], rIdx[1]);
381 } else {
382 boardId = -1;
383 }
384
385 efiPrintf("* RESULT: BoardId = %d, R1 = %.0f, R2 = %.0f (Elapsed time: %.1f ms)", boardId, R[0], R[1], elapsed_Ms);
386#endif /* HELLEN_BOARD_ID_PIN_1 */
387 return boardId;
388}
void efiExtiDisablePin(brain_pin_e brainPin)
C
int getBrainPinIndex(Gpio brainPin)
ioportid_t getBrainPinPort(brain_pin_e brainPin)

Referenced by detectHellenBoardType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detectHellenBoardType()

void detectHellenBoardType ( )

Definition at line 222 of file hellen_common.cpp.

222 {
223#ifndef EFI_BOOTLOADER
225#endif /* EFI_BOOTLOADER */
226}
EngineState engineState
Definition engine.h:344
static EngineAccessor engine
Definition engine.h:413
int hackHellenBoardId(int detectedId)
int detectHellenBoardId()

Referenced by detectBoardType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableHellenSpi1()

static void enableHellenSpi1 ( )
static

Definition at line 38 of file hellen_logic.h.

38 {
39 engineConfiguration->spi1mosiPin = Gpio::H_SPI1_MOSI;
40 engineConfiguration->spi1misoPin = Gpio::H_SPI1_MISO;
41 engineConfiguration->spi1sckPin = Gpio::H_SPI1_SCK;
42 engineConfiguration->is_enabled_spi_1 = true;
43}

Referenced by setHellenSdCardSpi1Hardware().

Here is the caller graph for this function:

◆ enableHellenSpi2()

static void enableHellenSpi2 ( )
static

Definition at line 80 of file hellen_logic.h.

80 {
81 engineConfiguration->is_enabled_spi_2 = true;
82 engineConfiguration->spi2mosiPin = H_SPI2_MOSI;
83 engineConfiguration->spi2misoPin = H_SPI2_MISO;
84 engineConfiguration->spi2sckPin = H_SPI2_SCK;
85}

Referenced by alphax_4kgdi_boardConfigOverrides(), alphax_gold_boardConfigOverrides(), and setHellenSdCardSpi2().

Here is the caller graph for this function:

◆ enableHellenSpi3()

static void enableHellenSpi3 ( )
static

Definition at line 51 of file hellen_logic.h.

51 {
52 engineConfiguration->spi3mosiPin = H_SPI3_MOSI;
53 engineConfiguration->spi3misoPin = H_SPI3_MISO;
54 engineConfiguration->spi3sckPin = H_SPI3_SCK;
55 engineConfiguration->is_enabled_spi_3 = true;
56}

Referenced by alphax_silver_boardConfigOverrides(), alphax_silver_revA_boardConfigOverrides(), hellen154hyundai_f7_boardConfigOverrides(), and setHellenSdCardSpi3NoCS().

Here is the caller graph for this function:

◆ getHellenBoardEnabled()

bool getHellenBoardEnabled ( )

Definition at line 63 of file hellen_common.cpp.

63 {
65}
bool getLogicValue() const
Definition efi_gpio.cpp:667
PUBLIC_API_WEAK bool isBoardWithPowerManagement()
static OutputPin megaEn

Referenced by boardEnableSendWidebandInfo(), boardSdCardEnable(), fansDisabledByBoardStatus(), sendCanVerbose(), and setHwQcMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenBoardStandBy()

void hellenBoardStandBy ( )

Definition at line 172 of file hellen_common.cpp.

172 {
173 // we need to turn 'megaEn' and pause for a bit to make sure that WBO is off and does not wake main firmware right away
175 // todo: 200ms is totally random what's the science for this sleep duration?
176 chThdSleepMilliseconds(200);
177}
void hellenDisableEn(const char *msg)

Referenced by onBoardStandBy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenDisableEn()

void hellenDisableEn ( const char msg = "")

Definition at line 118 of file hellen_common.cpp.

118 {
119#if (EFI_FILE_LOGGING || EFI_CONFIGURATION_STORAGE) && EFI_PROD_CODE
120 // un-mount before turning power off SD card
121 // wait up to 1 second for SD card to become unmounted
122 efiPrintf("Long poll for SD card unmount");
123 int timeout = 1000;
125#if EFI_CONFIGURATION_STORAGE
126 // safe to call, even board does not have EXT FLASH
128#endif // EFI_CONFIGURATION_STORAGE
129 do {
130 chThdSleepMilliseconds(10);
132 break;
133 }
134 timeout -= 10;
135 } while (timeout > 0);
136#if EFI_CONFIGURATION_STORAGE
137 while (storageIsStorageRegistered(STORAGE_MFS_EXT_FLASH) && timeout > 0) {
138 chThdSleepMilliseconds(10);
139 timeout -= 10;
140 }
141#endif // EFI_CONFIGURATION_STORAGE
142#endif
143 efiPrintf("Turning board off [%s]", msg);
145}
void hellenDisableEnSilently()
void sdCardRequestMode(SD_MODE mode)
SD_MODE sdCardGetCurrentMode(void)
@ SD_MODE_UNMOUNT
Definition mmc_card.h:20
@ SD_MODE_IDLE
Definition mmc_card.h:17
bool storageIsStorageRegistered(StorageType type)
Definition storage.cpp:230
bool storagRequestUnregisterStorage(StorageType id)
Definition storage.cpp:243
@ STORAGE_MFS_EXT_FLASH
Definition storage.h:40

Referenced by configureRusefiLuaHooks(), and hellenBoardStandBy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenDisableEnSilently()

void hellenDisableEnSilently ( )

Definition at line 147 of file hellen_common.cpp.

147 {
148 // this function is called from criticalShutdown() that may be called from hardFault handler
149 // please no call to OS functions!
151}
static void setHellenEnValue(int value)

Referenced by hellenDisableEn(), and turnAllPinsOff().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenEnableEn()

void hellenEnableEn ( const char msg = "")

Definition at line 109 of file hellen_common.cpp.

109 {
110 efiPrintf("Turning board ON [%s]", msg);
112#if EFI_STORAGE_MFS
113 chThdSleepMilliseconds(1);
115#endif
116}
bool storagRequestRegisterStorage(StorageType id)
Definition storage.cpp:238

Referenced by boardSdCardEnable(), configureRusefiLuaHooks(), setHellenEnPin(), and setHwQcMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenMegaAccelerometerPreInitCS2Pin()

void hellenMegaAccelerometerPreInitCS2Pin ( )

Definition at line 201 of file hellen_common.cpp.

201 {
202#if EFI_ONBOARD_MEMS
204 accelerometerChipSelect.initPin("mm-CS2", Gpio::H_SPI1_CS2);
206 }
207#else
208 criticalError("probably broken MEMS configuration?");
209#endif // EFI_ONBOARD_MEMS
210}
bool isInitialized() const
Definition efi_gpio.cpp:559
OutputPin accelerometerChipSelect

Referenced by hellenMegaSdWithAccelerometer(), and setMegaUaefiBoardConfigOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenMegaModule()

void hellenMegaModule ( )

Definition at line 195 of file hellen_common.cpp.

195 {
199}
void hellenMegaSdWithAccelerometer()
void setHellenVbatt()
void setDefaultHellenAtPullUps(float pullup=HELLEN_DEFAULT_AT_PULLUP)

Referenced by alphax_8chan_boardConfigOverrides(), alphax_silver_boardConfigOverrides(), alphax_silver_revA_boardConfigOverrides(), hellen154hyundai_f7_boardConfigOverrides(), and hellen_honda_k_boardConfigOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenMegaSdWithAccelerometer()

void hellenMegaSdWithAccelerometer ( )

Definition at line 189 of file hellen_common.cpp.

189 {
191 // weird order of operations? i guess it does not really matter
193}
void hellenMegaAccelerometerPreInitCS2Pin()
static void setHellenSdCardSpi1Hardware()

Referenced by alphax_2chan_ConfigOverrides(), alphax_4chan_ConfigOverrides(), alphax_4kgdi_boardConfigOverrides(), alphax_gold_boardConfigOverrides(), hellen112_17_boardConfigOverrides(), hellenMegaModule(), super_uaefi_boardConfigOverrides(), and uaefi_boardConfigOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hellenWbo()

void hellenWbo ( )

◆ isBoardWithPowerManagement()

bool isBoardWithPowerManagement ( )

Definition at line 59 of file hellen_common.cpp.

59 {
60 return false;
61}

Referenced by FuelLevelFunc::convert(), and getHellenBoardEnabled().

Here is the caller graph for this function:

◆ setAccelerometerSpi()

static void setAccelerometerSpi ( )
static

Definition at line 64 of file hellen_logic.h.

64 {
65 /* accelerometer SPI is shared with SD card SPI on mm144 */
66 engineConfiguration->accelerometerSpiDevice = SPI_DEVICE_1;
67 engineConfiguration->accelerometerCsPin = Gpio::H_SPI1_CS2;
68}

Referenced by alphax_4chan_defaultConfiguration(), and hellen_honda_k_boardDefaultConfiguration().

Here is the caller graph for this function:

◆ setDefaultHellenAtPullUps()

void setDefaultHellenAtPullUps ( float  pullup = HELLEN_DEFAULT_AT_PULLUP)
inline

◆ setHellen64Can()

void setHellen64Can ( )

Definition at line 51 of file hellen_common.cpp.

51 {
52 engineConfiguration->canTxPin = Gpio::B9;
53 engineConfiguration->canRxPin = Gpio::B8;
54}

Referenced by small_can_board_boardConfigOverrides().

Here is the caller graph for this function:

◆ setHellen64MegaEnPin()

void setHellen64MegaEnPin ( )

Definition at line 168 of file hellen_common.cpp.

168 {
169 setHellenEnPin(Gpio::MM64_GP1); // OUT_PWR_EN
170}
void setHellenEnPin(Gpio pin, bool enableBoardOnStartUp)

Referenced by small_can_board_boardConfigOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHellen64SdCardSpi()

static void setHellen64SdCardSpi ( )
static

Definition at line 70 of file hellen_logic.h.

70 {
71 engineConfiguration->isSdCardEnabled = true;
72 engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
73 engineConfiguration->spi3mosiPin = Gpio::MM64_SPI3_MOSI;
74 engineConfiguration->spi3misoPin = Gpio::MM64_SPI3_MISO;
75 engineConfiguration->spi3sckPin = Gpio::MM64_SPI3_SCK;
76 engineConfiguration->is_enabled_spi_3 = true;
77 engineConfiguration->sdCardCsPin = Gpio::MM64_SPI3_CS;
78}

Referenced by small_can_board_boardConfigOverrides().

Here is the caller graph for this function:

◆ setHellenAnalogDividers()

void setHellenAnalogDividers ( )

Definition at line 33 of file hellen_common.cpp.

33 {
34 // 4.7k high side/4.7k low side = 2.0 ratio divider
35 engineConfiguration->analogInputDividerCoefficient = 2.0f;
36
37 // set vbatt_divider 5.835
38 // 33k / 6.8k
39 engineConfiguration->vbattDividerCoeff = (33 + 6.8) / 6.8; // 5.835
40 engineConfiguration->adcVcc = 3.3f;
41}

Referenced by setHellenVbatt(), and small_can_board_boardConfigOverrides().

Here is the caller graph for this function:

◆ setHellenCan()

void setHellenCan ( )

◆ setHellenCan2()

void setHellenCan2 ( )

Definition at line 18 of file hellen_common.cpp.

18 {
19 engineConfiguration->can2RxPin = Gpio::B12;
20 engineConfiguration->can2TxPin = Gpio::B13;
21}

Referenced by alphax_8chan_boardConfigOverrides(), alphax_8chan_reva_boardConfigOverrides(), uaefi_boardDefaultConfiguration(), and validateBoardConfig().

Here is the caller graph for this function:

◆ setHellenEnPin()

void setHellenEnPin ( Gpio  pin,
bool  enableBoardOnStartUp = true 
)

Definition at line 153 of file hellen_common.cpp.

153 {
156 megaEn.initPin("EN", pin);
157 if (enableBoardOnStartUp) {
158 hellenEnableEn("start-up");
159 }
160 }
161}
void hellenEnableEn(const char *msg)
static bool hellenEnPinInitialized
brain_pin_e pin
Definition stm32_adc.cpp:15

Referenced by alphax_2chan_ConfigOverrides(), alphax_4chan_ConfigOverrides(), alphax_8chan_boardInitHardware(), alphax_8chan_reva_boardInitHardware(), setHellen64MegaEnPin(), and setHellenMegaEnPin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHellenMegaEnPin()

void setHellenMegaEnPin ( bool  enableBoardOnStartUp = true)

◆ setHellenMMbaro()

void setHellenMMbaro ( )
inline

◆ setHellenSdCardSpi1Hardware()

static void setHellenSdCardSpi1Hardware ( )
static

Definition at line 45 of file hellen_logic.h.

45 {
46 engineConfiguration->sdCardCsPin = Gpio::H_SPI1_CS1;
47 engineConfiguration->sdCardSpiDevice = SPI_DEVICE_1;
49}
static void enableHellenSpi1()

Referenced by hellenMegaSdWithAccelerometer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHellenSdCardSpi2()

void setHellenSdCardSpi2 ( )
inline

◆ setHellenSdCardSpi3()

void setHellenSdCardSpi3 ( )
inline

Definition at line 93 of file hellen_logic.h.

93 {
95 engineConfiguration->sdCardCsPin = H_SPI3_CS;
96}
static void setHellenSdCardSpi3NoCS()

Referenced by hellen121_nissan_boardConfigOverrides(), hellen121_vag_boardConfigOverrides(), hellen81_boardConfigOverrides(), hellen88_boardConfigOverrides(), and hellen_MiataNB2_boardConfigOverrides().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHellenSdCardSpi3NoCS()

static void setHellenSdCardSpi3NoCS ( )
static

Definition at line 58 of file hellen_logic.h.

58 {
59 engineConfiguration->isSdCardEnabled = true;
60 engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
62}
static void enableHellenSpi3()

Referenced by setHellenSdCardSpi3().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHellenVbatt()

void setHellenVbatt ( )

Go to the source code of this file.