From: travisutk Date: Wed, 7 Oct 2009 11:19:50 +0000 (+0000) Subject: AVR support getting better. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=2d6cf1279657fb40d818675dd22923744ef178fc;ds=sidebyside AVR support getting better. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@191 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/client/GoodFETAVR.py b/client/GoodFETAVR.py index 2d36a44..97724ca 100644 --- a/client/GoodFETAVR.py +++ b/client/GoodFETAVR.py @@ -11,6 +11,39 @@ from GoodFET import GoodFET; class GoodFETAVR(GoodFET): AVRAPP=0x32; + AVRVendors={0x1E: "Atmel", + 0x00: "Locked", + }; + + #List from avr910.asm and other sources. + #More devices at http://avr.fenceline.de/device_data.html + AVRDevices={ + 0x9003: "tiny10", + 0x9004: "tiny11", + 0x9005: "tiny12", + 0x9006: "tiny15", + 0x9007: "tiny13", + 0x930B: "tiny85", + + 0x9001: "S1200", + + 0x9101: "S1213", + 0x9102: "S2323", + 0x9105: "S2333", + 0x9103: "S2343", + + 0x9201: "S4414", + 0x9203: "S4433", + 0x9202: "S4434", + + 0x9301: "S8515", + 0x9303: "S8535", + + 0x9305: "mega83", + 0x9701: "mega103", + 0x9401: "mega161", + 0x9402: "mega163", + }; def setup(self): """Move the FET into the SPI application.""" @@ -30,4 +63,13 @@ class GoodFETAVR(GoodFET): def identstr(self): """Return an identifying string.""" self.writecmd(self.AVRAPP,0x83,0,None); - return "AVR(%02x)" % ord(self.data[0]); + vendor=self.AVRVendors.get(ord(self.data[0])); + deviceid=(ord(self.data[1])<<8)+ord(self.data[2]); + device=self.AVRDevices.get(deviceid); + + #Return hex if device is unknown. + #They are similar enough that it needn't be known. + if device==None: + device=("0x%04x" % deviceid); + + return device; diff --git a/firmware/apps/avr/avr.c b/firmware/apps/avr/avr.c index c86711d..707ab9e 100644 --- a/firmware/apps/avr/avr.c +++ b/firmware/apps/avr/avr.c @@ -19,8 +19,8 @@ void avrsetup(){ //! Initialized an attached AVR. void avrconnect(){ - register int i; - avrsetup();//set I/O pins + //set I/O pins + avrsetup(); //Pulse !RST (SS) at least twice while CLK is low. CLRCLK; @@ -36,7 +36,7 @@ void avrconnect(){ avr_prgen(); } -//! Read and write an SPI byte. +//! Read and write an SPI byte with delays. unsigned char avrtrans8(unsigned char byte){ register unsigned int bit; //This function came from the SPI Wikipedia article. @@ -68,8 +68,7 @@ u8 avrexchange(u8 a, u8 b, u8 c, u8 d){ avrtrans8(b); if(avrtrans8(c)!=b){ debugstr("AVR sync error, b not returned as c."); - }else{ - debugstr("Synced properly."); + //Reconnect here? } return avrtrans8(d); } @@ -80,11 +79,11 @@ void avr_prgen(){ } //! Read AVR device code. -u8 avr_devicecode(){ +u8 avr_sig(u8 i){ return avrexchange(0x30, //Read signature byte 0x00, - 0x00, //&0x03 is sig adr - 0x00 //don't care. + i&0x03, //sig adr + 0x00 //don't care. ); } @@ -110,8 +109,9 @@ void avrhandle(unsigned char app, avrconnect(); //no break here case AVR_PEEKSIG: - cmddata[0]=avr_devicecode(); - txdata(app,verb,1); + for(i=0;i<4;i++) + cmddata[i]=avr_sig(i); + txdata(app,verb,4); break; case PEEK: case POKE: diff --git a/firmware/include/avr.h b/firmware/include/avr.h index 75cd504..d715394 100644 --- a/firmware/include/avr.h +++ b/firmware/include/avr.h @@ -14,7 +14,7 @@ void avrconnect(); //! Enable AVR programming mode. void avr_prgen(); //! Read AVR device code. -u8 avr_devicecode(); +u8 avr_sig(u8 i); //Command codes.