source: trunk/FirmwareFX2/eeprom.c@ 89

Last change on this file since 89 was 4, checked in by demin, 15 years ago

initial commit

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