blob: c17d6687bf43f16a0498c0ce2f4e1e37fa530138 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001
2/**************************************************************************
3* #includeÇø
4**************************************************************************/
5#include <stdio.h>
6#include <stdlib.h>
7#include <signal.h>
8#include <sys/time.h>
9#include <syslog.h>
10#include <fcntl.h>
11#include <pthread.h>
12#include <stdlib.h>
13#include <string.h>
14#include <errno.h>
15#include <sys/types.h>
16#include <sys/prctl.h>
17#include <unistd.h>
18#include <linux/rtc.h>
19#include <time.h>
20#include <sys/ipc.h>
21#include <sys/msg.h>
22#include "softap_api.h"
23#include "message.h"
24#include "rtc_timer.h"
25
26/**************************************************************************
27* Êý¾Ý½á¹¹¶¨ÒåÇø
28**************************************************************************/
29/**************************************************************************
30* Íⲿ±äÁ¿ÉùÃ÷Çø
31**************************************************************************/
32/**************************************************************************
33* ºê¶¨ÒåÇø
34**************************************************************************/
35
36/**************************************************************************/
37int rtc_timer_add(ULONG ulSec, RTC_ID rtc_id, int src_id)//add_rtc_timer
38{
39 int ret = -1;
40 int data_len = 0;
41 RTC_DATA_BUF buf = {0};
42 char rtc_cpu[16] = {0};
43 char rtc_cp_ready[8] = {0};
44
45 //¼à¿ØÓÐÄÄЩӦÓÃÉèÖÃÁ˶Ìʱ¼äµÄrtc
46 if (ulSec < 59)
47 slog(MISC_PRINT, SLOG_ERR, "rtc time is %d, less than 60. src:0x%x, id:0x%x \n", ulSec, src_id, rtc_id);
48
49 buf.srcModule = src_id;
50 buf.module = rtc_id;
51 buf.ulSec = ulSec;
52 buf.wakeup = 0;
53 buf.is_utc = 0;
54 data_len = sizeof(RTC_DATA_BUF);
55 buf.time_val = time(0);
56 buf.cpu = RTC_CPU_AP;
57
58 ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_ADD_ALARM, data_len, (unsigned char *)&buf, 0);
59 if (ret != 0) {
60 slog(MISC_PRINT, SLOG_ERR, "rtc: set rtc timer send msg failed \n");
61 return -1;
62 }
63
64 return ret;
65}
66
67int rtc_timer_add_utc(struct tm *sec, RTC_ID rtc_id, int src_id, int wakeup)//add_rtc_timer
68{
69 int ret = -1;
70 time_t cur_sec = time(0);
71 time_t set_sec = mktime(sec);
72 char sntp_result[20] = {0};
73 char rtc_cpu[16] = {0};
74 char rtc_cp_ready[8] = {0};
75
76 slog(MISC_PRINT, SLOG_ERR, "rtc_timer_add_utc enter \n");
77
78#if 0
79 // ÉèÖÃÊÀ½çʱÖÓ¶¨Ê±Æ÷£¬±ØÐëµÈsntp³É¹¦ºó
80 sc_cfg_get("sntp_process_result", sntp_result, sizeof(sntp_result));
81 if (strcmp("success", sntp_result) != 0) {
82 slog(MISC_PRINT, SLOG_ERR, "rtc: set utc timer should be after sntp success\n");
83 return ret;
84 }
85#endif
86 // ÉèÖö¨Ê±Æ÷ʱ¼ä±ØÐëÍíÓÚµ±Ç°Ê±¼ä
87 if (cur_sec >= set_sec) {
88 slog(MISC_PRINT, SLOG_ERR, "rtc: set time-%ld should be after then currnet time-%ld\n", set_sec, cur_sec);
89 return ret;
90 }
91
92 int data_len = 0;
93 RTC_DATA_BUF buf = {0};
94
95 buf.srcModule = src_id;
96 buf.module = rtc_id;
97 buf.ulSec = set_sec - cur_sec;
98 buf.time_val = cur_sec;
99 buf.wakeup = wakeup;
100 buf.is_utc = 1;
101 buf.cpu = RTC_CPU_AP;
102 data_len = sizeof(RTC_DATA_BUF);
103
104 slog(MISC_PRINT, SLOG_ERR, "rtc add utc timer, cur:%ld, set:%ld, ulSec:%d; year:%d, mon:%d, day:%d, hour:%d, min:%d, sec:%d, wday:%d, yday:%d \n", buf.time_val, set_sec, buf.ulSec, sec->tm_year, sec->tm_mon, sec->tm_mday, sec->tm_hour, sec->tm_min, sec->tm_sec, sec->tm_wday, sec->tm_yday);
105 ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_ADD_ALARM, data_len, (unsigned char *)&buf, 0);
106 if (ret != 0) {
107 slog(MISC_PRINT, SLOG_ERR, "rtc: set rtc utc timer send msg failed \n");
108 return -1;
109 }
110
111 return ret;
112}
113
114int rtc_timer_del(RTC_ID rtc_id, int src_id)
115{
116 int ret = -1;
117 int data_len = 0;
118 RTC_DATA_BUF buf = {0};
119
120 buf.srcModule = src_id;
121 buf.module = rtc_id;
122 buf.cpu = RTC_CPU_AP;
123 data_len = sizeof(RTC_DATA_BUF);
124
125 ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_DEL_ALARM, data_len, (unsigned char *) &buf, 0);
126 if (ret == 0)
127 return 0;
128 else
129 return -1;
130}
131
132int rtc_timer_del_all(int src_id, unsigned short req_cmd)
133{
134 int ret = -1;
135
136 ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_DEL_ALL, sizeof(unsigned short), &req_cmd, 0);
137 if (ret == 0)
138 return 0;
139 else
140 return -1;
141}
142
143int rtc_set_time(int src_id)
144{
145 int ret = -1;
146 time_t cur_time = time(0);
147
148 ret = ipc_send_message(src_id, MODULE_ID_RTC_SERVICE, RTC_MSG_SET_TIME, sizeof(time_t), &cur_time, 0);
149 if (ret == 0)
150 return 0;
151 else
152 return -1;
153}
154
155