/*-----------------------------------------------------------------------------\r
-\r
* FTDI EEPROM emulation\r
-\r
*-----------------------------------------------------------------------------\r
-\r
* Copyright (C) 2007 Kolja Waschk, ixo.de\r
-\r
*-----------------------------------------------------------------------------\r
-\r
* This code is part of usbjtag. usbjtag is free software; you can redistribute\r
-\r
* it and/or modify it under the terms of the GNU General Public License as\r
-\r
* published by the Free Software Foundation; either version 2 of the License,\r
-\r
* or (at your option) any later version. usbjtag is distributed in the hope\r
-\r
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied\r
-\r
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-\r
* GNU General Public License for more details. You should have received a\r
-\r
* copy of the GNU General Public License along with this program in the file\r
-\r
* COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin\r
-\r
* St, Fifth Floor, Boston, MA 02110-1301 USA\r
-\r
*-----------------------------------------------------------------------------\r
-\r
*/\r
\r
-\r
-\r
#include "eeprom.h"\r
-\r
#include "usb_descriptors.h"\r
\r
-\r
-\r
xdata unsigned char eeprom[128];\r
\r
-\r
-\r
extern xdata char dscr_vidpidver[6];\r
-\r
extern xdata char dscr_attrpow[2];\r
-\r
extern xdata char dscr_usbver[2];\r
-\r
extern xdata char dscr_strorder[4];\r
-\r
extern xdata char str1[];\r
-\r
extern xdata char str2[];\r
-\r
extern xdata char str3[];\r
\r
-\r
-\r
static unsigned char ee_ptr;\r
-\r
static unsigned short ee_cksum;\r
\r
-\r
-\r
void eeprom_append(unsigned char nb)\r
-\r
{\r
-\r
unsigned char pree_ptr = ee_ptr & ~1;\r
-\r
if(pree_ptr != ee_ptr)\r
-\r
{\r
-\r
ee_cksum = ee_cksum ^((unsigned short)nb << 8);\r
-\r
ee_cksum = ee_cksum ^ eeprom[pree_ptr];\r
-\r
ee_cksum = (ee_cksum << 1) | (ee_cksum >> 15);\r
-\r
};\r
-\r
eeprom[ee_ptr++] = nb;\r
-\r
}\r
\r
-\r
-\r
void eeprom_init(void)\r
-\r
{\r
-\r
char j,sofs;\r
-\r
ee_ptr = 0;\r
-\r
ee_cksum = 0xAAAA;\r
\r
-\r
-\r
eeprom_append(0x00);\r
-\r
eeprom_append(0x00);\r
-\r
for(j=0;j<6;j++) eeprom_append(dscr_vidpidver[j]);\r
-\r
for(j=0;j<2;j++) eeprom_append(dscr_attrpow[j]);\r
-\r
eeprom_append(0x1C);\r
-\r
eeprom_append(0x00);\r
-\r
for(j=0;j<2;j++) eeprom_append(dscr_usbver[j]);\r
-\r
sofs = 0x80 + ee_ptr + 6;\r
-\r
eeprom_append(sofs);\r
-\r
eeprom_append(str1[0]);\r
-\r
sofs += str1[0];\r
-\r
eeprom_append(sofs);\r
-\r
eeprom_append(str2[0]);\r
-\r
sofs += str2[0];\r
-\r
eeprom_append(sofs);\r
-\r
eeprom_append(str3[0]);\r
-\r
for(j=0;j<str1[0];j++) eeprom_append(str1[j]);\r
-\r
for(j=0;j<str2[0];j++) eeprom_append(str2[j]);\r
-\r
for(j=0;j<str3[0];j++) eeprom_append(str3[j]);\r
-\r
for(j=0;j<4;j++) eeprom_append(dscr_strorder[j]);\r
-\r
while(ee_ptr < 126) eeprom_append(0);\r
-\r
eeprom[126] = ee_cksum&0xFF;\r
-\r
eeprom[127] = (ee_cksum>>8)&0xFF;\r
-\r
}\r
\r
-\r
-\r