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: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:296
void stopHardware()
Definition hardware.cpp:477
void startHardware()
Definition hardware.cpp:502
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: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 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 537 of file hardware.cpp.

537 {
538 if (hasFirmwareError()) {
539 return;
540 }
541
542#if EFI_PROD_CODE && STM32_I2C_USE_I2C3
544 i2cStart(&EE_U2CD, &i2cfg);
545 }
546#endif // STM32_I2C_USE_I2C3
547
549#if EFI_PROD_CODE
550 // this applies some board configurations
552#endif // EFI_PROD_CODE
553
555
556#if HAL_USE_ADC
558#endif /* HAL_USE_ADC */
559
560#if EFI_SOFTWARE_KNOCK
562#endif /* EFI_SOFTWARE_KNOCK */
563
564#ifdef TRIGGER_SCOPE
566#endif // TRIGGER_SCOPE
567
568#if HAL_USE_SPI
570#endif /* HAL_USE_SPI */
571
572#if (EFI_PROD_CODE && BOARD_EXT_GPIOCHIPS > 0) || EFI_SIMULATOR
573 // initSmartGpio depends on 'initSpiModules'
575#endif
576
577 // output pins potentially depend on 'initSmartGpio'
579
580#if EFI_MC33816
581 initMc33816();
582#endif /* EFI_MC33816 */
583
584#if EFI_CAN_SUPPORT
585#if EFI_SIMULATOR
586 // Set CAN device name
587 CAND1.deviceName = "can0";
588#endif
589
590 initCan();
591#endif /* EFI_CAN_SUPPORT */
592
593
594#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
596#endif /* EFI_SHAFT_POSITION_INPUT */
598
599#if EFI_WS2812
600 initWS2812();
601#endif /* EFI_LED_WS2812 */
602
603#if EFI_ONBOARD_MEMS
605#endif
606
607#if EFI_BOSCH_YAW
609#endif /* EFI_BOSCH_YAW */
610
611#if EFI_UART_GPS
612 initGps();
613#endif
614
615#if EFI_CAN_SUPPORT
617#endif // EFI_CAN_SUPPORT
618
619#if EFI_CDM_INTEGRATION
620 cdmIonInit();
621#endif // EFI_CDM_INTEGRATION
622
623#if EFI_PROD_CODE && EFI_SENT_SUPPORT
624 initSent();
625#endif
626
627 initKLine();
628
629#if EFI_DAC
630 initDac();
631#endif
632
634
636
637 efiPrintf("initHardware() OK!");
638}
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
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:199
const I2CConfig i2cfg
Definition hardware.cpp:530
std::optional< setup_custom_board_overrides_type > custom_board_InitHardwareExtra
Definition hardware.cpp:78
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
438#endif
439
440#if EFI_HISTOGRAMS
441 /**
442 * histograms is a data structure for CPU monitor, it does not depend on configuration
443 */
445#endif /* EFI_HISTOGRAMS */
446
447#if EFI_GPIO_HARDWARE
448 /**
449 * We need the LED_ERROR pin even before we read configuration
450 */
452#endif // EFI_GPIO_HARDWARE
453
454#if EFI_PROD_CODE && EFI_SIGNAL_EXECUTOR_ONE_TIMER
455 // it's important to initialize this pretty early in the game before any scheduling usages
457#endif // EFI_PROD_CODE && EFI_SIGNAL_EXECUTOR_ONE_TIMER
458
459#if EFI_PROD_CODE && EFI_RTC
460 initRtc();
461#endif // EFI_PROD_CODE && EFI_RTC
462
463#if EFI_CONFIGURATION_STORAGE
464 initFlash();
465#endif
466
467#if EFI_FILE_LOGGING
469#endif // EFI_FILE_LOGGING
470
471#if HAL_USE_PAL && EFI_PROD_CODE
472 // this should be initialized before detectBoardType()
473 efiExtiInit();
474#endif // HAL_USE_PAL
475}
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 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 502 of file hardware.cpp.

502 {
503#if EFI_SHAFT_POSITION_INPUT
505#endif
506
507#if EFI_PROD_CODE && EFI_SHAFT_POSITION_INPUT
509#endif /* EFI_SHAFT_POSITION_INPUT */
510
511#if EFI_ENGINE_CONTROL
513#endif /* EFI_ENGINE_CONTROL */
514
515#if EFI_SHAFT_POSITION_INPUT
517
518#endif // EFI_SHAFT_POSITION_INPUT
519
521
522#if EFI_CAN_SUPPORT
523 startCanPins();
524#endif /* EFI_CAN_SUPPORT */
525}
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 477 of file hardware.cpp.

477 {
479
480#if EFI_PROD_CODE && (BOARD_EXT_GPIOCHIPS > 0)
482#endif /* (BOARD_EXT_GPIOCHIPS > 0) */
483
484#if EFI_LOGIC_ANALYZER
486#endif /* EFI_LOGIC_ANALYZER */
487
488#if EFI_EMULATE_POSITION_SENSORS
490#endif /* EFI_EMULATE_POSITION_SENSORS */
491
492#if EFI_VVT_PID
494#endif /* EFI_VVT_PID */
495}
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 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.