1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Thread */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define TX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "tx_api.h"
29 #include "tx_thread.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _tx_thread_shell_entry PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function calls the specified entry function of the thread. It */
45 /* also provides a place for the thread's entry function to return. */
46 /* If the thread returns, this function places the thread in a */
47 /* "COMPLETED" state. */
48 /* */
49 /* INPUT */
50 /* */
51 /* None */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* None */
56 /* */
57 /* CALLS */
58 /* */
59 /* thread_entry Thread's entry function */
60 /* _tx_thread_system_suspend Thread suspension routine */
61 /* _tx_thread_system_ni_suspend Non-interruptable suspend thread */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Initial thread stack frame */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
72 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* */
75 /**************************************************************************/
_tx_thread_shell_entry(VOID)76 VOID _tx_thread_shell_entry(VOID)
77 {
78
79 TX_INTERRUPT_SAVE_AREA
80
81 TX_THREAD *thread_ptr;
82 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
83 VOID (*entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT type);
84 #endif
85
86
87 /* Pickup thread pointer. */
88 TX_THREAD_GET_CURRENT(thread_ptr)
89
90 /* Perform any additional activities for tool or user purpose. */
91 TX_THREAD_STARTED_EXTENSION(thread_ptr)
92
93 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
94
95 /* Disable interrupts. */
96 TX_DISABLE
97
98 /* Pickup the entry/exit application callback routine. */
99 entry_exit_notify = thread_ptr -> tx_thread_entry_exit_notify;
100
101 /* Restore interrupts. */
102 TX_RESTORE
103
104 /* Determine if an application callback routine is specified. */
105 if (entry_exit_notify != TX_NULL)
106 {
107
108 /* Yes, notify application that this thread has been entered! */
109 (entry_exit_notify)(thread_ptr, TX_THREAD_ENTRY);
110 }
111 #endif
112
113 /* Call current thread's entry function. */
114 (thread_ptr -> tx_thread_entry) (thread_ptr -> tx_thread_entry_parameter);
115
116 /* Suspend thread with a "completed" state. */
117
118 /* Determine if the application is using mutexes. */
119 if (_tx_thread_mutex_release != TX_NULL)
120 {
121
122 /* Yes, call the mutex release function via a function pointer that
123 is setup during mutex initialization. */
124 (_tx_thread_mutex_release)(thread_ptr);
125 }
126
127 /* Lockout interrupts while the thread state is setup. */
128 TX_DISABLE
129
130 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
131
132 /* Pickup the entry/exit application callback routine again. */
133 entry_exit_notify = thread_ptr -> tx_thread_entry_exit_notify;
134 #endif
135
136 /* Set the status to suspending, in order to indicate the suspension
137 is in progress. */
138 thread_ptr -> tx_thread_state = TX_COMPLETED;
139
140 /* Thread state change. */
141 TX_THREAD_STATE_CHANGE(thread_ptr, TX_COMPLETED)
142
143 #ifdef TX_NOT_INTERRUPTABLE
144
145 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
146
147 /* Determine if an application callback routine is specified. */
148 if (entry_exit_notify != TX_NULL)
149 {
150
151 /* Yes, notify application that this thread has exited! */
152 (entry_exit_notify)(thread_ptr, TX_THREAD_EXIT);
153 }
154 #endif
155
156 /* Perform any additional activities for tool or user purpose. */
157 TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
158
159 /* Call actual non-interruptable thread suspension routine. */
160 _tx_thread_system_ni_suspend(thread_ptr, ((ULONG) 0));
161
162 /* Restore interrupts. */
163 TX_RESTORE
164 #else
165
166 /* Set the suspending flag. */
167 thread_ptr -> tx_thread_suspending = TX_TRUE;
168
169 /* Setup for no timeout period. */
170 thread_ptr -> tx_thread_timer.tx_timer_internal_remaining_ticks = ((ULONG) 0);
171
172 /* Temporarily disable preemption. */
173 _tx_thread_preempt_disable++;
174
175 /* Restore interrupts. */
176 TX_RESTORE
177
178 /* Perform any additional activities for tool or user purpose. */
179 TX_THREAD_COMPLETED_EXTENSION(thread_ptr)
180
181 #ifndef TX_DISABLE_NOTIFY_CALLBACKS
182
183 /* Determine if an application callback routine is specified. */
184 if (entry_exit_notify != TX_NULL)
185 {
186
187 /* Yes, notify application that this thread has exited! */
188 (entry_exit_notify)(thread_ptr, TX_THREAD_EXIT);
189 }
190 #endif
191
192 /* Call actual thread suspension routine. */
193 _tx_thread_system_suspend(thread_ptr);
194 #endif
195
196
197 #ifdef TX_SAFETY_CRITICAL
198
199 /* If we ever get here, raise safety critical exception. */
200 TX_SAFETY_CRITICAL_EXCEPTION(__FILE__, __LINE__, 0);
201 #endif
202 }
203
204