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 /**   Timer                                                               */
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_timer_delete                                   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 delete application timer     */
46 /*    function call.                                                      */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    timer_ptr                         Pointer to timer control block    */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    TX_TIMER_ERROR                    Invalid application timer pointer */
55 /*    TX_CALLER_ERROR                   Invalid caller of this function   */
56 /*    status                            Actual completion status          */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _tx_timer_delete                  Actual timer delete function      */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
71 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_txe_timer_delete(TX_TIMER * timer_ptr)75 UINT  _txe_timer_delete(TX_TIMER *timer_ptr)
76 {
77 
78 UINT            status;
79 #ifndef TX_TIMER_PROCESS_IN_ISR
80 TX_THREAD       *thread_ptr;
81 #endif
82 
83 
84 #ifndef TX_TIMER_PROCESS_IN_ISR
85 
86     /* Default status to success.  */
87     status =  TX_SUCCESS;
88 #endif
89 
90     /* Check for an invalid timer pointer.  */
91     if (timer_ptr == TX_NULL)
92     {
93         /* Timer pointer is invalid, return appropriate error code.  */
94         status =  TX_TIMER_ERROR;
95     }
96 
97     /* Now check for invalid timer ID.  */
98     else if (timer_ptr -> tx_timer_id != TX_TIMER_ID)
99     {
100         /* Timer pointer is invalid, return appropriate error code.  */
101         status =  TX_TIMER_ERROR;
102     }
103 
104     /* Check for invalid caller of this function.  */
105 
106     /* Is the caller an ISR or Initialization?  */
107     else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
108     {
109 
110         /* Invalid caller of this function, return appropriate error code.  */
111         status =  TX_CALLER_ERROR;
112     }
113     else
114     {
115 
116 #ifndef TX_TIMER_PROCESS_IN_ISR
117 
118         /* Pickup thread pointer.  */
119         TX_THREAD_GET_CURRENT(thread_ptr)
120 
121         /* Is the caller the system timer thread?  */
122         if (thread_ptr == &_tx_timer_thread)
123         {
124 
125             /* Invalid caller of this function, return appropriate error code.  */
126             status =  TX_CALLER_ERROR;
127         }
128 
129         /* Determine if everything is okay.  */
130         if (status == TX_SUCCESS)
131         {
132 #endif
133 
134             /* Call actual application timer delete function.  */
135             status =  _tx_timer_delete(timer_ptr);
136 
137 #ifndef TX_TIMER_PROCESS_IN_ISR
138         }
139 #endif
140     }
141 
142     /* Return completion status.  */
143     return(status);
144 }
145 
146