GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_system_timer_entry.c Lines: 92 92 100.0 %
Date: 2026-03-06 18:49:02 Branches: 51 51 100.0 %

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
315446405
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
315446405
    if (id == FX_TIMER_ID)
78
    {
79
80
        /* Break the current date time into separate fields for easier work!  */
81
315446404
        second =  (_fx_system_time & FX_SECOND_MASK) * 2;
82
315446404
        minute =  (_fx_system_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
83
315446404
        hour =    (_fx_system_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
84
315446404
        day =     _fx_system_date & FX_DAY_MASK;
85
315446404
        month =   (_fx_system_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
86
315446404
        year =    ((_fx_system_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) + FX_BASE_YEAR;
87
88
        /* Now apply the "second" update.  */
89
315446404
        second =  second + FX_UPDATE_RATE_IN_SECONDS;
90
91
        /* Determine if we need to adjust the minute field.  */
92
315446404
        if (second > FX_MAXIMUM_SECOND)
93
        {
94
95
            /* Yes, we need to adjust the minute field.  */
96
73936801
            minute =  minute + second / 60;
97
73936801
            second =  second % 60;
98
99
            /* Determine if we need to adjust the hour field.  */
100
73936801
            if (minute > FX_MAXIMUM_MINUTE)
101
            {
102
103
                /* Yes, we need to adjust the hour field.  */
104
26439913
                hour =    hour + minute / 60;
105
26439913
                minute =  minute % 60;
106
107
                /* Determine if we need to adjust the day field.  */
108
26439913
                if (hour > FX_MAXIMUM_HOUR)
109
                {
110
111
                    /* Yes, we need to adjust the day field.  */
112
25668424
                    hour =  0;
113
25668424
                    day++;
114
115
                    /* Determine if we need to adjust the month field.  */
116



25668424
                    switch (month)
117
                    {
118
119
2821
                    case 1:                 /* January  */
120
                    {
121
122
                        /* Check for end of the month.  */
123
2821
                        if (day > 31)
124
                        {
125
126
                            /* Move to next month.  */
127
91
                            day = 1;
128
91
                            month++;
129
                        }
130
2821
                        break;
131
                    }
132
133
2571
                    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
2571
                        if ((year % 4) == 0)
140
                        {
141
142
                            /* Leap year in February... check for 29 days
143
                               instead of 28.  */
144
639
                            if (day > 29)
145
                            {
146
147
                                /* Adjust the month.  */
148
23
                                day =  1;
149
23
                                month++;
150
                            }
151
                        }
152
                        else
153
                        {
154
155
1932
                            if (day > 28)
156
                            {
157
158
                                /* Adjust the month.  */
159
69
                                day = 1;
160
69
                                month++;
161
                            }
162
                        }
163
2571
                        break;
164
                    }
165
166
2852
                    case 3:                 /* March  */
167
                    {
168
169
                        /* Check for end of the month.  */
170
2852
                        if (day > 31)
171
                        {
172
173
                            /* Move to next month.  */
174
92
                            day = 1;
175
92
                            month++;
176
                        }
177
2852
                        break;
178
                    }
179
180
2760
                    case 4:                 /* April  */
181
                    {
182
183
                        /* Check for end of the month.  */
184
2760
                        if (day > 30)
185
                        {
186
187
                            /* Move to next month.  */
188
92
                            day = 1;
189
92
                            month++;
190
                        }
191
2760
                        break;
192
                    }
193
194
2852
                    case 5:                 /* May  */
195
                    {
196
197
                        /* Check for end of the month.  */
198
2852
                        if (day > 31)
199
                        {
200
201
                            /* Move to next month.  */
202
92
                            day = 1;
203
92
                            month++;
204
                        }
205
2852
                        break;
206
                    }
207
208
2760
                    case 6:                 /* June */
209
                    {
210
211
                        /* Check for end of the month.  */
212
2760
                        if (day > 30)
213
                        {
214
215
                            /* Move to next month.  */
216
92
                            day = 1;
217
92
                            month++;
218
                        }
219
2760
                        break;
220
                    }
221
222
2852
                    case 7:                 /* July */
223
                    {
224
225
                        /* Check for end of the month.  */
226
2852
                        if (day > 31)
227
                        {
228
229
                            /* Move to next month.  */
230
92
                            day = 1;
231
92
                            month++;
232
                        }
233
2852
                        break;
234
                    }
235
236
2852
                    case 8:                 /* August */
237
                    {
238
239
                        /* Check for end of the month.  */
240
2852
                        if (day > 31)
241
                        {
242
243
                            /* Move to next month.  */
244
92
                            day = 1;
245
92
                            month++;
246
                        }
247
2852
                        break;
248
                    }
249
250
2760
                    case 9:                 /* September */
251
                    {
252
253
                        /* Check for end of the month.  */
254
2760
                        if (day > 30)
255
                        {
256
257
                            /* Move to next month.  */
258
92
                            day = 1;
259
92
                            month++;
260
                        }
261
2760
                        break;
262
                    }
263
264
2852
                    case 10:                /* October */
265
                    {
266
267
                        /* Check for end of the month.  */
268
2852
                        if (day > 31)
269
                        {
270
271
                            /* Move to next month.  */
272
92
                            day = 1;
273
92
                            month++;
274
                        }
275
2852
                        break;
276
                    }
277
278
2760
                    case 11:                /* November */
279
                    {
280
281
                        /* Check for end of the month.  */
282
2760
                        if (day > 30)
283
                        {
284
285
                            /* Move to next month.  */
286
92
                            day = 1;
287
92
                            month++;
288
                        }
289
2760
                        break;
290
                    }
291
292
25551332
                    case 12:                /* December */
293
                    {
294
295
                        /* Check for end of the month.  */
296
25551332
                        if (day > 31)
297
                        {
298
299
                            /* Move to next month.  */
300
25548572
                            day = 1;
301
25548572
                            month = 1;
302
303
                            /* Also move to next year.  */
304
25548572
                            year++;
305
306
                            /* Check for a year that exceeds the representation
307
                               in this format.  */
308
25548572
                            if (year > FX_MAXIMUM_YEAR)
309
                            {
310
25548481
                                return;
311
                            }
312
                        }
313
2851
                        break;
314
                    }
315
316
86400
                    default:                /* Invalid month!  */
317
318
86400
                        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
289811523
        _fx_system_date =  ((year - FX_BASE_YEAR) << FX_YEAR_SHIFT) |
328
289811523
                            (month << FX_MONTH_SHIFT) | day;
329
330
        /* Set the new system time.  */
331
289811523
        _fx_system_time  =  (hour << FX_HOUR_SHIFT) |
332
289811523
                            (minute << FX_MINUTE_SHIFT) | (second / 2);
333
    }
334
}
335