#include <iomacros.h>
#include "avr.h"
-#include "glitch.h"
+//#include "glitch.h"
//! Setup the AVR pins.
void avrsetup(){
//! 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;
+ //delay(5);
SETSS;
CLRCLK;
- delay(10);
+ //delay(5);
CLRSS;
- delay(10);
+ //delay(5);
//Enable programming
avr_prgen();
}
//! Read and write an SPI byte with delays.
-unsigned char avrtrans8(unsigned char byte){
- register unsigned int bit;
+u8 avrtrans8(u8 byte){
+ register u16 bit;
//This function came from the SPI Wikipedia article.
//Minor alterations.
return avrexchange(0x20,a>>8,a&0xff,0);
}
+void avr_bulk_load(u16 start, u16 len, u8 *data) {
+ u16 adr;
+ for (adr = 0; adr < len; adr++) {
+ u16 a = adr + start;
+ avrexchange((adr & 1) ? 0x48 : 0x40,
+ a >> 9,
+ (a >> 1) & 0xff,
+ data[adr]);
+ }
+}
//! Handles an AVR command.
void avrhandle(unsigned char app,
unsigned long len){
unsigned long i;
unsigned int at;
- static u8 connected=0;
/*
if(!avr_isready() && connected)
avrsetup();
txdata(app,verb,0);
break;
- case START://returns device code
+ case START:
avrconnect();
- //no break here
+ txdata(app,verb,0);
+ break;//Used to fall through here.
+ case STOP:
+ SETSS;
+ txdata(app, verb, 0);
case AVR_PEEKSIG:
for(i=0;i<4;i++)
cmddata[i]=avr_sig(i);
cmddata[0]=avr_peekeeprom(cmddataword[0]);
txdata(app,verb,1);
break;
+ case AVR_BULKLOAD:
+ if (len < 3) {
+ debugstr("Length too short");
+ txdata(app, NOK, 0);
+ } else {
+ at = cmddataword[0];
+ avr_bulk_load(at, len - 2, cmddata + 2);
+ txdata(app, verb, 0);
+ }
+ break;
case PEEK:
//cmddata[0]=avr_peekflash(cmddataword[0]);
//txdata(app,verb,1);