From 03b5d454ee5a0a927d336ea18f34949d9c579aea Mon Sep 17 00:00:00 2001 From: Rutger Hofman Date: Thu, 4 Jun 2009 16:27:22 +0000 Subject: [PATCH] In USB cable open(), parport set/get_data/get_status/set_control, return/handle URJ_STATUS_OK/FAIL more correctly git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1642 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 5 ++ urjtag/src/tap/cable.c | 2 - urjtag/src/tap/cable/arcom.c | 18 ++++--- urjtag/src/tap/cable/byteblaster.c | 43 ++++++++++++---- urjtag/src/tap/cable/dlc5.c | 22 +++++--- urjtag/src/tap/cable/ea253.c | 18 ++++--- urjtag/src/tap/cable/ei012.c | 26 ++++++---- urjtag/src/tap/cable/ft2232.c | 75 ++++++++++++---------------- urjtag/src/tap/cable/jim.c | 4 +- urjtag/src/tap/cable/jlink.c | 16 +++--- urjtag/src/tap/cable/keithkoep.c | 15 ++++-- urjtag/src/tap/cable/lattice.c | 13 +++-- urjtag/src/tap/cable/mpcbdm.c | 10 +++- urjtag/src/tap/cable/triton.c | 9 +++- urjtag/src/tap/cable/ts7800.c | 4 +- urjtag/src/tap/cable/usbblaster.c | 2 +- urjtag/src/tap/cable/vision_ep9307.c | 4 +- urjtag/src/tap/cable/wiggler.c | 19 ++++--- urjtag/src/tap/cable/wiggler2.c | 9 +++- urjtag/src/tap/cable/xpc.c | 2 +- urjtag/src/tap/parport/direct.c | 2 - urjtag/src/tap/usbconn/libftdi.c | 6 +-- 22 files changed, 198 insertions(+), 126 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index d2b7f9f1..f9a93180 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,8 @@ +2009-06-04 Rutger Hofman + + * src/tap/cable/*.c, src/tap/parport/*.c, src/tap/usbconn/*.c: return/handle + URJ_STATUS_OK/FAIL more correctly + 2009-06-02 Arnim Laeuger * src/cmd/cmd_initbus.c: use separate index variable for driver selection diff --git a/urjtag/src/tap/cable.c b/urjtag/src/tap/cable.c index 1bb87dfd..3b18d732 100644 --- a/urjtag/src/tap/cable.c +++ b/urjtag/src/tap/cable.c @@ -43,8 +43,6 @@ #include #include -#undef VERBOSE - /* @@@@ RFHH stick these into a (or many) .h files */ extern urj_cable_driver_t urj_tap_cable_arcom_driver; extern urj_cable_driver_t urj_tap_cable_byteblaster_driver; diff --git a/urjtag/src/tap/cable/arcom.c b/urjtag/src/tap/cable/arcom.c index cc06a077..35eabb63 100644 --- a/urjtag/src/tap/cable/arcom.c +++ b/urjtag/src/tap/cable/arcom.c @@ -54,19 +54,20 @@ arcom_init (urj_cable_t *cable) { int data; - if (urj_tap_parport_open (cable->link.port)) - return -1; + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; if ((data = urj_tap_parport_get_data (cable->link.port)) < 0) { - if (urj_tap_parport_set_data (cable->link.port, 1 << TRST)) - return -1; + if (urj_tap_parport_set_data (cable->link.port, + 1 << TRST) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST; } else PARAM_SIGNALS (cable) = ((data >> TRST) && 1) ? URJ_POD_CS_TRST : 0; - return 0; + return URJ_STATUS_OK; } static void @@ -100,6 +101,7 @@ static int arcom_get_tdo (urj_cable_t *cable) { int trst = (PARAM_SIGNALS (cable) & URJ_POD_CS_TRST) ? 1 : 0; + int status; urj_tap_parport_set_data (cable->link.port, (trst << TRST) | (0 << TCK)); PARAM_SIGNALS (cable) &= @@ -107,7 +109,11 @@ arcom_get_tdo (urj_cable_t *cable) urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/byteblaster.c b/urjtag/src/tap/cable/byteblaster.c index 8713058d..08461c16 100644 --- a/urjtag/src/tap/cable/byteblaster.c +++ b/urjtag/src/tap/cable/byteblaster.c @@ -71,30 +71,47 @@ static int byteblaster_init (urj_cable_t *cable) { int BB_II = 0; + int status; - if (urj_tap_parport_open (cable->link.port)) - return -1; + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST; /* check if a ByteBlaster or ByteBlasterMV is connected */ urj_tap_parport_set_data (cable->link.port, 1 << BB_CHECK); - if (!((urj_tap_parport_get_status (cable->link.port) >> BB_PRESENT) & 1)) + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return URJ_STATUS_FAIL; + if (!((status >> BB_PRESENT) & 1)) BB_II = 1; urj_tap_parport_set_data (cable->link.port, 0); - if ((urj_tap_parport_get_status (cable->link.port) >> BB_PRESENT) & 1) + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return URJ_STATUS_FAIL; + if ((status >> BB_PRESENT) & 1) BB_II = 1; /* check if the power supply is ok (only for ByteBlaster II) */ /* if no ByteBlaster at all is connected this check will fail, too */ - if ((BB_II) - && ((urj_tap_parport_get_status (cable->link.port) >> VCC_OK_N) & 1)) - return -1; + if (BB_II) + { + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return URJ_STATUS_FAIL; + if ((status >> VCC_OK_N) & 1) + { + urj_error_set (URJ_ERROR_ILLEGAL_STATE, "Power supply not OK"); + return URJ_STATUS_FAIL; + } + } /* Enable ByteBlaster */ - urj_tap_parport_set_control (cable->link.port, BB_ENABLE); + if (urj_tap_parport_set_control (cable->link.port, + BB_ENABLE) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; - return 0; + return URJ_STATUS_OK; } static void @@ -125,12 +142,18 @@ static int byteblaster_get_tdo (urj_cable_t *cable) { urj_tap_parport_set_data (cable->link.port, 0 << TCK); + int status; + PARAM_SIGNALS (cable) &= ~(URJ_POD_CS_TDI | URJ_POD_CS_TCK | URJ_POD_CS_TMS); urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/dlc5.c b/urjtag/src/tap/cable/dlc5.c index 2354c76d..8ec432d6 100644 --- a/urjtag/src/tap/cable/dlc5.c +++ b/urjtag/src/tap/cable/dlc5.c @@ -59,12 +59,12 @@ static int dlc5_init (urj_cable_t *cable) { - if (urj_tap_parport_open (cable->link.port)) - return -1; + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST; - return 0; + return URJ_STATUS_OK; } static void @@ -78,12 +78,12 @@ dlc5_clock (urj_cable_t *cable, int tms, int tdi, int n) for (i = 0; i < n; i++) { urj_tap_parport_set_data (cable->link.port, - (1 << PROG) | (0 << TCK) | (tms << TMS) | - (tdi << TDI)); + (1 << PROG) | (0 << TCK) | (tms << TMS) + | (tdi << TDI)); urj_tap_cable_wait (cable); urj_tap_parport_set_data (cable->link.port, - (1 << PROG) | (1 << TCK) | (tms << TMS) | - (tdi << TDI)); + (1 << PROG) | (1 << TCK) | (tms << TMS) + | (tdi << TDI)); urj_tap_cable_wait (cable); } @@ -96,13 +96,19 @@ dlc5_clock (urj_cable_t *cable, int tms, int tdi, int n) static int dlc5_get_tdo (urj_cable_t *cable) { + int status; + urj_tap_parport_set_data (cable->link.port, (1 << PROG) | (0 << TCK)); PARAM_SIGNALS (cable) &= ~(URJ_POD_CS_TDI | URJ_POD_CS_TCK | URJ_POD_CS_TMS); urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/ea253.c b/urjtag/src/tap/cable/ea253.c index c9c063c8..71ee81d0 100644 --- a/urjtag/src/tap/cable/ea253.c +++ b/urjtag/src/tap/cable/ea253.c @@ -54,19 +54,20 @@ ea253_init (urj_cable_t *cable) { int data; - if (urj_tap_parport_open (cable->link.port)) - return -1; + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; if ((data = urj_tap_parport_get_data (cable->link.port)) < 0) { - if (urj_tap_parport_set_data (cable->link.port, 1 << TRST)) - return -1; + if (urj_tap_parport_set_data (cable->link.port, + 1 << TRST) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST; } else PARAM_SIGNALS (cable) = ((data >> TRST) && 1) ? URJ_POD_CS_TRST : 0; - return 0; + return URJ_STATUS_OK; } static void @@ -100,6 +101,7 @@ static int ea253_get_tdo (urj_cable_t *cable) { int trst = (PARAM_SIGNALS (cable) & URJ_POD_CS_TRST) ? 1 : 0; + int status; urj_tap_parport_set_data (cable->link.port, (trst << TRST) | (0 << TCK)); PARAM_SIGNALS (cable) &= @@ -107,7 +109,11 @@ ea253_get_tdo (urj_cable_t *cable) urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/ei012.c b/urjtag/src/tap/cable/ei012.c index 1e863120..045bcfc2 100644 --- a/urjtag/src/tap/cable/ei012.c +++ b/urjtag/src/tap/cable/ei012.c @@ -56,19 +56,20 @@ ei012_init (urj_cable_t *cable) { int data; - if (urj_tap_parport_open (cable->link.port)) - return -1; + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; if ((data = urj_tap_parport_get_data (cable->link.port)) < 0) { - if (urj_tap_parport_set_data (cable->link.port, 1 << TRST)) - return -1; + if (urj_tap_parport_set_data (cable->link.port, + 1 << TRST) != URJ_STATUS_OK) + return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST; } else PARAM_SIGNALS (cable) = ((data >> TRST) && 1) ? URJ_POD_CS_TRST : 0; - return 0; + return URJ_STATUS_OK; } static void @@ -83,12 +84,12 @@ ei012_clock (urj_cable_t *cable, int tms, int tdi, int n) for (i = 0; i < n; i++) { urj_tap_parport_set_data (cable->link.port, - (trst << TRST) | (0 << TCK) | (tms << TMS) | - (tdi << TDI)); + (trst << TRST) | (0 << TCK) | (tms << TMS) + | (tdi << TDI)); urj_tap_cable_wait (cable); urj_tap_parport_set_data (cable->link.port, - (trst << TRST) | (1 << TCK) | (tms << TMS) | - (tdi << TDI)); + (trst << TRST) | (1 << TCK) | (tms << TMS) + | (tdi << TDI)); urj_tap_cable_wait (cable); } @@ -102,6 +103,7 @@ static int ei012_get_tdo (urj_cable_t *cable) { int trst = (PARAM_SIGNALS (cable) & URJ_POD_CS_TRST) ? 1 : 0; + int status; urj_tap_parport_set_data (cable->link.port, (trst << TRST) | (0 << TCK)); PARAM_SIGNALS (cable) &= @@ -109,7 +111,11 @@ ei012_get_tdo (urj_cable_t *cable) urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/ft2232.c b/urjtag/src/tap/cable/ft2232.c index c6e05be7..7d393358 100644 --- a/urjtag/src/tap/cable/ft2232.c +++ b/urjtag/src/tap/cable/ft2232.c @@ -274,7 +274,7 @@ ft2232_generic_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* safe default values */ @@ -288,9 +288,8 @@ ft2232_generic_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte */ params->high_byte_value = 0; @@ -317,7 +316,7 @@ ft2232_jtagkey_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction: @@ -332,9 +331,8 @@ ft2232_jtagkey_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte default: @@ -372,7 +370,7 @@ ft2232_armusbocd_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction: @@ -387,9 +385,8 @@ ft2232_armusbocd_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte default: @@ -427,7 +424,7 @@ ft2232_gnice_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* safe default values */ @@ -441,9 +438,8 @@ ft2232_gnice_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte */ params->high_byte_value = BITMASK_GNICE_nTRST; @@ -473,7 +469,7 @@ ft2232_oocdlinks_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction */ @@ -487,9 +483,8 @@ ft2232_oocdlinks_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte default: @@ -527,7 +522,7 @@ ft2232_turtelizer2_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction: @@ -544,9 +539,8 @@ ft2232_turtelizer2_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte default: @@ -577,7 +571,7 @@ ft2232_usbtojtagif_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction: @@ -595,9 +589,8 @@ ft2232_usbtojtagif_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte default: @@ -631,7 +624,7 @@ ft2232_signalyzer_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction: @@ -648,9 +641,8 @@ ft2232_signalyzer_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte */ params->high_byte_value = 0; @@ -677,7 +669,7 @@ ft2232_flyswatter_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* static low byte value and direction: @@ -694,9 +686,8 @@ ft2232_flyswatter_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte */ /* Turn LED2 on */ @@ -724,7 +715,7 @@ ft2232_usbscarab2_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* Check if cable is connected to the target and the target is powered on */ @@ -751,9 +742,8 @@ ft2232_usbscarab2_init (urj_cable_t *cable) urj_tap_cable_cx_cmd_push (cmd_root, params->low_byte_value | BITMASK_TMS); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | BITMASK_TDI | - BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); /* Set Data Bits High Byte */ /* nLED=0 */ @@ -1310,9 +1300,8 @@ ft2232_set_signal_schedule (params_t *params, int mask, int val, (params-> low_byte_value | low_or) ^ low_xor); urj_tap_cable_cx_cmd_push (cmd_root, - params-> - low_byte_dir | BITMASK_TCK | - BITMASK_TDI | BITMASK_TMS); + params->low_byte_dir | BITMASK_TCK + | BITMASK_TDI | BITMASK_TMS); } if (set_high) diff --git a/urjtag/src/tap/cable/jim.c b/urjtag/src/tap/cable/jim.c index d8e3b21a..fe6ae4b7 100644 --- a/urjtag/src/tap/cable/jim.c +++ b/urjtag/src/tap/cable/jim.c @@ -50,9 +50,9 @@ jim_cable_connect (urj_cable_t *cable, const urj_param_t *params[]) jim_cable_params_t *cable_params; urj_jim_state_t *s; - if (urj_param_num (params) < 1) + if (urj_param_num (params) > 0) { - urj_error_set (URJ_ERROR_SYNTAX, _("not enough arguments")); + urj_error_set (URJ_ERROR_SYNTAX, _("too many arguments")); return URJ_STATUS_FAIL; } diff --git a/urjtag/src/tap/cable/jlink.c b/urjtag/src/tap/cable/jlink.c index 38a188e9..fe4460b1 100644 --- a/urjtag/src/tap/cable/jlink.c +++ b/urjtag/src/tap/cable/jlink.c @@ -177,6 +177,7 @@ jlink_get_status (urj_usbconn_libusb_param_t *params) if (result == 8) { int vref = data->usb_in_buffer[0] + (data->usb_in_buffer[1] << 8); + // @@@@ RFHH how can we handle this gracefully in liburjtag? urj_log (URJ_LOG_LEVEL_NORMAL, "Vref = %d.%d TCK=%d TDI=%d TDO=%d TMS=%d TRES=%d TRST=%d\n", vref / 1000, vref % 1000, @@ -187,15 +188,17 @@ jlink_get_status (urj_usbconn_libusb_param_t *params) data->usb_in_buffer[6], data->usb_in_buffer[7]); if (vref < 1500) { - urj_log (URJ_LOG_LEVEL_ERROR, - "Vref too low. Possibly the target isn't powered or disconnected?\n"); - result = -15; + urj_error_set (URJ_ERROR_USB, + "Vref too low. Possibly the target isn't powered or disconnected?"); + result = -1; } } else { - urj_log (URJ_LOG_LEVEL_ERROR, - "J-Link command 0x07 (get status) failed (%d)\n", result); + urj_error_set (URJ_ERROR_USB, + "J-Link command 0x07 (get status) failed (%d)\n", + result); + result = -1; } return result; @@ -425,7 +428,7 @@ jlink_init (urj_cable_t *cable) } data = params->data; - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; jlink_tap_init (data); @@ -443,6 +446,7 @@ jlink_init (urj_cable_t *cable) result = jlink_get_status (params); if (result < 0) { + // retain error state urj_log (URJ_LOG_LEVEL_ERROR, "Resetting J-Link. Please retry the cable command.\n"); usb_reset (params->handle); diff --git a/urjtag/src/tap/cable/keithkoep.c b/urjtag/src/tap/cable/keithkoep.c index 738745d9..4e36d343 100644 --- a/urjtag/src/tap/cable/keithkoep.c +++ b/urjtag/src/tap/cable/keithkoep.c @@ -66,7 +66,7 @@ static int keithkoep_init (urj_cable_t *cable) { - if (urj_tap_parport_open (cable->link.port)) + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) return URJ_STATUS_FAIL; urj_tap_parport_set_control (cable->link.port, 1 << TRST); @@ -102,13 +102,19 @@ keithkoep_clock (urj_cable_t *cable, int tms, int tdi, int n) static int keithkoep_get_tdo (urj_cable_t *cable) { + int status; + urj_tap_parport_set_data (cable->link.port, 0 << TCK); PARAM_SIGNALS (cable) &= ~(URJ_POD_CS_TDI | URJ_POD_CS_TCK | URJ_POD_CS_TMS); urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int @@ -133,9 +139,8 @@ keithkoep_set_signal (urj_cable_t *cable, int mask, int val) if ((mask & URJ_POD_CS_TRST) != 0) { urj_tap_parport_set_control (cable->link.port, - (sigs & URJ_POD_CS_TRST) ? (1 << - TRST) : - 0); + (sigs & URJ_POD_CS_TRST) + ? (1 << TRST) : 0); } PARAM_SIGNALS (cable) = sigs; } diff --git a/urjtag/src/tap/cable/lattice.c b/urjtag/src/tap/cable/lattice.c index 97a0e85a..56ebc124 100644 --- a/urjtag/src/tap/cable/lattice.c +++ b/urjtag/src/tap/cable/lattice.c @@ -56,13 +56,13 @@ lattice_init (urj_cable_t *cable) { int data; - if (urj_tap_parport_open (cable->link.port)) + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if ((data = urj_tap_parport_get_data (cable->link.port)) < 0) { - if (urj_tap_parport_set_data (cable->link.port, 1 << TRST) - != URJ_STATUS_OK) + if (urj_tap_parport_set_data (cable->link.port, + 1 << TRST) != URJ_STATUS_OK) return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST; } @@ -103,6 +103,7 @@ static int lattice_get_tdo (urj_cable_t *cable) { int trst = (PARAM_SIGNALS (cable) & URJ_POD_CS_TRST) ? 1 : 0; + int status; urj_tap_parport_set_data (cable->link.port, (trst << TRST) | (0 << TCK)); PARAM_SIGNALS (cable) &= @@ -110,7 +111,11 @@ lattice_get_tdo (urj_cable_t *cable) urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/mpcbdm.c b/urjtag/src/tap/cable/mpcbdm.c index 2380e29f..7d4f7b13 100644 --- a/urjtag/src/tap/cable/mpcbdm.c +++ b/urjtag/src/tap/cable/mpcbdm.c @@ -64,7 +64,7 @@ static int mpcbdm_init (urj_cable_t *cable) { - if (urj_tap_parport_open (cable->link.port)) + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) return URJ_STATUS_FAIL; urj_tap_parport_set_control (cable->link.port, 0); @@ -101,12 +101,18 @@ static int mpcbdm_get_tdo (urj_cable_t *cable) { urj_tap_parport_set_data (cable->link.port, 0 << TCK); + int status; + PARAM_SIGNALS (cable) &= ~(URJ_POD_CS_TDI | URJ_POD_CS_TCK | URJ_POD_CS_TMS); urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/triton.c b/urjtag/src/tap/cable/triton.c index 74e017ea..cdda1adf 100644 --- a/urjtag/src/tap/cable/triton.c +++ b/urjtag/src/tap/cable/triton.c @@ -69,7 +69,7 @@ static int triton_init (urj_cable_t *cable) { - if (urj_tap_parport_open (cable->link.port)) + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) return URJ_STATUS_FAIL; PARAM_SIGNALS (cable) = URJ_POD_CS_TRST | URJ_POD_CS_RESET; @@ -111,6 +111,7 @@ triton_get_tdo (urj_cable_t *cable) { int trst = (PARAM_SIGNALS (cable) & URJ_POD_CS_TRST) ? 1 : 0; int sreset = (PARAM_SIGNALS (cable) & URJ_POD_CS_RESET) ? 1 : 0; + int status; urj_tap_parport_set_data (cable->link.port, (trst << TRST) | (sreset << SRESET) | (0 << TCK)); @@ -119,7 +120,11 @@ triton_get_tdo (urj_cable_t *cable) urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/ts7800.c b/urjtag/src/tap/cable/ts7800.c index 1b2204c5..58d8576e 100644 --- a/urjtag/src/tap/cable/ts7800.c +++ b/urjtag/src/tap/cable/ts7800.c @@ -155,7 +155,7 @@ ts7800_connect (urj_cable_t *cable, const urj_param_t *params[]) { ts7800_params_t *cable_params; - if (urj_param_num (params) != 1) + if (urj_param_num (params) > 0) { urj_error_set (URJ_ERROR_SYNTAX, _("This cable type does not accept parameters")); @@ -200,7 +200,7 @@ ts7800_init (urj_cable_t *cable) { ts7800_params_t *p = cable->params; - if (ts7800_gpio_open (cable)) + if (ts7800_gpio_open (cable) != URJ_STATUS_OK) return URJ_STATUS_FAIL; p->signals = URJ_POD_CS_TRST; diff --git a/urjtag/src/tap/cable/usbblaster.c b/urjtag/src/tap/cable/usbblaster.c index e9c6a7f0..35e25fbc 100644 --- a/urjtag/src/tap/cable/usbblaster.c +++ b/urjtag/src/tap/cable/usbblaster.c @@ -114,7 +114,7 @@ usbblaster_init (urj_cable_t *cable) params_t *params = (params_t *) cable->params; urj_tap_cable_cx_cmd_root_t *cmd_root = &(params->cmd_root); - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; urj_tap_cable_cx_cmd_queue (cmd_root, 0); diff --git a/urjtag/src/tap/cable/vision_ep9307.c b/urjtag/src/tap/cable/vision_ep9307.c index cf904abb..22ae9d93 100644 --- a/urjtag/src/tap/cable/vision_ep9307.c +++ b/urjtag/src/tap/cable/vision_ep9307.c @@ -198,7 +198,7 @@ ep9307_connect (urj_cable_t *cable, const urj_param_t *params[]) { ep9307_params_t *cable_params; - if (urj_param_num (params) != 1) + if (urj_param_num (params) != 0) { urj_error_set (URJ_ERROR_SYNTAX, _("This cable type does not accept parameters")); @@ -235,7 +235,7 @@ ep9307_init (urj_cable_t *cable) { ep9307_params_t *p = cable->params; - if (ep9307_gpio_open (cable)) + if (ep9307_gpio_open (cable) != URJ_STATUS_OK) return URJ_STATUS_FAIL; ep9307_gpio_write (cable, 1 << TRST); diff --git a/urjtag/src/tap/cable/wiggler.c b/urjtag/src/tap/cable/wiggler.c index 9b97bce4..297fd77e 100644 --- a/urjtag/src/tap/cable/wiggler.c +++ b/urjtag/src/tap/cable/wiggler.c @@ -272,14 +272,14 @@ wiggler_init (urj_cable_t *cable) { int data; - if (urj_tap_parport_open (cable->link.port)) + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) return -1; if ((data = urj_tap_parport_get_data (cable->link.port)) < 0) { if (urj_tap_parport_set_data (cable->link.port, - (PRM_TRST_ACT (cable) - | PRM_TRST_INACT (cable)) + PRM_TRST_ACT (cable) + | PRM_TRST_INACT (cable) | PRM_UNUSED_BITS (cable)) != URJ_STATUS_OK) return URJ_STATUS_FAIL; @@ -319,7 +319,7 @@ wiggler_clock (urj_cable_t *cable, int tms, int tdi, int n) | PRM_TCK_ACT (cable) | (tms ? PRM_TMS_ACT (cable) : PRM_TMS_INACT (cable)) - | (tdi ? PRM_TDI_ACT (cable) + | (tdi ? PRM_TDI_ACT (cable) : PRM_TDI_INACT (cable)) | PRM_UNUSED_BITS (cable)); urj_tap_cable_wait (cable); @@ -335,14 +335,19 @@ wiggler_clock (urj_cable_t *cable, int tms, int tdi, int n) static int wiggler_get_tdo (urj_cable_t *cable) { + int status; + urj_tap_parport_set_data (cable->link.port, PRM_TRST_LVL (cable) | PRM_TCK_INACT (cable) | PRM_UNUSED_BITS (cable)); urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) & - (PRM_TDO_ACT (cable) | PRM_TDO_INACT (cable))) ^ - PRM_TDO_ACT (cable) ? 0 : 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return -1; + + return (status & (PRM_TDO_ACT (cable) | PRM_TDO_INACT (cable))) + ^ PRM_TDO_ACT (cable) ? 0 : 1; } static int diff --git a/urjtag/src/tap/cable/wiggler2.c b/urjtag/src/tap/cable/wiggler2.c index 2f632614..584ec45a 100644 --- a/urjtag/src/tap/cable/wiggler2.c +++ b/urjtag/src/tap/cable/wiggler2.c @@ -70,7 +70,7 @@ wiggler2_init (urj_cable_t *cable) { int data; - if (urj_tap_parport_open (cable->link.port)) + if (urj_tap_parport_open (cable->link.port) != URJ_STATUS_OK) return URJ_STATUS_FAIL; // TODO: CPU_RESET bit is set to zero here and can't be changed afterwards @@ -121,6 +121,7 @@ static int wiggler2_get_tdo (urj_cable_t *cable) { int trst = (PARAM_SIGNALS (cable) & URJ_POD_CS_TRST) ? 1 : 0; + int status; urj_tap_parport_set_data (cable->link.port, (trst << TRST) | (0 << TCK) | UNUSED_BITS); @@ -129,7 +130,11 @@ wiggler2_get_tdo (urj_cable_t *cable) urj_tap_cable_wait (cable); - return (urj_tap_parport_get_status (cable->link.port) >> TDO) & 1; + status = urj_tap_parport_get_status (cable->link.port); + if (status == -1) + return status; + + return (status >> TDO) & 1; } static int diff --git a/urjtag/src/tap/cable/xpc.c b/urjtag/src/tap/cable/xpc.c index 73d1702a..d52416b7 100644 --- a/urjtag/src/tap/cable/xpc.c +++ b/urjtag/src/tap/cable/xpc.c @@ -305,7 +305,7 @@ xpcu_common_init (urj_cable_t *cable) uint16_t buf; struct usb_dev_handle *xpcu; - if (urj_tap_usbconn_open (cable->link.usb)) + if (urj_tap_usbconn_open (cable->link.usb) != URJ_STATUS_OK) return URJ_STATUS_FAIL; xpcu = ((urj_usbconn_libusb_param_t *) (cable->link.usb->params))->handle; diff --git a/urjtag/src/tap/parport/direct.c b/urjtag/src/tap/parport/direct.c index 65839e1d..5693cefc 100644 --- a/urjtag/src/tap/parport/direct.c +++ b/urjtag/src/tap/parport/direct.c @@ -247,9 +247,7 @@ direct_connect (const char *devname) parport = direct_parport_alloc (port); if (!parport) - { return NULL; - } return parport; } diff --git a/urjtag/src/tap/usbconn/libftdi.c b/urjtag/src/tap/usbconn/libftdi.c index 171b1a44..5331bd76 100644 --- a/urjtag/src/tap/usbconn/libftdi.c +++ b/urjtag/src/tap/usbconn/libftdi.c @@ -295,7 +295,7 @@ usbconn_ftdi_connect (urj_usbconn_cable_t *template, /* do a test open with the specified cable paramters, alternatively we could use libusb to detect the presence of the specified USB device */ - if (usbconn_ftdi_common_open (c, URJ_LOG_LEVEL_DETAIL) != 0) + if (usbconn_ftdi_common_open (c, URJ_LOG_LEVEL_DETAIL) != URJ_STATUS_OK) { usbconn_ftdi_free (c); return NULL; @@ -432,7 +432,7 @@ usbconn_ftdi_open (urj_usbconn_t *conn) struct ftdi_context *fc = p->fc; int r; - if (usbconn_ftdi_common_open (conn, URJ_LOG_LEVEL_NORMAL) < 0) + if (usbconn_ftdi_common_open (conn, URJ_LOG_LEVEL_NORMAL) != URJ_STATUS_OK) return URJ_STATUS_FAIL; r = seq_reset (fc); @@ -482,7 +482,7 @@ usbconn_ftdi_mpsse_open (urj_usbconn_t *conn) struct ftdi_context *fc = p->fc; int r; - if (usbconn_ftdi_common_open (conn, URJ_LOG_LEVEL_NORMAL) < 0) + if (usbconn_ftdi_common_open (conn, URJ_LOG_LEVEL_NORMAL) != URJ_STATUS_OK) return URJ_STATUS_FAIL; /* This sequence might seem weird and containing superfluous stuff.