jtag-mpsse

JTAG tools for FTDI MPSSE transports
git clone http://frotz.net/git/jtag-mpsse.git
Log | Files | Refs

debug.c (1803B)


      1 /* Copyright 2014 Brian Swetland <swetland@frotz.net>
      2  *
      3  * Licensed under the Apache License, Version 2.0 (the "License");
      4  * you may not use this file except in compliance with the License.
      5  * You may obtain a copy of the License at
      6  *
      7  *     http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software
     10  * distributed under the License is distributed on an "AS IS" BASIS,
     11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  * See the License for the specific language governing permissions and
     13  * limitations under the License.
     14  */
     15 
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 #include <unistd.h>
     19 
     20 #include "jtag.h"
     21 #include "zynq.h"
     22 
     23 static JTAG *jtag;
     24 
     25 void jconnect(void) {
     26 	if (!(jtag = jtag_open())) {
     27 		fprintf(stderr, "jconnect: cannot open usb jtag ifc\n");
     28 		exit(-1);
     29 	}
     30 	if (jtag_enumerate(jtag) <= 0) {
     31 		fprintf(stderr, "jconnect: cannot enumerate jtag devices\n");
     32 		exit(-1);
     33 	}
     34 	if (jtag_select(jtag, 0x13722093)) {
     35 		fprintf(stderr, "jconnect: cannot connect to ZYNQ\n");
     36 		exit(-1);
     37 	}
     38 
     39 	jtag_ir_wr(jtag, XIL_USER4);
     40 }
     41 
     42 u32 jrd(u32 addr) {
     43 	u64 u;
     44 	jtag_dr_io(jtag, 4, addr & 7, &u);
     45 	jtag_dr_io(jtag, 36, 0, &u);
     46 	return (u32) u;
     47 }
     48 
     49 void jwr(u32 addr, u32 val) {
     50 	u64 u = ((u64)val) | (((u64) (addr & 7)) << 32) | 0x800000000ULL;
     51 	jtag_dr_io(jtag, 36, u, &u);
     52 }
     53 
     54 int main(int argc, char **argv) {
     55 
     56 	if (argc == 3) {
     57 		u32 addr = strtoul(argv[1], 0, 0);
     58 		u32 val = strtoul(argv[2], 0, 0);
     59 		jconnect();
     60 		jwr(addr, val);
     61 		return 0;
     62 	} else if (argc == 2) {
     63 		u32 addr = strtoul(argv[1], 0, 0);
     64 		u32 val;
     65 		jconnect();
     66  		val = jrd(addr);
     67 		printf("%08x\n", val);
     68 		return 0;
     69 	} else {
     70 		fprintf(stderr,
     71 			"usage:\n"
     72 			"  write:  debug <addr> <val>\n"
     73 			"   read:  debug <addr>\n");
     74 		return -1;
     75 	}
     76 }