From 2f3a905da7a450c200ea631ce9669e9258678d3a Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 11 Mar 2006 11:02:57 +0000 Subject: Permet la récupération des arguments sur host. Correction de bug avec les asserts. --- n/avr/common/common.h | 8 ++++++++ n/avr/modules/host/host.h | 7 ++++++- n/avr/modules/host/host.host.c | 13 ++++++++++++- n/avr/modules/host/test/test_host.c | 5 ++++- n/avr/modules/math/fixed/test/test_fixed.c | 3 ++- n/avr/modules/proto/test/test_proto.c | 3 ++- n/avr/modules/uart/test/test_uart.c | 3 ++- n/avr/modules/uart/uart.host.c | 5 +++-- n/avr/modules/utils/test/test_utils.c | 3 ++- n/avr/modules/utils/utils.host.c | 2 +- n/avr/modules/utils/utils.host.h | 5 +---- 11 files changed, 43 insertions(+), 14 deletions(-) diff --git a/n/avr/common/common.h b/n/avr/common/common.h index 54ed501..1097942 100644 --- a/n/avr/common/common.h +++ b/n/avr/common/common.h @@ -38,6 +38,8 @@ typedef int32_t i32; # define assert(x) +# define avr_init(argc, argv) do { } while (0) + #else /* HOST */ # ifdef NDEBUG @@ -60,6 +62,12 @@ typedef int32_t i32; __ASSERT_FUNCTION), 0))) # endif +/** Initialise host module. */ +void +host_init (int argc, char **argv); + +#define avr_init host_init + #endif /* HOST */ #endif /* common_h */ diff --git a/n/avr/modules/host/host.h b/n/avr/modules/host/host.h index d1a00af..73cd4a5 100644 --- a/n/avr/modules/host/host.h +++ b/n/avr/modules/host/host.h @@ -30,10 +30,15 @@ # error Use this header only for HOST only files ! #endif -/** Initialise host modules. */ +/** Initialise host module. */ void host_init (int argc, char **argv); +/** Retrieve saved program arguments. Program name and used parameters are + * stripped. */ +void +host_get_program_arguments (int *argc, char ***argv); + /** Host variables are usefull on reset. They are passed in the environment. * This is not optimised for performance. */ diff --git a/n/avr/modules/host/host.host.c b/n/avr/modules/host/host.host.c index bcfd7d2..7967e9c 100644 --- a/n/avr/modules/host/host.host.c +++ b/n/avr/modules/host/host.host.c @@ -36,7 +36,7 @@ static int host_saved_argc; static char **host_saved_argv; -/** Initialise host modules. */ +/** Initialise host module. */ void host_init (int argc, char **argv) { @@ -44,6 +44,16 @@ host_init (int argc, char **argv) host_saved_argv = argv; } +/** Retrieve saved program arguments. Program name and used parameters are + * stripped. */ +void +host_get_program_arguments (int *argc, char ***argv) +{ + assert (host_saved_argc); + *argc = host_saved_argc - 1; + *argv = host_saved_argv + 1; +} + /** Register a host integer. */ void host_register_integer (const char *name, int val) @@ -84,6 +94,7 @@ host_fetch_string (const char *name) void host_reset (void) { + assert (host_saved_argv); execv (program_invocation_name, host_saved_argv); assert_perror (errno); abort (); diff --git a/n/avr/modules/host/test/test_host.c b/n/avr/modules/host/test/test_host.c index db8161f..8c98a94 100644 --- a/n/avr/modules/host/test/test_host.c +++ b/n/avr/modules/host/test/test_host.c @@ -33,6 +33,8 @@ main (int argc, char **argv) { int i; const char *s; + int ac; + char **av; printf ("reset\n"); host_init (argc, argv); i = host_fetch_integer ("avr_integer"); @@ -40,7 +42,8 @@ main (int argc, char **argv) if (i != -1) { printf ("get\n"); - assert_print (argc == 2 && strcmp (argv[1], "ni") == 0, + host_get_program_arguments (&ac, &av); + assert_print (ac == 1 && strcmp (av[0], "ni") == 0, "argument passing not working"); assert (i == 42); assert (strcmp (s, "Ni!") == 0); diff --git a/n/avr/modules/math/fixed/test/test_fixed.c b/n/avr/modules/math/fixed/test/test_fixed.c index ff826d4..875aad4 100644 --- a/n/avr/modules/math/fixed/test/test_fixed.c +++ b/n/avr/modules/math/fixed/test/test_fixed.c @@ -233,8 +233,9 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) } int -main (void) +main (int argc, char **argv) { + avr_init (argc, argv); sei (); uart0_init (); proto_send0 ('z'); diff --git a/n/avr/modules/proto/test/test_proto.c b/n/avr/modules/proto/test/test_proto.c index 0503b6c..0b0883f 100644 --- a/n/avr/modules/proto/test/test_proto.c +++ b/n/avr/modules/proto/test/test_proto.c @@ -67,8 +67,9 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) } int -main (void) +main (int argc, char **argv) { + avr_init (argc, argv); sei (); uart0_init (); /* This command should be generaly sent on reset. */ diff --git a/n/avr/modules/uart/test/test_uart.c b/n/avr/modules/uart/test/test_uart.c index 76716e7..86b2058 100644 --- a/n/avr/modules/uart/test/test_uart.c +++ b/n/avr/modules/uart/test/test_uart.c @@ -28,8 +28,9 @@ #include "io.h" int -main (void) +main (int argc, char **argv) { + avr_init (argc, argv); sei (); uart0_init (); uart0_putc ('N'); diff --git a/n/avr/modules/uart/uart.host.c b/n/avr/modules/uart/uart.host.c index d6aa848..9a335b2 100644 --- a/n/avr/modules/uart/uart.host.c +++ b/n/avr/modules/uart/uart.host.c @@ -31,7 +31,6 @@ #if AC_UART (PORT) != -1 -#include #include #include #include @@ -83,10 +82,12 @@ void uart_init (void) { #ifdef DRIVER_STDIO + int r; # define uart_pt_fd_in 0 # define uart_pt_fd_out 1 /* Always use line buffering. */ - assert (setvbuf (stdout, 0, _IOLBF, BUFSIZ) == 0); + r = setvbuf (stdout, 0, _IOLBF, BUFSIZ); + assert (r == 0); #else # define uart_pt_fd_in uart_pt_fd # define uart_pt_fd_out uart_pt_fd diff --git a/n/avr/modules/utils/test/test_utils.c b/n/avr/modules/utils/test/test_utils.c index 4c85c45..d4df7b9 100644 --- a/n/avr/modules/utils/test/test_utils.c +++ b/n/avr/modules/utils/test/test_utils.c @@ -27,8 +27,9 @@ #include "io.h" int -main (void) +main (int argc, char **argv) { + avr_init (argc, argv); #ifndef HOST /* Test regv, the first one should generate a warning. */ TCCR0 = regv (FOC0, WGM00, COM01, COM0, WGM01, CS02, CS00, CS01, diff --git a/n/avr/modules/utils/utils.host.c b/n/avr/modules/utils/utils.host.c index 8d2be82..54dda95 100644 --- a/n/avr/modules/utils/utils.host.c +++ b/n/avr/modules/utils/utils.host.c @@ -22,12 +22,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ +#include "common.h" #include "utils.h" #include "modules/host/host.h" #include #include -#include /** Delay in seconds. */ void diff --git a/n/avr/modules/utils/utils.host.h b/n/avr/modules/utils/utils.host.h index e4c5183..2e73dc4 100644 --- a/n/avr/modules/utils/utils.host.h +++ b/n/avr/modules/utils/utils.host.h @@ -29,11 +29,8 @@ void utils_delay (double s); -void -utils_reset (void) __attribute__ ((noreturn)); - /** Reset. */ void -utils_reset (void); +utils_reset (void) __attribute__ ((noreturn)); #endif /* utils_host_h */ -- cgit v1.2.3