From 3699da5cbd56360750c73032f48328acb44b212a Mon Sep 17 00:00:00 2001 From: astralien3000 Date: Wed, 14 Feb 2018 20:08:44 +0100 Subject: [PATCH 1/2] added shell_commands.ld --- cpu/cortexm_common/ldscripts/cortexm_base.ld | 2 +- sys/Makefile.include | 9 ++ sys/include/shell_commands.h | 2 +- sys/shell/commands/shell_commands.c | 133 ++++++------------- sys/shell/commands/shell_commands.ld | 9 ++ sys/shell/commands/shell_commands_cortexm.ld | 9 ++ sys/shell/shell.c | 4 +- 7 files changed, 73 insertions(+), 95 deletions(-) create mode 100644 sys/shell/commands/shell_commands.ld create mode 100644 sys/shell/commands/shell_commands_cortexm.ld diff --git a/cpu/cortexm_common/ldscripts/cortexm_base.ld b/cpu/cortexm_common/ldscripts/cortexm_base.ld index f97a9babde04..9a5f95b3147d 100644 --- a/cpu/cortexm_common/ldscripts/cortexm_base.ld +++ b/cpu/cortexm_common/ldscripts/cortexm_base.ld @@ -115,7 +115,7 @@ SECTIONS _estack = .; } > ram - .relocate : AT (_etext) + .data : AT (_etext) { . = ALIGN(4); _srelocate = .; diff --git a/sys/Makefile.include b/sys/Makefile.include index 24b8c7259b11..72a0968634b3 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -86,3 +86,12 @@ endif ifneq (native,$(BOARD)) INCLUDES += -I$(RIOTBASE)/sys/libc/include endif + +ifneq (,$(filter shell_commands,$(USEMODULE))) +ifneq (,$(filter cortexm_common,$(USEMODULE))) + LINKFLAGS += $(RIOTBASE)/sys/shell/commands/shell_commands_cortexm.ld +else + LINKFLAGS += $(RIOTBASE)/sys/shell/commands/shell_commands.ld +endif + UNDEF += $(BINDIR)/shell_commands/shell_commands.o +endif diff --git a/sys/include/shell_commands.h b/sys/include/shell_commands.h index 0c306d093da0..a2447ccc2087 100644 --- a/sys/include/shell_commands.h +++ b/sys/include/shell_commands.h @@ -32,7 +32,7 @@ extern "C" { #define DISK_READ_SECTOR_CMD "dread_sec" #define DISK_READ_BYTES_CMD "dread" -extern const shell_command_t _shell_command_list[]; +extern const shell_command_t _shell_command_list; #ifdef __cplusplus } diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index f6e79d64c61d..62a5ea620347 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -23,18 +23,27 @@ #include #include "shell_commands.h" +#define __registered__ __attribute__((used,section("._shell_command_list"))) static +#define __end__ __attribute__((used,section("._shell_command_list_end"))) static + +__end__ shell_command_t _null_command = {NULL, NULL, NULL}; + extern int _reboot_handler(int argc, char **argv); +__registered__ shell_command_t _reboot_command = {"reboot", "Reboot the node", _reboot_handler}; #ifdef MODULE_CONFIG extern int _id_handler(int argc, char **argv); +__registered__ shell_command_t _id_handler_command = {"id", "Gets or sets the node's id.", _id_handler}; #endif #ifdef MODULE_LPC_COMMON extern int _heap_handler(int argc, char **argv); +__registered__ shell_command_t _heap_handler_command = {"heap", "Shows the heap state for the LPC2387 on the command shell.", _heap_handler}; #endif #ifdef MODULE_PS extern int _ps_handler(int argc, char **argv); +__registered__ shell_command_t _ps_handler_command = {"ps", "Prints information about running threads.", _ps_handler}; #endif #ifdef MODULE_SHT11 @@ -42,23 +51,32 @@ extern int _get_temperature_handler(int argc, char **argv); extern int _get_humidity_handler(int argc, char **argv); extern int _get_weather_handler(int argc, char **argv); extern int _set_offset_handler(int argc, char **argv); +__registered__ shell_command_t _get_temperature_handler_command = {"temp", "Prints measured temperature.", _get_temperature_handler}; +__registered__ shell_command_t _get_humidity_handler_command = {"hum", "Prints measured humidity.", _get_humidity_handler}; +__registered__ shell_command_t _get_weather_handler_command = {"weather", "Prints measured humidity and temperature.", _get_weather_handler}; +__registered__ shell_command_t _set_offset_handler_command = {"offset", "Set temperature offset.", _set_offset_handler}; #endif #ifdef MODULE_LTC4150 extern int _get_current_handler(int argc, char **argv); extern int _reset_current_handler(int argc, char **argv); +__registered__ shell_command_t _get_current_handler_command = {"cur", "Prints current and average power consumption.", _get_current_handler}; +__registered__ shell_command_t _reset_current_handler_command = {"rstcur", "Resets coulomb counter.", _reset_current_handler}; #endif #ifdef MODULE_AT30TSE75X extern int _at30tse75x_handler(int argc, char **argv); +__registered__ shell_command_t _at30tse75x_handler_command = {"at30tse75x", "Test AT30TSE75X temperature sensor", _at30tse75x_handler}; #endif #ifdef MODULE_SAUL_REG extern int _saul(int argc, char **argv); +__registered__ shell_command_t _saul_command = {"saul", "interact with sensors and actuators using SAUL", _saul}; #endif #ifdef MODULE_PERIPH_RTC extern int _rtc_handler(int argc, char **argv); +__registered__ shell_command_t _rtc_handler_command = {"rtc", "control RTC peripheral interface", _rtc_handler}; #endif #ifdef MODULE_MCI @@ -67,32 +85,44 @@ extern int _get_blocksize(int argc, char **argv); extern int _get_sectorcount(int argc, char **argv); extern int _read_sector(int argc, char **argv); extern int _read_bytes(int argc, char **argv); +__registered__ shell_command_t _read_sector_command = {DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector}; +__registered__ shell_command_t _read_bytes_command = {DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes}; +__registered__ shell_command_t _get_sectorsize_command = {DISK_GET_SECTOR_SIZE, "Get the sector size of inserted memory card", _get_sectorsize}; +__registered__ shell_command_t _get_sectorcount_command = {DISK_GET_SECTOR_COUNT, "Get the sector count of inserted memory card", _get_sectorcount}; +__registered__ shell_command_t _get_blocksize_command = {DISK_GET_BLOCK_SIZE, "Get the block size of inserted memory card", _get_blocksize}; #endif #ifdef MODULE_GNRC_ICMPV6_ECHO #ifdef MODULE_XTIMER extern int _icmpv6_ping(int argc, char **argv); +__registered__ shell_command_t _icmpv6_ping_command = { "ping6", "Ping via ICMPv6", _icmpv6_ping}; #endif #endif #ifdef MODULE_RANDOM extern int _random_init(int argc, char **argv); extern int _random_get(int argc, char **argv); +__registered__ shell_command_t _random_init_command = { "random_init", "initializes the PRNG", _random_init}; +__registered__ shell_command_t _random_get_command = { "random_get", "returns 32 bit of pseudo randomness", _random_get}; #endif #ifdef MODULE_GNRC_IPV6_NIB extern int _gnrc_ipv6_nib(int argc, char **argv); +__registered__ shell_command_t _gnrc_ipv6_nib_command = {"nib", "Configure neighbor information base", _gnrc_ipv6_nib}; #endif #ifdef MODULE_GNRC_NETIF extern int _gnrc_netif_config(int argc, char **argv); +__registered__ shell_command_t _gnrc_netif_config_command = {"ifconfig", "Configure network interfaces", _gnrc_netif_config}; #ifdef MODULE_GNRC_TXTSND extern int _gnrc_netif_send(int argc, char **argv); +__registered__ shell_command_t _gnrc_netif_send_command = {"txtsnd", "Sends a custom string as is over the link layer", _gnrc_netif_send}; #endif #endif #ifdef MODULE_FIB extern int _fib_route_handler(int argc, char **argv); +__registered__ shell_command_t _fib_route_handler_command = {"fibroute", "Manipulate the FIB (info: 'fibroute [add|del]')", _fib_route_handler}; #endif #ifdef MODULE_GNRC_IPV6_NC @@ -102,19 +132,23 @@ extern int _ipv6_nc_routers(int argc, char **argv); #ifdef MODULE_GNRC_IPV6_WHITELIST extern int _whitelist(int argc, char **argv); +__registered__ shell_command_t _whitelist_command = {"whitelist", "whitelists an address for receival ('whitelist [add|del|help]')", _whitelist}; #endif #ifdef MODULE_GNRC_IPV6_BLACKLIST extern int _blacklist(int argc, char **argv); +__registered__ shell_command_t _blacklist_command = {"blacklist", "blacklists an address for receival ('blacklist [add|del|help]')", _blacklist}; #endif #ifdef MODULE_GNRC_RPL extern int _gnrc_rpl(int argc, char **argv); +__registered__ shell_command_t _gnrc_rpl_command = {"rpl", "rpl configuration tool ('rpl help' for more information)", _gnrc_rpl}; #endif #ifdef MODULE_GNRC_SIXLOWPAN_CTX #ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER extern int _gnrc_6ctx(int argc, char **argv); +__registered__ shell_command_t _gnrc_6ctx_command = {"6ctx", "6LoWPAN context configuration tool", _gnrc_6ctx}; #endif #endif @@ -123,108 +157,25 @@ extern int _ccnl_open(int argc, char **argv); extern int _ccnl_content(int argc, char **argv); extern int _ccnl_interest(int argc, char **argv); extern int _ccnl_fib(int argc, char **argv); +__registered__ shell_command_t _ccnl_open_command = { "ccnl_open", "opens an interface or socket", _ccnl_open}; +__registered__ shell_command_t _ccnl_interest_command = { "ccnl_int", "sends an interest", _ccnl_interest}; +__registered__ shell_command_t _ccnl_content_command = { "ccnl_cont", "create content and populated it", _ccnl_content}; +__registered__ shell_command_t _ccnl_fib_command = { "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib}; #endif #ifdef MODULE_SNTP extern int _ntpdate(int argc, char **argv); +__registered__ shell_command_t _ntpdate_command = { "ntpdate", "synchronizes with a remote time server", _ntpdate}; #endif #ifdef MODULE_VFS extern int _vfs_handler(int argc, char **argv); extern int _ls_handler(int argc, char **argv); +__registered__ shell_command_t _vfs_handler_command = {"vfs", "virtual file system operations", _vfs_handler}; +__registered__ shell_command_t _ls_handler_command = {"ls", "list files", _ls_handler}; #endif #ifdef MODULE_CONN_CAN extern int _can_handler(int argc, char **argv); +__registered__ shell_command_t _can_handler_command = {"can", "CAN commands", _can_handler}; #endif - -const shell_command_t _shell_command_list[] = { - {"reboot", "Reboot the node", _reboot_handler}, -#ifdef MODULE_CONFIG - {"id", "Gets or sets the node's id.", _id_handler}, -#endif -#ifdef MODULE_LPC_COMMON - {"heap", "Shows the heap state for the LPC2387 on the command shell.", _heap_handler}, -#endif -#ifdef MODULE_PS - {"ps", "Prints information about running threads.", _ps_handler}, -#endif -#ifdef MODULE_SHT11 - {"temp", "Prints measured temperature.", _get_temperature_handler}, - {"hum", "Prints measured humidity.", _get_humidity_handler}, - {"weather", "Prints measured humidity and temperature.", _get_weather_handler}, - {"offset", "Set temperature offset.", _set_offset_handler}, -#endif -#ifdef MODULE_LTC4150 - {"cur", "Prints current and average power consumption.", _get_current_handler}, - {"rstcur", "Resets coulomb counter.", _reset_current_handler}, -#endif -#ifdef MODULE_AT30TSE75X - {"at30tse75x", "Test AT30TSE75X temperature sensor", _at30tse75x_handler}, -#endif -#ifdef MODULE_MCI - {DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector}, - {DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes}, - {DISK_GET_SECTOR_SIZE, "Get the sector size of inserted memory card", _get_sectorsize}, - {DISK_GET_SECTOR_COUNT, "Get the sector count of inserted memory card", _get_sectorcount}, - {DISK_GET_BLOCK_SIZE, "Get the block size of inserted memory card", _get_blocksize}, -#endif -#ifdef MODULE_GNRC_ICMPV6_ECHO -#ifdef MODULE_XTIMER - { "ping6", "Ping via ICMPv6", _icmpv6_ping }, -#endif -#endif -#ifdef MODULE_RANDOM - { "random_init", "initializes the PRNG", _random_init }, - { "random_get", "returns 32 bit of pseudo randomness", _random_get }, -#endif -#ifdef MODULE_PERIPH_RTC - {"rtc", "control RTC peripheral interface", _rtc_handler}, -#endif -#ifdef MODULE_GNRC_IPV6_NIB - {"nib", "Configure neighbor information base", _gnrc_ipv6_nib}, -#endif -#ifdef MODULE_GNRC_NETIF - {"ifconfig", "Configure network interfaces", _gnrc_netif_config}, -#ifdef MODULE_GNRC_TXTSND - {"txtsnd", "Sends a custom string as is over the link layer", _gnrc_netif_send }, -#endif -#endif -#ifdef MODULE_FIB - {"fibroute", "Manipulate the FIB (info: 'fibroute [add|del]')", _fib_route_handler}, -#endif -#ifdef MODULE_GNRC_IPV6_WHITELIST - {"whitelist", "whitelists an address for receival ('whitelist [add|del|help]')", _whitelist }, -#endif -#ifdef MODULE_GNRC_IPV6_BLACKLIST - {"blacklist", "blacklists an address for receival ('blacklist [add|del|help]')", _blacklist }, -#endif -#ifdef MODULE_GNRC_RPL - {"rpl", "rpl configuration tool ('rpl help' for more information)", _gnrc_rpl }, -#endif -#ifdef MODULE_GNRC_SIXLOWPAN_CTX -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER - {"6ctx", "6LoWPAN context configuration tool", _gnrc_6ctx }, -#endif -#endif -#ifdef MODULE_SAUL_REG - {"saul", "interact with sensors and actuators using SAUL", _saul }, -#endif -#ifdef MODULE_CCN_LITE_UTILS - { "ccnl_open", "opens an interface or socket", _ccnl_open }, - { "ccnl_int", "sends an interest", _ccnl_interest }, - { "ccnl_cont", "create content and populated it", _ccnl_content }, - { "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib }, -#endif -#ifdef MODULE_SNTP - { "ntpdate", "synchronizes with a remote time server", _ntpdate }, -#endif -#ifdef MODULE_VFS - {"vfs", "virtual file system operations", _vfs_handler}, - {"ls", "list files", _ls_handler}, -#endif -#ifdef MODULE_CONN_CAN - {"can", "CAN commands", _can_handler}, -#endif - {NULL, NULL, NULL} -}; diff --git a/sys/shell/commands/shell_commands.ld b/sys/shell/commands/shell_commands.ld new file mode 100644 index 000000000000..de0cc5888a8f --- /dev/null +++ b/sys/shell/commands/shell_commands.ld @@ -0,0 +1,9 @@ +SECTIONS +{ + .data : + { + _shell_command_list = .; /* begining of the command list */ + KEEP(*(._shell_command_list)) + KEEP(*(._shell_command_list_end)) + } +} diff --git a/sys/shell/commands/shell_commands_cortexm.ld b/sys/shell/commands/shell_commands_cortexm.ld new file mode 100644 index 000000000000..8c60f542a490 --- /dev/null +++ b/sys/shell/commands/shell_commands_cortexm.ld @@ -0,0 +1,9 @@ +SECTIONS +{ + .data : + { + _shell_command_list = .; /* begining of the command list */ + KEEP(*(._shell_command_list)) + KEEP(*(._shell_command_list_end)) + } > ram +} diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 67b7b830e20e..4786775f80d4 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -49,7 +49,7 @@ static shell_command_handler_t find_handler(const shell_command_t *command_list, const shell_command_t *command_lists[] = { command_list, #ifdef MODULE_SHELL_COMMANDS - _shell_command_list, + &_shell_command_list, #endif }; @@ -81,7 +81,7 @@ static void print_help(const shell_command_t *command_list) const shell_command_t *command_lists[] = { command_list, #ifdef MODULE_SHELL_COMMANDS - _shell_command_list, + &_shell_command_list, #endif }; From 3e011382d148b00277ebebba99b25cd9894d1888 Mon Sep 17 00:00:00 2001 From: astralien3000 Date: Thu, 15 Feb 2018 12:21:55 +0100 Subject: [PATCH 2/2] add REGISTER_SHELL_COMMAND macro + split shell command lists --- sys/Makefile.include | 2 +- sys/include/shell_commands.h | 3 + sys/shell/commands/sc_at30tse75x.c | 4 +- sys/shell/commands/sc_blacklist.c | 4 + sys/shell/commands/sc_can.c | 4 + sys/shell/commands/sc_ccnl.c | 7 ++ sys/shell/commands/sc_disk.c | 8 ++ sys/shell/commands/sc_fib.c | 4 + sys/shell/commands/sc_gnrc_6ctx.c | 4 + sys/shell/commands/sc_gnrc_ipv6_nib.c | 4 + sys/shell/commands/sc_gnrc_netif.c | 7 ++ sys/shell/commands/sc_gnrc_rpl.c | 5 + sys/shell/commands/sc_heap.c | 4 + sys/shell/commands/sc_icmpv6_echo.c | 6 +- sys/shell/commands/sc_ps.c | 4 + sys/shell/commands/sc_random.c | 5 + sys/shell/commands/sc_rtc.c | 4 + sys/shell/commands/sc_saul_reg.c | 4 + sys/shell/commands/sc_sht11.c | 7 +- sys/shell/commands/sc_sntp.c | 4 + sys/shell/commands/sc_sys.c | 3 + sys/shell/commands/sc_vfs.c | 7 +- sys/shell/commands/sc_whitelist.c | 4 + sys/shell/commands/shell_commands.c | 154 -------------------------- 24 files changed, 98 insertions(+), 164 deletions(-) diff --git a/sys/Makefile.include b/sys/Makefile.include index 72a0968634b3..201b95c1e107 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -93,5 +93,5 @@ ifneq (,$(filter cortexm_common,$(USEMODULE))) else LINKFLAGS += $(RIOTBASE)/sys/shell/commands/shell_commands.ld endif - UNDEF += $(BINDIR)/shell_commands/shell_commands.o + UNDEF += -Wl,--whole-archive $(BINDIR)/shell_commands.a -Wl,--no-whole-archive endif diff --git a/sys/include/shell_commands.h b/sys/include/shell_commands.h index a2447ccc2087..8cfcd785bbb9 100644 --- a/sys/include/shell_commands.h +++ b/sys/include/shell_commands.h @@ -32,6 +32,9 @@ extern "C" { #define DISK_READ_SECTOR_CMD "dread_sec" #define DISK_READ_BYTES_CMD "dread" +#define __registered__ __attribute__((used,section("._shell_command_list"))) static +#define REGISTER_SHELL_COMMAND(name, desc, handler) __registered__ shell_command_t handler ## _command = {name, desc, handler} + extern const shell_command_t _shell_command_list; #ifdef __cplusplus diff --git a/sys/shell/commands/sc_at30tse75x.c b/sys/shell/commands/sc_at30tse75x.c index 32304f43aa49..c0d451350bec 100644 --- a/sys/shell/commands/sc_at30tse75x.c +++ b/sys/shell/commands/sc_at30tse75x.c @@ -24,7 +24,7 @@ #include #include "at30tse75x.h" -#ifdef MODULE_AT30TSE75X +#include "shell_commands.h" static bool initialized = false; static at30tse75x_t dev; @@ -157,4 +157,4 @@ int _at30tse75x_handler(int argc, char **argv) return 0; } -#endif /* MODULE_AT30TSE75X */ +REGISTER_SHELL_COMMAND("at30tse75x", "Test AT30TSE75X temperature sensor", _at30tse75x_handler); diff --git a/sys/shell/commands/sc_blacklist.c b/sys/shell/commands/sc_blacklist.c index 27df59e75060..46fca0882022 100644 --- a/sys/shell/commands/sc_blacklist.c +++ b/sys/shell/commands/sc_blacklist.c @@ -19,6 +19,8 @@ #include "net/gnrc/ipv6/blacklist.h" +#include "shell_commands.h" + static void _usage(char *cmd) { printf("usage: * %s\n", cmd); @@ -60,4 +62,6 @@ int _blacklist(int argc, char **argv) return 0; } +REGISTER_SHELL_COMMAND("blacklist", "blacklists an address for receival ('blacklist [add|del|help]')", _blacklist); + /** @} */ diff --git a/sys/shell/commands/sc_can.c b/sys/shell/commands/sc_can.c index 61041b396f24..ebf73b0e2262 100644 --- a/sys/shell/commands/sc_can.c +++ b/sys/shell/commands/sc_can.c @@ -27,6 +27,8 @@ #include "can/conn/raw.h" #include "can/raw.h" +#include "shell_commands.h" + #define SC_CAN_MAX_FILTERS 10 #define xstr(a) str(a) #define str(a) #a @@ -182,3 +184,5 @@ int _can_handler(int argc, char **argv) } return 0; } + +REGISTER_SHELL_COMMAND("can", "CAN commands", _can_handler); diff --git a/sys/shell/commands/sc_ccnl.c b/sys/shell/commands/sc_ccnl.c index da2160fc4c4d..89c38bad1653 100644 --- a/sys/shell/commands/sc_ccnl.c +++ b/sys/shell/commands/sc_ccnl.c @@ -24,6 +24,8 @@ #include "ccn-lite-riot.h" #include "ccnl-pkt-ndntlv.h" +#include "shell_commands.h" + #define BUF_SIZE (64) #define MAX_ADDR_LEN (GNRC_NETIF_L2ADDR_MAXLEN) @@ -266,3 +268,8 @@ int _ccnl_fib(int argc, char **argv) } return 0; } + +REGISTER_SHELL_COMMAND( "ccnl_open", "opens an interface or socket", _ccnl_open); +REGISTER_SHELL_COMMAND( "ccnl_int", "sends an interest", _ccnl_interest); +REGISTER_SHELL_COMMAND( "ccnl_cont", "create content and populated it", _ccnl_content); +REGISTER_SHELL_COMMAND( "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib); diff --git a/sys/shell/commands/sc_disk.c b/sys/shell/commands/sc_disk.c index 1c54eef879d8..3cbf21963153 100644 --- a/sys/shell/commands/sc_disk.c +++ b/sys/shell/commands/sc_disk.c @@ -25,6 +25,8 @@ #include "shell_commands.h" #include "diskio.h" +#include "shell_commands.h" + static inline uint8_t sector_read(unsigned char *read_buf, unsigned long sector, unsigned long length, unsigned long offset) { if (mci_read(read_buf, sector, 1) == DISKIO_RES_OK) { @@ -173,3 +175,9 @@ int _read_bytes(int argc, char **argv) return 1; } + +REGISTER_SHELL_COMMAND(DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector); +REGISTER_SHELL_COMMAND(DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes); +REGISTER_SHELL_COMMAND(DISK_GET_SECTOR_SIZE, "Get the sector size of inserted memory card", _get_sectorsize); +REGISTER_SHELL_COMMAND(DISK_GET_SECTOR_COUNT, "Get the sector count of inserted memory card", _get_sectorcount); +REGISTER_SHELL_COMMAND(DISK_GET_BLOCK_SIZE, "Get the block size of inserted memory card", _get_blocksize); diff --git a/sys/shell/commands/sc_fib.c b/sys/shell/commands/sc_fib.c index 511a76a396cc..60d47e791f4e 100644 --- a/sys/shell/commands/sc_fib.c +++ b/sys/shell/commands/sc_fib.c @@ -29,6 +29,8 @@ #include "net/fib.h" #include "net/gnrc/ipv6.h" +#include "shell_commands.h" + #define INFO1_TXT "fibroute add via [dev ]" #define INFO2_TXT " [lifetime ]" #define INFO3_TXT " - the destination address with optional prefix size, e.g. /116\n" \ @@ -252,3 +254,5 @@ int _fib_route_handler(int argc, char **argv) puts("\nunrecognized parameters.\nPlease enter fibroute [add|del] for more information."); return 1; } + +REGISTER_SHELL_COMMAND("fibroute", "Manipulate the FIB (info: 'fibroute [add|del]')", _fib_route_handler); diff --git a/sys/shell/commands/sc_gnrc_6ctx.c b/sys/shell/commands/sc_gnrc_6ctx.c index d88c252a539d..2e8bc861db45 100644 --- a/sys/shell/commands/sc_gnrc_6ctx.c +++ b/sys/shell/commands/sc_gnrc_6ctx.c @@ -25,6 +25,8 @@ #include "timex.h" #include "xtimer.h" +#include "shell_commands.h" + static xtimer_t del_timer[GNRC_SIXLOWPAN_CTX_SIZE]; void _del_cb(void *ptr) { @@ -146,4 +148,6 @@ int _gnrc_6ctx(int argc, char **argv) return 0; } +REGISTER_SHELL_COMMAND("6ctx", "6LoWPAN context configuration tool", _gnrc_6ctx); + /** @} */ diff --git a/sys/shell/commands/sc_gnrc_ipv6_nib.c b/sys/shell/commands/sc_gnrc_ipv6_nib.c index 7e6a13bc6c9b..3d612700763e 100644 --- a/sys/shell/commands/sc_gnrc_ipv6_nib.c +++ b/sys/shell/commands/sc_gnrc_ipv6_nib.c @@ -19,6 +19,8 @@ #include "net/gnrc/netif.h" #include "net/ipv6/addr.h" +#include "shell_commands.h" + static void _usage(char **argv); static int _nib_neigh(int argc, char **argv); static int _nib_prefix(int argc, char **argv); @@ -245,4 +247,6 @@ static int _nib_route(int argc, char **argv) return 0; } +REGISTER_SHELL_COMMAND("nib", "Configure neighbor information base", _gnrc_ipv6_nib); + /** @} */ diff --git a/sys/shell/commands/sc_gnrc_netif.c b/sys/shell/commands/sc_gnrc_netif.c index 7b494bb85c5a..322038680ddb 100644 --- a/sys/shell/commands/sc_gnrc_netif.c +++ b/sys/shell/commands/sc_gnrc_netif.c @@ -33,6 +33,8 @@ #include "net/l2filter.h" #endif +#include "shell_commands.h" + /** * @brief The default IPv6 prefix length if not specified. */ @@ -1233,6 +1235,9 @@ int _gnrc_netif_send(int argc, char **argv) return 0; } + +REGISTER_SHELL_COMMAND("txtsnd", "Sends a custom string as is over the link layer", _gnrc_netif_send); + #endif int _gnrc_netif_config(int argc, char **argv) @@ -1347,3 +1352,5 @@ int _gnrc_netif_config(int argc, char **argv) _usage(argv[0]); return 1; } + +REGISTER_SHELL_COMMAND("ifconfig", "Configure network interfaces", _gnrc_netif_config); diff --git a/sys/shell/commands/sc_gnrc_rpl.c b/sys/shell/commands/sc_gnrc_rpl.c index 7167b877d834..05e94e8d8b2e 100644 --- a/sys/shell/commands/sc_gnrc_rpl.c +++ b/sys/shell/commands/sc_gnrc_rpl.c @@ -29,6 +29,8 @@ #include "net/gnrc/rpl/p2p_structs.h" #endif +#include "shell_commands.h" + int _gnrc_rpl_init(char *arg) { kernel_pid_t iface_pid = atoi(arg); @@ -431,6 +433,9 @@ int _gnrc_rpl(int argc, char **argv) puts("* show\t\t\t\t\t- show instance and dodag tables"); return 0; } + +REGISTER_SHELL_COMMAND("rpl", "rpl configuration tool ('rpl help' for more information)", _gnrc_rpl); + /** * @} */ diff --git a/sys/shell/commands/sc_heap.c b/sys/shell/commands/sc_heap.c index 17fe27844f27..37e00edc4baf 100644 --- a/sys/shell/commands/sc_heap.c +++ b/sys/shell/commands/sc_heap.c @@ -18,6 +18,8 @@ * @} */ +#include "shell_commands.h" + extern void heap_stats(void); int _heap_handler(int argc, char **argv) @@ -29,3 +31,5 @@ int _heap_handler(int argc, char **argv) return 0; } + +REGISTER_SHELL_COMMAND("heap", "Shows the heap state for the LPC2387 on the command shell.", _heap_handler); diff --git a/sys/shell/commands/sc_icmpv6_echo.c b/sys/shell/commands/sc_icmpv6_echo.c index f7b7a674c3ac..1623d3edd9dc 100644 --- a/sys/shell/commands/sc_icmpv6_echo.c +++ b/sys/shell/commands/sc_icmpv6_echo.c @@ -19,8 +19,6 @@ #include #include -#ifdef MODULE_GNRC_ICMPV6 - #include "byteorder.h" #include "net/gnrc/icmpv6.h" #include "net/ipv6/addr.h" @@ -34,6 +32,8 @@ #include "utlist.h" #include "xtimer.h" +#include "shell_commands.h" + static uint16_t id = 0x53; static uint16_t min_seq_expected = 0; static uint16_t max_seq_expected = 0; @@ -340,7 +340,7 @@ int _icmpv6_ping(int argc, char **argv) return success ? 0 : 1; } -#endif +REGISTER_SHELL_COMMAND( "ping6", "Ping via ICMPv6", _icmpv6_ping); /** * @} diff --git a/sys/shell/commands/sc_ps.c b/sys/shell/commands/sc_ps.c index 7b311305166c..357e4fb29a7f 100644 --- a/sys/shell/commands/sc_ps.c +++ b/sys/shell/commands/sc_ps.c @@ -20,6 +20,8 @@ #include "ps.h" +#include "shell_commands.h" + int _ps_handler(int argc, char **argv) { (void) argc; @@ -29,3 +31,5 @@ int _ps_handler(int argc, char **argv) return 0; } + +REGISTER_SHELL_COMMAND("ps", "Prints information about running threads.", _ps_handler); diff --git a/sys/shell/commands/sc_random.c b/sys/shell/commands/sc_random.c index 764885837adc..0215ffc3513e 100644 --- a/sys/shell/commands/sc_random.c +++ b/sys/shell/commands/sc_random.c @@ -30,6 +30,8 @@ #include "random.h" +#include "shell_commands.h" + int _random_init(int argc, char **argv) { int initval; @@ -64,3 +66,6 @@ int _random_get(int argc, char **argv) return 0; } + +REGISTER_SHELL_COMMAND( "random_init", "initializes the PRNG", _random_init); +REGISTER_SHELL_COMMAND( "random_get", "returns 32 bit of pseudo randomness", _random_get); diff --git a/sys/shell/commands/sc_rtc.c b/sys/shell/commands/sc_rtc.c index 268f57361e4f..42353fbee157 100644 --- a/sys/shell/commands/sc_rtc.c +++ b/sys/shell/commands/sc_rtc.c @@ -27,6 +27,8 @@ #include "periph/rtc.h" +#include "shell_commands.h" + static void _alarm_handler(void *arg) { (void) arg; @@ -183,3 +185,5 @@ int _rtc_handler(int argc, char **argv) } return 0; } + +REGISTER_SHELL_COMMAND("rtc", "control RTC peripheral interface", _rtc_handler); diff --git a/sys/shell/commands/sc_saul_reg.c b/sys/shell/commands/sc_saul_reg.c index 7922292ecacb..8b3354970af3 100644 --- a/sys/shell/commands/sc_saul_reg.c +++ b/sys/shell/commands/sc_saul_reg.c @@ -25,6 +25,8 @@ #include "saul_reg.h" +#include "shell_commands.h" + /* this function does not check, if the given device is valid */ static void probe(int num, saul_reg_t *dev) { @@ -153,3 +155,5 @@ int _saul(int argc, char **argv) } return 0; } + +REGISTER_SHELL_COMMAND("saul", "interact with sensors and actuators using SAUL", _saul); diff --git a/sys/shell/commands/sc_sht11.c b/sys/shell/commands/sc_sht11.c index 6722626125bf..45a78f35437e 100644 --- a/sys/shell/commands/sc_sht11.c +++ b/sys/shell/commands/sc_sht11.c @@ -24,7 +24,7 @@ #include #include "sht11.h" -#ifdef MODULE_SHT11 +#include "shell_commands.h" extern float sht11_temperature_offset; @@ -109,4 +109,7 @@ int _set_offset_handler(int argc, char **argv) } } -#endif +REGISTER_SHELL_COMMAND("temp", "Prints measured temperature.", _get_temperature_handler); +REGISTER_SHELL_COMMAND("hum", "Prints measured humidity.", _get_humidity_handler); +REGISTER_SHELL_COMMAND("weather", "Prints measured humidity and temperature.", _get_weather_handler); +REGISTER_SHELL_COMMAND("offset", "Set temperature offset.", _set_offset_handler); diff --git a/sys/shell/commands/sc_sntp.c b/sys/shell/commands/sc_sntp.c index 5e4bc0da1078..3a1c0e0dfed0 100644 --- a/sys/shell/commands/sc_sntp.c +++ b/sys/shell/commands/sc_sntp.c @@ -27,6 +27,8 @@ #include "net/ipv6/addr.h" #include "timex.h" +#include "shell_commands.h" + #define _DEFAULT_TIMEOUT (500000LU) static void _usage(char *cmd) @@ -102,3 +104,5 @@ int _ntpdate(int argc, char **argv) #endif return 0; } + +REGISTER_SHELL_COMMAND( "ntpdate", "synchronizes with a remote time server", _ntpdate); diff --git a/sys/shell/commands/sc_sys.c b/sys/shell/commands/sc_sys.c index f14d09392e13..983b1e6d739e 100644 --- a/sys/shell/commands/sc_sys.c +++ b/sys/shell/commands/sc_sys.c @@ -19,6 +19,7 @@ */ #include "periph/pm.h" +#include "shell_commands.h" int _reboot_handler(int argc, char **argv) { @@ -29,3 +30,5 @@ int _reboot_handler(int argc, char **argv) return 0; } + +REGISTER_SHELL_COMMAND("reboot", "Reboot the node", _reboot_handler); diff --git a/sys/shell/commands/sc_vfs.c b/sys/shell/commands/sc_vfs.c index d5a085a1dd80..fb62b9b28a95 100644 --- a/sys/shell/commands/sc_vfs.c +++ b/sys/shell/commands/sc_vfs.c @@ -18,7 +18,6 @@ * @} */ -#if MODULE_VFS #include #include #include @@ -31,6 +30,8 @@ #include "vfs.h" +#include "shell_commands.h" + #define SHELL_VFS_BUFSIZE 256 static uint8_t _shell_vfs_data_buffer[SHELL_VFS_BUFSIZE]; @@ -582,4 +583,6 @@ int _vfs_handler(int argc, char **argv) return 1; } } -#endif + +REGISTER_SHELL_COMMAND("vfs", "virtual file system operations", _vfs_handler); +REGISTER_SHELL_COMMAND("ls", "list files", _ls_handler); diff --git a/sys/shell/commands/sc_whitelist.c b/sys/shell/commands/sc_whitelist.c index ffc48d247300..7a739baec95c 100644 --- a/sys/shell/commands/sc_whitelist.c +++ b/sys/shell/commands/sc_whitelist.c @@ -18,6 +18,8 @@ #include "net/gnrc/ipv6/whitelist.h" +#include "shell_commands.h" + static void _usage(char *cmd) { printf("usage: * %s\n", cmd); @@ -59,4 +61,6 @@ int _whitelist(int argc, char **argv) return 0; } +REGISTER_SHELL_COMMAND("whitelist", "whitelists an address for receival ('whitelist [add|del|help]')", _whitelist); + /** @} */ diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 62a5ea620347..820b348623c3 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -23,159 +23,5 @@ #include #include "shell_commands.h" -#define __registered__ __attribute__((used,section("._shell_command_list"))) static #define __end__ __attribute__((used,section("._shell_command_list_end"))) static - __end__ shell_command_t _null_command = {NULL, NULL, NULL}; - -extern int _reboot_handler(int argc, char **argv); -__registered__ shell_command_t _reboot_command = {"reboot", "Reboot the node", _reboot_handler}; - -#ifdef MODULE_CONFIG -extern int _id_handler(int argc, char **argv); -__registered__ shell_command_t _id_handler_command = {"id", "Gets or sets the node's id.", _id_handler}; -#endif - -#ifdef MODULE_LPC_COMMON -extern int _heap_handler(int argc, char **argv); -__registered__ shell_command_t _heap_handler_command = {"heap", "Shows the heap state for the LPC2387 on the command shell.", _heap_handler}; -#endif - -#ifdef MODULE_PS -extern int _ps_handler(int argc, char **argv); -__registered__ shell_command_t _ps_handler_command = {"ps", "Prints information about running threads.", _ps_handler}; -#endif - -#ifdef MODULE_SHT11 -extern int _get_temperature_handler(int argc, char **argv); -extern int _get_humidity_handler(int argc, char **argv); -extern int _get_weather_handler(int argc, char **argv); -extern int _set_offset_handler(int argc, char **argv); -__registered__ shell_command_t _get_temperature_handler_command = {"temp", "Prints measured temperature.", _get_temperature_handler}; -__registered__ shell_command_t _get_humidity_handler_command = {"hum", "Prints measured humidity.", _get_humidity_handler}; -__registered__ shell_command_t _get_weather_handler_command = {"weather", "Prints measured humidity and temperature.", _get_weather_handler}; -__registered__ shell_command_t _set_offset_handler_command = {"offset", "Set temperature offset.", _set_offset_handler}; -#endif - -#ifdef MODULE_LTC4150 -extern int _get_current_handler(int argc, char **argv); -extern int _reset_current_handler(int argc, char **argv); -__registered__ shell_command_t _get_current_handler_command = {"cur", "Prints current and average power consumption.", _get_current_handler}; -__registered__ shell_command_t _reset_current_handler_command = {"rstcur", "Resets coulomb counter.", _reset_current_handler}; -#endif - -#ifdef MODULE_AT30TSE75X -extern int _at30tse75x_handler(int argc, char **argv); -__registered__ shell_command_t _at30tse75x_handler_command = {"at30tse75x", "Test AT30TSE75X temperature sensor", _at30tse75x_handler}; -#endif - -#ifdef MODULE_SAUL_REG -extern int _saul(int argc, char **argv); -__registered__ shell_command_t _saul_command = {"saul", "interact with sensors and actuators using SAUL", _saul}; -#endif - -#ifdef MODULE_PERIPH_RTC -extern int _rtc_handler(int argc, char **argv); -__registered__ shell_command_t _rtc_handler_command = {"rtc", "control RTC peripheral interface", _rtc_handler}; -#endif - -#ifdef MODULE_MCI -extern int _get_sectorsize(int argc, char **argv); -extern int _get_blocksize(int argc, char **argv); -extern int _get_sectorcount(int argc, char **argv); -extern int _read_sector(int argc, char **argv); -extern int _read_bytes(int argc, char **argv); -__registered__ shell_command_t _read_sector_command = {DISK_READ_SECTOR_CMD, "Reads the specified sector of inserted memory card", _read_sector}; -__registered__ shell_command_t _read_bytes_command = {DISK_READ_BYTES_CMD, "Reads the specified bytes from inserted memory card", _read_bytes}; -__registered__ shell_command_t _get_sectorsize_command = {DISK_GET_SECTOR_SIZE, "Get the sector size of inserted memory card", _get_sectorsize}; -__registered__ shell_command_t _get_sectorcount_command = {DISK_GET_SECTOR_COUNT, "Get the sector count of inserted memory card", _get_sectorcount}; -__registered__ shell_command_t _get_blocksize_command = {DISK_GET_BLOCK_SIZE, "Get the block size of inserted memory card", _get_blocksize}; -#endif - -#ifdef MODULE_GNRC_ICMPV6_ECHO -#ifdef MODULE_XTIMER -extern int _icmpv6_ping(int argc, char **argv); -__registered__ shell_command_t _icmpv6_ping_command = { "ping6", "Ping via ICMPv6", _icmpv6_ping}; -#endif -#endif - -#ifdef MODULE_RANDOM -extern int _random_init(int argc, char **argv); -extern int _random_get(int argc, char **argv); -__registered__ shell_command_t _random_init_command = { "random_init", "initializes the PRNG", _random_init}; -__registered__ shell_command_t _random_get_command = { "random_get", "returns 32 bit of pseudo randomness", _random_get}; -#endif - -#ifdef MODULE_GNRC_IPV6_NIB -extern int _gnrc_ipv6_nib(int argc, char **argv); -__registered__ shell_command_t _gnrc_ipv6_nib_command = {"nib", "Configure neighbor information base", _gnrc_ipv6_nib}; -#endif - -#ifdef MODULE_GNRC_NETIF -extern int _gnrc_netif_config(int argc, char **argv); -__registered__ shell_command_t _gnrc_netif_config_command = {"ifconfig", "Configure network interfaces", _gnrc_netif_config}; -#ifdef MODULE_GNRC_TXTSND -extern int _gnrc_netif_send(int argc, char **argv); -__registered__ shell_command_t _gnrc_netif_send_command = {"txtsnd", "Sends a custom string as is over the link layer", _gnrc_netif_send}; -#endif -#endif - -#ifdef MODULE_FIB -extern int _fib_route_handler(int argc, char **argv); -__registered__ shell_command_t _fib_route_handler_command = {"fibroute", "Manipulate the FIB (info: 'fibroute [add|del]')", _fib_route_handler}; -#endif - -#ifdef MODULE_GNRC_IPV6_NC -extern int _ipv6_nc_manage(int argc, char **argv); -extern int _ipv6_nc_routers(int argc, char **argv); -#endif - -#ifdef MODULE_GNRC_IPV6_WHITELIST -extern int _whitelist(int argc, char **argv); -__registered__ shell_command_t _whitelist_command = {"whitelist", "whitelists an address for receival ('whitelist [add|del|help]')", _whitelist}; -#endif - -#ifdef MODULE_GNRC_IPV6_BLACKLIST -extern int _blacklist(int argc, char **argv); -__registered__ shell_command_t _blacklist_command = {"blacklist", "blacklists an address for receival ('blacklist [add|del|help]')", _blacklist}; -#endif - -#ifdef MODULE_GNRC_RPL -extern int _gnrc_rpl(int argc, char **argv); -__registered__ shell_command_t _gnrc_rpl_command = {"rpl", "rpl configuration tool ('rpl help' for more information)", _gnrc_rpl}; -#endif - -#ifdef MODULE_GNRC_SIXLOWPAN_CTX -#ifdef MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER -extern int _gnrc_6ctx(int argc, char **argv); -__registered__ shell_command_t _gnrc_6ctx_command = {"6ctx", "6LoWPAN context configuration tool", _gnrc_6ctx}; -#endif -#endif - -#ifdef MODULE_CCN_LITE_UTILS -extern int _ccnl_open(int argc, char **argv); -extern int _ccnl_content(int argc, char **argv); -extern int _ccnl_interest(int argc, char **argv); -extern int _ccnl_fib(int argc, char **argv); -__registered__ shell_command_t _ccnl_open_command = { "ccnl_open", "opens an interface or socket", _ccnl_open}; -__registered__ shell_command_t _ccnl_interest_command = { "ccnl_int", "sends an interest", _ccnl_interest}; -__registered__ shell_command_t _ccnl_content_command = { "ccnl_cont", "create content and populated it", _ccnl_content}; -__registered__ shell_command_t _ccnl_fib_command = { "ccnl_fib", "shows or modifies the CCN-Lite FIB", _ccnl_fib}; -#endif - -#ifdef MODULE_SNTP -extern int _ntpdate(int argc, char **argv); -__registered__ shell_command_t _ntpdate_command = { "ntpdate", "synchronizes with a remote time server", _ntpdate}; -#endif - -#ifdef MODULE_VFS -extern int _vfs_handler(int argc, char **argv); -extern int _ls_handler(int argc, char **argv); -__registered__ shell_command_t _vfs_handler_command = {"vfs", "virtual file system operations", _vfs_handler}; -__registered__ shell_command_t _ls_handler_command = {"ls", "list files", _ls_handler}; -#endif - -#ifdef MODULE_CONN_CAN -extern int _can_handler(int argc, char **argv); -__registered__ shell_command_t _can_handler_command = {"can", "CAN commands", _can_handler}; -#endif