Added part library (libpart).

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@74 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Marcel Telka 23 years ago
parent bb18e29227
commit 248ed10446

@ -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 <marcel@telka.sk>, 2002.
*
*/
#ifndef JTAG_BSBIT_H
#define JTAG_BSBIT_H
#include <jtag/signal.h>
#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 */

@ -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 <marcel@telka.sk>, 2002.
*
*/
#ifndef JTAG_INSTRUCTION_H
#define JTAG_INSTRUCTION_H
#include <jtag/register.h>
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 */

@ -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 <marcel@telka.sk>, 2002.
*
*/
#ifndef JTAG_PART_H
#define JTAG_PART_H
#include <stdio.h>
#include <jtag/signal.h>
#include <jtag/instruction.h>
#include <jtag/bsbit.h>
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 */

@ -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 <marcel@telka.sk>, 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 */

@ -35,6 +35,7 @@ AC_CONFIG_FILES(
Makefile
src/Makefile
src/tap/Makefile
src/part/Makefile
)
AM_MAINTAINER_MODE

@ -21,12 +21,16 @@
# Written by Marcel Telka <marcel@telka.sk>, 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

@ -29,13 +29,14 @@
#include <jtag/register.h>
#include <jtag/tap.h>
#include <jtag/ctrl.h>
#include <jtag/part.h>
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();

@ -0,0 +1,3 @@
Makefile
Makefile.in
.deps

@ -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 <marcel@telka.sk>, 2002.
#
noinst_LIBRARIES = libpart.a
libpart_a_SOURCES = \
signal.c \
instruction.c \
bsbit.c \
part.c \
parse.c
INCLUDES = -I$(top_srcdir)/include

@ -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 <marcel@telka.sk>, 2002.
*
*/
#include <stdlib.h>
#include <string.h>
#include <jtag/bsbit.h>
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 );
}

@ -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 <marcel@telka.sk>, 2002.
*
*/
#include <stdlib.h>
#include <string.h>
#include <jtag/instruction.h>
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 );
}

@ -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 <marcel@telka.sk>, 2002.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <jtag/part.h>
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;
}

@ -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 <marcel@telka.sk>, 2002.
*
*/
#include <stdlib.h>
#include <jtag/part.h>
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;
}

@ -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 <marcel@telka.sk>, 2002.
*
*/
#include <stdlib.h>
#include <string.h>
#include <jtag/signal.h>
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 );
}
Loading…
Cancel
Save