From 0a060ead2d6293cc1e4227918d52258b71f9e716 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 1 May 2007 19:51:47 +0000 Subject: [PATCH] add the possibility to monitor the JTAG state machine --- Makefile | 8 +-- jtagkey.c | 4 ++ jtagmon.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ jtagmon.h | 1 + 4 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 jtagmon.c create mode 100644 jtagmon.h diff --git a/Makefile b/Makefile index 21cb565..cb025f2 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ SOBJECTS=libusb-driver.so libusb-driver-DEBUG.so all: $(SOBJECTS) -libusb-driver.so: usb-driver.c parport.c jtagkey.c config.c usb-driver.h parport.h jtagkey.h config.h Makefile - gcc $(CFLAGS) usb-driver.c parport.c config.c $(JTAGKEYSRC) -o $@ -ldl -lusb -lpthread $(FTDI) -shared +libusb-driver.so: usb-driver.c parport.c jtagkey.c config.c jtagmon.c usb-driver.h parport.h jtagkey.h config.h jtagmon.h Makefile + gcc $(CFLAGS) usb-driver.c parport.c config.c jtagmon.c $(JTAGKEYSRC) -o $@ -ldl -lusb -lpthread $(FTDI) -shared -libusb-driver-DEBUG.so: usb-driver.c parport.c jtagkey.c config.c usb-driver.h parport.h jtagkey.h config.h Makefile - gcc -DDEBUG $(CFLAGS) usb-driver.c parport.c config.c $(JTAGKEYSRC) -o $@ -ldl -lusb -lpthread $(FTDI) -shared +libusb-driver-DEBUG.so: usb-driver.c parport.c jtagkey.c config.c jtagmon.c usb-driver.h parport.h jtagkey.h config.h jtagmon.h Makefile + gcc -DDEBUG $(CFLAGS) usb-driver.c parport.c config.c jtagmon.c $(JTAGKEYSRC) -o $@ -ldl -lusb -lpthread $(FTDI) -shared clean: rm -f $(SOBJECTS) diff --git a/jtagkey.c b/jtagkey.c index ffae2fa..19011fa 100644 --- a/jtagkey.c +++ b/jtagkey.c @@ -5,6 +5,7 @@ #include "usb-driver.h" #include "config.h" #include "jtagkey.h" +#include "jtagmon.h" #define USBBUFSIZE 1048576 #define JTAG_SPEED 100000 @@ -206,6 +207,9 @@ int jtagkey_transfer(WD_TRANSFER *tr, int fd, unsigned int request, int ppbase, #ifdef DEBUG if (tr[i].cmdTrans == 13) DPRINTF("write byte: %d\n", val); + + if (tr[i].cmdTrans == 13) + tapmon(val & PP_TCK, val & PP_TMS); #endif /* Pad writebuf for read-commands in stream */ diff --git a/jtagmon.c b/jtagmon.c new file mode 100644 index 0000000..198a2c6 --- /dev/null +++ b/jtagmon.c @@ -0,0 +1,206 @@ +#include +#include +#include "jtagmon.h" + +enum tap_states { + TEST_LOGIC_RESET, + RUN_TEST_IDLE, + SELECT_DR, + CAPTURE_DR, + SHIFT_DR, + EXIT1_DR, + PAUSE_DR, + EXIT2_DR, + UPDATE_DR, + SELECT_IR, + CAPTURE_IR, + SHIFT_IR, + EXIT1_IR, + PAUSE_IR, + EXIT2_IR, + UPDATE_IR +}; + +void tapmon(unsigned char tck, unsigned char tms) { + static unsigned char last_tck = 1; + static int state = TEST_LOGIC_RESET; + static char state_text[32] = "Test Logic Reset"; + char last_state_text[32]; + int last_state = state; + + strcpy(last_state_text, state_text); + + if (!last_tck && tck) { + switch(state) { + case TEST_LOGIC_RESET: + if (tms) { + state = TEST_LOGIC_RESET; + } else { + state = RUN_TEST_IDLE; + } + break; + case RUN_TEST_IDLE: + if (tms) { + state = SELECT_DR; + } else { + state = RUN_TEST_IDLE; + } + break; + case SELECT_DR: + if (tms) { + state = SELECT_IR; + } else { + state = CAPTURE_DR; + } + break; + case CAPTURE_DR: + if (tms) { + state = EXIT1_DR; + } else { + state = SHIFT_DR; + } + break; + case SHIFT_DR: + if (tms) { + state = EXIT1_DR; + } else { + state = SHIFT_DR; + } + break; + case EXIT1_DR: + if (tms) { + state = UPDATE_DR; + } else { + state = PAUSE_DR; + } + break; + case PAUSE_DR: + if (tms) { + state = EXIT2_DR; + } else { + state = PAUSE_DR; + } + break; + case EXIT2_DR: + if (tms) { + state = UPDATE_DR; + } else { + state = SHIFT_DR; + } + break; + case UPDATE_DR: + if (tms) { + state = SELECT_DR; + } else { + state = RUN_TEST_IDLE; + } + break; + case SELECT_IR: + if (tms) { + state = TEST_LOGIC_RESET; + } else { + state = CAPTURE_IR; + } + break; + case CAPTURE_IR: + if (tms) { + state = EXIT1_IR; + } else { + state = SHIFT_IR; + } + break; + case SHIFT_IR: + if (tms) { + state = EXIT1_IR; + } else { + state = SHIFT_IR; + } + break; + case EXIT1_IR: + if (tms) { + state = UPDATE_IR; + } else { + state = PAUSE_IR; + } + break; + case PAUSE_IR: + if (tms) { + state = EXIT2_IR; + } else { + state = PAUSE_IR; + } + break; + case EXIT2_IR: + if (tms) { + state = UPDATE_IR; + } else { + state = SHIFT_IR; + } + break; + case UPDATE_IR: + if (tms) { + state = SELECT_DR; + } else { + state = RUN_TEST_IDLE; + } + break; + } + + switch(state) { + case TEST_LOGIC_RESET: + strcpy(state_text, "Test Logic Reset"); + break; + case RUN_TEST_IDLE: + strcpy(state_text, "Run-Test / Idle"); + break; + case SELECT_DR: + strcpy(state_text, "Select-DR"); + break; + case CAPTURE_DR: + strcpy(state_text, "Capture-DR"); + break; + case SHIFT_DR: + strcpy(state_text, "Shift-DR"); + break; + case EXIT1_DR: + strcpy(state_text, "Exit1-DR"); + break; + case PAUSE_DR: + strcpy(state_text, "Pause-DR"); + break; + case EXIT2_DR: + strcpy(state_text, "Exit2-DR"); + break; + case UPDATE_DR: + strcpy(state_text, "Update-DR"); + break; + case SELECT_IR: + strcpy(state_text, "Select-IR"); + break; + case CAPTURE_IR: + strcpy(state_text, "Capture-IR"); + break; + case SHIFT_IR: + strcpy(state_text, "Shift-IR"); + break; + case EXIT1_IR: + strcpy(state_text, "Exit1-IR"); + break; + case PAUSE_IR: + strcpy(state_text, "Pause-IR"); + break; + case EXIT2_IR: + strcpy(state_text, "Exit2-IR"); + break; + case UPDATE_IR: + strcpy(state_text, "Update-IR"); + break; + } + + if (last_state != state) { + fprintf(stderr,"TAP state transition from %s to %s\n", last_state_text, state_text); + } + } + + last_tck = tck; +} diff --git a/jtagmon.h b/jtagmon.h new file mode 100644 index 0000000..26dea79 --- /dev/null +++ b/jtagmon.h @@ -0,0 +1 @@ +void tapmon(unsigned char tck, unsigned char tms); -- 2.39.2