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 /** GUIX Component                                                        */
16 /**                                                                       */
17 /**   System Management (System)                                          */
18 /**                                                                       */
19 /**************************************************************************/
20 
21 #define GX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "gx_api.h"
27 #include "gx_system.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _gx_system_timer_stop                               PORTABLE C      */
35 /*                                                           6.1.3        */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Kenneth Maxwell, Microsoft Corporation                              */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This service stops the timer for the specified widget.              */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    owner                                 Pointer to widget control     */
47 /*                                            block                       */
48 /*    timer_id                              ID of timer                   */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    status                                Completion status             */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _gx_system_lock                       lock critical section         */
57 /*    _gx_system_unlock                     unlock critical section       */
58 /*    tx_timer_deactivate                   stop the ThreadX timer        */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    GUIX Application                                                    */
63 /*    GUIX Internal Code                                                  */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
70 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*  12-31-2020     Kenneth Maxwell          Modified comment(s),          */
73 /*                                            added GX_DISABLE_THREADX_   */
74 /*                                            TIMER_SOURCE configuration, */
75 /*                                            resulting in version 6.1.3  */
76 /*                                                                        */
77 /**************************************************************************/
_gx_system_timer_stop(GX_WIDGET * owner,UINT timer_id)78 UINT _gx_system_timer_stop(GX_WIDGET *owner, UINT timer_id)
79 {
80 UINT      status = GX_FAILURE;
81 GX_TIMER *next_timer;
82 GX_TIMER *previous_timer = GX_NULL;
83 GX_TIMER *search;
84 
85     GX_ENTER_CRITICAL
86 
87     /* find the timer in our active list */
88     search = _gx_system_active_timer_list;
89 
90     while (search)
91     {
92         /* save point to next active timer */
93         next_timer = search -> gx_timer_next;
94 
95         /* is this timer owned by caller? */
96         if (search -> gx_timer_owner == owner)
97         {
98             /* is this the requested timer? */
99             if (timer_id == 0 || search -> gx_timer_id == timer_id)
100             {
101                 /* save status that we found at least one timer */
102                 status = GX_SUCCESS;
103 
104                 /* If timer we found is first in active list, update list head */
105                 if (previous_timer == GX_NULL)
106                 {
107                     _gx_system_active_timer_list = search -> gx_timer_next;
108                 }
109                 else
110                 {
111                     previous_timer -> gx_timer_next = search -> gx_timer_next;
112                 }
113 
114                 /* add this timer to head of free list */
115                 search -> gx_timer_next = _gx_system_free_timer_list;
116                 _gx_system_free_timer_list = search;
117 
118                 /* if just looking for one timer, we are done */
119                 if (timer_id != 0)
120                 {
121                     break;
122                 }
123                 else
124                 {
125                     search = previous_timer;
126                 }
127             }
128         }
129 
130         /* advance search to next active timer */
131         previous_timer = search;
132         search = next_timer;
133 
134     }
135     GX_EXIT_CRITICAL
136 
137     /* if our active list is NULL, then stop the tx_timer */
138 
139     if (_gx_system_active_timer_list == GX_NULL &&
140         _gx_system_animation_list == GX_NULL)
141     {
142 #ifdef GX_THREADX_BINDING
143 #ifndef GX_DISABLE_THREADX_TIMER_SOURCE
144         tx_timer_deactivate(&_gx_system_timer);
145 #endif
146 #else
147         GX_TIMER_STOP;
148 #endif
149     }
150     return status;
151 }
152 
153