VSF Documented
rtc_template.inc
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#if VSF_HAL_USE_RTC == ENABLED
19
20/*============================ INCLUDES ======================================*/
21
22/* The four *_API_TEMPLATE branches below synthesize get/set helpers on top of
23 * libc <time.h> (struct tm / time_t / gmtime / mktime). Include the header
24 * here instead of relying on the driver to do it indirectly, and guard the
25 * width assumption between time_t and vsf_rtc_time_t (uint64_t).
26 *
27 * If the target platform exposes a narrower, signed time_t (e.g. int32_t),
28 * values past 2038-01-19 will sign-extend into vsf_rtc_time_t; drivers that
29 * need to handle Y2K38 should reimplement get_time/set_time rather than use
30 * these template branches.
31 */
32#if (VSF_RTC_CFG_GET_API_TEMPLATE == ENABLED) \
33 || (VSF_RTC_CFG_SET_API_TEMPLATE == ENABLED) \
34 || (VSF_RTC_CFG_GET_TIME_API_TEMPLATE == ENABLED) \
35 || (VSF_RTC_CFG_SET_TIME_API_TEMPLATE == ENABLED)
36# include <time.h>
37VSF_STATIC_ASSERT(sizeof(time_t) <= sizeof(vsf_rtc_time_t));
38#endif
39
40/*============================ MACROS ========================================*/
41
42#if VSF_RTC_CFG_GET_API_TEMPLATE == ENABLED && VSF_RTC_CFG_GET_TIME_API_TEMPLATE == ENABLED
43# error "VSF_RTC_CFG_GET_API_TEMPLATE and VSF_RTC_CFG_GET_TIME_API_TEMPLATE Only one can be defined at a time"
44#endif
45
46#if VSF_RTC_CFG_SET_API_TEMPLATE == ENABLED && VSF_RTC_CFG_SET_TIME_API_TEMPLATE == ENABLED
47# error "VSF_RTC_CFG_SET_API_TEMPLATE and VSF_RTC_CFG_SET_TIME_API_TEMPLATE Only one can be defined at a time"
48#endif
49
50#ifndef VSF_RTC_CFG_REIMPLEMENT_API_GET_CONFIGURATION
51# define VSF_RTC_CFG_REIMPLEMENT_API_GET_CONFIGURATION DISABLED
52#endif
53
54#ifndef VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY
55# define VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY DISABLED
56#endif
57
58#ifndef VSF_RTC_CFG_REIMPLEMENT_API_CTRL
59# define VSF_RTC_CFG_REIMPLEMENT_API_CTRL DISABLED
60#endif
61
62#ifdef VSF_RTC_CFG_IMP_REMAP_PREFIX
63# undef VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY
64# define VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY ENABLED
65# undef VSF_RTC_CFG_REIMPLEMENT_API_GET_CONFIGURATION
66# define VSF_RTC_CFG_REIMPLEMENT_API_GET_CONFIGURATION ENABLED
67# undef VSF_RTC_CFG_REIMPLEMENT_API_CTRL
68# define VSF_RTC_CFG_REIMPLEMENT_API_CTRL ENABLED
69#endif
70
71#if VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY == DISABLED
72# ifndef VSF_RTC_CFG_CAPABILITY_T_IRQ_MASK
73# define VSF_RTC_CFG_CAPABILITY_T_IRQ_MASK VSF_RTC_IRQ_ALL_BITS_MASK
74# endif
75#endif
76
77#if defined(VSF_RTC_CFG_IMP_RENAME_DEVICE_PREFIX) && (VSF_RTC_CFG_IMP_RENAME_DEVICE_PREFIX == ENABLED)
78# define vsf_real_rtc_t VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _t)
79# define vsf_real_rtc_capability VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _capability)
80# define vsf_real_rtc_ctrl VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _ctrl)
81# define vsf_real_rtc_get_configuration VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _get_configuration)
82# define vsf_real_rtc_get VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _get)
83# define vsf_real_rtc_set VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _set)
84# define vsf_real_rtc_get_time VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _get_time)
85# define vsf_real_rtc_set_time VSF_MCONNECT(VSF_RTC_CFG_IMP_DEVICE_PREFIX, _set_time)
86#else
87# define vsf_real_rtc_t VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_t)
88# define vsf_real_rtc_capability VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_capability)
89# define vsf_real_rtc_ctrl VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_ctrl)
90# define vsf_real_rtc_get_configuration VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_get_configuration)
91# define vsf_real_rtc_get VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_get)
92# define vsf_real_rtc_set VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_set)
93# define vsf_real_rtc_get_time VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_get_time)
94# define vsf_real_rtc_set_time VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_set_time)
95#endif
96
97/*============================ MACROFIED FUNCTIONS ===========================*/
98/*============================ TYPES =========================================*/
99/*============================ GLOBAL VARIABLES ==============================*/
100/*============================ LOCAL VARIABLES ===============================*/
101/*============================ PROTOTYPES ====================================*/
102/*============================ IMPLEMENTATION ================================*/
103
104#if VSF_RTC_CFG_GET_API_TEMPLATE == ENABLED
105vsf_err_t vsf_real_rtc_get(vsf_real_rtc_t *rtc_ptr, vsf_rtc_tm_t *rtc_tm)
106{
107 VSF_HAL_ASSERT(rtc_ptr != NULL);
108 VSF_HAL_ASSERT(rtc_tm != NULL);
109
110 time_t second, milliseconds;
111 vsf_err_t result = vsf_real_rtc_get_time(rtc_ptr, &second, &milliseconds);
112 if (result != VSF_ERR_NONE) {
113 return result;
114 }
115
116 struct tm *t = gmtime(&second);
117 if (t == NULL) {
118 return VSF_ERR_FAIL;
119 }
120
121 rtc_tm->tm_sec = t->tm_sec;
122 rtc_tm->tm_min = t->tm_min;
123 rtc_tm->tm_hour = t->tm_hour;
124 rtc_tm->tm_mday = t->tm_mday;
125 rtc_tm->tm_wday = t->tm_wday + 1;
126 rtc_tm->tm_mon = t->tm_mon + 1;
127 rtc_tm->tm_year = t->tm_year + 1900;
128 rtc_tm->tm_ms = milliseconds;
129
130 return VSF_ERR_NONE;
131}
132#endif
133
134#if VSF_RTC_CFG_SET_API_TEMPLATE == ENABLED
135vsf_err_t vsf_real_rtc_set(vsf_real_rtc_t *rtc_ptr, const vsf_rtc_tm_t *rtc_tm)
136{
137 VSF_HAL_ASSERT(rtc_ptr != NULL);
138 VSF_HAL_ASSERT(rtc_tm != NULL);
139
140 struct tm t = {
141 .tm_sec = rtc_tm->tm_sec,
142 .tm_min = rtc_tm->tm_min,
143 .tm_hour = rtc_tm->tm_hour,
144 .tm_mday = rtc_tm->tm_mday,
145 .tm_mon = rtc_tm->tm_mon - 1,
146 .tm_year = rtc_tm->tm_year - 1900,
147 };
148
149 time_t second = mktime(&t);
150 return vsf_real_rtc_set_time(rtc_ptr, second, rtc_tm->tm_ms);
151}
152#endif
153
154#if VSF_RTC_CFG_REIMPLEMENT_API_CTRL == DISABLED
155vsf_err_t vsf_real_rtc_ctrl(vsf_real_rtc_t *rtc_ptr, vsf_rtc_ctrl_t ctrl, void *param)
156{
157 VSF_HAL_ASSERT(NULL != rtc_ptr);
158
159 // Default implementation: not supported, trigger assertion
161
162 return VSF_ERR_NOT_SUPPORT;
163}
164#endif
165
166#if VSF_RTC_CFG_GET_TIME_API_TEMPLATE == ENABLED
167vsf_err_t vsf_real_rtc_get_time(vsf_real_rtc_t *rtc_ptr, vsf_rtc_time_t *second_ptr, vsf_rtc_time_t *milliseconds_ptr)
168{
169 VSF_HAL_ASSERT(rtc_ptr != NULL);
170 VSF_HAL_ASSERT((second_ptr != NULL) || (milliseconds_ptr != NULL));
171
172 vsf_rtc_tm_t rtc_tm;
173 vsf_err_t result = vsf_real_rtc_get(rtc_ptr, &rtc_tm);
174 if (result != VSF_ERR_NONE) {
175 return result;
176 }
177
178 if (second_ptr != NULL) {
179 struct tm t = {
180 .tm_sec = rtc_tm.tm_sec,
181 .tm_min = rtc_tm.tm_min,
182 .tm_hour = rtc_tm.tm_hour,
183 .tm_mday = rtc_tm.tm_mday,
184 .tm_mon = rtc_tm.tm_mon - 1,
185 .tm_year = rtc_tm.tm_year - 1900,
186 };
187 /* Explicit integer conversion: mktime() returns time_t, which may be
188 * narrower and/or of different signedness than vsf_rtc_time_t. Go
189 * through a local time_t to make the widening explicit. */
190 time_t sec_t = mktime(&t);
191 *second_ptr = (vsf_rtc_time_t)sec_t;
192 }
193
194 if (milliseconds_ptr != NULL) {
195 *milliseconds_ptr = rtc_tm.tm_ms;
196 }
197
198 return VSF_ERR_NONE;
199}
200#endif
201
202#if VSF_RTC_CFG_SET_TIME_API_TEMPLATE == ENABLED
203vsf_err_t vsf_real_rtc_set_time(vsf_real_rtc_t *rtc_ptr, vsf_rtc_time_t second, vsf_rtc_time_t milliseconds)
204{
205 VSF_HAL_ASSERT(rtc_ptr != NULL);
206
207 /* Use a local time_t instead of reinterpret-casting &second: time_t may
208 * be narrower than vsf_rtc_time_t, and gmtime() would otherwise read
209 * sizeof(time_t) bytes from a possibly wider storage. */
210 time_t sec_t = (time_t)second;
211 struct tm *t = gmtime(&sec_t);
212 if (NULL == t) {
213 return VSF_ERR_FAIL;
214 }
215
216 vsf_rtc_tm_t rtc_tm = {
217 .tm_sec = t->tm_sec,
218 .tm_min = t->tm_min,
219 .tm_hour = t->tm_hour,
220 .tm_mday = t->tm_mday,
221 .tm_mon = t->tm_mon + 1,
222 .tm_year = t->tm_year + 1900,
223 .tm_ms = milliseconds,
224 };
225
226 return vsf_real_rtc_set(rtc_ptr, &rtc_tm);
227}
228#endif
229
230#if VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY == DISABLED
231vsf_rtc_capability_t vsf_real_rtc_capability(vsf_real_rtc_t *rtc_ptr)
232{
233 vsf_rtc_capability_t rtc_capability = {
235 };
236
237 return rtc_capability;
238}
239#endif
240
241#if VSF_RTC_CFG_REIMPLEMENT_API_GET_CONFIGURATION == DISABLED
242vsf_err_t vsf_real_rtc_get_configuration(vsf_real_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr)
243{
244 VSF_HAL_ASSERT(NULL != rtc_ptr);
245 VSF_HAL_ASSERT(NULL != cfg_ptr);
246 VSF_HAL_ASSERT(0); // Default implementation: not supported, trigger assertion
247 return VSF_ERR_NOT_SUPPORT;
248}
249#endif
250
251/*============================ MACROS ========================================*/
252
253#undef VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY
254#undef VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG
255#undef VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK
256#undef VSF_RTC_CFG_REIMPLEMENT_TYPE_CTRL
257#undef VSF_RTC_CFG_REIMPLEMENT_API_CAPABILITY
258#undef VSF_RTC_CFG_REIMPLEMENT_API_CTRL
259#undef VSF_RTC_CFG_REIMPLEMENT_API_GET_CONFIGURATION
260#undef VSF_RTC_CFG_CAPABILITY_T_IRQ_MASK
261#undef vsf_real_rtc_t
262#undef vsf_real_rtc_capability
263#undef vsf_real_rtc_ctrl
264#undef vsf_real_rtc_get_configuration
265#undef vsf_real_rtc_get
266#undef vsf_real_rtc_set
267#undef vsf_real_rtc_get_time
268#undef vsf_real_rtc_set_time
269
270/*============================ MACROS ========================================*/
271
272#ifdef VSF_RTC_CFG_IMP_REMAP_PREFIX
273
274# define vsf_imp_rtc_t VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_t)
275# define vsf_imp_rtc_init VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_init)
276# define vsf_imp_rtc_enable VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_enable)
277# define vsf_imp_rtc_disable VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_disable)
278# define vsf_imp_rtc_capability VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_capability)
279# define vsf_imp_rtc_get VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_get)
280# define vsf_imp_rtc_set VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_set)
281# define vsf_imp_rtc_get_time VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_get_time)
282# define vsf_imp_rtc_set_time VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_set_time)
283# define vsf_imp_rtc_get_configuration VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_get_configuration)
284# define vsf_imp_rtc_ctrl VSF_MCONNECT(VSF_RTC_CFG_IMP_PREFIX, _rtc_ctrl)
285
286# define vsf_remap_rtc_t VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_t)
287# define vsf_remap_rtc_init VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_init)
288# define vsf_remap_rtc_fini VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_fini)
289# define vsf_remap_rtc_enable VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_enable)
290# define vsf_remap_rtc_disable VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_disable)
291# define vsf_remap_rtc_capability VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_capability)
292# define vsf_remap_rtc_get VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_get)
293# define vsf_remap_rtc_set VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_set)
294# define vsf_remap_rtc_get_time VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_get_time)
295# define vsf_remap_rtc_set_time VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_set_time)
296# define vsf_remap_rtc_get_configuration VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_get_configuration)
297# define vsf_remap_rtc_ctrl VSF_MCONNECT(VSF_RTC_CFG_IMP_REMAP_PREFIX, _rtc_ctrl)
298
299# define VSF_RTC_CFG_IMP_REMAP_FUNCTIONS \
300 vsf_err_t vsf_imp_rtc_init(vsf_imp_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr) \
301 { \
302 VSF_HAL_ASSERT(rtc_ptr != NULL); \
303 return vsf_remap_rtc_init(rtc_ptr, cfg_ptr); \
304 } \
305 void vsf_imp_rtc_fini(vsf_imp_rtc_t *rtc_ptr) \
306 { \
307 VSF_HAL_ASSERT(rtc_ptr != NULL); \
308 vsf_remap_rtc_fini(rtc_ptr); \
309 } \
310 fsm_rt_t vsf_imp_rtc_enable(vsf_imp_rtc_t *rtc_ptr) \
311 { \
312 VSF_HAL_ASSERT(rtc_ptr != NULL); \
313 return vsf_remap_rtc_enable(rtc_ptr); \
314 } \
315 fsm_rt_t vsf_imp_rtc_disable(vsf_imp_rtc_t *rtc_ptr) \
316 { \
317 VSF_HAL_ASSERT(rtc_ptr != NULL); \
318 return vsf_remap_rtc_disable(rtc_ptr); \
319 } \
320 vsf_err_t vsf_imp_rtc_get(vsf_imp_rtc_t *rtc_ptr, vsf_rtc_tm_t *rtc_tm) \
321 { \
322 VSF_HAL_ASSERT(rtc_ptr != NULL); \
323 return vsf_remap_rtc_get(rtc_ptr, rtc_tm); \
324 } \
325 vsf_err_t vsf_imp_rtc_set(vsf_imp_rtc_t *rtc_ptr, const vsf_rtc_tm_t *rtc_tm) \
326 { \
327 VSF_HAL_ASSERT(rtc_ptr != NULL); \
328 return vsf_remap_rtc_set(rtc_ptr, rtc_tm); \
329 } \
330 vsf_err_t vsf_imp_rtc_get_time(vsf_imp_rtc_t *rtc_ptr, vsf_rtc_time_t *second_ptr, \
331 vsf_rtc_time_t *millisecond_ptr) \
332 { \
333 VSF_HAL_ASSERT(rtc_ptr != NULL); \
334 return vsf_remap_rtc_get_time(rtc_ptr, second_ptr, millisecond_ptr); \
335 } \
336 vsf_err_t vsf_imp_rtc_set_time(vsf_imp_rtc_t *rtc_ptr, vsf_rtc_time_t second, \
337 vsf_rtc_time_t millisecond) \
338 { \
339 VSF_HAL_ASSERT(rtc_ptr != NULL); \
340 return vsf_remap_rtc_set_time(rtc_ptr, second, millisecond); \
341 } \
342 vsf_rtc_capability_t vsf_imp_rtc_capability(vsf_imp_rtc_t *rtc_ptr) \
343 { \
344 VSF_HAL_ASSERT(rtc_ptr != NULL); \
345 return vsf_remap_rtc_capability(rtc_ptr); \
346 } \
347 \
348 vsf_err_t vsf_imp_rtc_get_configuration(vsf_imp_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr) \
349 { \
350 VSF_HAL_ASSERT(rtc_ptr != NULL); \
351 return vsf_remap_rtc_get_configuration(rtc_ptr, cfg_ptr); \
352 } \
353 vsf_err_t vsf_imp_rtc_ctrl(vsf_imp_rtc_t *rtc_ptr, vsf_rtc_ctrl_t ctrl, void *param) \
354 { \
355 VSF_HAL_ASSERT(rtc_ptr != NULL); \
356 return vsf_remap_rtc_ctrl(rtc_ptr, ctrl, param); \
357 }
358#endif
359
360/*============================ GLOBAL VARIABLES ==============================*/
361
362#define VSF_HAL_TEMPLATE_IMP_NAME _rtc
363#define VSF_HAL_TEMPLATE_IMP_UPCASE_NAME _RTC
364
365#if !defined(VSF_RTC_CFG_IMP_PREFIX) && !defined(VSF_RTC_CFG_IMP_DEVICE_PREFIX)
366# error "Please define VSF_RTC_CFG_IMP_PREFIX in rtc driver"
367#endif
368
369#if !defined(VSF_RTC_CFG_IMP_UPCASE_PREFIX) && !defined(VSF_RTC_CFG_IMP_DEVICE_UPCASE_PREFIX)
370# error "Please define VSF_RTC_CFG_IMP_UPCASE_PREFIX in rtc driver"
371#endif
372
373#ifndef VSF_RTC_CFG_IMP_COUNT_MASK_PREFIX
374# define VSF_RTC_CFG_IMP_COUNT_MASK_PREFIX VSF_RTC_CFG_IMP_UPCASE_PREFIX
375#endif
376
377#ifdef VSF_RTC_CFG_IMP_REMAP_FUNCTIONS
378# define VSF_HAL_CFG_IMP_REMAP_FUNCTIONS VSF_RTC_CFG_IMP_REMAP_FUNCTIONS
379#endif
380
382
383#undef VSF_RTC_CFG_IMP_PREFIX
384#undef VSF_RTC_CFG_IMP_COUNT_MASK_PREFIX
385#undef VSF_RTC_CFG_IMP_UPCASE_PREFIX
386#undef VSF_RTC_CFG_IMP_DEVICE_PREFIX
387#undef VSF_RTC_CFG_IMP_DEVICE_UPCASE_PREFIX
388#undef VSF_RTC_CFG_IMP_LV0
389#undef VSF_RTC_CFG_IMP_REMAP_FUNCTIONS
390#undef VSF_RTC_CFG_IMP_HAS_OP
391#undef VSF_RTC_CFG_IMP_EXTERN_OP
392#undef VSF_RTC_CFG_IMP_RENAME_DEVICE_PREFIX
393
394#undef vsf_imp_rtc_t
395#undef vsf_imp_rtc_init
396#undef vsf_imp_rtc_enable
397#undef vsf_imp_rtc_disable
398#undef vsf_imp_rtc_capability
399#undef vsf_imp_rtc_get
400#undef vsf_imp_rtc_set
401#undef vsf_imp_rtc_get_time
402#undef vsf_imp_rtc_set_time
403#undef vsf_imp_rtc_get_configuration
404#undef vsf_imp_rtc_ctrl
405
406#undef vsf_remap_rtc_t
407#undef vsf_remap_rtc_init
408#undef vsf_remap_rtc_enable
409#undef vsf_remap_rtc_disable
410#undef vsf_remap_rtc_capability
411#undef vsf_remap_rtc_get
412#undef vsf_remap_rtc_set
413#undef vsf_remap_rtc_get_time
414#undef vsf_remap_rtc_set_time
415#undef vsf_remap_rtc_get_configuration
416#undef vsf_remap_rtc_ctrl
417
418#undef VSF_HAL_TEMPLATE_IMP_NAME
419#undef VSF_HAL_TEMPLATE_IMP_UPCASE_NAME
420
421/*============================ STATIC ASSERTIONS ==============================*/
422
423/* User-extensible macros for custom mode and IRQ mask values
424 * Users can define these macros before including this template to append
425 * their custom enum values to the uniqueness checks.
426 *
427 * Check modes for custom values:
428 * VSF_RTC_CFG_MODE_CHECK_UNIQUE - Check mode for custom mode values
429 * Default: VSF_HAL_CHECK_MODE_LOOSE (loose mode, no overlapping bits)
430 * Can be set to: VSF_HAL_CHECK_MODE_STRICT (strict mode, no overlapping bits)
431 * VSF_RTC_CFG_IRQ_MASK_CHECK_UNIQUE - Check mode for custom IRQ mask values
432 * Default: VSF_HAL_CHECK_MODE_STRICT (strict mode, no overlapping bits)
433 * Can be set to: VSF_HAL_CHECK_MODE_LOOSE (loose mode, no overlapping bits)
434 *
435 * Example usage in vendor driver:
436 * #define VSF_RTC_CUSTOM_MODE_VALUES MY_CUSTOM_MODE1, MY_CUSTOM_MODE2
437 * #define VSF_RTC_CFG_MODE_CHECK_UNIQUE VSF_HAL_CHECK_MODE_LOOSE
438 * #define VSF_RTC_CUSTOM_IRQ_MASK_VALUES MY_CUSTOM_IRQ1, MY_CUSTOM_IRQ2
439 * #define VSF_RTC_CFG_IRQ_MASK_CHECK_UNIQUE VSF_HAL_CHECK_MODE_STRICT
440 * #include "hal/driver/common/rtc/rtc_template.inc"
441 */
442
443
444#ifdef VSF_RTC_CFG_MODE_CHECK_UNIQUE
445/* Default mode lists - can be redefined by users before including this file */
446/* Note: RTC typically doesn't have mode enums, but custom modes can be added */
447
448#ifdef VSF_RTC_CUSTOM_MODE_VALUES
449/* Check uniqueness among custom mode values using user-specified check mode */
451#endif
452#endif /* VSF_RTC_CFG_MODE_CHECK_UNIQUE */
453
454/* ==================== IRQ MASK UNIQUENESS CHECKS ==================== */
455
456#ifdef VSF_RTC_CFG_IRQ_MASK_CHECK_UNIQUE
457
458#ifdef VSF_RTC_CUSTOM_IRQ_MASK_VALUES
459/* Check uniqueness among custom IRQ mask values using user-specified check mode */
461#endif
462
463/* Check uniqueness within vsf_rtc_irq_mask_t enum */
464
465/* Check IRQ mask uniqueness - all IRQ mask bits should have different values
466 * Mandatory: VSF_RTC_IRQ_MASK_ALARM
467 */
470 /* Mandatory IRQ masks - always included */
472 /* User-defined IRQ masks - appended by user configuration */
473#ifdef VSF_RTC_CUSTOM_IRQ_MASK_VALUES
474 , VSF_RTC_CUSTOM_IRQ_MASK_VALUES
475#endif
476);
477#endif /* VSF_RTC_CFG_IRQ_MASK_CHECK_UNIQUE */
478
479#undef VSF_RTC_CFG_MODE_CHECK_UNIQUE
480#undef VSF_RTC_CFG_IRQ_MASK_CHECK_UNIQUE
481#undef VSF_RTC_CUSTOM_MODE_VALUES
482#undef VSF_RTC_CUSTOM_IRQ_MASK_VALUES
483
484#endif /* VSF_HAL_USE_RTC */
485
#define VSF_STATIC_ASSERT(__COND,...)
Definition __type.h:199
vsf_err_t
Definition __type.h:42
@ VSF_ERR_NOT_SUPPORT
function not supported
Definition __type.h:46
@ VSF_ERR_NONE
none error
Definition __type.h:44
@ VSF_ERR_FAIL
failed
Definition __type.h:51
#define VSF_RTC_CFG_CAPABILITY_IRQ_MASK
Definition rtc.c:148
__TIME_T time_t
Definition types.h:152
#define NULL
Definition lvgl.h:26
struct tm * gmtime(const time_t *t)
Definition vsf_linux_glibc_time.c:366
time_t mktime(struct tm *tm)
Definition vsf_linux_glibc_time.c:86
Definition time.h:53
int tm_mon
Definition time.h:58
int tm_year
Definition time.h:59
int tm_hour
Definition time.h:56
int tm_sec
Definition time.h:54
int tm_mday
Definition time.h:57
int tm_min
Definition time.h:55
int tm_wday
Definition time.h:60
RTC capability structure. Describes the features and capabilities supported by the RTC hardware.
Definition vsf_template_rtc.h:379
RTC configuration structure.
Definition vsf_template_rtc.h:365
Time structure for RTC operations. Used to represent date and time information in a standardized form...
Definition vsf_template_rtc.h:255
uint16_t tm_ms
Milliseconds component of time [0-999]. Provides sub-second precision.
Definition vsf_template_rtc.h:326
uint8_t tm_sec
Seconds component of time [0-59].
Definition vsf_template_rtc.h:262
uint16_t tm_year
Year value [0-65535].
Definition vsf_template_rtc.h:316
uint8_t tm_mon
Month [1-12]. January=1, February=2, ..., December=12.
Definition vsf_template_rtc.h:308
uint8_t tm_wday
Day of week [1-7]. Sunday=1, Monday=2, ..., Saturday=7.
Definition vsf_template_rtc.h:298
uint8_t tm_mday
Day of month [1-31].
Definition vsf_template_rtc.h:288
uint8_t tm_hour
Hours component of time [0-23]. Uses 24-hour format.
Definition vsf_template_rtc.h:280
uint8_t tm_min
Minutes component of time [0-59].
Definition vsf_template_rtc.h:270
#define VSF_RTC_CFG_IRQ_MASK_CHECK_UNIQUE
Definition rtc.c:225
#define VSF_RTC_CFG_MODE_CHECK_UNIQUE
Definition rtc.c:224
#define VSF_HAL_ASSERT(__CON)
all hal modules use this configuration file
Definition vsf_hal_cfg.h:36
vsf_rtc_ctrl_t
RTC control commands for hardware-specific operations.
Definition vsf_template_rtc.h:413
VSF_RTC_CFG_TIME_TYPE vsf_rtc_time_t
RTC time type definition.
Definition vsf_template_rtc.h:245
@ VSF_RTC_IRQ_MASK_ALARM
Alarm interrupt mask. Triggers when the RTC time matches the configured alarm time.
Definition vsf_template_rtc.h:211
#define VSF_HAL_CHECK_UNIQUE_CUSTOM(__CHECK_FUNC,...)
Definition vsf_template_static_assert_unique.h:2426
Generated from commit: vsfteam/vsf@7f3e4ff