X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Favr%2Favr.c;h=c5d192927889f94db13018e597337fa0a47bb90b;hp=0cc4c0da79842727fd70833ad4dba75b8321400d;hb=b8cf36028990c8152a6cea86d1e5d5ffed770ea8;hpb=3e4992b4d109f361b42abdda403471860edfeabf diff --git a/firmware/apps/avr/avr.c b/firmware/apps/avr/avr.c index 0cc4c0d..c5d1929 100644 --- a/firmware/apps/avr/avr.c +++ b/firmware/apps/avr/avr.c @@ -6,12 +6,30 @@ #include "platform.h" #include "command.h" -#include -#include -#include #include "avr.h" //#include "glitch.h" +// +//! Handles an AVR command. +void avr_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len); + +// define the jtag app's app_t +app_t const avr_app = { + + /* app number */ + XAVR, + + /* handle fn */ + avr_handle_fn, + + /* name */ + "AVR", + + /* desc */ + "\tThe AVR app adds support for debugging AVR based devices.\n" +}; //! Setup the AVR pins. void avrsetup(){ @@ -22,10 +40,10 @@ void avrsetup(){ void avrconnect(){ //set I/O pins avrsetup(); //Cut this? - + SETSS; //delay(50); - + //Pulse !RST (SS) at least twice while CLK is low. CLRCLK; CLRSS; @@ -36,7 +54,7 @@ void avrconnect(){ //delay(5); CLRSS; //delay(5); - + //Enable programming avr_prgen(); } @@ -46,7 +64,7 @@ u8 avrtrans8(u8 byte){ register u16 bit; //This function came from the SPI Wikipedia article. //Minor alterations. - + for (bit = 0; bit < 8; bit++) { /* write MOSI on trailing edge of previous clock */ if (byte & 0x80) @@ -54,16 +72,16 @@ u8 avrtrans8(u8 byte){ else CLRMOSI; byte <<= 1; - + delay(2); SETCLK; - + /* read MISO on trailing edge */ byte |= READMISO; delay(2); CLRCLK; } - + return byte; } @@ -142,17 +160,18 @@ void avr_bulk_load(u16 start, u16 len, u8 *data) { } //! Handles an AVR command. -void avrhandle(unsigned char app, - unsigned char verb, - unsigned long len){ - unsigned long i; +void avr_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len) +{ + unsigned long i, l; unsigned int at; - + /* if(!avr_isready() && connected) debugstr("AVR is not yet ready."); */ - + switch(verb){ case READ: case WRITE: @@ -209,16 +228,17 @@ void avrhandle(unsigned char app, //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. + l = len; + if(l>2){ + l=(cmddataword[1]);//always even. }else{ - len=1; + l=1; } - txhead(app,verb,len); - for(i=0;i