2 \author Travis Goodspeed
3 \brief AVR SPI Programmer
15 //! Setup the AVR pins.
20 //! Initialized an attached AVR.
23 avrsetup();//set I/O pins
25 //Pulse !RST (SS) at least twice while CLK is low.
39 //! Read and write an SPI byte.
40 unsigned char avrtrans8(unsigned char byte){
41 register unsigned int bit;
42 //This function came from the SPI Wikipedia article.
45 for (bit = 0; bit < 8; bit++) {
46 /* write MOSI on trailing edge of previous clock */
56 /* read MISO on trailing edge */
65 //! Perform a 4-byte exchange.
66 u8 avrexchange(u8 a, u8 b, u8 c, u8 d){
70 debugstr("AVR sync error, b not returned as c.");
72 debugstr("Synced properly.");
77 //! Enable AVR programming mode.
79 avrexchange(0xAC, 0x53, 0, 0);
82 //! Read AVR device code.
84 return avrexchange(0x30, //Read signature byte
86 0x00, //&0x03 is sig adr
91 //! Handles an AVR command.
92 void avrhandle(unsigned char app,
102 cmddata[i]=spitrans8(cmddata[i]);
103 txdata(app,verb,len);
109 case START://returns device code
113 cmddata[0]=avr_devicecode();
119 debugstr("Verb unimplemented in AVR application.");