]> git.sur5r.net Git - openocd/commitdiff
Dick Hollenbeck <dick@softplc.com> - This patch adds JTAG state tracking to dummy.c
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 19 Dec 2008 19:41:58 +0000 (19:41 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 19 Dec 2008 19:41:58 +0000 (19:41 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@1263 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/jtag/dummy.c

index f6ca87c2488b5d09b086b5037bbf5763de5f3d8d..a3a0a1aa9ae28de46530c24e0a7f83b4da01a86c 100644 (file)
 #include "jtag.h"\r
 #include "bitbang.h"\r
 \r
+\r
+/* my private tap controller state, which tracks state for calling code */\r
+static tap_state_t dummy_state = TAP_RESET;\r
+\r
+static int dummy_clock;         /* edge detector */\r
+\r
+static tap_state_t tap_state_transition(tap_state_t cur_state, int tms);\r
+\r
+\r
 int dummy_speed(int speed);\r
 int dummy_register_commands(struct command_context_s *cmd_ctx);\r
 int dummy_init(void);\r
@@ -70,12 +79,28 @@ int dummy_read(void)
        return 1;\r
 }\r
 \r
+\r
 void dummy_write(int tck, int tms, int tdi)\r
 {\r
+       /* TAP standard: "state transitions occur on rising edge of clock" */\r
+       if( tck != dummy_clock )\r
+       {\r
+               if( tck )\r
+               {\r
+                       int old_state = dummy_state;\r
+                       dummy_state = tap_state_transition( dummy_state, tms );\r
+                       if( old_state != dummy_state )\r
+                               LOG_INFO( "dummy_tap=%s", jtag_state_name(dummy_state) );\r
+               }\r
+               dummy_clock = tck;\r
+       }\r
 }\r
 \r
 void dummy_reset(int trst, int srst)\r
 {\r
+       dummy_clock = 0;\r
+       dummy_state = TAP_RESET;\r
+       LOG_DEBUG( "reset to %s", jtag_state_name(dummy_state) );\r
 }\r
 \r
 static int dummy_khz(int khz, int *jtag_speed)\r
@@ -130,3 +155,107 @@ int dummy_quit(void)
 void dummy_led(int on)\r
 {\r
 }\r
+\r
+\r
+/**\r
+ * Function tap_state_transition\r
+ * takes a current TAP state and returns the next state according to the tms value.\r
+ *\r
+ * Even though there is code to duplicate this elsewhere, we do it here a little\r
+ * differently just to get a second opinion, i.e. a verification, on state tracking\r
+ * in that other logic. Plus array lookups without index checking are no favorite thing.\r
+ * This is educational for developers new to TAP controllers.\r
+ */\r
+static tap_state_t tap_state_transition(tap_state_t cur_state, int tms)\r
+{\r
+       tap_state_t new_state;\r
+\r
+       if (tms)\r
+       {\r
+               switch (cur_state)\r
+               {\r
+               case TAP_RESET:\r
+                       new_state = cur_state;\r
+                       break;\r
+               case TAP_IDLE:\r
+               case TAP_DRUPDATE:\r
+               case TAP_IRUPDATE:\r
+                       new_state = TAP_DRSELECT;\r
+                       break;\r
+               case TAP_DRSELECT:\r
+                       new_state = TAP_IRSELECT;\r
+                       break;\r
+               case TAP_DRCAPTURE:\r
+               case TAP_DRSHIFT:\r
+                       new_state = TAP_DREXIT1;\r
+                       break;\r
+               case TAP_DREXIT1:\r
+               case TAP_DREXIT2:\r
+                       new_state = TAP_DRUPDATE;\r
+                       break;\r
+               case TAP_DRPAUSE:\r
+                       new_state = TAP_DREXIT2;\r
+                       break;\r
+               case TAP_IRSELECT:\r
+                       new_state = TAP_RESET;\r
+                       break;\r
+               case TAP_IRCAPTURE:\r
+               case TAP_IRSHIFT:\r
+                       new_state = TAP_IREXIT1;\r
+                       break;\r
+               case TAP_IREXIT1:\r
+               case TAP_IREXIT2:\r
+                       new_state = TAP_IRUPDATE;\r
+                       break;\r
+               case TAP_IRPAUSE:\r
+                       new_state = TAP_IREXIT2;\r
+                       break;\r
+               default:\r
+                       LOG_ERROR( "fatal: invalid argument cur_state=%d", cur_state );\r
+                       exit(1);\r
+                       break;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               switch (cur_state)\r
+               {\r
+               case TAP_RESET:\r
+               case TAP_IDLE:\r
+               case TAP_DRUPDATE:\r
+               case TAP_IRUPDATE:\r
+                       new_state = TAP_IDLE;\r
+                       break;\r
+               case TAP_DRSELECT:\r
+                       new_state = TAP_DRCAPTURE;\r
+                       break;\r
+               case TAP_DRCAPTURE:\r
+               case TAP_DRSHIFT:\r
+               case TAP_DREXIT2:\r
+                       new_state = TAP_DRSHIFT;\r
+                       break;\r
+               case TAP_DREXIT1:\r
+               case TAP_DRPAUSE:\r
+                       new_state = TAP_DRPAUSE;\r
+                       break;\r
+               case TAP_IRSELECT:\r
+                       new_state = TAP_IRCAPTURE;\r
+                       break;\r
+               case TAP_IRCAPTURE:\r
+               case TAP_IRSHIFT:\r
+               case TAP_IREXIT2:\r
+                       new_state = TAP_IRSHIFT;\r
+                       break;\r
+               case TAP_IREXIT1:\r
+               case TAP_IRPAUSE:\r
+                       new_state = TAP_IRPAUSE;\r
+                       break;\r
+               default:\r
+                       LOG_ERROR( "fatal: invalid argument cur_state=%d", cur_state );\r
+                       exit(1);\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return new_state;\r
+}\r