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_ENABLE_EVENT_TRACE
31 #include "tx_trace.h"
32 #endif
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _tx_timer_activate                                  PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    William E. Lamie, Microsoft Corporation                             */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function activates the specified application timer.            */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    timer_ptr                         Pointer to timer control block    */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    TX_SUCCESS                        Always returns success            */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _tx_timer_system_activate         Actual timer activation function  */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
70 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_tx_timer_activate(TX_TIMER * timer_ptr)74 UINT  _tx_timer_activate(TX_TIMER *timer_ptr)
75 {
76 
77 TX_INTERRUPT_SAVE_AREA
78 
79 UINT        status;
80 
81 
82     /* Disable interrupts to put the timer on the created list.  */
83     TX_DISABLE
84 
85 #ifdef TX_ENABLE_EVENT_TRACE
86 
87     /* If trace is enabled, insert this event into the trace buffer.  */
88     TX_TRACE_IN_LINE_INSERT(TX_TRACE_TIMER_ACTIVATE, timer_ptr, 0, 0, 0, TX_TRACE_TIMER_EVENTS)
89 #endif
90 
91 #ifdef TX_ENABLE_EVENT_LOGGING
92 
93     /* Log this kernel call.  */
94     TX_EL_TIMER_ACTIVATE_INSERT
95 #endif
96 
97     /* Check for an already active timer.  */
98     if (timer_ptr -> tx_timer_internal.tx_timer_internal_list_head != TX_NULL)
99     {
100 
101         /* Timer is already active, return an error.  */
102         status =  TX_ACTIVATE_ERROR;
103     }
104 
105     /* Check for a timer with a zero expiration.  */
106     else if (timer_ptr -> tx_timer_internal.tx_timer_internal_remaining_ticks == ((ULONG) 0))
107     {
108 
109         /* Timer is being activated with a zero expiration.  */
110         status =  TX_ACTIVATE_ERROR;
111     }
112     else
113     {
114 
115 #ifdef TX_TIMER_ENABLE_PERFORMANCE_INFO
116 
117         /* Increment the total activations counter.  */
118         _tx_timer_performance_activate_count++;
119 
120         /* Increment the number of activations on this timer.  */
121         timer_ptr -> tx_timer_performance_activate_count++;
122 #endif
123 
124         /* Call actual activation function.  */
125         _tx_timer_system_activate(&(timer_ptr -> tx_timer_internal));
126 
127         /* Return a successful status.  */
128         status =  TX_SUCCESS;
129     }
130 
131     /* Restore interrupts.  */
132     TX_RESTORE
133 
134     /* Return completion status.  */
135     return(status);
136 }
137 
138