Skip to content
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

sys/shell: reduce overhead of XFA shell commands #20958

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion examples/rust-async/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/rust-gcoap/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/rust-hello-world/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,14 @@ int shell_parse_file(const shell_command_t *commands,
* ```
*/
#define SHELL_COMMAND(cmd, help, func) \
XFA_USE_CONST(shell_command_xfa_t*, shell_commands_xfa); \
XFA_USE_CONST(shell_command_xfa_t, shell_commands_xfa_v2); \
mguetschow marked this conversation as resolved.
Show resolved Hide resolved
static FLASH_ATTR const char _xfa_ ## cmd ## _cmd_name[] = #cmd; \
static FLASH_ATTR const char _xfa_ ## cmd ## _cmd_desc[] = help; \
static const shell_command_xfa_t _xfa_ ## cmd ## _cmd = { \
XFA_CONST(shell_command_xfa_t, shell_commands_xfa_v2, 0) _xfa_ ## cmd ## _cmd = { \
.name = _xfa_ ## cmd ## _cmd_name, \
.desc = _xfa_ ## cmd ## _cmd_desc, \
.handler = &func \
}; \
XFA_ADD_PTR(shell_commands_xfa, cmd, cmd, &_xfa_ ## cmd ## _cmd)
};
#endif /* __cplusplus */

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion sys/rust_riotmodules_standalone/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <assert.h>
#include <errno.h>

#include "kernel_defines.h"
#include "xfa.h"
#include "shell.h"
#include "shell_lock.h"
Expand All @@ -47,7 +46,7 @@
#endif

/* define shell command cross file array */
XFA_INIT_CONST(shell_command_xfa_t*, shell_commands_xfa);
XFA_INIT_CONST(shell_command_xfa_t, shell_commands_xfa_v2);

#define ETX '\x03' /** ASCII "End-of-Text", or Ctrl-C */
#define EOT '\x04' /** ASCII "End-of-Transmission", or Ctrl-D */
Expand Down Expand Up @@ -102,10 +101,10 @@ static shell_command_handler_t search_commands(const shell_command_t *entry,

static shell_command_handler_t search_commands_xfa(char *command)
{
unsigned n = XFA_LEN(shell_command_t*, shell_commands_xfa);
unsigned n = XFA_LEN(shell_command_t, shell_commands_xfa_v2);

for (unsigned i = 0; i < n; i++) {
const volatile shell_command_xfa_t *entry = shell_commands_xfa[i];
const volatile shell_command_xfa_t *entry = &shell_commands_xfa_v2[i];
if (flash_strcmp(command, entry->name) == 0) {
return entry->handler;
}
Expand Down Expand Up @@ -147,15 +146,15 @@ static void print_commands_json(const shell_command_t *cmd_list)
}
}

unsigned n = XFA_LEN(shell_command_xfa_t*, shell_commands_xfa);
unsigned n = XFA_LEN(shell_command_xfa_t, shell_commands_xfa_v2);
for (unsigned i = 0; i < n; i++) {
if (first) {
first = false;
}
else {
printf(", ");
}
const volatile shell_command_xfa_t *entry = shell_commands_xfa[i];
const volatile shell_command_xfa_t *entry = &shell_commands_xfa_v2[i];
printf("{\"cmd\": \"%s\", \"desc\": \"%s\"}", entry->name, entry->desc);
}
puts("]}");
Expand All @@ -170,9 +169,9 @@ static void print_commands(const shell_command_t *entry)

static void print_commands_xfa(void)
{
unsigned n = XFA_LEN(shell_command_xfa_t*, shell_commands_xfa);
unsigned n = XFA_LEN(shell_command_xfa_t, shell_commands_xfa_v2);
for (unsigned i = 0; i < n; i++) {
const volatile shell_command_xfa_t *entry = shell_commands_xfa[i];
const volatile shell_command_xfa_t *entry = &shell_commands_xfa_v2[i];
printf("%-20" PRIsflash " %" PRIsflash "\n",
entry->name, entry->desc);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/rust_minimal/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading