RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dev_rtc.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2012-10-10 aozima first version.
9 * 2021-06-11 iysheng implement RTC framework V2.0
10 * 2021-07-30 Meco Man move rtc_core.h to rtc.h
11 * 2022-04-05 tyx add timestamp function
12 */
13
14#ifndef __DEV_RTC_H__
15#define __DEV_RTC_H__
16
17#include <rtdef.h>
18#include <sys/time.h>
78
83#ifdef __cplusplus
84extern "C" {
85#endif
86
87#define RT_DEVICE_CTRL_RTC_GET_TIME (RT_DEVICE_CTRL_BASE(RTC) + 0x01)
88#define RT_DEVICE_CTRL_RTC_SET_TIME (RT_DEVICE_CTRL_BASE(RTC) + 0x02)
89#define RT_DEVICE_CTRL_RTC_GET_TIMEVAL (RT_DEVICE_CTRL_BASE(RTC) + 0x03)
90#define RT_DEVICE_CTRL_RTC_SET_TIMEVAL (RT_DEVICE_CTRL_BASE(RTC) + 0x04)
91#define RT_DEVICE_CTRL_RTC_GET_ALARM (RT_DEVICE_CTRL_BASE(RTC) + 0x05)
92#define RT_DEVICE_CTRL_RTC_SET_ALARM (RT_DEVICE_CTRL_BASE(RTC) + 0x06)
93#define RT_DEVICE_CTRL_RTC_GET_TIMESPEC (RT_DEVICE_CTRL_BASE(RTC) + 0x07)
94#define RT_DEVICE_CTRL_RTC_SET_TIMESPEC (RT_DEVICE_CTRL_BASE(RTC) + 0x08)
95#define RT_DEVICE_CTRL_RTC_GET_TIMERES (RT_DEVICE_CTRL_BASE(RTC) + 0x09)
96
101{
102 rt_bool_t enable; /* 0 = alarm disabled, 1 = alarm enabled */
103 rt_int32_t tm_sec; /* alarm at tm_sec */
104 rt_int32_t tm_min; /* alarm at tm_min */
105 rt_int32_t tm_hour; /* alarm at tm_hour */
106 rt_int32_t tm_mday; /* alarm at tm_mday */
107 rt_int32_t tm_mon; /* alarm at tm_mon */
108 rt_int32_t tm_year; /* alarm at tm_year */
109};
110
114{
115 rt_err_t (*init)(void);
116 rt_err_t (*get_secs)(time_t *sec);
117 rt_err_t (*set_secs)(time_t *sec);
120 rt_err_t (*get_timeval)(struct timeval *tv);
121 rt_err_t (*set_timeval)(struct timeval *tv);
122};
123
127typedef struct rt_rtc_device
128{
130 const struct rt_rtc_ops *ops;
132
143 const char *name,
144 rt_uint32_t flag,
145 void *data);
146
156
166
173rt_err_t set_timestamp(time_t timestamp);
174
181rt_err_t get_timestamp(time_t *timestamp);
182
183#ifdef RT_USING_SYSTEM_WORKQUEUE
184rt_err_t rt_soft_rtc_sync(void);
185rt_err_t rt_soft_rtc_set_source(const char *name);
186#endif
187
188#ifdef __cplusplus
189}
190#endif
191
193
194#endif /* __DEV_RTC_H__ */
rt_err_t set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day)
set date
rt_err_t rt_hw_rtc_register(rt_rtc_dev_t *rtc, const char *name, rt_uint32_t flag, void *data)
Register a RTC device
struct rt_rtc_device rt_rtc_dev_t
RTC device structure
rt_err_t set_timestamp(time_t timestamp)
set timestamp
rt_err_t get_timestamp(time_t *timestamp)
get timestamp
rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
set time
int rt_bool_t
rt_base_t rt_err_t
unsigned int rt_uint32_t
signed int rt_int32_t
RTC device structure
struct rt_device parent
const struct rt_rtc_ops * ops
RTC operations
rt_err_t(* set_alarm)(struct rt_rtc_wkalarm *alarm)
rt_err_t(* get_secs)(time_t *sec)
rt_err_t(* set_secs)(time_t *sec)
rt_err_t(* get_timeval)(struct timeval *tv)
rt_err_t(* set_timeval)(struct timeval *tv)
rt_err_t(* init)(void)
rt_err_t(* get_alarm)(struct rt_rtc_wkalarm *alarm)
RTC alarm structure
rt_int32_t tm_sec
rt_int32_t tm_mon
rt_int32_t tm_mday
rt_int32_t tm_hour
rt_int32_t tm_min
rt_int32_t tm_year