99 lines
2.8 KiB
C
99 lines
2.8 KiB
C
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description: rtc_api.h
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2024-07-12
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#ifndef RTC_API_H
|
|
#define RTC_API_H
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
#endif
|
|
|
|
#define ALARM_ENABLE 0
|
|
|
|
#if ALARM_ENABLE
|
|
typedef uint32_t (*alarm_callback)(void *);
|
|
#endif
|
|
|
|
struct rtc_time
|
|
{
|
|
int tm_year; // 年 1900-2099
|
|
int tm_mon; // 月 1-12
|
|
int tm_mday; // 日 1-31
|
|
int tm_hour; // 时 0-23
|
|
int tm_min; // 分 0-59
|
|
int tm_sec; // 秒 0-59
|
|
int tm_wday; // 星期 0-6
|
|
int tm_yday; // 一年中的第几天 1-365
|
|
int tm_isdst; // 夏令时
|
|
};
|
|
|
|
struct rtc_class_ops
|
|
{
|
|
uint32_t (*open)(void); // 打开
|
|
void (*close)(void); // 释放
|
|
uint32_t (*set_rtc_time)(const struct rtc_time *);
|
|
uint32_t (*set_standard_time)(const struct tm *);
|
|
uint32_t (*get_rtc_time)(struct rtc_time *); // 读时间
|
|
uint32_t (*get_rtc_utc_time)(struct rtc_time *); // 读UTC时间
|
|
uint32_t (*get_standard_time)(struct tm *); // 读时间
|
|
uint32_t (*set_timestamp)(const uint64_t timestamp); // 设置UTC秒时间戳
|
|
uint32_t (*set_ms_timestamp)(const uint64_t timestamp); // 设置UTC毫秒时间戳
|
|
uint32_t (*get_timestamp)(uint64_t *timestamp); // 读UTC时间戳
|
|
uint32_t (*get_ms_timestamp)(uint64_t *timestamp); // 读UTC毫秒时间戳
|
|
uint32_t (*set_diff)(int64_t diff); // 设置时间偏移
|
|
uint32_t (*get_diff)(int64_t *); // 读时间偏移
|
|
#if ALARM_ENABLE
|
|
uint32_t (*get_alarm)(struct tm *); // 读闹钟
|
|
uint32_t (*set_alarm)(const struct tm *); // 设闹钟
|
|
uint32_t (*register_alarm_callback)(alarm_callback callback); // 读回调函数
|
|
#endif
|
|
};
|
|
|
|
/**
|
|
* @brief 解析时间字符串
|
|
* @param[in] str
|
|
* @param[out] time
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t tjd_driver_rtc_parse_str(const char *str, struct rtc_time *time);
|
|
|
|
/**
|
|
* @brief 时间转字符串
|
|
* @param[int] time
|
|
* @param[out] str
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t tjd_driver_rtc_parse_time(const struct rtc_time *time, char *str);
|
|
|
|
/**
|
|
* @brief 同步蓝牙时间
|
|
* @param[in] date 蓝牙传输的时间数据
|
|
* @param[in] len 数据长度
|
|
* @return uint32_t
|
|
*/
|
|
uint32_t tjd_driver_rtc_sync_bt_time(uint8_t *data, uint32_t len);
|
|
|
|
uint32_t tjd_driver_rtc_save_time(void);
|
|
|
|
struct rtc_class_ops *tjd_driver_rtc_get_ops(void);
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
#endif |