fome-fw/firmware/console/eficonsole.cpp

167 lines
5.1 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file eficonsole.cpp
* @brief Console package entry point code
*
*
* @date Nov 15, 2012
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*
*
* 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/>.
*/
#include "pch.h"
2022-09-07 12:56:45 -07:00
2015-07-10 06:01:56 -07:00
#include "eficonsole.h"
#include "console_io.h"
2023-02-22 15:39:27 -08:00
#include "gitversion.h"
2015-07-10 06:01:56 -07:00
static void testCritical() {
2017-03-21 11:58:14 -07:00
chDbgCheck(0);
2015-07-10 06:01:56 -07:00
}
static void myerror() {
firmwareError(ObdCode::CUSTOM_ERR_TEST_ERROR, "firmwareError: %d", getRusEfiVersion());
2015-07-10 06:01:56 -07:00
}
static void sayHello() {
2023-01-11 09:12:51 -08:00
efiPrintf(PROTOCOL_HELLO_PREFIX " rusEFI LLC (c) 2012-2023. All rights reserved.");
2023-02-22 15:39:27 -08:00
efiPrintf(PROTOCOL_HELLO_PREFIX " built from " GIT_HASH);
2023-03-02 02:39:41 -08:00
efiPrintf(PROTOCOL_HELLO_PREFIX " FOME v%d", getRusEfiVersion());
efiPrintf(PROTOCOL_HELLO_PREFIX " Chibios Kernel: %s", CH_KERNEL_VERSION);
efiPrintf(PROTOCOL_HELLO_PREFIX " Compiled: " __DATE__ " - " __TIME__ "");
efiPrintf(PROTOCOL_HELLO_PREFIX " COMPILER=%s", __VERSION__);
2022-01-16 16:56:49 -08:00
#if USE_OPENBLT
efiPrintf(PROTOCOL_HELLO_PREFIX " with OPENBLT");
#endif
2020-04-22 17:20:22 -07:00
#if ENABLE_AUTO_DETECT_HSE
extern float hseFrequencyMhz;
extern uint8_t autoDetectedRoundedMhz;
efiPrintf(PROTOCOL_HELLO_PREFIX " detected HSE clock %.2f MHz PLLM = %d", hseFrequencyMhz, autoDetectedRoundedMhz);
#endif /* ENABLE_AUTO_DETECT_HSE */
efiPrintf("hellenBoardId=%d", engine->engineState.hellenBoardId);
2021-08-07 09:36:39 -07:00
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
2020-04-22 17:20:22 -07:00
uint32_t *uid = ((uint32_t *)UID_BASE);
efiPrintf("UID=%x %x %x", uid[0], uid[1], uid[2]);
2021-01-14 20:34:10 -08:00
efiPrintf("can read 0x20000010 %d", ramReadProbe((const char *)0x20000010));
efiPrintf("can read 0x20020010 %d", ramReadProbe((const char *)0x20020010));
efiPrintf("can read 0x20070010 %d", ramReadProbe((const char *)0x20070010));
#if defined(STM32F4)
efiPrintf("isStm32F42x %s", boolToString(isStm32F42x()));
#endif // STM32F4
2021-10-07 22:29:40 -07:00
2021-01-14 20:34:10 -08:00
#define TM_ID_GetFlashSize() (*(__IO uint16_t *) (FLASHSIZE_BASE))
#define MCU_REVISION_MASK 0xfff
int mcuRevision = DBGMCU->IDCODE & MCU_REVISION_MASK;
2022-12-16 15:24:39 -08:00
#ifndef MIN_FLASH_SIZE
#define MIN_FLASH_SIZE 1024
2022-12-16 15:24:39 -08:00
#endif // MIN_FLASH_SIZE
int flashSize = TM_ID_GetFlashSize();
if (flashSize < MIN_FLASH_SIZE) {
firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Expected at least %dK of flash but found %dK", MIN_FLASH_SIZE, flashSize);
}
// todo: bug, at the moment we report 1MB on dual-bank F7
efiPrintf("MCU rev=%x flashSize=%d", mcuRevision, flashSize);
2020-04-22 17:20:22 -07:00
#endif
2015-07-10 06:01:56 -07:00
/**
* Time to finish output. This is needed to avoid mix-up of this methods output and console command confirmation
*/
chThdSleepMilliseconds(5);
}
2023-04-11 16:32:47 -07:00
void validateStack(const char*msg, ObdCode code, int desiredStackUnusedSize) {
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
int unusedStack = CountFreeStackSpace(chThdGetSelfX()->wabase);
if (unusedStack < desiredStackUnusedSize) {
warning(code, "Stack low on %s: %d", msg, unusedStack);
}
#else
(void)msg; (void)code; (void)desiredStackUnusedSize;
#endif
}
2019-11-06 16:53:09 -08:00
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
int CountFreeStackSpace(const void* wabase) {
2019-06-13 05:31:25 -07:00
const uint8_t* stackBase = reinterpret_cast<const uint8_t*>(wabase);
const uint8_t* stackUsage = stackBase;
// thread stacks are filled with CH_DBG_STACK_FILL_VALUE
2019-06-13 05:31:25 -07:00
// find out where that ends - that's the last thing we needed on the stack
while (*stackUsage == CH_DBG_STACK_FILL_VALUE) {
2019-06-13 05:31:25 -07:00
stackUsage++;
}
return (int)(stackUsage - stackBase);
2019-06-13 05:31:25 -07:00
}
2019-11-06 16:53:09 -08:00
#endif
2019-06-13 05:31:25 -07:00
2015-07-10 06:01:56 -07:00
/**
2019-06-13 05:31:25 -07:00
* This methods prints all threads, their stack usage, and their total times
2015-07-10 06:01:56 -07:00
*/
static void cmd_threads() {
2019-06-13 05:31:25 -07:00
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
thread_t* tp = chRegFirstThread();
efiPrintf("name\twabase\ttime\tfree stack");
2019-06-13 05:31:25 -07:00
while (tp) {
int freeBytes = CountFreeStackSpace(tp->wabase);
efiPrintf("%s\t%08x\t%lu\t%d", tp->name, tp->wabase, tp->time, freeBytes);
2019-06-13 05:31:25 -07:00
2021-10-04 05:19:58 -07:00
if (freeBytes < 100) {
firmwareError(ObdCode::OBD_PCM_Processor_Fault, "Ran out of stack on thread %s, %d bytes remain", tp->name, freeBytes);
2021-10-04 05:19:58 -07:00
}
2019-06-13 05:31:25 -07:00
tp = chRegNextThread(tp);
}
int isrSpace = CountFreeStackSpace(reinterpret_cast<void*>(0x20000000));
efiPrintf("isr\t0\t0\t%d", isrSpace);
2019-06-13 05:31:25 -07:00
#else // CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
efiPrintf("CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS is not enabled");
2019-06-13 05:31:25 -07:00
2015-07-10 06:01:56 -07:00
#endif
}
void initializeConsole() {
initConsoleLogic();
2015-07-10 06:01:56 -07:00
startConsole(&handleConsoleLine);
2015-07-10 06:01:56 -07:00
sayHello();
addConsoleAction("test", [](){ /* do nothing */});
2015-07-10 06:01:56 -07:00
addConsoleAction("hello", sayHello);
#if EFI_HAS_RESET
addConsoleAction("reset", scheduleReset);
#endif
2020-03-28 18:28:32 -07:00
addConsoleAction("critical", testCritical);
2015-07-10 06:01:56 -07:00
addConsoleAction("error", myerror);
addConsoleAction("threadsinfo", cmd_threads);
}