VSF Documented
vsf_template_rtc.h
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#ifndef __VSF_TEMPLATE_RTC_H__
19#define __VSF_TEMPLATE_RTC_H__
20
21/*============================ INCLUDES ======================================*/
22
24#include "hal/arch/vsf_arch.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*============================ MACROS ========================================*/
31
32// multi-class support enabled by default for maximum availability.
33#ifndef VSF_RTC_CFG_MULTI_CLASS
34# define VSF_RTC_CFG_MULTI_CLASS ENABLED
35#endif
36
37#if defined(VSF_HW_RTC_COUNT) && !defined(VSF_HW_RTC_MASK)
38# define VSF_HW_RTC_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_RTC_COUNT)
39#endif
40
41#if defined(VSF_HW_RTC_MASK) && !defined(VSF_HW_RTC_COUNT)
42# define VSF_HW_RTC_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_RTC_MASK)
43#endif
44
45// application code can redefine it
46#ifndef VSF_RTC_CFG_PREFIX
47# if VSF_RTC_CFG_MULTI_CLASS == ENABLED
48# define VSF_RTC_CFG_PREFIX vsf
49# elif defined(VSF_HW_RTC_COUNT) && (VSF_HW_RTC_COUNT != 0)
50# define VSF_RTC_CFG_PREFIX vsf_hw
51# else
52# define VSF_RTC_CFG_PREFIX vsf
53# endif
54#endif
55
56#ifndef VSF_RTC_CFG_FUNCTION_RENAME
57# define VSF_RTC_CFG_FUNCTION_RENAME ENABLED
58#endif
59
60#ifndef VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK
61# define VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
62#endif
63
64#ifndef VSF_RTC_CFG_TIME_TYPE
65# define VSF_RTC_CFG_TIME_TYPE uint64_t
66#endif
67
71#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
72# define VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG DISABLED
73#endif
74
78#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
79# define VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
80#endif
81
82#ifndef VSF_RTC_CFG_INHERT_HAL_CAPABILITY
83# define VSF_RTC_CFG_INHERT_HAL_CAPABILITY ENABLED
84#endif
85
86/*============================ MACROFIED FUNCTIONS ===========================*/
87
88#define VSF_RTC_APIS(__prefix_name) \
89 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, init, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr) \
90 __VSF_HAL_TEMPLATE_API(__prefix_name, void, rtc, fini, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr) \
91 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, rtc, enable, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr) \
92 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, rtc, disable, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr) \
93 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_rtc_capability_t, rtc, capability, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr) \
94 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, get, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr, vsf_rtc_tm_t *rtc_tm) \
95 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, set, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr, const vsf_rtc_tm_t *rtc_tm) \
96 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, get_time, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr, vsf_rtc_time_t *second_ptr, vsf_rtc_time_t *millisecond_ptr) \
97 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, set_time, VSF_MCONNECT(__prefix_name, _rtc_t) *rtc_ptr, vsf_rtc_time_t second, vsf_rtc_time_t millisecond)
98
99/*============================ TYPES =========================================*/
100
101#if VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
102typedef enum vsf_rtc_irq_mask_t {
105#endif
106
107enum {
110};
111
113
114typedef struct vsf_rtc_tm_t {
115 uint8_t tm_sec; // [0 .. 59]
116 uint8_t tm_min; // [0 .. 59]
117 uint8_t tm_hour; // [0 .. 23]
118 uint8_t tm_mday; // [1 .. 31]
119 uint8_t tm_wday; // [1 .. 7] - [Sunday, Monday, ..., Saturday]
120 uint8_t tm_mon; // [1 .. 12] - [January -- December]
121 uint16_t tm_year; // [1900 .. ]
124
125
126#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
127typedef struct vsf_rtc_t vsf_rtc_t;
128typedef void vsf_rtc_isr_handler_t(void *target_ptr, vsf_rtc_t *rtc_ptr, vsf_rtc_irq_mask_t irq_mask);
129
130typedef struct vsf_rtc_isr_t {
135
137typedef struct vsf_rtc_cfg_t {
140#endif
141
142#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
143typedef struct vsf_rtc_capability_t {
144#if VSF_RTC_CFG_INHERT_HAL_CAPABILITY == ENABLED
146#endif
147
150#endif
151
152typedef struct vsf_rtc_op_t {
153#undef __VSF_HAL_TEMPLATE_API
154#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
155
156 VSF_RTC_APIS(vsf)
158
159#if VSF_RTC_CFG_MULTI_CLASS == ENABLED
160struct vsf_rtc_t {
162};
163#endif
164
165/*============================ GLOBAL VARIABLES ==============================*/
166/*============================ PROTOTYPES ====================================*/
167
187extern vsf_err_t vsf_rtc_init(vsf_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr);
188
201extern void vsf_rtc_fini(vsf_rtc_t *rtc_ptr);
202
216extern fsm_rt_t vsf_rtc_enable(vsf_rtc_t *rtc_ptr);
217
231extern fsm_rt_t vsf_rtc_disable(vsf_rtc_t *rtc_ptr);
232
245
258extern vsf_err_t vsf_rtc_get(vsf_rtc_t *rtc_ptr, vsf_rtc_tm_t *rtc_tm);
259
272extern vsf_err_t vsf_rtc_set(vsf_rtc_t *rtc_ptr, const vsf_rtc_tm_t *rtc_tm);
273
295extern vsf_err_t vsf_rtc_get_time(vsf_rtc_t *rtc_ptr, vsf_rtc_time_t *second_ptr, vsf_rtc_time_t *millisecond_ptr);
296
309extern vsf_err_t vsf_rtc_set_time(vsf_rtc_t *rtc_ptr, vsf_rtc_time_t second, vsf_rtc_time_t millisecond);
310
311/*============================ MACROFIED FUNCTIONS ===========================*/
312
313#if VSF_RTC_CFG_FUNCTION_RENAME == ENABLED
314# define __vsf_rtc_t VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_t)
315# define vsf_rtc_init(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_init) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
316# define vsf_rtc_enable(__RTC) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_enable) ((__vsf_rtc_t *)(__RTC))
317# define vsf_rtc_disable(__RTC) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_disable) ((__vsf_rtc_t *)(__RTC))
318# define vsf_rtc_capability(__RTC) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_capability) ((__vsf_rtc_t *)(__RTC))
319# define vsf_rtc_get(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_get) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
320# define vsf_rtc_set(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_set) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
321# define vsf_rtc_get_time(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_get_time) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
322# define vsf_rtc_set_time(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_set_time) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
323#endif
324
325#ifdef __cplusplus
326}
327#endif
328
329#endif /*__VSF_TEMPLATE_RTC_H__*/
vsf_err_t
Definition __type.h:42
vsf_arch_prio_t
Definition cortex_a_generic.h:88
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned short uint16_t
Definition stdint.h:7
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_hal_driver.h:203
Definition vsf_template_rtc.h:143
inherit(vsf_peripheral_capability_t) vsf_rtc_irq_mask_t irq_mask
rtc configuration
Definition vsf_template_rtc.h:137
vsf_rtc_isr_t isr
Definition vsf_template_rtc.h:138
Definition vsf_template_rtc.h:130
vsf_arch_prio_t prio
Definition vsf_template_rtc.h:133
vsf_rtc_isr_handler_t * handler_fn
Definition vsf_template_rtc.h:131
void * target_ptr
Definition vsf_template_rtc.h:132
Definition vsf_template_rtc.h:152
Definition vsf_template_rtc.h:160
const vsf_rtc_op_t * op
Definition vsf_template_rtc.h:161
Definition vsf_template_rtc.h:114
uint16_t tm_ms
Definition vsf_template_rtc.h:122
uint8_t tm_sec
Definition vsf_template_rtc.h:115
uint16_t tm_year
Definition vsf_template_rtc.h:121
uint8_t tm_mon
Definition vsf_template_rtc.h:120
uint8_t tm_wday
Definition vsf_template_rtc.h:119
uint8_t tm_mday
Definition vsf_template_rtc.h:118
uint8_t tm_hour
Definition vsf_template_rtc.h:117
uint8_t tm_min
Definition vsf_template_rtc.h:116
fsm_rt_t
Definition vsf_fsm.h:315
#define VSF_RTC_CFG_TIME_TYPE
Definition vsf_template_rtc.h:65
#define vsf_rtc_get_time(__RTC,...)
Definition vsf_template_rtc.h:321
#define VSF_RTC_APIS(__prefix_name)
Definition vsf_template_rtc.h:88
#define vsf_rtc_set_time(__RTC,...)
Definition vsf_template_rtc.h:322
#define vsf_rtc_get(__RTC,...)
Definition vsf_template_rtc.h:319
#define vsf_rtc_disable(__RTC)
Definition vsf_template_rtc.h:317
void vsf_rtc_fini(vsf_rtc_t *rtc_ptr)
finalize a rtc instance.
Definition rtc_common.c:48
VSF_RTC_CFG_TIME_TYPE vsf_rtc_time_t
Definition vsf_template_rtc.h:112
vsf_rtc_irq_mask_t
Definition vsf_template_rtc.h:102
@ VSF_RTC_IRQ_MASK_ALARM
Definition vsf_template_rtc.h:103
void vsf_rtc_isr_handler_t(void *target_ptr, vsf_rtc_t *rtc_ptr, vsf_rtc_irq_mask_t irq_mask)
Definition vsf_template_rtc.h:128
#define vsf_rtc_set(__RTC,...)
Definition vsf_template_rtc.h:320
@ VSF_RTC_IRQ_COUNT
Definition vsf_template_rtc.h:108
@ VSF_RTC_IRQ_ALL_BITS_MASK
Definition vsf_template_rtc.h:109
#define vsf_rtc_init(__RTC,...)
Definition vsf_template_rtc.h:315
#define vsf_rtc_capability(__RTC)
Definition vsf_template_rtc.h:318
#define vsf_rtc_enable(__RTC)
Definition vsf_template_rtc.h:316