From 677540b4f092de214a72dc364f17d4f24b3fad5e Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Thu, 23 Oct 2003 19:29:41 +0000 Subject: [PATCH] 2003-10-23 Marcel Telka * include/bssignal.h (salias_t): Added new type. (salias_alloc, salias_free): Adde new function prototypes. * include/part.h (struct part): Added new structure member 'saliases'. * src/cmd/Makefile.am (libcmd_a_SOURCES): Added salias.c. * src/cmd/cmd.c (cmds): Added cmd_salias. * src/cmd/salias.c: New file. * src/part/part.c (part_alloc): Added saliases initialization. (part_free): Added saliases deallocation. (part_find_signal): Added signal aliases searching. * src/part/signal.c (salias_alloc, salias_free): New functions. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@582 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 13 ++++++ jtag/NEWS | 1 + jtag/include/bssignal.h | 14 +++++- jtag/include/part.h | 1 + jtag/src/cmd/Makefile.am | 1 + jtag/src/cmd/cmd.c | 2 + jtag/src/cmd/salias.c | 99 ++++++++++++++++++++++++++++++++++++++++ jtag/src/part/part.c | 20 +++++++- jtag/src/part/signal.c | 26 +++++++++++ 9 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 jtag/src/cmd/salias.c diff --git a/jtag/ChangeLog b/jtag/ChangeLog index e8ed5026..72d52b7b 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,16 @@ +2003-10-23 Marcel Telka + + * include/bssignal.h (salias_t): Added new type. + (salias_alloc, salias_free): Adde new function prototypes. + * include/part.h (struct part): Added new structure member 'saliases'. + * src/cmd/Makefile.am (libcmd_a_SOURCES): Added salias.c. + * src/cmd/cmd.c (cmds): Added cmd_salias. + * src/cmd/salias.c: New file. + * src/part/part.c (part_alloc): Added saliases initialization. + (part_free): Added saliases deallocation. + (part_find_signal): Added signal aliases searching. + * src/part/signal.c (salias_alloc, salias_free): New functions. + 2003-10-20 Marcel Telka * data/hitachi/hd64465/hd64465: Completed BSR bits declaration. diff --git a/jtag/NEWS b/jtag/NEWS index 316e4083..3d015abb 100644 --- a/jtag/NEWS +++ b/jtag/NEWS @@ -5,6 +5,7 @@ See libbrux/NEWS for more news. * Added new JTAG declarations for - Hitachi HD64465 - Hitachi SH7729 (Beregnyei Balazs) + * Added new command 'salias'. jtag-0.5.1 (2003-10-11): diff --git a/jtag/include/bssignal.h b/jtag/include/bssignal.h index dfaf844b..44c2e33c 100644 --- a/jtag/include/bssignal.h +++ b/jtag/include/bssignal.h @@ -2,6 +2,7 @@ * $Id$ * * Copyright (C) 2002 ETC s.r.o. + * Copyright (C) 2003 Marcel Telka * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * - * Written by Marcel Telka , 2002. + * Written by Marcel Telka , 2002, 2003. * */ @@ -36,7 +37,18 @@ struct signal { bsbit_t *output; }; +typedef struct salias salias_t; + +struct salias { + char *name; + salias_t *next; + signal_t *signal; +}; + signal_t *signal_alloc( const char *name ); void signal_free( signal_t *s ); +salias_t *salias_alloc( const char *name, const signal_t *signal ); +void salias_free( salias_t *salias ); + #endif /* SIGNAL_H */ diff --git a/jtag/include/part.h b/jtag/include/part.h index 2bb06464..123c36dd 100644 --- a/jtag/include/part.h +++ b/jtag/include/part.h @@ -44,6 +44,7 @@ struct part { char part[MAXLEN_PART + 1]; char stepping[MAXLEN_STEPPING + 1]; signal_t *signals; + salias_t *saliases; int instruction_length; instruction *instructions; instruction *active_instruction; diff --git a/jtag/src/cmd/Makefile.am b/jtag/src/cmd/Makefile.am index e2ab6a7b..f1405edd 100644 --- a/jtag/src/cmd/Makefile.am +++ b/jtag/src/cmd/Makefile.am @@ -31,6 +31,7 @@ libcmd_a_SOURCES = \ discovery.c \ detect.c \ signal.c \ + salias.c \ bit.c \ register.c \ initbus.c \ diff --git a/jtag/src/cmd/cmd.c b/jtag/src/cmd/cmd.c index 89ac848b..7f325879 100644 --- a/jtag/src/cmd/cmd.c +++ b/jtag/src/cmd/cmd.c @@ -38,6 +38,7 @@ extern cmd_t cmd_cable; extern cmd_t cmd_discovery; extern cmd_t cmd_detect; extern cmd_t cmd_signal; +extern const cmd_t cmd_salias; extern cmd_t cmd_bit; extern cmd_t cmd_register; extern const cmd_t cmd_initbus; @@ -67,6 +68,7 @@ const cmd_t *cmds[] = { &cmd_discovery, &cmd_detect, &cmd_signal, + &cmd_salias, &cmd_bit, &cmd_register, &cmd_initbus, diff --git a/jtag/src/cmd/salias.c b/jtag/src/cmd/salias.c new file mode 100644 index 00000000..6250c384 --- /dev/null +++ b/jtag/src/cmd/salias.c @@ -0,0 +1,99 @@ +/* + * $Id$ + * + * Copyright (C) 2003 Marcel Telka + * + * 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 , 2003. + * + */ + +#include "sysdep.h" + +#include +#include +#include + +#include "jtag.h" + +#include "cmd.h" + +static int +cmd_salias_run( char *params[] ) +{ + part_t *part; + signal_t *s; + salias_t *sa; + + if (cmd_params( params ) != 3) + return -1; + + if (!cmd_test_cable()) + return 1; + + if (!chain->parts) { + printf( _("Run \"detect\" first.\n") ); + return 1; + } + + if (chain->active_part >= chain->parts->len) { + printf( _("%s: no active part\n"), "signal" ); + return 1; + } + + part = chain->parts->parts[chain->active_part]; + if (part_find_signal( part, params[1] ) != NULL) { + printf( _("Signal '%s' already defined\n"), params[1] ); + return 1; + } + + s = part_find_signal( part, params[2] ); + if (s == NULL) { + printf( _("Signal '%s' not found\n"), params[2] ); + return 1; + } + + sa = salias_alloc( params[1], s ); + if (!sa) { + printf( _("out of memory\n") ); + return 1; + } + + sa->next = part->saliases; + part->saliases = sa; + + return 1; +} + +static void +cmd_salias_help( void ) +{ + printf( _( + "Usage: %s ALIAS SIGNAL\n" + "Define new signal ALIAS as alias for existing SIGNAL.\n" + "\n" + "ALIAS New signal alias name\n" + "SIGNAL Existing signal name\n" + ), "signal" ); +} + +const cmd_t cmd_salias = { + "salias", + N_("define an alias for a signal"), + cmd_salias_help, + cmd_salias_run +}; diff --git a/jtag/src/part/part.c b/jtag/src/part/part.c index 8a6bf1a4..3b598d1e 100644 --- a/jtag/src/part/part.c +++ b/jtag/src/part/part.c @@ -43,6 +43,7 @@ part_alloc( const tap_register *id ) p->part[0] = '\0'; p->stepping[0] = '\0'; p->signals = NULL; + p->saliases = NULL; p->instruction_length = 0; p->instructions = NULL; p->active_instruction = NULL; @@ -71,6 +72,13 @@ part_free( part_t *p ) signal_free( s ); } + /* saliases */ + while (p->saliases) { + salias_t *sa = p->saliases; + p->saliases = sa->next; + salias_free( sa ); + } + /* instructions */ while (p->instructions) { instruction *i = p->instructions; @@ -133,6 +141,7 @@ signal_t * part_find_signal( part_t *p, const char *signalname ) { signal_t *s; + salias_t *sa; if (!p || !signalname) return NULL; @@ -140,11 +149,18 @@ part_find_signal( part_t *p, const char *signalname ) s = p->signals; while (s) { if (strcmp( signalname, s->name ) == 0) - break; + return s; s = s->next; } - return s; + sa = p->saliases; + while (sa) { + if (strcmp( signalname, sa->name ) == 0) + return sa->signal; + sa = sa->next; + } + + return NULL; } void diff --git a/jtag/src/part/signal.c b/jtag/src/part/signal.c index e53baee9..52b98350 100644 --- a/jtag/src/part/signal.c +++ b/jtag/src/part/signal.c @@ -54,3 +54,29 @@ signal_free( signal_t *s ) free( s->name ); free( s ); } + +salias_t * +salias_alloc( const char *name, const signal_t *signal ) +{ + salias_t *sa = malloc( sizeof *sa ); + if (sa == NULL) + return NULL; + + sa->name = strdup( name ); + if (sa->name == NULL) { + free( sa ); + return NULL; + } + sa->next = NULL; + sa->signal = signal; + + return sa; +} + +void salias_free( salias_t *salias ) +{ + if (salias == NULL) + return; + free( salias->name ); + free( salias ); +}