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