From: travisutk Date: Tue, 9 Jun 2009 22:08:35 +0000 (+0000) Subject: Chipcon support is coming along. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=7e6962f68870771eafca05e8401a7cfeea132a3f;hp=aa1ad64b8f1a87590c9a94d32a1561bca33e843c Chipcon support is coming along. All simple macros except instruction execution. Nothing has been tested; I'm still waiting on hardware. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@33 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/firmware/apps/Makefile b/firmware/apps/Makefile index 2c99c0d..7228f2c 100644 --- a/firmware/apps/Makefile +++ b/firmware/apps/Makefile @@ -10,14 +10,23 @@ GCCINC=-T ../ldscripts/161x.x CC=msp430-gcc -g -mmcu=$(mcu) -DGCC $(GCCINC) -I ../include -apps= monitor/monitor.c spi/spi.c i2c/i2c.c +apps= monitor/monitor.c spi/spi.c i2c/i2c.c chipcon/chipcon.c libs= ../lib/msp430f1612.c ../lib/command.c app=goodfet +all: $(app) + +goodfet.hex: goodfet + + install: $(app) $(BSL) -e -p $(app) $(BSL) -P $(app) -r $(app): $(app).c $(libs) $(apps) +$(app).hex: $(app) + msp430-objcopy goodfet -O ihex goodfet.hex +m4s: $(app).hex + msp430-objdump -D -m msp430 $(app).hex | m4s init erase: $(BSL) -e clean: diff --git a/firmware/apps/chipcon/chipcon.c b/firmware/apps/chipcon/chipcon.c new file mode 100644 index 0000000..2748a58 --- /dev/null +++ b/firmware/apps/chipcon/chipcon.c @@ -0,0 +1,305 @@ +//GoodFET ChipCon Debugging Application +//Handles basic I/O for the Chipcon 8051 debugging protocol. + +//Higher level left to client application. + +//This is like SPI, except that you read or write, not both. + +/** N.B. The READ verb performs a write of all (any) supplied data, + then reads a single byte reply from the target. The WRITE verb + only writes. +*/ + +//This is REALLY untested. + +#include "platform.h" +#include "command.h" +#include "chipcon.h" + +#include +#include +#include + + +/** Concerning clock rates, + the maximimum clock rates are defined on page 4 of the spec. + They vary, but are roughly 30MHz. Raising this clock rate might + allow for clock glitching, but the GoodFET isn't sufficient fast for that. + Perhaps a 200MHz ARM or an FPGA in the BadassFET? +*/ + +//Pins and I/O +//MISO and MOSI are the same pin, direction changes. +#define RST BIT0 +#define MOSI BIT2 +#define MISO BIT2 +#define SCK BIT3 + +//This could be more accurate. +//Does it ever need to be? +#define CCSPEED 0 +#define CCDELAY(x) delay(x) + +#define SETMOSI P5OUT|=MOSI +#define CLRMOSI P5OUT&=~MOSI +#define SETCLK P5OUT|=SCK +#define CLRCLK P5OUT&=~SCK +#define READMISO (P5IN&MISO?1:0) + +#define CCWRITE P5DIR|=MOSI +#define CCREAD P5DIR&=~MISO + +//! Set up the pins for CC mode. Does not init debugger. +unsigned char ccsetup(){ + P5OUT|=MOSI+SCK+RST; + P5DIR|=MOSI+SCK+RST; + //P5DIR&=~MISO; //MOSI is MISO +} + +//! Initialize the debugger +void ccdebuginit(){ + //Two positive debug clock pulses while !RST is low. + //Take RST low, pulse twice, then high. + P5OUT&=~SCK; + P5OUT&=~RST; + + //pulse twice + CCDELAY(CCSPEED); + P5OUT|=SCK; //up + CCDELAY(CCSPEED); + P5OUT&=~SCK; //down + CCDELAY(CCSPEED); + P5OUT|=SCK; //up + CCDELAY(CCSPEED); + P5OUT&=~SCK; //down + + //Raise !RST. + P5OUT|=RST; +} + +//! Read and write a CC bit. +unsigned char cctrans8(unsigned char byte){ + unsigned int 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) + SETMOSI; + else + CLRMOSI; + byte <<= 1; + + /* half a clock cycle before leading/rising edge */ + CCDELAY(CCSPEED/2); + SETCLK; + + /* half a clock cycle before trailing/falling edge */ + CCDELAY(CCSPEED/2); + + /* read MISO on trailing edge */ + byte |= READMISO; + CLRCLK; + } + + return byte; +} + +//! Send a command from txbytes. +void cccmd(unsigned char len){ + unsigned char i; + CCWRITE; + for(i=0;i