blob: 945e0a4839a07a02bb9686c7db5a9638b6c6329d [file] [log] [blame]
l.yangb488ebc2023-08-21 17:58:00 +08001/*******************************************************
2*
3* @brief: none
4* @details: Add wakealrm and poweralarm api code
5* @author: l.yang
6* @date: 2023.8.17
7* @version: V1.0
8* @copyright: Copyright (c) MobileTek
9*
10*********************************************/
11
12#include<stdio.h>
13#include<stdlib.h>
14#include<unistd.h>
15#include<stdbool.h>
16#include<log/log.h>
17#include "liblog/lynq_deflog.h"
18#include <include/libpoweralarm.h>
19#include <pthread.h>
20
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define USER_LOG_TAG "LYNQ_POWERALARM"
27
28
29static int wk_rtc_id = 1;
30static int pw_rtc_id = 2;
31static int wk_srcid = 0;
32
33typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
34extern int sc_rtc_timer_init(void);
35extern int sc_rtc_timer_uninit(void );
36extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);
37extern int sc_rtc_timer_del(int srcid, int rtc_id);
38
39
40
41/*****************************************
42* @brief:sc_rtc_timer_add_cb
43* @param count [IN]:src_id, rtc_id,
44* @param sum [OUT]:NA
45* @return :0
46* @todo:
47* @see:NA
48* @warning:
49******************************************/
50int sc_rtc_timer_add_cb(unsigned int src_id, int rtc_id)
51{
52 return 0;
53}
54
55
56/*****************************************
57* @brief:Set wakealarm time
58* @param count [IN]:buffer,
59* @param sum [OUT]:NA
60* @return :success 0, failed -1
61* @todo:
62* @see:NA
63* @warning:
64******************************************/
65ssize_t wakealarm(char *buffer)
66{
67 unsigned long time_sec = 0;
68 int ret = 0;
69
70 LYLOGSET(LOG_INFO);
71 LYLOGEINIT(USER_LOG_TAG);
72
73 if(buffer == NULL)
74 {
75 LYINFLOG("Bad input parameter,exit!!!!");
76 return -1;
77 }
78
l.yang4c4e7382023-08-22 16:13:09 +080079 time_sec = atoll(buffer);
l.yangb488ebc2023-08-21 17:58:00 +080080
l.yang4c4e7382023-08-22 16:13:09 +080081 LYINFLOG("Set wakealarm %lu seconds ",time_sec);
l.yangb488ebc2023-08-21 17:58:00 +080082 wk_srcid = sc_rtc_timer_init();
83 if (wk_srcid <= 0)
84 {
85 LYINFLOG("rtc_timer_init fail!");
86 return -1;
87 }
88 ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
89 if(ret < 0)
90 {
91 LYINFLOG("Add rtc timer failed!!!!");
92 return -1;
93 }
94
95 LYINFLOG("Set wakealarm success !!!");
96
97 ret = sc_rtc_timer_uninit();
98 if(ret != 0)
99 {
100 LYINFLOG("Deinit failed");
101 }
102
103 return 0;
104
105}
106
107
108/*****************************************
109* @brief:set poweralarm time
110* @param count [IN]:buffer,
111* @param sum [OUT]:NA
112* @return :success 0, failed -1
113* @todo:
114* @see:NA
115* @warning:
116******************************************/
117ssize_t poweralarm(char *buffer)
118{
119 int srcid = 0;
120 unsigned long time_sec = 0;
121 int ret = 0;
122
123 LYLOGSET(LOG_INFO);
124 LYLOGEINIT(USER_LOG_TAG);
125
126 if(buffer == NULL)
127 {
128 LYINFLOG("Bad input parameter,exit!!!!");
129 return -1;
130 }
131
l.yang4c4e7382023-08-22 16:13:09 +0800132 time_sec = atoll(buffer);
l.yangb488ebc2023-08-21 17:58:00 +0800133
l.yang4c4e7382023-08-22 16:13:09 +0800134 LYINFLOG("Set poweralarm %lu seconds",time_sec);
l.yangb488ebc2023-08-21 17:58:00 +0800135 srcid = sc_rtc_timer_init();
136 if (srcid <= 0)
137 {
138 LYINFLOG("rtc_timer_init fail!");
139 return -1;
140 }
141 ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
142 if(ret < 0)
143 {
144 LYINFLOG("Add rtc timer failed!!!!");
145 return -1;
146 }
147
148 LYINFLOG("Set poweralarm success !!!");
149
150 ret = sc_rtc_timer_uninit();
151 if(ret != 0)
152 {
153 LYINFLOG("Deinit failed");
154 }
155
156 return 0;
157
158}
159
160/**********************************************
161* @brief:cancel_wakealarm,
162* @param count [IN]:void
163* @param sum [OUT]:NA
164* @return :success 0, failed -1
165* @todo:
166* @see:NA
167* @warning:
168********************************************/
169ssize_t cancel_wakealarm(void)
170{
171 int ret = 0;
172
173 LYINFLOG("Enter cancel_wakealarm ");
174 ret = sc_rtc_timer_del(wk_srcid, wk_rtc_id);
175 if(ret < 0)
176 {
177 LYINFLOG("Del wakealarm failed!!!");
178 return -1;
179 }
180
181 return 0;
182
183}
184
185
186/*****************************************
187* @brief:lynq_set_poweralarm
188* @param count [IN]:unsigned long time_sec
189* @param sum [OUT]:NA
190* @return :success 0, failed -1
191* @todo:
192* @see:NA
193* @warning:
194******************************************/
195int lynq_set_poweralarm(unsigned long time_sec)
196{
l.yang4c4e7382023-08-22 16:13:09 +0800197 LYLOGSET(LOG_INFO);
198 LYLOGEINIT(USER_LOG_TAG);
l.yangb488ebc2023-08-21 17:58:00 +0800199 int ret = 0;
200 int srcid = 0;
l.yang4c4e7382023-08-22 16:13:09 +0800201 LYINFLOG("lynq_set_poweralarm %lu seconds",time_sec);
l.yangb488ebc2023-08-21 17:58:00 +0800202 srcid = sc_rtc_timer_init();
203 if (srcid <= 0)
204 {
205 LYINFLOG("rtc_timer_init fail!");
206 return -1;
207 }
208 ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
209 if(ret < 0)
210 {
211 LYINFLOG("Add rtc timer failed!!!!");
212 return -1;
213 }
214
215 LYINFLOG("Set poweralarm success !!!");
216
217 ret = sc_rtc_timer_uninit();
218 if(ret != 0)
219 {
220 LYINFLOG("Deinit failed");
221 }
222
223 return 0;
224
225}
226
227
228/*****************************************
229* @brief:lynq_set_wakealarm
230* @param count [IN]:unsigned long time_sec
231* @param sum [OUT]:NA
232* @return :success 0, failed -1
233* @todo:
234* @see:NA
235* @warning:
236******************************************/
237int lynq_set_wakealarm(unsigned long time_sec)
238{
239 int ret = 0;
l.yang4c4e7382023-08-22 16:13:09 +0800240
241 LYLOGSET(LOG_INFO);
242 LYLOGEINIT(USER_LOG_TAG);
243
244 LYINFLOG("lynq_set_wakealarm %lu seconds ",time_sec);
l.yangb488ebc2023-08-21 17:58:00 +0800245 wk_srcid = sc_rtc_timer_init();
246 if (wk_srcid <= 0)
247 {
248 LYINFLOG("rtc_timer_init fail!");
249 return -1;
250 }
251 ret = sc_rtc_timer_add(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
252 if(ret < 0)
253 {
254 LYINFLOG("Add rtc timer failed!!!!");
255 return -1;
256 }
257
258 LYINFLOG("Set wakealarm success !!!");
259
260 ret = sc_rtc_timer_uninit();
261 if(ret != 0)
262 {
263 LYINFLOG("Deinit failed!!!");
264 }
265
266 return 0;
267
268}
269
270
271#ifdef __cplusplus
272}
273#endif
274