summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--digital/io/src/getsamples_cb.c3
-rw-r--r--digital/io/src/gutter_cb.c3
-rw-r--r--digital/io/src/main.c13
-rw-r--r--digital/io/src/main.h36
-rw-r--r--digital/io/src/move_cb.c3
5 files changed, 55 insertions, 3 deletions
diff --git a/digital/io/src/getsamples_cb.c b/digital/io/src/getsamples_cb.c
index cb598a16..48b3a520 100644
--- a/digital/io/src/getsamples_cb.c
+++ b/digital/io/src/getsamples_cb.c
@@ -32,6 +32,7 @@
#include "giboulee.h" /* BOT_ */
#include "playground.h" /* PG_* */
+#include "main.h" /* main_post_event_for_top_fsm */
#include "io.h"
@@ -116,7 +117,7 @@ fsm_branch_t
getsamples__CLOSE_INPUT_HOLE__arm_move_succeed (void)
{
/* Tell the top FSM we have finished */
- fsm_handle_event (&top_fsm, TOP_EVENT_get_samples_fsm_finished);
+ main_post_event_for_top_fsm = TOP_EVENT_get_samples_fsm_finished + 1;
return getsamples_next (CLOSE_INPUT_HOLE, arm_move_succeed);
}
diff --git a/digital/io/src/gutter_cb.c b/digital/io/src/gutter_cb.c
index 3824a259..22696c20 100644
--- a/digital/io/src/gutter_cb.c
+++ b/digital/io/src/gutter_cb.c
@@ -29,6 +29,7 @@
#include "asserv.h" /* asserv_go_to_the_wall */
#include "trap.h" /* trap_* */
#include "playground.h" /* PG_GUTTER_A */
+#include "main.h" /* main_post_event_for_top_fsm */
/**
* Gutter private data to wait a certain number of cycles.
@@ -97,6 +98,6 @@ gutter__DROP_BALLS__wait_finished (void)
/* Close the rear panel */
trap_close_rear_panel ();
/* Tell the top FSM we have finished */
- fsm_handle_event (&top_fsm, TOP_EVENT_gutter_fsm_finished);
+ main_post_event_for_top_fsm = TOP_EVENT_gutter_fsm_finished + 1;
return gutter_next (DROP_BALLS, wait_finished);
}
diff --git a/digital/io/src/main.c b/digital/io/src/main.c
index 81928cd6..0baf8738 100644
--- a/digital/io/src/main.c
+++ b/digital/io/src/main.c
@@ -64,6 +64,11 @@ static void main_loop (void);
enum team_color_e bot_color;
/**
+ * Post a event to the top FSM in the next iteration of main loop.
+ */
+uint8_t main_post_event_for_top_fsm;
+
+/**
* Initialize the main and all its subsystems.
*/
static void
@@ -197,6 +202,14 @@ main_loop (void)
{
FSM_HANDLE_EVENT (&gutter_fsm, GUTTER_EVENT_wait_finished);
}
+ /* Event generated at the end of the sub FSM to post to the top FSM */
+ if (main_post_event_for_top_fsm)
+ {
+ /* Post the event */
+ FSM_HANDLE_EVENT (&top_fsm, main_post_event_for_top_fsm - 1);
+ /* Reset */
+ main_post_event_for_top_fsm = 0;
+ }
/* TODO: Check other sensors */
}
}
diff --git a/digital/io/src/main.h b/digital/io/src/main.h
new file mode 100644
index 00000000..40bf1f9d
--- /dev/null
+++ b/digital/io/src/main.h
@@ -0,0 +1,36 @@
+#ifndef main_h
+#define main_h
+/* main.h */
+/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
+ *
+ * Copyright (C) 2008 Dufour Jérémy
+ *
+ * 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.
+ *
+ * }}} */
+
+/**
+ * Post a event to the top FSM in the next iteration of main loop.
+ * You just need to set variable to the value of the event you want to post to
+ * the top FSM and add one to it (because some event could have a zero value).
+ * It will be posted and cleared in the next main loop iteration.
+ */
+extern uint8_t main_post_event_for_top_fsm;
+
+#endif /* main_h */
diff --git a/digital/io/src/move_cb.c b/digital/io/src/move_cb.c
index 12e10c35..e7069c37 100644
--- a/digital/io/src/move_cb.c
+++ b/digital/io/src/move_cb.c
@@ -10,6 +10,7 @@
#include "move_cb.h"
#include "move.h"
#include "asserv.h"
+#include "main.h" /* main_post_event_for_top_fsm */
/*
* IDLE =start=>
@@ -86,7 +87,7 @@ move__DESIRED_POSITION__blocked (void)
fsm_branch_t
move__DESIRED_POSITION__reached (void)
{
- fsm_handle_event (&top_fsm, TOP_EVENT_move_fsm_finished);
+ main_post_event_for_top_fsm = TOP_EVENT_move_fsm_finished + 1;
return move_next (DESIRED_POSITION, reached);
}