Repository: incubator-mynewt-core Updated Branches: refs/heads/develop efbaf05f4 -> 7f690f7f5
native; allow user to specify real ttys to connect to from command line when invoking simulator. --uart0 <filename> for uart0, --uart1 <filename> for uart1. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7f690f7f Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7f690f7f Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7f690f7f Branch: refs/heads/develop Commit: 7f690f7f59bb561d89898af8ce53b37fa89320ad Parents: efbaf05 Author: System Administrator <ma...@runtime.io> Authored: Tue Mar 28 16:38:52 2017 -0700 Committer: System Administrator <ma...@runtime.io> Committed: Tue Mar 28 16:38:52 2017 -0700 ---------------------------------------------------------------------- hw/mcu/native/include/mcu/mcu_sim.h | 1 + hw/mcu/native/src/hal_system.c | 48 ++++++++++++++++++++++++++++---- hw/mcu/native/src/hal_uart.c | 1 + 3 files changed, 45 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f690f7f/hw/mcu/native/include/mcu/mcu_sim.h ---------------------------------------------------------------------- diff --git a/hw/mcu/native/include/mcu/mcu_sim.h b/hw/mcu/native/include/mcu/mcu_sim.h index cf7dd1a..5c9f804 100644 --- a/hw/mcu/native/include/mcu/mcu_sim.h +++ b/hw/mcu/native/include/mcu/mcu_sim.h @@ -27,6 +27,7 @@ extern "C" { extern char *native_flash_file; extern char *native_uart_log_file; +extern const char *native_uart_dev_strs[]; void mcu_sim_parse_args(int argc, char **argv); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f690f7f/hw/mcu/native/src/hal_system.c ---------------------------------------------------------------------- diff --git a/hw/mcu/native/src/hal_system.c b/hw/mcu/native/src/hal_system.c index a27932c..ad78cba 100644 --- a/hw/mcu/native/src/hal_system.c +++ b/hw/mcu/native/src/hal_system.c @@ -21,6 +21,7 @@ #include <unistd.h> #include <string.h> #include <assert.h> +#include <getopt.h> #include "syscfg/syscfg.h" #include "hal/hal_system.h" @@ -49,13 +50,18 @@ hal_system_reset(void) static void usage(char *progname, int rc) { - const char msg[] = - "Usage: %s [-f flash_file] [-u uart_log_file]\n" + const char msg1[] = "Usage: "; + const char msg2[] = + "\n [-f flash_file][-u uart_log_file][--uart0 <file>][--uart1 <file>]\n" " -f flash_file tells where binary flash file is located. It gets\n" " created if it doesn't already exist.\n" - " -u uart_log_file puts all UART data exchanges into a logfile.\n"; + " -u uart_log_file puts all UART data exchanges into a logfile.\n" + " -uart0 uart0_file connects UART0 to character device uart0_file.\n" + " -uart1 uart1_file connects UART1 to character device uart1_file.\n"; - write(2, msg, strlen(msg)); + write(2, msg1, strlen(msg1)); + write(2, progname, strlen(progname)); + write(2, msg2, strlen(msg2)); exit(rc); } @@ -64,6 +70,15 @@ mcu_sim_parse_args(int argc, char **argv) { int ch; char *progname; + struct option options[] = { + { "flash", required_argument, 0, 'f' }, + { "uart_log", required_argument, 0, 'u' }, + { "help", no_argument, 0, 'h' }, + { "uart0", required_argument, 0, 0 }, + { "uart1", required_argument, 0, 0 }, + { NULL } + }; + int opt_idx; extern int main(int argc, char **arg); #if MYNEWT_VAL(OS_SCHEDULING) @@ -72,7 +87,8 @@ mcu_sim_parse_args(int argc, char **argv) } #endif progname = argv[0]; - while ((ch = getopt(argc, argv, "hf:u:")) != -1) { + while ((ch = getopt_long(argc, argv, "hf:u:", options, &opt_idx)) != + -1) { switch (ch) { case 'f': native_flash_file = optarg; @@ -83,6 +99,28 @@ mcu_sim_parse_args(int argc, char **argv) case 'h': usage(progname, 0); break; + case 0: + switch (opt_idx) { + case 0: + native_flash_file = optarg; + break; + case 1: + native_uart_log_file = optarg; + break; + case 2: + usage(progname, 0); + break; + case 3: + native_uart_dev_strs[0] = optarg; + break; + case 4: + native_uart_dev_strs[1] = optarg; + break; + default: + usage(progname, -1); + break; + } + break; default: usage(progname, -1); break; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7f690f7f/hw/mcu/native/src/hal_uart.c ---------------------------------------------------------------------- diff --git a/hw/mcu/native/src/hal_uart.c b/hw/mcu/native/src/hal_uart.c index d9328aa..4ef6186 100644 --- a/hw/mcu/native/src/hal_uart.c +++ b/hw/mcu/native/src/hal_uart.c @@ -37,6 +37,7 @@ #include <termios.h> #include <errno.h> +#include "mcu/mcu_sim.h" #include "native_uart_cfg_priv.h" #define UART_CNT 2