-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_stack.c
446 lines (377 loc) · 11.5 KB
/
debug_stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#include "brtos/includes/BRTOS.h"
#include "drivers/serial.h"
//#include "BRTOS.h"
//#include "serial.h"
void Transmite_Uptime(void);
void Transmite_RAM_Ocupada(void);
void Transmite_Task_Stacks(void);
const CHAR8 UptimeText[] = "UPTIME: ";
const CHAR8 CPULoadText[] = "CPU LOAD: ";
const CHAR8 CPU100Text[] = "100 %";
const CHAR8 IdleTaskText[] = "Idle Task: ";
const CHAR8 TaskStackText[] = "TASK STACK:";
const CHAR8 MemoryText[] = "MEMORY: ";
const CHAR8 OfText[] = " of ";
/*
const rom CHAR8 UptimeText[] = "UPTIME: ";
const rom CHAR8 CPULoadText[] = "CPU LOAD: ";
const rom CHAR8 CPU100Text[] = "100 %";
const rom CHAR8 IdleTaskText[] = "Idle Task: ";
const rom CHAR8 TaskStackText[] = "TASK STACK:";
const rom CHAR8 MemoryText[] = "MEMORY: ";
const rom CHAR8 OfText[] = " of ";
*/
void Transmite_Uptime(void)
{
INT8U caracter = 0;
OSTime* Uptime;
OSDate* UpDate;
OSEnterCritical();
Uptime = OSUptime();
UpDate = OSUpDate();
OSExitCritical();
/*
strcpypgm2ram (BufferText, (const rom char far *)UptimeText);
*/
Serial_Envia_Frase(BufferText);
// S� funciona at� 99 dias
if(UpDate->RTC_Day > 0)
{
if(UpDate->RTC_Day > 9)
{
caracter = (UpDate->RTC_Day / 10) + 48;
Serial_Envia_Caracter(caracter);
}
caracter = (UpDate->RTC_Day%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter('d');
Serial_Envia_Caracter(' ');
}
if(Uptime->RTC_Hour > 9)
{
caracter = (Uptime->RTC_Hour / 10) + 48;
Serial_Envia_Caracter(caracter);
}
caracter = (Uptime->RTC_Hour%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter('h');
Serial_Envia_Caracter(' ');
if(Uptime->RTC_Minute > 9)
{
caracter = (Uptime->RTC_Minute / 10) + 48;
Serial_Envia_Caracter(caracter);
}
caracter = (Uptime->RTC_Minute%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter('m');
Serial_Envia_Caracter(' ');
if(Uptime->RTC_Second > 9)
{
caracter = (Uptime->RTC_Second / 10) + 48;
Serial_Envia_Caracter(caracter);
}
caracter = (Uptime->RTC_Second%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter('s');
Serial_Envia_Caracter(' ');
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
}
void Transmite_RAM_Ocupada(void)
{
INT8U caracter = 0;
INT8U mil,cent,dez;
INT16U SPAddress = 0;
INT16U backup = 0;
/*
strcpypgm2ram (BufferText, (const rom char far *)MemoryText);
*/
Serial_Envia_Frase(BufferText);
OSEnterCritical();
SPAddress = iStackAddress;
OSExitCritical();
mil = (SPAddress / 1000);
caracter = mil + 48;
if(caracter != 48)
Serial_Envia_Caracter(caracter);
backup = SPAddress - (INT16U)mil*1000;
cent = backup / 100;
//cent = ((SPAddress - mil*1000)/100);
caracter = cent + 48;
Serial_Envia_Caracter(caracter);
backup = SPAddress - 1000*mil;
backup = backup - (INT16U)cent*100;
dez = backup / 10;
//dez = (INT16U)(SPAddress - (INT16U)(1000*mil) - (INT16U)(cent*100))/(INT8U)10;
caracter = dez + 48;
Serial_Envia_Caracter(caracter);
caracter = (SPAddress%10) + 48;
Serial_Envia_Caracter(caracter);
/*
strcpypgm2ram (BufferText, (const rom char far *)OfText);
*/
Serial_Envia_Frase(BufferText);
mil = (HEAP_SIZE / 1000);
caracter = mil + 48;
if(caracter != 48)
Serial_Envia_Caracter(caracter);
backup = HEAP_SIZE - (INT16U)mil*1000;
cent = backup / 100;
caracter = cent + 48;
Serial_Envia_Caracter(caracter);
backup = HEAP_SIZE - 1000*mil;
backup = backup - (INT16U)cent*100;
dez = backup / 10;
caracter = dez + 48;
Serial_Envia_Caracter(caracter);
caracter = (HEAP_SIZE%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
}
void Transmite_Task_Stacks(void)
{
INT8U caracter = 0;
INT8U mil,cent,dez;
INT16U VirtualStack = 0;
INT16U backup = 0;
INT8U j = 0;
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
/*
strcpypgm2ram (BufferText, (const rom char far *)TaskStackText);
*/
Serial_Envia_Frase(BufferText);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
for (j=1;j<=NumberOfInstalledTasks;j++)
{
Serial_Envia_Caracter('[');
Serial_Envia_Caracter(j+48);
Serial_Envia_Caracter(']');
Serial_Envia_Caracter(' ');
/*
strcpypgm2ram (BufferText, (const rom char far *)ContextTask[j].TaskName);
*/
Serial_Envia_Frase(BufferText);
Serial_Envia_Caracter(':');
Serial_Envia_Caracter(' ');
OSEnterCritical();
VirtualStack = (ContextTask[j].StackPoint) - (ContextTask[j].StackInit);
OSExitCritical();
mil = (VirtualStack / 1000);
caracter = mil + 48;
if(caracter != 48)
Serial_Envia_Caracter(caracter);
backup = VirtualStack - (INT16U)mil*1000;
cent = backup / 100;
caracter = cent + 48;
if(caracter != 48)
Serial_Envia_Caracter(caracter);
backup = VirtualStack - 1000*mil;
backup = backup - (INT16U)cent*100;
dez = backup / 10;
caracter = dez + 48;
Serial_Envia_Caracter(caracter);
caracter = (VirtualStack%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
}
Serial_Envia_Caracter('[');
Serial_Envia_Caracter(j+48);
Serial_Envia_Caracter(']');
Serial_Envia_Caracter(' ');
/*
strcpypgm2ram (BufferText, (const rom char far *)IdleTaskText);
*/
Serial_Envia_Frase(BufferText);
OSEnterCritical();
VirtualStack = ContextTask[NUMBER_OF_TASKS+1].StackPoint - ContextTask[NUMBER_OF_TASKS+1].StackInit;
OSExitCritical();
mil = (VirtualStack / 1000);
caracter = mil + 48;
if(caracter != 48)
Serial_Envia_Caracter(caracter);
backup = VirtualStack - (INT16U)mil*1000;
cent = backup / 100;
caracter = cent + 48;
if(caracter != 48)
Serial_Envia_Caracter(caracter);
backup = VirtualStack - 1000*mil;
backup = backup - (INT16U)cent*100;
dez = backup / 10;
caracter = dez + 48;
Serial_Envia_Caracter(caracter);
caracter = (VirtualStack%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
}
#if (COMPUTES_CPU_LOAD == 1)
void Transmite_CPU_Load(void)
{
INT16U percent = 0;
INT8U caracter = 0;
OSEnterCritical();
percent = LastOSDuty;
percent = (percent*100)/TIMER_MODULE;
OSExitCritical();
/*
strcpypgm2ram (BufferText, (const rom char far *)CPULoadText);
*/
Serial_Envia_Frase(BufferText);
if (percent >= 100)
{
/*
strcpypgm2ram (BufferText, (const rom char far *)CPU100Text);
*/
Serial_Envia_Frase(BufferText);
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
}
else
{
caracter = (percent / 10) + 48;
Serial_Envia_Caracter(caracter);
caracter = (percent%10) + 48;
Serial_Envia_Caracter(caracter);
Serial_Envia_Caracter('%');
Serial_Envia_Caracter(10);
Serial_Envia_Caracter(13);
}
}
#endif
#if (OSTRACE == 1)
/* OS trace function */
/* coded as 8 bit: 0xTTTTTSSS
- T: task bits (1-31: task id, 0: ISR)
- S: syscall (
0: DELAYTASK, 1: SEMPEND, 2: QUEUEPEND, 3: MUTEXPEND
4: SEMPOST, 5: QUEUEPOST, 6: MUTEXPOST, 7: OS_IDLE
0x00: undefined
*/
static INT8U OSTrace[MAX_DEPTH_TRACE];
static INT8U OSTrace_snapshot[MAX_DEPTH_TRACE];
static INT8U index;
// update OSTrace history
void Update_OSTrace (INT8U task, INT8U syscall)
{
OSTrace[index] = (INT8U)((task << 5) | syscall);
index++;
if(index == MAX_DEPTH_TRACE)
{
index=0;
}
}
// send OSTrace to serial
void Send_OSTrace(void){
#if (NESTING_INT == 1)
INT16U CPU_SR = 0;
#endif
INT8U i=0;
INT8U j=0;
const CHAR8 *TaskName;
OSEnterCritical();
for(i=index, j=0;i<MAX_DEPTH_TRACE;i++,j++){
OSTrace_snapshot[j] = OSTrace[i];
OSTrace[i] = 0; // clear history
}
for(i=0;i<index;i++,j++){
OSTrace_snapshot[j] = OSTrace[i];
OSTrace[i] = 0; // clear history
}
index = 0;
OSExitCritical();
j=0;
do{
for(i=j;i<(j+MAX_TRACE_LINE);i++)
{
if(!(OSTrace_snapshot[i]>>5))
{
switch(OSTrace_snapshot[i] & 0x07)
{
case ISR_ONLY:
Serial_Envia_Frase("ISR ONLY");
break;
case ISR_TICK:
#if(OS_TICK_SHOW == 1)
Serial_Envia_Frase("ISR TICK");
#endif
break;
case SEMPOST:
Serial_Envia_Frase("ISR SEMPOST");
break;
case QUEUEPOST:
Serial_Envia_Frase("ISR QUEUEPOST");
break;
case MUTEXPOST:
Serial_Envia_Frase("ISR MUTEXPOST");
break;
case OS_IDLE:
#if(OS_IDLE_SHOW == 1)
Serial_Envia_Frase("ISR IDLE");
#endif
break;
default:
Serial_Envia_Frase("________");
break;
}
}else
{
#if(OS_IDLE_SHOW == 1)
Serial_Envia_Frase("TASK ");
car = OSTrace_snapshot[i]>>5;
car = (car / 10) + 48;
Serial_Envia_Caracter(car);
car = OSTrace_snapshot[i]>>5;
car = (car%10) + 48;
Serial_Envia_Caracter(car);
Serial_Envia_Caracter(' ');
#else
if((OSTrace_snapshot[i]>>5) != (NUMBER_OF_TASKS+1))
{
TaskName = ContextTask[OSTrace_snapshot[i]>>5].TaskName;
Serial_Envia_Frase(TaskName);
Serial_Envia_Caracter(' ');
}
#endif
switch(OSTrace_snapshot[i] & 0x07){
case DELAYTASK:
Serial_Envia_Frase("DELAYTASK");
break;
case SEMPEND:
Serial_Envia_Frase("SEMPEND");
break;
case QUEUEPEND:
Serial_Envia_Frase("QUEUEPEND");
break;
case MUTEXPEND:
Serial_Envia_Frase("MUTEXPEND");
break;
case SEMPOST:
Serial_Envia_Frase("SEMPOST");
break;
case QUEUEPOST:
Serial_Envia_Frase("QUEUEPOST");
break;
case MUTEXPOST:
Serial_Envia_Frase("MUTEXPOST");
break;
case OS_IDLE:
#if(OS_IDLE_SHOW == 1)
Serial_Envia_Frase("IDLE");
#endif
break;
default:
break;
}
}
Serial_Envia_Frase(" - ");
}
j += MAX_TRACE_LINE;
Serial_Envia_Caracter(LF);
} while(j < MAX_DEPTH_TRACE);
Serial_Envia_Caracter(CR);
}
#endif