Removed annoying debug message.
[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 #include "builddate.h"
10 #if (platform == tilaunchpad)
11 #include <setjmp.h>
12 extern jmp_buf warmstart;
13
14 #endif
15
16 #define MONITOR_APP
17
18 //! Handles a monitor command.
19 void monitor_handle_fn(uint8_t const app,
20                                            uint8_t const verb,
21                                            uint32_t const len);
22
23 //! Overwrite all of RAM with 0xBEEF, then reboot.
24 void monitor_ram_pattern();
25
26 //! Return the number of contiguous bytes 0xBEEF, to measure RAM usage.
27 unsigned int monitor_ram_depth();
28
29 //! Call a function by address.
30 int fncall(unsigned int adr);
31
32
33 // define the monitor app's app_t
34 app_t const monitor_app = {
35
36         /* app number */
37         MONITOR,
38
39         /* handle fn */
40         monitor_handle_fn,
41
42         /* name */
43         "Monitor",
44
45         /* desc */
46         "\tThe monitor app handles basic operations on the MSP430\n"
47         "\tsuch as peeking and poking memory, calling functions and\n"
48         "\tmanaging the baud rate.\n"
49 };
50
51
52 //! Handles a monitor command.
53 void monitor_handle_fn(uint8_t const app,
54                        uint8_t const verb,
55                        uint32_t const len)
56 {
57         int i;
58
59         switch(verb)
60         {
61         default:
62                 debugstr("ERROR: Command unsupported by debug monitor.");
63                 break;
64
65         case MONITOR_ECHO:
66           //Echo back the same buffer.
67           txdata(app,verb,len);
68           break;
69
70         case MONITOR_LIST_APPS:
71                 // transmit firmware build date
72                 txstring(app, verb, build_date);
73
74                 // transmit app descriptions
75                 for(i = 0; i < num_apps; i++)
76                 {
77                         txstring(app, verb, apps[i]->name);
78                         // if full list, then add in description
79                         if(cmddata[0])
80                                 txstring(app, verb, apps[i]->desc);
81                 }
82                 txdata(app, verb, 0);
83                 break;
84
85         case PEEK:
86           #ifdef MSP430
87                 cmddata[0]=memorybyte[cmddataword[0]];
88           #else
89                 debugstr("Monitor peeks are unsupported on this platform.");
90                 debughex(cmddataword[0]);
91                 cmddata[0]=0x00;
92           #endif
93                 txdata(app,verb,1);
94                 break;
95
96         case POKE:
97           #ifdef MSP430
98                 //Todo, make word or byte.
99                 memorybyte[cmddataword[0]] = cmddata[2];
100                 cmddata[0] = memorybyte[cmddataword[0]];
101           #else
102                 debugstr("Monitor pokes are unsupported on this platform.");
103                 debughex(cmddataword[0]);
104                 cmddata[0]=0x00;
105           #endif
106                 txdata(app,verb,1);
107                 break;
108
109         case CALL:
110                 //Set the program counter to cmdword[0];
111                 cmddataword[0]=fncall(cmddataword[0]);
112                 txdata(app,verb,2);
113                 break;
114
115         case EXEC:
116                 //Execute the argument as code from RAM.
117                 cmddataword[0]=fncall((u16) cmddataword);
118                 txdata(app,verb,2);
119                 break;
120
121         case MONITOR_SIZEBUF:
122                 //TODO make the data length target-specific, varying by ram.
123                 cmddataword[0]=0x100;
124                 txdata(app,verb,2);
125                 break;
126
127         case MONITOR_CHANGE_BAUD:
128                 //This command, and ONLY this command, does not reply.
129                 setbaud(cmddata[0]);
130                 //txdata(app,verb,0);
131                 break;
132
133         case MONITOR_RAM_PATTERN:
134                 monitor_ram_pattern();//reboots, will never return
135                 break;
136
137         case MONITOR_RAM_DEPTH:
138                 cmddataword[0]=monitor_ram_depth();
139                 txdata(app,verb,2);
140                 break;
141
142         case MONITOR_DIR:
143         case MONITOR_IN:
144         case MONITOR_OUT:
145           debugstr("Command deprecated.");
146           txdata(app,verb,1);
147           break;
148                 
149         case MONITOR_SILENT:
150                 silent=cmddata[0];
151                 txdata(app,verb,1);
152                 break;
153
154         case MONITOR_CONNECTED:
155           #ifdef MSP430
156           msp430_init_dco_done();
157           #endif
158           txdata(app,verb,0);
159           break;
160         }
161 }
162
163 //! Overwrite all of RAM with 0xBEEF, then reboot.
164 void monitor_ram_pattern()
165 {
166         register int *a;
167
168         //Wipe all of ram.
169         for(a=(int*)0x1100;a<(int*)0x2500;a++)
170         {//TODO get these from the linker.
171                 *((int*)a) = 0xBEEF;
172         }
173         txdata(0x00,0x90,0);
174
175 #if (platform == tilaunchpad)
176         longjmp(warmstart,1);
177 #else
178         //Reboot
179 #ifdef MSP430
180         asm("br &0xfffe");
181 #endif
182 #endif
183 }
184
185 //! Return the number of contiguous bytes 0xBEEF, to measure RAM usage.
186 unsigned int monitor_ram_depth()
187 {
188         register int a;
189         register int count=0;
190         for(a=0x1100;a<0x2500;a+=2)
191                 if(*((int*)a)==0xBEEF) count+=2;
192
193         return count;
194 }
195
196 //! Call a function by address.
197 int fncall(unsigned int adr)
198 {
199         int (*machfn)() = 0;
200         machfn = (int (*)()) adr;
201         return machfn();
202 }
203
204