rusEFI
The most advanced open source ECU
Functions
eficonsole.cpp File Reference

Detailed Description

Console package entry point code.

Date
Nov 15, 2012
Author
Andrey Belomutskiy, (c) 2012-2020

This file is part of rusEfi - see http://rusefi.com

rusEfi is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file eficonsole.cpp.

Functions

static void testCritical ()
 
static void myerror ()
 
static void testHardFault ()
 
static void printUid ()
 
PUBLIC_API_WEAK void boardSayHello ()
 
static void sayHello ()
 
int CountFreeStackSpace (const void *wabase)
 
static void cmd_threads ()
 
static void echo (int value)
 This is just a test function. More...
 
void checkStackAndHandleConsoleLine (char *line)
 
void onCliCaseError (const char *token)
 
void onCliDuplicateError (const char *token)
 
void onCliOverflowError ()
 
void initializeConsole ()
 

Function Documentation

◆ boardSayHello()

PUBLIC_API_WEAK void boardSayHello ( )

Definition at line 62 of file eficonsole.cpp.

62  {
63 }

Referenced by sayHello().

Here is the caller graph for this function:

◆ checkStackAndHandleConsoleLine()

void checkStackAndHandleConsoleLine ( char *  line)

Definition at line 233 of file eficonsole.cpp.

233  {
234  assertStackVoid("console", ObdCode::STACK_USAGE_MISC, EXPECTED_REMAINING_STACK);
235  handleConsoleLine(line);
236 }
void handleConsoleLine(char *line)
This function takes care of one command line once we have it.
@ STACK_USAGE_MISC
Here is the call graph for this function:

◆ cmd_threads()

static void cmd_threads ( )
static

This methods prints all threads, their stack usage, and their total times

Definition at line 198 of file eficonsole.cpp.

198  {
199 #if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
200 
201  thread_t* tp = chRegFirstThread();
202 
203  efiPrintf("name\twabase\ttime\tfree stack");
204 
205  while (tp) {
206  int freeBytes = CountFreeStackSpace(tp->wabase);
207  efiPrintf("%s\t%08x\t%lu\t%d", tp->name, (unsigned int)tp->wabase, tp->time, freeBytes);
208 
209  if (freeBytes < 100) {
210  criticalError("Ran out of stack on thread %s, %d bytes remain", tp->name, freeBytes);
211  }
212 
213  tp = chRegNextThread(tp);
214  }
215 
216  int isrSpace = CountFreeStackSpace(reinterpret_cast<void*>(0x20000000));
217  efiPrintf("isr\t0\t0\t%d", isrSpace);
218 
219 #else // CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
220 
221  efiPrintf("CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS is not enabled");
222 
223 #endif
224 }
int CountFreeStackSpace(const void *wabase)
Definition: eficonsole.cpp:181

Referenced by initializeConsole().

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

◆ CountFreeStackSpace()

int CountFreeStackSpace ( const void *  wabase)

Definition at line 181 of file eficonsole.cpp.

181  {
182  const uint8_t* stackBase = reinterpret_cast<const uint8_t*>(wabase);
183  const uint8_t* stackUsage = stackBase;
184 
185  // thread stacks are filled with CH_DBG_STACK_FILL_VALUE
186  // find out where that ends - that's the last thing we needed on the stack
187  while (*stackUsage == CH_DBG_STACK_FILL_VALUE) {
188  stackUsage++;
189  }
190 
191  return (int)(stackUsage - stackBase);
192 }

Referenced by cmd_threads().

Here is the caller graph for this function:

◆ echo()

static void echo ( int  value)
static

This is just a test function.

Definition at line 229 of file eficonsole.cpp.

229  {
230  efiPrintf("got value: %d", value);
231 }

Referenced by initializeConsole().

Here is the caller graph for this function:

◆ initializeConsole()

void initializeConsole ( )

Definition at line 250 of file eficonsole.cpp.

250  {
252 
254 
255 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
256  addConsoleAction("uid", printUid);
257 #endif
258 
259  sayHello();
260  addConsoleAction("test", [](){ /* do nothing */});
261  addConsoleActionI("echo", echo);
262  addConsoleAction("hello", sayHello);
263  #if EFI_USE_OPENBLT
264  addConsoleAction("show_blt_version", [](){
265  uint32_t bltBinVersion = getOpenBltVersion();
266  efiPrintf("********************** blt=%lx %s version", bltBinVersion, bltBinVersion == BLT_CURRENT_VERSION ? "CURRENT" : "UNEXPECTED");
267  });
268  #endif
269 #if EFI_HAS_RESET
270  addConsoleAction("reset", scheduleReset);
271 #endif
272 
273  addConsoleAction("critical", testCritical);
274  addConsoleAction("error", myerror);
275  addConsoleAction("hard_fault", testHardFault);
276  addConsoleAction("threadsinfo", cmd_threads);
277 
278 #if HAL_USE_WDG
279  addConsoleActionI("set_watchdog_timeout", startWatchdog);
280  addConsoleActionI("set_watchdog_reset", setWatchdogResetPeriod);
281 #endif
282 }
void startWatchdog(int)
void setWatchdogResetPeriod(int)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void initConsoleLogic()
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
void startConsole(CommandHandler console_line_callback_p)
Definition: console_io.cpp:55
static void sayHello()
Definition: eficonsole.cpp:65
static void testCritical()
Definition: eficonsole.cpp:31
static void echo(int value)
This is just a test function.
Definition: eficonsole.cpp:229
static void myerror()
Definition: eficonsole.cpp:35
static void cmd_threads()
Definition: eficonsole.cpp:198
static void printUid()
Definition: eficonsole.cpp:44
static void testHardFault()
Definition: eficonsole.cpp:39

Referenced by runRusEfi().

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

◆ myerror()

static void myerror ( )
static

Definition at line 35 of file eficonsole.cpp.

35  {
37 }
void firmwareError(ObdCode code, const char *fmt,...)
int getRusEfiVersion()
@ CUSTOM_ERR_TEST_ERROR

Referenced by initializeConsole().

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

◆ onCliCaseError()

void onCliCaseError ( const char *  token)

Definition at line 238 of file eficonsole.cpp.

238  {
239  firmwareError(ObdCode::CUSTOM_ERR_COMMAND_LOWER_CASE_EXPECTED, "lowerCase expected [%s]", token);
240 }
@ CUSTOM_ERR_COMMAND_LOWER_CASE_EXPECTED

Referenced by doAddAction().

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

◆ onCliDuplicateError()

void onCliDuplicateError ( const char *  token)

Definition at line 242 of file eficonsole.cpp.

242  {
243  firmwareError(ObdCode::CUSTOM_SAME_TWICE, "Same action twice [%s]", token);
244 }
@ CUSTOM_SAME_TWICE

Referenced by doAddAction().

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

◆ onCliOverflowError()

void onCliOverflowError ( )

Definition at line 246 of file eficonsole.cpp.

246  {
247  firmwareError(ObdCode::CUSTOM_CONSOLE_TOO_MANY, "Too many console actions");
248 }
@ CUSTOM_CONSOLE_TOO_MANY

Referenced by doAddAction().

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

◆ printUid()

static void printUid ( )
static

Definition at line 44 of file eficonsole.cpp.

44  {
45  uint32_t *uid = ((uint32_t *)UID_BASE);
46  engine->outputChannels.deviceUid = crc8((const uint8_t*)uid, 12);
47  efiPrintf("********************** UID=%lx:%lx:%lx crc=%d ******************************", uid[0], uid[1], uid[2], engine->outputChannels.deviceUid);
48  engineConfiguration->device_uid[0] = uid[0];
49  engineConfiguration->device_uid[1] = uid[1];
50  engineConfiguration->device_uid[2] = uid[2];
51 }
TunerStudioOutputChannels outputChannels
Definition: engine.h:103
Engine * engine
engine_configuration_s * engineConfiguration

Referenced by initializeConsole(), and sayHello().

Here is the caller graph for this function:

◆ sayHello()

static void sayHello ( )
static

Time to finish output. This is needed to avoid mix-up of this methods output and console command confirmation this code here dates back to 2015. today in 2024 I have no idea what it does :(

Definition at line 65 of file eficonsole.cpp.

65  {
66  efiPrintf(PROTOCOL_HELLO_PREFIX " rusEFI LLC (c) 2012-2024. All rights reserved.");
67  efiPrintf(PROTOCOL_HELLO_PREFIX " rusEFI v%d@%u now=%d", getRusEfiVersion(), /*do we have a working way to print 64 bit values?!*/(int)SIGNATURE_HASH, (int)getTimeNowMs());
68  efiPrintf(PROTOCOL_HELLO_PREFIX " Chibios Kernel: %s", CH_KERNEL_VERSION);
69  efiPrintf(PROTOCOL_HELLO_PREFIX " Compiled: " __DATE__ " - " __TIME__ "");
70  efiPrintf(PROTOCOL_HELLO_PREFIX " COMPILER=%s", __VERSION__);
71 #if EFI_USE_OPENBLT
72  efiPrintf(PROTOCOL_HELLO_PREFIX " with OPENBLT");
73 #endif
74 
75  boardSayHello();
76 
77 #if EFI_PROD_CODE && ENABLE_AUTO_DETECT_HSE
78  extern float hseFrequencyMhz;
79  extern uint8_t autoDetectedRoundedMhz;
80  efiPrintf(PROTOCOL_HELLO_PREFIX " detected HSE clock %.2f MHz PLLM = %d", hseFrequencyMhz, autoDetectedRoundedMhz);
81 #endif /* ENABLE_AUTO_DETECT_HSE */
82 
83  efiPrintf("hellenBoardId=%d", engine->engineState.hellenBoardId);
84 
85 #if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
86  printUid();
87 
88 #if defined(STM32F4) && !defined(AT32F4XX)
89  efiPrintf("can read 0x20000010 %d", ramReadProbe((const char *)0x20000010));
90  efiPrintf("can read 0x20020010 %d", ramReadProbe((const char *)0x20020010));
91  efiPrintf("can read 0x20070010 %d", ramReadProbe((const char *)0x20070010));
92 
93  efiPrintf("isStm32F42x %s", boolToString(isStm32F42x()));
94 #endif // STM32F4
95 
96 #ifndef MIN_FLASH_SIZE
97 #define MIN_FLASH_SIZE 1024
98 #endif // MIN_FLASH_SIZE
99 
100  int flashSize = TM_ID_GetFlashSize();
101  if (flashSize < MIN_FLASH_SIZE) {
102  // todo: bug, at the moment we report 1MB on dual-bank F7
103  criticalError("rusEFI expected at least %dK of flash", MIN_FLASH_SIZE);
104  }
105 
106 #ifdef AT32F4XX
107  int mcuRevision = DBGMCU->SERID & 0x07;
108  int mcuSerId = (DBGMCU->SERID >> 8) & 0xff;
109  const char *partNumber, *package;
110  uint32_t pnFlashSize;
111  int ret = at32GetMcuType(DBGMCU->IDCODE, &partNumber, &package, &pnFlashSize);
112  if (ret == 0) {
113  efiPrintf("MCU IDCODE %s in %s with %ld KB flash",
114  partNumber, package, pnFlashSize);
115  } else {
116  efiPrintf("MCU IDCODE unknown 0x%lx", DBGMCU->IDCODE);
117  }
118  efiPrintf("MCU SER_ID %s rev %c",
119  (mcuSerId == 0x0d) ? "AT32F435" : ((mcuSerId == 0x0e) ? "AT32F437" : "UNKNOWN"),
120  'A' + mcuRevision);
121  efiPrintf("MCU F_SIZE %d KB", flashSize);
122  efiPrintf("MCU RAM %d KB", at32GetRamSizeKb());
123 #else
124 #define MCU_REVISION_MASK 0xfff
125  int mcuRevision = DBGMCU->IDCODE & MCU_REVISION_MASK;
126  efiPrintf("MCU rev=%x flashSize=%d", mcuRevision, flashSize);
127 #endif
128 #endif
129 
130 #ifdef CH_CFG_ST_FREQUENCY
131  efiPrintf("CH_CFG_ST_FREQUENCY=%d", CH_CFG_ST_FREQUENCY);
132 #endif
133 
134 #ifdef ENABLE_PERF_TRACE
135  efiPrintf("ENABLE_PERF_TRACE=%d", ENABLE_PERF_TRACE);
136 #endif
137 
138 #ifdef STM32_ADCCLK
139  efiPrintf("STM32_ADCCLK=%d", STM32_ADCCLK);
140  efiPrintf("STM32_TIMCLK1=%d", STM32_TIMCLK1);
141  efiPrintf("STM32_TIMCLK2=%d", STM32_TIMCLK2);
142 #endif
143 #ifdef STM32_PCLK1
144  efiPrintf("STM32_PCLK1=%d", STM32_PCLK1);
145  efiPrintf("STM32_PCLK2=%d", STM32_PCLK2);
146 #endif
147 
148  efiPrintf("PORT_IDLE_THREAD_STACK_SIZE=%d", PORT_IDLE_THREAD_STACK_SIZE);
149 
150  efiPrintf("CH_DBG_ENABLE_ASSERTS=%d", CH_DBG_ENABLE_ASSERTS);
151 #ifdef CH_DBG_ENABLED
152  efiPrintf("CH_DBG_ENABLED=%d", CH_DBG_ENABLED);
153 #endif
154  efiPrintf("CH_DBG_SYSTEM_STATE_CHECK=%d", CH_DBG_SYSTEM_STATE_CHECK);
155  efiPrintf("CH_DBG_ENABLE_STACK_CHECK=%d", CH_DBG_ENABLE_STACK_CHECK);
156 
157 #ifdef EFI_LOGIC_ANALYZER
158  efiPrintf("EFI_LOGIC_ANALYZER=%d", EFI_LOGIC_ANALYZER);
159 #endif
160 #ifdef EFI_TUNER_STUDIO
161  efiPrintf("EFI_TUNER_STUDIO=%d", EFI_TUNER_STUDIO);
162 #else
163  efiPrintf("EFI_TUNER_STUDIO=%d", 0);
164 #endif
165 
166 #if defined(EFI_SHAFT_POSITION_INPUT)
167  efiPrintf("EFI_SHAFT_POSITION_INPUT=%d", EFI_SHAFT_POSITION_INPUT);
168 #endif
169 #ifdef EFI_INTERNAL_ADC
170  efiPrintf("EFI_INTERNAL_ADC=%d", EFI_INTERNAL_ADC);
171 #endif
172 
173  /**
174  * Time to finish output. This is needed to avoid mix-up of this methods output and console command confirmation
175  * this code here dates back to 2015. today in 2024 I have no idea what it does :(
176  */
177  chThdSleepMilliseconds(5);
178 }
int at32GetMcuType(uint32_t id, const char **pn, const char **package, uint32_t *flashSize)
Definition: at32_common.cpp:12
bool isStm32F42x(void)
int at32GetRamSizeKb(void)
Definition: at32_common.cpp:70
EngineState engineState
Definition: engine.h:322
PUBLIC_API_WEAK void boardSayHello()
Definition: eficonsole.cpp:62
const char * boolToString(bool value)
Definition: efilib.cpp:18
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition: efitime.cpp:34
bool ramReadProbe(volatile const char *read_address)
Probe an address to see if can be read without generating a bus fault.
float hseFrequencyMhz
uint8_t autoDetectedRoundedMhz
static uint16_t flashSize()
Definition: mpu_util.cpp:17

Referenced by initializeConsole().

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

◆ testCritical()

static void testCritical ( )
static

Definition at line 31 of file eficonsole.cpp.

31  {
32  chDbgCheck(0);
33 }

Referenced by initializeConsole().

Here is the caller graph for this function:

◆ testHardFault()

static void testHardFault ( )
static

Definition at line 39 of file eficonsole.cpp.

39  {
41 }
void causeHardFault()
Definition: arm_common.cpp:16

Referenced by initializeConsole().

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

Go to the source code of this file.