You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2025/11/07 16:53:18 UTC
(mynewt-core) 18/26: hw/battery: Register module statically
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit fe69c608dcf2f640bd638a34e8a089f6f9e6e0d4
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 4 19:30:15 2025 +0200
hw/battery: Register module statically
Now bat shell module is registered at link time to
reduce memory footprint.
No change in functionality.
Signed-off-by: Jerzy Kasenberg <je...@apache.org>
---
hw/battery/include/battery/battery.h | 4 --
hw/battery/pkg.yml | 2 +
hw/battery/src/battery.c | 4 --
hw/battery/src/battery_shell.c | 84 +-----------------------------------
4 files changed, 3 insertions(+), 91 deletions(-)
diff --git a/hw/battery/include/battery/battery.h b/hw/battery/include/battery/battery.h
index 50500a37a..de635e88a 100644
--- a/hw/battery/include/battery/battery.h
+++ b/hw/battery/include/battery/battery.h
@@ -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
-
/**
* }@
*/
diff --git a/hw/battery/pkg.yml b/hw/battery/pkg.yml
index dd0799b9b..bce2de6b1 100644
--- a/hw/battery/pkg.yml
+++ b/hw/battery/pkg.yml
@@ -28,5 +28,7 @@ pkg.deps:
pkg.req_apis:
- console
+pkg.whole_archive: true
+
pkg.init:
battery_pkg_init: 'MYNEWT_VAL(BATTERY_SYSINIT_STAGE)'
diff --git a/hw/battery/src/battery.c b/hw/battery/src/battery.c
index 892f2d298..61f03ac7c 100644
--- a/hw/battery/src/battery.c
+++ b/hw/battery/src/battery.c
@@ -142,10 +142,6 @@ battery_pkg_init(void)
SYSINIT_ASSERT_ACTIVE();
battery_mgr_init();
-
-#if MYNEWT_VAL(BATTERY_SHELL)
- battery_shell_register();
-#endif
}
int
diff --git a/hw/battery/src/battery_shell.c b/hw/battery/src/battery_shell.c
index 3455ec604..3ce2b1db6 100644
--- a/hw/battery/src/battery_shell.c
+++ b/hw/battery/src/battery_shell.c
@@ -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)
@@ -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",
@@ -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