2016-11-04 20:09:17 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-11-04 20:09:17 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <misc/printk.h>
|
2016-12-24 03:06:46 +08:00
|
|
|
#include <shell/shell.h>
|
2016-11-04 20:09:17 +08:00
|
|
|
#include <init.h>
|
2016-12-24 20:10:20 +08:00
|
|
|
#include <debug/object_tracing.h>
|
2016-11-04 20:09:17 +08:00
|
|
|
|
|
|
|
#define SHELL_KERNEL "kernel"
|
|
|
|
|
|
|
|
static int shell_cmd_version(int argc, char *argv[])
|
|
|
|
{
|
2017-04-21 22:36:04 +08:00
|
|
|
u32_t version = sys_kernel_version_get();
|
2016-11-04 20:09:17 +08:00
|
|
|
|
2016-12-21 14:11:41 +08:00
|
|
|
ARG_UNUSED(argc);
|
|
|
|
ARG_UNUSED(argv);
|
|
|
|
|
2016-11-04 20:09:17 +08:00
|
|
|
printk("Zephyr version %d.%d.%d\n",
|
|
|
|
SYS_KERNEL_VER_MAJOR(version),
|
|
|
|
SYS_KERNEL_VER_MINOR(version),
|
|
|
|
SYS_KERNEL_VER_PATCHLEVEL(version));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shell_cmd_uptime(int argc, char *argv[])
|
|
|
|
{
|
2016-12-21 14:11:41 +08:00
|
|
|
ARG_UNUSED(argc);
|
|
|
|
ARG_UNUSED(argv);
|
|
|
|
|
2016-11-04 20:09:17 +08:00
|
|
|
printk("uptime: %u ms\n", k_uptime_get_32());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shell_cmd_cycles(int argc, char *argv[])
|
|
|
|
{
|
2016-12-21 14:11:41 +08:00
|
|
|
ARG_UNUSED(argc);
|
|
|
|
ARG_UNUSED(argv);
|
|
|
|
|
2016-11-04 20:09:17 +08:00
|
|
|
printk("cycles: %u hw cycles\n", k_cycle_get_32());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-24 20:10:20 +08:00
|
|
|
#if defined(CONFIG_OBJECT_TRACING) && defined(CONFIG_THREAD_MONITOR)
|
2017-12-02 04:44:26 +08:00
|
|
|
static int shell_cmd_threads(int argc, char *argv[])
|
2016-12-24 20:10:20 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(argc);
|
|
|
|
ARG_UNUSED(argv);
|
|
|
|
struct k_thread *thread_list = NULL;
|
|
|
|
|
2017-12-02 04:44:26 +08:00
|
|
|
printk("Threads:\n");
|
2016-12-24 20:10:20 +08:00
|
|
|
|
|
|
|
thread_list = (struct k_thread *)SYS_THREAD_MONITOR_HEAD;
|
|
|
|
while (thread_list != NULL) {
|
2017-01-23 02:05:08 +08:00
|
|
|
printk("%s%p: options: 0x%x priority: %d\n",
|
2016-12-24 20:10:20 +08:00
|
|
|
(thread_list == k_current_get()) ? "*" : " ",
|
|
|
|
thread_list,
|
2017-01-23 02:05:08 +08:00
|
|
|
thread_list->base.user_options,
|
2016-12-24 20:10:20 +08:00
|
|
|
k_thread_priority_get(thread_list));
|
|
|
|
thread_list = (struct k_thread *)SYS_THREAD_MONITOR_NEXT(thread_list);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-04 20:09:17 +08:00
|
|
|
|
2017-01-10 21:41:12 +08:00
|
|
|
#if defined(CONFIG_INIT_STACKS)
|
|
|
|
static int shell_cmd_stack(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
k_call_stacks_analyze();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-04 20:09:17 +08:00
|
|
|
struct shell_cmd kernel_commands[] = {
|
|
|
|
{ "version", shell_cmd_version, "show kernel version" },
|
|
|
|
{ "uptime", shell_cmd_uptime, "show system uptime in milliseconds" },
|
|
|
|
{ "cycles", shell_cmd_cycles, "show system hardware cycles" },
|
2016-12-24 20:10:20 +08:00
|
|
|
#if defined(CONFIG_OBJECT_TRACING) && defined(CONFIG_THREAD_MONITOR)
|
2017-12-02 04:44:26 +08:00
|
|
|
{ "threads", shell_cmd_threads, "show running threads" },
|
2017-01-10 21:41:12 +08:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_INIT_STACKS)
|
|
|
|
{ "stacks", shell_cmd_stack, "show system stacks" },
|
2016-12-24 20:10:20 +08:00
|
|
|
#endif
|
2016-12-21 14:11:41 +08:00
|
|
|
{ NULL, NULL, NULL }
|
2016-11-04 20:09:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SHELL_REGISTER(SHELL_KERNEL, kernel_commands);
|