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 |
|
|
/* _fxe_system_date_set PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* William E. Lamie, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function checks for errors in the set system date call. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* year Year (1980-2107) */ |
49 |
|
|
/* month Month (1-12) */ |
50 |
|
|
/* day Day (1-28/29/30/31) */ |
51 |
|
|
/* */ |
52 |
|
|
/* OUTPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* FX_INVALID_YEAR Supplied year is invalid */ |
55 |
|
|
/* FX_INVALID_MONTH Supplied month is invalid */ |
56 |
|
|
/* FX_INVALID_DAY Supplied day is invalid */ |
57 |
|
|
/* status Actual completion status */ |
58 |
|
|
/* */ |
59 |
|
|
/* CALLS */ |
60 |
|
|
/* */ |
61 |
|
|
/* _fx_system_date_set Actual system date set call */ |
62 |
|
|
/* */ |
63 |
|
|
/* CALLED BY */ |
64 |
|
|
/* */ |
65 |
|
|
/* Application Code */ |
66 |
|
|
/* */ |
67 |
|
|
/* RELEASE HISTORY */ |
68 |
|
|
/* */ |
69 |
|
|
/* DATE NAME DESCRIPTION */ |
70 |
|
|
/* */ |
71 |
|
|
/* 05-19-2020 William E. Lamie Initial Version 6.0 */ |
72 |
|
|
/* 09-30-2020 William E. Lamie Modified comment(s), */ |
73 |
|
|
/* resulting in version 6.1 */ |
74 |
|
|
/* */ |
75 |
|
|
/**************************************************************************/ |
76 |
|
32 |
UINT _fxe_system_date_set(UINT year, UINT month, UINT day) |
77 |
|
|
{ |
78 |
|
|
|
79 |
|
|
UINT status; |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
/* Check for invalid year. */ |
83 |
✓✓✓✓
|
32 |
if ((year < FX_BASE_YEAR) || (year > FX_MAXIMUM_YEAR)) |
84 |
|
|
{ |
85 |
|
2 |
return(FX_INVALID_YEAR); |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
/* Check for invalid day. */ |
89 |
✓✓ |
30 |
if (day < 1) |
90 |
|
|
{ |
91 |
|
1 |
return(FX_INVALID_DAY); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
/* Check for invalid day. */ |
95 |
✓✓✓✓ ✓✓✓✓ ✓✓✓✓ ✓ |
29 |
switch (month) |
96 |
|
|
{ |
97 |
|
|
|
98 |
|
2 |
case 1: |
99 |
|
|
{ |
100 |
|
|
|
101 |
|
|
/* Check for 31 days. */ |
102 |
✓✓ |
2 |
if (day > 31) |
103 |
|
|
{ |
104 |
|
1 |
return(FX_INVALID_DAY); |
105 |
|
|
} |
106 |
|
1 |
break; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
5 |
case 2: |
110 |
|
|
{ |
111 |
|
|
|
112 |
|
|
/* Check for leap year. */ |
113 |
✓✓ |
5 |
if ((year % 4) == 0) |
114 |
|
|
{ |
115 |
|
|
|
116 |
|
|
/* Leap year, February has 29 days. */ |
117 |
✓✓ |
3 |
if (day > 29) |
118 |
|
|
{ |
119 |
|
2 |
return(FX_INVALID_DAY); |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
else |
123 |
|
|
{ |
124 |
|
|
|
125 |
|
|
/* Otherwise, non-leap year. February has |
126 |
|
|
28 days. */ |
127 |
✓✓ |
2 |
if (day > 28) |
128 |
|
|
{ |
129 |
|
1 |
return(FX_INVALID_DAY); |
130 |
|
|
} |
131 |
|
|
} |
132 |
|
2 |
break; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
2 |
case 3: |
136 |
|
|
{ |
137 |
|
|
|
138 |
|
|
/* Check for 31 days. */ |
139 |
✓✓ |
2 |
if (day > 31) |
140 |
|
|
{ |
141 |
|
1 |
return(FX_INVALID_DAY); |
142 |
|
|
} |
143 |
|
1 |
break; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
2 |
case 4: |
147 |
|
|
{ |
148 |
|
|
|
149 |
|
|
/* Check for 30 days. */ |
150 |
✓✓ |
2 |
if (day > 30) |
151 |
|
|
{ |
152 |
|
1 |
return(FX_INVALID_DAY); |
153 |
|
|
} |
154 |
|
1 |
break; |
155 |
|
|
} |
156 |
|
|
|
157 |
|
2 |
case 5: |
158 |
|
|
{ |
159 |
|
|
|
160 |
|
|
/* Check for 31 days. */ |
161 |
✓✓ |
2 |
if (day > 31) |
162 |
|
|
{ |
163 |
|
1 |
return(FX_INVALID_DAY); |
164 |
|
|
} |
165 |
|
1 |
break; |
166 |
|
|
} |
167 |
|
|
|
168 |
|
2 |
case 6: |
169 |
|
|
{ |
170 |
|
|
|
171 |
|
|
/* Check for 30 days. */ |
172 |
✓✓ |
2 |
if (day > 30) |
173 |
|
|
{ |
174 |
|
1 |
return(FX_INVALID_DAY); |
175 |
|
|
} |
176 |
|
1 |
break; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
2 |
case 7: |
180 |
|
|
{ |
181 |
|
|
|
182 |
|
|
/* Check for 31 days. */ |
183 |
✓✓ |
2 |
if (day > 31) |
184 |
|
|
{ |
185 |
|
1 |
return(FX_INVALID_DAY); |
186 |
|
|
} |
187 |
|
1 |
break; |
188 |
|
|
} |
189 |
|
|
|
190 |
|
2 |
case 8: |
191 |
|
|
{ |
192 |
|
|
|
193 |
|
|
/* Check for 31 days. */ |
194 |
✓✓ |
2 |
if (day > 31) |
195 |
|
|
{ |
196 |
|
1 |
return(FX_INVALID_DAY); |
197 |
|
|
} |
198 |
|
1 |
break; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
2 |
case 9: |
202 |
|
|
{ |
203 |
|
|
|
204 |
|
|
/* Check for 30 days. */ |
205 |
✓✓ |
2 |
if (day > 30) |
206 |
|
|
{ |
207 |
|
1 |
return(FX_INVALID_DAY); |
208 |
|
|
} |
209 |
|
1 |
break; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
2 |
case 10: |
213 |
|
|
{ |
214 |
|
|
|
215 |
|
|
/* Check for 31 days. */ |
216 |
✓✓ |
2 |
if (day > 31) |
217 |
|
|
{ |
218 |
|
1 |
return(FX_INVALID_DAY); |
219 |
|
|
} |
220 |
|
1 |
break; |
221 |
|
|
} |
222 |
|
|
|
223 |
|
2 |
case 11: |
224 |
|
|
{ |
225 |
|
|
|
226 |
|
|
/* Check for 30 days. */ |
227 |
✓✓ |
2 |
if (day > 30) |
228 |
|
|
{ |
229 |
|
1 |
return(FX_INVALID_DAY); |
230 |
|
|
} |
231 |
|
1 |
break; |
232 |
|
|
} |
233 |
|
|
|
234 |
|
3 |
case 12: |
235 |
|
|
{ |
236 |
|
|
|
237 |
|
|
/* Check for 31 days. */ |
238 |
✓✓ |
3 |
if (day > 31) |
239 |
|
|
{ |
240 |
|
1 |
return(FX_INVALID_DAY); |
241 |
|
|
} |
242 |
|
2 |
break; |
243 |
|
|
} |
244 |
|
|
|
245 |
|
1 |
default: |
246 |
|
|
|
247 |
|
|
/* Invalid month. */ |
248 |
|
1 |
return(FX_INVALID_MONTH); |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
/* Call actual system date set service. */ |
252 |
|
14 |
status = _fx_system_date_set(year, month, day); |
253 |
|
|
|
254 |
|
|
/* Return status. */ |
255 |
|
14 |
return(status); |
256 |
|
|
} |
257 |
|
|
|