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 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    tx_timer.h                                          PORTABLE C      */
29 /*                                                           6.1          */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    William E. Lamie, Microsoft Corporation                             */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the ThreadX timer management component, including */
37 /*    data types and external references.  It is assumed that tx_api.h    */
38 /*    and tx_port.h have already been included.                           */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
45 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
46 /*                                            resulting in version 6.1    */
47 /*                                                                        */
48 /**************************************************************************/
49 
50 #ifndef TX_TIMER_H
51 #define TX_TIMER_H
52 
53 
54 /* Define timer management specific data definitions.  */
55 
56 #define TX_TIMER_ID                             ((ULONG) 0x4154494D)
57 #define TX_TIMER_ENTRIES                        ((ULONG) 32)
58 
59 
60 /* Define internal timer management function prototypes.  */
61 
62 VOID        _tx_timer_expiration_process(VOID);
63 VOID        _tx_timer_initialize(VOID);
64 VOID        _tx_timer_system_activate(TX_TIMER_INTERNAL *timer_ptr);
65 VOID        _tx_timer_system_deactivate(TX_TIMER_INTERNAL *timer_ptr);
66 VOID        _tx_timer_thread_entry(ULONG timer_thread_input);
67 
68 
69 /* Timer management component data declarations follow.  */
70 
71 /* Determine if the initialization function of this component is including
72    this file.  If so, make the data definitions really happen.  Otherwise,
73    make them extern so other functions in the component can access them.  */
74 
75 #ifdef TX_TIMER_INIT
76 #define TIMER_DECLARE
77 #else
78 #define TIMER_DECLARE extern
79 #endif
80 
81 
82 /* Define the system clock value that is continually incremented by the
83    periodic timer interrupt processing.  */
84 
85 TIMER_DECLARE volatile ULONG    _tx_timer_system_clock;
86 
87 
88 /* Define the current time slice value.  If non-zero, a time-slice is active.
89    Otherwise, the time_slice is not active.  */
90 
91 TIMER_DECLARE ULONG             _tx_timer_time_slice;
92 
93 
94 /* Define the time-slice expiration flag.  This is used to indicate that a time-slice
95    has happened.  */
96 
97 TIMER_DECLARE UINT              _tx_timer_expired_time_slice;
98 
99 
100 /* Define the thread and application timer entry list.  This list provides a direct access
101    method for insertion of times less than TX_TIMER_ENTRIES.  */
102 
103 TIMER_DECLARE TX_TIMER_INTERNAL *_tx_timer_list[TX_TIMER_ENTRIES];
104 
105 
106 /* Define the boundary pointers to the list.  These are setup to easily manage
107    wrapping the list.  */
108 
109 TIMER_DECLARE TX_TIMER_INTERNAL **_tx_timer_list_start;
110 TIMER_DECLARE TX_TIMER_INTERNAL **_tx_timer_list_end;
111 
112 
113 /* Define the current timer pointer in the list.  This pointer is moved sequentially
114    through the timer list by the timer interrupt handler.  */
115 
116 TIMER_DECLARE TX_TIMER_INTERNAL **_tx_timer_current_ptr;
117 
118 
119 /* Define the timer expiration flag.  This is used to indicate that a timer
120    has expired.  */
121 
122 TIMER_DECLARE UINT              _tx_timer_expired;
123 
124 
125 /* Define the created timer list head pointer.  */
126 
127 TIMER_DECLARE TX_TIMER          *_tx_timer_created_ptr;
128 
129 
130 /* Define the created timer count.  */
131 
132 TIMER_DECLARE ULONG             _tx_timer_created_count;
133 
134 
135 /* Define the pointer to the timer that has expired and is being processed.  */
136 
137 TIMER_DECLARE TX_TIMER_INTERNAL *_tx_timer_expired_timer_ptr;
138 
139 
140 #ifndef TX_TIMER_PROCESS_IN_ISR
141 
142 /* Define the timer thread's control block.  */
143 
144 TIMER_DECLARE TX_THREAD         _tx_timer_thread;
145 
146 
147 /* Define the variable that holds the timer thread's starting stack address.  */
148 
149 TIMER_DECLARE VOID              *_tx_timer_stack_start;
150 
151 
152 /* Define the variable that holds the timer thread's stack size.  */
153 
154 TIMER_DECLARE ULONG             _tx_timer_stack_size;
155 
156 
157 /* Define the variable that holds the timer thread's priority.  */
158 
159 TIMER_DECLARE UINT              _tx_timer_priority;
160 
161 /* Define the system timer thread's stack.   The default size is defined
162    in tx_port.h.  */
163 
164 TIMER_DECLARE ULONG             _tx_timer_thread_stack_area[(((UINT) TX_TIMER_THREAD_STACK_SIZE)+((sizeof(ULONG)) - ((UINT) 1)))/sizeof(ULONG)];
165 
166 #else
167 
168 
169 /* Define the busy flag that will prevent nested timer ISR processing.  */
170 
171 TIMER_DECLARE UINT              _tx_timer_processing_active;
172 
173 #endif
174 
175 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
176 
177 /* Define the total number of timer activations.  */
178 
179 TIMER_DECLARE  ULONG            _tx_timer_performance_activate_count;
180 
181 
182 /* Define the total number of timer reactivations.  */
183 
184 TIMER_DECLARE  ULONG            _tx_timer_performance_reactivate_count;
185 
186 
187 /* Define the total number of timer deactivations.  */
188 
189 TIMER_DECLARE  ULONG            _tx_timer_performance_deactivate_count;
190 
191 
192 /* Define the total number of timer expirations.  */
193 
194 TIMER_DECLARE  ULONG            _tx_timer_performance_expiration_count;
195 
196 
197 /* Define the total number of timer expiration adjustments. These are required
198    if the expiration time is greater than the size of the timer list. In such
199    cases, the timer is placed at the end of the list and then reactivated
200    as many times as necessary to finally achieve the resulting timeout. */
201 
202 TIMER_DECLARE  ULONG            _tx_timer_performance__expiration_adjust_count;
203 
204 
205 #endif
206 
207 
208 /* Define default post timer delete macro to whitespace, if it hasn't been defined previously (typically in tx_port.h).  */
209 
210 #ifndef TX_TIMER_DELETE_PORT_COMPLETION
211 #define TX_TIMER_DELETE_PORT_COMPLETION(t)
212 #endif
213 
214 
215 #endif
216