1e7330dd49707df2876f56f94957ebdd58a3f534
[goodfet] / firmware / apps / glitch / glitch.c
1 /*! \file glitch.c
2   \author Travis Goodspeed
3   \brief Glitching Support for GoodFET20
4   
5   See the TI example MSP430x261x_dac12_01.c for usage of the DAC.
6   This module sends odd and insufficient voltages on P6.6/DAC0
7   in order to bypass security restrictions of target devices.
8 */
9
10 #include "platform.h"
11 #include "command.h"
12 #include "glitch.h"
13
14 //! Disable glitch state at init.
15 void glitchsetup(){
16 #ifdef DAC12IR
17   //Set GSEL high to disable glitching.
18
19   P5DIR|=0x80;
20   P6DIR|=0x40;  
21   
22   P5OUT|=0x80;
23   P6OUT|=0x40;
24   
25   glitchsetupdac();
26 #endif
27 }
28
29 //! Setup analog chain for glitching.
30 void glitchsetupdac(){
31 #ifdef DAC12IR
32   int i;
33   ADC12CTL0 = REF2_5V + REFON;                  // Internal 2.5V ref on
34   // Delay here for reference to settle.
35   for(i=0;i!=0xFFFF;i++) asm("nop");
36   DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
37   // 1.0V 0x0666, 2.5V 0x0FFF
38   DAC12_0DAT = 0x0FFF;
39   //DAC12_0DAT = 0x0880;
40   //__bis_SR_register(LPM0_bits + GIE);           // Enter LPM0
41 #endif 
42 }