2 #include "libnexys.win32.c"
4 #define LIBNEXYS_INTERNAL
11 #include <linux/ioctl.h>
12 #include <linux/ppdev.h>
21 nexys2_t nexys2_init(void) {
22 int pfd = open("/dev/parport0", O_RDWR);
25 perror("open /dev/parport0");
29 if ((ioctl(pfd, PPEXCL) < 0) || (ioctl(pfd, PPCLAIM) < 0))
31 perror("lock /dev/parport0");
38 int nexys2_jtag_enable(int pfd)
43 int nexys2_jtag_disable(int pfd)
48 int nexys2_jtag_setbits(int pfd, int tms, int tdi, int tck)
53 data = ((!!tms) << TMS) | ((!!tdi) << TDI) | ((!!tck) << TCK);
55 if (ioctl(pfd, PPWDATA, &data) < 0)
57 perror("nexys2_jtag_setbits: ioctl");
68 if (ioctl(pfd, PPRSTATUS, &data) < 0)
70 perror("_gettdi: PPRSTATUS");
81 int nexys2_jtag_puttdi(int pfd, int tms, int nbits, unsigned char *bits, unsigned char *obits)
86 memset(obits, 0, (nbits / 8) + ((nbits % 8) != 0));
88 for (i = 0; i < nbits; i++)
92 bit = bits[i / 8] & (1 << (i % 8));
93 nexys2_jtag_setbits(pfd, tms, bit, 1);
94 nexys2_jtag_setbits(pfd, tms, bit, 0);
96 obits[i/8] |= _gettdo(pfd) << (i % 8);
101 int nexys2_jtag_puttmstdi(int pfd, int nbits, unsigned char *bits, unsigned char *obits)
106 memset(obits, 0, (nbits / 8) + ((nbits % 8) != 0));
108 for (i = 0; i < nbits; i++)
112 tdi = bits[i / 4] & (1 << ((i % 4) * 2));
113 tms = bits[i / 4] & (2 << ((i % 4) * 2));
114 nexys2_jtag_setbits(pfd, tms, tdi, 0);
115 nexys2_jtag_setbits(pfd, tms, tdi, 1);
116 nexys2_jtag_setbits(pfd, tms, tdi, 0);
118 obits[i/8] |= _gettdo(pfd) << (i % 8);
123 int nexys2_jtag_gettdo(int pfd, int tdi, int tms, int nbits, unsigned char *obits)
128 memset(obits, 0, (nbits / 8) + ((nbits % 8) != 0));
130 for (i = 0; i < nbits; i++)
132 nexys2_jtag_setbits(pfd, tms, tdi, 0);
133 nexys2_jtag_setbits(pfd, tms, tdi, 1);
134 nexys2_jtag_setbits(pfd, tms, tdi, 0);
136 obits[i/8] |= _gettdo(pfd) << (i % 8);
145 void poke_idcode(nexys2_t nexys)
147 unsigned char seq1[] = { 0xaa, 0x22};
148 unsigned char seq2[] = { 0xaa, 0x02};
149 unsigned int idcode = 0;
150 unsigned int woop = 0x12345678;
154 while (nexys2_jtag_enable(nexys) < 0)
156 if (nexys2_jtag_puttmstdi(nexys, 8, seq1, NULL) < 0)
160 if (nexys2_jtag_gettdo(nexys, 0, 0, 32, &idcode) < 0)
162 printf("IDCODE: %08x\n", idcode);
163 } while(idcode && (idcode != 0xFFFFFFFF));
164 if (nexys2_jtag_puttmstdi(nexys, 8, seq2, NULL) < 0)
166 if (nexys2_jtag_disable(nexys) < 0)
174 nexys = nexys2_init();