projects
/
goodfet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
still working
[goodfet]
/
firmware
/
apps
/
avr
/
avr.c
diff --git
a/firmware/apps/avr/avr.c
b/firmware/apps/avr/avr.c
index
fdef1aa
..
9531563
100644
(file)
--- a/
firmware/apps/avr/avr.c
+++ b/
firmware/apps/avr/avr.c
@@
-11,6
+11,7
@@
#include <iomacros.h>
#include "avr.h"
#include <iomacros.h>
#include "avr.h"
+//#include "glitch.h"
//! Setup the AVR pins.
void avrsetup(){
//! Setup the AVR pins.
void avrsetup(){
@@
-20,25
+21,29
@@
void avrsetup(){
//! Initialized an attached AVR.
void avrconnect(){
//set I/O pins
//! Initialized an attached AVR.
void avrconnect(){
//set I/O pins
- avrsetup();
+ avrsetup(); //Cut this?
+
+ SETSS;
+ //delay(50);
//Pulse !RST (SS) at least twice while CLK is low.
CLRCLK;
CLRSS;
//Pulse !RST (SS) at least twice while CLK is low.
CLRCLK;
CLRSS;
+ //delay(5);
SETSS;
CLRCLK;
SETSS;
CLRCLK;
-
delay(500
);
+
//delay(5
);
CLRSS;
CLRSS;
-
delay(500
);
+
//delay(5
);
//Enable programming
avr_prgen();
}
//! Read and write an SPI byte with delays.
//Enable programming
avr_prgen();
}
//! Read and write an SPI byte with delays.
-u
nsigned char avrtrans8(unsigned char
byte){
- register u
nsigned int
bit;
+u
8 avrtrans8(u8
byte){
+ register u
16
bit;
//This function came from the SPI Wikipedia article.
//Minor alterations.
//This function came from the SPI Wikipedia article.
//Minor alterations.
@@
-67,7
+72,7
@@
u8 avrexchange(u8 a, u8 b, u8 c, u8 d){
avrtrans8(a);
avrtrans8(b);
if(avrtrans8(c)!=b){
avrtrans8(a);
avrtrans8(b);
if(avrtrans8(c)!=b){
- debugstr("AVR sync error, b not returned as c.");
+
//
debugstr("AVR sync error, b not returned as c.");
//Reconnect here?
}
return avrtrans8(d);
//Reconnect here?
}
return avrtrans8(d);
@@
-101,6
+106,11
@@
void avr_erase(){
u8 avr_lockbits(){
return avrexchange(0x58, 0, 0, 0);
}
u8 avr_lockbits(){
return avrexchange(0x58, 0, 0, 0);
}
+//! Write lock bits.
+void avr_setlock(u8 bits){
+ avrexchange(0xAC,0xE0,0x00,
+ bits);
+}
//! Read a byte of EEPROM.
u8 avr_peekeeprom(u16 adr){
//! Read a byte of EEPROM.
u8 avr_peekeeprom(u16 adr){
@@
-111,6
+121,14
@@
u8 avr_pokeeeprom(u16 adr, u8 val){
return avrexchange(0xC0, adr>>8, adr&0xFF, val);
}
return avrexchange(0xC0, adr>>8, adr&0xFF, val);
}
+//! Read a byte of Flash
+u8 avr_peekflash(u16 adr){
+ u16 a=adr>>1;
+ if(adr&1) //high byte
+ return avrexchange(0x28,a>>8,a&0xff,0);
+ else //low byte
+ return avrexchange(0x20,a>>8,a&0xff,0);
+}
//! Handles an AVR command.
//! Handles an AVR command.
@@
-118,10
+136,12
@@
void avrhandle(unsigned char app,
unsigned char verb,
unsigned long len){
unsigned long i;
unsigned char verb,
unsigned long len){
unsigned long i;
-
static u8 connected=0
;
+
unsigned int at
;
+ /*
if(!avr_isready() && connected)
debugstr("AVR is not yet ready.");
if(!avr_isready() && connected)
debugstr("AVR is not yet ready.");
+ */
switch(verb){
case READ:
switch(verb){
case READ:
@@
-134,9
+154,10
@@
void avrhandle(unsigned char app,
avrsetup();
txdata(app,verb,0);
break;
avrsetup();
txdata(app,verb,0);
break;
- case START:
//returns device code
+ case START:
avrconnect();
avrconnect();
- //no break here
+ txdata(app,verb,0);
+ break;//Used to fall through here.
case AVR_PEEKSIG:
for(i=0;i<4;i++)
cmddata[i]=avr_sig(i);
case AVR_PEEKSIG:
for(i=0;i<4;i++)
cmddata[i]=avr_sig(i);
@@
-150,7
+171,10
@@
void avrhandle(unsigned char app,
cmddata[0]=avr_lockbits();
txdata(app,verb,1);
break;
cmddata[0]=avr_lockbits();
txdata(app,verb,1);
break;
-
+ case AVR_POKELOCK:
+ avr_setlock(cmddata[0]);
+ txdata(app,verb,0);
+ break;
case AVR_POKEEEPROM:
avr_pokeeeprom(cmddataword[0], cmddata[2]);
//no break here.
case AVR_POKEEEPROM:
avr_pokeeeprom(cmddataword[0], cmddata[2]);
//no break here.
@@
-159,6
+183,22
@@
void avrhandle(unsigned char app,
txdata(app,verb,1);
break;
case PEEK:
txdata(app,verb,1);
break;
case PEEK:
+ //cmddata[0]=avr_peekflash(cmddataword[0]);
+ //txdata(app,verb,1);
+ at=cmddataword[0];
+
+ //Fetch large blocks for bulk fetches,
+ //small blocks for individual peeks.
+ if(len>2){
+ len=(cmddataword[1]);//always even.
+ }else{
+ len=1;
+ }
+ txhead(app,verb,len);
+ for(i=0;i<len;i++){
+ serial_tx(avr_peekflash(at++));
+ }
+ break;
case POKE:
default:
debugstr("Verb unimplemented in AVR application.");
case POKE:
default:
debugstr("Verb unimplemented in AVR application.");