From 30a334288fa4db90ce0a3ef4e6d2a7e4395b6ee4 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 17 May 2020 15:43:00 -0700 Subject: [PATCH] [lib][console] move the command block private stuff into lib/console Pull some of the machinery of the lib/console stuff into a private header that is only pulled in when lib/console is built. --- lib/console/include/lib/console.h | 1 + lib/console/include/lib/console/cmd.h | 53 +++++++++++++++++++++++++++ top/include/lk/console_cmd.h | 31 +--------------- 3 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 lib/console/include/lib/console/cmd.h diff --git a/lib/console/include/lib/console.h b/lib/console/include/lib/console.h index 177d6f22..bbcbc584 100644 --- a/lib/console/include/lib/console.h +++ b/lib/console/include/lib/console.h @@ -14,6 +14,7 @@ * this file. */ #include +#include /* external api */ int console_init(void); diff --git a/lib/console/include/lib/console/cmd.h b/lib/console/include/lib/console/cmd.h new file mode 100644 index 00000000..d5ba21b6 --- /dev/null +++ b/lib/console/include/lib/console/cmd.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2008-2009 Travis Geiselbrecht + * + * Use of this source code is governed by a MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT + */ +#pragma once + +#include +#include +#include + +/* included from top level lk/console_cmd.h when lib/console is built. + * Provides definitions for how to register a command block to be picked up by + * the lib/console machinery. + */ + +/* an individual command */ +typedef struct { + const char *cmd_str; + const char *help_str; + const console_cmd cmd_callback; + uint8_t availability_mask; +} cmd; + +/* a block of commands to register */ +typedef struct _cmd_block { + struct _cmd_block *next; + size_t count; + const cmd *list; +} cmd_block; + +#define STATIC_COMMAND_START static const cmd _cmd_list[] = { + +#define STATIC_COMMAND_END(name) }; cmd_block _cmd_block_##name \ + __ALIGNED(sizeof(void *)) __SECTION("commands") = \ + { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list } + +/* same as above but with a suffixed name to make the list unique within the file */ +#define STATIC_COMMAND_START_NAMED(name) static const cmd _cmd_list_##name[] = { + +#define STATIC_COMMAND_END_NAMED(name) }; cmd_block _cmd_block_##name \ + __ALIGNED(sizeof(void *)) __SECTION("commands") = \ + { NULL, sizeof(_cmd_list_##name) / sizeof(_cmd_list_##name[0]), _cmd_list_##name } + +#define STATIC_COMMAND(command_str, help_str, func) \ + { command_str, help_str, func, CMD_AVAIL_NORMAL }, + +#define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) \ + { command_str, help_str, func, availability_mask }, + + diff --git a/top/include/lk/console_cmd.h b/top/include/lk/console_cmd.h index d24d2ddf..8a12582a 100644 --- a/top/include/lk/console_cmd.h +++ b/top/include/lk/console_cmd.h @@ -27,39 +27,14 @@ typedef int (*console_cmd)(int argc, const cmd_args *argv); #define CMD_AVAIL_PANIC (0x1 << 1) #define CMD_AVAIL_ALWAYS (CMD_AVAIL_NORMAL | CMD_AVAIL_PANIC) -/* a block of commands to register */ -typedef struct { - const char *cmd_str; - const char *help_str; - const console_cmd cmd_callback; - uint8_t availability_mask; -} cmd; - -typedef struct _cmd_block { - struct _cmd_block *next; - size_t count; - const cmd *list; -} cmd_block; - /* Register a static block of commands at init time when lib/console is * paret of the build. Otherwise stub out these definitions so that they do * not get included. */ #if WITH_LIB_CONSOLE -#define STATIC_COMMAND_START static const cmd _cmd_list[] = { - -#define STATIC_COMMAND_END(name) }; cmd_block _cmd_block_##name __ALIGNED(sizeof(void *)) __SECTION("commands") = \ - { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list } - -/* same as above but with a suffixed name to make the list unique within the file */ -#define STATIC_COMMAND_START_NAMED(name) static const cmd _cmd_list_##name[] = { - -#define STATIC_COMMAND_END_NAMED(name) }; cmd_block _cmd_block_##name __ALIGNED(sizeof(void *)) __SECTION("commands") = \ - { NULL, sizeof(_cmd_list_##name) / sizeof(_cmd_list_##name[0]), _cmd_list_##name } - -#define STATIC_COMMAND(command_str, help_str, func) { command_str, help_str, func, CMD_AVAIL_NORMAL }, -#define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) { command_str, help_str, func, availability_mask }, +/* pull the equivalent strctures and macros out of lib/console's headers */ +#include #else @@ -73,5 +48,3 @@ typedef struct _cmd_block { #define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) #endif - -#define COMMAND_BLOCK_INIT_ITEM(cmd_block_ptr, cmd_ptr) {(cmd_block_ptr)->next = NULL; (cmd_block_ptr)->count = 1; (cmd_block_ptr)->list = cmd_ptr;}