From c63fa4693820603a0444cc323ca34ad0b8fa9791 Mon Sep 17 00:00:00 2001 From: travisutk Date: Tue, 24 Nov 2009 11:57:39 +0000 Subject: [PATCH] GLITCH application is coming together. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@239 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- firmware/apps/avr/avr.c | 2 +- firmware/apps/glitch/glitch.c | 53 ++++++++++++++++++++++++++++++++--- firmware/goodfet.c | 3 ++ firmware/include/apps.h | 1 + firmware/include/glitch.h | 20 +++++++++++++ 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/firmware/apps/avr/avr.c b/firmware/apps/avr/avr.c index f1fe5b7..c9d0b94 100644 --- a/firmware/apps/avr/avr.c +++ b/firmware/apps/avr/avr.c @@ -70,7 +70,7 @@ u8 avrexchange(u8 a, u8 b, u8 c, u8 d){ avrtrans8(a); avrtrans8(b); if(avrtrans8(c)!=b){ - debugstr("AVR sync error, b not returned as c."); + //debugstr("AVR sync error, b not returned as c."); //Reconnect here? } return avrtrans8(d); diff --git a/firmware/apps/glitch/glitch.c b/firmware/apps/glitch/glitch.c index 1e7330d..e125544 100644 --- a/firmware/apps/glitch/glitch.c +++ b/firmware/apps/glitch/glitch.c @@ -28,15 +28,60 @@ void glitchsetup(){ //! Setup analog chain for glitching. void glitchsetupdac(){ -#ifdef DAC12IR + glitchvoltages(glitchL,glitchH); +} + + +u16 glitchH=0xfff, glitchL=0xfff, + glitchstate, glitchcount; + +//! Glitch an application. +void glitchapp(u8 app){ + debugstr("That app is not yet supported."); +} +//! Set glitching voltages. +void glitchvoltages(u16 low, u16 high){ int i; + glitchH=high; + glitchL=low; + + + #ifdef DAC12IR ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref on // Delay here for reference to settle. for(i=0;i!=0xFFFF;i++) asm("nop"); DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1 // 1.0V 0x0666, 2.5V 0x0FFF - DAC12_0DAT = 0x0FFF; + DAC12_0DAT = high; //DAC12_0DAT = 0x0880; - //__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 -#endif + #endif +} +//! Set glitching rate. +void glitchrate(u16 rate){ + glitchcount=rate; +} + + +//! Handles a monitor command. +void glitchhandle(unsigned char app, + unsigned char verb, + unsigned long len){ + switch(verb){ + case GLITCHVOLTAGES: + glitchvoltages(cmddataword[0], + cmddataword[1]); + txdata(app,verb,0); + break; + case GLITCHRATE: + glitchrate(cmddataword[0]); + txdata(app,verb,0); + break; + case START: + case STOP: + case GLITCHAPP: + case GLITCHVERB: + default: + debugstr("Unknown glitching verb."); + txdata(app,NOK,0); + } } diff --git a/firmware/goodfet.c b/firmware/goodfet.c index 8dea02e..b08313f 100644 --- a/firmware/goodfet.c +++ b/firmware/goodfet.c @@ -39,6 +39,9 @@ void handle(unsigned char app, unsigned long len){ //debugstr("GoodFET"); switch(app){ + case GLITCH: + glitchhandle(app,verb,len); + break; case MONITOR: monitorhandle(app,verb,len); break; diff --git a/firmware/include/apps.h b/firmware/include/apps.h index b3989c6..ddb8a0b 100644 --- a/firmware/include/apps.h +++ b/firmware/include/apps.h @@ -13,5 +13,6 @@ #define AVR 0x32 #define OCT 0x70 +#define GLITCH 0x71 #define DEBUGAPP 0xFF diff --git a/firmware/include/glitch.h b/firmware/include/glitch.h index de3d4a8..6f30d6d 100644 --- a/firmware/include/glitch.h +++ b/firmware/include/glitch.h @@ -7,7 +7,27 @@ #include #include +//Command codes +#define GLITCHAPP 0x80 +#define GLITCHVERB 0x81 +#define GLITCHVOLTAGES 0x90 +#define GLITCHRATE 0x91 + //! Disable glitch state at init. void glitchsetup(); //! Setup analog chain for glitching. void glitchsetupdac(); + +extern u16 glitchH, glitchL, glitchstate, glitchcount; + +//! Glitch an application. +void glitchapp(u8 app); +//! Set glitching voltages. +void glitchvoltages(u16 low, u16 high); +//! Set glitching rate. +void glitchrate(u16 rate); + +//! Handles a monitor command. +void glitchhandle(unsigned char app, + unsigned char verb, + unsigned long len); -- 2.20.1