diff --git a/include/jtag/register.h b/include/jtag/register.h index c41a99c1..96055266 100644 --- a/include/jtag/register.h +++ b/include/jtag/register.h @@ -32,6 +32,7 @@ typedef struct tap_register { } tap_register; tap_register *register_alloc( int len ); +tap_register *register_duplicate( tap_register *tr ); void register_free( tap_register *tr ); tap_register *register_fill( tap_register *tr, int val ); const char *register_get_string( tap_register *tr ); diff --git a/jtag/src/tap/register.c b/jtag/src/tap/register.c index a7bc2d24..1abb84f9 100644 --- a/jtag/src/tap/register.c +++ b/jtag/src/tap/register.c @@ -58,6 +58,15 @@ register_alloc( int len ) return tr; } +tap_register * +register_duplicate( tap_register *tr ) +{ + if (!tr) + return NULL; + + return register_init( register_alloc( tr->len ), register_get_string( tr ) ); +} + void register_free( tap_register *tr ) { @@ -80,12 +89,13 @@ register_fill( tap_register *tr, int val ) const char * register_get_string( tap_register *tr ) { - if (tr) { - int i; + int i; - for (i = 0; i < tr->len; i++) - tr->string[tr->len - 1 - i] = (tr->data[i] & 1) ? '1' : '0'; - } + if (!tr) + return NULL; + + for (i = 0; i < tr->len; i++) + tr->string[tr->len - 1 - i] = (tr->data[i] & 1) ? '1' : '0'; return tr->string; }