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 #include "tx_timer.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _txe_thread_reset                                   PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the thread reset function call.  */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    thread_ptr                            Pointer to thread to reset    */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    TX_THREAD_ERROR                       Invalid thread pointer        */
54 /*    TX_CALLER_ERROR                       Invalid caller of function    */
55 /*    status                                Service return status         */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _tx_thread_reset                      Actual thread reset function  */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
70 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_txe_thread_reset(TX_THREAD * thread_ptr)74 UINT  _txe_thread_reset(TX_THREAD *thread_ptr)
75 {
76 
77 UINT        status;
78 #ifndef TX_TIMER_PROCESS_IN_ISR
79 TX_THREAD   *current_thread;
80 #endif
81 
82 
83     /* Default status to success.  */
84     status =  TX_SUCCESS;
85 
86     /* Check for an invalid thread pointer.  */
87     if (thread_ptr == TX_NULL)
88     {
89 
90         /* Thread pointer is invalid, return appropriate error code.  */
91         status =  TX_THREAD_ERROR;
92     }
93 
94     /* Now check for an invalid thread ID.  */
95     else if (thread_ptr -> tx_thread_id != TX_THREAD_ID)
96     {
97 
98         /* Thread pointer is invalid, return appropriate error code.  */
99         status =  TX_THREAD_ERROR;
100     }
101     else
102     {
103 
104 #ifndef TX_TIMER_PROCESS_IN_ISR
105 
106         /* Pickup thread pointer.  */
107         TX_THREAD_GET_CURRENT(current_thread)
108 
109         /* Check for invalid caller of this function.  First check for a calling thread.  */
110         if (current_thread == &_tx_timer_thread)
111         {
112 
113             /* Invalid caller of this function, return appropriate error code.  */
114             status =  TX_CALLER_ERROR;
115         }
116 #endif
117 
118         /* Check for interrupt or initialization call.  */
119         if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
120         {
121 
122             /* Invalid caller of this function, return appropriate error code.  */
123             status =  TX_CALLER_ERROR;
124         }
125     }
126 
127     /* Determine if everything is okay.  */
128     if (status == TX_SUCCESS)
129     {
130 
131         /* Call actual thread reset function.  */
132         status =  _tx_thread_reset(thread_ptr);
133     }
134 
135     /* Return completion status.  */
136     return(status);
137 }
138 
139