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
00069
00070
00071
00072
00073
00074
00075 #include <compiler.h>
00076 #include <sys/thread.h>
00077 #include <sys/timer.h>
00078 #include <sys/event.h>
00079 #include <sys/heap.h>
00080
00081 #include <sys/osdebug.h>
00082
00083 #if defined(__arm__) || defined(__m68k__) || defined(__H8300H__) || defined(__H8300S__) || defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00084 #define ARCH_32BIT
00085 #endif
00086
00087
00088 FILE *__os_trs;
00089 uint_fast8_t __os_trf;
00090
00091 FILE *__heap_trs;
00092 uint_fast8_t __heap_trf;
00093
00094 static char *states[] = { "TRM", "RUN", "RDY", "SLP" };
00095
00096 #ifdef ARCH_32BIT
00097
00098 static prog_char qheader[] = "\nHandle Name Prio Sta Queue Timer StackPtr FreeMem\n";
00099 #else
00100
00101 static prog_char qheader[] = "\nHndl Name Prio Sta QUE Timr StkP FreeMem\n";
00102 #endif
00103
00113 void NutDumpThreadQueue(FILE * stream, NUTTHREADINFO * tdp)
00114 {
00115 #ifdef ARCH_32BIT
00116 static prog_char fmt[] = "%08lX %-8s %4u %s %08lX %08lX %08lX %9lu %s\n";
00117 #else
00118 static prog_char fmt[] = "%04X %-8s %4u %s %04X %04X %04X %5u %s\n";
00119 #endif
00120
00121 if (tdp == SIGNALED)
00122 fputs("SIGNALED\n", stream);
00123 else {
00124 while (tdp) {
00125 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00126 fprintf_P(stream, fmt, (uintptr_t) tdp, tdp->td_name, tdp->td_priority,
00127 states[tdp->td_state], (uintptr_t) tdp->td_queue, (uintptr_t) tdp->td_timer, tdp->td_cs_level, 0, "--");
00128 #else
00129 fprintf_P(stream, fmt, (uintptr_t) tdp, tdp->td_name, tdp->td_priority,
00130 states[tdp->td_state], (uintptr_t) tdp->td_queue,
00131 (uintptr_t) tdp->td_timer, tdp->td_sp,
00132 (uintptr_t) tdp->td_sp - (uintptr_t) tdp->td_memory,
00133 *((uint32_t *) tdp->td_memory) != DEADBEEF
00134 && *((uint32_t *) (tdp->td_memory + 4)) != DEADBEEF
00135 && *((uint32_t *) (tdp->td_memory + 8)) != DEADBEEF
00136 && *((uint32_t *) (tdp->td_memory + 12)) != DEADBEEF ? "FAIL" : "OK");
00137 #endif
00138 tdp = tdp->td_qnxt;
00139
00140 }
00141 }
00142 }
00143
00152 void NutDumpThreadList(FILE * stream)
00153 {
00154
00155 #ifdef ARCH_32BIT
00156 static prog_char fmt1[] = "%08lX %-8s %4u %s %08lX %08lX %08lX %9lu %s";
00157 static prog_char fmt2[] = " %08lX";
00158 #else
00159 static prog_char fmt1[] = "%04X %-8s %4u %s %04X %04X %04X %5u %s";
00160 static prog_char fmt2[] = " %04X";
00161 #endif
00162 NUTTHREADINFO *tqp;
00163 NUTTHREADINFO *tdp;
00164
00165 fputs_P(qheader, stream);
00166
00167 tdp = nutThreadList;
00168 while (tdp) {
00169 #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
00170 fprintf_P(stream, fmt1, (uintptr_t) tdp, tdp->td_name, tdp->td_priority,
00171 states[tdp->td_state], (uintptr_t) tdp->td_queue, (uintptr_t) tdp->td_timer, tdp->td_cs_level, 0, "--");
00172 #else
00173 fprintf_P(stream, fmt1, (uintptr_t) tdp, tdp->td_name, tdp->td_priority,
00174 states[tdp->td_state], (uintptr_t) tdp->td_queue,
00175 (uintptr_t) tdp->td_timer, tdp->td_sp,
00176 (uintptr_t) tdp->td_sp - (uintptr_t) tdp->td_memory, *((uint32_t *) tdp->td_memory) != DEADBEEF ? "FAIL" : "OK");
00177 #endif
00178 if (tdp->td_queue) {
00179 tqp = *(NUTTHREADINFO **) (tdp->td_queue);
00180 if (tqp == SIGNALED)
00181 fputs("SIGNALED", stream);
00182 else {
00183 while (tqp) {
00184 fprintf_P(stream, fmt2, (uintptr_t) tqp);
00185 tqp = tqp->td_qnxt;
00186 }
00187 }
00188 }
00189 fputc('\n', stream);
00190 tdp = tdp->td_next;
00191 }
00192 }
00193
00202 void NutDumpTimerList(FILE * stream)
00203 {
00204
00205 static prog_char wname[] = "NutThreadWake";
00206 static prog_char tname[] = "NutEventTimeout";
00207 #ifdef ARCH_32BIT
00208 static prog_char theader[] = "Address Ticks Left Callback\n";
00209 static prog_char fmt1[] = "%08lX%6lu%6lu ";
00210 static prog_char fmt2[] = "%09lX";
00211 static prog_char fmt3[] = "(%08lX)\n";
00212 #else
00213 static prog_char theader[] = "Addr Ticks Left Callback\n";
00214 static prog_char fmt1[] = "%04X%6lu%6lu ";
00215 static prog_char fmt2[] = "%05lX";
00216 static prog_char fmt3[] = "(%04X)\n";
00217 #endif
00218
00219 NUTTIMERINFO *tnp;
00220 if ((tnp = nutTimerList) != 0) {
00221 fputs_P(theader, stream);
00222 while (tnp) {
00223 fprintf_P(stream, fmt1, (uintptr_t) tnp, tnp->tn_ticks, tnp->tn_ticks_left);
00224 if (tnp->tn_callback == NutThreadWake)
00225 fputs_P(wname, stream);
00226 else if (tnp->tn_callback == NutEventTimeout)
00227 fputs_P(tname, stream);
00228 else
00229 fprintf_P(stream, fmt2, (uint32_t) ((uintptr_t) tnp->tn_callback) << 1);
00230 fprintf_P(stream, fmt3, (uintptr_t) tnp->tn_arg);
00231 tnp = tnp->tn_next;
00232 }
00233 }
00234 }
00235
00243 void NutTraceOs(FILE * stream, uint8_t flags)
00244 {
00245 if (stream)
00246 __os_trs = stream;
00247 if (__os_trs)
00248 __os_trf = flags;
00249 else
00250 __os_trf = 0;
00251 }
00252
00259 void NutDumpHeap(FILE * stream)
00260 {
00261
00262 #ifdef ARCH_32BIT
00263 static prog_char fmt1[] = "%08lx %9ld\n";
00264 static prog_char fmt2[] = "%lu counted, but %lu reported\n";
00265 static prog_char fmt3[] = "%lu bytes free\n";
00266 #else
00267 static prog_char fmt1[] = "%04x %5d\n";
00268 static prog_char fmt2[] = "%u counted, but %u reported\n";
00269 static prog_char fmt3[] = "%u bytes free\n";
00270 #endif
00271 HEAPNODE *node;
00272 size_t sum = 0;
00273 size_t avail;
00274
00275 fputc('\n', stream);
00276 for (node = heapFreeList; node; node = node->hn_next) {
00277 sum += node->hn_size;
00278 fprintf_P(stream, fmt1, (uintptr_t) node, node->hn_size);
00279
00280 if ((uintptr_t) node < 0x60 || (uintptr_t) node > 0x7fff)
00281 break;
00282 }
00283 if ((avail = NutHeapAvailable()) != sum)
00284 fprintf_P(stream, fmt2, sum, avail);
00285 else
00286 fprintf_P(stream, fmt3, avail);
00287 }
00288
00296 void NutTraceHeap(FILE * stream, uint8_t flags)
00297 {
00298 if (stream)
00299 __heap_trs = stream;
00300 if (__heap_trs)
00301 __heap_trf = flags;
00302 else
00303 __heap_trf = 0;
00304 }