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 /** GUIX Component                                                        */
17 /**                                                                       */
18 /**   System Management (System)                                          */
19 /**                                                                       */
20 /**************************************************************************/
21 
22 #define GX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "gx_api.h"
28 #include "gx_system.h"
29 #include "gx_animation.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _gx_system_timer_update                             PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Kenneth Maxwell, Microsoft Corporation                              */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is called when the GUIX timers need to be updated.    */
45 /*    It updates all of the GUIX application timers, and sends events     */
46 /*    as needed.                                                          */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    None                                                                */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    None                                                                */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*   _gx_system_lock                        Lock system mutex             */
59 /*   _gx_system_unlock                      Unlock system mutex           */
60 /*   [gx_widget_event_process_function]     Event handler of timer owner  */
61 /*   _gx_system_timer_stop                  Stop the system timer         */
62 /*   _gx_animation_update                   Update the animation sequence */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    tx_timer                                                            */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Kenneth Maxwell          Initial Version 6.0           */
73 /*  09-30-2020     Kenneth Maxwell          Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_gx_system_timer_update(ULONG ticks)77 VOID  _gx_system_timer_update(ULONG ticks)
78 {
79 GX_TIMER  *current_timer;
80 GX_TIMER  *next_timer;
81 GX_WIDGET *timer_owner;
82 UINT       timer_id;
83 GX_EVENT   timer_event;
84 
85 GX_ENTER_CRITICAL
86 
87     current_timer = _gx_system_active_timer_list;
88 
89     timer_event.gx_event_type = GX_EVENT_TIMER;
90 
91     while (current_timer)
92     {
93         next_timer = current_timer -> gx_timer_next;
94 
95         /* has this timer expired? */
96         if (current_timer -> gx_timer_initial_ticks > ticks)
97         {
98             /* just decrement the timer */
99             current_timer -> gx_timer_initial_ticks -= ticks;
100         }
101         else
102         {
103             /* timer has expired, call the timer owner's event handler */
104             timer_owner = current_timer -> gx_timer_owner;
105             timer_id = current_timer -> gx_timer_id;
106 
107             /* check to see if this timer should be removed or restarted */
108 
109             if (current_timer -> gx_timer_reschedule_ticks > 0)
110             {
111                 /* reload the timer */
112                 current_timer -> gx_timer_initial_ticks = current_timer -> gx_timer_reschedule_ticks;
113             }
114             else
115             {
116                 /* remove the timer */
117                 _gx_system_timer_stop(current_timer -> gx_timer_owner, current_timer -> gx_timer_id);
118             }
119 
120             if (timer_owner != GX_NULL && timer_owner -> gx_widget_event_process_function)
121             {
122                 timer_event.gx_event_payload.gx_event_timer_id = timer_id;
123                 timer_event.gx_event_target = timer_owner;
124                 /*_gx_system_event_fold(&timer_event);*/
125                 _gx_system_event_send(&timer_event);
126             }
127         }
128         current_timer = next_timer;
129     }
130 
131     if (_gx_system_animation_list)
132     {
133         _gx_animation_update();
134     }
135 
136     /* release our lock */
137     GX_EXIT_CRITICAL
138 }
139 
140