blob: 77a3c5ce9cee229bfa6a76239aa8776e3b18b089 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**
2* @file rtc_timer.h
3* @brief Public APIs of Sanechips
4*
5* Copyright (C) 2017 Sanechips Technology Co., Ltd.
6* @author Linxu Gebin
7* @defgroup si_id Sanechips
8*
9* This program is free software; you can redistribute it and/or modify
10* it under the terms of the GNU General Public License version 2 as
11* published by the Free Software Foundation.
12*************************************************************************
13*/
14
15#ifndef _RTC_TIMER_H
16#define _RTC_TIMER_H
17
18/*******************************************************************************
19 * Include header files *
20 ******************************************************************************/
21#include <sys/time.h>
22#include "message.h"
23
24/*******************************************************************************
25 * Macro definitions *
26******************************************************************************/
27
28#ifndef DOXYGEN_SHOULD_SKIP_THIS
29/*******************************************************************************
30 * Type definitions *
31 ******************************************************************************/
32/**
33* @brief rtc message type
34* @note
35*/
36enum RTC_CPU {
xf.libdd93d52023-05-12 07:10:14 -070037 RTC_CPU_CAP = 0, //rtcÓÉCAP·¢Æð
lh9ed821d2023-04-07 01:36:19 -070038 RTC_CPU_AP, //rtcÓÉAP·¢Æð
39};
40
41/**
42* @brief rtc type
43* @note
44*/
45typedef enum {
46 RTC_ID_START = 0,
47 WIFI_INTERVAL_SLEEP,
48 WIFI_PWR_SAVE,
49 WIFI_WAKE_UP_SYSTEM,
50 WIFI_WPS_RESULT_CHECK,
51 WIFI_TSW_SLEEP,
52 WIFI_TSW_WAKEUP,
53 WIFI_ACL_SERVICE,
54 WDT_TEMP_PROTECT,
55 RTC_SAFECARE_CONTIME,
56 RTC_SAFECARE_DELAY,
57 RTC_ID_FP_CLOCK,
58 RTC_ID_NOTDISTURB_BEGIN,
59 RTC_ID_NOTDISTURB_END,
60 RTC_ID_MMI_ALARM,
61 RTC_ID_MMI_CLOCK_MODE_CHECK,
62 RTC_ID_TRACK_BEGIN,
63 RTC_ID_TRACK_UPLOAD=RTC_ID_TRACK_BEGIN,
64 RTC_ID_TRACK_BASE,
65 RTC_ID_TRACK_SERVER_CON,
66 RTC_ID_TRACK_SLAVE_SERVER_CON,
67 RTC_ID_TRACK_SLAVE_SERVER_CMD,
68 RTC_ID_TRACK_DEBUG_SERVER_CON,
69 RTC_ID_TRACK_LINK,
70 RTC_ID_TRACK_LINK_TIMEOUT,
71 RTC_ID_TRACK_AGPS,
72 RTC_ID_TRACK_WEATHER_UPDATE,
73 RTC_ID_TRACK_END,
xf.li742dd022023-06-08 01:43:32 -070074 RTC_ID_SC_TIMER,
75 RTC_ID_SC_ALARM,
lh9ed821d2023-04-07 01:36:19 -070076 RTC_ID_END,
77} RTC_ID;
78#endif
79
80/**
81* @brief rtc ÏûÏ¢ÀàÐÍ
82* @param RTC_MSG_ALARM_ELAPSED µ±¶¨Ê±Æ÷´¥·¢Ê±»á·¢Õâ¸öÏûÏ¢¸ø¶¨Ê±Æ÷ÓµÓÐÕß
83* @param RTC_MSG_TIME_CHANGED RTCʱ¼ä¸üÐÂ:±íʾÊÀ½çʱ¼ä·¢Éú±ä»¯£¬¼´Ê±¼äͬ²½Íê³É»òÕßÓû§ÊÖ¶¯ÖØÐÂÉèÖõ±Ç°µÄÊÀ½çʱ¼äÁË£¬´ËʱRTC½ø³Ì»á¹ã²¥¸øÒÑ×¢²áÊÀ½çʱ¼äµÄÄ£¿é£¬ÒÔÈÃÏà¹ØÄ£¿é½øÐÐÊÀ½çʱ¼ä¶¨Ê±Æ÷µÄÖØÐÂÉèÖÃ
84* @note
85*/
86#ifndef DOXYGEN_SHOULD_SKIP_THIS
87enum RTC_MSG_CMD {
88 RTC_MSG_GET_TIME = MSG_CMD_RTC_BASE, //»ñȡʱ¼ä£¬Ö±½Óµ÷ÓÃlinuxϵͳʱ¼ä½Ó¿Ú
89 RTC_MSG_SET_TIME, //ÉèÖÃʱ¼ä
90 RTC_MSG_ADD_ALARM, //Ìí¼Órtc¶¨Ê±Æ÷
91 RTC_MSG_DEL_ALARM, //ɾ³ýrtc¶¨Ê±Æ÷
92 RTC_MSG_ALARM_TIMEOUT, //RTC alarm¶¨Ê±Æ÷ʱ¼ä³¬Ê±
93 RTC_MSG_TIMER_TIMEOUT, //RTC timer¶¨Ê±Æ÷ʱ¼ä³¬Ê±
94 RTC_MSG_ALARM_ELAPSED, //µ±¶¨Ê±Æ÷´¥·¢Ê±»á·¢Õâ¸öÏûÏ¢¸ø¶¨Ê±Æ÷ÓµÓÐÕß
95 RTC_MSG_DEL_ALL, //Çå³ýËùÓйػú²»±£´æµÄ¶¨Ê±Æ÷£¬·ñÔòrtc¶¨Ê±Æ÷µ½µã»¹»áÉϱ¨
96 RTC_MSG_TIME_CHANGED, //RTCʱ¼ä¸üÐÂ:±íʾÊÀ½çʱ¼ä·¢Éú±ä»¯£¬¼´Ê±¼äͬ²½Íê³É»òÕßÓû§ÊÖ¶¯ÖØÐÂÉèÖõ±Ç°µÄÊÀ½çʱ¼äÁË£¬´ËʱRTC½ø³Ì»á¹ã²¥¸øÒÑ×¢²áÊÀ½çʱ¼äµÄÄ£¿é£¬ÒÔÈÃÏà¹ØÄ£¿é½øÐÐÊÀ½çʱ¼ä¶¨Ê±Æ÷µÄÖØÐÂÉèÖÃ
xf.li742dd022023-06-08 01:43:32 -070097 RTC_MSG_SNTP_UPDATE, //SNTPͬ²½
lh9ed821d2023-04-07 01:36:19 -070098};
99#endif
100
101/**
102* @brief rtc data buffer
103* @param srcModule ´´½¨¶¨Ê±Æ÷µÄÄ£¿é
104* @param module ¶¨Ê±Æ÷id
105* @param ulSec ¼ä¸ôʱ¼ä£¬µ¥Î»:s
106* @param time_val µ±Ç°Ê±¼ä
107* @param wakeup ¹Ø»ú»½ÐÑ£¬1:´ò¿ª£¬0:¹Ø±Õ
108* @param is_utc ÊÇ·ñutcʱ¼ä£¬
109* @param cpu rtc·¢ÆðµÄcpu£¬ 0: cp, 1:ap
110* @note utcʱ¼äÕý³£±È½Ï³¤£¬ÓÃWKALM¶¨Ê±Æ÷
111*/
112typedef struct tag_RTC_DATA_BUF {
113 int srcModule;
114 unsigned int module;
115 unsigned long ulSec;
116 unsigned long time_val;
117 int wakeup;
118 int is_utc;
119 int cpu;
120} RTC_DATA_BUF;
121
122
123/*******************************************************************************
124 * Global function declarations *
125 ******************************************************************************/
126/**
127* @brief Ìí¼Ó¶¨Ê±Æ÷
128* @param ulSec ¶¨Ê±Æ÷ʱ¼ä£¬µ¥Î»Ãë
129* @param rtc_id ¶¨Ê±Æ÷ID
130* @param src_id ´´½¨¶¨Ê±Æ÷µÄÄ£¿éID
131* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1
132*/
133int rtc_timer_add(unsigned long ulSec, RTC_ID rtc_id, int src_id);
134
135/**
136* @brief Ìí¼Ó¶¨Ê±Æ÷
137* @param time ¶¨Ê±Æ÷ʱ¼ä£¬µ¥Î»ÊÀ½çʱÖÓ,ÐèÒªÌî: tm_sec/tm_min/tm_hour/tm_mday/tm_mon/tm_year
138* @param rtc_id ¶¨Ê±Æ÷ID£¬
139* @param src_id ´´½¨¶¨Ê±Æ÷µÄÄ£¿éID
140* @param wakeup ¹Ø»úÊÇ·ñ»½ÐÑ
141* @note wakeup ÊÇ0²»»½ÐÑ, 1 »½ÐÑ
142* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1
143*/
144int rtc_timer_add_utc(struct tm *time, RTC_ID rtc_id, int src_id, int wakeup);
145
146
147/**
148* @brief ɾ³ý¶¨Ê±Æ÷
149* @param rtc_id ¶¨Ê±Æ÷ID
150* @param src_id ´´½¨¶¨Ê±Æ÷µÄÄ£¿éID
151* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1
152*/
153int rtc_timer_del(RTC_ID rtc_id, int src_id);
154
155
156/**
157* @brief ɾ³ýËùÓж¨Ê±Æ÷
158* @param src_id ɾ³ý¶¨Ê±Æ÷µÄÄ£¿éID
159* @param req_cmd »Ø¸´µÄÏûÏ¢cmd
160* @return ³É¹¦·µ»Ø0£¬Ê§°Ü·µ»Ø-1
161*/
162int rtc_timer_del_all(int src_id, unsigned short req_cmd);
163
164
165/**
166* @brief ÉèÖÃrtcµ±Ç°Ê±¼ä
167* @param src_id ÉèÖÃʱ¼äµÄÄ£¿éID
168* @return ÉèÖÃrtcµ±Ç°Ê±¼ä
169*/
170int rtc_set_time(int src_id);
171
172#endif
173
174