Debug functions for tracking RTOS task usage.

Since configUSE_TRACE_FACILITY is not enabled :(
This commit is contained in:
Johny Mattsson 2016-05-31 18:46:59 +10:00
parent e15dfee13f
commit 239af986df
2 changed files with 47 additions and 0 deletions

12
app/include/rtos_dbg.h Normal file
View File

@ -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
app/user/rtos_dbg.c Normal file
View File

@ -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);
}