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_start PORTABLE C */ |
35 |
|
|
/* 6.1.7 */ |
36 |
|
|
/* AUTHOR */ |
37 |
|
|
/* */ |
38 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
39 |
|
|
/* */ |
40 |
|
|
/* DESCRIPTION */ |
41 |
|
|
/* */ |
42 |
|
|
/* This service starts a timer for the specified widget. */ |
43 |
|
|
/* */ |
44 |
|
|
/* INPUT */ |
45 |
|
|
/* */ |
46 |
|
|
/* owner Pointer to widget control */ |
47 |
|
|
/* block */ |
48 |
|
|
/* timer_id ID of timer */ |
49 |
|
|
/* initial ticks Initial expiration ticks */ |
50 |
|
|
/* reschedule_ticks Periodic expiration ticks */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* status Completion status */ |
55 |
|
|
/* */ |
56 |
|
|
/* CALLS */ |
57 |
|
|
/* */ |
58 |
|
|
/* tx_timer_activate start the ThreadX timer */ |
59 |
|
|
/* _gx_system_lock lock system mutex */ |
60 |
|
|
/* _gx_system_unlock unlock system mutex */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLED BY */ |
63 |
|
|
/* */ |
64 |
|
|
/* GUIX Application */ |
65 |
|
|
/* GUIX Internal Code */ |
66 |
|
|
/* */ |
67 |
|
|
/* RELEASE HISTORY */ |
68 |
|
|
/* */ |
69 |
|
|
/* DATE NAME DESCRIPTION */ |
70 |
|
|
/* */ |
71 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
72 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
73 |
|
|
/* resulting in version 6.1 */ |
74 |
|
|
/* 12-31-2020 Kenneth Maxwell Modified comment(s), */ |
75 |
|
|
/* added GX_DISABLE_THREADX_ */ |
76 |
|
|
/* TIMER_SOURCE configuration, */ |
77 |
|
|
/* resulting in version 6.1.3 */ |
78 |
|
|
/* 06-02-2021 Ting Zhu Modified comment(s), */ |
79 |
|
|
/* fixed compile warning when */ |
80 |
|
|
/* ThreadX timer is disabled, */ |
81 |
|
|
/* resulting in version 6.1.7 */ |
82 |
|
|
/* */ |
83 |
|
|
/**************************************************************************/ |
84 |
|
835 |
UINT _gx_system_timer_start(GX_WIDGET *owner, UINT timer_id, UINT initial_ticks, UINT reschedule_ticks) |
85 |
|
|
{ |
86 |
|
|
GX_TIMER *found; |
87 |
|
|
|
88 |
|
|
#ifdef GX_THREADX_BINDING |
89 |
|
|
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE |
90 |
|
|
UINT tx_timer_active; |
91 |
|
|
#endif |
92 |
|
|
#endif |
93 |
|
|
|
94 |
|
|
/* check for bad widget pointer */ |
95 |
✓✓ |
835 |
if (!owner) |
96 |
|
|
{ |
97 |
|
1 |
return GX_PTR_ERROR; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
/* lock entering critical section */ |
101 |
|
834 |
GX_ENTER_CRITICAL |
102 |
|
|
|
103 |
|
|
/* check for already having this timer */ |
104 |
|
834 |
found = _gx_system_active_timer_list; |
105 |
|
|
|
106 |
✓✓ |
1124 |
while (found) |
107 |
|
|
{ |
108 |
✓✓ |
331 |
if (found -> gx_timer_id == timer_id && |
109 |
✓✓ |
284 |
found -> gx_timer_owner == owner) |
110 |
|
|
{ |
111 |
|
|
/* yes, this timer is already running */ |
112 |
|
|
/* reset the existing timer value and return */ |
113 |
|
41 |
found -> gx_timer_initial_ticks = initial_ticks; |
114 |
|
41 |
found -> gx_timer_reschedule_ticks = reschedule_ticks; |
115 |
|
41 |
GX_EXIT_CRITICAL |
116 |
|
41 |
return GX_SUCCESS; |
117 |
|
|
} |
118 |
|
290 |
found = found -> gx_timer_next; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
/* check for having timer available */ |
122 |
✓✓ |
793 |
if (!_gx_system_free_timer_list) |
123 |
|
|
{ |
124 |
|
|
/* no timers available, unlock and return error */ |
125 |
|
1 |
GX_EXIT_CRITICAL |
126 |
|
1 |
return GX_OUT_OF_TIMERS; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
/* we have a free timer, remove from free list */ |
130 |
|
792 |
found = _gx_system_free_timer_list; |
131 |
|
792 |
_gx_system_free_timer_list = found -> gx_timer_next; |
132 |
|
|
|
133 |
|
|
/* initialize new timer */ |
134 |
|
792 |
found -> gx_timer_initial_ticks = initial_ticks; |
135 |
|
792 |
found -> gx_timer_reschedule_ticks = reschedule_ticks; |
136 |
|
792 |
found -> gx_timer_id = timer_id; |
137 |
|
792 |
found -> gx_timer_owner = owner; |
138 |
|
|
|
139 |
|
|
/* link this timer at the head of the active list */ |
140 |
|
792 |
found -> gx_timer_next = _gx_system_active_timer_list; |
141 |
|
792 |
_gx_system_active_timer_list = found; |
142 |
|
|
|
143 |
|
|
#ifdef GX_THREADX_BINDING |
144 |
|
|
#ifndef GX_DISABLE_THREADX_TIMER_SOURCE |
145 |
|
|
/* if the low-level timer is not active, start it */ |
146 |
|
792 |
tx_timer_info_get(&_gx_system_timer, (CHAR **)TX_NULL, &tx_timer_active, |
147 |
|
|
(ULONG *)TX_NULL, (ULONG *)TX_NULL, (TX_TIMER **)TX_NULL); |
148 |
|
|
|
149 |
✓✓ |
792 |
if (!tx_timer_active) |
150 |
|
|
{ |
151 |
|
431 |
tx_timer_activate(&_gx_system_timer); |
152 |
|
|
} |
153 |
|
|
#endif |
154 |
|
|
#else |
155 |
|
|
GX_TIMER_START; |
156 |
|
|
#endif |
157 |
|
|
|
158 |
|
|
/* release our lock */ |
159 |
|
792 |
GX_EXIT_CRITICAL |
160 |
|
792 |
return GX_SUCCESS; |
161 |
|
|
} |
162 |
|
|
|