Added signal handling.

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@79 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Marcel Telka 23 years ago
parent 525aa3f1c8
commit b936122067

@ -25,6 +25,8 @@
#ifndef JTAG_BSBIT_H
#define JTAG_BSBIT_H
typedef struct bsbit bsbit;
#include <jtag/signal.h>
#define BSBIT_INPUT 1
@ -34,8 +36,6 @@
#define BSBIT_STATE_Z (-1)
typedef struct bsbit bsbit;
struct bsbit {
int bit;
char *name;

@ -37,13 +37,19 @@ struct part {
signal *signals;
int instruction_length;
instruction *instructions;
instruction *active_instruction;
int boundary_length;
bsbit **bsbits;
tap_register *bsr;
tap_register *prev_bsr;
};
part *part_alloc( void );
void part_free( part *p );
part *read_part( FILE *f );
instruction *part_find_instruction( part *p, const char *iname );
void part_set_signal( part *p, const char *pname, int out, int val );
int part_get_signal( part *p, const char *pname );
typedef struct parts parts;
@ -55,5 +61,6 @@ struct parts {
parts *parts_alloc( void );
void parts_free( parts *ps );
int parts_add_part( parts *ps, part *p );
void parts_set_instruction( parts *ps, const char *iname );
#endif /* JTAG_PART_H */

@ -27,9 +27,13 @@
typedef struct signal signal;
#include <jtag/bsbit.h>
struct signal {
char *name;
signal *next;
bsbit *input;
bsbit *output;
};
signal *signal_alloc( const char *name );

@ -51,6 +51,13 @@ bsbit_alloc( int bit, const char *name, int type, signal* signals, int safe )
while (s) {
if (strcmp( s->name, name ) == 0) {
b->signal = s;
switch (type) {
case BSBIT_INPUT:
s->input = b;
break;
case BSBIT_OUTPUT:
s->output = b;
}
break;
}
s = s->next;

@ -159,6 +159,20 @@ read_part( FILE *f )
for (i = 0; i < part->boundary_length; i++)
part->bsbits[i] = NULL;
part->bsr = register_alloc( part->boundary_length );
part->prev_bsr = register_alloc( part->boundary_length );
if (!part->bsr || !part->prev_bsr) {
printf( "(%d) out of memory\n", line );
continue;
}
t = get_token( NULL );
if (t) {
printf( "(%d) parse error\n", line );
continue;
}
continue;
}
@ -182,7 +196,7 @@ read_part( FILE *f )
/* get bit type */
t = get_token( NULL );
if (!t || (sizeof( *t ) != 1)) {
if (!t || (strlen( t ) != 1)) {
printf( "(%d) parse error\n", line );
continue;
}
@ -206,11 +220,12 @@ read_part( FILE *f )
/* get safe value */
t = get_token( NULL );
if (!t || (sizeof( *t ) != 1)) {
if (!t || (strlen( t ) != 1)) {
printf( "(%d) parse error\n", line );
continue;
}
safe = (*t == '1') ? 1 : 0;
part->bsr->data[bit] = safe;
/* get bit name */
t = get_token( NULL );
@ -226,6 +241,46 @@ read_part( FILE *f )
continue;
}
/* we have control bit? */
t = get_token( NULL );
if (t) {
int control;
control = strtol( t, &t, 10 );
if ((t && *t) || (control < 0)) {
printf( "(%d) invalid control bit number\n", line );
continue;
}
part->bsbits[bit]->control = control;
/* control value */
t = get_token( NULL );
if (!t || (strlen( t ) != 1)) {
printf( "(%d) parse error\n", line );
continue;
}
part->bsbits[bit]->control_value = (*t == '1') ? 1 : 0;
/* control state */
t = get_token( NULL );
if (!t || (strlen( t ) != 1)) {
printf( "(%d) parse error\n", line );
continue;
}
if (*t != 'Z') {
printf( "(%d) parse error\n", line );
continue;
}
part->bsbits[bit]->control_state = BSBIT_STATE_Z;
t = get_token( NULL );
if (t) {
printf( "(%d) parse error\n", line );
continue;
}
}
continue;
}

@ -25,6 +25,9 @@
#include <stdlib.h>
#include <jtag/part.h>
#include <jtag/tap.h>
/* part */
part *
part_alloc( void )
@ -36,8 +39,11 @@ part_alloc( void )
p->signals = NULL;
p->instruction_length = 0;
p->instructions = NULL;
p->active_instruction = NULL;
p->boundary_length = 0;
p->bsbits = NULL;
p->bsr = NULL;
p->prev_bsr = NULL;
return p;
}
@ -69,9 +75,95 @@ part_free( part *p )
bsbit_free( p->bsbits[i] );
free( p->bsbits );
/* bsr */
register_free( p->bsr );
register_free( p->prev_bsr );
free( p );
}
instruction *
part_find_instruction( part *p, const char *iname )
{
instruction *i;
if (!p || !iname)
return NULL;
i = p->instructions;
while (i) {
if (strcmp( iname, i->name ) == 0)
break;
i = i->next;
}
return i;
}
void
part_set_signal( part *p, const char *pname, int out, int val )
{
/* search signal */
signal *s = p->signals;
while (s) {
if (strcmp( pname, s->name ) == 0)
break;
s = s->next;
}
if (!s) {
printf( "signal %s not found\n", pname );
return;
}
/*setup signal */
if (out) {
int control;
if (!s->output) {
printf( "signal %s cannot be set as output\n", pname );
return;
}
p->bsr->data[s->output->bit] = val & 1;
control = p->bsbits[s->output->bit]->control;
if (control >= 0)
p->bsr->data[control] = p->bsbits[s->output->bit]->control_value ^ 1;
} else {
if (!s->input) {
printf( "signal %s cannot be set as input\n", pname );
return;
}
if (s->output)
p->bsr->data[s->output->control] = p->bsbits[s->output->control]->control_value;
}
}
int
part_get_signal( part *p, const char *pname )
{
/* search signal */
signal *s = p->signals;
while (s) {
if (strcmp( pname, s->name ) == 0)
break;
s = s->next;
}
if (!s) {
printf( "signal %s not found\n", pname );
return;
}
if (!s->input) {
printf( "signal %s is not input signal\n", pname );
return;
}
return p->prev_bsr->data[s->input->bit];
}
/* parts */
parts *
parts_alloc( void )
{
@ -113,3 +205,21 @@ parts_add_part( parts *ps, part *p )
return 1;
}
void
parts_set_instruction( parts *ps, const char *iname )
{
int j;
tap_capture_ir();
for (j = 0; j < ps->len; j++) {
instruction *i = part_find_instruction( ps->parts[j], iname );
if (!i) {
printf( "Instruction '%s' not found\n", iname );
return;
}
ps->parts[j]->active_instruction = i;
tap_shift_register( i->value, NULL, (j + 1) == ps->len );
}
}

@ -40,6 +40,8 @@ signal_alloc( const char *name )
return NULL;
}
s->next = NULL;
s->input = NULL;
s->output = NULL;
return s;
}

Loading…
Cancel
Save