GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: fx_system_timer_entry.c Lines: 92 92 100.0 %
Date: 2024-01-10 21:53:23 Branches: 51 51 100.0 %

Line Branch Exec Source
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
/** 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
/*  RELEASE HISTORY                                                       */
65
/*                                                                        */
66
/*    DATE              NAME                      DESCRIPTION             */
67
/*                                                                        */
68
/*  05-19-2020     William E. Lamie         Initial Version 6.0           */
69
/*  09-30-2020     William E. Lamie         Modified comment(s),          */
70
/*                                            resulting in version 6.1    */
71
/*                                                                        */
72
/**************************************************************************/
73
315446405
VOID    _fx_system_timer_entry(ULONG id)
74
{
75
76
UINT second;
77
UINT minute;
78
UINT hour;
79
UINT day;
80
UINT month;
81
UINT year;
82
83
84
    /* Determine if the ID is valid.  */
85
315446405
    if (id == FX_TIMER_ID)
86
    {
87
88
        /* Break the current date time into separate fields for easier work!  */
89
315446404
        second =  (_fx_system_time & FX_SECOND_MASK) * 2;
90
315446404
        minute =  (_fx_system_time >> FX_MINUTE_SHIFT) & FX_MINUTE_MASK;
91
315446404
        hour =    (_fx_system_time >> FX_HOUR_SHIFT) & FX_HOUR_MASK;
92
315446404
        day =     _fx_system_date & FX_DAY_MASK;
93
315446404
        month =   (_fx_system_date >> FX_MONTH_SHIFT) & FX_MONTH_MASK;
94
315446404
        year =    ((_fx_system_date >> FX_YEAR_SHIFT) & FX_YEAR_MASK) + FX_BASE_YEAR;
95
96
        /* Now apply the "second" update.  */
97
315446404
        second =  second + FX_UPDATE_RATE_IN_SECONDS;
98
99
        /* Determine if we need to adjust the minute field.  */
100
315446404
        if (second > FX_MAXIMUM_SECOND)
101
        {
102
103
            /* Yes, we need to adjust the minute field.  */
104
73936800
            minute =  minute + second / 60;
105
73936800
            second =  second % 60;
106
107
            /* Determine if we need to adjust the hour field.  */
108
73936800
            if (minute > FX_MAXIMUM_MINUTE)
109
            {
110
111
                /* Yes, we need to adjust the hour field.  */
112
26439912
                hour =    hour + minute / 60;
113
26439912
                minute =  minute % 60;
114
115
                /* Determine if we need to adjust the day field.  */
116
26439912
                if (hour > FX_MAXIMUM_HOUR)
117
                {
118
119
                    /* Yes, we need to adjust the day field.  */
120
25668423
                    hour =  0;
121
25668423
                    day++;
122
123
                    /* Determine if we need to adjust the month field.  */
124



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