rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
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 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.
 
void checkStackAndHandleConsoleLine (char *line)
 
void onCliCaseError (const char *token)
 
void onCliDuplicateError (const char *token)
 
void onCliOverflowError ()
 
void initializeConsole ()
 

Variables

std::optional< setup_custom_board_overrides_typecustom_board_boardSayHello
 

Function Documentation

◆ boardSayHello()

PUBLIC_API_WEAK void boardSayHello ( )

Definition at line 53 of file eficonsole.cpp.

53 {
54}

Referenced by sayHello().

Here is the caller graph for this function:

◆ checkStackAndHandleConsoleLine()

void checkStackAndHandleConsoleLine ( char line)

Definition at line 227 of file eficonsole.cpp.

227 {
228 assertStackVoid("console", ObdCode::STACK_USAGE_MISC, EXPECTED_REMAINING_STACK);
229 handleConsoleLine(line);
230}
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 188 of file eficonsole.cpp.

188 {
189#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
190 thread_t* tp = chRegFirstThread();
191
192 efiPrintf("name\twabase\ttime\tfree stack");
193
194 while (tp) {
195 int freeBytes = CountFreeStackSpace(tp->wabase);
196 efiPrintf("%s\t%08x\t%lu\t%d", tp->name, (unsigned int)tp->wabase, tp->time, freeBytes);
197
198 if (freeBytes < 100) {
199 criticalError("Ran out of stack on thread %s, %d bytes remain", tp->name, freeBytes);
200 }
201
202 tp = chRegNextThread(tp);
203 }
204
205#if EFI_PROD_CODE
206 // isr stack base
207 extern uint32_t __main_stack_base__;
208
209 int isrSpace = CountFreeStackSpace(reinterpret_cast<void*>(&__main_stack_base__));
210 efiPrintf("isr\t0\t0\t%d", isrSpace);
211#endif // EFI_PROD_CODE
212
213#else // CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
214
215 efiPrintf("CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS is not enabled");
216
217#endif
218}
uint32_t __main_stack_base__
int CountFreeStackSpace(const void *wabase)

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 171 of file eficonsole.cpp.

171 {
172 const uint8_t* stackBase = reinterpret_cast<const uint8_t*>(wabase);
173 const uint8_t* stackUsage = stackBase;
174
175 // thread stacks are filled with CH_DBG_STACK_FILL_VALUE
176 // find out where that ends - that's the last thing we needed on the stack
177 while (*stackUsage == CH_DBG_STACK_FILL_VALUE) {
178 stackUsage++;
179 }
180
181 return (int)(stackUsage - stackBase);
182}

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 223 of file eficonsole.cpp.

223 {
224 efiPrintf("got value: %d", value);
225}

Referenced by initializeConsole().

Here is the caller graph for this function:

◆ initializeConsole()

void initializeConsole ( )

Definition at line 244 of file eficonsole.cpp.

244 {
246
248
249#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
251#endif
252
253 sayHello();
254 addConsoleAction("test", [](){ /* do nothing */});
255 addConsoleActionI("echo", echo);
256 addConsoleAction("hello", sayHello);
257 #if EFI_USE_OPENBLT
258 addConsoleAction("show_blt_version", [](){
259 uint32_t bltBinVersion = getOpenBltVersion();
260 efiPrintf("********************** blt=%lx %s version", bltBinVersion, bltBinVersion == BLT_CURRENT_VERSION ? "CURRENT" : "UNEXPECTED");
261 });
262 #endif
263#if EFI_HAS_RESET
264 addConsoleAction("reset", scheduleReset);
265#endif
266
267 addConsoleAction("threadsinfo", cmd_threads);
268
269#if HAL_USE_WDG
270 addConsoleActionI("set_watchdog_timeout", startWatchdog);
271 addConsoleActionI("set_watchdog_reset", setWatchdogResetPeriod);
272#endif
273}
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)
static void sayHello()
static void echo(int value)
This is just a test function.
static void cmd_threads()
static void printUid()

Referenced by runRusEfi().

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 232 of file eficonsole.cpp.

232 {
233 firmwareError(ObdCode::CUSTOM_ERR_COMMAND_LOWER_CASE_EXPECTED, "lowerCase expected [%s]", token);
234}
void firmwareError(ObdCode code, const char *fmt,...)
@ 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 236 of file eficonsole.cpp.

236 {
237 firmwareError(ObdCode::CUSTOM_SAME_TWICE, "Same action twice [%s]", token);
238}
@ 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 240 of file eficonsole.cpp.

240 {
241 firmwareError(ObdCode::CUSTOM_CONSOLE_TOO_MANY, "Too many console actions");
242}
@ 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 35 of file eficonsole.cpp.

35 {
36 uint32_t *uid = ((uint32_t *)UID_BASE);
37 engine->outputChannels.deviceUid = crc8((const uint8_t*)uid, 12);
38 efiPrintf("********************** UID=%lx:%lx:%lx crc=%d ******************************", uid[0], uid[1], uid[2], engine->outputChannels.deviceUid);
42}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413
static constexpr 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 56 of file eficonsole.cpp.

56 {
57 efiPrintf(PROTOCOL_HELLO_PREFIX " rusEFI LLC (c) 2012-2024. All rights reserved.");
58 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());
59 efiPrintf(PROTOCOL_HELLO_PREFIX " Chibios Kernel: %s", CH_KERNEL_VERSION);
60 efiPrintf(PROTOCOL_HELLO_PREFIX " Compiled: " __DATE__ " - " __TIME__ "");
61 efiPrintf(PROTOCOL_HELLO_PREFIX " COMPILER=%s", __VERSION__);
62#if EFI_USE_OPENBLT
63 efiPrintf(PROTOCOL_HELLO_PREFIX " with OPENBLT");
64#endif
65
68
69#if EFI_PROD_CODE && ENABLE_AUTO_DETECT_HSE
70 extern float hseFrequencyMhz;
71 extern uint8_t autoDetectedRoundedMhz;
72 efiPrintf(PROTOCOL_HELLO_PREFIX " detected HSE clock %.2f MHz PLLM = %d", hseFrequencyMhz, autoDetectedRoundedMhz);
73#endif /* ENABLE_AUTO_DETECT_HSE */
74
75 efiPrintf("hellenBoardId=%d", engine->engineState.hellenBoardId);
76
77#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
78 printUid();
79
80#if defined(STM32F4) && !defined(AT32F4XX)
81// efiPrintf("ramReadProbe 0x20000010 %d", ramReadProbe((const char *)0x20000010));
82// efiPrintf("ramReadProbe 0x20020010 %d", ramReadProbe((const char *)0x20020010));
83// efiPrintf("ramReadProbe 0x20070010 %d", ramReadProbe((const char *)0x20070010));
84
85 efiPrintf("isStm32F42x %s", boolToString(isStm32F42x()));
86#endif // STM32F4
87
88#ifndef MIN_FLASH_SIZE
89#define MIN_FLASH_SIZE 1024
90#endif // MIN_FLASH_SIZE
91
92 int flashSize = TM_ID_GetFlashSize();
93 if (flashSize < MIN_FLASH_SIZE) {
94 // todo: bug, at the moment we report 1MB on dual-bank F7
95 criticalError("rusEFI expected at least %dK of flash", MIN_FLASH_SIZE);
96 }
97
98#ifdef AT32F4XX
99 int mcuRevision = DBGMCU->SERID & 0x07;
100 int mcuSerId = (DBGMCU->SERID >> 8) & 0xff;
101 const char *partNumber, *package;
102 uint32_t pnFlashSize;
103 int ret = at32GetMcuType(DBGMCU->IDCODE, &partNumber, &package, &pnFlashSize);
104 if (ret == 0) {
105 efiPrintf("MCU IDCODE %s in %s with %ld KB flash",
106 partNumber, package, pnFlashSize);
107 } else {
108 efiPrintf("MCU IDCODE unknown 0x%lx", DBGMCU->IDCODE);
109 }
110 efiPrintf("MCU SER_ID %s rev %c",
111 (mcuSerId == 0x0d) ? "AT32F435" : ((mcuSerId == 0x0e) ? "AT32F437" : "UNKNOWN"),
112 'A' + mcuRevision);
113 efiPrintf("MCU F_SIZE %d KB", flashSize);
114 efiPrintf("MCU RAM %d KB", at32GetRamSizeKb());
115#else
116#define MCU_REVISION_MASK 0xfff
117 int mcuRevision = DBGMCU->IDCODE & MCU_REVISION_MASK;
118 efiPrintf("MCU rev=%x flashSize=%d", mcuRevision, flashSize);
119#endif
120#endif
121
122#ifdef CH_CFG_ST_FREQUENCY
123 efiPrintf("CH_CFG_ST_FREQUENCY=%d", CH_CFG_ST_FREQUENCY);
124#endif
125
126#ifdef ENABLE_PERF_TRACE
127 efiPrintf("ENABLE_PERF_TRACE=%d", ENABLE_PERF_TRACE);
128#endif
129
130#ifdef STM32_ADCCLK
131 efiPrintf("STM32_ADCCLK=%d", STM32_ADCCLK);
132 efiPrintf("STM32_TIMCLK1=%d", STM32_TIMCLK1);
133 efiPrintf("STM32_TIMCLK2=%d", STM32_TIMCLK2);
134#endif
135#ifdef STM32_PCLK1
136 efiPrintf("STM32_PCLK1=%d", STM32_PCLK1);
137 efiPrintf("STM32_PCLK2=%d", STM32_PCLK2);
138#endif
139#ifdef STM32_RTCSEL
140 if (1) {
141 #define STM32_RTCSEL_SHIFT 8
142 const char * rtcsel_names[4] = {"no clock", "LSE", "LSI", "HSE"};
143
144 int rtcsel = (RCC->BDCR & STM32_RTCSEL_MASK) >> STM32_RTCSEL_SHIFT;
145 efiPrintf("STM32_RTCSEL=%d %s actual=%d %s",
146 STM32_RTCSEL >> STM32_RTCSEL_SHIFT, rtcsel_names[STM32_RTCSEL >> STM32_RTCSEL_SHIFT], rtcsel, rtcsel_names[rtcsel]);
147#ifdef RUSEFI_STM32_LSE_WAIT_MAX_RTCSEL
148 efiPrintf("RUSEFI_STM32_LSE_WAIT_MAX_RTCSEL=%d %s",
149 RUSEFI_STM32_LSE_WAIT_MAX_RTCSEL >> STM32_RTCSEL_SHIFT, rtcsel_names[RUSEFI_STM32_LSE_WAIT_MAX_RTCSEL >> STM32_RTCSEL_SHIFT]);
150#endif
151 }
152#endif
153
154 efiPrintf("PORT_IDLE_THREAD_STACK_SIZE=%d", PORT_IDLE_THREAD_STACK_SIZE);
155
156 efiPrintf("CH_DBG_ENABLE_ASSERTS=%d", CH_DBG_ENABLE_ASSERTS);
157#ifdef CH_DBG_ENABLED
158 efiPrintf("CH_DBG_ENABLED=%d", CH_DBG_ENABLED);
159#endif
160 efiPrintf("CH_DBG_SYSTEM_STATE_CHECK=%d", CH_DBG_SYSTEM_STATE_CHECK);
161 efiPrintf("CH_DBG_ENABLE_STACK_CHECK=%d", CH_DBG_ENABLE_STACK_CHECK);
162
163 /**
164 * Time to finish output. This is needed to avoid mix-up of this methods output and console command confirmation
165 * this code here dates back to 2015. today in 2024 I have no idea what it does :(
166 */
167 chThdSleepMilliseconds(5);
168}
int at32GetMcuType(uint32_t id, const char **pn, const char **package, uint32_t *flashSize)
bool isStm32F42x(void)
int at32GetRamSizeKb(void)
static bool call_board_override(std::optional< setup_custom_board_overrides_type > board_override)
EngineState engineState
Definition engine.h:344
std::optional< setup_custom_board_overrides_type > custom_board_boardSayHello
PUBLIC_API_WEAK void boardSayHello()
const char * boolToString(bool value)
Definition efilib.cpp:19
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition efitime.cpp:34
int getRusEfiVersion()
float hseFrequencyMhz
uint8_t autoDetectedRoundedMhz
static uint16_t flashSize()
Definition mpu_util.cpp:21

Referenced by initializeConsole().

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

Variable Documentation

◆ custom_board_boardSayHello

std::optional<setup_custom_board_overrides_type> custom_board_boardSayHello

Definition at line 32 of file eficonsole.cpp.

Referenced by sayHello().

Go to the source code of this file.