Please look over this patch and commit if acceptable.

It moves the test for a stable state into the jtag_add_clocks() call and out of each driver , introducing ERROR_JTAG_NOT_STABLE_STATE to report this problem.

It recognizes that a TMS=1 is required for staying in the stable state TAP_RESET, odd duck.

It implements the XTRST opcode in xsvf.c.

It adds the quiet argument to the xsvf command.

Also, if somebody could submit my earlier xsvf_tools patch that would be appreciated.


Thanks,

Dick

Index: src/jtag/bitbang.c
===================================================================
--- src/jtag/bitbang.c	(revision 1355)
+++ src/jtag/bitbang.c	(working copy)
@@ -38,6 +38,14 @@
 #include <unistd.h>
 
 
+/**
+ * Function bitbang_stableclocks
+ * issues a number of clock cycles while staying in a stable state.
+ * Because the TMS value required to stay in the RESET state is a 1, whereas
+ * the TMS value required to stay in any of the other stable states is a 0,
+ * this function checks the current stable state to decide on the value of TMS
+ * to use.
+ */
 static void bitbang_stableclocks(int num_cycles);
 
 
@@ -162,13 +170,14 @@
 
 static void bitbang_stableclocks(int num_cycles)
 {
+	int tms = (cur_state == TAP_RESET ? 1 : 0);
 	int i;
 
 	/* send num_cycles clocks onto the cable */
 	for (i = 0; i < num_cycles; i++)
 	{
-		bitbang_interface->write(1, 0, 0);
-		bitbang_interface->write(0, 0, 0);
+		bitbang_interface->write(1, tms, 0);
+		bitbang_interface->write(0, tms, 0);
 	}
 }
 
@@ -293,6 +302,9 @@
 				break;
 
 			case JTAG_STABLECLOCKS:
+				/* this is only allowed while in a stable state.  A check for a stable
+				 * state was done in jtag_add_clocks()
+				 */
 				bitbang_stableclocks(cmd->cmd.stableclocks->num_cycles);
 				break;
 
Index: src/jtag/ft2232.c
===================================================================
--- src/jtag/ft2232.c	(revision 1355)
+++ src/jtag/ft2232.c	(working copy)
@@ -1415,22 +1415,9 @@
 				break;
 
 			case JTAG_STABLECLOCKS:
-				/* "if (tap_move_map[cur_state] != -1)" is of no help when cur_state==TAP_IDLE */
-				switch(cur_state)
-				{
-				case TAP_DRSHIFT:
-				case TAP_IDLE:
-				case TAP_RESET:
-				case TAP_DRPAUSE:
-				case TAP_IRSHIFT:
-				case TAP_IRPAUSE:
-					 break;			/* above stable states are OK */
-				default:
-					 LOG_ERROR( "jtag_add_clocks() was called with TAP in non-stable state \"%s\"",
-							 jtag_state_name(cur_state) );
-					 retval = ERROR_JTAG_QUEUE_FAILED;
-				}
-
+				/* this is only allowed while in a stable state.  A check for a stable
+				 * state was done in jtag_add_clocks()
+				 */
 				if (ft2232_stableclocks(cmd->cmd.stableclocks->num_cycles, cmd) != ERROR_OK)
 					retval = ERROR_JTAG_QUEUE_FAILED;
 #ifdef _DEBUG_JTAG_IO_
@@ -2336,11 +2323,15 @@
 {
 	int retval = 0;
 
+	/* 7 bits of either ones or zeros. */
+	u8 tms = (cur_state == TAP_RESET ? 0x7F : 0x00);
+
 	while (num_cycles > 0)
 	{
 		/* the command 0x4b, "Clock Data to TMS/CS Pin (no Read)" handles
 		 * at most 7 bits per invocation.  Here we invoke it potentially
 		 * several times.
+		 * see: http://www.ftdichip.com/Documents/AppNotes/AN2232C-01_MPSSE_Cmnd.pdf
 		 */
 		int bitcount_per_command = (num_cycles > 7) ? 7 : num_cycles;
 
@@ -2358,8 +2349,8 @@
 		/* scan 7 bit */
 		BUFFER_ADD = bitcount_per_command - 1;
 
-		/* TMS data bits are all zeros to stay in the current stable state */
-		BUFFER_ADD = 0x0;
+		/* TMS data bits are either all zeros or ones to stay in the current stable state */
+		BUFFER_ADD = tms;
 
 		require_send = 1;
 
Index: src/jtag/jtag.c
===================================================================
--- src/jtag/jtag.c	(revision 1355)
+++ src/jtag/jtag.c	(working copy)
@@ -1093,11 +1093,31 @@
 {
 	int retval;
 
-	jtag_prelude1();
+	/* "if (tap_move_map[cm_queue_cur_state] != -1)" is of no help when cur_state==TAP_IDLE */
+	switch(cmd_queue_cur_state)
+	{
+	case TAP_DRSHIFT:
+	case TAP_IDLE:
+	case TAP_RESET:
+	case TAP_DRPAUSE:
+	case TAP_IRSHIFT:
+	case TAP_IRPAUSE:
+		 break;			/* above stable states are OK */
+	default:
+		 LOG_ERROR( "jtag_add_clocks() was called with TAP in non-stable state \"%s\"",
+				 jtag_state_name(cmd_queue_cur_state) );
+		 jtag_error = ERROR_JTAG_NOT_STABLE_STATE;
+		 return;
+	}
 
-	retval=interface_jtag_add_clocks(num_cycles);
-	if (retval!=ERROR_OK)
-		jtag_error=retval;
+	if( num_cycles > 0 )
+	{
+		jtag_prelude1();
+
+		retval=interface_jtag_add_clocks(num_cycles);
+		if (retval!=ERROR_OK)
+			jtag_error=retval;
+	}
 }
 
 void jtag_add_reset(int req_tlr_or_trst, int req_srst)
Index: src/jtag/jtag.h
===================================================================
--- src/jtag/jtag.h	(revision 1355)
+++ src/jtag/jtag.h	(working copy)
@@ -499,12 +499,14 @@
  * JTAG subsystem uses codes between -100 and -199 */
 
 #define ERROR_JTAG_INIT_FAILED			(-100)
-#define ERROR_JTAG_INVALID_INTERFACE	(-101)
+#define ERROR_JTAG_INVALID_INTERFACE		(-101)
 #define ERROR_JTAG_NOT_IMPLEMENTED		(-102)
-#define ERROR_JTAG_TRST_ASSERTED		(-103)
+#define ERROR_JTAG_TRST_ASSERTED			(-103)
 #define ERROR_JTAG_QUEUE_FAILED			(-104)
+#define ERROR_JTAG_NOT_STABLE_STATE		(-105)
 #define ERROR_JTAG_DEVICE_ERROR			(-107)
 
+
 /* this allows JTAG devices to implement the entire jtag_xxx() layer in hw/sw */
 #ifdef HAVE_JTAG_MINIDRIVER_H
 /* Here a #define MINIDRIVER() and an inline version of hw fifo interface_jtag_add_dr_out can be defined */
Index: src/xsvf/xsvf.c
===================================================================
--- src/xsvf/xsvf.c	(revision 1355)
+++ src/xsvf/xsvf.c	(working copy)
@@ -107,6 +107,7 @@
 #define LCOUNT			0x19
 #define LDELAY			0x1A
 #define LSDR				0x1B
+#define XTRST			0x1C
 
 
 /* XSVF valid state values for the XSTATE command, from appendix B of xapp503.pdf */
@@ -127,6 +128,11 @@
 #define XSV_IREXIT2		0x0E
 #define XSV_IRUPDATE		0x0F
 
+/* arguments to XTRST */
+#define XTRST_ON			0
+#define XTRST_OFF		1
+#define XTRST_Z			2
+#define XTRST_ABSENT		3
 
 #define XSTATE_MAX_PATH 12
 
@@ -210,7 +216,7 @@
 int xsvf_register_commands(struct command_context_s *cmd_ctx)
 {
 	register_command(cmd_ctx, NULL, "xsvf", handle_xsvf_command,
-		COMMAND_EXEC, "run xsvf <file> [virt2]");
+		COMMAND_EXEC, "run xsvf <file> [virt2] [quiet]");
 
 	return ERROR_OK;
 }
@@ -288,6 +294,8 @@
 	int 		unsupported = 0;
 	int 		tdo_mismatch = 0;
 	int 		result;
+	int		verbose = 1;
+	char*	filename;
 
 	int 		runtest_requires_tck = 0;	/* a flag telling whether to clock TCK during waits, or simply sleep, controled by virt2 */
 
@@ -300,10 +308,12 @@
 
 	if (argc < 2)
 	{
-		command_print(cmd_ctx, "usage: xsvf <device#|plain> <file> <variant>");
+		command_print(cmd_ctx, "usage: xsvf <device#|plain> <file> [<variant>] [quiet]");
 		return ERROR_FAIL;
 	}
 
+	filename = args[1];		/* we mess with args starting point below, snapshot filename here */
+
 	if (strcmp(args[0], "plain") != 0)
 	{
 		tap = jtag_TapByString( args[0] );
@@ -314,9 +324,9 @@
 		}
 	}
 
-	if ((xsvf_fd = open(args[1], O_RDONLY)) < 0)
+	if ((xsvf_fd = open(filename, O_RDONLY)) < 0)
 	{
-		command_print(cmd_ctx, "file \"%s\" not found", args[1]);
+		command_print(cmd_ctx, "file \"%s\" not found", filename);
 		return ERROR_FAIL;
 	}
 
@@ -324,8 +334,15 @@
 	if ((argc > 2) && (strcmp(args[2], "virt2") == 0))
 	{
 		runtest_requires_tck = 1;
+		--argc;
+		++args;
 	}
 
+	if ((argc > 2) && (strcmp(args[2], "quiet") == 0))
+	{
+		verbose = 0;
+	}
+
 	LOG_USER("xsvf processing file: \"%s\"", args[1]);
 
 	while( read(xsvf_fd, &opcode, 1) > 0 )
@@ -462,7 +479,8 @@
 
 							jtag_add_pathmove( sizeof(exception_path)/sizeof(exception_path[0]), exception_path);
 
-							LOG_USER("%s %d retry %d", op_name, xsdrsize, attempt);
+							if (verbose)
+								LOG_USER("%s %d retry %d", op_name, xsdrsize, attempt);
 						}
 
 						field.tap = tap;
@@ -749,7 +767,8 @@
 					} while (uc != 0);
 
 					comment[sizeof(comment)-1] = 0;		/* regardless, terminate */
-					LOG_USER(comment);
+					if (verbose)
+						LOG_USER(comment);
 				}
 				break;
 
@@ -924,7 +943,7 @@
 						field.out_mask = NULL;
 						field.in_value = NULL;
 
-						if (attempt > 0)
+						if (attempt > 0 && verbose)
 							LOG_USER("LSDR retry %d", attempt);
 
 						jtag_set_check_value(&field, dr_in_buf, dr_in_mask, NULL);
@@ -954,6 +973,43 @@
 				}
 				break;
 
+			case XTRST:
+				{
+					u8	trst_mode;
+
+					if (read(xsvf_fd, &trst_mode, 1) < 0)
+					{
+						do_abort = 1;
+						break;
+					}
+
+					/*
+					result = jtag_execute_queue();
+					if(result != ERROR_OK)
+					{
+						tdo_mismatch = 1;
+						break;
+					}
+					*/
+
+					switch( trst_mode )
+					{
+					case XTRST_ON:
+						jtag_add_reset(1, 0);
+						break;
+					case XTRST_OFF:
+						jtag_add_reset(1, 1);
+						break;
+					case XTRST_Z:
+					case XTRST_ABSENT:
+						break;
+					default:
+						LOG_ERROR( "XTRST mode argument (0x%02X) out of range", trst_mode );
+						do_abort = 1;
+					}
+				}
+				break;
+
 			default:
 				LOG_ERROR("unknown xsvf command (0x%02X)\n", uc);
 				unsupported = 1;
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to