From 3fbdc7429fe6e4de4ab0f4f4d909dacf846aec0e Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Tue, 4 Feb 2003 18:16:12 +0000 Subject: [PATCH] 2003-02-04 Marcel Telka * src/jtag.c (main): Added more checks for syntax errors. Added support for printing input data registers - command 'dr'. Added 'set signal' command. * src/help.c (help): Updated help for 'dr' command, added help for 'set signal. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@334 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 8 +++ jtag/NEWS | 3 + jtag/src/help.c | 15 ++++- jtag/src/jtag.c | 142 +++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 146 insertions(+), 22 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 3706245d..7288db5e 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,11 @@ +2003-02-04 Marcel Telka + + * src/jtag.c (main): Added more checks for syntax errors. Added support for + printing input data registers - command 'dr'. Added 'set signal' + command. + * src/help.c (help): Updated help for 'dr' command, added help for 'set + signal. + 2003-02-04 Marcel Telka Version 0.2.2 released. diff --git a/jtag/NEWS b/jtag/NEWS index fa55ec5f..03724ea9 100644 --- a/jtag/NEWS +++ b/jtag/NEWS @@ -1,5 +1,8 @@ $Id$ + * Enhanced 'dr' command functionality. + * Added new 'set signal' command. + jtag-0.2.2 (2003-02-04): * Added new manufacturer: Cypress. (patch 669157, Chris Ellec) diff --git a/jtag/src/help.c b/jtag/src/help.c index ebfcb6b3..80618e79 100644 --- a/jtag/src/help.c +++ b/jtag/src/help.c @@ -141,10 +141,12 @@ help( const char *cmd ) ); else if (strcmp( cmd, "dr" ) == 0) printf( - "Usage: dr PART\n" - "Display data register content.\n" + "Usage: dr PART [DIR]\n" + "Display input or output data register content.\n" "\n" "PART part number (see print command)\n" + "DIR requested data register; possible values: 'in' for\n" + " input and 'out' for output; default is 'out'\n" ); else if (strcmp( cmd, "detectflash" ) == 0) printf( @@ -183,7 +185,14 @@ help( const char *cmd ) ); else if (strcmp( cmd, "set" ) == 0) printf( - "TODO\n" + "Usage: set signal PART SIGNAL DIR [DATA]\n" + "Set signal state in input BSR (Boundary Scan Register).\n" + "\n" + "PART part number (see print command)\n" + "SIGNAL signal name (from JTAG declaration file)\n" + "DIR requested signal direction; possible values: 'in' or 'out'\n" + "DATA desired output signal value ('0' or '1'); used only if DIR\n" + " is 'out'\n" ); else printf( "Invalid command.\n" ); diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index 551c5bba..bd62355d 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -88,8 +88,13 @@ main( void ) if (!t) continue; - if (strcmp( t, "quit" ) == 0) + if (strcmp( t, "quit" ) == 0) { + if (get_token( NULL )) { + printf( "quit: syntax error\n\nType \"help\" for help.\n\n" ); + continue; + } break; + } if (strcmp( t, "help" ) == 0) { t = get_token( NULL ); @@ -113,8 +118,12 @@ main( void ) continue; } - printf( "Setting TCK frequency to %u Hz\n", freq ); + if (get_token( NULL )) { + printf( "frequency: syntax error\n" ); + continue; + } + printf( "Setting TCK frequency to %u Hz\n", freq ); frequency = freq; continue; @@ -210,7 +219,10 @@ main( void ) continue; } - t = get_token( NULL ); + if (get_token( NULL )) { + printf( "detect: syntax error\n" ); + continue; + } parts_free( ps ); ps = detect_parts( JTAG_DATA_DIR ); @@ -262,17 +274,15 @@ main( void ) printf( "flashmem: missing filename\n" ); continue; } + if (get_token( NULL )) { + printf( "syntax error!\n" ); + continue; + } f = fopen( t, "r" ); if (!f) { printf( "Unable to open file `%s'!\n", t ); continue; } - t = get_token( NULL ); - if (t) { - printf( "syntax error!\n" ); - fclose( f ); - continue; - } if (msbin) flashmsbin( ps, f ); else @@ -322,18 +332,16 @@ main( void ) printf( "flashmem: missing filename\n" ); continue; } + if (get_token( NULL )) { + printf( "syntax error!\n" ); + continue; + } + f = fopen( t, "w" ); if (!f) { printf( "Unable to create file `%s'!\n", t ); continue; } - t = get_token( NULL ); - if (t) { - printf( "syntax error!\n" ); - fclose( f ); - continue; - } - readmem( ps, f, addr, len ); fclose( f ); @@ -341,6 +349,11 @@ main( void ) } if (strcmp( t, "detectflash" ) == 0) { + if (get_token( NULL )) { + printf( "detectflash: syntax error\n" ); + continue; + } + if (!cable) { printf( "Error: Cable not configured. Use 'cable' command first!\n" ); continue; @@ -356,6 +369,11 @@ main( void ) } if (strcmp( t, "print" ) == 0) { + if (get_token( NULL )) { + printf( "print: syntax error\n" ); + continue; + } + if (!cable) { printf( "Error: Cable not configured. Use 'cable' command first!\n" ); continue; @@ -389,7 +407,7 @@ main( void ) printf( "instruction: syntax error\n" ); continue; } - + if ((n < 0) || (n >= ps->len)) { printf( "instruction: invalid part number\n" ); continue; @@ -401,6 +419,11 @@ main( void ) continue; } + if (get_token( NULL )) { + printf( "instruction: syntax error\n" ); + continue; + } + part_set_instruction( ps->parts[n], t ); continue; @@ -430,6 +453,8 @@ main( void ) if (strcmp( t, "dr" ) == 0) { int n; + int dir; + tap_register *r; if (!cable) { printf( "Error: Cable not configured. Use 'cable' command first!\n" ); @@ -458,18 +483,97 @@ main( void ) continue; } - printf( "%s\n", register_get_string( ps->parts[n]->active_instruction->data_register->out ) ); + t = get_token( NULL ); + if (!t) + dir = 1; + else { + if (strcmp( t, "in" ) == 0) + dir = 0; + else if (strcmp( t, "out" ) == 0) + dir = 1; + else { + printf( "dr: syntax error\n" ); + continue; + } + + if (get_token( NULL )) { + printf( "dr: syntax error\n" ); + continue; + } + } + + if (dir) + r = ps->parts[n]->active_instruction->data_register->out; + else + r = ps->parts[n]->active_instruction->data_register->in; + printf( "%s\n", register_get_string( r ) ); continue; } if (strcmp( t, "set" ) == 0) { + int n; + int data; + int dir; + char *s; + + if (!cable) { + printf( "Error: Cable not configured. Use 'cable' command first!\n" ); + continue; + } + + t = get_token( NULL ); + if (!t || strcmp( t, "signal" ) != 0) { + printf( "set: syntax error\n" ); + continue; + } + t = get_token( NULL ); if (!t) { printf( "set: syntax error\n" ); continue; } - + n = strtol( t, &t, 10 ); + if (t && *t) { + printf( "set: syntax error\n" ); + continue; + } + + if ((n < 0) || (n >= ps->len)) { + printf( "set: invalid part number\n" ); + continue; + } + + s = get_token( NULL ); /* signal name */ + if (!s) { + printf( "set: syntax error\n" ); + continue; + } + + t = get_token( NULL ); /* direction */ + if (!t || (strcmp( t, "in" ) != 0 && strcmp( t, "out" ) != 0)) { + printf( "set: syntax error\n" ); + continue; + } + + dir = (strcmp( t, "in" ) == 0) ? 0 : 1; + if (dir) { + t = get_token( NULL ); + data = strtol( t, &t, 10 ); + if (t && *t) { + printf( "set: syntax error\n" ); + continue; + } + + if ((data < 0) || (data > 1)) { + printf( "set: invalid data value\n" ); + continue; + } + } else + data = 0; + + part_set_signal( ps->parts[n], s, dir, data ); + continue; }