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

Functions

void startHardware ()
 
void stopHardware ()
 
SPIDriver * getSpiDevice (spi_device_e spiDevice)
 
void turnOnSpi (spi_device_e device)
 
void lockSpi (spi_device_e device)
 
void unlockSpi (spi_device_e device)
 
brain_pin_e getMisoPin (spi_device_e device)
 
brain_pin_e getMosiPin (spi_device_e device)
 
brain_pin_e getSckPin (spi_device_e device)
 
void printSpiConfig (const char *msg, spi_device_e device)
 
void onFastAdcComplete (adcsample_t *)
 
void applyNewHardwareSettings ()
 
void initHardwareNoConfig ()
 
void initHardware ()
 
void setBor (int borValue)
 

Function Documentation

◆ applyNewHardwareSettings()

void applyNewHardwareSettings ( )

this method is NOT currently invoked on ECU start todo: reduce code duplication by moving more logic into startHardware method

All 'stop' methods need to go before we begin starting pins.

We take settings from 'activeConfiguration' not 'engineConfiguration' while stopping hardware. Some hardware is restart unconditionally on change of parameters while for some systems we make extra effort and restart only relevant settings were changes.

Definition at line 314 of file hardware.cpp.

314 {
315 /**
316 * All 'stop' methods need to go before we begin starting pins.
317 *
318 * We take settings from 'activeConfiguration' not 'engineConfiguration' while stopping hardware.
319 * Some hardware is restart unconditionally on change of parameters while for some systems we make extra effort and restart only
320 * relevant settings were changes.
321 *
322 */
324
325#if EFI_PROD_CODE
326 stopSensors();
327#endif // EFI_PROD_CODE
328
329#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
331#endif /* EFI_SHAFT_POSITION_INPUT */
332
333#if EFI_PROD_CODE && EFI_SENT_SUPPORT
334 stopSent();
335#endif // EFI_SENT_SUPPORT
336
337#if EFI_CAN_SUPPORT
338 stopCanPins();
339#endif /* EFI_CAN_SUPPORT */
340
341 stopKLine();
342
343
344 stopHardware();
345
346#if HAL_USE_SPI
348#endif /* HAL_USE_SPI */
349
350 if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) {
351 // bug? duplication with stopSwitchPins?
353 }
354
356
357#if EFI_PROD_CODE
359#endif /* EFI_PROD_CODE */
360
362
363 /*******************************************
364 * Start everything back with new settings *
365 ******************************************/
367
368#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
369 /* TODO: properly restart gpio chips...
370 * This is only workaround for "CS pin lost" bug
371 * see: https://github.com/rusefi/rusefi/issues/2107
372 * We should provide better way to gracefully stop all
373 * gpio chips: set outputs to safe state, release all
374 * on-chip resources (gpios, SPIs, etc) and then restart
375 * with updated settings.
376 * Following code just re-inits CS pins for all external
377 * gpio chips, but does not update CS pin definition in
378 * gpio chips private data/settings. So changing CS pin
379 * on-fly does not work */
381#endif /* (BOARD_EXT_GPIOCHIPS > 0) */
382
383 startKLine();
384
385#if EFI_PROD_CODE && EFI_IDLE_CONTROL
388 }
389#endif
390
391#if EFI_BOOST_CONTROL
393#endif
394#if EFI_EMULATE_POSITION_SENSORS
396#endif /* EFI_EMULATE_POSITION_SENSORS */
397#if EFI_LOGIC_ANALYZER
399#endif /* EFI_LOGIC_ANALYZER */
400#if EFI_VVT_PID
402#endif /* EFI_VVT_PID */
403
404#if EFI_PROD_CODE && EFI_SENT_SUPPORT
405 startSent();
406#endif
407
409}
void startBoostPin()
void stopCanPins()
Definition can_hw.cpp:123
static void startConfigurationList()
Definition debounce.cpp:49
static void stopConfigurationList()
Definition debounce.cpp:39
void unregisterPins()
Definition efi_gpio.cpp:228
EnginePins enginePins
Definition efi_gpio.cpp:24
engine_configuration_s & activeConfiguration
static void calcFastAdcIndexes()
Definition hardware.cpp:299
void stopHardware()
Definition hardware.cpp:480
void startHardware()
Definition hardware.cpp:505
static void stopSpiModules()
Definition hardware.cpp:233
bool isIdleHardwareRestartNeeded()
void initIdleHardware()
void reconfigureSensors()
void stopSensors()
void efiSetPadUnused(brain_pin_e brainPin)
Definition io_pins.cpp:20
void stopKLine()
Definition kline.cpp:184
void startKLine()
Definition kline.cpp:157
void startLogicAnalyzerPins()
void stopSent()
void startSent()
void startSmartCsPins()
void startTriggerEmulatorPins()
void stopTriggerInputPins()
void startVvtControlPins()
Definition vvt.cpp:178

Referenced by incrementGlobalConfigurationVersion().

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

◆ getMisoPin()

brain_pin_e getMisoPin ( spi_device_e  device)

Definition at line 89 of file hardware.cpp.

Referenced by printSpiConfig(), stopSpi(), and turnOnSpi().

Here is the caller graph for this function:

◆ getMosiPin()

brain_pin_e getMosiPin ( spi_device_e  device)

Definition at line 109 of file hardware.cpp.

Referenced by printSpiConfig(), stopSpi(), and turnOnSpi().

Here is the caller graph for this function:

◆ getSckPin()

brain_pin_e getSckPin ( spi_device_e  device)

Definition at line 129 of file hardware.cpp.

Referenced by printSpiConfig(), stopSpi(), and turnOnSpi().

Here is the caller graph for this function:

◆ getSpiDevice()

SPIDriver * getSpiDevice ( spi_device_e  spiDevice)
Returns
NULL if SPI device not specified

Definition at line 152 of file hardware.cpp.

152 {
153 if (spiDevice == SPI_NONE) {
154 return nullptr;
155 }
156#if STM32_SPI_USE_SPI1
157 if (spiDevice == SPI_DEVICE_1) {
158 return &SPID1;
159 }
160#endif
161#if STM32_SPI_USE_SPI2
162 if (spiDevice == SPI_DEVICE_2) {
163 return &SPID2;
164 }
165#endif
166#if STM32_SPI_USE_SPI3
167 if (spiDevice == SPI_DEVICE_3) {
168 return &SPID3;
169 }
170#endif
171#if STM32_SPI_USE_SPI4
172 if (spiDevice == SPI_DEVICE_4) {
173 return &SPID4;
174 }
175#endif
176#if STM32_SPI_USE_SPI5
177 if (spiDevice == SPI_DEVICE_5) {
178 return &SPID5;
179 }
180#endif
181#if STM32_SPI_USE_SPI6
182 if (spiDevice == SPI_DEVICE_6) {
183 return &SPID6;
184 }
185#endif
186 firmwareError(ObdCode::CUSTOM_ERR_UNEXPECTED_SPI, "Unexpected SPI device: %d", spiDevice);
187 return nullptr;
188}
void firmwareError(ObdCode code, const char *fmt,...)
SPIDriver SPID1
SPI0 driver identifier.
Definition hal_spi_lld.c:42
SPIDriver SPID2
SPI1 driver identifier.
Definition hal_spi_lld.c:47
@ CUSTOM_ERR_UNEXPECTED_SPI

Referenced by initAccelerometer(), initializeMmcBlockDevice(), initPotentiometers(), initSmartGpio(), lockSpi(), nm_bus_init(), and unlockSpi().

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

◆ initHardware()

void initHardware ( )

Definition at line 540 of file hardware.cpp.

540 {
541 if (hasFirmwareError()) {
542 return;
543 }
544
545#if EFI_PROD_CODE && STM32_I2C_USE_I2C3
547 i2cStart(&EE_U2CD, &i2cfg);
548 }
549#endif // STM32_I2C_USE_I2C3
550
552#if EFI_PROD_CODE
553 // this applies some board configurations
555#endif // EFI_PROD_CODE
556
558
559#if HAL_USE_ADC
561#endif /* HAL_USE_ADC */
562
563#if EFI_SOFTWARE_KNOCK
565#endif /* EFI_SOFTWARE_KNOCK */
566
567#ifdef TRIGGER_SCOPE
569#endif // TRIGGER_SCOPE
570
571#if HAL_USE_SPI
573#endif /* HAL_USE_SPI */
574
575#if (EFI_PROD_CODE && BOARD_EXT_GPIOCHIPS > 0) || EFI_SIMULATOR
576 // initSmartGpio depends on 'initSpiModules'
578#endif
579
580 // output pins potentially depend on 'initSmartGpio'
582
583#if EFI_MC33816
584 initMc33816();
585#endif /* EFI_MC33816 */
586
587#if EFI_CAN_SUPPORT
588#if EFI_SIMULATOR
589 // Set CAN device name
590 CAND1.deviceName = "can0";
591#endif
592
593 initCan();
594#endif /* EFI_CAN_SUPPORT */
595
596
597#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
599#endif /* EFI_SHAFT_POSITION_INPUT */
601
602#if EFI_WS2812
603 initWS2812();
604#endif /* EFI_LED_WS2812 */
605
606#if EFI_ONBOARD_MEMS
608#endif
609
610#if EFI_BOSCH_YAW
612#endif /* EFI_BOSCH_YAW */
613
614#if EFI_UART_GPS
615 initGps();
616#endif
617
618#if EFI_CAN_SUPPORT
620#endif // EFI_CAN_SUPPORT
621
622#if EFI_CDM_INTEGRATION
623 cdmIonInit();
624#endif // EFI_CDM_INTEGRATION
625
626#if EFI_PROD_CODE && EFI_SENT_SUPPORT
627 initSent();
628#endif
629
630 initKLine();
631
632#if EFI_DAC
633 initDac();
634#endif
635
637
639
640 efiPrintf("initHardware() OK!");
641}
void initWS2812()
Definition WS2812.cpp:21
void initAccelerometer()
void initAdcInputs()
static bool call_board_override(std::optional< FuncType > board_override, Args &&... args)
void initCan()
Definition can_hw.cpp:189
void initCanVssSupport()
Definition can_vss.cpp:199
void cdmIonInit(void)
void initDac()
Definition dac.cpp:42
void initMiscOutputPins()
Definition efi_gpio.cpp:690
std::optional< setup_custom_board_config_type > custom_board_OnConfigurationChange
void initGps(void)
Definition gps_uart.cpp:102
std::optional< setup_custom_board_overrides_type > custom_board_InitHardware
Definition hardware.cpp:77
static void initSpiModules()
Definition hardware.cpp:202
const I2CConfig i2cfg
Definition hardware.cpp:533
std::optional< setup_custom_board_overrides_type > custom_board_InitHardwareExtra
Definition hardware.cpp:78
void initKLine()
Definition kline.cpp:198
void initMc33816()
Definition mc33816.cpp:280
void initSent(void)
Definition sent.cpp:167
void initSmartGpio()
void initSoftwareKnock()
void onEcuStartTriggerImplementation()
void onEcuStartDoSomethingTriggerInputPins()
void initTriggerScope()
void initBoschYawRateSensor()

Referenced by commonEarlyInit().

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

◆ initHardwareNoConfig()

void initHardwareNoConfig ( )

histograms is a data structure for CPU monitor, it does not depend on configuration

We need the LED_ERROR pin even before we read configuration

Definition at line 430 of file hardware.cpp.

430 {
431 efiAssertVoid(ObdCode::CUSTOM_IH_STACK, hasLotsOfRemainingStack(), "init h");
432
433 efiPrintf("initHardware()");
434
435#if EFI_PROD_CODE
437#endif
438
439#if EFI_PROD_CODE
441#endif
442
443#if EFI_HISTOGRAMS
444 /**
445 * histograms is a data structure for CPU monitor, it does not depend on configuration
446 */
448#endif /* EFI_HISTOGRAMS */
449
450#if EFI_GPIO_HARDWARE
451 /**
452 * We need the LED_ERROR pin even before we read configuration
453 */
455#endif // EFI_GPIO_HARDWARE
456
457#if EFI_PROD_CODE && EFI_SIGNAL_EXECUTOR_ONE_TIMER
458 // it's important to initialize this pretty early in the game before any scheduling usages
460#endif // EFI_PROD_CODE && EFI_SIGNAL_EXECUTOR_ONE_TIMER
461
462#if EFI_PROD_CODE && EFI_RTC
463 initRtc();
464#endif // EFI_PROD_CODE && EFI_RTC
465
466#if EFI_CONFIGURATION_STORAGE
467 initFlash();
468#endif
469
470#if EFI_FILE_LOGGING
472#endif // EFI_FILE_LOGGING
473
474#if HAL_USE_PAL && EFI_PROD_CODE
475 // this should be initialized before detectBoardType()
476 efiExtiInit();
477#endif // HAL_USE_PAL
478}
void efiExtiInit()
void initPrimaryPins()
Definition efi_gpio.cpp:842
void initFlash()
std::optional< setup_custom_board_overrides_type > custom_board_InitHardwareEarly
Definition hardware.cpp:76
void initHistogramsModule(void)
Definition histogram.cpp:44
void initEarlyMmcCard()
@ CUSTOM_IH_STACK
void initPinRepository(void)
void initRtc()
void initSingleTimerExecutorHardware()

Referenced by runRusEfi().

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

◆ lockSpi()

void lockSpi ( spi_device_e  device)

Only one consumer can use SPI bus at a given time

Definition at line 193 of file hardware.cpp.

193 {
194 efiAssertVoid(ObdCode::CUSTOM_STACK_SPI, hasLotsOfRemainingStack(), "lockSpi");
195 spiAcquireBus(getSpiDevice(device));
196}
SPIDriver * getSpiDevice(spi_device_e spiDevice)
Definition hardware.cpp:152
@ CUSTOM_STACK_SPI

Referenced by sendToPot().

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

◆ onFastAdcComplete()

void onFastAdcComplete ( adcsample_t )

This method is not in the adc* lower-level file because it is more business logic then hardware.

this callback is executed 10 000 times a second, it needs to be as fast as possible

Definition at line 278 of file hardware.cpp.

278 {
280
281#if HAL_TRIGGER_USE_ADC
282 // we need to call this ASAP, because trigger processing is time-critical
284#endif /* HAL_TRIGGER_USE_ADC */
285
286 /**
287 * this callback is executed 10 000 times a second, it needs to be as fast as possible
288 */
289 efiAssertVoid(ObdCode::CUSTOM_STACK_ADC, hasLotsOfRemainingStack(), "lowstck#9b");
290
291 auto mapRaw = adcRawValueToScaledVoltage(getFastAdc(fastMapSampleIndex), engineConfiguration->map.sensor.hwChannel);
293#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
295#endif /* EFI_MAP_AVERAGING */
296}
adcsample_t getFastAdc(AdcToken token)
Definition mpu_util.cpp:288
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413
static AdcToken triggerSampleIndex
Definition hardware.cpp:272
static AdcToken fastMapSampleIndex
Definition hardware.cpp:269
void mapAveragingAdcCallback(float instantVoltage)
@ CUSTOM_STACK_ADC
@ AdcCallbackFast
scaled_channel< uint16_t, 1000, 1 > rawMapFast
void triggerAdcCallback(triggerAdcSample_t value)

Referenced by adc_callback(), and fastAdcDoneCB().

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

◆ printSpiConfig()

void printSpiConfig ( const char msg,
spi_device_e  device 
)

Definition at line 259 of file hardware.cpp.

259 {
260 efiPrintf("%s %s mosi=%s", msg, getSpi_device_e(device), hwPortname(getMosiPin(device)));
261 efiPrintf("%s %s miso=%s", msg, getSpi_device_e(device), hwPortname(getMisoPin(device)));
262 efiPrintf("%s %s sck=%s", msg, getSpi_device_e(device), hwPortname(getSckPin(device)));
263}
const char * getSpi_device_e(spi_device_e value)
brain_pin_e getSckPin(spi_device_e device)
Definition hardware.cpp:129
brain_pin_e getMosiPin(spi_device_e device)
Definition hardware.cpp:109
brain_pin_e getMisoPin(spi_device_e device)
Definition hardware.cpp:89
const char * hwPortname(brain_pin_e brainPin)

Referenced by sdStatistics().

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

◆ setBor()

void setBor ( int  borValue)

Definition at line 412 of file hardware.cpp.

412 {
413 efiPrintf("setting BOR to %d", borValue);
414 BOR_Set((BOR_Level_t)borValue);
415}
BOR_Result_t BOR_Set(BOR_Level_t BORValue)
BOR_Level_t
Here is the call graph for this function:

◆ startHardware()

void startHardware ( )

This method is invoked both on ECU start and configuration change At the moment we have too many system which handle ECU start and configuration change separately TODO: move move hardware code here

Definition at line 505 of file hardware.cpp.

505 {
506#if EFI_SHAFT_POSITION_INPUT
508#endif
509
510#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
512#endif /* EFI_SHAFT_POSITION_INPUT */
513
514#if EFI_ENGINE_CONTROL
516#endif /* EFI_ENGINE_CONTROL */
517
518#if EFI_SHAFT_POSITION_INPUT
520
521#endif // EFI_SHAFT_POSITION_INPUT
522
524
525#if EFI_CAN_SUPPORT
526 startCanPins();
527#endif /* EFI_CAN_SUPPORT */
528}
void startCanPins()
Definition can_hw.cpp:135
void startPins()
Definition efi_gpio.cpp:258
void initStartStopButton()
void startSwitchPins()
void validateTriggerInputs()
void startTriggerInputPins()

Referenced by applyNewHardwareSettings(), and initHardware().

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

◆ stopHardware()

void stopHardware ( )

Definition at line 480 of file hardware.cpp.

480 {
482
483#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
485#endif /* (BOARD_EXT_GPIOCHIPS > 0) */
486
487#if EFI_LOGIC_ANALYZER
489#endif /* EFI_LOGIC_ANALYZER */
490
491#if EFI_EMULATE_POSITION_SENSORS
493#endif /* EFI_EMULATE_POSITION_SENSORS */
494
495#if EFI_VVT_PID
497#endif /* EFI_VVT_PID */
498}
void stopSwitchPins()
void stopLogicAnalyzerPins()
void stopSmartCsPins()
void stopTriggerEmulatorPins()
void stopVvtControlPins()
Definition vvt.cpp:184

Referenced by applyNewHardwareSettings().

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

◆ turnOnSpi()

void turnOnSpi ( spi_device_e  device)

Definition at line 151 of file at32_spi.cpp.

151 {
153 return; // already initialized
154 isSpiInitialized[device] = true;
155 if (device == SPI_DEVICE_1) {
156// todo: introduce a nice structure with all fields for same SPI
157#if STM32_SPI_USE_SPI1
158// scheduleMsg(&logging, "Turning on SPI1 pins");
165#else
166 criticalError("SPI1 not available in this binary");
167#endif /* STM32_SPI_USE_SPI1 */
168 }
169 if (device == SPI_DEVICE_2) {
170#if STM32_SPI_USE_SPI2
171 //scheduleMsg(&logging, "Turning on SPI2 pins");
178#else
179 criticalError("SPI2 not available in this binary");
180#endif /* STM32_SPI_USE_SPI2 */
181 }
182 if (device == SPI_DEVICE_3) {
183#if STM32_SPI_USE_SPI3
184 //scheduleMsg(&logging, "Turning on SPI3 pins");
191#else
192 criticalError("SPI3 not available in this binary");
193#endif /* STM32_SPI_USE_SPI3 */
194 }
195 if (device == SPI_DEVICE_4) {
196#if STM32_SPI_USE_SPI4
197 //scheduleMsg(&logging, "Turning on SPI4 pins");
198 /* there are no configuration fields for SPI4 in engineConfiguration, rely on board init code
199 * it should set proper functions for SPI4 pins */
200#else
201 criticalError("SPI4 not available in this binary");
202#endif /* STM32_SPI_USE_SPI4 */
203 }
204}
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, int mosiMode, int misoMode)
Definition at32_spi.cpp:206
bool isSpiInitialized[SPI_TOTAL_COUNT+1]
Definition at32_spi.cpp:13

Referenced by initSpiModules().

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

◆ unlockSpi()

void unlockSpi ( spi_device_e  device)

Definition at line 198 of file hardware.cpp.

198 {
199 spiReleaseBus(getSpiDevice(device));
200}

Referenced by sendToPot().

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

Go to the source code of this file.