Files
luban-lite-t3e-pro/application/rt-thread/t3e-pro/components/RTC_Clock/ESP32_Clock.h

152 lines
4.7 KiB
C
Raw Normal View History

2025-09-30 11:56:06 +08:00
/******************************************************************************
Filename: ESP32_Clock.h
Revised: $Date: 2019-12-02
Revision:
Description: ESP32 Clock definition and manipulation functions.
******************************************************************************/
#ifndef __ESP32_CLOCK_H__
#define __ESP32_CLOCK_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "rtthread.h"
#include <aic_core.h>
#include <aic_hal.h>
#include "rtconfig.h"
#ifndef ULOG_USING_SYSLOG
#include <ulog.h>
#else
#include <syslog.h>
#endif /* ULOG_USING_SYSLOG */
#ifdef __cplusplus
extern "C"
{
#endif
//定义一个全局变量
typedef struct
{
uint16_t type; //设备类型: 0代表无设备1~255表示lora/sub1g设备0xfffe表示433设备
uint32_t device_id; //设备id
uint32_t delay_value; //设备延迟重复触发时间(单位是s);如果为0 触发的时候重新赋值 再次触发 检测不为0 则触发无效
uint32_t leave_value; //红外多久无人上报
}REPEATTRIGGER_Info;
/*********************************************************************
* INCLUDES
*/
/*********************************************************************
* MACROS
*/
#define IsLeapYear(yr) (!((yr) % 400) || (((yr) % 100) && !((yr) % 4)))
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* TYPEDEFS
*/
// number of seconds since 0 hrs, 0 minutes, 0 seconds, on the
// 1st of January 1900 UTC
//typedef uint32_t UTCTime;
typedef time_t UTCTime;
// To be used with
typedef struct
{
uint8_t seconds; // 0-59
uint8_t minutes; // 0-59
uint8_t hour; // 0-23
uint8_t day; // 0-30
uint8_t month; // 0-11
uint16_t year; // 1900+
} UTCTimeStruct;
//struct tm
//{
// int tm_sec; // 秒 取值区间为[0,59]
// int tm_min; // 分 - 取值区间为[0,59]
// int tm_hour; // 时 - 取值区间为[0,23]
// int tm_mday; // 一个月中的日期 - 取值区间为[1,31]
// int tm_mon; // 月份从一月开始0代表一月 - 取值区间为[0,11]
// int tm_year; // 年份其值等于实际年份减去1900
// int tm_wday; // 星期 取值区间为[0,6]其中0代表星期天1代表星期一以此类推
// int tm_yday; // 从每年的1月1日开始的天数 取值区间为[0,365]其中0代表1月1日1代表1月2日以此类推
// int tm_isdst; // 夏令时标识符实行夏令时的时候tm_isdst为正。不实行夏令时的进候tm_isdst为0不了解情况时tm_isdst()为负。
//};
/*********************************************************************
* GLOBAL VARIABLES
*/
/*********************************************************************
* FUNCTIONS
*/
/*
* Updates the OSAL clock and Timers from the MAC 320us timer tick.
*/
extern void esp32TimeUpdate( void );
/*
* Set the new time. This will only set the seconds portion
* of time and doesn't change the factional second counter.
* newTime - number of seconds since 0 hrs, 0 minutes,
* 0 seconds, on the 1st of January 1900 UTC
*/
//extern void esp32_setClock( UTCTime newTime );
extern void esp32_setClock(UTCTime newTime);
/*
* Gets the current time. This will only return the seconds
* portion of time and doesn't include the factional second counter.
* returns: number of seconds since 0 hrs, 0 minutes,
* 0 seconds, on the 1st of January 1900 UTC
*/
extern UTCTime esp32_getClock( void );
/*
* Converts UTCTime to UTCTimeStruct
*
* secTime - number of seconds since 0 hrs, 0 minutes,
* 0 seconds, on the 1st of January 1900 UTC
* tm - pointer to breakdown struct
*/
extern void esp32_ConvertUTCTime( UTCTimeStruct *tm, UTCTime secTime );
/*
* Converts UTCTimeStruct to UTCTime (seconds since 00:00:00 01/01/1900)
*
* tm - pointer to UTC time struct
*/
extern UTCTime esp32_ConvertUTCSecs( UTCTimeStruct *tm );
2025-09-30 13:01:24 +08:00
extern long dateToEpoch(int year, int month, int day, int hour, int minute, int second);
2025-09-30 11:56:06 +08:00
/*
* Update/Adjust the esp32 clock and timers
* Msec - elapsed time in milli seconds
*/
extern void esp32AdjustTimer( uint32_t Msec );
void esp32Timeinit(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* OSAL_CLOCK_H */