|
1、使能栈检测
- #define TX_ENABLE_STACK_CHECKING
复制代码
2、注册回调:
- tx_thread_stack_error_notify(my_stack_error_handler);
复制代码
3、回调实现:
- void my_stack_error_handler(TX_THREAD *thread_ptr)
- {
- App_Printf("===============================================================\r\n");
- App_Printf("如下任务被检测出栈溢出\r\n");
- App_Printf("===============================================================\r\n");
- App_Printf(" 任务优先级 任务栈大小 当前使用栈 最大栈使用 任务名\r\n");
- App_Printf(" Prio StackSize CurStack MaxStack Taskname\r\n");
-
- TX_THREAD *p_tcb; /* 定义一个任务控制块指针 */
- p_tcb = &AppTaskStartTCB;
-
- /* 遍历任务控制列表TCB list),打印所有的任务的优先级和名称 */
- do
- {
- if(p_tcb != (TX_THREAD *)thread_ptr)
- {
- p_tcb = p_tcb->tx_thread_created_next;
- }
- else
- {
-
- App_Printf(" %2d %5d %5d %5d %s\r\n",
- p_tcb->tx_thread_priority,
- p_tcb->tx_thread_stack_size,
- (int)p_tcb->tx_thread_stack_end - (int)p_tcb->tx_thread_stack_ptr,
- (int)p_tcb->tx_thread_stack_end - (int)p_tcb->tx_thread_stack_highest_ptr,
- p_tcb->tx_thread_name);
-
- // tx_thread_terminate(thread_ptr);
- // tx_thread_reset(thread_ptr);
- // tx_thread_resume(thread_ptr);
- while(1);
- }
- }while(1);
- }
复制代码
打印栈溢出的任务
|
|