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