[Bugfix][T106BUG-181] Resolve the problem poweralarm not start on time
Only Configure:No
Affected branch:master
Affected module:Rtc
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Yes
Change-Id: Icf0556362231174cadc9a28bd647cac72700c645
diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
index 3d17411..b3b7827 100755
--- a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
@@ -31,7 +31,6 @@
static int wk_rtc_id = 1;
-static int pw_rtc_id = 2;
static int wk_srcid = 0;
typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
@@ -42,6 +41,10 @@
extern int sc_rtc_timer_add_utc(int srcid, int rtc_id, struct tm *utc_sec, int wakeup, sc_rtc_timer_exp_cb rtc_notify);
+extern int sc_rtc_get_poweroff_alarm_modid(int src_id,char *name);
+
+extern int sc_rtc_add_poweroff_alarm(int srcid, int alarm_modid, int rtc_id, struct tm *utc_sec, sc_rtc_timer_exp_cb rtc_notify);
+
/*****************************************
* @brief:sc_rtc_timer_add_cb
* @param count [IN]:src_id, rtc_id,
@@ -72,10 +75,10 @@
int ret = 0;
char *buf_bak = buffer;
time_t tmp_time = 0;
- struct tm *ptime = NULL;
+
struct tm *wake_arlarm = NULL;
tmp_time = time(NULL);
- ptime = localtime(&tmp_time);
+ localtime(&tmp_time);
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);
@@ -155,7 +158,15 @@
unsigned long time_sec = 0;
int ret = 0;
char *buf_bak = buffer;
-
+
+ int alarmid = 0;
+ char username[8] = "user";
+ time_t tmp_time = 0;
+ struct tm *power_arlarm = NULL;
+ tmp_time = time(NULL);
+ localtime(&tmp_time);
+
+
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);
@@ -181,6 +192,10 @@
buffer = buf_bak;
time_sec = strtoul(buffer,NULL,10);
+
+ tmp_time += time_sec;
+ power_arlarm = localtime(&tmp_time);
+
if(time_sec < MIN_TIME || time_sec > MAX_TIME || errno == ERANGE)
{
LYERRLOG("Illeagle input: too large or too small !!!");
@@ -194,23 +209,30 @@
LYERRLOG("rtc_timer_init fail!");
return -1;
}
- ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
- if(ret < 0)
+
+ alarmid = sc_rtc_get_poweroff_alarm_modid(srcid, username);
+ if(alarmid < 0)
{
- LYERRLOG("Add rtc timer failed!!!!");
+ LYERRLOG("Get poweroff alarm id failed !!!");
return -1;
}
-
- LYINFLOG("Set poweralarm success !!!");
+
+ ret = sc_rtc_add_poweroff_alarm(srcid, alarmid, 0, power_arlarm, sc_rtc_timer_add_cb);
+ if(ret < 0)
+ {
+ LYERRLOG("Set power alarm failed !!!");
+ return -1;
+ }
+ LYINFLOG("Set power alarm success !!!!");
ret = sc_rtc_timer_uninit();
if(ret != 0)
{
- LYINFLOG("Deinit failed");
+ LYINFLOG("Deinit failed!!!");
}
return 0;
-
+
}
/**********************************************
@@ -254,6 +276,18 @@
int ret = 0;
int srcid = 0;
+ int alarmid = 0;
+ char username[8] = "user";
+
+ time_t tmp_time = 0;
+ struct tm *power_arlarm = NULL;
+ tmp_time = time(NULL);
+ localtime(&tmp_time);
+
+
+ tmp_time += time_sec;
+ power_arlarm = localtime(&tmp_time);
+
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);
@@ -262,30 +296,39 @@
LYERRLOG("Illeagle input: too large or too small !!!");
return -1;
}
-
- LYINFLOG("lynq_set_poweralarm %lu seconds",time_sec);
+
+ LYINFLOG("lynq_set_poweralarm %lu seconds",time_sec);
srcid = sc_rtc_timer_init();
if (srcid <= 0)
{
LYERRLOG("rtc_timer_init fail!");
return -1;
}
- ret = sc_rtc_timer_add(srcid, pw_rtc_id, time_sec, sc_rtc_timer_add_cb);
+
+ alarmid = sc_rtc_get_poweroff_alarm_modid(srcid, username);
+ if(alarmid < 0)
+ {
+ LYERRLOG("Get poweroff alarm id failed !!!");
+ return -1;
+ }
+
+ ret = sc_rtc_add_poweroff_alarm(srcid, alarmid, 0, power_arlarm, sc_rtc_timer_add_cb);
if(ret < 0)
{
- LYINFLOG("Add rtc timer failed!!!!");
+ LYERRLOG("Set power alarm failed !!!");
return -1;
}
- LYINFLOG("Set poweralarm success !!!");
-
+ LYINFLOG("Set power alarm success !!!!");
+
ret = sc_rtc_timer_uninit();
if(ret != 0)
{
- LYINFLOG("Deinit failed");
+ LYINFLOG("Deinit rtc_timer failed!!!");
}
return 0;
+
}
@@ -304,10 +347,9 @@
int ret = 0;
time_t tmp_time = 0;
- struct tm *ptime = NULL;
struct tm *wake_arlarm = NULL;
tmp_time = time(NULL);
- ptime = localtime(&tmp_time);
+ localtime(&tmp_time);
LYLOGSET(LOG_INFO);
LYLOGEINIT(USER_LOG_TAG);