Moving CCSPI reflexive jamming to its own channel.
[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 //! Handles a monitor command.
15 void ps2_handle_fn( uint8_t const app,
16                                         uint8_t const verb,
17                                         uint32_t const len);
18
19
20 // define the ps2 app's app_t
21 app_t const ps2_app = {
22
23         /* app number */
24         PS2,
25
26         /* handle fn */
27         ps2_handle_fn,
28
29         /* name */
30         "PS2",
31
32         /* desc */
33         "\tThe PS2 app spies on PS/2.  For now, it just reports the\n"
34         "\tinter-character timing information.\n"
35 };
36
37
38 u32 mclock=0;
39 u32 clock=0;
40
41 // Timer A0 interrupt service routine
42 interrupt(TIMERA0_VECTOR) Timer_A (void)
43 {
44   if(!clock++)
45     mclock++;
46   return;
47 }
48
49
50
51 /** Pins (Clk, Dat)
52     TDI P5.1
53     TDO P5.2
54 */
55
56 u32 oldclock=0;
57 //! Handles a monitor command.
58 void ps2_handle_fn( uint8_t const app,
59                                         uint8_t const verb,
60                                         uint32_t const len)
61 {
62   switch(verb){
63   case START:
64     WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
65     TACTL = TASSEL1 + TACLR;              // SMCLK, clear TAR
66     CCTL0 = CCIE;                         // CCR0 interrupt enabled
67     CCR0 = 0x100; //clock divider
68     TACTL |= MC_3;
69     _EINT();                              // Enable interrupts 
70     
71     
72     P5DIR&=~(TDI+TDO);//input mode
73     P5OUT=0; // pull down
74     
75     debugstr("Waiting for a keypress.");
76     //Wait for a keypress.
77     
78     while(1){
79       //Debounce the 1s polling
80       while((P5IN&TDI && P5IN&TDO))
81         while((P5IN&TDI));// && P5IN&TDO));
82       
83       //Transmit the data only if it is new.
84       if((clock-oldclock)>0x100){
85         cmddatalong[0]=clock;//-oldclock;
86         cmddatalong[0]-=oldclock;
87         oldclock=clock;
88         
89         txdata(app,verb,4);
90       }
91     }
92     break;
93   case STOP:
94   default:
95     debugstr("Unknown ps2 verb.");
96     txdata(app,NOK,0);
97   }
98 }