#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
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
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