shell: split kernel shell into separate module

Add kernel functions to kernel module and make it part
of the shell sample.

Change-Id: If5e8ff8ce7b8edbbb8d62509964700b007eaf88b
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2016-11-04 08:09:17 -04:00 committed by Anas Nashif
parent 559b46f37d
commit b27d3a8a60
6 changed files with 70 additions and 37 deletions

View file

@ -7,3 +7,14 @@ config ENABLE_SHELL
Enabling shell services. If it is enabled, kernel shell commands are
also available for use.
if ENABLE_SHELL
config KERNEL_SHELL
bool "Enable kernel shell"
default n
help
This shell provides access to basic kernel data like version, uptime
and other useful information.
endif

View file

@ -1 +1,2 @@
obj-$(CONFIG_ENABLE_SHELL) += shell_service.o
obj-$(CONFIG_KERNEL_SHELL) += kernel_service.o

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* 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.
*/
#include <misc/printk.h>
#include <misc/shell.h>
#include <init.h>
#define SHELL_KERNEL "kernel"
static int shell_cmd_version(int argc, char *argv[])
{
uint32_t version = sys_kernel_version_get();
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[])
{
printk("uptime: %u ms\n", k_uptime_get_32());
return 0;
}
static int shell_cmd_cycles(int argc, char *argv[])
{
printk("cycles: %u hw cycles\n", k_cycle_get_32());
return 0;
}
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" },
{ NULL, NULL }
};
SHELL_REGISTER(SHELL_KERNEL, kernel_commands);

View file

@ -26,33 +26,13 @@
#include <misc/shell.h>
#include <init.h>
#define SHELL_KERNEL "kernel"
#define SHELL_PROMPT "shell> "
static int shell_cmd_version(int argc, char *argv[])
{
uint32_t version = sys_kernel_version_get();
printk("Zephyr version %d.%d.%d\n",
SYS_KERNEL_VER_MAJOR(version),
SYS_KERNEL_VER_MINOR(version),
SYS_KERNEL_VER_PATCHLEVEL(version));
return 0;
}
struct shell_cmd kernel_commands[] = {
{ "version", shell_cmd_version, "show kernel version" },
{ NULL, NULL }
};
int shell_run(struct device *dev)
{
ARG_UNUSED(dev);
shell_init(SHELL_PROMPT);
SHELL_REGISTER(SHELL_KERNEL, kernel_commands);
return 0;
}

View file

@ -2,3 +2,4 @@ CONFIG_CONSOLE_HANDLER=y
CONFIG_CONSOLE_HANDLER_SHELL=y
CONFIG_ENABLE_SHELL=y
CONFIG_PRINTK=y
CONFIG_KERNEL_SHELL=y

View file

@ -40,29 +40,12 @@ static int shell_cmd_params(int argc, char *argv[])
return 0;
}
static int shell_cmd_uptime(int argc, char *argv[])
{
printk("uptime: %u ms\n", k_uptime_get_32());
return 0;
}
static int shell_cmd_cycles(int argc, char *argv[])
{
printk("cycles: %u hw cycles\n", k_cycle_get_32());
return 0;
}
#ifdef CONFIG_SAMPLE_MODULE_USE_SHELL
#define MY_SHELL_MODULE "sample_module"
static struct shell_cmd commands[] = {
{ "ping", shell_cmd_ping },
{ "uptime", shell_cmd_uptime },
{ "cycles", shell_cmd_cycles },
{ "params", shell_cmd_params, "print argc" },
{ NULL, NULL }
};