[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openocd-development
Subject:    [OpenOCD-devel] [PATCH]: 90ed918 drivers/jtag: usb_blaster add pin controls
From:       gerrit () openocd ! zylin ! com
Date:       2013-06-17 18:35:04
Message-ID: 20130617183504.CE78F242C2 () openocd ! zylin ! com
[Download RAW message or body]

This is an automated email from Gerrit.

Robert Jarzmik (robert.jarzmik@free.fr) just uploaded a new patch set to Gerrit, \
which you can find at http://openocd.zylin.com/1448

-- gerrit

commit 90ed918a44874198dddde5938c0de271b1ad9f8f
Author: Robert Jarzmik <robert.jarzmik@free.fr>
Date:   Sun Jun 16 20:22:30 2013 +0200

    drivers/jtag: usb_blaster add pin controls
    
    Add pin controls (pin6 and pin8). These pins can be
    controled either :
     - with a fixed value (0 or 1)
     - by TRST or SRST reset signal (driven low when signal
     activated).
    
    Change-Id: Ie6a3e57fc6ba6a38fdb9a009c976e3febab8f578
    Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr>

diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c \
b/src/jtag/drivers/usb_blaster/usb_blaster.c index 3400ca5..4ffbcbf 100644
--- a/src/jtag/drivers/usb_blaster/usb_blaster.c
+++ b/src/jtag/drivers/usb_blaster/usb_blaster.c
@@ -82,11 +82,20 @@
  */
 #define BUF_LEN 4096
 
+enum GPIO_PIN {
+	FIXED_0 = 0,
+	FIXED_1,
+	SRST,
+	TRST,
+};
+
 struct ublast_info {
-	int pin6;
-	int pin8;
+	enum GPIO_PIN pin6;
+	enum GPIO_PIN pin8;
 	int tms;
 	int tdi;
+	bool trst_asserted;
+	bool srst_asserted;
 	uint8_t buf[BUF_LEN];
 	int bufidx;
 
@@ -103,6 +112,10 @@ static struct ublast_info info = {
 	.ublast_vid = 0x09fb, /* Altera */
 	.ublast_pid = 0x6001, /* USB-Blaster */
 	.lowlevel_name = NULL,
+	.srst_asserted = false,
+	.trst_asserted = false,
+	.pin6 = FIXED_1,
+	.pin8 = FIXED_1,
 };
 
 /*
@@ -219,20 +232,6 @@ static void ublast_flush_buffer(void)
 #define READ_TDO	(1 << 0)
 
 /**
- * ublast_reset - reset the JTAG device is possible
- * @trst: 1 if TRST is to be asserted
- * @srst: 1 if SRST is to be asserted
- *
- * This is not implemented yet. If pin6 or pin8 controlls the TRST/SRST, code
- * should be added so that this function makes use of it.
- */
-static void ublast_reset(int trst, int srst)
-{
-	DEBUG_JTAG_IO("TODO: ublast_reset(%d,%d) isn't implemented!",
-		  trst, srst);
-}
-
-/**
  * ublast_queue_byte - queue one 'bitbang mode' byte for USB Blaster
  * @abyte: the byte to queue
  *
@@ -251,6 +250,28 @@ static void ublast_queue_byte(uint8_t abyte)
 }
 
 /**
+ * ublast_compute_pin - compute if gpio should be asserted
+ * @state: control (ie. TRST driven, SRST driven, of fixed)
+ *
+ * Returns pin value (1 means driven high, 0 mean driven low)
+ */
+bool ublast_compute_pin(enum GPIO_PIN state)
+{
+	switch(state) {
+	case FIXED_0:
+		return 0;
+	case FIXED_1:
+		return 1;
+	case SRST:
+		return !info.srst_asserted;
+	case TRST:
+		return !info.trst_asserted;
+	default:
+		return 1;
+	}
+}
+
+/**
  * ublast_build_out - build bitbang mode output byte
  * @type: says if reading back TDO is required
  *
@@ -261,8 +282,8 @@ static uint8_t ublast_build_out(enum scan_type type)
 	uint8_t abyte = 0;
 
 	abyte |= info.tms ? TMS : 0;
-	abyte |= info.pin6 ? NCE : 0;
-	abyte |= info.pin8 ? NCS : 0;
+	abyte |= ublast_compute_pin(info.pin6) ? NCE : 0;
+	abyte |= ublast_compute_pin(info.pin8) ? NCS : 0;
 	abyte |= info.tdi ? TDI : 0;
 	abyte |= LED;
 	if (type == SCAN_IN || type == SCAN_IO)
@@ -271,6 +292,25 @@ static uint8_t ublast_build_out(enum scan_type type)
 }
 
 /**
+ * ublast_reset - reset the JTAG device is possible
+ * @trst: 1 if TRST is to be asserted
+ * @srst: 1 if SRST is to be asserted
+ *
+ * This is not implemented yet. If pin6 or pin8 controlls the TRST/SRST, code
+ * should be added so that this function makes use of it.
+ */
+static void ublast_reset(int trst, int srst)
+{
+	uint8_t out_value;
+
+	info.trst_asserted = trst;
+	info.srst_asserted = srst;
+	out_value = ublast_build_out(SCAN_OUT);
+	ublast_queue_byte(out_value);
+	ublast_flush_buffer();
+}
+
+/**
  * ublast_clock_tms - clock a TMS transition
  * @tms: the TMS to be sent
  *
@@ -841,14 +881,54 @@ COMMAND_HANDLER(ublast_handle_vid_pid_command)
 COMMAND_HANDLER(ublast_handle_pin_command)
 {
 	uint8_t out_value;
+	const char * const pin_name = CMD_ARGV[0];
+	enum GPIO_PIN state;
+	static const char *pin_val_str[] = {
+		"0", "1", "SRST driven", "TRST driven",
+	};
 
-	if (CMD_ARGC == 2) {
-		const char * const pin_name = CMD_ARGV[0];
-		unsigned int state;
+	if (CMD_ARGC > 2) {
+		LOG_ERROR("%s takes exactly one or two arguments", CMD_NAME);
+		return ERROR_COMMAND_SYNTAX_ERROR;
+	}
+	if (strcmp(pin_name, "pin6") && (strcmp(pin_name, "pin8"))) {
+		LOG_ERROR("%s: pin name must be \"pin6\" or \"pin8\"",
+			  CMD_NAME);
+		return ERROR_COMMAND_SYNTAX_ERROR;
+	}
+
+	if (CMD_ARGC == 1) {
+		if (!strcmp(pin_name, "pin6"))
+			state = info.pin6;
+		else if (!strcmp(pin_name, "pin8"))
+			state = info.pin8;
+		LOG_INFO("%s: %s is set as %s\n", CMD_NAME, pin_name,
+			 pin_val_str[state]);
+		return ERROR_OK;
+	}
 
-		COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], state);
-		if ((state != 0) && (state != 1)) {
-			LOG_ERROR("%s: pin state must be 0 or 1", CMD_NAME);
+	if (CMD_ARGC == 2) {
+		const char * const pin_value = CMD_ARGV[1];
+		char val = pin_value[0];
+
+		if (strlen(pin_value) > 1)
+			val = '?';
+		switch(tolower(val)) {
+		case '0':
+			state = FIXED_0;
+			break;
+		case '1':
+			state = FIXED_1;
+			break;
+		case 't':
+			state = TRST;
+			break;
+		case 's':
+			state = SRST;
+			break;
+		default:
+			LOG_ERROR("%s: pin value must be 0, 1, s (SRST) or t (TRST)",
+				pin_value);
 			return ERROR_COMMAND_SYNTAX_ERROR;
 		}
 
@@ -856,10 +936,6 @@ COMMAND_HANDLER(ublast_handle_pin_command)
 			info.pin6 = state;
 		} else if (!strcmp(pin_name, "pin8")) {
 			info.pin8 = state;
-		} else {
-			LOG_ERROR("%s: pin name must be \"pin6\" or \"pin8\"",
-					CMD_NAME);
-			return ERROR_COMMAND_SYNTAX_ERROR;
 		}
 
 		if (info.drv) {
@@ -911,7 +987,7 @@ static const struct command_registration \
                ublast_command_handlers[] = {
 		.handler = ublast_handle_pin_command,
 		.mode = COMMAND_ANY,
 		.help = "set pin state for the unused GPIO pins",
-		.usage = "(pin6|pin8) (0|1)",
+		.usage = "(pin6|pin8) (0|1|s|t)",
 	},
 	COMMAND_REGISTRATION_DONE
 };

-- 

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic