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
38#ifndef VSF_RTC_CFG_MULTI_CLASS
39# define VSF_RTC_CFG_MULTI_CLASS ENABLED
40#endif
41
52#if defined(VSF_HW_RTC_COUNT) && !defined(VSF_HW_RTC_MASK)
53# define VSF_HW_RTC_MASK VSF_HAL_COUNT_TO_MASK(VSF_HW_RTC_COUNT)
54#endif
55
62#if defined(VSF_HW_RTC_MASK) && !defined(VSF_HW_RTC_COUNT)
63# define VSF_HW_RTC_COUNT VSF_HAL_MASK_TO_COUNT(VSF_HW_RTC_MASK)
64#endif
65
74#ifndef VSF_RTC_CFG_PREFIX
75# if VSF_RTC_CFG_MULTI_CLASS == ENABLED
76# define VSF_RTC_CFG_PREFIX vsf
77# elif defined(VSF_HW_RTC_COUNT) && (VSF_HW_RTC_COUNT != 0)
78# define VSF_RTC_CFG_PREFIX vsf_hw
79# else
80# define VSF_RTC_CFG_PREFIX vsf
81# endif
82#endif
83
92#ifndef VSF_RTC_CFG_FUNCTION_RENAME
93# define VSF_RTC_CFG_FUNCTION_RENAME ENABLED
94#endif
95
104#ifndef VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK
105# define VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK DISABLED
106#endif
107
114#ifndef VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG
115# define VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG DISABLED
116#endif
117
124#ifndef VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY
125# define VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY DISABLED
126#endif
127
136#ifndef VSF_RTC_CFG_TIME_TYPE
137# define VSF_RTC_CFG_TIME_TYPE uint64_t
138#endif
139
148#ifndef VSF_RTC_CFG_INHERIT_HAL_CAPABILITY
149# define VSF_RTC_CFG_INHERIT_HAL_CAPABILITY ENABLED
150#endif
151
162#ifndef VSF_RTC_CFG_REIMPLEMENT_TYPE_CTRL
163# define VSF_RTC_CFG_REIMPLEMENT_TYPE_CTRL DISABLED
164#endif
165
166/*============================ MACROFIED FUNCTIONS ===========================*/
167
178#define VSF_RTC_APIS(__prefix_name) \
179 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, init, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr) \
180 __VSF_HAL_TEMPLATE_API(__prefix_name, void, rtc, fini, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr) \
181 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, get_configuration, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr) \
182 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, rtc, enable, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr) \
183 __VSF_HAL_TEMPLATE_API(__prefix_name, fsm_rt_t, rtc, disable, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr) \
184 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_rtc_capability_t, rtc, capability, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr) \
185 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, get, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, vsf_rtc_tm_t *rtc_tm) \
186 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, set, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, const vsf_rtc_tm_t *rtc_tm) \
187 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, get_time, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, vsf_rtc_time_t *second_ptr, vsf_rtc_time_t *millisecond_ptr) \
188 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, set_time, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, vsf_rtc_time_t seconds, vsf_rtc_time_t milliseconds) \
189 __VSF_HAL_TEMPLATE_API(__prefix_name, vsf_err_t, rtc, ctrl, VSF_MCONNECT(__prefix_name, _t) *rtc_ptr, vsf_rtc_ctrl_t ctrl, void* param)
190
191/*============================ TYPES =========================================*/
192
193#if VSF_RTC_CFG_REIMPLEMENT_TYPE_IRQ_MASK == DISABLED
202typedef enum vsf_rtc_irq_mask_t {
213#endif
214
223enum {
224#ifndef VSF_RTC_IRQ_ALL_BITS_MASK
234#endif
235};
236
246
255typedef struct vsf_rtc_tm_t {
263
271
281
289
299
309
317
328
329
330#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CFG == DISABLED
331typedef struct vsf_rtc_t vsf_rtc_t;
332
345typedef void vsf_rtc_isr_handler_t(void *target_ptr, vsf_rtc_t *rtc_ptr, vsf_rtc_irq_mask_t irq_mask);
346
353typedef struct vsf_rtc_isr_t {
358
365typedef struct vsf_rtc_cfg_t {
368#endif
369
378#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY == DISABLED
379typedef struct vsf_rtc_capability_t {
380#if VSF_RTC_CFG_INHERIT_HAL_CAPABILITY == ENABLED
390#endif /* VSF_RTC_CFG_INHERIT_HAL_CAPABILITY */
391
402#endif /* VSF_RTC_CFG_REIMPLEMENT_TYPE_CAPABILITY */
403
404#if VSF_RTC_CFG_REIMPLEMENT_TYPE_CTRL == DISABLED
413typedef enum vsf_rtc_ctrl_t {
433#endif
434
439typedef struct vsf_rtc_op_t {
441#undef __VSF_HAL_TEMPLATE_API
442#define __VSF_HAL_TEMPLATE_API VSF_HAL_TEMPLATE_API_FP
444
445 VSF_RTC_APIS(vsf_rtc)
447
448#if VSF_RTC_CFG_MULTI_CLASS == ENABLED
453struct vsf_rtc_t {
457};
458#endif
459
460/*============================ GLOBAL VARIABLES ==============================*/
461/*============================ PROTOTYPES ====================================*/
462
481extern vsf_err_t vsf_rtc_init(vsf_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr);
482
494extern void vsf_rtc_fini(vsf_rtc_t *rtc_ptr);
495
507extern fsm_rt_t vsf_rtc_enable(vsf_rtc_t *rtc_ptr);
508
520extern fsm_rt_t vsf_rtc_disable(vsf_rtc_t *rtc_ptr);
521
534
555
569extern vsf_err_t vsf_rtc_get(vsf_rtc_t *rtc_ptr, vsf_rtc_tm_t *rtc_tm);
570
584extern vsf_err_t vsf_rtc_set(vsf_rtc_t *rtc_ptr, const vsf_rtc_tm_t *rtc_tm);
585
601extern vsf_err_t vsf_rtc_get_time(vsf_rtc_t *rtc_ptr, vsf_rtc_time_t *second_ptr, vsf_rtc_time_t *millisecond_ptr);
602
618extern vsf_err_t vsf_rtc_set_time(vsf_rtc_t *rtc_ptr, vsf_rtc_time_t seconds, vsf_rtc_time_t milliseconds);
619
635extern vsf_err_t vsf_rtc_ctrl(vsf_rtc_t *rtc_ptr, vsf_rtc_ctrl_t ctrl, void * param);
636
637/*============================ MACROFIED FUNCTIONS ===========================*/
638
640#if VSF_RTC_CFG_FUNCTION_RENAME == ENABLED
641# define __vsf_rtc_t VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_t)
642# define vsf_rtc_init(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_init) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
643# define vsf_rtc_get_configuration(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_get_configuration) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
644# define vsf_rtc_enable(__RTC) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_enable) ((__vsf_rtc_t *)(__RTC))
645# define vsf_rtc_disable(__RTC) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_disable) ((__vsf_rtc_t *)(__RTC))
646# define vsf_rtc_capability(__RTC) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_capability) ((__vsf_rtc_t *)(__RTC))
647# define vsf_rtc_get(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_get) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
648# define vsf_rtc_set(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_set) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
649# define vsf_rtc_get_time(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_get_time) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
650# define vsf_rtc_set_time(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_set_time) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
651# define vsf_rtc_ctrl(__RTC, ...) VSF_MCONNECT(VSF_RTC_CFG_PREFIX, _rtc_ctrl) ((__vsf_rtc_t *)(__RTC), ##__VA_ARGS__)
652#endif
654
655#ifdef __cplusplus
656}
657#endif /* __cplusplus */
658
659#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:204
RTC capability structure. Describes the features and capabilities supported by the RTC hardware.
Definition vsf_template_rtc.h:379
inherit(vsf_peripheral_capability_t) vsf_rtc_irq_mask_t irq_mask
Inherit common peripheral capabilities. Must be the first member of the structure.
RTC configuration structure.
Definition vsf_template_rtc.h:365
vsf_rtc_isr_t isr
Interrupt service routine configuration.
Definition vsf_template_rtc.h:366
RTC interrupt service routine configuration structure.
Definition vsf_template_rtc.h:353
vsf_arch_prio_t prio
Priority level for RTC interrupts.
Definition vsf_template_rtc.h:356
void * target_ptr
User context pointer passed to the handler.
Definition vsf_template_rtc.h:355
vsf_rtc_isr_handler_t * handler_fn
Interrupt handler function to process RTC interrupts.
Definition vsf_template_rtc.h:354
RTC operation function pointer type, used for RTC Multi Class support.
Definition vsf_template_rtc.h:439
RTC instance structure, used for RTC Multi Class support, not needed in non Multi Class mode.
Definition vsf_template_rtc.h:453
const vsf_rtc_op_t * op
Definition vsf_template_rtc.h:456
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
vsf_rtc_irq_mask_t
Definition rtc.h:109
void vsf_rtc_isr_handler_t(void *target_ptr, vsf_rtc_t *rtc_ptr, vsf_rtc_irq_mask_t irq_mask)
Definition rtc.h:118
fsm_rt_t
Definition vsf_fsm.h:315
@ VSF_RTC_IRQ_ALL_BITS_MASK
All supported RTC interrupt masks combined. Includes all interrupt types the RTC hardware supports.
Definition vsf_template_rtc.h:233
vsf_err_t vsf_rtc_init(vsf_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr)
Initialize a RTC instance.
Definition rtc_common.c:39
#define VSF_RTC_CFG_TIME_TYPE
Configure the data type used for time representation.
Definition vsf_template_rtc.h:137
vsf_err_t vsf_rtc_get(vsf_rtc_t *rtc_ptr, vsf_rtc_tm_t *rtc_tm)
Get RTC date and time.
Definition rtc_common.c:75
vsf_rtc_ctrl_t
RTC control commands for hardware-specific operations.
Definition vsf_template_rtc.h:413
@ __VSF_RTC_CTRL_DUMMY
Dummy value for compilation, required when no actual control commands are defined.
Definition vsf_template_rtc.h:431
struct vsf_rtc_cfg_t vsf_rtc_cfg_t
RTC configuration structure.
fsm_rt_t vsf_rtc_enable(vsf_rtc_t *rtc_ptr)
Enable a RTC instance.
Definition rtc_common.c:57
#define VSF_RTC_APIS(__prefix_name)
RTC API template macro, used to generate RTC type, specific prefix function declarations,...
Definition vsf_template_rtc.h:178
vsf_err_t vsf_rtc_set(vsf_rtc_t *rtc_ptr, const vsf_rtc_tm_t *rtc_tm)
Set RTC date and time.
Definition rtc_common.c:84
void vsf_rtc_fini(vsf_rtc_t *rtc_ptr)
Finalize a RTC instance.
Definition rtc_common.c:48
fsm_rt_t vsf_rtc_disable(vsf_rtc_t *rtc_ptr)
Disable a RTC instance.
Definition rtc_common.c:66
vsf_rtc_capability_t vsf_rtc_capability(vsf_rtc_t *rtc_ptr)
Get the capability of RTC instance.
Definition rtc_common.c:111
vsf_err_t vsf_rtc_get_time(vsf_rtc_t *rtc_ptr, vsf_rtc_time_t *second_ptr, vsf_rtc_time_t *millisecond_ptr)
Get RTC time in seconds and milliseconds.
Definition rtc_common.c:93
VSF_RTC_CFG_TIME_TYPE vsf_rtc_time_t
RTC time type definition.
Definition vsf_template_rtc.h:245
vsf_rtc_irq_mask_t
RTC interrupt mask definition. Used to identify and manage different types of RTC interrupts.
Definition vsf_template_rtc.h:202
@ VSF_RTC_IRQ_MASK_ALARM
Alarm interrupt mask. Triggers when the RTC time matches the configured alarm time.
Definition vsf_template_rtc.h:211
void vsf_rtc_isr_handler_t(void *target_ptr, vsf_rtc_t *rtc_ptr, vsf_rtc_irq_mask_t irq_mask)
RTC interrupt handler function type.
Definition vsf_template_rtc.h:345
vsf_err_t vsf_rtc_get_configuration(vsf_rtc_t *rtc_ptr, vsf_rtc_cfg_t *cfg_ptr)
Get the current configuration of an RTC instance.
Definition rtc_common.c:120
struct vsf_rtc_capability_t vsf_rtc_capability_t
RTC capability structure. Describes the features and capabilities supported by the RTC hardware.
vsf_err_t vsf_rtc_set_time(vsf_rtc_t *rtc_ptr, vsf_rtc_time_t seconds, vsf_rtc_time_t milliseconds)
Set RTC time in seconds and milliseconds.
Definition rtc_common.c:102
vsf_err_t vsf_rtc_ctrl(vsf_rtc_t *rtc_ptr, vsf_rtc_ctrl_t ctrl, void *param)
Calls the specified RTC command.
Definition rtc_common.c:130
struct vsf_rtc_isr_t vsf_rtc_isr_t
RTC interrupt service routine configuration structure.
Generated from commit: vsfteam/vsf@b2e9e8a