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 311 of file hardware.cpp.

311 {
312 /**
313 * All 'stop' methods need to go before we begin starting pins.
314 *
315 * We take settings from 'activeConfiguration' not 'engineConfiguration' while stopping hardware.
316 * Some hardware is restart unconditionally on change of parameters while for some systems we make extra effort and restart only
317 * relevant settings were changes.
318 *
319 */
321
322#if EFI_PROD_CODE
323 stopSensors();
324#endif // EFI_PROD_CODE
325
326#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
328#endif /* EFI_SHAFT_POSITION_INPUT */
329
330#if EFI_PROD_CODE && EFI_SENT_SUPPORT
331 stopSent();
332#endif // EFI_SENT_SUPPORT
333
334#if EFI_CAN_SUPPORT
335 stopCanPins();
336#endif /* EFI_CAN_SUPPORT */
337
338 stopKLine();
339
340
341 stopHardware();
342
343#if HAL_USE_SPI
345#endif /* HAL_USE_SPI */
346
347 if (isPinOrModeChanged(clutchUpPin, clutchUpPinMode)) {
348 // bug? duplication with stopSwitchPins?
350 }
351
353
354#if EFI_PROD_CODE
356#endif /* EFI_PROD_CODE */
357
359
360 /*******************************************
361 * Start everything back with new settings *
362 ******************************************/
364
365#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
366 /* TODO: properly restart gpio chips...
367 * This is only workaround for "CS pin lost" bug
368 * see: https://github.com/rusefi/rusefi/issues/2107
369 * We should provide better way to gracefully stop all
370 * gpio chips: set outputs to safe state, release all
371 * on-chip resources (gpios, SPIs, etc) and then restart
372 * with updated settings.
373 * Following code just re-inits CS pins for all external
374 * gpio chips, but does not update CS pin definition in
375 * gpio chips private data/settings. So changing CS pin
376 * on-fly does not work */
378#endif /* (BOARD_EXT_GPIOCHIPS > 0) */
379
380 startKLine();
381
382#if EFI_PROD_CODE && EFI_IDLE_CONTROL
385 }
386#endif
387
388#if EFI_BOOST_CONTROL
390#endif
391#if EFI_EMULATE_POSITION_SENSORS
393#endif /* EFI_EMULATE_POSITION_SENSORS */
394#if EFI_LOGIC_ANALYZER
396#endif /* EFI_LOGIC_ANALYZER */
397#if EFI_VVT_PID
399#endif /* EFI_VVT_PID */
400
401#if EFI_PROD_CODE && EFI_SENT_SUPPORT
402 startSent();
403#endif
404
406}
void startBoostPin()
void stopCanPins()
Definition can_hw.cpp:114
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:296
void stopHardware()
Definition hardware.cpp:478
void startHardware()
Definition hardware.cpp:503
static void stopSpiModules()
Definition hardware.cpp:230
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:180

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 86 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 106 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 126 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 149 of file hardware.cpp.

149 {
150 if (spiDevice == SPI_NONE) {
151 return nullptr;
152 }
153#if STM32_SPI_USE_SPI1
154 if (spiDevice == SPI_DEVICE_1) {
155 return &SPID1;
156 }
157#endif
158#if STM32_SPI_USE_SPI2
159 if (spiDevice == SPI_DEVICE_2) {
160 return &SPID2;
161 }
162#endif
163#if STM32_SPI_USE_SPI3
164 if (spiDevice == SPI_DEVICE_3) {
165 return &SPID3;
166 }
167#endif
168#if STM32_SPI_USE_SPI4
169 if (spiDevice == SPI_DEVICE_4) {
170 return &SPID4;
171 }
172#endif
173#if STM32_SPI_USE_SPI5
174 if (spiDevice == SPI_DEVICE_5) {
175 return &SPID5;
176 }
177#endif
178#if STM32_SPI_USE_SPI6
179 if (spiDevice == SPI_DEVICE_6) {
180 return &SPID6;
181 }
182#endif
183 firmwareError(ObdCode::CUSTOM_ERR_UNEXPECTED_SPI, "Unexpected SPI device: %d", spiDevice);
184 return nullptr;
185}
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 538 of file hardware.cpp.

538 {
539 if (hasFirmwareError()) {
540 return;
541 }
542
543#if EFI_PROD_CODE && STM32_I2C_USE_I2C3
545 i2cStart(&EE_U2CD, &i2cfg);
546 }
547#endif // STM32_I2C_USE_I2C3
548
551#if EFI_PROD_CODE
552 // this applies some board configurations
554#endif // EFI_PROD_CODE
557
558#if HAL_USE_ADC
560#endif /* HAL_USE_ADC */
561
562#if EFI_SOFTWARE_KNOCK
564#endif /* EFI_SOFTWARE_KNOCK */
565
566#ifdef TRIGGER_SCOPE
568#endif // TRIGGER_SCOPE
569
570#if HAL_USE_SPI
572#endif /* HAL_USE_SPI */
573
574#if (EFI_PROD_CODE && BOARD_EXT_GPIOCHIPS > 0) || EFI_SIMULATOR
575 // initSmartGpio depends on 'initSpiModules'
577#endif
578
579 // output pins potentially depend on 'initSmartGpio'
581
582#if EFI_MC33816
583 initMc33816();
584#endif /* EFI_MC33816 */
585
586#if EFI_CAN_SUPPORT
587#if EFI_SIMULATOR
588 // Set CAN device name
589 CAND1.deviceName = "can0";
590#endif
591
592 initCan();
593#endif /* EFI_CAN_SUPPORT */
594
595
596#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
598#endif /* EFI_SHAFT_POSITION_INPUT */
600
601#if EFI_WS2812
602 initWS2812();
603#endif /* EFI_LED_WS2812 */
604
605#if EFI_ONBOARD_MEMS
607#endif
608
609#if EFI_BOSCH_YAW
611#endif /* EFI_BOSCH_YAW */
612
613#if EFI_UART_GPS
614 initGps();
615#endif
616
617#if EFI_CAN_SUPPORT
619#endif // EFI_CAN_SUPPORT
620
621#if EFI_CDM_INTEGRATION
622 cdmIonInit();
623#endif // EFI_CDM_INTEGRATION
624
625#if EFI_PROD_CODE && EFI_SENT_SUPPORT
626 initSent();
627#endif
628
629 initKLine();
630
631#if EFI_DAC
632 initDac();
633#endif
634
636
638
639 efiPrintf("initHardware() OK!");
640}
void initWS2812()
Definition WS2812.cpp:21
void initAccelerometer()
void initAdcInputs()
static bool call_board_override(std::optional< setup_custom_board_overrides_type > board_override)
void initCan()
Definition can_hw.cpp:166
void initCanVssSupport()
Definition can_vss.cpp:199
void cdmIonInit(void)
void initDac()
Definition dac.cpp:42
void initMiscOutputPins()
Definition efi_gpio.cpp:690
void initGps(void)
Definition gps_uart.cpp:102
void boardInitHardwareExtra()
Definition hardware.cpp:422
std::optional< setup_custom_board_overrides_type > custom_board_InitHardware
Definition hardware.cpp:77
static void initSpiModules()
Definition hardware.cpp:199
const I2CConfig i2cfg
Definition hardware.cpp:531
std::optional< setup_custom_board_overrides_type > custom_board_InitHardwareExtra
Definition hardware.cpp:78
void boardInitHardware()
Definition hardware.cpp:419
void boardOnConfigurationChange(engine_configuration_s *)
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 427 of file hardware.cpp.

427 {
428 efiAssertVoid(ObdCode::CUSTOM_IH_STACK, hasLotsOfRemainingStack(), "init h");
429
430 efiPrintf("initHardware()");
431
432#if EFI_PROD_CODE
434#endif
435
436#if EFI_PROD_CODE
439#endif
440
441#if EFI_HISTOGRAMS
442 /**
443 * histograms is a data structure for CPU monitor, it does not depend on configuration
444 */
446#endif /* EFI_HISTOGRAMS */
447
448#if EFI_GPIO_HARDWARE
449 /**
450 * We need the LED_ERROR pin even before we read configuration
451 */
453#endif // EFI_GPIO_HARDWARE
454
455#if EFI_PROD_CODE && EFI_SIGNAL_EXECUTOR_ONE_TIMER
456 // it's important to initialize this pretty early in the game before any scheduling usages
458#endif // EFI_PROD_CODE && EFI_SIGNAL_EXECUTOR_ONE_TIMER
459
460#if EFI_PROD_CODE && EFI_RTC
461 initRtc();
462#endif // EFI_PROD_CODE && EFI_RTC
463
464#if EFI_CONFIGURATION_STORAGE
465 initFlash();
466#endif
467
468#if EFI_FILE_LOGGING
470#endif // EFI_FILE_LOGGING
471
472#if HAL_USE_PAL && EFI_PROD_CODE
473 // this should be initialized before detectBoardType()
474 efiExtiInit();
475#endif // HAL_USE_PAL
476}
void efiExtiInit()
void initPrimaryPins()
Definition efi_gpio.cpp:842
void initFlash()
void boardInitHardwareEarly()
Definition hardware.cpp:416
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 190 of file hardware.cpp.

190 {
191 efiAssertVoid(ObdCode::CUSTOM_STACK_SPI, hasLotsOfRemainingStack(), "lockSpi");
192 spiAcquireBus(getSpiDevice(device));
193}
SPIDriver * getSpiDevice(spi_device_e spiDevice)
Definition hardware.cpp:149
@ 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 275 of file hardware.cpp.

275 {
277
278#if HAL_TRIGGER_USE_ADC
279 // we need to call this ASAP, because trigger processing is time-critical
281#endif /* HAL_TRIGGER_USE_ADC */
282
283 /**
284 * this callback is executed 10 000 times a second, it needs to be as fast as possible
285 */
286 efiAssertVoid(ObdCode::CUSTOM_STACK_ADC, hasLotsOfRemainingStack(), "lowstck#9b");
287
288 auto mapRaw = adcRawValueToScaledVoltage(getFastAdc(fastMapSampleIndex), engineConfiguration->map.sensor.hwChannel);
290#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
292#endif /* EFI_MAP_AVERAGING */
293}
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:269
static AdcToken fastMapSampleIndex
Definition hardware.cpp:266
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 256 of file hardware.cpp.

256 {
257 efiPrintf("%s %s mosi=%s", msg, getSpi_device_e(device), hwPortname(getMosiPin(device)));
258 efiPrintf("%s %s miso=%s", msg, getSpi_device_e(device), hwPortname(getMisoPin(device)));
259 efiPrintf("%s %s sck=%s", msg, getSpi_device_e(device), hwPortname(getSckPin(device)));
260}
const char * getSpi_device_e(spi_device_e value)
brain_pin_e getSckPin(spi_device_e device)
Definition hardware.cpp:126
brain_pin_e getMosiPin(spi_device_e device)
Definition hardware.cpp:106
brain_pin_e getMisoPin(spi_device_e device)
Definition hardware.cpp:86
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 409 of file hardware.cpp.

409 {
410 efiPrintf("setting BOR to %d", borValue);
411 BOR_Set((BOR_Level_t)borValue);
412}
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 503 of file hardware.cpp.

503 {
504#if EFI_SHAFT_POSITION_INPUT
506#endif
507
508#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
510#endif /* EFI_SHAFT_POSITION_INPUT */
511
512#if EFI_ENGINE_CONTROL
514#endif /* EFI_ENGINE_CONTROL */
515
516#if EFI_SHAFT_POSITION_INPUT
518
519#endif // EFI_SHAFT_POSITION_INPUT
520
522
523#if EFI_CAN_SUPPORT
524 startCanPins();
525#endif /* EFI_CAN_SUPPORT */
526}
void startCanPins()
Definition can_hw.cpp:122
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 478 of file hardware.cpp.

478 {
480
481#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
483#endif /* (BOARD_EXT_GPIOCHIPS > 0) */
484
485#if EFI_LOGIC_ANALYZER
487#endif /* EFI_LOGIC_ANALYZER */
488
489#if EFI_EMULATE_POSITION_SENSORS
491#endif /* EFI_EMULATE_POSITION_SENSORS */
492
493#if EFI_VVT_PID
495#endif /* EFI_VVT_PID */
496}
void stopSwitchPins()
void stopLogicAnalyzerPins()
void stopSmartCsPins()
void stopTriggerEmulatorPins()
void stopVvtControlPins()
Definition vvt.cpp:186

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 195 of file hardware.cpp.

195 {
196 spiReleaseBus(getSpiDevice(device));
197}

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.