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/>.
|
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2019-07-03 18:48:04 -07:00
|
|
|
#include "os_access.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "eficonsole.h"
|
|
|
|
#include "console_io.h"
|
|
|
|
#include "svnversion.h"
|
|
|
|
|
2020-03-28 18:28:32 -07:00
|
|
|
static void testCritical(void) {
|
2017-03-21 11:58:14 -07:00
|
|
|
chDbgCheck(0);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void myerror(void) {
|
2017-03-05 11:13:47 -08:00
|
|
|
firmwareError(CUSTOM_ERR_TEST_ERROR, "firmwareError: %d", getRusEfiVersion());
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sayHello(void) {
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf(PROTOCOL_HELLO_PREFIX " rusEFI LLC (c) 2012-2021. All rights reserved.");
|
|
|
|
efiPrintf(PROTOCOL_HELLO_PREFIX " rusEFI v%d@%s", getRusEfiVersion(), VCS_VERSION);
|
|
|
|
efiPrintf(PROTOCOL_HELLO_PREFIX " Chibios Kernel: %s", CH_KERNEL_VERSION);
|
|
|
|
efiPrintf(PROTOCOL_HELLO_PREFIX " Compiled: " __DATE__ " - " __TIME__ "");
|
|
|
|
efiPrintf(PROTOCOL_HELLO_PREFIX " COMPILER=%s", __VERSION__);
|
2020-04-22 17:20:22 -07:00
|
|
|
|
2021-07-14 09:42:09 -07:00
|
|
|
#ifdef ENABLE_AUTO_DETECT_HSE
|
2021-07-14 12:20:38 -07:00
|
|
|
extern float hseFrequencyMhz;
|
2021-07-19 15:04:59 -07:00
|
|
|
extern uint8_t autoDetectedRoundedMhz;
|
|
|
|
efiPrintf(PROTOCOL_HELLO_PREFIX " detected HSE clock %.2f MHz PLLM = %d", hseFrequencyMhz, autoDetectedRoundedMhz);
|
2021-07-14 09:42:09 -07:00
|
|
|
#endif /* ENABLE_AUTO_DETECT_HSE */
|
|
|
|
|
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);
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("UID=%x %x %x", uid[0], uid[1], uid[2]);
|
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;
|
|
|
|
|
2021-05-07 14:04:54 -07:00
|
|
|
#define MIN_FLASH_SIZE 1024
|
|
|
|
|
|
|
|
int flashSize = TM_ID_GetFlashSize();
|
|
|
|
if (flashSize < MIN_FLASH_SIZE) {
|
|
|
|
firmwareError(OBD_PCM_Processor_Fault, "rusEFI expected at least %dK of flash", MIN_FLASH_SIZE);
|
|
|
|
}
|
|
|
|
|
2021-08-07 09:36:39 -07:00
|
|
|
efiPrintf("MCU rev=%x size=%d", mcuRevision, flashSize);
|
2020-04-22 17:20:22 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-02-04 12:01:45 -08:00
|
|
|
#ifdef CH_FREQUENCY
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("CH_FREQUENCY=%d", CH_FREQUENCY);
|
2016-02-04 12:01:45 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#ifdef CORTEX_MAX_KERNEL_PRIORITY
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("CORTEX_MAX_KERNEL_PRIORITY=%d", CORTEX_MAX_KERNEL_PRIORITY);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef STM32_ADCCLK
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("STM32_ADCCLK=%d", STM32_ADCCLK);
|
|
|
|
efiPrintf("STM32_TIMCLK1=%d", STM32_TIMCLK1);
|
|
|
|
efiPrintf("STM32_TIMCLK2=%d", STM32_TIMCLK2);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef STM32_PCLK1
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("STM32_PCLK1=%d", STM32_PCLK1);
|
|
|
|
efiPrintf("STM32_PCLK2=%d", STM32_PCLK2);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("PORT_IDLE_THREAD_STACK_SIZE=%d", PORT_IDLE_THREAD_STACK_SIZE);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("CH_DBG_ENABLE_ASSERTS=%d", CH_DBG_ENABLE_ASSERTS);
|
2016-02-04 12:01:45 -08:00
|
|
|
#ifdef CH_DBG_ENABLED
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("CH_DBG_ENABLED=%d", CH_DBG_ENABLED);
|
2016-02-04 12:01:45 -08:00
|
|
|
#endif
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("CH_DBG_SYSTEM_STATE_CHECK=%d", CH_DBG_SYSTEM_STATE_CHECK);
|
|
|
|
efiPrintf("CH_DBG_ENABLE_STACK_CHECK=%d", CH_DBG_ENABLE_STACK_CHECK);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-12-03 22:11:10 -08:00
|
|
|
#ifdef EFI_LOGIC_ANALYZER
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_LOGIC_ANALYZER=%d", EFI_LOGIC_ANALYZER);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef EFI_TUNER_STUDIO
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_TUNER_STUDIO=%d", EFI_TUNER_STUDIO);
|
2015-07-10 06:01:56 -07:00
|
|
|
#else
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_TUNER_STUDIO=%d", 0);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EFI_SIGNAL_EXECUTOR_SLEEP
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_SIGNAL_EXECUTOR_SLEEP=%d", EFI_SIGNAL_EXECUTOR_SLEEP);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EFI_SIGNAL_EXECUTOR_HW_TIMER
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_SIGNAL_EXECUTOR_HW_TIMER=%d", EFI_SIGNAL_EXECUTOR_HW_TIMER);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if defined(EFI_SHAFT_POSITION_INPUT)
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_SHAFT_POSITION_INPUT=%d", EFI_SHAFT_POSITION_INPUT);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
#ifdef EFI_INTERNAL_ADC
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("EFI_INTERNAL_ADC=%d", EFI_INTERNAL_ADC);
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Time to finish output. This is needed to avoid mix-up of this methods output and console command confirmation
|
|
|
|
*/
|
|
|
|
chThdSleepMilliseconds(5);
|
|
|
|
}
|
|
|
|
|
2020-08-02 07:52:52 -07:00
|
|
|
void validateStack(const char*msg, obd_code_e 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);
|
|
|
|
}
|
2021-01-11 05:49:20 -08:00
|
|
|
#else
|
|
|
|
(void)msg; (void)code; (void)desiredStackUnusedSize;
|
2020-08-02 07:52:52 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-11-06 16:53:09 -08:00
|
|
|
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
|
2020-08-01 18:31:23 -07:00
|
|
|
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;
|
|
|
|
|
2020-08-01 18:31:23 -07:00
|
|
|
// 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
|
2020-08-01 18:31:23 -07:00
|
|
|
while (*stackUsage == CH_DBG_STACK_FILL_VALUE) {
|
2019-06-13 05:31:25 -07:00
|
|
|
stackUsage++;
|
|
|
|
}
|
|
|
|
|
2020-08-01 18:31:23 -07:00
|
|
|
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(void) {
|
2019-06-13 05:31:25 -07:00
|
|
|
#if CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
|
|
|
|
|
|
|
|
thread_t* tp = chRegFirstThread();
|
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("name\twabase\ttime\tfree stack");
|
2019-06-13 05:31:25 -07:00
|
|
|
|
2020-08-01 18:31:23 -07:00
|
|
|
while (tp) {
|
|
|
|
int freeBytes = CountFreeStackSpace(tp->wabase);
|
2021-04-21 09:53:13 -07:00
|
|
|
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(OBD_PCM_Processor_Fault, "Ran out of stack on thread %s, %d bytes remain", tp->name, freeBytes);
|
|
|
|
}
|
|
|
|
|
2019-06-13 05:31:25 -07:00
|
|
|
tp = chRegNextThread(tp);
|
|
|
|
}
|
|
|
|
|
2020-08-01 18:31:23 -07:00
|
|
|
int isrSpace = CountFreeStackSpace(reinterpret_cast<void*>(0x20000000));
|
2021-04-21 09:53:13 -07:00
|
|
|
efiPrintf("isr\t0\t0\t%d", isrSpace);
|
2019-06-13 05:31:25 -07:00
|
|
|
|
|
|
|
#else // CH_DBG_THREADS_PROFILING && CH_DBG_FILL_THREADS
|
|
|
|
|
2021-04-21 09:53:13 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-04-20 11:09:41 -07:00
|
|
|
void initializeConsole() {
|
|
|
|
initConsoleLogic();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-04-20 11:09:41 -07:00
|
|
|
startConsole(&handleConsoleLine);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
sayHello();
|
2021-02-19 04:58:52 -08:00
|
|
|
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);
|
|
|
|
}
|