2 # GoodFET SPI and SPIFlash Client Library
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
6 # This code is being rewritten and refactored. You've been warned!
8 import sys, time, string, cStringIO, struct, glob, serial, os;
10 from GoodFET import GoodFET;
12 class GoodFETAVR(GoodFET):
14 AVRVendors={0x1E: "Atmel",
18 #List from avr910.asm and other sources.
19 #More devices at http://avr.fenceline.de/device_data.html
49 """Move the FET into the SPI application."""
50 self.writecmd(self.AVRAPP,0x10,0,self.data); #SPI/SETUP
53 """Exchange data by AVR.
54 Input should probably be 4 bytes."""
56 self.writecmd(self.AVRAPP,0x00,len(data),data);
60 """Start the connection."""
61 self.writecmd(self.AVRAPP,0x20,0,None);
63 """Erase the target chip."""
64 self.writecmd(self.AVRAPP,0xF0,0,None);
66 """Read the target's lockbits."""
67 self.writecmd(self.AVRAPP,0x82,0,None);
68 return ord(self.data[0]);
69 def eeprompeek(self, adr):
70 """Read a byte of the target's EEPROM."""
71 self.writecmd(self.AVRAPP,0x81 ,2,
72 [ (adr&0xFF), (adr>>8)]
73 );#little-endian address
74 return ord(self.data[0]);
75 def eeprompoke(self, adr, val):
76 """Write a byte of the target's EEPROM."""
77 self.writecmd(self.AVRAPP,0x91 ,3,
78 [ (adr&0xFF), (adr>>8), val]
79 );#little-endian address
80 return ord(self.data[0]);
83 """Return an identifying string."""
84 self.writecmd(self.AVRAPP,0x83,0, None);
85 vendor=self.AVRVendors.get(ord(self.data[0]));
86 deviceid=(ord(self.data[1])<<8)+ord(self.data[2]);
87 device=self.AVRDevices.get(deviceid);
89 #Return hex if device is unknown.
90 #They are similar enough that it needn't be known.
92 device=("0x%04x" % deviceid);