2 * Copyright (C) Eicon Technology Corporation, 2000.
4 * Eicon File Revision : 1.2
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
15 #define FPGA_PORT 0x6E
16 #define FPGA_DLOAD_BUFLEN 256
17 #define NAME_OFFSET 0x10
18 #define NAME_MAXLEN 12
19 #define DATE_OFFSET 0x2c
20 #define DATE_MAXLEN 10
22 word UxCardPortIoInW(ux_diva_card_t *card, byte *base, int offset);
23 void UxCardPortIoOutW(ux_diva_card_t *card, byte *base, int offset, word);
24 void UxPause(long int);
26 /*-------------------------------------------------------------------------*/
27 /* Loads the FPGA configuration file onto the hardware. */
28 /* Function returns 0 on success, else an error number. */
29 /* On success, an identifier string is returned in the buffer */
31 /* A buffer of FPGA_BUFSIZE, a handle to the already opened bitstream */
32 /* file and a file read function has to be provided by the operating */
34 /* ----------------------------------------------------------------------- */
35 int FPGA_Download( word cardtype,
43 word baseval, Mask_PROGRAM, Mask_DONE, Mask_CCLK, Mask_DIN;
47 //--- check for legal cardtype
50 case IDI_ADAPTER_MAESTRAQ:
51 addr = RegBase ; // address where to access FPGA
52 Mask_PROGRAM = 0x0001; // FPGA pins at address
56 baseval = 0x000d; // PROGRAM hi, CCLK lo, DIN lo by default
61 DPRINTF(("divas: FPGA Download ,Illegal Card"));
62 return -1; // illegal card
65 //--- generate id string from file content
66 for (j=NAME_OFFSET, k=0; j<(NAME_OFFSET+NAME_MAXLEN); j++, k++) //name
68 if (!FPGA_SRC[j]) break;
69 strbuf[k] = FPGA_SRC[j];
72 for (j=DATE_OFFSET; j<(DATE_OFFSET+DATE_MAXLEN); j++, k++) // date
74 if (!FPGA_SRC[j]) break;
75 strbuf[k] = FPGA_SRC[j];
79 DPRINTF(("divas: FPGA Download - %s", strbuf));
81 //--- prepare download, Pulse PROGRAM pin down.
82 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval &~Mask_PROGRAM); // PROGRAM low pulse
83 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); // release
84 UxPause(50); // wait until FPGA finised internal memory clear
86 //--- check done pin, must be low
87 if (UxCardPortIoInW(NULL, (byte *) addr, FPGA_PORT) &Mask_DONE)
89 DPRINTF(("divas: FPGA_ERR_DONE_WRONG_LEVEL"));
96 /* Move past the header */
97 while ((FPGA_SRC[i] != 0xFF) && (i < FPGA_LEN))
102 // We've hit the 0xFF so move on to the next byte
104 DPRINTF(("divas: FPGA Code starts at offset %d", i));
106 //--- put data onto the FPGA
107 for (;i<FPGA_LEN; i++)
109 //--- put byte onto FPGA
112 if (FPGA_SRC[i] &(0x80>>j)) baseval |= Mask_DIN; // write a hi
113 else baseval &=~Mask_DIN; // write a lo
114 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval);
115 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval | Mask_CCLK); // set CCLK hi
116 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); // set CCLK lo
120 //--- add some additional startup clock cycles and check done pin
123 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval | Mask_CCLK); // set CCLK hi
124 UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); // set CCLK lo
129 if (UxCardPortIoInW(NULL, (byte *) addr, FPGA_PORT) &Mask_DONE)
131 DPRINTF(("divas: FPGA download successful"));
135 DPRINTF(("divas: FPGA download failed - 0x%x", UxCardPortIoInW(NULL, (byte *) addr, FPGA_PORT)));