diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index cb0150f2..1f5fb457 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,10 @@ +2009-05-04 Rutger Hofman + + * src/cmd/cmd_bus.c, src/bus/buses.c, include/urjtag/bus.h: transform the + bus cmd implementation into an API call + * src/cmd/cmd_detect.c, src/tap/detect.c, include/urjtag/tap.h: transform the + detect cmd implementation into an API call + 2009-05-02 Rutger Hofman Refactor the autoconf stuff a bit so make install actually creates diff --git a/urjtag/include/urjtag/bus.h b/urjtag/include/urjtag/bus.h index f231af03..0a277e44 100644 --- a/urjtag/include/urjtag/bus.h +++ b/urjtag/include/urjtag/bus.h @@ -36,8 +36,6 @@ extern urj_bus_t *urj_bus; void urj_bus_readmem (urj_bus_t *bus, FILE *f, uint32_t addr, uint32_t len); void urj_bus_writemem (urj_bus_t *bus, FILE *f, uint32_t addr, uint32_t len); -/* @@@@ this had better be in an internal include file RFHH */ - typedef struct { int len; @@ -51,4 +49,10 @@ void urj_bus_buses_free (void); void urj_bus_buses_add (urj_bus_t *abus); void urj_bus_buses_delete (urj_bus_t *abus); +/** set active bus + * @param n choose n'th bus in #urj_buses as the active bus + * @return URJ_STATUS_OK on success; URJ_STATUS_FAIL on error + */ +int urj_bus_buses_set (int n); + #endif /* URJ_BUS_H */ diff --git a/urjtag/include/urjtag/tap.h b/urjtag/include/urjtag/tap.h index 1afc4ecb..35400a34 100644 --- a/urjtag/include/urjtag/tap.h +++ b/urjtag/include/urjtag/tap.h @@ -47,5 +47,12 @@ int urj_tap_manual_add (urj_chain_t *chain, int instr_len); int urj_tap_detect_register_size (urj_chain_t *chain); void urj_tap_discovery (urj_chain_t *chain); void urj_tap_idcode (urj_chain_t *chain, unsigned int bytes); +/** + * Convenience function that detects the parts, initialises them to BYPASS, + * and initialises the bus drivers. + * + * @return URJ_STATUS_OK on success; URJ_STATUS_FAILURE on error + */ +int urj_tap_detect (urj_chain_t *chain); #endif /* URJ_TAP_H */ diff --git a/urjtag/src/bus/buses.c b/urjtag/src/bus/buses.c index f0c2818b..708e190e 100644 --- a/urjtag/src/bus/buses.c +++ b/urjtag/src/bus/buses.c @@ -27,6 +27,7 @@ #include #include +#include #include #include "buses.h" @@ -206,3 +207,17 @@ urj_bus_buses_delete (urj_bus_t *abus) if (urj_buses.len > 0) urj_bus = urj_buses.buses[0]; } + +int +urj_bus_buses_set (int n) +{ + if (n >= urj_buses.len) + { + urj_error_set(URJ_ERROR_INVALID, _("invalid bus number")); + return URJ_STATUS_FAIL; + } + + urj_bus = urj_buses.buses[n]; + + return URJ_STATUS_OK; +} diff --git a/urjtag/src/cmd/cmd_bus.c b/urjtag/src/cmd/cmd_bus.c index b41bfade..3cd0454a 100644 --- a/urjtag/src/cmd/cmd_bus.c +++ b/urjtag/src/cmd/cmd_bus.c @@ -54,13 +54,7 @@ cmd_bus_run (urj_chain_t *chain, char *params[]) if (urj_cmd_get_number (params[1], &n)) return -1; - if (n >= urj_buses.len) - { - printf (_("%s: invalid bus number\n"), "bus"); - return 1; - } - - urj_bus = urj_buses.buses[n]; + (void)urj_bus_buses_set(n); return 1; } diff --git a/urjtag/src/cmd/cmd_detect.c b/urjtag/src/cmd/cmd_detect.c index 06f6c088..5e8e4689 100644 --- a/urjtag/src/cmd/cmd_detect.c +++ b/urjtag/src/cmd/cmd_detect.c @@ -27,11 +27,7 @@ #include #include -#include #include -#include -#include -#include #include @@ -40,42 +36,15 @@ static int cmd_detect_run (urj_chain_t *chain, char *params[]) { - int i; - urj_bus_t *abus; - if (urj_cmd_params (params) != 1) return -1; if (!urj_cmd_test_cable (chain)) return 1; - urj_bus_buses_free (); - urj_part_parts_free (chain->parts); - chain->parts = NULL; - urj_tap_detect_parts (chain, urj_get_data_dir ()); - if (!chain->parts) - return 1; - if (!chain->parts->len) + if (urj_tap_detect (chain) != URJ_STATUS_OK) { - urj_part_parts_free (chain->parts); - chain->parts = NULL; - return 1; - } - urj_part_parts_set_instruction (chain->parts, "SAMPLE/PRELOAD"); - urj_tap_chain_shift_instructions (chain); - urj_tap_chain_shift_data_registers (chain, 1); - urj_part_parts_set_instruction (chain->parts, "BYPASS"); - urj_tap_chain_shift_instructions (chain); - - // Initialize all the buses - for (i = 0; i < urj_buses.len; i++) - { - abus = urj_buses.buses[i]; - if (abus->driver->init) - { - if (abus->driver->init (abus) != URJ_STATUS_OK) - return -1; - } + return -1; } return 1; diff --git a/urjtag/src/tap/detect.c b/urjtag/src/tap/detect.c index 0dbed307..59990ca1 100644 --- a/urjtag/src/tap/detect.c +++ b/urjtag/src/tap/detect.c @@ -39,7 +39,9 @@ #include #include #include - +#include +#include +#include struct id_record { @@ -500,3 +502,46 @@ urj_tap_manual_add (urj_chain_t *chain, int instr_len) return chain->parts->len; } + +int +urj_tap_detect (urj_chain_t *chain) +{ + int i; + urj_bus_t *abus; + + urj_bus_buses_free (); + urj_part_parts_free (chain->parts); + chain->parts = NULL; + urj_tap_detect_parts (chain, urj_get_data_dir ()); + if (!chain->parts) + { + urj_error_set (URJ_ERROR_INVALID, "chain has no parts"); + return URJ_STATUS_FAIL; + } + if (!chain->parts->len) + { + urj_part_parts_free (chain->parts); + chain->parts = NULL; + urj_error_set (URJ_ERROR_INVALID, "chain has empty parts list"); + return URJ_STATUS_FAIL; + } + urj_part_parts_set_instruction (chain->parts, "SAMPLE/PRELOAD"); + urj_tap_chain_shift_instructions (chain); + urj_tap_chain_shift_data_registers (chain, 1); + urj_part_parts_set_instruction (chain->parts, "BYPASS"); + urj_tap_chain_shift_instructions (chain); + + // Initialize all the buses + for (i = 0; i < urj_buses.len; i++) + { + abus = urj_buses.buses[i]; + if (abus->driver->init) + { + if (abus->driver->init (abus) != URJ_STATUS_OK) + // retain error state + return URJ_STATUS_FAIL; + } + } + + return URJ_STATUS_OK; +}