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