]> hackdaworld.org Git - my-code/pnx.git/commitdiff
implemented set ir stuff master
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 28 Mar 2011 11:33:48 +0000 (13:33 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 28 Mar 2011 11:33:48 +0000 (13:33 +0200)
jtag.c

diff --git a/jtag.c b/jtag.c
index 2497cf78dbd935c1a632cdc53f3a0307b82c4af6..9d05d5f54cb3970f98f7e73d37b0463e42a796f5 100644 (file)
--- a/jtag.c
+++ b/jtag.c
@@ -1,6 +1,7 @@
 /*
  * jtag.c - basic jtag stuff (good excercise!)
  *
+ * build: gcc -Wall jtag.c -o jtag
  * author: hackbard@hackdaworld.org
  *
  */
@@ -164,12 +165,15 @@ int jtag_read_data(u8 *p,int bitlen) {
        memset(p,0,bitlen+7/8);
        count=0;
 
+       printf("  <- ");
        while(bitlen) {
                in=jtag_clock(0,0);
                p[count/8]|=((in&1)<<(count%8));
+               printf("%d",p[count/8]&(1<<(count%8))?1:0);
                count+=1;
                bitlen-=1;
        }
+       printf("\n");
 
        return 0;
 
@@ -181,11 +185,14 @@ int jtag_write_data(u8 *p,int bitlen) {
 
        count=0;
 
+       printf("  -> ");
        while(bitlen) {
-               jtag_clock(0,p[count/8]&(1<<count)?1:0);
+               jtag_clock(0,p[count/8]&(1<<(count%8))?1:0);
+               printf("%d",p[count/8]&(1<<(count%8))?1:0);
                bitlen-=1;
                count+=1;
        }
+       printf("\n");
 
        return 0;
 
@@ -239,18 +246,20 @@ int jtag_set_ir(char *s,int bitlen) {
        }
 
        memset(ir,0,MAXDEV*MAXIRLEN/8*sizeof(u8));
+       count=0;
 
-       printf("ir to set: ");
+       printf("set ir: ");
        while(bitlen) {
-               ir[count/8]|=(s[count]<<(count%8));
-               printf("%d",ir[count/8]&(1<<count%8)?1:0);
+               if(s[count]=='1')
+                       ir[count/8]|=(1<<(count%8));
+               printf("%d",ir[count/8]&(1<<(count%8))?1:0);
                count+=1;
                bitlen-=1;
        }
        printf("\n");
 
        jtag_enter_shift_ir();
-       jtag_write_data(ir,bitlen);
+       jtag_write_data(ir,count);
        jtag_leave_shift_ir();
 
        return 0;
@@ -261,7 +270,6 @@ int main(int argc,char **argv) {
 
        t_jtag jtag;
        u8 io[256];
-       int i;
 
        memset(&jtag,0,sizeof(t_jtag));
 
@@ -281,10 +289,6 @@ int main(int argc,char **argv) {
        jtag_set_ir("000001000001",12);
        jtag_enter_shift_dr();
        jtag_read_data(io,64);
-       for(i=0;i<64;i++) {
-               printf("%d",io[i/8]&(1<<(i%8))?1:0);
-       }
-       printf("\n");
        jtag_leave_shift_dr();
 
        return 0;