[Feature][ZXW-182] Sleep wake-up interface setting callback function
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: I6d7c6e4251c1e7e6ff92d78925b5156aa1a16cb6
diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
index b3b7827..26f57be 100755
--- a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
@@ -30,10 +30,9 @@
#define MAX_TIME 268435456
-static int wk_rtc_id = 1;
-static int wk_srcid = 0;
-
typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
+typedef int (*lynq_wakealarm_add_cb)(unsigned int src_id, int rtc_id);
+
extern int sc_rtc_timer_init(void);
extern int sc_rtc_timer_uninit(void );
extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);
@@ -45,31 +44,67 @@
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,
+* @brief:lynq_rtc_service_init
+* @param count [IN]:NA
* @param sum [OUT]:NA
-* @return :0
+* @return :success src_id, failed -1
* @todo:
* @see:NA
* @warning:
-******************************************/
-int sc_rtc_timer_add_cb(unsigned int src_id, int rtc_id)
+*****************************************/
+int lynq_rtc_service_init(void)
{
+ int src_id = -1;
+
+ LYLOGSET(LOG_INFO);
+ LYLOGEINIT(USER_LOG_TAG);
+
+ src_id = sc_rtc_timer_init();
+ if (src_id <= 0)
+ {
+ LYERRLOG("rtc_timer_init fail!");
+ return -1;
+ }
+ return src_id;
+
+}
+
+/*****************************************
+* @brief:lynq_rtc_service_init
+* @param count [IN]:NA
+* @param sum [OUT]:NA
+* @return :success src_id, failed -1
+* @todo:
+* @see:NA
+* @warning:
+*****************************************/
+int lynq_rtc_service_deinit(void)
+{
+ int ret = -1;
+ ret = sc_rtc_timer_uninit();
+ if(ret != 0)
+ {
+ LYINFLOG("Deinit failed!!!");
+ return -1;
+ }
+
return 0;
+
}
/*****************************************
* @brief:Set wakealarm time
-* @param count [IN]:buffer,
+* @param count [IN]:char *buffer,int src_id ...
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
-ssize_t wakealarm(char *buffer)
+ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
{
unsigned long time_sec = 0;
int ret = 0;
@@ -80,9 +115,6 @@
tmp_time = time(NULL);
localtime(&tmp_time);
- LYLOGSET(LOG_INFO);
- LYLOGEINIT(USER_LOG_TAG);
-
if(buffer == NULL)
{
LYINFLOG("Bad input parameter,exit!!!!");
@@ -115,15 +147,8 @@
wake_arlarm = localtime(&tmp_time);
LYINFLOG("Set wakealarm %lu seconds ",time_sec);
-
- wk_srcid = sc_rtc_timer_init();
- if (wk_srcid <= 0)
- {
- LYINFLOG("rtc_timer_init fail!");
- return -1;
- }
-
- ret = sc_rtc_timer_add_utc(wk_srcid, wk_rtc_id,wake_arlarm,0,sc_rtc_timer_add_cb);
+
+ ret = sc_rtc_timer_add_utc(src_id, rtc_id,wake_arlarm,0,wakealarm_notify);
if(ret < 0)
{
LYINFLOG("Add rtc timer failed!!!!");
@@ -132,12 +157,6 @@
LYINFLOG("Set wakealarm success !!!");
- ret = sc_rtc_timer_uninit();
- if(ret != 0)
- {
- LYINFLOG("Deinit failed");
- }
-
return 0;
}
@@ -145,28 +164,26 @@
/*****************************************
* @brief:set poweralarm time
-* @param count [IN]:buffer,
+* @param count [IN]:char *buffer, int srcid
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
-ssize_t poweralarm(char *buffer)
+ssize_t poweralarm(char *buffer,int src_id )
{
- int srcid = 0;
+
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);
@@ -203,21 +220,16 @@
}
LYINFLOG("Set poweralarm %lu seconds",time_sec);
- srcid = sc_rtc_timer_init();
- if (srcid <= 0)
- {
- LYERRLOG("rtc_timer_init fail!");
- return -1;
- }
- alarmid = sc_rtc_get_poweroff_alarm_modid(srcid, username);
+
+ alarmid = sc_rtc_get_poweroff_alarm_modid(src_id, 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);
+ ret = sc_rtc_add_poweroff_alarm(src_id, alarmid, 0, power_arlarm, NULL);
if(ret < 0)
{
LYERRLOG("Set power alarm failed !!!");
@@ -225,37 +237,31 @@
}
LYINFLOG("Set power alarm success !!!!");
- ret = sc_rtc_timer_uninit();
- if(ret != 0)
- {
- LYINFLOG("Deinit failed!!!");
- }
-
return 0;
}
/**********************************************
* @brief:cancel_wakealarm,
-* @param count [IN]:void
+* @param count [IN]:int src_id, int rtc_id
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
********************************************/
-ssize_t cancel_wakealarm(void)
+ssize_t cancel_wakealarm(int src_id, int rtc_id)
{
int ret = 0;
LYINFLOG("Enter cancel_wakealarm ");
- ret = sc_rtc_timer_del(wk_srcid, wk_rtc_id);
+ ret = sc_rtc_timer_del(src_id, rtc_id);
if(ret < 0)
{
LYERRLOG("Del wakealarm failed!!!");
return -1;
}
-
+ LYINFLOG("Cancel success ");
return 0;
}
@@ -263,19 +269,17 @@
/*****************************************
* @brief:lynq_set_poweralarm
-* @param count [IN]:unsigned long time_sec
+* @param count [IN]:unsigned long time_sec , int src_id
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
-int lynq_set_poweralarm(unsigned long time_sec)
+int lynq_set_poweralarm(unsigned long time_sec,int src_id)
{
int ret = 0;
- int srcid = 0;
-
int alarmid = 0;
char username[8] = "user";
@@ -283,14 +287,11 @@
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);
-
+
if(time_sec < MIN_TIME || time_sec > MAX_TIME )
{
LYERRLOG("Illeagle input: too large or too small !!!");
@@ -298,21 +299,16 @@
}
LYINFLOG("lynq_set_poweralarm %lu seconds",time_sec);
- srcid = sc_rtc_timer_init();
- if (srcid <= 0)
- {
- LYERRLOG("rtc_timer_init fail!");
- return -1;
- }
- alarmid = sc_rtc_get_poweroff_alarm_modid(srcid, username);
+
+ alarmid = sc_rtc_get_poweroff_alarm_modid(src_id, 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);
+ ret = sc_rtc_add_poweroff_alarm(src_id, alarmid, 0, power_arlarm, NULL);
if(ret < 0)
{
LYERRLOG("Set power alarm failed !!!");
@@ -321,12 +317,6 @@
LYINFLOG("Set power alarm success !!!!");
- ret = sc_rtc_timer_uninit();
- if(ret != 0)
- {
- LYINFLOG("Deinit rtc_timer failed!!!");
- }
-
return 0;
@@ -335,14 +325,14 @@
/*****************************************
* @brief:lynq_set_wakealarm
-* @param count [IN]:unsigned long time_sec
+* @param count [IN]:unsigned long time_sec,....
* @param sum [OUT]:NA
* @return :success 0, failed -1
* @todo:
* @see:NA
* @warning:
******************************************/
-int lynq_set_wakealarm(unsigned long time_sec)
+int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
{
int ret = 0;
@@ -350,10 +340,7 @@
struct tm *wake_arlarm = NULL;
tmp_time = time(NULL);
localtime(&tmp_time);
-
- LYLOGSET(LOG_INFO);
- LYLOGEINIT(USER_LOG_TAG);
-
+
if(time_sec < MIN_TIME || time_sec > MAX_TIME)
{
LYERRLOG("Illeagle input: too large or too small !!!");
@@ -361,19 +348,12 @@
}
LYINFLOG("lynq_set_wakealarm %lu seconds ",time_sec);
-
- wk_srcid = sc_rtc_timer_init();
- if (wk_srcid <= 0)
- {
- LYINFLOG("rtc_timer_init fail!");
- return -1;
- }
-
+
tmp_time += time_sec;
wake_arlarm = localtime(&tmp_time);
LYINFLOG("Set wakealarm %lu seconds ",time_sec);
- ret = sc_rtc_timer_add_utc(wk_srcid, wk_rtc_id,wake_arlarm,0,sc_rtc_timer_add_cb);
+ ret = sc_rtc_timer_add_utc(src_id, rtc_id,wake_arlarm,0,wakealarm_notify);
if(ret < 0)
{
LYINFLOG("Add rtc timer failed!!!!");
@@ -381,17 +361,12 @@
}
LYINFLOG("Set wakealarm success !!!");
-
- ret = sc_rtc_timer_uninit();
- if(ret != 0)
- {
- LYINFLOG("Deinit failed!!!");
- }
return 0;
}
+
DEFINE_LYNQ_LIB_LOG(LYNQ_POWERALARM)
#ifdef __cplusplus