vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / jtag / jtag.c
blob6bb258757d9aa7fadba4a5a3f08c5b81e85134df
1 /* ******************************************************** */
2 /* Small program to download a VHDL program to a JTAG port. */
3 /* Julian Lewis Mon 7th April 2003 */
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/file.h>
12 #include <lenval.h>
13 #include <micro.h>
14 #include <ports.h>
16 void setPort(short p,short val);
17 void readByte(unsigned char *data);
18 unsigned char readTDOBit();
19 void waitTime(long microsec);
20 void pulseClock();
22 static int xsvf_iDebugLevel = 0;
23 static FILE *inp = NULL;
24 static short *jtagAddr = NULL;
25 static unsigned short jtag = 0x0F; /* Keep all jtag bits */
27 #include <lenval.c>
28 #include <micro.c>
29 #include <ports.c>
30 #include <smemio.c>
32 /* ********************************************* */
33 /* Arguments: Filename VME-Address [Debug-Level] */
35 int main(int argc,char *argv[]) {
37 char fname[128], *cp, *ep, yn;
38 short *vmeAddress;
39 int cc;
41 if ((argc < 3) || (argc > 4)) {
42 printf("jtag: <filename> <vme address> [<debug level>]\n");
43 printf("Examples:\n");
44 printf(" nouchi.xsvf 0x1000\n");
45 printf(" nouchi.xsvf 0x1000 4\n");
46 exit(0);
49 strcpy(fname,argv[1]);
50 cp = argv[2];
51 vmeAddress = (short *) strtoul(cp,&ep,0);
52 if (argc == 4) xsvf_iDebugLevel = strtoul(argv[3],&ep,0);
54 printf("VHDL-Compiled BitStream Filename: %s VMEAddress: 0x%X DebugLevel: %d \n",
55 fname,
56 (int) vmeAddress,
57 (int) xsvf_iDebugLevel);
59 printf("Continue (Y/N):"); yn = getchar();
60 if ((yn != 'y') && (yn != 'Y')) exit(0);
62 inp = fopen(fname,"r");
63 if (inp) {
65 if (GetJtagPort(vmeAddress)) {
67 cc = xsvfExecute(); /* Play the xsvf file */
68 if (cc) printf("Jtag: xsvfExecute: ReturnCode: %d Error\n",cc);
69 else printf("Jtag: xsvfExecute: ReturnCode: %d All OK\n",cc);
70 fclose(inp);
71 exit(0);
73 } else {
74 perror("fopen");
75 printf("Could not open the file: %s for reading\n",fname);
77 exit(0);