summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschodet2005-10-08 11:10:24 +0000
committerschodet2005-10-08 11:10:24 +0000
commitfce0e09f5373a93d4071349fe26a4cec42a9916d (patch)
tree838374c78c9ea067459bd68c419ff07bf62bc5fd
parent45f5194c8d72ec43d1094b9ca992d2fd00e2f298 (diff)
Ajout des variables host.
Ajout du programme de test.
-rw-r--r--n/avr/modules/host/Makefile.module2
-rw-r--r--n/avr/modules/host/host.h4
-rw-r--r--n/avr/modules/host/host.host.c (renamed from n/avr/modules/host/host.c)21
-rw-r--r--n/avr/modules/host/test/Makefile17
-rw-r--r--n/avr/modules/host/test/avrconfig.h28
-rw-r--r--n/avr/modules/host/test/test_host.c52
6 files changed, 114 insertions, 10 deletions
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.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.c b/n/avr/modules/host/host.host.c
index f4d76e9..e3f5a32 100644
--- a/n/avr/modules/host/host.c
+++ b/n/avr/modules/host/host.host.c
@@ -22,11 +22,14 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
+#define _GNU_SOURCE
#include "host.h"
-/** Global integer variables list. */
-
-/** Global string variables list. */
+#include <errno.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
/** Initialise host modules. */
void
@@ -38,26 +41,32 @@ host_init (int argc, char **argv)
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)
{
- return -1;
+ 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 0;
+ return getenv (name);
}
/** Reset the program. */
@@ -68,5 +77,3 @@ host_reset (void)
assert_perror (errno);
abort ();
}
-
-#endif /* host_h */
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 <string.h>
+#include <assert.h>
+#include <stdio.h>
+
+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;
+}