GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_system_timer_entry.c Lines: 92 92 100.0 %
Date: 2024-03-11 05:15:45 Branches: 51 51 100.0 %

Line Branch Exec Source
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
/** FileX Component                                                       */
16
/**                                                                       */
17
/**   System                                                              */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
#define FX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "fx_api.h"
28
#include "fx_system.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _fx_system_timer_entry                              PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    William E. Lamie, Microsoft Corporation                             */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function is FileX system timer function.  It is called at the  */
44
/*    rate specified by FX_UPDATE_RATE_IN_SECONDS and is responsible for  */
45
/*    maintaining both the system date and time.                          */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    id                                    Not used                      */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    None                                                                */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    Application Initialization                                          */
62
/*                                                                        */
63
/*  RELEASE HISTORY                                                       */
64
/*                                                                        */
65
/*    DATE              NAME                      DESCRIPTION             */
66
/*                                                                        */
67
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
68
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
69
/*                                            resulting in version 6.1    */
70
/*                                                                        */
71
/**************************************************************************/
72
315446404
VOID    _fx_system_timer_entry(ULONG id)
73
{
74
75
UINT second;
76
UINT minute;
77
UINT hour;
78
UINT day;
79
UINT month;
80
UINT year;
81
82
83
    /* Determine if the ID is valid.  */
84
315446404
    if (id == FX_TIMER_ID)
85
    {
86
87
        /* Break the current date time into separate fields for easier work!  */
88
315446403
        second =  (_fx_system_time & FX_SECOND_MASK) * 2;
89
315446403
        minute =  (_fx_system_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
90
315446403
        hour =    (_fx_system_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
91
315446403
        day =     _fx_system_date & FX_DAY_MASK;
92
315446403
        month =   (_fx_system_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
93
315446403
        year =    ((_fx_system_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) + FX_BASE_YEAR;
94
95
        /* Now apply the "second" update.  */
96
315446403
        second =  second + FX_UPDATE_RATE_IN_SECONDS;
97
98
        /* Determine if we need to adjust the minute field.  */
99
315446403
        if (second > FX_MAXIMUM_SECOND)
100
        {
101
102
            /* Yes, we need to adjust the minute field.  */
103
73936801
            minute =  minute + second / 60;
104
73936801
            second =  second % 60;
105
106
            /* Determine if we need to adjust the hour field.  */
107
73936801
            if (minute > FX_MAXIMUM_MINUTE)
108
            {
109
110
                /* Yes, we need to adjust the hour field.  */
111
26439913
                hour =    hour + minute / 60;
112
26439913
                minute =  minute % 60;
113
114
                /* Determine if we need to adjust the day field.  */
115
26439913
                if (hour > FX_MAXIMUM_HOUR)
116
                {
117
118
                    /* Yes, we need to adjust the day field.  */
119
25668424
                    hour =  0;
120
25668424
                    day++;
121
122
                    /* Determine if we need to adjust the month field.  */
123



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