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_timer.h"
30 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
31 #include "tx_trace.h"
32 #endif
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _tx_timer_performance_info_get                      PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    William E. Lamie, Microsoft Corporation                             */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function retrieves performance information from the specified  */
48 /*    timer.                                                              */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    timer_ptr                         Pointer to timer control block    */
53 /*    activates                         Destination for the number of     */
54 /*                                        activations of this timer       */
55 /*    reactivates                       Destination for the number of     */
56 /*                                        reactivations of this timer     */
57 /*    deactivates                       Destination for the number of     */
58 /*                                        deactivations of this timer     */
59 /*    expirations                       Destination for the number of     */
60 /*                                        expirations of this timer       */
61 /*    expiration_adjusts                Destination for the number of     */
62 /*                                        expiration adjustments of this  */
63 /*                                        timer                           */
64 /*                                                                        */
65 /*  OUTPUT                                                                */
66 /*                                                                        */
67 /*    status                            Completion status                 */
68 /*                                                                        */
69 /*  CALLS                                                                 */
70 /*                                                                        */
71 /*    None                                                                */
72 /*                                                                        */
73 /*  CALLED BY                                                             */
74 /*                                                                        */
75 /*    Application Code                                                    */
76 /*                                                                        */
77 /*  RELEASE HISTORY                                                       */
78 /*                                                                        */
79 /*    DATE              NAME                      DESCRIPTION             */
80 /*                                                                        */
81 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
82 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
83 /*                                            resulting in version 6.1    */
84 /*                                                                        */
85 /**************************************************************************/
_tx_timer_performance_info_get(TX_TIMER * timer_ptr,ULONG * activates,ULONG * reactivates,ULONG * deactivates,ULONG * expirations,ULONG * expiration_adjusts)86 UINT  _tx_timer_performance_info_get(TX_TIMER *timer_ptr, ULONG *activates, ULONG *reactivates,
87                     ULONG *deactivates, ULONG *expirations, ULONG *expiration_adjusts)
88 {
89 
90 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
91 
92 TX_INTERRUPT_SAVE_AREA
93 UINT                    status;
94 
95 
96     /* Determine if this is a legal request.  */
97     if (timer_ptr == TX_NULL)
98     {
99 
100         /* Timer pointer is illegal, return error.  */
101         status =  TX_PTR_ERROR;
102     }
103 
104     /* Determine if the timer ID is invalid.  */
105     else if (timer_ptr -> tx_timer_id != TX_TIMER_ID)
106     {
107 
108         /* Timer pointer is illegal, return error.  */
109         status =  TX_PTR_ERROR;
110     }
111     else
112     {
113 
114         /* Disable interrupts.  */
115         TX_DISABLE
116 
117         /* If trace is enabled, insert this event into the trace buffer.  */
118         TX_TRACE_IN_LINE_INSERT(TX_TRACE_TIMER_PERFORMANCE_INFO_GET, timer_ptr, 0, 0, 0, TX_TRACE_TIMER_EVENTS)
119 
120         /* Log this kernel call.  */
121         TX_EL_TIMER_PERFORMANCE_INFO_GET_INSERT
122 
123         /* Retrieve the number of activations of this timer.  */
124         if (activates != TX_NULL)
125         {
126 
127             *activates =  timer_ptr -> tx_timer_performance_activate_count;
128         }
129 
130         /* Retrieve the number of reactivations of this timer.  */
131         if (reactivates != TX_NULL)
132         {
133 
134             *reactivates =  timer_ptr -> tx_timer_performance_reactivate_count;
135         }
136 
137         /* Retrieve the number of deactivations of this timer.  */
138         if (deactivates != TX_NULL)
139         {
140 
141             *deactivates =  timer_ptr -> tx_timer_performance_deactivate_count;
142         }
143 
144         /* Retrieve the number of expirations of this timer.  */
145         if (expirations != TX_NULL)
146         {
147 
148             *expirations =  timer_ptr -> tx_timer_performance_expiration_count;
149         }
150 
151         /* Retrieve the number of expiration adjustments of this timer.  */
152         if (expiration_adjusts != TX_NULL)
153         {
154 
155             *expiration_adjusts =  timer_ptr -> tx_timer_performance__expiration_adjust_count;
156         }
157 
158         /* Restore interrupts.  */
159         TX_RESTORE
160 
161         /* Return successful completion.  */
162         status =  TX_SUCCESS;
163     }
164 #else
165 UINT                    status;
166 
167 
168     /* Access input arguments just for the sake of lint, MISRA, etc.  */
169     if (timer_ptr != TX_NULL)
170     {
171 
172         /* Not enabled, return error.  */
173         status =  TX_FEATURE_NOT_ENABLED;
174     }
175     else if (activates != TX_NULL)
176     {
177 
178         /* Not enabled, return error.  */
179         status =  TX_FEATURE_NOT_ENABLED;
180     }
181     else if (reactivates != TX_NULL)
182     {
183 
184         /* Not enabled, return error.  */
185         status =  TX_FEATURE_NOT_ENABLED;
186     }
187     else if (deactivates != TX_NULL)
188     {
189 
190         /* Not enabled, return error.  */
191         status =  TX_FEATURE_NOT_ENABLED;
192     }
193     else if (expirations != TX_NULL)
194     {
195 
196         /* Not enabled, return error.  */
197         status =  TX_FEATURE_NOT_ENABLED;
198     }
199     else if (expiration_adjusts != TX_NULL)
200     {
201 
202         /* Not enabled, return error.  */
203         status =  TX_FEATURE_NOT_ENABLED;
204     }
205     else
206     {
207 
208         /* Not enabled, return error.  */
209         status =  TX_FEATURE_NOT_ENABLED;
210     }
211 #endif
212 
213     /* Return completion status.  */
214     return(status);
215 }
216 
217