X-Git-Url: https://www.hackdaworld.org/gitweb/?a=blobdiff_plain;f=fx2%2Ffx2.c;h=0ba6db9da40da48d38b35b0040fba80f958d9279;hb=dda42c5ae4c74fdb488ae105d2a493bce58483fa;hp=3a57b12c4e83456709715a195c1f90af059087d3;hpb=07f700caf7db1d12cf0dde7627ced350d162d107;p=my-code%2Ffpga.git diff --git a/fx2/fx2.c b/fx2/fx2.c index 3a57b12..0ba6db9 100644 --- a/fx2/fx2.c +++ b/fx2/fx2.c @@ -11,10 +11,7 @@ */ /* constant definitions */ -#define TRUE 1 -#define FALSE 0 -#define POWER_ON 1; -#define POWER_OFF 0; +#define GET_TDO 0x20 /* type definitions */ typedef unsigned char u8; @@ -133,29 +130,49 @@ void slave_fifo_init() { /* initialization of the slave fifo, used by external logic (the fpga) * to do usb communication with the host */ - /* set bit 0 and 1 - fifo slave config */ - IFCONFIG|=0x03; + /* enable dyn_out and enhanced packet handling (p. 189) */ + REVCTL=0x03; SYNCDELAY; - /* async mode */ - IFCONFIG|=0x04; + /* internal 48 mhz clock, async, slave fifo */ + IFCONFIG=0xcb; SYNCDELAY; - /* p. 180: must be set to 1 */ - REVCTL|=((1<<0)|(1<<1)); - SYNCDELAY; - - /* 8 bit fifo to all endpoints + /* endpoint setup: * - * ('or' of all these bits define port d functionality) + * ep2: bulk out 2x512 + * ep4: bulk out 2x512 + * ep6: bulk in 2x512 + * ep8: bulk in 2x512 */ - EP2FIFOCFG&=~(1<<0); + EP2CFG=0xa2; + EP4CFG=0xa0; + EP6CFG=0xc2; + EP8CFG=0xc0; + SYNCDELAY; + + /* reset the fifo */ + FIFORESET=0x80; /* nak all transfers */ SYNCDELAY; - EP4FIFOCFG&=~(1<<0); + FIFORESET=0x02; /* reset ep2 */ SYNCDELAY; - EP6FIFOCFG&=~(1<<0); + FIFORESET=0x04; /* reset ep4 */ SYNCDELAY; - EP8FIFOCFG&=~(1<<0); + FIFORESET=0x06; /* reset ep6 */ + SYNCDELAY; + FIFORESET=0x08; /* reset ep8 */ + SYNCDELAY; + FIFORESET=0x00; /* restore normal operation */ + SYNCDELAY; + + /* 8 bit fifo to all endpoints */ + EP2FIFOCFG=; + SYNCDELAY; + EP4FIFOCFG=; + SYNCDELAY; + EP6FIFOCFG=; + SYNCDELAY; + EP8FIFOCFG=; SYNCDELAY; /* default indexed flag configuration: @@ -167,33 +184,6 @@ void slave_fifo_init() { * todo: -> fixed configuration */ - /* endpoint configuration: - * - * ep2: bulk out 4x512 - * ep6: bulk in 4x512 - * - * 0xa0 = 1 0 1 0 0 0 0 0 = bulk out 4x512 - * 0xe0 = 1 1 1 0 0 0 0 0 = bulk in 4x512 - */ - EP2CFG=0xa0; - SYNCDELAY; - EP4CFG&=(~0x80); - SYNCDELAY; - EP6CFG=0xe0; - SYNCDELAY; - EP8CFG&=(~0x80); - SYNCDELAY; - - /* reset the fifo */ - FIFORESET=0x80; /* nak all transfers */ - SYNCDELAY; - FIFORESET=0x02; /* reset ep2 */ - SYNCDELAY; - FIFORESET=0x06; /* reset ep6 */ - SYNCDELAY; - FIFORESET=0x00; /* restore normal operation */ - SYNCDELAY; - /* auto in/out, no cpu interaction! auto in len = 512 */ EP2FIFOCFG|=(1<<4); SYNCDELAY; @@ -219,7 +209,7 @@ void ep1_init() { */ /* arm ep1out, clear ep1out and ep1in stall bit */ - EP1OUTBC=1; + EP1OUTBC=0; EP1OUTCS&=~STALL; EP1INCS&=~STALL; @@ -227,6 +217,9 @@ void ep1_init() { void fx2_init() { + /* syncdelay */ + SYNCDELAY; + /* cpu init */ cpu_init(); @@ -239,26 +232,29 @@ void fx2_init() { /* ep1 init */ ep1_init(); + + /* jtag init */ + jtag_init(); } void main() { - u8 buf; + u8 buf,set; /* initialize the fx2 */ fx2_init(); /* jtag by polling ep1 */ + while(1) { if(!(EP1OUTCS&BUSY)) { + set=IOD; buf=EP1OUTBUF[0]; - buf&=0x1c; - IOD|=buf; + IOD=(IOD&(~0x1c))|(buf&0x1c); EP1OUTBC=1; } if(!(EP1INCS&BUSY)) { - buf=IOD&0x01?1:0; - EP1INBUF[0]=buf; + EP1INBUF[0]=IOD&0x01; EP1INBC=1; } }