Bläddra i källkod

Debug functions for tracking RTOS task usage.

Since configUSE_TRACE_FACILITY is not enabled :(
Johny Mattsson 8 år sedan
förälder
incheckning
239af986df
2 ändrade filer med 47 tillägg och 0 borttagningar
  1. 12 0
      app/include/rtos_dbg.h
  2. 35 0
      app/user/rtos_dbg.c

+ 12 - 0
app/include/rtos_dbg.h

@@ -0,0 +1,12 @@
+#ifndef _RTOS_DBG_H_
+#define _RTOS_DBG_H_
+
+#include <stdint.h>
+
+#define rtos_dbg_here() do{rtos_dbg_task_print(__FILE__,__LINE__);} while(0)
+#define rtos_dbg_stack_here() do{rtos_dbg_stack_print(__FILE__,__LINE__);} while(0)
+
+void rtos_dbg_task_print (const char *file, uint32_t line);
+void rtos_dbg_stack_print (const char *file, uint32_t line);
+
+#endif

+ 35 - 0
app/user/rtos_dbg.c

@@ -0,0 +1,35 @@
+#include "rtos_dbg.h"
+#include <freertos/FreeRTOSConfig.h>
+#include <stdio.h>
+
+extern struct {
+  uint32_t *pxTopOfStack;
+  uint32_t x[5];
+  uint32_t y[5];
+  unsigned uxPriority;
+  uint32_t *pxStack;
+  signed char pcTaskName[configMAX_TASK_NAME_LEN];
+} *pxCurrentTCB;
+
+void rtos_dbg_task_print (const char *file, uint32_t line)
+{
+  printf(">>dbg: %s:%d in RTOS task \"%s\": prio %d\n",
+    file,
+    line,
+    pxCurrentTCB->pcTaskName,
+    pxCurrentTCB->uxPriority
+  );
+}
+
+
+void rtos_dbg_stack_print (const char *file, uint32_t line)
+{
+  uint32_t fill = 0xa5a5a5a5u;
+  uint32_t nwords = 0;
+  uint32_t *p = (uint32_t*)pxCurrentTCB->pxStack;
+  for (;p < pxCurrentTCB->pxTopOfStack && *p == fill; ++p)
+    ++nwords; 
+
+  printf(">>dbg: %s:%d in RTOS task \"%s\": %u stack untouched\n",
+    file, line, pxCurrentTCB->pcTaskName, nwords * 4);
+}