From 53d07e8c120c30f8acb3197fb0559f70ad17a621 Mon Sep 17 00:00:00 2001 From: TT Date: Sun, 18 Aug 2019 08:19:17 +0900 Subject: [PATCH] feat: add version command --- Makefile | 7 ++++++- main.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6cd661a..fccbfcf 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,11 @@ endif # Build global options ############################################################################## +ifeq ($(VERSION),) + #VERSION="unknown" + VERSION="$(shell git describe --tags)" +endif + ############################################################################## # Architecture or project specific options # @@ -200,7 +205,7 @@ CPPWARN = -Wall -Wextra -Wundef # # List all user C define here, like -D_DEBUG=1 -UDEFS = -DSHELL_CMD_TEST_ENABLED=FALSE -DSHELL_CMD_MEM_ENABLED=FALSE -DARM_MATH_CM0 +UDEFS = -DSHELL_CMD_TEST_ENABLED=FALSE -DSHELL_CMD_MEM_ENABLED=FALSE -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\" # Define ASM defines here UADEFS = diff --git a/main.c b/main.c index 25a9f20..cbcadb4 100644 --- a/main.c +++ b/main.c @@ -1663,14 +1663,23 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[]) } +#ifndef VERSION +#define VERSION "unknown" +#endif - +static void cmd_version(BaseSequentialStream *chp, int argc, char *argv[]) +{ + (void)argc; + (void)argv; + chprintf(chp, VERSION "\r\n"); +} #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(256) static THD_WORKING_AREA(waThread2, SHELL_WA_SIZE); static const ShellCommand commands[] = { + { "version", cmd_version }, { "reset", cmd_reset }, { "freq", cmd_freq }, { "offset", cmd_offset },