Skip to content

Commit e08c5ee

Browse files
author
Gang Li
committed
【完善】通过traceRETURN_xTaskGetCurrentTaskHandle获取FreeRTOS任务栈信息, 避免修改源码
1 parent 6013293 commit e08c5ee

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

Diff for: cm_backtrace/cm_backtrace.c

+11-3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ void cm_backtrace_firmware_info(void) {
182182
}
183183

184184
#ifdef CMB_USING_OS_PLATFORM
185+
186+
#if (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
187+
uint32_t start_addr;
188+
size_t size;
189+
#endif
190+
185191
/**
186192
* Get current thread stack information
187193
*
@@ -208,8 +214,9 @@ static void get_cur_thread_stack_info(uint32_t *sp, uint32_t *start_addr, size_t
208214
*start_addr = (uint32_t) OSTCBCurPtr->StkBasePtr;
209215
*size = OSTCBCurPtr->StkSize * sizeof(CPU_STK_SIZE);
210216
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
211-
*start_addr = (uint32_t)vTaskStackAddr();
212-
*size = vTaskStackSize() * sizeof( StackType_t );
217+
xTaskGetCurrentTaskHandle();
218+
*start_addr = (uint32_t) start_addr;
219+
*size = (size_t) size;
213220
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
214221
osRtxThread_t *thread = osRtxInfo.thread.run.curr;
215222
*start_addr = (uint32_t)thread->stack_mem;
@@ -241,7 +248,8 @@ static const char *get_cur_thread_name(void) {
241248

242249
return (const char *)OSTCBCurPtr->NamePtr;
243250
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
244-
return vTaskName();
251+
char *taskName = pcTaskGetName(NULL);
252+
return (const char *)taskName;
245253
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
246254
return osRtxInfo.thread.run.curr->name;
247255
#endif

Diff for: cm_backtrace/cmb_def.h

+17-4
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,10 @@ if (!(EXPR)) \
342342
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_UCOSIII)
343343
#include <os.h>
344344
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
345-
#include <FreeRTOS.h>
346-
extern uint32_t *vTaskStackAddr(void);/* need to modify the FreeRTOS/tasks source code */
347-
extern uint32_t vTaskStackSize(void);
348-
extern char * vTaskName(void);
345+
#include <FreeRTOS.h>
346+
#include "task.h"
347+
extern TaskHandle_t xTaskGetCurrentTaskHandle(void);
348+
extern char * pcTaskGetName(TaskHandle_t xTaskToQuery);
349349
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
350350
#include "rtx_os.h"
351351
#else
@@ -423,4 +423,17 @@ if (!(EXPR)) \
423423
#error "not supported compiler"
424424
#endif
425425

426+
#if (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
427+
extern uint32_t start_addr;
428+
extern size_t size;
429+
430+
#undef traceRETURN_xTaskGetCurrentTaskHandle
431+
#define traceRETURN_xTaskGetCurrentTaskHandle(xReturn) \
432+
{ \
433+
start_addr = (xReturn != NULL ? (StackType_t)xReturn->pxStack : 0); \
434+
size = (xReturn != NULL ? (StackType_t)xReturn - (StackType_t)xReturn->pxStack - \
435+
4 * sizeof(StackType_t) : 0); \
436+
}
437+
#endif
438+
426439
#endif /* _CMB_DEF_H_ */

0 commit comments

Comments
 (0)