summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
Diffstat (limited to 'digital')
-rw-r--r--digital/ai/src/fsm/fsm.host.c6
-rw-r--r--digital/io-hub/src/guybrush/Makefile1
-rw-r--r--digital/io-hub/src/guybrush/logger.avr.c134
-rw-r--r--digital/io-hub/src/guybrush/logger.h63
-rw-r--r--digital/io-hub/src/guybrush/main.c4
-rw-r--r--digital/io-hub/src/robospierre/logger.h30
-rw-r--r--digital/io/src/logger.h30
7 files changed, 268 insertions, 0 deletions
diff --git a/digital/ai/src/fsm/fsm.host.c b/digital/ai/src/fsm/fsm.host.c
index 391792e9..ad9d0b00 100644
--- a/digital/ai/src/fsm/fsm.host.c
+++ b/digital/ai/src/fsm/fsm.host.c
@@ -1143,7 +1143,10 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings)
/* Introduction. */
fprintf (f, "/* This file has been generated, do not edit. */\n\n");
+ fprintf (f, "#include \"common.h\"\n\n");
+ fprintf (f, "#include \"io.h\"\n\n");
fprintf (f, "#include \"fsm_%s_gen.h\"\n\n", fsm->name);
+ fprintf (f, "#include \"logger.h\"\n\n");
fprintf (f, "#include \"modules/proto/proto.h\"\n\n");
/* Gen state strings. */
@@ -1357,6 +1360,9 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings)
fsm->name,
fsm->name,
fsm->name);
+ fprintf (f, "\t\t\tlogger_log (old_state, e, "
+ "fsm_%s_active_states[i]);\n",
+ fsm->name);
fprintf (f, "\t\t\tproto_send3b ('F', old_state, e, "
"fsm_%s_active_states[i]);\n",
fsm->name);
diff --git a/digital/io-hub/src/guybrush/Makefile b/digital/io-hub/src/guybrush/Makefile
index 7db25b77..121a900c 100644
--- a/digital/io-hub/src/guybrush/Makefile
+++ b/digital/io-hub/src/guybrush/Makefile
@@ -6,6 +6,7 @@ PROGS = io_hub
io_hub_SOURCES = main.c top.c strat.c \
radar_defs.c radar.c path.c move.c \
pressure.c \
+ logger.avr.c \
init.c fsm.host.c fsm_AI_gen.avr.c fsm_queue.c \
contact.avr.c contact.host.c \
output.c output.host.c \
diff --git a/digital/io-hub/src/guybrush/logger.avr.c b/digital/io-hub/src/guybrush/logger.avr.c
new file mode 100644
index 00000000..3e069bff
--- /dev/null
+++ b/digital/io-hub/src/guybrush/logger.avr.c
@@ -0,0 +1,134 @@
+/* logger.avr.c */
+/* guybrush - Eurobot 2012 AI. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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 "logger.h"
+
+#include <avr/eeprom.h>
+
+/** Record log in EEPROM, bufferize data not to disturb real time
+ * constrains.
+ *
+ * Special bytes:
+ * 0xf0 - 0xfd: event counter, to be used for synchronisation.
+ * 0xfe: escape character.
+ * 0xff: overflow.
+ * */
+
+/** Maximum buffer size. */
+#define LOGGER_BUF_SIZE 32
+
+/** Maximum log size. */
+#define LOGGER_SIZE (E2END + 1)
+
+/** Code writen on overflow. */
+#define LOGGER_OVERFLOW 0xff
+
+/** Code writen to escape characters. */
+#define LOGGER_ESCAPE 0xfe
+
+/** Special code mask. */
+#define LOGGER_SPECIAL 0xf0
+
+/** Event counter rollover value. */
+#define LOGGER_EVENT_COUNTER_NB 14
+
+/** Logger context. */
+struct logger_t
+{
+ /** Log buffer. */
+ uint8_t buf[LOGGER_BUF_SIZE];
+ /** Head and tail in buffer. */
+ uint8_t head, tail;
+ /** Current log pointer. */
+ uint16_t current;
+ /** Event counter, incremented at each event, used for synchronisation. */
+ uint8_t event_counter;
+} logger;
+
+EEMEM uint8_t logger_eeprom[LOGGER_SIZE];
+
+void
+logger_init (void)
+{
+ /* Read last log event counter and choose another value. */
+ logger.event_counter = eeprom_read_byte (&logger_eeprom[0]);
+ logger.event_counter = (logger.event_counter + 1) %
+ LOGGER_EVENT_COUNTER_NB;
+}
+
+void
+logger_update (void)
+{
+ if (eeprom_is_ready () && logger.head != logger.tail
+ && logger.current < LOGGER_SIZE)
+ {
+ /* Write next byte. */
+ uint8_t next = logger.buf[logger.head];
+ eeprom_write_byte (&logger_eeprom[logger.current++], next);
+ logger.head = (logger.head + 1) % LOGGER_BUF_SIZE;
+ }
+}
+
+static void
+logger_write_internal (uint8_t b)
+{
+ uint8_t tail_new = (logger.tail + 1) % LOGGER_BUF_SIZE;
+ if (tail_new == logger.head)
+ {
+ /* Overflow! */
+ logger.buf[logger.tail] = LOGGER_OVERFLOW;
+ }
+ else
+ {
+ logger.tail = tail_new;
+ logger.buf[tail_new] = b;
+ }
+}
+
+void
+logger_write_event_counter (void)
+{
+ logger_write_internal (LOGGER_SPECIAL | logger.event_counter);
+ logger.event_counter = (logger.event_counter + 1) %
+ LOGGER_EVENT_COUNTER_NB;
+}
+
+void
+logger_write (uint8_t b)
+{
+ if ((b & LOGGER_SPECIAL) == LOGGER_SPECIAL)
+ {
+ uint8_t tail_after = (logger.tail + 2) % LOGGER_BUF_SIZE;
+ if (tail_after == logger.head)
+ logger_write_internal (LOGGER_OVERFLOW);
+ else
+ {
+ logger_write_internal (LOGGER_ESCAPE);
+ logger_write_internal (b);
+ }
+ }
+ else
+ logger_write_internal (b);
+}
diff --git a/digital/io-hub/src/guybrush/logger.h b/digital/io-hub/src/guybrush/logger.h
new file mode 100644
index 00000000..e672ab71
--- /dev/null
+++ b/digital/io-hub/src/guybrush/logger.h
@@ -0,0 +1,63 @@
+#ifndef logger_h
+#define logger_h
+/* logger.h */
+/* guybrush - Eurobot 2012 AI. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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.
+ *
+ * }}} */
+
+/** Log a serie of bytes. */
+#define logger_log(args...) \
+ do { \
+ logger_write_event_counter (); \
+ PREPROC_FOR (logger_log_, ## args) \
+ } while (0)
+#define logger_log_(b) logger_write (b);
+
+#ifndef HOST
+
+/** Initialise logger, do not write anything yet. */
+void
+logger_init (void);
+
+/** Write pending information. */
+void
+logger_update (void);
+
+/** Write event counter for synchronisation. */
+void
+logger_write_event_counter (void);
+
+/** Write one byte in buffer. */
+void
+logger_write (uint8_t b);
+
+#else
+
+#define logger_init()
+#define logger_update()
+#define logger_write_event_counter()
+#define logger_write(b)
+
+#endif
+
+#endif /* logger_h */
diff --git a/digital/io-hub/src/guybrush/main.c b/digital/io-hub/src/guybrush/main.c
index 7a44d142..32463b67 100644
--- a/digital/io-hub/src/guybrush/main.c
+++ b/digital/io-hub/src/guybrush/main.c
@@ -43,6 +43,7 @@
#include "output.h"
#include "radar.h"
#include "pressure.h"
+#include "logger.h"
#define FSM_NAME AI
#include "fsm.h"
@@ -139,6 +140,7 @@ main_init (void)
contact_init ();
output_init ();
usdist_init ();
+ logger_init ();
/* Send some debug aid in case of TWI synchronisation failure.
* If !Z is sent, but not !z, this means that a slave is missing or is not
* functioning. */
@@ -315,6 +317,7 @@ main_loop (void)
/* Is match over? */
if (chrono_is_match_over ())
{
+
/* Open everything. */
IO_SET (OUTPUT_UPPER_CLAMP_OPEN);
IO_CLR (OUTPUT_LOWER_CLAMP_1_CLOSE);
@@ -342,6 +345,7 @@ main_loop (void)
simu_send_pos_report (main_obstacles_pos, main_obstacles_nb, 0);
}
pressure_update ();
+ logger_update ();
/* Update AI modules. */
top_update ();
path_decay ();
diff --git a/digital/io-hub/src/robospierre/logger.h b/digital/io-hub/src/robospierre/logger.h
new file mode 100644
index 00000000..e8668b3f
--- /dev/null
+++ b/digital/io-hub/src/robospierre/logger.h
@@ -0,0 +1,30 @@
+#ifndef logger_h
+#define logger_h
+/* logger.h */
+/* robospierre - Eurobot 2011 AI. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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 logger_log(args...)
+
+#endif /* logger_h */
diff --git a/digital/io/src/logger.h b/digital/io/src/logger.h
new file mode 100644
index 00000000..80fad10e
--- /dev/null
+++ b/digital/io/src/logger.h
@@ -0,0 +1,30 @@
+#ifndef logger_h
+#define logger_h
+/* logger.h */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * 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 logger_log(args...)
+
+#endif /* logger_h */