Moved header transmission to txhead, about to switch to 16-bit length field.
[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_SIZEBUF:
26     //TODO make the data length target-specific, varying by ram.
27     cmddataword[0]=0x100;
28     txdata(app,verb,2);
29     break;
30   case MONITOR_CHANGE_BAUD:
31     //This command, and ONLY this command, does not reply.
32     setbaud(cmddata[0]);
33     //txdata(app,verb,0);
34     break;
35   case MONITOR_RAM_PATTERN:
36     monitor_ram_pattern();//reboots, will never return
37     break;
38   case MONITOR_RAM_DEPTH:
39     cmddataword[0]=monitor_ram_depth();
40     txdata(app,verb,2);
41     break;
42   case MONITOR_DIR:
43     P5DIR=cmddata[0];
44     txdata(app,verb,1);
45     break;
46   case MONITOR_IN:
47     cmddata[0]=P5IN;
48     txdata(app,verb,1);
49     break;
50   case MONITOR_OUT:
51     P5OUT=cmddata[0];
52     txdata(app,verb,1);
53     break;
54   case MONITOR_SILENT:
55     silent=cmddata[0];
56     txdata(app,verb,1);
57     break;
58   }
59 }
60
61 //! Overwrite all of RAM with 0xBEEF, then reboot.
62 void monitor_ram_pattern(){
63   register int *a;
64   
65   //Wipe all of ram.
66   for(a=(int*)0x1100;a<(int*)0x2500;a++){//TODO get these from the linker.
67     *((int*)a) = 0xBEEF;
68   }
69   txdata(0x00,0x90,0);
70   
71   //Reboot
72   asm("br &0xfffe");
73 }
74
75 //! Return the number of contiguous bytes 0xBEEF, to measure RAM usage.
76 unsigned int monitor_ram_depth(){
77   register int a;
78   register int count=0;
79   for(a=0x1100;a<0x2500;a+=2)
80     if(*((int*)a)==0xBEEF) count+=2;
81   
82   return count;
83 }