1 |
17 |
wfjm |
/* $Id: eeprom.c 395 2011-07-17 22:02:55Z mueller $ */
|
2 |
|
|
/*-----------------------------------------------------------------------------
|
3 |
|
|
* FTDI EEPROM emulation
|
4 |
|
|
*-----------------------------------------------------------------------------
|
5 |
|
|
* Copyright (C) 2007 Kolja Waschk, ixo.de
|
6 |
|
|
*-----------------------------------------------------------------------------
|
7 |
|
|
* This code is part of usbjtag. usbjtag is free software; you can redistribute
|
8 |
|
|
* it and/or modify it under the terms of the GNU General Public License as
|
9 |
|
|
* published by the Free Software Foundation; either version 2 of the License,
|
10 |
|
|
* or (at your option) any later version. usbjtag is distributed in the hope
|
11 |
|
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
12 |
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
* GNU General Public License for more details. You should have received a
|
14 |
|
|
* copy of the GNU General Public License along with this program in the file
|
15 |
|
|
* COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
16 |
|
|
* St, Fifth Floor, Boston, MA 02110-1301 USA
|
17 |
|
|
*-----------------------------------------------------------------------------
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
#include "eeprom.h"
|
21 |
|
|
#include "usb_descriptors.h"
|
22 |
|
|
|
23 |
|
|
xdata unsigned char eeprom[128];
|
24 |
|
|
|
25 |
|
|
extern xdata char dscr_vidpidver[6];
|
26 |
|
|
extern xdata char dscr_attrpow[2];
|
27 |
|
|
extern xdata char dscr_usbver[2];
|
28 |
|
|
extern xdata char dscr_strorder[4];
|
29 |
|
|
extern xdata char str1[];
|
30 |
|
|
extern xdata char str2[];
|
31 |
|
|
extern xdata char str3[];
|
32 |
|
|
|
33 |
|
|
static unsigned char ee_ptr;
|
34 |
|
|
static unsigned short ee_cksum;
|
35 |
|
|
|
36 |
|
|
void eeprom_append(unsigned char nb)
|
37 |
|
|
{
|
38 |
|
|
unsigned char pree_ptr = ee_ptr & ~1;
|
39 |
|
|
if(pree_ptr != ee_ptr)
|
40 |
|
|
{
|
41 |
|
|
ee_cksum = ee_cksum ^((unsigned short)nb << 8);
|
42 |
|
|
ee_cksum = ee_cksum ^ eeprom[pree_ptr];
|
43 |
|
|
ee_cksum = (ee_cksum << 1) | (ee_cksum >> 15);
|
44 |
|
|
};
|
45 |
|
|
eeprom[ee_ptr++] = nb;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
void eeprom_init(void)
|
49 |
|
|
{
|
50 |
|
|
char j,sofs;
|
51 |
|
|
ee_ptr = 0;
|
52 |
|
|
ee_cksum = 0xAAAA;
|
53 |
|
|
|
54 |
|
|
eeprom_append(0x00);
|
55 |
|
|
eeprom_append(0x00);
|
56 |
|
|
for(j=0;j<6;j++) eeprom_append(dscr_vidpidver[j]);
|
57 |
|
|
for(j=0;j<2;j++) eeprom_append(dscr_attrpow[j]);
|
58 |
|
|
eeprom_append(0x1C);
|
59 |
|
|
eeprom_append(0x00);
|
60 |
|
|
for(j=0;j<2;j++) eeprom_append(dscr_usbver[j]);
|
61 |
|
|
sofs = 0x80 + ee_ptr + 6;
|
62 |
|
|
eeprom_append(sofs);
|
63 |
|
|
eeprom_append(str1[0]);
|
64 |
|
|
sofs += str1[0];
|
65 |
|
|
eeprom_append(sofs);
|
66 |
|
|
eeprom_append(str2[0]);
|
67 |
|
|
sofs += str2[0];
|
68 |
|
|
eeprom_append(sofs);
|
69 |
|
|
eeprom_append(str3[0]);
|
70 |
|
|
for(j=0;j<str1[0];j++) eeprom_append(str1[j]);
|
71 |
|
|
for(j=0;j<str2[0];j++) eeprom_append(str2[j]);
|
72 |
|
|
for(j=0;j<str3[0];j++) eeprom_append(str3[j]);
|
73 |
|
|
for(j=0;j<4;j++) eeprom_append(dscr_strorder[j]);
|
74 |
|
|
while(ee_ptr < 126) eeprom_append(0);
|
75 |
|
|
eeprom[126] = ee_cksum&0xFF;
|
76 |
|
|
eeprom[127] = (ee_cksum>>8)&0xFF;
|
77 |
|
|
}
|
78 |
|
|
|