GCC Code Coverage Report


Directory: common/src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 92 / 0 / 92
Functions: 100.0% 1 / 0 / 1
Branches: 100.0% 51 / 0 / 51

fx_system_timer_entry.c
Line Branch Exec Source
1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 * Copyright (c) 2026-present Eclipse ThreadX contributors
4 *
5 * This program and the accompanying materials are made available under the
6 * terms of the MIT License which is available at
7 * https://opensource.org/licenses/MIT.
8 *
9 * SPDX-License-Identifier: MIT
10 **************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** FileX Component */
17 /** */
18 /** System */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define FX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "fx_api.h"
29 #include "fx_system.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _fx_system_timer_entry PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function is FileX system timer function. It is called at the */
45 /* rate specified by FX_UPDATE_RATE_IN_SECONDS and is responsible for */
46 /* maintaining both the system date and time. */
47 /* */
48 /* INPUT */
49 /* */
50 /* id Not used */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* None */
55 /* */
56 /* CALLS */
57 /* */
58 /* None */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application Initialization */
63 /* */
64 /**************************************************************************/
65 2839017636 VOID _fx_system_timer_entry(ULONG id)
66 {
67
68 UINT second;
69 UINT minute;
70 UINT hour;
71 UINT day;
72 UINT month;
73 UINT year;
74
75
76 /* Determine if the ID is valid. */
77
2/2
✓ Branch 2 → 3 taken 2839017627 times.
✓ Branch 2 → 49 taken 9 times.
2839017636 if (id == FX_TIMER_ID)
78 {
79
80 /* Break the current date time into separate fields for easier work! */
81 2839017627 second = (_fx_system_time & FX_SECOND_MASK) * 2;
82 2839017627 minute = (_fx_system_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
83 2839017627 hour = (_fx_system_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
84 2839017627 day = _fx_system_date & FX_DAY_MASK;
85 2839017627 month = (_fx_system_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
86 2839017627 year = ((_fx_system_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) + FX_BASE_YEAR;
87
88 /* Now apply the "second" update. */
89 2839017627 second = second + FX_UPDATE_RATE_IN_SECONDS;
90
91 /* Determine if we need to adjust the minute field. */
92
2/2
✓ Branch 3 → 4 taken 644140802 times.
✓ Branch 3 → 48 taken 2194876825 times.
2839017627 if (second > FX_MAXIMUM_SECOND)
93 {
94
95 /* Yes, we need to adjust the minute field. */
96 644140802 minute = minute + second / 60;
97 644140802 second = second % 60;
98
99 /* Determine if we need to adjust the hour field. */
100
2/2
✓ Branch 4 → 5 taken 212481696 times.
✓ Branch 4 → 48 taken 431659106 times.
644140802 if (minute > FX_MAXIMUM_MINUTE)
101 {
102
103 /* Yes, we need to adjust the hour field. */
104 212481696 hour = hour + minute / 60;
105 212481696 minute = minute % 60;
106
107 /* Determine if we need to adjust the day field. */
108
2/2
✓ Branch 5 → 6 taken 205470284 times.
✓ Branch 5 → 48 taken 7011412 times.
212481696 if (hour > FX_MAXIMUM_HOUR)
109 {
110
111 /* Yes, we need to adjust the day field. */
112 205470284 hour = 0;
113 205470284 day++;
114
115 /* Determine if we need to adjust the month field. */
116
13/13
✓ Branch 6 → 7 taken 25668 times.
✓ Branch 6 → 10 taken 23393 times.
✓ Branch 6 → 16 taken 25916 times.
✓ Branch 6 → 19 taken 25080 times.
✓ Branch 6 → 22 taken 25916 times.
✓ Branch 6 → 25 taken 25080 times.
✓ Branch 6 → 28 taken 25916 times.
✓ Branch 6 → 31 taken 25916 times.
✓ Branch 6 → 34 taken 25080 times.
✓ Branch 6 → 37 taken 25916 times.
✓ Branch 6 → 40 taken 25080 times.
✓ Branch 6 → 43 taken 204413723 times.
✓ Branch 6 → 47 taken 777600 times.
205470284 switch (month)
117 {
118
119 25668 case 1: /* January */
120 {
121
122 /* Check for end of the month. */
123
2/2
✓ Branch 7 → 8 taken 828 times.
✓ Branch 7 → 9 taken 24840 times.
25668 if (day > 31)
124 {
125
126 /* Move to next month. */
127 828 day = 1;
128 828 month++;
129 }
130 25668 break;
131 }
132
133 23393 case 2: /* February */
134 {
135
136 /* Check for leap year. We don't need to check for leap
137 century her (century years divisible by 400) since 2000
138 is and this FAT format only supports years to 2107. */
139
2/2
✓ Branch 10 → 11 taken 5837 times.
✓ Branch 10 → 13 taken 17556 times.
23393 if ((year % 4) == 0)
140 {
141
142 /* Leap year in February... check for 29 days
143 instead of 28. */
144
2/2
✓ Branch 11 → 12 taken 209 times.
✓ Branch 11 → 15 taken 5628 times.
5837 if (day > 29)
145 {
146
147 /* Adjust the month. */
148 209 day = 1;
149 209 month++;
150 }
151 }
152 else
153 {
154
155
2/2
✓ Branch 13 → 14 taken 627 times.
✓ Branch 13 → 15 taken 16929 times.
17556 if (day > 28)
156 {
157
158 /* Adjust the month. */
159 627 day = 1;
160 627 month++;
161 }
162 }
163 23393 break;
164 }
165
166 25916 case 3: /* March */
167 {
168
169 /* Check for end of the month. */
170
2/2
✓ Branch 16 → 17 taken 836 times.
✓ Branch 16 → 18 taken 25080 times.
25916 if (day > 31)
171 {
172
173 /* Move to next month. */
174 836 day = 1;
175 836 month++;
176 }
177 25916 break;
178 }
179
180 25080 case 4: /* April */
181 {
182
183 /* Check for end of the month. */
184
2/2
✓ Branch 19 → 20 taken 836 times.
✓ Branch 19 → 21 taken 24244 times.
25080 if (day > 30)
185 {
186
187 /* Move to next month. */
188 836 day = 1;
189 836 month++;
190 }
191 25080 break;
192 }
193
194 25916 case 5: /* May */
195 {
196
197 /* Check for end of the month. */
198
2/2
✓ Branch 22 → 23 taken 836 times.
✓ Branch 22 → 24 taken 25080 times.
25916 if (day > 31)
199 {
200
201 /* Move to next month. */
202 836 day = 1;
203 836 month++;
204 }
205 25916 break;
206 }
207
208 25080 case 6: /* June */
209 {
210
211 /* Check for end of the month. */
212
2/2
✓ Branch 25 → 26 taken 836 times.
✓ Branch 25 → 27 taken 24244 times.
25080 if (day > 30)
213 {
214
215 /* Move to next month. */
216 836 day = 1;
217 836 month++;
218 }
219 25080 break;
220 }
221
222 25916 case 7: /* July */
223 {
224
225 /* Check for end of the month. */
226
2/2
✓ Branch 28 → 29 taken 836 times.
✓ Branch 28 → 30 taken 25080 times.
25916 if (day > 31)
227 {
228
229 /* Move to next month. */
230 836 day = 1;
231 836 month++;
232 }
233 25916 break;
234 }
235
236 25916 case 8: /* August */
237 {
238
239 /* Check for end of the month. */
240
2/2
✓ Branch 31 → 32 taken 836 times.
✓ Branch 31 → 33 taken 25080 times.
25916 if (day > 31)
241 {
242
243 /* Move to next month. */
244 836 day = 1;
245 836 month++;
246 }
247 25916 break;
248 }
249
250 25080 case 9: /* September */
251 {
252
253 /* Check for end of the month. */
254
2/2
✓ Branch 34 → 35 taken 836 times.
✓ Branch 34 → 36 taken 24244 times.
25080 if (day > 30)
255 {
256
257 /* Move to next month. */
258 836 day = 1;
259 836 month++;
260 }
261 25080 break;
262 }
263
264 25916 case 10: /* October */
265 {
266
267 /* Check for end of the month. */
268
2/2
✓ Branch 37 → 38 taken 836 times.
✓ Branch 37 → 39 taken 25080 times.
25916 if (day > 31)
269 {
270
271 /* Move to next month. */
272 836 day = 1;
273 836 month++;
274 }
275 25916 break;
276 }
277
278 25080 case 11: /* November */
279 {
280
281 /* Check for end of the month. */
282
2/2
✓ Branch 40 → 41 taken 836 times.
✓ Branch 40 → 42 taken 24244 times.
25080 if (day > 30)
283 {
284
285 /* Move to next month. */
286 836 day = 1;
287 836 month++;
288 }
289 25080 break;
290 }
291
292 204413723 case 12: /* December */
293 {
294
295 /* Check for end of the month. */
296
2/2
✓ Branch 43 → 44 taken 204388668 times.
✓ Branch 43 → 46 taken 25055 times.
204413723 if (day > 31)
297 {
298
299 /* Move to next month. */
300 204388668 day = 1;
301 204388668 month = 1;
302
303 /* Also move to next year. */
304 204388668 year++;
305
306 /* Check for a year that exceeds the representation
307 in this format. */
308
2/2
✓ Branch 44 → 45 taken 204387840 times.
✓ Branch 44 → 46 taken 828 times.
204388668 if (year > FX_MAXIMUM_YEAR)
309 {
310 204387840 return;
311 }
312 }
313 25883 break;
314 }
315
316 777600 default: /* Invalid month! */
317
318 777600 return; /* Skip updating date/time! */
319 }
320 }
321 }
322 }
323
324 /* Now apply the new setting to the internal representation. */
325
326 /* Set the system date. */
327 2633852187 _fx_system_date = ((year - FX_BASE_YEAR) << FX_YEAR_SHIFT) |
328 2633852187 (month << FX_MONTH_SHIFT) | day;
329
330 /* Set the new system time. */
331 2633852187 _fx_system_time = (hour << FX_HOUR_SHIFT) |
332 2633852187 (minute << FX_MINUTE_SHIFT) | (second / 2);
333 }
334 }
335
336