Rearranging firmware for use with Doxygen.
[goodfet] / firmware / apps / monitor / monitor.c
1 /*! \file monitor.c
2   \author Travis Goodspeed
3   
4   This is an implementation of the SPI protocol
5   for the GoodFET project.
6 */
7
8 #include "command.h"
9 #include "platform.h"
10 #include "monitor.h"
11
12 //! Handles a monitor command.
13 void monitorhandle(unsigned char app,
14                    unsigned char verb,
15                    unsigned char len){
16   switch(verb){
17   case PEEK:
18     cmddata[0]=memorybyte[cmddataword[0]];
19     txdata(app,verb,1);
20     break;
21   case POKE:
22     //Todo, make word or byte.
23     memorybyte[cmddataword[0]]=cmddata[2];
24     cmddata[0]=memorybyte[cmddataword[0]];
25     txdata(app,verb,1);
26     break;
27   case MONITOR_CHANGE_BAUD:
28     //This command, and ONLY this command, does not reply.
29     setbaud(cmddata[0]);
30     //txdata(app,verb,0);
31     break;
32   case MONITOR_RAM_PATTERN:
33     monitor_ram_pattern();//reboots, will never return
34     break;
35   case MONITOR_RAM_DEPTH:
36     cmddataword[0]=monitor_ram_depth();
37     txdata(app,verb,2);
38     break;
39   case MONITOR_DIR:
40     P5DIR=cmddata[0];
41     txdata(app,verb,1);
42     break;
43   case MONITOR_IN:
44     cmddata[0]=P5IN;
45     txdata(app,verb,1);
46     break;
47   case MONITOR_OUT:
48     P5OUT=cmddata[0];
49     txdata(app,verb,1);
50     break;
51   }
52 }
53
54 //! Overwrite all of RAM with 0xBEEF, then reboot.
55 void monitor_ram_pattern(){
56   register int *a;
57   
58   //Wipe all of ram.
59   for(a=(int*)0x1100;a<(int*)0x2500;a++){//TODO get these from the linker.
60     *((int*)a) = 0xBEEF;
61   }
62   txdata(0x00,0x90,0);
63   
64   //Reboot
65   asm("br &0xfffe");
66 }
67
68 //! Return the number of contiguous bytes 0xBEEF, to measure RAM usage.
69 unsigned int monitor_ram_depth(){
70   register int a;
71   register int count=0;
72   for(a=0x1100;a<0x2500;a+=2)
73     if(*((int*)a)==0xBEEF) count+=2;
74   
75   return count;
76 }