Skip to content

Commit

Permalink
【完善】通过traceRETURN_xTaskGetCurrentTaskHandle获取FreeRTOS任务栈信息, 避免修改源码
Browse files Browse the repository at this point in the history
  • Loading branch information
Gang Li committed May 13, 2024
1 parent 6013293 commit e847d8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
14 changes: 11 additions & 3 deletions cm_backtrace/cm_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ void cm_backtrace_firmware_info(void) {
}

#ifdef CMB_USING_OS_PLATFORM

#if (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
uint32_t ft_start_addr;
size_t ft_size;
#endif

/**
* Get current thread stack information
*
Expand All @@ -208,8 +214,9 @@ static void get_cur_thread_stack_info(uint32_t *sp, uint32_t *start_addr, size_t
*start_addr = (uint32_t) OSTCBCurPtr->StkBasePtr;
*size = OSTCBCurPtr->StkSize * sizeof(CPU_STK_SIZE);
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
*start_addr = (uint32_t)vTaskStackAddr();
*size = vTaskStackSize() * sizeof( StackType_t );
xTaskGetCurrentTaskHandle();
*start_addr = (uint32_t) ft_start_addr;
*size = (size_t) ft_size;
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
osRtxThread_t *thread = osRtxInfo.thread.run.curr;
*start_addr = (uint32_t)thread->stack_mem;
Expand Down Expand Up @@ -241,7 +248,8 @@ static const char *get_cur_thread_name(void) {

return (const char *)OSTCBCurPtr->NamePtr;
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
return vTaskName();
char *taskName = pcTaskGetName(NULL);
return (const char *)taskName;
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
return osRtxInfo.thread.run.curr->name;
#endif
Expand Down
21 changes: 17 additions & 4 deletions cm_backtrace/cmb_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ if (!(EXPR)) \
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_UCOSIII)
#include <os.h>
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
#include <FreeRTOS.h>
extern uint32_t *vTaskStackAddr(void);/* need to modify the FreeRTOS/tasks source code */
extern uint32_t vTaskStackSize(void);
extern char * vTaskName(void);
#include <FreeRTOS.h>
#include "task.h"
extern TaskHandle_t xTaskGetCurrentTaskHandle(void);
extern char * pcTaskGetName(TaskHandle_t xTaskToQuery);
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
#include "rtx_os.h"
#else
Expand Down Expand Up @@ -423,4 +423,17 @@ if (!(EXPR)) \
#error "not supported compiler"
#endif

#if (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
extern uint32_t ft_start_addr;
extern size_t ft_size;

#undef traceRETURN_xTaskGetCurrentTaskHandle
#define traceRETURN_xTaskGetCurrentTaskHandle(xReturn) \
{ \
ft_start_addr = (xReturn != NULL ? (StackType_t)xReturn->pxStack : 0); \
ft_size = (xReturn != NULL ? (StackType_t)xReturn - (StackType_t)xReturn->pxStack - \
4 * sizeof(StackType_t) : 0); \
}
#endif

#endif /* _CMB_DEF_H_ */

0 comments on commit e847d8b

Please sign in to comment.