void init_user()
{
EA = 0; //Interrupts disabled - simplify debugging and setup times
IFCONFIG = 0xE3; SYNCDELAY(); //internal, 48MHz, SYNC, slave
REVCTL = 0x03; SYNCDELAY();
//Setup debug endpoints
EP1OUTCFG = 0xB0; SYNCDELAY(); //Interrupt
EP1INCFG = 0xB0; SYNCDELAY();
REARMEP1OUT();
//init flags. listed in docs/fpga-cypacket.txt
PINFLAGSAB = 0x8C; SYNCDELAY();
PINFLAGSCD = 0x09; SYNCDELAY();
//FIFOINPOLAR = 0x00; SYNCDELAY();
//Setup LED output, and light it
PORTCCFG &= ~0x80;
OEC |= 0x80;
SYNCDELAY();
PC7 = 1;
//Sort out FIFOs
//see: http://www.embeddedrelated.com/usenet/embedded/show/65142-1.php
//Issue with cypress chip and 'full' flag on a warm start
EP2CFG = 0xE4; SYNCDELAY();
EP4CFG = 0xA2; SYNCDELAY();
EP6CFG = 0x00; SYNCDELAY();
EP8CFG = 0x00; SYNCDELAY();
FIFORESET = 0x80; SYNCDELAY();
FIFORESET = 0x82; SYNCDELAY();
FIFORESET = 0x84; SYNCDELAY();
FIFORESET = 0x86; SYNCDELAY();
FIFORESET = 0x88; SYNCDELAY();
FIFORESET = 0x00; SYNCDELAY();
OUTPKTEND = 0x84; SYNCDELAY();
OUTPKTEND = 0x84; SYNCDELAY();
INPKTEND = 0x82; SYNCDELAY();
INPKTEND = 0x82; SYNCDELAY();
EP2FIFOCFG = 0x00; SYNCDELAY(); //to ensure it sees a 0->1 transition
EP4FIFOCFG = 0x00; SYNCDELAY();
EP2FIFOCFG = 0x0B; SYNCDELAY();
EP4FIFOCFG = 0x11; SYNCDELAY();
EP2AUTOINLENH = 0x01; SYNCDELAY();
EP2AUTOINLENL = 0x00; SYNCDELAY();
EA = 1;
}