From 05c742ca7ab2ea981fa966e7c078750abf6ad19a Mon Sep 17 00:00:00 2001 From: Rutger Hofman Date: Mon, 4 May 2009 21:13:18 +0000 Subject: [PATCH] Fix bug I introduced in bsbit_alloc; fix error returns from API routines in cmd git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1559 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/include/urjtag/bsbit.h | 8 ++++---- urjtag/include/urjtag/error.h | 6 +++--- urjtag/src/cmd/cmd_bit.c | 33 +++++++++++++++++++++++--------- urjtag/src/cmd/cmd_bus.c | 7 ++++++- urjtag/src/cmd/cmd_detect.c | 3 +++ urjtag/src/cmd/cmd_instruction.c | 10 +++++++++- urjtag/src/cmd/cmd_signal.c | 10 +++++++++- urjtag/src/global/urjtag.c | 30 +++++++++++++++++++++++++++++ urjtag/src/part/bsbit.c | 26 ++++++------------------- urjtag/src/part/part.c | 8 ++++---- urjtag/src/tap/parport.c | 2 ++ urjtag/src/tap/usbconn.c | 1 + 12 files changed, 101 insertions(+), 43 deletions(-) diff --git a/urjtag/include/urjtag/bsbit.h b/urjtag/include/urjtag/bsbit.h index e5565c71..1182bd78 100644 --- a/urjtag/include/urjtag/bsbit.h +++ b/urjtag/include/urjtag/bsbit.h @@ -50,19 +50,19 @@ struct urj_bsbit /** * Define new BSR (Boundary Scan Register) bit for signal name. * - * @param chain + * @param part * @param bit * @param name associated signal name * @param type URJ_BSBIT_{INPUT|OUTPUT|BIDIR|CONTROL|INTERNAL} * @param safe default (safe) value (0|1) */ -urj_bsbit_t *urj_part_bsbit_alloc (urj_chain_t *chain, int bit, +urj_bsbit_t *urj_part_bsbit_alloc (urj_part_t *part, int bit, const char *name, int type, int safe); /** * Define new BSR (Boundary Scan Register) bit for signal name. * Additionally, define control bit. * - * @param chain + * @param part * @param bit * @param name associated signal name * @param type URJ_BSBIT_{INPUT|OUTPUT|BIDIR|CONTROL|INTERNAL} @@ -71,7 +71,7 @@ urj_bsbit_t *urj_part_bsbit_alloc (urj_chain_t *chain, int bit, * @param ctrl_val control value * @param ctrl_state control state; valid statis is only URJ_BSBIT_STATE_Z */ -urj_bsbit_t *urj_part_bsbit_alloc_control (urj_chain_t *chain, int bit, +urj_bsbit_t *urj_part_bsbit_alloc_control (urj_part_t *part, int bit, const char *name, int type, int safe, int ctrl_num, int ctrl_val, int ctrl_state); diff --git a/urjtag/include/urjtag/error.h b/urjtag/include/urjtag/error.h index 4c8c7502..265b3a28 100644 --- a/urjtag/include/urjtag/error.h +++ b/urjtag/include/urjtag/error.h @@ -76,12 +76,12 @@ extern urj_error_state_t urj_error_state; /** * The top of the error stack. The caller must not modify the returned struct. */ -const urj_error_state_t *urj_error_get(void); +const urj_error_state_t *urj_error_get (void); /** * Pop the top off the error stack. * @return #URJ_ERROR_OK if the bottom of the error stack is reached */ -urj_error_t urj_error_get_reset(void); +urj_error_t urj_error_get_reset (void); /** * The top of the error state in human-readable form. * @@ -89,6 +89,6 @@ urj_error_t urj_error_get_reset(void); * * @return a pointer to a static area. */ -const char *urj_error_describe(void); +const char *urj_error_describe (void); #endif /* URJ_ERROR_H */ diff --git a/urjtag/src/cmd/cmd_bit.c b/urjtag/src/cmd/cmd_bit.c index ad6b4632..94a774fe 100644 --- a/urjtag/src/cmd/cmd_bit.c +++ b/urjtag/src/cmd/cmd_bit.c @@ -28,7 +28,10 @@ #include #include +#include #include +#include +#include #include @@ -52,12 +55,12 @@ cmd_bit_print_params (char *params[], unsigned int parameters, char *command, static int cmd_bit_run (urj_chain_t *chain, char *params[]) { + urj_part_t *part; unsigned int bit; int type; int safe; unsigned int control; unsigned int parameters = urj_cmd_params (params); - urj_bsbit_t *bsbit; char command[1024]; cmd_bit_print_params (params, parameters, command, sizeof command); @@ -76,6 +79,12 @@ cmd_bit_run (urj_chain_t *chain, char *params[]) return 1; } + part = urj_tap_chain_active_part (chain); + if (part == NULL) + { + return 1; + } + /* bit number */ if (urj_cmd_get_number (params[1], &bit)) { @@ -129,10 +138,13 @@ cmd_bit_run (urj_chain_t *chain, char *params[]) /* test for control bit */ if (urj_cmd_params (params) == 5) { - bsbit = urj_part_bsbit_alloc (chain, bit, params[4], type, safe); - if (bsbit == NULL) + part->bsbits[bit] = urj_part_bsbit_alloc (part, bit, params[4], type, + safe); + if (part->bsbits[bit] == NULL) { - return -1; + printf ("%s for command '%s'\n", urj_error_describe(), command); + urj_error_get_reset(); + return 1; } } else { @@ -161,12 +173,15 @@ cmd_bit_run (urj_chain_t *chain, char *params[]) control_state = URJ_BSBIT_STATE_Z; - bsbit = urj_part_bsbit_alloc_control (chain, bit, params[4], type, safe, - control, control_value, - control_state); - if (bsbit == NULL) + part->bsbits[bit] = urj_part_bsbit_alloc_control (part, bit, params[4], + type, safe, control, + control_value, + control_state); + if (part->bsbits[bit] == NULL) { - return -1; + printf ("%s for command '%s'\n", urj_error_describe(), command); + urj_error_get_reset(); + return 1; } } diff --git a/urjtag/src/cmd/cmd_bus.c b/urjtag/src/cmd/cmd_bus.c index 3cd0454a..2fb7aa9f 100644 --- a/urjtag/src/cmd/cmd_bus.c +++ b/urjtag/src/cmd/cmd_bus.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -54,7 +55,11 @@ cmd_bus_run (urj_chain_t *chain, char *params[]) if (urj_cmd_get_number (params[1], &n)) return -1; - (void)urj_bus_buses_set(n); + if (urj_bus_buses_set (n) != URJ_STATUS_OK) + { + printf ("%s\n", urj_error_describe()); + urj_error_get_reset(); + } return 1; } diff --git a/urjtag/src/cmd/cmd_detect.c b/urjtag/src/cmd/cmd_detect.c index 5e8e4689..c7589ffa 100644 --- a/urjtag/src/cmd/cmd_detect.c +++ b/urjtag/src/cmd/cmd_detect.c @@ -28,6 +28,7 @@ #include #include +#include #include @@ -44,6 +45,8 @@ cmd_detect_run (urj_chain_t *chain, char *params[]) if (urj_tap_detect (chain) != URJ_STATUS_OK) { + printf ("%s\n", urj_error_describe()); + urj_error_get_reset(); return -1; } diff --git a/urjtag/src/cmd/cmd_instruction.c b/urjtag/src/cmd/cmd_instruction.c index 3155006d..d15750b1 100644 --- a/urjtag/src/cmd/cmd_instruction.c +++ b/urjtag/src/cmd/cmd_instruction.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -65,7 +66,12 @@ cmd_instruction_run (urj_chain_t *chain, char *params[]) if (urj_cmd_get_number (params[2], &len)) return -1; - return urj_part_instruction_length_set (part, len); + if (urj_part_instruction_length_set (part, len) != URJ_STATUS_OK) + { + printf ("%s\n", urj_error_describe()); + urj_error_get_reset(); + } + return 1; } if (urj_cmd_params (params) == 4) @@ -75,6 +81,8 @@ cmd_instruction_run (urj_chain_t *chain, char *params[]) i = urj_part_instruction_define (part, params[1], params[2], params[3]); if (!i) { + printf ("%s\n", urj_error_describe()); + urj_error_get_reset(); return 1; } diff --git a/urjtag/src/cmd/cmd_signal.c b/urjtag/src/cmd/cmd_signal.c index 9563efbc..dc9a5737 100644 --- a/urjtag/src/cmd/cmd_signal.c +++ b/urjtag/src/cmd/cmd_signal.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -59,7 +60,12 @@ cmd_signal_run (urj_chain_t *chain, char *params[]) { printf ("Defining pin for signal %s\n", s->name); - return urj_part_signal_redefine_pin(chain, s, params[2]); + if (urj_part_signal_redefine_pin(chain, s, params[2]) != URJ_STATUS_OK) + { + printf ("%s\n", urj_error_describe()); + urj_error_get_reset(); + } + return 1; } else { @@ -77,6 +83,8 @@ cmd_signal_run (urj_chain_t *chain, char *params[]) s = urj_part_signal_define(chain, params[1]); } if (s == NULL) { + printf ("%s\n", urj_error_describe()); + urj_error_get_reset(); return 1; } diff --git a/urjtag/src/global/urjtag.c b/urjtag/src/global/urjtag.c index 36143dc8..9b498a1c 100644 --- a/urjtag/src/global/urjtag.c +++ b/urjtag/src/global/urjtag.c @@ -29,3 +29,33 @@ urj_error_state_t urj_error_state; int urj_debug_mode = 0; int urj_big_endian = 0; + +const urj_error_state_t * +urj_error_get (void) +{ + return &urj_error_state; +} + +urj_error_t +urj_error_get_reset (void) +{ + urj_error_t e = urj_error_state.errnum; + + urj_error_state.errnum = URJ_ERROR_OK; + + return e; +} + +const char * +urj_error_describe (void) +{ + static char msg[URJ_ERROR_MSG_LEN + 1024 + 256 + 20]; + + snprintf (msg, sizeof msg, "%s:%d %s(): %s", urj_error_state.file, + urj_error_state.line, urj_error_state.function, + urj_error_state.msg); + + return msg; +} + + diff --git a/urjtag/src/part/bsbit.c b/urjtag/src/part/bsbit.c index 4f2d79c7..147cd2f5 100644 --- a/urjtag/src/part/bsbit.c +++ b/urjtag/src/part/bsbit.c @@ -35,28 +35,14 @@ #include urj_bsbit_t * -urj_part_bsbit_alloc_control (urj_chain_t *chain, int bit, const char *name, +urj_part_bsbit_alloc_control (urj_part_t *part, int bit, const char *name, int type, int safe, int ctrl_num, int ctrl_val, int ctrl_state) { urj_bsbit_t *b; - urj_part_t *part; urj_data_register_t *bsr; urj_part_signal_t *signal; - if (!chain->parts) - { - urj_error_set (URJ_ERROR_NO_ACTIVE_PART, _("Run \"detect\" first.\n")); - return NULL; - } - if (chain->active_part >= chain->parts->len) - { - urj_error_set (URJ_ERROR_NO_ACTIVE_PART, - _("%s: no active part\n"), "signal"); - return NULL; - } - - part = chain->parts->parts[chain->active_part]; bsr = urj_part_find_data_register (part, "BSR"); if (bsr == NULL) { @@ -125,21 +111,21 @@ urj_part_bsbit_alloc_control (urj_chain_t *chain, int bit, const char *name, urj_error_set(URJ_ERROR_INVALID, _("invalid control bit number\n")); return NULL; } - part->bsbits[bit]->control = ctrl_num; - part->bsbits[bit]->control_value = ctrl_val; - part->bsbits[bit]->control_state = URJ_BSBIT_STATE_Z; + b->control = ctrl_num; + b->control_value = ctrl_val; + b->control_state = URJ_BSBIT_STATE_Z; } return b; } urj_bsbit_t * -urj_part_bsbit_alloc (urj_chain_t *chain, int bit, const char *name, int type, +urj_part_bsbit_alloc (urj_part_t *part, int bit, const char *name, int type, int safe) { urj_bsbit_t *b; - b = urj_part_bsbit_alloc_control (chain, bit, name, type, safe, -1, -1, -1); + b = urj_part_bsbit_alloc_control (part, bit, name, type, safe, -1, -1, -1); return b; } diff --git a/urjtag/src/part/part.c b/urjtag/src/part/part.c index 65a2f675..c56eba83 100644 --- a/urjtag/src/part/part.c +++ b/urjtag/src/part/part.c @@ -294,7 +294,7 @@ urj_part_instruction_length_set (urj_part_t *part, int length) if (part->instructions != NULL) { urj_error_set (URJ_ERROR_ALREADY, - _("instruction length is already set and used\n")); + _("instruction length is already set and used")); return URJ_STATUS_FAIL; } @@ -314,14 +314,14 @@ urj_part_instruction_define (urj_part_t *part, const char *instruction, if (strlen (code) != part->instruction_length) { urj_error_set (URJ_ERROR_INVALID, - _("invalid instruction length\n")); + _("invalid instruction length")); return NULL; } if (urj_part_find_instruction (part, instruction) != NULL) { urj_error_set (URJ_ERROR_ALREADY, - _("Instruction '%s' already defined\n"), instruction); + _("Instruction '%s' already defined"), instruction); return NULL; } @@ -329,7 +329,7 @@ urj_part_instruction_define (urj_part_t *part, const char *instruction, if (dr == NULL) { urj_error_set(URJ_ERROR_NOTFOUND, - _("unknown data register '%s'\n"), data_register); + _("unknown data register '%s'"), data_register); return NULL; } diff --git a/urjtag/src/tap/parport.c b/urjtag/src/tap/parport.c index 3f2a6975..a1667d5e 100644 --- a/urjtag/src/tap/parport.c +++ b/urjtag/src/tap/parport.c @@ -24,6 +24,8 @@ #include +#include + #include extern urj_parport_driver_t urj_tap_parport_direct_parport_driver; diff --git a/urjtag/src/tap/usbconn.c b/urjtag/src/tap/usbconn.c index 367e5fae..e29af5f2 100644 --- a/urjtag/src/tap/usbconn.c +++ b/urjtag/src/tap/usbconn.c @@ -25,6 +25,7 @@ #include #include +#include #include