rusEFI
The most advanced open source ECU
Functions | Variables
rusefi.cpp File Reference

Detailed Description

Initialization code and main status reporting look.

Date
Dec 25, 2013
Author
Andrey Belomutskiy, (c) 2012-2021

Definition in file rusefi.cpp.

Functions

void rebootNow ()
 
void scheduleReboot ()
 
void onAssertionFailure ()
 
void runRusEfiWithConfig ()
 
__NO_RETURN void runMainLoop ()
 
void runRusEfi ()
 
void chDbgStackOverflowPanic (thread_t *otp)
 

Variables

bool main_loop_started = false
 
static char panicMessage [200]
 
static virtual_timer_t resetTimer
 
static jmp_buf jmpEnv
 

Function Documentation

◆ chDbgStackOverflowPanic()

void chDbgStackOverflowPanic ( thread_t *  otp)

this depends on chcore.h patch +void chDbgStackOverflowPanic(thread_t *otp);

  • chSysHalt("stack overflow"); \
  • chDbgStackOverflowPanic(otp); \

Definition at line 312 of file rusefi.cpp.

312  {
313  (void)otp;
314  strcpy(panicMessage, "stack overflow: ");
315 #if defined(CH_USE_REGISTRY)
316  int p_name_len = strlen(otp->p_name);
317  if (p_name_len < sizeof(panicMessage) - 2)
318  strcat(panicMessage, otp->p_name);
319 #endif
320  chDbgPanic3(panicMessage, __FILE__, __LINE__);
321 }
void chDbgPanic3(const char *, const char *, int)
static char panicMessage[200]
Definition: rusefi.cpp:145
Here is the call graph for this function:

◆ onAssertionFailure()

void onAssertionFailure ( )

Definition at line 165 of file rusefi.cpp.

165  {
166  // There's been an assertion failure: instead of hanging, jump back to where we check
167  // if (setjmp(jmpEnv)) (see below for more complete explanation)
168  longjmp(jmpEnv, 1);
169 }
void longjmp(jmp_buf, int)
static jmp_buf jmpEnv
Definition: rusefi.cpp:164

Referenced by chDbgPanic3().

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

◆ rebootNow()

void rebootNow ( )

Definition at line 150 of file rusefi.cpp.

150  {
151  NVIC_SystemReset();
152 }

Referenced by executeTSCommand(), and scheduleReboot().

Here is the caller graph for this function:

◆ runMainLoop()

void runMainLoop ( )

This loop is the closes we have to 'main loop' - but here we only publish the status. The main logic of engine control is around main_trigger_callback

Definition at line 285 of file rusefi.cpp.

285  {
286  efiPrintf("Running main loop");
287  main_loop_started = true;
288  /**
289  * This loop is the closes we have to 'main loop' - but here we only publish the status. The main logic of engine
290  * control is around main_trigger_callback
291  */
292  while (true) {
293 #if EFI_CLI_SUPPORT && !EFI_UART_ECHO_TEST_MODE
294  // sensor state + all pending messages for our own rusEfi console
295  // todo: is this mostly dead code?
297 #endif /* EFI_CLI_SUPPORT */
298 
299  chThdSleepMilliseconds(200);
300  }
301 }
bool main_loop_started
Definition: rusefi.cpp:143
void updateDevConsoleState()
Sends all pending data to rusEfi console.

Referenced by runRusEfi().

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

◆ runRusEfi()

void runRusEfi ( void  )

we need to initialize table objects before default configuration can set values

Next we should initialize serial port console, it's important to know what's going on

Definition at line 174 of file rusefi.cpp.

174  {
175  engine->setConfig();
176 
177 #if EFI_TEXT_LOGGING
178  // Initialize logging system early - we can't log until this is called
180 #endif
181 
182 #if EFI_PROD_CODE
184 #endif
185 
186 #if defined(STM32F4) || defined(STM32F7)
187 // addConsoleAction("stm32_stop", stm32_stop);
188  addConsoleAction("stm32_standby", stm32_standby);
189 #endif
190 
191  addConsoleAction(CMD_REBOOT, scheduleReboot);
192 #if EFI_DFU_JUMP
193  addConsoleAction(CMD_REBOOT_DFU, jump_to_bootloader);
194 #endif /* EFI_DFU_JUMP */
195 
196 #if EFI_USE_OPENBLT
197  addConsoleAction(CMD_REBOOT_OPENBLT, jump_to_openblt);
198 #endif
199 
200  /**
201  * we need to initialize table objects before default configuration can set values
202  */
204 
205  // Perform hardware initialization that doesn't need configuration
207 
208  // at the moment that's always hellen board ID
209  detectBoardType();
210 
211 #if EFI_ETHERNET
213 #endif
214 
215 #if EFI_USB_SERIAL
216  startUsbConsole();
217 #endif
218 
219 #if HAL_USE_USB_MSD
220  initUsbMsd();
221 #endif
222 
223  /**
224  * Next we should initialize serial port console, it's important to know what's going on
225  */
227 
229 
230  // Read configuration from flash memory
232 
233 #if EFI_TUNER_STUDIO
235 #endif /* EFI_TUNER_STUDIO */
236 
237  // Start hardware serial ports (including bluetooth, if present)
238 #if EFI_TUNER_STUDIO
240 #endif // EFI_TUNER_STUDIO
241 
243 
244  // periodic events need to be initialized after fuel&spark pins to avoid a warning
246 
247  runMainLoop();
248 }
void stm32_standby()
Definition: mpu_util.cpp:17
void jump_to_openblt()
void jump_to_bootloader()
void setConfig()
Definition: engine.cpp:400
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void detectBoardType()
void initializeConsole()
Definition: eficonsole.cpp:230
void startEthernetConsole()
void startUsbConsole()
Definition: usb_console.cpp:56
void loadConfiguration()
Engine * engine
void initPeriodicEvents()
void initDataStructures()
void checkLastBootError()
void initHardwareNoConfig()
Definition: hardware.cpp:467
void checkLastResetCause()
Definition: hardware.cpp:708
void startLoggingProcessor()
void initUsbMsd()
void scheduleReboot()
Definition: rusefi.cpp:158
__NO_RETURN void runMainLoop()
Definition: rusefi.cpp:285
void runRusEfiWithConfig()
Definition: rusefi.cpp:250
void startTunerStudioConnectivity(void)
void startSerialChannels()
Here is the call graph for this function:

◆ runRusEfiWithConfig()

void runRusEfiWithConfig ( )

Now let's initialize actual engine control logic todo: should we initialize some? most? controllers before hardware?

Definition at line 250 of file rusefi.cpp.

250  {
251  // If some config operation caused an OS assertion failure, return immediately
252  // This sets the "unwind point" that we can jump back to later with longjmp if we have
253  // an assertion failure. If that happens, setjmp() will return non-zero, so we will
254  // return immediately from this function instead of trying to init hardware again (which failed last time)
255  if (setjmp(jmpEnv)) {
256  return;
257  }
258 
259  commonEarlyInit();
260 
261 #if EFI_WIFI
263 #endif
264 
265  // Config could be completely bogus - don't start anything else!
266  if (validateConfig()) {
267  /**
268  * Now let's initialize actual engine control logic
269  * todo: should we initialize some? most? controllers before hardware?
270  */
272 
273 
274  // This has to happen after RegisteredOutputPins are init'd: otherwise no change will be detected, and no init will happen
276 
277  #if EFI_PERF_METRICS
279  #endif
280 
282  }
283 }
void runSchedulingPrecisionTestIfNeeded(void)
void startWifiConsole()
void rememberCurrentConfiguration()
void commonEarlyInit()
bool validateConfig()
void initRealHardwareEngineController()
int setjmp(jmp_buf)
void initTimePerfActions()

Referenced by runRusEfi().

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

◆ scheduleReboot()

void scheduleReboot ( )

Some configuration changes require full firmware reset. Once day we will write graceful shutdown, but that would be one day.

Definition at line 158 of file rusefi.cpp.

158  {
159  efiPrintf("Rebooting in 3 seconds...");
160  chibios_rt::CriticalSectionLocker csl;
161  chVTSetI(&resetTimer, TIME_MS2I(3000), (vtfunc_t) rebootNow, NULL);
162 }
static virtual_timer_t resetTimer
Definition: rusefi.cpp:147
void rebootNow()
Definition: rusefi.cpp:150

Referenced by processCanQcBenchTest(), runRusEfi(), and unlockEcu().

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

Variable Documentation

◆ jmpEnv

jmp_buf jmpEnv
static

Definition at line 164 of file rusefi.cpp.

Referenced by onAssertionFailure(), and runRusEfiWithConfig().

◆ main_loop_started

bool main_loop_started = false

Definition at line 143 of file rusefi.cpp.

Referenced by runMainLoop(), and writeSdLogLine().

◆ panicMessage

char panicMessage[200]
static

Definition at line 145 of file rusefi.cpp.

Referenced by chDbgStackOverflowPanic().

◆ resetTimer

virtual_timer_t resetTimer
static

Definition at line 147 of file rusefi.cpp.

Referenced by scheduleReboot().

Go to the source code of this file.