Transform commands 'bus' and 'detect' into API calls

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1557 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Rutger Hofman 16 years ago
parent 138b69dae3
commit 1b394b8042

@ -1,3 +1,10 @@
2009-05-04 Rutger Hofman <rfhh>
* 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 <rfhh>
Refactor the autoconf stuff a bit so make install actually creates

@ -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 */

@ -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 */

@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <urjtag/error.h>
#include <urjtag/bus.h>
#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;
}

@ -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;
}

@ -27,11 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <urjtag/chain.h>
#include <urjtag/tap.h>
#include <urjtag/part.h>
#include <urjtag/bus.h>
#include <urjtag/jtag.h>
#include <urjtag/cmd.h>
@ -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;

@ -39,7 +39,9 @@
#include <urjtag/cable.h>
#include <urjtag/part.h>
#include <urjtag/chain.h>
#include <urjtag/part.h>
#include <urjtag/bus.h>
#include <urjtag/jtag.h>
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;
}

Loading…
Cancel
Save