From 3d91eb26478dd0801294ce0ead01605687687d5e Mon Sep 17 00:00:00 2001 From: Jérôme Jutteau Date: Sat, 14 May 2011 13:29:02 +0200 Subject: digital/ai/src/fsm: use program space read function for transition table --- digital/ai/src/fsm/fsm.host.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'digital/ai/src/fsm/fsm.host.c') diff --git a/digital/ai/src/fsm/fsm.host.c b/digital/ai/src/fsm/fsm.host.c index bf8b761d..b7b6ab4e 100644 --- a/digital/ai/src/fsm/fsm.host.c +++ b/digital/ai/src/fsm/fsm.host.c @@ -1056,11 +1056,18 @@ fsm_build_gen_avr_h (fsm_build_t *fsm, uint embedded_strings) /* Gen function table. */ fprintf (f, "typedef fsm_%s_branch_t (*fsm_%s_func_t)(void);\n", fsm->name, fsm->name); - fprintf (f, "extern const fsm_%s_func_t PROGMEM fsm_%s_trans_table[%u][%u];\n\n", + fprintf (f, "extern const fsm_%s_func_t PROGMEM fsm_%s_trans_table[%u][%u];\n", fsm->name, fsm->name, fsm->event_nb, fsm->state_nb); + /* Gen read function for trans table. */ + fprintf (f, "fsm_%s_func_t fsm_%s_read_trans (fsm_%s_event_t event, " + "fsm_%s_state_t state);\n\n", + fsm->name, + fsm->name, + fsm->name, + fsm->name); /* Gen active states array. */ fprintf (f, "extern fsm_%s_state_t fsm_%s_active_states[%u];\n\n", @@ -1280,6 +1287,19 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings) } fprintf (f, "};\n\n"); + /* Gen read function for trans table. */ + fprintf (f, "fsm_%s_func_t fsm_%s_read_trans (fsm_%s_event_t event, " + "fsm_%s_state_t state)\n{\n", + fsm->name, + fsm->name, + fsm->name, + fsm->name); + fprintf (f, "\treturn (fsm_%s_func_t) pgm_read_word " + "(&fsm_%s_trans_table[event][state]);\n", + fsm->name, + fsm->name); + fprintf (f, "}\n\n"); + /* Gen active states array. */ fprintf (f, "fsm_%s_state_t fsm_%s_active_states[%u];\n\n", fsm->name, @@ -1324,15 +1344,15 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings) fprintf (f, "\tint handled = 0;\n"); fprintf (f, "\tfor (i = 0; i < fsm_%s_max_active_states; i++)\n\t{\n", fsm->name); - fprintf (f, "\t\tif (fsm_%s_trans_table[e][fsm_%s_active_states[i]])\n", + fprintf (f, "\t\tif (fsm_%s_read_trans (e, fsm_%s_active_states[i]))\n", fsm->name, fsm->name); fprintf (f, "\t\t{\n"); - fprintf (f, "\t\t\tfsm_%s_active_states[i] = \ - fsm_%s_trans_table[e][fsm_%s_active_states[i]]();\n", - fsm->name, - fsm->name, - fsm->name); + fprintf (f, "\t\t\tfsm_%s_active_states[i] = fsm_%s_read_trans (e, " + "fsm_%s_active_states[i])();\n", + fsm->name, + fsm->name, + fsm->name); fprintf (f, "\t\t\thandled = 1;\n"); if (fsm->timeouts != NULL) { @@ -1352,9 +1372,9 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings) fprintf (f, "\tuint16_t i;\n"); fprintf (f, "\tfor (i = 0; i < fsm_%s_max_active_states; i++)\n", fsm->name); - fprintf (f, "\t\tif (fsm_%s_trans_table[e][fsm_%s_active_states[i]])\n", - fsm->name, - fsm->name); + fprintf (f, "\t\tif (fsm_%s_read_trans (e, fsm_%s_active_states[i]))\n", + fsm->name, + fsm->name); fprintf (f, "\t\t\treturn 1;\n"); fprintf (f, "\treturn 0;\n"); fprintf (f, "}\n\n"); -- cgit v1.2.3 From 9bd92331b124a2123b3f9fb6bf84510c81ccce5e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 21 May 2011 13:04:28 +0200 Subject: digital/ai/src/fsm: fix AVR timeout code --- digital/ai/src/fsm/fsm.host.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'digital/ai/src/fsm/fsm.host.c') diff --git a/digital/ai/src/fsm/fsm.host.c b/digital/ai/src/fsm/fsm.host.c index b7b6ab4e..ad791272 100644 --- a/digital/ai/src/fsm/fsm.host.c +++ b/digital/ai/src/fsm/fsm.host.c @@ -1451,18 +1451,19 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings) fprintf (f, "\tint out = 0;\n"); fprintf (f, "\tfor (i = 0; i < fsm_%s_max_active_states; i++)\n\t{\n", fsm->name); - fprintf (f, "\t\tif (fsm_%s_timeout_counters[i] > 0)\n", + fprintf (f, "\t\tif (fsm_%s_timeout_counters[i] > 0)\n\t\t{\n", fsm->name); fprintf (f, "\t\t\tfsm_%s_timeout_counters[i]--;\n", fsm->name); - fprintf (f, "\t\tif (fsm_%s_timeout_counters[i] == 0)\n\t\t{\n", + fprintf (f, "\t\t\tif (fsm_%s_timeout_counters[i] == 0)\n\t\t\t{\n", fsm->name); - fprintf (f, "\t\t\tfsm_%s_handle (fsm_%s_timeout_events[fsm_%s_active_states[i]]);\n", + fprintf (f, "\t\t\t\tfsm_%s_handle (fsm_%s_timeout_events[fsm_%s_active_states[i]]);\n", fsm->name, fsm->name, fsm->name); - fprintf (f, "\t\t\tout = 1;\n"); - fprintf (f, "\t\t}\n\n"); + fprintf (f, "\t\t\t\tout = 1;\n"); + fprintf (f, "\t\t\t}\n"); + fprintf (f, "\t\t}\n"); fprintf (f, "\t}\n"); fprintf (f, "\treturn out;\n"); fprintf (f, "}\n\n"); -- cgit v1.2.3 From 22d384a1c0fc9464c25db92550210c4d633c97e1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 27 May 2011 00:21:28 +0200 Subject: digital/ai/src/fsm: fix timeout assignment --- digital/ai/src/fsm/fsm.host.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'digital/ai/src/fsm/fsm.host.c') diff --git a/digital/ai/src/fsm/fsm.host.c b/digital/ai/src/fsm/fsm.host.c index ad791272..ed93221d 100644 --- a/digital/ai/src/fsm/fsm.host.c +++ b/digital/ai/src/fsm/fsm.host.c @@ -1356,7 +1356,9 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings) fprintf (f, "\t\t\thandled = 1;\n"); if (fsm->timeouts != NULL) { - fprintf (f, "\t\t\tfsm_%s_timeout_counters[i] = fsm_%s_timeout_values[e];\n", + fprintf (f, "\t\t\tfsm_%s_timeout_counters[i] = " + "fsm_%s_timeout_values[fsm_%s_active_states[i]];\n", + fsm->name, fsm->name, fsm->name); } -- cgit v1.2.3 From 09193b811d682c035fca4a15caf0728c1d36a9c1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 3 Jun 2011 08:35:10 +0200 Subject: digital/ai/src/fsm: add proto debug --- digital/ai/src/fsm/fsm.host.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'digital/ai/src/fsm/fsm.host.c') diff --git a/digital/ai/src/fsm/fsm.host.c b/digital/ai/src/fsm/fsm.host.c index ed93221d..50336722 100644 --- a/digital/ai/src/fsm/fsm.host.c +++ b/digital/ai/src/fsm/fsm.host.c @@ -1144,6 +1144,7 @@ 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 \"fsm_%s_gen.h\"\n\n", fsm->name); + fprintf (f, "#include \"modules/proto/proto.h\"\n\n"); /* Gen state strings. */ if (embedded_strings) @@ -1348,6 +1349,8 @@ fsm_build_gen_avr_c (fsm_build_t *fsm, uint embedded_strings) fsm->name, fsm->name); fprintf (f, "\t\t{\n"); + fprintf (f, "\t\t\tproto_send2b ('F', fsm_%s_active_states[i], e);\n", + fsm->name); fprintf (f, "\t\t\tfsm_%s_active_states[i] = fsm_%s_read_trans (e, " "fsm_%s_active_states[i])();\n", fsm->name, -- cgit v1.2.3