--- /dev/null
+/*! \file avr.c
+ \author Travis Goodspeed
+ \brief AVR SPI Programmer
+*/
+
+#include "platform.h"
+#include "command.h"
+
+#include <signal.h>
+#include <io.h>
+#include <iomacros.h>
+
+#include "avr.h"
+
+//! Setup the AVR pins.
+void avrsetup(){
+ spisetup();
+}
+
+//! Initialized an attached AVR.
+void avrconnect(){
+ register int i;
+ avrsetup();//set I/O pins
+
+ //Pulse !RST (SS) at least twice while CLK is low.
+ CLRSS;
+ CLRCLK;
+
+ for(i=0;i<5;i++){
+ SETSS;
+ CLRSS;
+ }
+
+ //Enable programming
+ avr_prgen();
+}
+
+//! Perform a 4-byte exchange.
+u8 avrexchange(u8 a, u8 b, u8 c, u8 d){
+ spitrans8(a);
+ spitrans8(b);
+ if(spitrans8(c)!=b){
+ debugstr("AVR sync error, b not returned as c.");
+ }
+ spitrans8(c);
+ return spitrans8(d);
+}
+
+//! Enable AVR programming mode.
+void avr_prgen(){
+ avrexchange(0xac, 0x53, 0, 0);
+}
+
+//! Read AVR device code.
+u8 avr_devicecode(){
+ return avrexchange(0x30, //Read signature byte
+ 0x00,
+ 0x00, //&0x03 is sig adr
+ 0x00 //don't care.
+ );
+}
+
+//! Handles an AVR command.
+void avrhandle(unsigned char app,
+ unsigned char verb,
+ unsigned long len){
+ unsigned long i;
+
+
+ switch(verb){
+ case READ:
+ case WRITE:
+ for(i=0;i<len;i++)
+ cmddata[i]=spitrans8(cmddata[i]);
+ txdata(app,verb,len);
+ break;
+ case SETUP:
+ avrsetup();
+ txdata(app,verb,0);
+ break;
+ case START:
+ avrconnect();
+ txdata(app,verb,0);
+ break;
+ case PEEK:
+ case POKE:
+ default:
+ debugstr("Verb unimplemented in AVR application.");
+ txdata(app,NOK,0);
+ break;
+ }
+}
+
--- /dev/null
+/*! \file avr.h
+ \author Travis Goodspeed
+ \brief AVR SPI Programmer
+*/
+
+#include "spi.h"
+
+//! Setup the AVR pins.
+void avrsetup();
+
+//! Initialized an attached AVR.
+void avrconnect();
+
+//! Enable AVR programming mode.
+void avr_prgen();
+//! Read AVR device code.
+u8 avr_devicecode();
+
+
+//Command codes.
+//! Performa chip erase.
+#define AVR_ERASE 0xF0
+//! Fetch RDY/!BSY byte.
+#define AVR_RDYBSY 0xF1
+
+//! Read Program Memory
+#define AVR_PEEKPGM 0x80
+//! Read EEPROM
+#define AVR_PEEKEEPROM 0x81
+//! Read lock bits.
+#define AVR_PEEKLOCK 0x82
+//! Read signature.
+#define AVR_PEEKSIG 0x83
+//! Read fuse bits.
+#define AVR_READFUSES 0x84
+//! Read calibration byte.
+#define AVR_READCAL 0x85
\brief Command codes and buffers.
*/
-//! Global data buffer.
+
+//Types
+#define u8 unsigned char
+#define u16 unsigned int
+#define u32 unsigned long
+
#ifndef CMDDATALEN
#define CMDDATALEN 0x204
#endif
+//! Global data buffer.
extern unsigned char cmddata[CMDDATALEN];
extern unsigned char silent;