From: travisutk Date: Wed, 7 Oct 2009 08:19:42 +0000 (+0000) Subject: Refactoring, beginning AVR application. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=6dc88d2f1713d2bf9f2fabb5fbfb9f235a679b2f Refactoring, beginning AVR application. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@187 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/firmware/Makefile b/firmware/Makefile index d701b74..e4b021f 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -21,7 +21,7 @@ CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include $(CCEXTRA) #Define extra modules here. moreapps?= -apps= $(moreapps) apps/monitor/monitor.o apps/spi/spi.o apps/i2c/i2c.o apps/chipcon/chipcon.o apps/jtag/jtag.o apps/jtag/jtag430.o apps/jtag/jtag430x2.o +apps= $(moreapps) apps/monitor/monitor.o apps/spi/spi.o apps/i2c/i2c.o apps/chipcon/chipcon.o apps/jtag/jtag.o apps/jtag/jtag430.o apps/jtag/jtag430x2.o apps/avr/avr.o libs= lib/$(mcu).o lib/command.o apps/jtag/jtag430asm.o app= goodfet diff --git a/firmware/apps/jtag/jtag.c b/firmware/apps/jtag/jtag.c index 73a6750..6ef9315 100644 --- a/firmware/apps/jtag/jtag.c +++ b/firmware/apps/jtag/jtag.c @@ -59,7 +59,7 @@ unsigned long jtagtransn(unsigned long word, unsigned int bitcount){ unsigned int bit; //0x8000 - unsigned long high; + unsigned long high=0x8000; if(bitcount==20) high=0x80000; diff --git a/firmware/apps/jtag/jtag430.c b/firmware/apps/jtag/jtag430.c index d0b83cb..0d1fbfb 100644 --- a/firmware/apps/jtag/jtag430.c +++ b/firmware/apps/jtag/jtag430.c @@ -276,7 +276,6 @@ void jtag430_setinstrfetch(){ void jtag430handle(unsigned char app, unsigned char verb, unsigned long len){ - register char blocks; unsigned long at; unsigned int i, val; diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index f02d402..0985340 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -12,7 +12,7 @@ #include #include -#include +#include "spi.h" //This could be more accurate. //Does it ever need to be? @@ -115,28 +115,6 @@ void spiflash_peekblock(unsigned long adr, SETSS; //Raise !SS to end transaction. } -//! Write many blocks to the SPI Flash. -void spiflash_pokeblocks(unsigned long adr, - unsigned char *buf, - unsigned int len){ - long off=0;//offset of this block - int blen;//length of this block - SETSS; - spiflash_setstatus(0x02); - spiflash_wrten(); - - while(off0x100?0x100:len-off); - //write the block - spiflash_pokeblock(adr+off, - buf+off, - blen); - //add offset - off+=blen; - } -} - //! Read a block to a buffer. void spiflash_pokeblock(unsigned long adr, unsigned char *buf, @@ -168,6 +146,30 @@ void spiflash_pokeblock(unsigned long adr, } +//! Write many blocks to the SPI Flash. +void spiflash_pokeblocks(unsigned long adr, + unsigned char *buf, + unsigned int len){ + long off=0;//offset of this block + int blen;//length of this block + SETSS; + spiflash_setstatus(0x02); + spiflash_wrten(); + + while(off0x100?0x100:len-off); + //write the block + spiflash_pokeblock(adr+off, + buf+off, + blen); + //add offset + off+=blen; + } +} + + + //! Peek some blocks. void spiflash_peek(unsigned char app, unsigned char verb, diff --git a/firmware/goodfet.c b/firmware/goodfet.c index deb2991..8ff94b6 100644 --- a/firmware/goodfet.c +++ b/firmware/goodfet.c @@ -44,6 +44,9 @@ void handle(unsigned char app, case SPI: spihandle(app,verb,len); break; + case AVR: + avrhandle(app,verb,len); + break; case I2CAPP: i2chandle(app,verb,len); break; diff --git a/firmware/include/apps.h b/firmware/include/apps.h index 4835e14..b3989c6 100644 --- a/firmware/include/apps.h +++ b/firmware/include/apps.h @@ -10,6 +10,7 @@ #define JTAG430 0x11 #define CHIPCON 0x30 #define SIF 0x31 +#define AVR 0x32 #define OCT 0x70 diff --git a/firmware/include/chipcon.h b/firmware/include/chipcon.h index ece1e53..31f375d 100644 --- a/firmware/include/chipcon.h +++ b/firmware/include/chipcon.h @@ -40,3 +40,27 @@ void cc_resume(); //! Step an instruction void cc_step_instr(); + +//CHIPCON commands +#define CC_CHIP_ERASE 0x80 +#define CC_WR_CONFIG 0x81 +#define CC_RD_CONFIG 0x82 +#define CC_GET_PC 0x83 +#define CC_READ_STATUS 0x84 +#define CC_SET_HW_BRKPNT 0x85 +#define CC_HALT 0x86 +#define CC_RESUME 0x87 +#define CC_DEBUG_INSTR 0x88 +#define CC_STEP_INSTR 0x89 +#define CC_STEP_REPLACE 0x8a +#define CC_GET_CHIP_ID 0x8b +//CHIPCON macros +#define CC_READ_CODE_MEMORY 0x90 +#define CC_READ_XDATA_MEMORY 0x91 +#define CC_WRITE_XDATA_MEMORY 0x92 +#define CC_SET_PC 0x93 +#define CC_CLOCK_INIT 0x94 +#define CC_WRITE_FLASH_PAGE 0x95 +#define CC_READ_FLASH_PAGE 0x96 +#define CC_MASS_ERASE_FLASH 0x97 +#define CC_PROGRAM_FLASH 0x98 diff --git a/firmware/include/command.h b/firmware/include/command.h index f781e2c..88f0de2 100644 --- a/firmware/include/command.h +++ b/firmware/include/command.h @@ -46,34 +46,7 @@ extern unsigned char silent; #define MONITOR_SIZEBUF 0xC2 -//CHIPCON commands -#define CC_CHIP_ERASE 0x80 -#define CC_WR_CONFIG 0x81 -#define CC_RD_CONFIG 0x82 -#define CC_GET_PC 0x83 -#define CC_READ_STATUS 0x84 -#define CC_SET_HW_BRKPNT 0x85 -#define CC_HALT 0x86 -#define CC_RESUME 0x87 -#define CC_DEBUG_INSTR 0x88 -#define CC_STEP_INSTR 0x89 -#define CC_STEP_REPLACE 0x8a -#define CC_GET_CHIP_ID 0x8b -//CHIPCON macros -#define CC_READ_CODE_MEMORY 0x90 -#define CC_READ_XDATA_MEMORY 0x91 -#define CC_WRITE_XDATA_MEMORY 0x92 -#define CC_SET_PC 0x93 -#define CC_CLOCK_INIT 0x94 -#define CC_WRITE_FLASH_PAGE 0x95 -#define CC_READ_FLASH_PAGE 0x96 -#define CC_MASS_ERASE_FLASH 0x97 -#define CC_PROGRAM_FLASH 0x98 - -//JTAG commands -#define JTAG_IR_SHIFT 0x80 -#define JTAG_DR_SHIFT 0x81 -#define JTAG_DR_SHIFT20 0x91 + //SPI commands #define SPI_JEDEC 0x80 @@ -83,21 +56,6 @@ extern unsigned char silent; #define OCT_CMP 0x90 #define OCT_RES 0x91 -//JTAG430 commands -#define JTAG430_HALTCPU 0xA0 -#define JTAG430_RELEASECPU 0xA1 -#define JTAG430_SETINSTRFETCH 0xC1 -#define JTAG430_SETPC 0xC2 -#define JTAG430_WRITEMEM 0xE0 -#define JTAG430_WRITEFLASH 0xE1 -#define JTAG430_READMEM 0xE2 -#define JTAG430_ERASEFLASH 0xE3 -#define JTAG430_ERASECHECK 0xE4 -#define JTAG430_VERIFYMEM 0xE5 -#define JTAG430_BLOWFUSE 0xE6 -#define JTAG430_ISFUSEBLOWN 0xE7 -#define JTAG430_COREIP_ID 0xF0 -#define JTAG430_DEVICE_ID 0xF1 //! Handle a plugin, weak-linked to error. extern int pluginhandle(unsigned char app, @@ -150,4 +108,6 @@ void jtaghandle(unsigned char, unsigned char, unsigned long); void jtag430handle(unsigned char, unsigned char, unsigned long); void jtag430x2handle(unsigned char app, unsigned char verb, unsigned long len); - +void avrhandle(unsigned char app, + unsigned char verb, + unsigned long len); diff --git a/firmware/include/jtag.h b/firmware/include/jtag.h index 5dd5675..f08ec85 100644 --- a/firmware/include/jtag.h +++ b/firmware/include/jtag.h @@ -138,3 +138,26 @@ extern int savedtclk; unsigned int jtag430x2_syncpor(); //! Executes an MSP430X2 POR unsigned int jtag430x2_por(); + + +//JTAG commands +#define JTAG_IR_SHIFT 0x80 +#define JTAG_DR_SHIFT 0x81 +#define JTAG_DR_SHIFT20 0x91 + + +//JTAG430 commands +#define JTAG430_HALTCPU 0xA0 +#define JTAG430_RELEASECPU 0xA1 +#define JTAG430_SETINSTRFETCH 0xC1 +#define JTAG430_SETPC 0xC2 +#define JTAG430_WRITEMEM 0xE0 +#define JTAG430_WRITEFLASH 0xE1 +#define JTAG430_READMEM 0xE2 +#define JTAG430_ERASEFLASH 0xE3 +#define JTAG430_ERASECHECK 0xE4 +#define JTAG430_VERIFYMEM 0xE5 +#define JTAG430_BLOWFUSE 0xE6 +#define JTAG430_ISFUSEBLOWN 0xE7 +#define JTAG430_COREIP_ID 0xF0 +#define JTAG430_DEVICE_ID 0xF1 diff --git a/firmware/include/spi.h b/firmware/include/spi.h index c39766d..f5c0d8e 100644 --- a/firmware/include/spi.h +++ b/firmware/include/spi.h @@ -18,3 +18,20 @@ #define SETCLK P5OUT|=SCK #define CLRCLK P5OUT&=~SCK #define READMISO (P5IN&MISO?1:0) + +//! Set up the pins for SPI mode. +void spisetup(); + +//! Read and write an SPI byte. +unsigned char spitrans8(unsigned char byte); + +//! Read a block to a buffer. +void spiflash_peekblock(unsigned long adr, + unsigned char *buf, + unsigned int len); + + +//! Write many blocks to the SPI Flash. +void spiflash_pokeblocks(unsigned long adr, + unsigned char *buf, + unsigned int len);