2016-02-20 13:51:02 +00:00
|
|
|
/*
|
2016-03-18 10:29:35 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
2016-02-20 13:51:02 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file shell_cmd.c
|
|
|
|
* @brief Simple CLI shell common commands code.
|
|
|
|
*
|
|
|
|
* @addtogroup SHELL
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
#include "shell.h"
|
|
|
|
#include "shell_cmd.h"
|
|
|
|
#include "chprintf.h"
|
|
|
|
|
|
|
|
#if (SHELL_CMD_TEST_ENABLED == TRUE) || defined(__DOXYGEN__)
|
2016-04-02 07:11:56 +00:00
|
|
|
#include "ch_test.h"
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local definitions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2016-03-22 14:02:36 +00:00
|
|
|
#if ((SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)) || \
|
|
|
|
defined(__DOXYGEN__)
|
|
|
|
static void cmd_exit(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc > 0) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "exit");
|
2016-03-22 14:02:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shellExit(MSG_OK);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 13:51:02 +00:00
|
|
|
#if (SHELL_CMD_INFO_ENABLED == TRUE) || defined(__DOXYGEN__)
|
|
|
|
static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc > 0) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "info");
|
2016-02-20 13:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Kernel: %s"SHELL_NEWLINE_STR, CH_KERNEL_VERSION);
|
2016-02-20 13:51:02 +00:00
|
|
|
#ifdef PORT_COMPILER_NAME
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Compiler: %s"SHELL_NEWLINE_STR, PORT_COMPILER_NAME);
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Architecture: %s"SHELL_NEWLINE_STR, PORT_ARCHITECTURE_NAME);
|
2016-02-20 13:51:02 +00:00
|
|
|
#ifdef PORT_CORE_VARIANT_NAME
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Core Variant: %s"SHELL_NEWLINE_STR, PORT_CORE_VARIANT_NAME);
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef PORT_INFO
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Port Info: %s"SHELL_NEWLINE_STR, PORT_INFO);
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef PLATFORM_NAME
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Platform: %s"SHELL_NEWLINE_STR, PLATFORM_NAME);
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef BOARD_NAME
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Board: %s"SHELL_NEWLINE_STR, BOARD_NAME);
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __DATE__
|
|
|
|
#ifdef __TIME__
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "Build time: %s%s%s"SHELL_NEWLINE_STR, __DATE__, " - ", __TIME__);
|
2016-02-20 13:51:02 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 14:32:35 +00:00
|
|
|
#if (SHELL_CMD_ECHO_ENABLED == TRUE) || defined(__DOXYGEN__)
|
|
|
|
static void cmd_echo(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc != 1) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "echo \"message\"");
|
2016-02-20 14:32:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "%s"SHELL_NEWLINE_STR, argv[0]);
|
2016-02-20 14:32:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 13:51:02 +00:00
|
|
|
#if (SHELL_CMD_SYSTIME_ENABLED == TRUE) || defined(__DOXYGEN__)
|
|
|
|
static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc > 0) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "systime");
|
2016-02-20 13:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "%lu"SHELL_NEWLINE_STR, (unsigned long)chVTGetSystemTime());
|
2016-02-20 13:51:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (SHELL_CMD_MEM_ENABLED == TRUE) || defined(__DOXYGEN__)
|
|
|
|
static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
size_t n, total, largest;
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc > 0) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "mem");
|
2016-02-20 13:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
n = chHeapStatus(NULL, &total, &largest);
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "core free memory : %u bytes"SHELL_NEWLINE_STR, chCoreGetStatusX());
|
|
|
|
chprintf(chp, "heap fragments : %u"SHELL_NEWLINE_STR, n);
|
|
|
|
chprintf(chp, "heap free total : %u bytes"SHELL_NEWLINE_STR, total);
|
|
|
|
chprintf(chp, "heap free largest: %u bytes"SHELL_NEWLINE_STR, largest);
|
2016-02-20 13:51:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (SHELL_CMD_THREADS_ENABLED == TRUE) || defined(__DOXYGEN__)
|
|
|
|
static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
static const char *states[] = {CH_STATE_NAMES};
|
|
|
|
thread_t *tp;
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc > 0) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "threads");
|
2016-02-20 13:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "stklimit stack addr refs prio state name\r\n"SHELL_NEWLINE_STR);
|
2016-02-20 13:51:02 +00:00
|
|
|
tp = chRegFirstThread();
|
|
|
|
do {
|
2016-04-10 12:21:53 +00:00
|
|
|
#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)
|
|
|
|
uint32_t stklimit = (uint32_t)tp->wabase;
|
2016-04-02 16:47:14 +00:00
|
|
|
#else
|
|
|
|
uint32_t stklimit = 0U;
|
|
|
|
#endif
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s"SHELL_NEWLINE_STR,
|
2016-04-02 16:47:14 +00:00
|
|
|
stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp,
|
2016-02-24 14:44:50 +00:00
|
|
|
(uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state],
|
2016-02-20 13:51:02 +00:00
|
|
|
tp->name == NULL ? "" : tp->name);
|
|
|
|
tp = chRegNextThread(tp);
|
|
|
|
} while (tp != NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (SHELL_CMD_TEST_ENABLED == TRUE) || defined(__DOXYGEN__)
|
|
|
|
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|
|
|
thread_t *tp;
|
|
|
|
|
|
|
|
(void)argv;
|
|
|
|
if (argc > 0) {
|
2016-04-10 12:14:23 +00:00
|
|
|
shellUsage(chp, "test");
|
2016-02-20 13:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-21 10:45:42 +00:00
|
|
|
tp = chThdCreateFromHeap(NULL, SHELL_CMD_TEST_WA_SIZE,
|
|
|
|
"test", chThdGetPriorityX(),
|
2016-04-02 07:11:56 +00:00
|
|
|
(tfunc_t)test_execute, chp);
|
2016-02-20 13:51:02 +00:00
|
|
|
if (tp == NULL) {
|
2016-04-10 12:14:23 +00:00
|
|
|
chprintf(chp, "out of memory"SHELL_NEWLINE_STR);
|
2016-02-20 13:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
chThdWait(tp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Array of the default commands.
|
|
|
|
*/
|
|
|
|
ShellCommand shell_local_commands[] = {
|
2016-03-22 14:02:36 +00:00
|
|
|
#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
|
|
|
|
{"exit", cmd_exit},
|
|
|
|
#endif
|
2016-02-20 13:51:02 +00:00
|
|
|
#if SHELL_CMD_INFO_ENABLED == TRUE
|
|
|
|
{"info", cmd_info},
|
|
|
|
#endif
|
2016-02-20 14:32:35 +00:00
|
|
|
#if SHELL_CMD_ECHO_ENABLED == TRUE
|
|
|
|
{"echo", cmd_echo},
|
|
|
|
#endif
|
2016-02-20 13:51:02 +00:00
|
|
|
#if SHELL_CMD_SYSTIME_ENABLED == TRUE
|
|
|
|
{"systime", cmd_systime},
|
|
|
|
#endif
|
|
|
|
#if SHELL_CMD_MEM_ENABLED == TRUE
|
|
|
|
{"mem", cmd_mem},
|
|
|
|
#endif
|
|
|
|
#if SHELL_CMD_THREADS_ENABLED == TRUE
|
|
|
|
{"threads", cmd_threads},
|
|
|
|
#endif
|
|
|
|
#if SHELL_CMD_TEST_ENABLED == TRUE
|
|
|
|
{"test", cmd_test},
|
|
|
|
#endif
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @} */
|