/*
- * jtag via parallel
+ * doing jtag via the
+ *
+ * 'low cost jtag parallel programming cable'
*
* author: hackbard@hackdaworld.org
*
*/
-#define XILINX_LOW_COST_CABLE 0x00
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/io.h>
-#define ALTERA_BYTE_BLASTER
+#define PARPORT 0x378
+#define TMS (1<<2) /* d2 */
+#define TDI (1<<0) /* d0 */
+#define TCK (1<<1) /* d1 */
+#define TDO (1<<4) /* select in */
+#define JTAG_INITIALIZED 0x01
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
+#define FALSE 0
+#define TRUE 1
-#include <sys/io.h>
+typedef unsigned char u8;
+typedef unsigned short int u16;
+typedef unsigned int u32;
+
+typedef struct s_jtag {
+ u16 port;
+ u8 status;
+} t_jtag;
+
+int jtag_set_port(t_jtag *jtag,u16 port) {
+
+ jtag->port=port;
+
+ return 0;
+}
+
+int jtag_init(t_jtag *jtag) {
+
+ int ret;
+ u8 out;
+
+ out=0;
+
+ /* permissions */
+ ret=ioperm(jtag->port,2,TRUE);
+ if(ret<0) {
+ perror("ioperm");
+ return -1;
+ }
+
+ /* set tck to zero */
+ outb(out,jtag->port);
+
+ return 0;
+}
+
+u8 jtag_act(t_jtag *jtag,u8 tms,u8 tdi) {
+
+ u8 out;
+ u8 tdo;
+ int i;
+
+ out=0;
+
+ if(tms) out|=(1<<TMS);
+ if(tdi) out|=(1<<TDI);
+
+ /* with tck high */
+ outb((out|TCK),jtag->port);
+
+ /* with tck low */
+ outb(out,jtag->port);
+
+ tdo=inb(jtag->port+1);
+printf("%0x2 %c | ",tdo,((tdo<0x20)|(tdo>0x7e))?'.':tdo);
+for(i=0;i<8;i++) printf("%d ",((tdo<<(7-i))&0x01)?1:0);
+printf("\n");
+
+ return tdo;
+}
+
+int jtag_reset(t_jtag *jtag) {
+
+ int i;
+
+ for(i=0;i<5;i++) jtag_act(jtag,1,0);
+
+ return 0;
+}
+
+int jtag_shift_dr(t_jtag *jtag) {
+
+ /* assume 'test logic reset' status */
+
+ jtag_act(jtag,0,0);
+ jtag_act(jtag,1,0);
+ jtag_act(jtag,0,0);
+ jtag_act(jtag,0,0);
+
+ return 0;
+}
+
+int main(int argc,char **argv) {
+
+ t_jtag jtag;
+ int i;
+
+ jtag_init(&jtag);
+
+ jtag_reset(&jtag);
+
+ jtag_shift_dr(&jtag);
+
+ for(i=0;i<32;i++) jtag_act(&jtag,0,0);
+ return 0;
+}