Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | /* * * Copyright (C) Eicon Technology Corporation, 2000. * * Eicon File Revision : 1.2 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "sys.h" #include "idi.h" #include "uxio.h" #define FPGA_PORT 0x6E #define FPGA_DLOAD_BUFLEN 256 #define NAME_OFFSET 0x10 #define NAME_MAXLEN 12 #define DATE_OFFSET 0x2c #define DATE_MAXLEN 10 word UxCardPortIoInW(ux_diva_card_t *card, byte *base, int offset); void UxCardPortIoOutW(ux_diva_card_t *card, byte *base, int offset, word); void UxPause(long int); /*-------------------------------------------------------------------------*/ /* Loads the FPGA configuration file onto the hardware. */ /* Function returns 0 on success, else an error number. */ /* On success, an identifier string is returned in the buffer */ /* */ /* A buffer of FPGA_BUFSIZE, a handle to the already opened bitstream */ /* file and a file read function has to be provided by the operating */ /* system part. */ /* ----------------------------------------------------------------------- */ int FPGA_Download( word cardtype, dword RegBase, byte *strbuf, byte FPGA_SRC[], int FPGA_LEN ) { word i, j, k; word baseval, Mask_PROGRAM, Mask_DONE, Mask_CCLK, Mask_DIN; dword addr; byte *pFPGA; //--- check for legal cardtype switch (cardtype) { case IDI_ADAPTER_MAESTRAQ: addr = RegBase ; // address where to access FPGA Mask_PROGRAM = 0x0001; // FPGA pins at address Mask_DONE = 0x0002; Mask_CCLK = 0x0100; Mask_DIN = 0x0400; baseval = 0x000d; // PROGRAM hi, CCLK lo, DIN lo by default break; default: DPRINTF(("divas: FPGA Download ,Illegal Card")); return -1; // illegal card } //--- generate id string from file content for (j=NAME_OFFSET, k=0; j<(NAME_OFFSET+NAME_MAXLEN); j++, k++) //name { if (!FPGA_SRC[j]) break; strbuf[k] = FPGA_SRC[j]; } strbuf[k++] = ' '; for (j=DATE_OFFSET; j<(DATE_OFFSET+DATE_MAXLEN); j++, k++) // date { if (!FPGA_SRC[j]) break; strbuf[k] = FPGA_SRC[j]; } strbuf[k] = 0; DPRINTF(("divas: FPGA Download - %s", strbuf)); //--- prepare download, Pulse PROGRAM pin down. UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval &~Mask_PROGRAM); // PROGRAM low pulse UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); // release UxPause(50); // wait until FPGA finised internal memory clear //--- check done pin, must be low if (UxCardPortIoInW(NULL, (byte *) addr, FPGA_PORT) &Mask_DONE) { DPRINTF(("divas: FPGA_ERR_DONE_WRONG_LEVEL")); return -1; } pFPGA = FPGA_SRC; i = 0; /* Move past the header */ while ((FPGA_SRC[i] != 0xFF) && (i < FPGA_LEN)) { i++; } // We've hit the 0xFF so move on to the next byte // i++; DPRINTF(("divas: FPGA Code starts at offset %d", i)); //--- put data onto the FPGA for (;i<FPGA_LEN; i++) { //--- put byte onto FPGA for (j=0; j<8; j++) { if (FPGA_SRC[i] &(0x80>>j)) baseval |= Mask_DIN; // write a hi else baseval &=~Mask_DIN; // write a lo UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval | Mask_CCLK); // set CCLK hi UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); // set CCLK lo } } //--- add some additional startup clock cycles and check done pin for (i=0; i<5; i++) { UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval | Mask_CCLK); // set CCLK hi UxCardPortIoOutW(NULL, (byte *) addr, FPGA_PORT, baseval); // set CCLK lo } UxPause(100); if (UxCardPortIoInW(NULL, (byte *) addr, FPGA_PORT) &Mask_DONE) { DPRINTF(("divas: FPGA download successful")); } else { DPRINTF(("divas: FPGA download failed - 0x%x", UxCardPortIoInW(NULL, (byte *) addr, FPGA_PORT))); return -1; } return 0; } |