00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #include <compiler.h>
00069 #include <sys/thread.h>
00070 #include <sys/timer.h>
00071 #include <sys/event.h>
00072 #include <sys/heap.h>
00073
00074 #include <sys/osdebug.h>
00075
00076 #if defined(__arm__) || defined(__m68k__) || defined(__H8300H__) || defined(__H8300S__) || defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00077 #define ARCH_32BIT
00078 #endif
00079
00080
00081 FILE *__os_trs;
00082 u_char __os_trf;
00083
00084 FILE *__heap_trs;
00085 u_char __heap_trf;
00086
00087 static char *states[] = { "TRM", "RUN", "RDY", "SLP" };
00088
00089 #ifdef ARCH_32BIT
00090
00091 static prog_char qheader[] = "\nHandle Name Prio Sta Queue Timer StackPtr FreeMem\n";
00092 #else
00093
00094 static prog_char qheader[] = "\nHndl Name Prio Sta QUE Timr StkP FreeMem\n";
00095 #endif
00096
00106 void NutDumpThreadQueue(FILE * stream, NUTTHREADINFO * tdp)
00107 {
00108 #ifdef ARCH_32BIT
00109 static prog_char fmt[] = "%08lX %-8s %4u %s %08lX %08lX %08lX %9lu %s\n";
00110 #else
00111 static prog_char fmt[] = "%04X %-8s %4u %s %04X %04X %04X %5u %s\n";
00112 #endif
00113
00114 if (tdp == SIGNALED)
00115 fputs("SIGNALED\n", stream);
00116 else {
00117 while (tdp) {
00118 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00119 fprintf_P(stream, fmt, (uptr_t) tdp, tdp->td_name, tdp->td_priority,
00120 states[tdp->td_state], (uptr_t) tdp->td_queue, (uptr_t) tdp->td_timer, tdp->td_cs_level, 0, "--");
00121 #else
00122 fprintf_P(stream, fmt, (uptr_t) tdp, tdp->td_name, tdp->td_priority,
00123 states[tdp->td_state], (uptr_t) tdp->td_queue,
00124 (uptr_t) tdp->td_timer, tdp->td_sp,
00125 (uptr_t) tdp->td_sp - (uptr_t) tdp->td_memory,
00126 *((u_long *) tdp->td_memory) != DEADBEEF
00127 && *((u_long *) (tdp->td_memory + 4)) != DEADBEEF
00128 && *((u_long *) (tdp->td_memory + 8)) != DEADBEEF
00129 && *((u_long *) (tdp->td_memory + 12)) != DEADBEEF ? "FAIL" : "OK");
00130 #endif
00131 tdp = tdp->td_qnxt;
00132
00133 }
00134 }
00135 }
00136
00145 void NutDumpThreadList(FILE * stream)
00146 {
00147
00148 #ifdef ARCH_32BIT
00149 static prog_char fmt1[] = "%08lX %-8s %4u %s %08lX %08lX %08lX %9lu %s";
00150 static prog_char fmt2[] = " %08lX";
00151 #else
00152 static prog_char fmt1[] = "%04X %-8s %4u %s %04X %04X %04X %5u %s";
00153 static prog_char fmt2[] = " %04X";
00154 #endif
00155 NUTTHREADINFO *tqp;
00156 NUTTHREADINFO *tdp;
00157
00158 fputs_P(qheader, stream);
00159
00160 tdp = nutThreadList;
00161 while (tdp) {
00162 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00163 fprintf_P(stream, fmt1, (uptr_t) tdp, tdp->td_name, tdp->td_priority,
00164 states[tdp->td_state], (uptr_t) tdp->td_queue, (uptr_t) tdp->td_timer, tdp->td_cs_level, 0, "--");
00165 #else
00166 fprintf_P(stream, fmt1, (uptr_t) tdp, tdp->td_name, tdp->td_priority,
00167 states[tdp->td_state], (uptr_t) tdp->td_queue,
00168 (uptr_t) tdp->td_timer, tdp->td_sp,
00169 (uptr_t) tdp->td_sp - (uptr_t) tdp->td_memory, *((u_long *) tdp->td_memory) != DEADBEEF ? "FAIL" : "OK");
00170 #endif
00171 if (tdp->td_queue) {
00172 tqp = *(NUTTHREADINFO **) (tdp->td_queue);
00173 if (tqp == SIGNALED)
00174 fputs("SIGNALED", stream);
00175 else {
00176 while (tqp) {
00177 fprintf_P(stream, fmt2, (uptr_t) tqp);
00178 tqp = tqp->td_qnxt;
00179 }
00180 }
00181 }
00182 fputc('\n', stream);
00183 tdp = tdp->td_next;
00184 }
00185 }
00186
00195 void NutDumpTimerList(FILE * stream)
00196 {
00197
00198 static prog_char wname[] = "NutThreadWake";
00199 static prog_char tname[] = "NutEventTimeout";
00200 #ifdef ARCH_32BIT
00201 static prog_char theader[] = "Address Ticks Left Callback\n";
00202 static prog_char fmt1[] = "%08lX%6lu%6lu ";
00203 static prog_char fmt2[] = "%09lX";
00204 static prog_char fmt3[] = "(%08lX)\n";
00205 #else
00206 static prog_char theader[] = "Addr Ticks Left Callback\n";
00207 static prog_char fmt1[] = "%04X%6lu%6lu ";
00208 static prog_char fmt2[] = "%05lX";
00209 static prog_char fmt3[] = "(%04X)\n";
00210 #endif
00211
00212 NUTTIMERINFO *tnp;
00213 if ((tnp = nutTimerList) != 0) {
00214 fputs_P(theader, stream);
00215 while (tnp) {
00216 fprintf_P(stream, fmt1, (uptr_t) tnp, tnp->tn_ticks, tnp->tn_ticks_left);
00217 if (tnp->tn_callback == NutThreadWake)
00218 fputs_P(wname, stream);
00219 else if (tnp->tn_callback == NutEventTimeout)
00220 fputs_P(tname, stream);
00221 else
00222 fprintf_P(stream, fmt2, (u_long) ((uptr_t) tnp->tn_callback) << 1);
00223 fprintf_P(stream, fmt3, (uptr_t) tnp->tn_arg);
00224 tnp = tnp->tn_next;
00225 }
00226 }
00227 }
00228
00236 void NutTraceOs(FILE * stream, u_char flags)
00237 {
00238 if (stream)
00239 __os_trs = stream;
00240 if (__os_trs)
00241 __os_trf = flags;
00242 else
00243 __os_trf = 0;
00244 }
00245
00252 void NutDumpHeap(FILE * stream)
00253 {
00254
00255 #ifdef ARCH_32BIT
00256 static prog_char fmt1[] = "%08lx %9ld\n";
00257 static prog_char fmt2[] = "%lu counted, but %lu reported\n";
00258 static prog_char fmt3[] = "%lu bytes free\n";
00259 #else
00260 static prog_char fmt1[] = "%04x %5d\n";
00261 static prog_char fmt2[] = "%u counted, but %u reported\n";
00262 static prog_char fmt3[] = "%u bytes free\n";
00263 #endif
00264 HEAPNODE *node;
00265 size_t sum = 0;
00266 size_t avail;
00267
00268 fputc('\n', stream);
00269 for (node = heapFreeList; node; node = node->hn_next) {
00270 sum += node->hn_size;
00271 fprintf_P(stream, fmt1, (uptr_t) node, node->hn_size);
00272
00273 if ((uptr_t) node < 0x60 || (uptr_t) node > 0x7fff)
00274 break;
00275 }
00276 if ((avail = NutHeapAvailable()) != sum)
00277 fprintf_P(stream, fmt2, sum, avail);
00278 else
00279 fprintf_P(stream, fmt3, avail);
00280 }
00281
00289 void NutTraceHeap(FILE * stream, u_char flags)
00290 {
00291 if (stream)
00292 __heap_trs = stream;
00293 if (__heap_trs)
00294 __heap_trf = flags;
00295 else
00296 __heap_trf = 0;
00297 }