diff --git a/include/jtag/part.h b/include/jtag/part.h index 9062e21d..21b5abaa 100644 --- a/include/jtag/part.h +++ b/include/jtag/part.h @@ -32,9 +32,16 @@ #include #include +#define MAXLEN_MANUFACTURER 20 +#define MAXLEN_PART 20 +#define MAXLEN_STEPPING 8 + typedef struct part part; struct part { + char manufacturer[MAXLEN_MANUFACTURER + 1]; + char part[MAXLEN_PART + 1]; + char stepping[MAXLEN_STEPPING + 1]; signal *signals; int instruction_length; instruction *instructions; @@ -68,5 +75,6 @@ int parts_add_part( parts *ps, part *p ); void parts_set_instruction( parts *ps, const char *iname ); void parts_shift_instructions( parts *ps ); void parts_shift_data_registers( parts *ps ); +void parts_print( parts *ps, int header ); #endif /* JTAG_PART_H */ diff --git a/jtag/src/part/part.c b/jtag/src/part/part.c index be9e4ae2..861c143e 100644 --- a/jtag/src/part/part.c +++ b/jtag/src/part/part.c @@ -37,6 +37,9 @@ part_alloc( void ) if (!p) return NULL; + p->manufacturer[0] = '\0'; + p->part[0] = '\0'; + p->stepping[0] = '\0'; p->signals = NULL; p->instruction_length = 0; p->instructions = NULL; @@ -316,3 +319,37 @@ parts_shift_data_registers( parts *ps ) ps->parts[i]->active_instruction->data_register->out, (i + 1) == ps->len ); } } + +void +parts_print( parts *ps, int header ) +{ + int i; + + char format[100]; + snprintf( format, 100, " %%-%ds %%-%ds %%-%ds %%-%ds %%-%ds \n", MAXLEN_MANUFACTURER, MAXLEN_PART, MAXLEN_STEPPING, + MAXLEN_INSTRUCTION, MAXLEN_DATA_REGISTER ); + + if (header) { + printf( " No." ); + printf( format, "Manufacturer", "Part", "Stepping", "Instruction", "Register" ); + for (i = 0; i < 10 + MAXLEN_MANUFACTURER + MAXLEN_PART + MAXLEN_STEPPING + MAXLEN_INSTRUCTION + MAXLEN_DATA_REGISTER; i++ ) + putchar( '-' ); + putchar( '\n' ); + } + + if (!ps) + return; + + for (i = 0; i < ps->len; i++) { + char *instruction = "(none)"; + char *dr = "(none)"; + part *p = ps->parts[i]; + + if (p->active_instruction) { + instruction = p->active_instruction->name; + dr = p->active_instruction->data_register->name; + } + printf( " %3d", i ); + printf( format, p->manufacturer, p->part, p->stepping, instruction, dr ); + } +}