1 /*-----------------------------------------------------------------------------
\r
3 * FTDI EEPROM emulation
\r
5 *-----------------------------------------------------------------------------
\r
7 * Copyright (C) 2007 Kolja Waschk, ixo.de
\r
9 *-----------------------------------------------------------------------------
\r
11 * This code is part of usbjtag. usbjtag is free software; you can redistribute
\r
13 * it and/or modify it under the terms of the GNU General Public License as
\r
15 * published by the Free Software Foundation; either version 2 of the License,
\r
17 * or (at your option) any later version. usbjtag is distributed in the hope
\r
19 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
\r
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
23 * GNU General Public License for more details. You should have received a
\r
25 * copy of the GNU General Public License along with this program in the file
\r
27 * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
\r
29 * St, Fifth Floor, Boston, MA 02110-1301 USA
\r
31 *-----------------------------------------------------------------------------
\r
39 #include "usb_descriptors.h"
\r
43 xdata unsigned char eeprom[128];
\r
47 extern xdata char dscr_vidpidver[6];
\r
49 extern xdata char dscr_attrpow[2];
\r
51 extern xdata char dscr_usbver[2];
\r
53 extern xdata char dscr_strorder[4];
\r
55 extern xdata char str1[];
\r
57 extern xdata char str2[];
\r
59 extern xdata char str3[];
\r
63 static unsigned char ee_ptr;
\r
65 static unsigned short ee_cksum;
\r
69 void eeprom_append(unsigned char nb)
\r
73 unsigned char pree_ptr = ee_ptr & ~1;
\r
75 if(pree_ptr != ee_ptr)
\r
79 ee_cksum = ee_cksum ^((unsigned short)nb << 8);
\r
81 ee_cksum = ee_cksum ^ eeprom[pree_ptr];
\r
83 ee_cksum = (ee_cksum << 1) | (ee_cksum >> 15);
\r
87 eeprom[ee_ptr++] = nb;
\r
93 void eeprom_init(void)
\r
105 eeprom_append(0x00);
\r
107 eeprom_append(0x00);
\r
109 for(j=0;j<6;j++) eeprom_append(dscr_vidpidver[j]);
\r
111 for(j=0;j<2;j++) eeprom_append(dscr_attrpow[j]);
\r
113 eeprom_append(0x1C);
\r
115 eeprom_append(0x00);
\r
117 for(j=0;j<2;j++) eeprom_append(dscr_usbver[j]);
\r
119 sofs = 0x80 + ee_ptr + 6;
\r
121 eeprom_append(sofs);
\r
123 eeprom_append(str1[0]);
\r
127 eeprom_append(sofs);
\r
129 eeprom_append(str2[0]);
\r
133 eeprom_append(sofs);
\r
135 eeprom_append(str3[0]);
\r
137 for(j=0;j<str1[0];j++) eeprom_append(str1[j]);
\r
139 for(j=0;j<str2[0];j++) eeprom_append(str2[j]);
\r
141 for(j=0;j<str3[0];j++) eeprom_append(str3[j]);
\r
143 for(j=0;j<4;j++) eeprom_append(dscr_strorder[j]);
\r
145 while(ee_ptr < 126) eeprom_append(0);
\r
147 eeprom[126] = ee_cksum&0xFF;
\r
149 eeprom[127] = (ee_cksum>>8)&0xFF;
\r