Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /* XCF Flash PROM JTAG programming algorithms |
| 2 | |
| 3 | Copyright (C) 2004 Andrew Rogers |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | #include "progalgxcf.h" |
| 23 | |
| 24 | const byte ProgAlgXCF::SERASE=0x0a; |
| 25 | const byte ProgAlgXCF::ISPEN=0xe8; |
| 26 | const byte ProgAlgXCF::FPGM=0xea; |
| 27 | const byte ProgAlgXCF::FADDR=0xeb; |
| 28 | const byte ProgAlgXCF::FERASE=0xec; |
| 29 | const byte ProgAlgXCF::FDATA0=0xed; |
| 30 | const byte ProgAlgXCF::FVFY0=0xef; |
| 31 | const byte ProgAlgXCF::NORMRST=0xf0; |
| 32 | const byte ProgAlgXCF::IDCODE=0xfe; |
| 33 | const byte ProgAlgXCF::BYPASS=0xff; |
| 34 | |
| 35 | const byte ProgAlgXCF::BIT3=0x08; |
| 36 | const byte ProgAlgXCF::BIT4=0x10; |
| 37 | |
| 38 | ProgAlgXCF::ProgAlgXCF(Jtag &j, IOBase &i) |
| 39 | { |
| 40 | jtag=&j; |
| 41 | io=&i; |
| 42 | } |
| 43 | |
| 44 | int ProgAlgXCF::erase() |
| 45 | { |
| 46 | byte data[4]; |
| 47 | jtag->shiftIR(&NORMRST); |
| 48 | io->cycleTCK(40000); |
| 49 | byte ircap[1]; |
| 50 | jtag->shiftIR(&BYPASS,ircap); |
| 51 | if((ircap[0]&BIT3)==BIT3){ |
| 52 | fprintf(stderr,"Device is write protected.\n",ircap[0]); |
| 53 | return 1; |
| 54 | } |
| 55 | jtag->shiftIR(&ISPEN); |
| 56 | jtag->shiftIR(&FADDR); |
| 57 | jtag->longToByteArray(1,data); |
| 58 | jtag->shiftDR(data,0,16); |
| 59 | io->cycleTCK(2); |
| 60 | |
| 61 | printf("Erasing...."); fflush(stdout); |
| 62 | jtag->shiftIR(&FERASE); |
| 63 | io->cycleTCK(2400000); |
| 64 | printf("done.\n"); |
| 65 | |
| 66 | jtag->shiftIR(&BYPASS); |
| 67 | io->tapTestLogicReset(); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | int ProgAlgXCF::program(BitFile &file) |
| 73 | { |
| 74 | jtag->shiftIR(&NORMRST); |
| 75 | io->cycleTCK(40000); |
| 76 | io->setTapState(IOBase::TEST_LOGIC_RESET); |
| 77 | byte data[4]; |
| 78 | jtag->shiftIR(&ISPEN); |
| 79 | data[0]=0x34; |
| 80 | jtag->shiftDR(data,0,6); |
| 81 | |
| 82 | for(int i=0; i<file.getLength(); i+=4096){ |
| 83 | int frame=i/128; |
| 84 | printf("Programming frames 0x%04x to 0x%04x....",frame,frame+31); fflush(stdout); |
| 85 | jtag->shiftIR(&FDATA0); |
| 86 | if((i+4096)<=file.getLength()){ |
| 87 | jtag->shiftDR(&(file.getData())[i/8],0,4096); |
| 88 | } |
| 89 | else{ |
| 90 | int rem=(file.getLength()-i)/8; // Bytes remaining |
| 91 | int pad=512-rem; |
| 92 | byte paddata[pad]; for(int k=0; k<pad; k++)paddata[k]=0xff; |
| 93 | jtag->shiftDR(&(file.getData())[i/8],0,rem*8,0,false); // Do not goto EXIT1-DR |
| 94 | jtag->shiftDR(paddata,0,pad*8); |
| 95 | } |
| 96 | jtag->longToByteArray(frame,data); |
| 97 | jtag->shiftIR(&FADDR); |
| 98 | jtag->shiftDR(data,0,16); |
| 99 | io->cycleTCK(2); |
| 100 | jtag->shiftIR(&FPGM); |
| 101 | io->cycleTCK(5000); |
| 102 | printf("done.\n"); |
| 103 | } |
| 104 | |
| 105 | jtag->shiftIR(&BYPASS); |
| 106 | io->tapTestLogicReset(); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int ProgAlgXCF::verify(BitFile &file) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 |
Branches:
master
