Skip to content

【完善】通过traceRETURN_xTaskGetCurrentTaskHandle获取FreeRTOS任务栈信息, 避免修改源码 #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -246,7 +253,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;
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_THREADX)
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 @@ -343,10 +343,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"
#elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_THREADX)
Expand Down Expand Up @@ -427,4 +427,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_ */