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_trace.h"
30 #include "tx_timer.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _tx_timer_delete PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* William E. Lamie, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function deletes the specified application timer. */
46 /* */
47 /* INPUT */
48 /* */
49 /* timer_ptr Pointer to timer control block */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* TX_SUCCESS Successful completion status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _tx_timer_system_deactivate Timer deactivation function */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* Application Code */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
68 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
69 /* resulting in version 6.1 */
70 /* */
71 /**************************************************************************/
_tx_timer_delete(TX_TIMER * timer_ptr)72 UINT _tx_timer_delete(TX_TIMER *timer_ptr)
73 {
74
75 TX_INTERRUPT_SAVE_AREA
76
77 TX_TIMER *next_timer;
78 TX_TIMER *previous_timer;
79
80
81 /* Disable interrupts to remove the timer from the created list. */
82 TX_DISABLE
83
84 /* Determine if the timer needs to be deactivated. */
85 if (timer_ptr -> tx_timer_internal.tx_timer_internal_list_head != TX_NULL)
86 {
87
88 /* Yes, deactivate the timer before it is deleted. */
89 _tx_timer_system_deactivate(&(timer_ptr -> tx_timer_internal));
90 }
91
92 /* If trace is enabled, insert this event into the trace buffer. */
93 TX_TRACE_IN_LINE_INSERT(TX_TRACE_TIMER_DELETE, timer_ptr, 0, 0, 0, TX_TRACE_TIMER_EVENTS)
94
95 /* Optional timer delete extended processing. */
96 TX_TIMER_DELETE_EXTENSION(timer_ptr)
97
98 /* If trace is enabled, unregister this object. */
99 TX_TRACE_OBJECT_UNREGISTER(timer_ptr)
100
101 /* Log this kernel call. */
102 TX_EL_TIMER_DELETE_INSERT
103
104 /* Clear the timer ID to make it invalid. */
105 timer_ptr -> tx_timer_id = TX_CLEAR_ID;
106
107 /* Decrement the number of created timers. */
108 _tx_timer_created_count--;
109
110 /* See if the timer is the only one on the list. */
111 if (_tx_timer_created_count == TX_EMPTY)
112 {
113
114 /* Only created timer, just set the created list to NULL. */
115 _tx_timer_created_ptr = TX_NULL;
116 }
117 else
118 {
119
120 /* Link-up the neighbors. */
121 next_timer = timer_ptr -> tx_timer_created_next;
122 previous_timer = timer_ptr -> tx_timer_created_previous;
123 next_timer -> tx_timer_created_previous = previous_timer;
124 previous_timer -> tx_timer_created_next = next_timer;
125
126 /* See if we have to update the created list head pointer. */
127 if (_tx_timer_created_ptr == timer_ptr)
128 {
129
130 /* Yes, move the head pointer to the next link. */
131 _tx_timer_created_ptr = next_timer;
132 }
133 }
134
135 /* Execute Port-Specific completion processing. If needed, it is typically defined in tx_port.h. */
136 TX_TIMER_DELETE_PORT_COMPLETION(timer_ptr)
137
138 /* Restore interrupts. */
139 TX_RESTORE
140
141 /* Return TX_SUCCESS. */
142 return(TX_SUCCESS);
143 }
144
145