From fce0e09f5373a93d4071349fe26a4cec42a9916d Mon Sep 17 00:00:00 2001 From: schodet Date: Sat, 8 Oct 2005 11:10:24 +0000 Subject: Ajout des variables host. Ajout du programme de test. --- n/avr/modules/host/Makefile.module | 2 +- n/avr/modules/host/host.c | 72 --------------------------------- n/avr/modules/host/host.h | 4 +- n/avr/modules/host/host.host.c | 79 +++++++++++++++++++++++++++++++++++++ n/avr/modules/host/test/Makefile | 17 ++++++++ n/avr/modules/host/test/avrconfig.h | 28 +++++++++++++ n/avr/modules/host/test/test_host.c | 52 ++++++++++++++++++++++++ 7 files changed, 179 insertions(+), 75 deletions(-) delete mode 100644 n/avr/modules/host/host.c create mode 100644 n/avr/modules/host/host.host.c create mode 100644 n/avr/modules/host/test/Makefile create mode 100644 n/avr/modules/host/test/avrconfig.h create mode 100644 n/avr/modules/host/test/test_host.c (limited to 'n') diff --git a/n/avr/modules/host/Makefile.module b/n/avr/modules/host/Makefile.module index 6ce2645..cf2cf1e 100644 --- a/n/avr/modules/host/Makefile.module +++ b/n/avr/modules/host/Makefile.module @@ -1 +1 @@ -host_SOURCES = host.c +host_SOURCES = host.host.c diff --git a/n/avr/modules/host/host.c b/n/avr/modules/host/host.c deleted file mode 100644 index f4d76e9..0000000 --- a/n/avr/modules/host/host.c +++ /dev/null @@ -1,72 +0,0 @@ -/* host.c */ -/* avr.host - Host fonctions modules. {{{ - * - * Copyright (C) 2005 Nicolas Schodet - * - * Robot APB Team/Efrei 2006. - * Web: http://assos.efrei.fr/robot/ - * Email: robot AT efrei DOT fr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * }}} */ -#include "host.h" - -/** Global integer variables list. */ - -/** Global string variables list. */ - -/** Initialise host modules. */ -void -host_init (int argc, char **argv) -{ -} - -/** Register a host integer. */ -void -host_register_integer (const char *name, int val) -{ -} - -/** Register a host string. */ -void -host_register_string (const char *name, const char *val) -{ -} - -/** Fetch a host integer, return -1 if non existant. */ -int -host_fetch_integer (const char *name) -{ - return -1; -} - -/** Fetch a host string, return 0 if non existant. */ -const char * -host_fetch_string (const char *name) -{ - return 0; -} - -/** Reset the program. */ -void -host_reset (void) -{ - execlp (program_invocation_name, program_invocation_name, 0); - assert_perror (errno); - abort (); -} - -#endif /* host_h */ diff --git a/n/avr/modules/host/host.h b/n/avr/modules/host/host.h index 7dd901f..22cd347 100644 --- a/n/avr/modules/host/host.h +++ b/n/avr/modules/host/host.h @@ -34,8 +34,8 @@ void host_init (int argc, char **argv); -/** Host variables are usefull on reset. They are passed on the command - * line. This is not optimised for performance. */ +/** Host variables are usefull on reset. They are passed in the environment. + * This is not optimised for performance. */ /** Register a host integer. */ void diff --git a/n/avr/modules/host/host.host.c b/n/avr/modules/host/host.host.c new file mode 100644 index 0000000..e3f5a32 --- /dev/null +++ b/n/avr/modules/host/host.host.c @@ -0,0 +1,79 @@ +/* host.c */ +/* avr.host - Host fonctions modules. {{{ + * + * Copyright (C) 2005 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#define _GNU_SOURCE +#include "host.h" + +#include +#include +#include +#include +#include + +/** Initialise host modules. */ +void +host_init (int argc, char **argv) +{ +} + +/** Register a host integer. */ +void +host_register_integer (const char *name, int val) +{ + char sval[256]; + /* Convert to string, and register the string. */ + assert (snprintf (sval, sizeof (sval), "%d", val) < (int) sizeof (sval)); + host_register_string (name, sval); +} + +/** Register a host string. */ +void +host_register_string (const char *name, const char *val) +{ + assert (setenv (name, val, 1) == 0); +} + +/** Fetch a host integer, return -1 if non existant. */ +int +host_fetch_integer (const char *name) +{ + const char *sval = host_fetch_string (name); + return sval ? atoi (sval) : -1; +} + +/** Fetch a host string, return 0 if non existant. */ +const char * +host_fetch_string (const char *name) +{ + return getenv (name); +} + +/** Reset the program. */ +void +host_reset (void) +{ + execlp (program_invocation_name, program_invocation_name, 0); + assert_perror (errno); + abort (); +} diff --git a/n/avr/modules/host/test/Makefile b/n/avr/modules/host/test/Makefile new file mode 100644 index 0000000..6c3ec51 --- /dev/null +++ b/n/avr/modules/host/test/Makefile @@ -0,0 +1,17 @@ +BASE = ../../.. +HOST_PROGS = test_host +test_host_SOURCES = test_host.c +DOC = +EXTRACTDOC = +MODULES = host +CONFIGFILE = avrconfig.h +# atmega8, atmega8535, atmega128... +AVR_MCU = none +# -O2 : speed +# -Os : size +OPTIMIZE = -O2 + +DEFS = +LIBS = + +include $(BASE)/make/Makefile.gen diff --git a/n/avr/modules/host/test/avrconfig.h b/n/avr/modules/host/test/avrconfig.h new file mode 100644 index 0000000..f3c23a9 --- /dev/null +++ b/n/avr/modules/host/test/avrconfig.h @@ -0,0 +1,28 @@ +#ifndef avrconfig_h +#define avrconfig_h +/* avrconfig.h - test_host config file. */ +/* host - Host fonctions modules. {{{ + * + * Copyright (C) 2005 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ + +#endif /* avrconfig_h */ diff --git a/n/avr/modules/host/test/test_host.c b/n/avr/modules/host/test/test_host.c new file mode 100644 index 0000000..3b839dd --- /dev/null +++ b/n/avr/modules/host/test/test_host.c @@ -0,0 +1,52 @@ +/* test_host.c */ +/* avr.host - Host fonctions modules. {{{ + * + * Copyright (C) 2005 Nicolas Schodet + * + * Robot APB Team/Efrei 2006. + * Web: http://assos.efrei.fr/robot/ + * Email: robot AT efrei DOT fr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include "common.h" +#include "modules/host/host.h" + +#include +#include +#include + +int +main (void) +{ + int i = host_fetch_integer ("avr_integer"); + const char *s = host_fetch_string ("avr_string"); + printf ("reset\n"); + if (i != -1) + { + printf ("get\n"); + assert (i == 42); + assert (strcmp (s, "Ni!") == 0); + } + else + { + printf ("set\n"); + host_register_integer ("avr_integer", 42); + host_register_string ("avr_string", "Ni!"); + host_reset (); + } + return 0; +} -- cgit v1.2.3