File: eeprom.c

package info (click to toggle)
ixo-usb-jtag 0.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 344 kB
  • sloc: ansic: 2,572; makefile: 90
file content (77 lines) | stat: -rw-r--r-- 2,638 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*-----------------------------------------------------------------------------
 * FTDI EEPROM emulation
 *-----------------------------------------------------------------------------
 * Copyright (C) 2007 Kolja Waschk, ixo.de
 *-----------------------------------------------------------------------------
 * This code is part of usbjtag. usbjtag is free software; you can redistribute
 * it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version. usbjtag is distributed in the hope
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.  You should have received a
 * copy of the GNU General Public License along with this program in the file
 * COPYING; if not, write to the Free Software Foundation, Inc., 51 Franklin
 * St, Fifth Floor, Boston, MA  02110-1301  USA
 *-----------------------------------------------------------------------------
 */

#include "eeprom.h"
#include "usb_descriptors.h"

xdata unsigned char eeprom[128];

extern xdata char dscr_vidpidver[6];
extern xdata char dscr_attrpow[2];
extern xdata char dscr_usbver[2];
extern xdata char dscr_strorder[4];
extern xdata char str1[];
extern xdata char str2[];
extern xdata char str3[];

static unsigned char ee_ptr;
static unsigned short ee_cksum;

void eeprom_append(unsigned char nb)
{
  unsigned char pree_ptr = ee_ptr & ~1;
  if(pree_ptr != ee_ptr)
  {
    ee_cksum = ee_cksum ^((unsigned short)nb << 8);
    ee_cksum = ee_cksum ^ eeprom[pree_ptr];
    ee_cksum = (ee_cksum << 1) | (ee_cksum >> 15);
  };
  eeprom[ee_ptr++] = nb;
}

void eeprom_init(void)
{
  char j,sofs;
  ee_ptr = 0;
  ee_cksum = 0xAAAA;

  eeprom_append(0x00);
  eeprom_append(0x00);
  for(j=0;j<6;j++) eeprom_append(dscr_vidpidver[j]);
  for(j=0;j<2;j++) eeprom_append(dscr_attrpow[j]);
  eeprom_append(0x1C);
  eeprom_append(0x00);
  for(j=0;j<2;j++) eeprom_append(dscr_usbver[j]);
  sofs = 0x80 + ee_ptr + 6;
  eeprom_append(sofs);
  eeprom_append(str1[0]);
  sofs += str1[0];
  eeprom_append(sofs);
  eeprom_append(str2[0]);
  sofs += str2[0];
  eeprom_append(sofs);
  eeprom_append(str3[0]);
  for(j=0;j<str1[0];j++) eeprom_append(str1[j]);
  for(j=0;j<str2[0];j++) eeprom_append(str2[j]);
  for(j=0;j<str3[0];j++) eeprom_append(str3[j]);
  for(j=0;j<4;j++) eeprom_append(dscr_strorder[j]);
  while(ee_ptr < 126) eeprom_append(0);
  eeprom[126] = ee_cksum&0xFF;
  eeprom[127] = (ee_cksum>>8)&0xFF;
}