Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_thread.h"
...
...
_tx_thread_stack_analyze(TX_THREAD *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesthreadxcommon/src/tx_thread_stack_analyze.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** ThreadX Component */ /** */ /** Thread */ /** */... /**************************************************************************/ /**************************************************************************/ #define TX_SOURCE_CODE /* Include necessary system files. */ #include "tx_api.h" #include "tx_thread.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _tx_thread_stack_analyze PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function analyzes the stack to calculate the highest stack */ /* pointer in the thread's stack. This can then be used to derive the */ /* minimum amount of stack left for any given thread. */ /* */ /* INPUT */ /* */ /* thread_ptr Thread control block pointer */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* None */ /* */ /* CALLED BY */ /* */ /* ThreadX internal code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ VOID _tx_thread_stack_analyze(TX_THREAD *thread_ptr) { TX_INTERRUPT_SAVE_AREA ULONG *stack_ptr; ULONG *stack_lowest; ULONG *stack_highest; ULONG size; /* Disable interrupts. */ TX_DISABLE /* Determine if the thread pointer is NULL. */ if (thread_ptr != TX_NULL) { /* Determine if the thread ID is invalid. */ if (thread_ptr -> tx_thread_id == TX_THREAD_ID) { /* Pickup the current stack variables. */ stack_lowest = TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_stack_start); /* Determine if the pointer is null. */ if (stack_lowest != TX_NULL) { /* Pickup the highest stack pointer. */ stack_highest = TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_stack_highest_ptr); /* Determine if the pointer is null. */ if (stack_highest != TX_NULL) { /* Restore interrupts. */ TX_RESTORE /* We need to binary search the remaining stack for missing 0xEFEFEFEF 32-bit data pattern. This is a best effort algorithm to find the highest stack usage. *//* ... */ do { /* Calculate the size again. */ size = (ULONG) (TX_ULONG_POINTER_DIF(stack_highest, stack_lowest))/((ULONG) 2); stack_ptr = TX_ULONG_POINTER_ADD(stack_lowest, size); /* Determine if the pattern is still there. */ if (*stack_ptr != TX_STACK_FILL) { /* Update the stack highest, since we need to look in the upper half now. */ stack_highest = stack_ptr; }if (*stack_ptr != TX_STACK_FILL) { ... } else { /* Update the stack lowest, since we need to look in the lower half now. */ stack_lowest = stack_ptr; }else { ... } ...} while(size > ((ULONG) 1)); /* Position to first used word - at this point we are within a few words. */ while (*stack_ptr == TX_STACK_FILL) { /* Position to next word in stack. */ stack_ptr = TX_ULONG_POINTER_ADD(stack_ptr, 1); }while (*stack_ptr == TX_STACK_FILL) { ... } /* Optional processing extension. */ TX_THREAD_STACK_ANALYZE_EXTENSION /* Disable interrupts. */ TX_DISABLE /* Check to see if the thread is still created. */ if (thread_ptr -> tx_thread_id == TX_THREAD_ID) { /* Yes, thread is still created. */ /* Now check the new highest stack pointer is past the stack start. */ if (stack_ptr > (TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_stack_start))) { /* Yes, now check that the new highest stack pointer is less than the previous highest stack pointer. */ if (stack_ptr < (TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_stack_highest_ptr))) { /* Yes, is the current highest stack pointer pointing at used memory? */ if (*stack_ptr != TX_STACK_FILL) { /* Yes, setup the highest stack usage. */ thread_ptr -> tx_thread_stack_highest_ptr = stack_ptr; }if (*stack_ptr != TX_STACK_FILL) { ... } }if (stack_ptr < (TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_stack_highest_ptr))) { ... } }if (stack_ptr > (TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_stack_start))) { ... } }if (thread_ptr -> tx_thread_id == TX_THREAD_ID) { ... } }if (stack_highest != TX_NULL) { ... } }if (stack_lowest != TX_NULL) { ... } }if (thread_ptr -> tx_thread_id == TX_THREAD_ID) { ... } }if (thread_ptr != TX_NULL) { ... } /* Restore interrupts. */ TX_RESTORE }{ ... }