Skip to content

update shell commands to static registration #3453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
95b9ef2
fs/fs_cli: Register commands statically
kasjer May 31, 2025
220ad30
sys/stats: Register commands statically
kasjer May 31, 2025
595f5df
test/flash_test: Register commands statically
kasjer May 31, 2025
17bc4b5
util/coremark: Register commands statically
kasjer May 31, 2025
d5e5313
sys/log: Register commands statically
kasjer May 31, 2025
25c7c79
test/crash_test: Register commands statically
kasjer Jun 1, 2025
fc3d1f7
sys/config: Register commands statically
kasjer Jun 1, 2025
e78670f
mgmt/imgmgr: Register commands statically
kasjer Jun 1, 2025
f9c9886
tinyusb: Register shell module statically
kasjer Jun 1, 2025
6de09f7
test/spiflash_stress_test: Register command statically
kasjer Jun 1, 2025
dea92e3
sys/fault: Register command statically
kasjer Jun 1, 2025
d8120c2
test/i2c_scan: Register command statically
kasjer Jun 1, 2025
3aac3cc
stm32f4/mcu_cli: Register shell module statically
kasjer Jun 1, 2025
50236ba
stm32f1/mcu_cli: Register shell module statically
kasjer Jun 1, 2025
342fa38
drivers/bq27z561: Register command statically
kasjer Jun 4, 2025
f38611e
drivers/ina219: Register command statically
kasjer Jun 4, 2025
be4a051
drivers/ina226: Register command statically
kasjer Jun 4, 2025
3cde312
hw/battery: Register module statically
kasjer Jun 4, 2025
ddf90d2
net/lora: Register commands statically
kasjer Jun 6, 2025
930c1dd
drivers/adp5061: Register command statically
kasjer Jun 6, 2025
00947cb
drivers/lsm6dso: Register command statically
kasjer Jun 6, 2025
f13b4a1
drivers/ds3231: Register command statically
kasjer Jun 6, 2025
810fa5c
drivers/bme280: Register command statically
kasjer Jun 6, 2025
e9e0561
drivers/bmp280: Register command statically
kasjer Jun 6, 2025
23e654f
drivers/ds1307: Register command statically
kasjer Jun 6, 2025
b77d8f2
drivers/adxl345: Register command statically
kasjer Jun 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fs/fs/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ pkg.deps.FS_CLI:

pkg.deps.FS_MGMT:
- "@apache-mynewt-mcumgr/cmd/fs/port/mynewt"

pkg.whole_archive: true
42 changes: 6 additions & 36 deletions fs/fs/src/fs_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,6 @@

#include "fs/fs.h"

static int fs_ls_cmd(int argc, char **argv);
static int fs_rm_cmd(int argc, char **argv);
static int fs_mkdir_cmd(int argc, char **argv);
static int fs_mv_cmd(int argc, char **argv);
static int fs_cat_cmd(int argc, char **argv);

static struct shell_cmd fs_ls_struct = {
.sc_cmd = "ls",
.sc_cmd_func = fs_ls_cmd
};
static struct shell_cmd fs_rm_struct = {
.sc_cmd = "rm",
.sc_cmd_func = fs_rm_cmd
};
static struct shell_cmd fs_mkdir_struct = {
.sc_cmd = "mkdir",
.sc_cmd_func = fs_mkdir_cmd
};
static struct shell_cmd fs_mv_struct = {
.sc_cmd = "mv",
.sc_cmd_func = fs_mv_cmd
};
static struct shell_cmd fs_cat_struct = {
.sc_cmd = "cat",
.sc_cmd_func = fs_cat_cmd
};

static void
fs_ls_file(const char *name, struct fs_file *file)
{
Expand Down Expand Up @@ -220,13 +193,10 @@ fs_cat_cmd(int argc, char **argv)
return 0;
}

void
fs_cli_init(void)
{
shell_cmd_register(&fs_ls_struct);
shell_cmd_register(&fs_rm_struct);
shell_cmd_register(&fs_mkdir_struct);
shell_cmd_register(&fs_mv_struct);
shell_cmd_register(&fs_cat_struct);
}
MAKE_SHELL_CMD(ls, fs_ls_cmd, NULL)
MAKE_SHELL_CMD(rm, fs_rm_cmd, NULL)
MAKE_SHELL_CMD(mkdir, fs_mkdir_cmd, NULL)
MAKE_SHELL_CMD(mv, fs_mv_cmd, NULL)
MAKE_SHELL_CMD(cat, fs_cat_cmd, NULL)

#endif /* MYNEWT_VAL(FS_CLI) */
11 changes: 0 additions & 11 deletions fs/fs/src/fs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@

static SLIST_HEAD(, fs_ops) root_fops = SLIST_HEAD_INITIALIZER();

#if MYNEWT_VAL(FS_CLI)
static uint8_t g_cli_initialized;
#endif

#if MYNEWT_VAL(FS_MGMT)
static uint8_t g_mgmt_initialized;
#endif
Expand All @@ -49,13 +45,6 @@ fs_register(struct fs_ops *fops)

SLIST_INSERT_HEAD(&root_fops, fops, sc_next);

#if MYNEWT_VAL(FS_CLI)
if (!g_cli_initialized) {
fs_cli_init();
g_cli_initialized = 1;
}
#endif

#if MYNEWT_VAL(FS_MGMT)
if (!g_mgmt_initialized) {
fs_mgmt_register_group();
Expand Down
3 changes: 0 additions & 3 deletions fs/fs/src/fs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ struct fs_ops;
struct fs_ops *fs_ops_for(const char *fs_name);
struct fs_ops *safe_fs_ops_for(const char *fs_name);

#if MYNEWT_VAL(FS_CLI)
void fs_cli_init(void);
#endif

#ifdef __cplusplus
}
Expand Down
4 changes: 0 additions & 4 deletions hw/battery/include/battery/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,6 @@ int battery_get_driver_count(struct os_dev *battery);
struct battery_driver *get_battery_driver(struct os_dev *battery,
const char *dev_name);

#if MYNEWT_VAL(BATTERY_SHELL)
void battery_shell_register(void);
#endif

/**
* }@
*/
Expand Down
2 changes: 2 additions & 0 deletions hw/battery/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ pkg.deps:
pkg.req_apis:
- console

pkg.whole_archive: true

pkg.init:
battery_pkg_init: 'MYNEWT_VAL(BATTERY_SYSINIT_STAGE)'
4 changes: 0 additions & 4 deletions hw/battery/src/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ battery_pkg_init(void)
SYSINIT_ASSERT_ACTIVE();

battery_mgr_init();

#if MYNEWT_VAL(BATTERY_SHELL)
battery_shell_register();
#endif
}

int
Expand Down
84 changes: 1 addition & 83 deletions hw/battery/src/battery_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include <battery/battery.h>
#include <battery/battery_prop.h>

static int bat_compat_cmd(int argc, char **argv);

#if MYNEWT_VAL(SHELL_CMD_HELP)
#define HELP(a) &(a)

Expand Down Expand Up @@ -78,37 +76,6 @@ static const struct shell_cmd_help bat_monitor_help = {
#define HELP(a) NULL
#endif

static const struct shell_cmd bat_cli_cmd = {
.sc_cmd = "bat",
.sc_cmd_func = bat_compat_cmd,
};

/**
* cmd bat help
*
* Help for the bat command.
*
*/
static void
cmd_bat_help(void)
{
console_printf("Usage: bat <cmd> [options]\n");
console_printf("Available bat commands:\n");
console_printf(" pollrate <time_in_s>\n");
console_printf(" monitor [<prop>] [off]\n");
console_printf(" list\n");
console_printf(" read [<prop>] | all\n");
console_printf(" write <prop> <value>\n");

console_printf("Examples:\n");
console_printf(" list\n");
console_printf(" monitor VoltageADC\n");
console_printf(" monitor off\n");
console_printf(" read Voltage\n");
console_printf(" read all\n");
console_printf(" write VoltageLoAlarmSet\n");
}

static const char *bat_status[] = {
"???",
"charging",
Expand Down Expand Up @@ -482,57 +449,8 @@ static const struct shell_cmd bat_cli_commands[] = {
SHELL_CMD("list", cmd_bat_list, &bat_list_help),
SHELL_CMD("pollrate", cmd_bat_poll_rate, &bat_poll_rate_help),
SHELL_CMD("monitor", cmd_bat_monitor, &bat_monitor_help),
{ 0 },
};

/**
* bat cmd
*
* Main processing function for K4 cli bat command
*
* @param argc Number of arguments
* @param argv Argument list
*
* @return int 0: success, -1 error
*/
static int
bat_compat_cmd(int argc, char **argv)
{
int rc;
int i;

if (argc < 2) {
rc = SYS_EINVAL;
} else {
for (i = 0; bat_cli_commands[i].sc_cmd; ++i) {
if (strcmp(bat_cli_commands[i].sc_cmd, argv[1]) == 0) {
rc = bat_cli_commands[i].sc_cmd_func(argc - 1, argv + 1);
break;
}
}
/* No command found */
if (bat_cli_commands[i].sc_cmd == NULL) {
console_printf("Invalid command.\n");
rc = -1;
}
}

/* Print help in case of error */
if (rc) {
cmd_bat_help();
}

return rc;
}

void
battery_shell_register(void)
{
int rc;

rc = shell_register("bat", bat_cli_commands);
rc = shell_cmd_register(&bat_cli_cmd);
SYSINIT_PANIC_ASSERT_MSG(rc == 0, "Failed to register battery shell");
}
SHELL_MODULE_WITH_TABLE(bat, bat_cli_commands)

#endif
9 changes: 0 additions & 9 deletions hw/drivers/bq27z561/include/bq27z561/bq27z561.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,6 @@ int bq27z561_config(struct bq27z561 * bq27z561, struct bq27z561_cfg * cfg);
*/
int bq27z561_init(struct os_dev * dev, void * arg);

#if MYNEWT_VAL(BQ27Z561_CLI)
/**
* Initialize the BQ27Z561 shell extensions.
*
* @return 0 on success, non-zero on failure.
*/
int bq27z561_shell_init(void);
#endif

#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
/**
* Create I2C bus node for BQ27Z561
Expand Down
4 changes: 2 additions & 2 deletions hw/drivers/bq27z561/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pkg.deps.BUS_DRIVER_PRESENT:
pkg.req_apis:
- stats

pkg.whole_archive: true

pkg.deps.BQ27Z561_CLI:
- "@apache-mynewt-core/util/parse"

pkg.init:
bq27z561_pkg_init: 'MYNEWT_VAL(BQ27Z561_SYSINIT_STAGE)'
9 changes: 0 additions & 9 deletions hw/drivers/bq27z561/src/bq27z561.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,15 +1348,6 @@ bq27z561_init(struct os_dev *dev, void *arg)
return 0;
}

int bq27z561_pkg_init(void)
{
#if MYNEWT_VAL(BQ27Z561_CLI)
return bq27z561_shell_init();
#else
return 0;
#endif
}

#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
static void
init_node_cb(struct bus_node *bnode, void *arg)
Expand Down
11 changes: 1 addition & 10 deletions hw/drivers/bq27z561/src/bq27z561_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,6 @@ bq27z561_shell_cmd(int argc, char * argv[])
return 0;
}

static const struct shell_cmd bq27z561_shell_cmd_desc = {
.sc_cmd = "bq27z561",
.sc_cmd_func = bq27z561_shell_cmd,
};

int
bq27z561_shell_init(void)
{
return shell_cmd_register(&bq27z561_shell_cmd_desc);
}
MAKE_SHELL_CMD(bq27z561, bq27z561_shell_cmd, NULL)

#endif
4 changes: 0 additions & 4 deletions hw/drivers/bq27z561/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ syscfg.defs:
description: >
Number of OS ticks to wait for each I2C transaction to complete.
value: 6
BQ27Z561_SYSINIT_STAGE:
description: >
Sysinit stage for the BQ27Z561 driver.
value: 500

### Log settings.

Expand Down
2 changes: 2 additions & 0 deletions hw/drivers/chg_ctrl/adp5061/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ pkg.deps.!BUS_DRIVER_PRESENT||ADP5061_USE_CHARGE_CONTROL:
pkg.deps.ADP5061_CLI:
- '@apache-mynewt-core/sys/shell'
- '@apache-mynewt-core/util/parse'

pkg.whole_archive: true
5 changes: 0 additions & 5 deletions hw/drivers/chg_ctrl/adp5061/src/adp5061.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <os/mynewt.h>
#include <console/console.h>
#include <mcu/nrf52_hal.h>
#include <hal/hal_gpio.h>
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
#include "bus/drivers/i2c_common.h"
Expand Down Expand Up @@ -675,10 +674,6 @@ adp5061_init(struct os_dev *dev, void *arg)
}
#endif /* ADP5061_USE_CHARGE_CONTROL */

#if MYNEWT_VAL(ADP5061_CLI)
adp5061_shell_init(adp5061);
#endif

return 0;
err:
return rc;
Expand Down
17 changes: 4 additions & 13 deletions hw/drivers/chg_ctrl/adp5061/src/adp5061_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,6 @@ static const struct adp5061_reg adp5061_device_regs[] = {
#define NUM_DEVICE_REGS (sizeof(adp5061_device_regs)\
/sizeof(adp5061_device_regs[0]))

static int adp5061_shell_cmd(int argc, char **argv);

static const struct shell_cmd adp5061_shell_cmd_struct = {
.sc_cmd = "adp5061",
.sc_cmd_func = adp5061_shell_cmd
};

static int
adp5061_shell_err_too_many_args(const char *cmd_name)
{
Expand Down Expand Up @@ -665,7 +658,7 @@ adp5061_shell_err_missing_arg(const char *cmd_name)
static int
adp5061_shell_help(void)
{
console_printf("%s cmd\n", adp5061_shell_cmd_struct.sc_cmd);
console_printf("adp5061 cmd\n");
console_printf("cmd:\n");
console_printf("\thelp\n");
#if MYNEWT_VAL(ADP5061_CLI_DECODE)
Expand Down Expand Up @@ -970,16 +963,14 @@ adp5061_shell_cmd(int argc, char **argv)
return adp5061_shell_err_unknown_arg(argv[1]);
}

MAKE_SHELL_CMD(adp5061, adp5061_shell_cmd, NULL);

int
adp5061_shell_init(struct adp5061_dev *dev)
{
int rc;

adp5061_dev = dev;
rc = shell_cmd_register(&adp5061_shell_cmd_struct);
SYSINIT_PANIC_ASSERT(rc == 0);

return rc;
return 0;
}

#endif
11 changes: 8 additions & 3 deletions hw/drivers/rtc/ds1307/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ pkg.req_apis:
- log
- stats

pkg.whole_archive: true

pkg.source_files:
- src/ds1307.c

pkg.source_files.DS1307_CLI:
- src/ds1307_shell.c

pkg.init:
ds1307_pkg_init: 601

pkg.init.DS1307_CLI:
ds1307_shell_init: 1000
Loading
Loading