Clear P2SEL to disable XIN on MSP430F2274.
[goodfet] / firmware / apps / plugins / ps2.c
1 /*! \file glitch.c
2   \author Travis Goodspeed
3   \brief PS2 Timing Monitor for GoodFET
4   
5   This module spies on PS/2.  For now, it just reports the
6   inter-character timing information.
7 */
8
9 #include "platform.h"
10 #include "command.h"
11 #include "ps2.h"
12 #include "jtag.h"
13
14 u32 mclock=0;
15 u32 clock=0;
16
17 // Timer A0 interrupt service routine
18 interrupt(TIMERA0_VECTOR) Timer_A (void)
19 {
20   if(!clock++)
21     mclock++;
22   return;
23 }
24
25
26
27 /** Pins (Clk, Dat)
28     TDI P5.1
29     TDO P5.2
30 */
31
32 // This is just a plugin for now.
33 #define ps2handle pluginhandle
34
35 u32 oldclock=0;
36 //! Handles a monitor command.
37 int ps2handle(unsigned char app,
38               unsigned char verb,
39               unsigned int len){
40   
41   switch(verb){
42   case START:
43     WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
44     TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
45     CCTL0 = CCIE;                         // CCR0 interrupt enabled
46     CCR0 = 0x100; //clock divider
47     TACTL |= MC_3;
48     _EINT();                              // Enable interrupts 
49     
50     
51     P5DIR&=~(TDI+TDO);//input mode
52     P5OUT=0; // pull down
53     
54     debugstr("Waiting for a keypress.");
55     //Wait for a keypress.
56     
57     while(1){
58       //Debounce the 1s polling
59       while((P5IN&TDI && P5IN&TDO))
60         while((P5IN&TDI));// && P5IN&TDO));
61       
62       //Transmit the data only if it is new.
63       if((clock-oldclock)>0x100){
64         cmddatalong[0]=clock;//-oldclock;
65         cmddatalong[0]-=oldclock;
66         oldclock=clock;
67         
68         txdata(app,verb,4);
69       }
70     }
71     break;
72   case STOP:
73   default:
74     debugstr("Unknown ps2 verb.");
75     txdata(app,NOK,0);
76   }
77 }