From 248ed104461447cb969056522cfcc6b1c892bf67 Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Tue, 23 Jul 2002 18:25:28 +0000 Subject: [PATCH] Added part library (libpart). git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@74 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- include/jtag/bsbit.h | 53 ++++++++ include/jtag/instruction.h | 41 +++++++ include/jtag/part.h | 59 +++++++++ include/jtag/signal.h | 38 ++++++ jtag/configure.ac | 1 + jtag/src/Makefile.am | 8 +- jtag/src/detect.c | 48 ++++++-- jtag/src/part/.cvsignore | 3 + jtag/src/part/Makefile.am | 33 +++++ jtag/src/part/bsbit.c | 70 +++++++++++ jtag/src/part/instruction.c | 70 +++++++++++ jtag/src/part/parse.c | 236 ++++++++++++++++++++++++++++++++++++ jtag/src/part/part.c | 115 ++++++++++++++++++ jtag/src/part/signal.c | 54 +++++++++ 14 files changed, 818 insertions(+), 11 deletions(-) create mode 100644 include/jtag/bsbit.h create mode 100644 include/jtag/instruction.h create mode 100644 include/jtag/part.h create mode 100644 include/jtag/signal.h create mode 100644 jtag/src/part/.cvsignore create mode 100644 jtag/src/part/Makefile.am create mode 100644 jtag/src/part/bsbit.c create mode 100644 jtag/src/part/instruction.c create mode 100644 jtag/src/part/parse.c create mode 100644 jtag/src/part/part.c create mode 100644 jtag/src/part/signal.c diff --git a/include/jtag/bsbit.h b/include/jtag/bsbit.h new file mode 100644 index 00000000..1e3a99ca --- /dev/null +++ b/include/jtag/bsbit.h @@ -0,0 +1,53 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#ifndef JTAG_BSBIT_H +#define JTAG_BSBIT_H + +#include + +#define BSBIT_INPUT 1 +#define BSBIT_OUTPUT 2 +#define BSBIT_CONTROL 3 +#define BSBIT_INTERNAL 4 + +#define BSBIT_STATE_Z (-1) + +typedef struct bsbit bsbit; + +struct bsbit { + int bit; + char *name; + int type; + signal *signal; + int safe; /* safe value */ + int control; /* -1 for none */ + int control_value; + int control_state; +}; + +bsbit *bsbit_alloc( int bit, const char *name, int type, signal* signals, int safe ); +void bsbit_free( bsbit *b ); + +#endif /* JTAG_BSBIT_H */ diff --git a/include/jtag/instruction.h b/include/jtag/instruction.h new file mode 100644 index 00000000..258f5bb7 --- /dev/null +++ b/include/jtag/instruction.h @@ -0,0 +1,41 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#ifndef JTAG_INSTRUCTION_H +#define JTAG_INSTRUCTION_H + +#include + +typedef struct instruction instruction; + +struct instruction { + char *name; + tap_register *value; + instruction *next; +}; + +instruction *instruction_alloc( const char *name, int len, const char *val ); +void instruction_free( instruction *i ); + +#endif /* JTAG_INSTRUCTION_H */ diff --git a/include/jtag/part.h b/include/jtag/part.h new file mode 100644 index 00000000..7d858a79 --- /dev/null +++ b/include/jtag/part.h @@ -0,0 +1,59 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#ifndef JTAG_PART_H +#define JTAG_PART_H + +#include + +#include +#include +#include + +typedef struct part part; + +struct part { + signal *signals; + int instruction_length; + instruction *instructions; + int boundary_length; + bsbit **bsbits; +}; + +part *part_alloc( void ); +void part_free( part *p ); +part *read_part( FILE *f ); + +typedef struct parts parts; + +struct parts { + int len; + part **parts; +}; + +parts *parts_alloc( void ); +void parts_free( parts *ps ); +int parts_add_part( parts *ps, part *p ); + +#endif /* JTAG_PART_H */ diff --git a/include/jtag/signal.h b/include/jtag/signal.h new file mode 100644 index 00000000..6d8f2d8a --- /dev/null +++ b/include/jtag/signal.h @@ -0,0 +1,38 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#ifndef JTAG_SIGNAL_H +#define JTAG_SIGNAL_H + +typedef struct signal signal; + +struct signal { + char *name; + signal *next; +}; + +signal *signal_alloc( const char *name ); +void signal_free( signal *s ); + +#endif /* JTAG_SIGNAL_H */ diff --git a/jtag/configure.ac b/jtag/configure.ac index c1353aed..e712fc7c 100644 --- a/jtag/configure.ac +++ b/jtag/configure.ac @@ -35,6 +35,7 @@ AC_CONFIG_FILES( Makefile src/Makefile src/tap/Makefile + src/part/Makefile ) AM_MAINTAINER_MODE diff --git a/jtag/src/Makefile.am b/jtag/src/Makefile.am index d7211e3c..d5d9f29d 100644 --- a/jtag/src/Makefile.am +++ b/jtag/src/Makefile.am @@ -21,12 +21,16 @@ # Written by Marcel Telka , 2002. # -SUBDIRS = tap +SUBDIRS = \ + tap \ + part bin_PROGRAMS = detect detect_SOURCES = detect.c -detect_LDADD = -Ltap -ltap -lioperm +detect_DEPENDENCIES = tap/libtap.a part/libpart.a + +detect_LDADD = -Ltap -ltap -Lpart -lpart -lioperm INCLUDES = -I$(top_srcdir)/include diff --git a/jtag/src/detect.c b/jtag/src/detect.c index a2df2418..ea8f99f2 100644 --- a/jtag/src/detect.c +++ b/jtag/src/detect.c @@ -29,13 +29,14 @@ #include #include #include +#include struct id_record { char name[20]; char fullname[100]; }; -int +static int find_record( char *filename, tap_register *key, struct id_record *idr ) { FILE *file; @@ -149,14 +150,22 @@ find_record( char *filename, tap_register *key, struct id_record *idr ) return r; } -void -detect_devices( char *db_path ) +parts * +detect_parts( char *db_path ) { - tap_register *zeros = register_fill( register_alloc( 32 ), 0 ); - tap_register *id = register_alloc( 32 ); - + tap_register *zeros; + tap_register *id; char data_path[1024]; - + + parts *ps = parts_alloc(); + if (!ps) { + printf( __FUNCTION__ ": out of memory\n" ); + return NULL; + } + + zeros = register_fill( register_alloc( 32 ), 0 ); + id = register_alloc( 32 ); + tap_reset(); tap_capture_dr(); @@ -228,22 +237,43 @@ detect_devices( char *db_path ) register_free( key ); printf( " Stepping: %s\n", idr.fullname ); + + /* part definition file */ + p = strrchr( data_path, '/' ); + if (p) + p[1] = '\0'; + else + data_path[0] = '\0'; + strcat( data_path, idr.name ); + + printf( "Reading file: %s ... ", data_path ); + { + FILE *f = fopen( data_path, "r" ); + part *p = read_part( f ); + parts_add_part( ps, p ); + } + printf( "done\n" ); } register_free( zeros ); register_free( id ); - return; + + return ps; } int main( void ) { + parts *ps; + tap_init(); tap_set_trst( 0 ); tap_set_trst( 1 ); - detect_devices( "../data" ); + ps = detect_parts( "../data" ); + + parts_free( ps ); tap_done(); diff --git a/jtag/src/part/.cvsignore b/jtag/src/part/.cvsignore new file mode 100644 index 00000000..051d1bd5 --- /dev/null +++ b/jtag/src/part/.cvsignore @@ -0,0 +1,3 @@ +Makefile +Makefile.in +.deps diff --git a/jtag/src/part/Makefile.am b/jtag/src/part/Makefile.am new file mode 100644 index 00000000..41d076b3 --- /dev/null +++ b/jtag/src/part/Makefile.am @@ -0,0 +1,33 @@ +# +# $Id$ +# +# Copyright (C) 2002 ETC s.r.o. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# Written by Marcel Telka , 2002. +# + +noinst_LIBRARIES = libpart.a + +libpart_a_SOURCES = \ + signal.c \ + instruction.c \ + bsbit.c \ + part.c \ + parse.c + +INCLUDES = -I$(top_srcdir)/include diff --git a/jtag/src/part/bsbit.c b/jtag/src/part/bsbit.c new file mode 100644 index 00000000..37b0d572 --- /dev/null +++ b/jtag/src/part/bsbit.c @@ -0,0 +1,70 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#include +#include + +#include + +bsbit * +bsbit_alloc( int bit, const char *name, int type, signal* signals, int safe ) +{ + signal *s = signals; + + bsbit *b = malloc( sizeof *b ); + if (!b) + return NULL; + + b->name = strdup( name ); + if (!b->name) { + free( b ); + return NULL; + } + + b->bit = bit; + b->type = type; + b->signal = NULL; + b->safe = safe; + b->control = -1; + + while (s) { + if (strcmp( s->name, name ) == 0) { + b->signal = s; + break; + } + s = s->next; + } + + return b; +} + +void +bsbit_free( bsbit *b ) +{ + if (!b) + return; + + free( b->name ); + free( b ); +} diff --git a/jtag/src/part/instruction.c b/jtag/src/part/instruction.c new file mode 100644 index 00000000..3871564b --- /dev/null +++ b/jtag/src/part/instruction.c @@ -0,0 +1,70 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#include +#include + +#include + +instruction * +instruction_alloc( const char *name, int len, const char *val ) +{ + instruction *i; + + if (!name || !val) + return NULL; + + i = malloc( sizeof *i ); + if (!i) + return NULL; + + i->name = strdup( name ); + if (!i->name) { + free( i ); + return NULL; + } + + i->value = register_alloc( len ); + if (!i->value) { + free( i->name ); + free( i ); + return NULL; + } + + register_init( i->value, val ); + i->next = NULL; + + return i; +} + +void +instruction_free( instruction *i ) +{ + if (!i) + return; + + free( i->name ); + register_free( i->value ); + free( i ); +} diff --git a/jtag/src/part/parse.c b/jtag/src/part/parse.c new file mode 100644 index 00000000..95cdc3c8 --- /dev/null +++ b/jtag/src/part/parse.c @@ -0,0 +1,236 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#include +#include +#include + +#include + +static char * +get_token( char *buf ) +{ + char *t = strtok( buf, " \f\n\r\t\v" ); + if (t && (*t == '#')) + return NULL; + return t; +} + +part * +read_part( FILE *f ) +{ + int line = 0; + + part *part = part_alloc(); + if (!part) { + printf( "out of memory\n" ); + return NULL; + } + + for (;;) { + char *t; + char buf[1024]; + + if (fgets( buf, 1024, f ) == NULL) + break; + + line++; + + t = get_token( buf ); + if (!t) + continue; + + /* pin */ + if (strcmp( t, "pin" ) == 0) { + signal *s; + + t = get_token( NULL ); + if (!t) { + printf( "(%d) parse error\n", line ); + continue; + } + + s = signal_alloc( t ); + if (!s) { + printf( "(%d) out of memory\n", line ); + continue; + } + s->next = part->signals; + part->signals = s; + + continue; + } + + /* instruction */ + if (strcmp( t, "instruction" ) == 0) { + t = get_token( NULL ); /* 'length' or instruction name */ + if (!t) { + printf( "(%d) parse error\n", line ); + continue; + } + /* we need 'length' first */ + if ((strcmp( t, "length" ) != 0) && (part->instruction_length == 0)) { + printf( "(%d) instruction length missing\n", line ); + continue; + } + + if (strcmp( t, "length" ) == 0) { + t = get_token( NULL ); + if (!t) { + printf( "(%d) parse error\n", line ); + continue; + } + part->instruction_length = strtol( t, &t, 10 ); + if ((t && *t) || (part->instruction_length < 1)) { + printf( "(%d) invalid instruction length\n", line ); + continue; + } + } else { + char *n = t; /* save instruction name */ + instruction *i; + + t = get_token( NULL ); + if (!t || (strlen( t ) != part->instruction_length)) { + printf( "(%d) parse error\n", line ); + continue; + } + + i = instruction_alloc( n, part->instruction_length, t ); + if (!i) { + printf( "(%d) out of memory\n", line ); + continue; + } + + i->next = part->instructions; + part->instructions = i; + } + + t = get_token( NULL ); + if (t) { + printf( "(%d) parse error\n", line ); + continue; + } + + continue; + } + + /* boundary */ + if (strcmp( t, "boundary" ) == 0) { + int i; + + char *l = get_token( NULL ); /* 1st token */ + t = get_token( NULL ); /* 2nd token */ + if (!t || !l || (strcmp( l, "length" ) != 0)) { + printf( "(%d) parse error\n", line ); + continue; + } + + part->boundary_length = strtol( t, &t, 10 ); + if ((t && *t) || (part->boundary_length < 1)) { + printf( "(%d) invalid boundary length\n", line ); + continue; + } + part->bsbits = malloc( part->boundary_length * sizeof *part->bsbits ); + if (!part->bsbits) { + printf( "(%d) out of memory\n", line ); + continue; + } + for (i = 0; i < part->boundary_length; i++) + part->bsbits[i] = NULL; + + continue; + } + + /* bit */ + if (strcmp( t, "bit" ) == 0) { + int bit; + int type; + int safe; + + /* get bit number */ + t = get_token( NULL ); + bit = strtol( t, &t, 10 ); + if ((t && *t) || (bit < 0)) { + printf( "(%d) invalid boundary bit number\n", line ); + continue; + } + if (part->bsbits[bit]) { + printf( "(%d) duplicate bit declaration\n", line ); + continue; + } + + /* get bit type */ + t = get_token( NULL ); + if (!t || (sizeof( *t ) != 1)) { + printf( "(%d) parse error\n", line ); + continue; + } + switch (*t) { + case 'I': + type = BSBIT_INPUT; + break; + case 'O': + type = BSBIT_OUTPUT; + break; + case 'C': + type = BSBIT_CONTROL; + break; + case 'X': + type = BSBIT_INTERNAL; + break; + default: + printf( "(%d) parse error\n", line ); + continue; + } + + /* get safe value */ + t = get_token( NULL ); + if (!t || (sizeof( *t ) != 1)) { + printf( "(%d) parse error\n", line ); + continue; + } + safe = (*t == '1') ? 1 : 0; + + /* get bit name */ + t = get_token( NULL ); + if (!t) { + printf( "(%d) parse error\n", line ); + continue; + } + + /* allocate bsbit */ + part->bsbits[bit] = bsbit_alloc( bit, t, type, part->signals, safe ); + if (!part->bsbits[bit]) { + printf( "(%d) out of memory\n", line ); + continue; + } + + continue; + } + + printf( "(%d) parse error\n", line ); + } + + return part; +} diff --git a/jtag/src/part/part.c b/jtag/src/part/part.c new file mode 100644 index 00000000..4f67d80b --- /dev/null +++ b/jtag/src/part/part.c @@ -0,0 +1,115 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#include + +#include + +part * +part_alloc( void ) +{ + part *p = malloc( sizeof *p ); + if (!p) + return NULL; + + p->signals = NULL; + p->instruction_length = 0; + p->instructions = NULL; + p->boundary_length = 0; + p->bsbits = NULL; + + return p; +} + +void +part_free( part *p ) +{ + int i; + + if (!p) + return; + + /* sirnals */ + while (p->signals) { + signal *s = p->signals; + p->signals = s->next; + signal_free( s ); + } + + /* instructions */ + while (p->instructions) { + instruction *i = p->instructions; + p->instructions = i->next; + instruction_free( i ); + } + + /* bsbits */ + for (i = 0; i < p->boundary_length; i++) + bsbit_free( p->bsbits[i] ); + free( p->bsbits ); + + free( p ); +} + +parts * +parts_alloc( void ) +{ + parts *ps = malloc( sizeof *ps ); + if (!ps) + return NULL; + + ps->len = 0; + ps->parts = NULL; + + return ps; +} + +void +parts_free( parts *ps ) +{ + int i; + + if (!ps) + return; + + for (i = 0; i < ps->len; i++) + part_free(ps->parts[i]); + + free( ps->parts ); + free( ps ); +} + +int +parts_add_part( parts *ps, part *p ) +{ + part **np = realloc( ps->parts, (ps->len + 1) * sizeof *ps->parts ); + + if (!np) + return 0; + + ps->parts = np; + ps->parts[ps->len++] = p; + + return 1; +} diff --git a/jtag/src/part/signal.c b/jtag/src/part/signal.c new file mode 100644 index 00000000..067d2525 --- /dev/null +++ b/jtag/src/part/signal.c @@ -0,0 +1,54 @@ +/* + * $Id$ + * + * Copyright (C) 2002 ETC s.r.o. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Marcel Telka , 2002. + * + */ + +#include +#include + +#include + +signal * +signal_alloc( const char *name ) +{ + signal *s = malloc( sizeof *s ); + if (!s) + return NULL; + + s->name = strdup( name ); + if (!s->name) { + free( s ); + return NULL; + } + s->next = NULL; + + return s; +} + +void +signal_free( signal *s ) +{ + if (!s) + return; + free( s->name ); + free( s ); +}