[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/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp
index a83d3d7..75da1e1 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp
@@ -16,20 +16,26 @@
 st_api_test_case at_api_testcases[] = 

 {

     {0,   "print_help"},

-    {1,   "poweralarm"},

-    {2,   "wakealarm"},

-    {3,   "cancel_wakealarm"},

-    {4,   "lynq_set_poweralarm"},

-    {5,   "lynq_set_wakealarm"},

+    {1,   "lynq_rtc_service_init"},

+    {2,   "poweralarm"},

+    {3,   "wakealarm"},

+    {4,   "cancel_wakealarm"},

+    {5,   "lynq_set_poweralarm"},

+    {6,   "lynq_set_wakealarm"},

+    {7,   "lynq_rtc_service_deinit"},

     {-1,    NULL}

 };

 

+int src_id = -1;

+typedef int (*lynq_wakealarm_add_cb)(unsigned int src_id, int rtc_id);

 

-int (*poweralarm)(char *buffer);

-int (*wakealarm)(char *buffer);

-int (*cancel_wakealarm)();

-int (*lynq_set_poweralarm)(unsigned long time_sec);

-int (*lynq_set_wakealarm)(unsigned long time_sec);

+int (*lynq_rtc_service_init)(void);

+int (*lynq_rtc_service_deinit)(void);

+int (*poweralarm)(char *buffer,int src_id);

+int (*wakealarm)(char *buffer,int srcid,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify);

+int (*cancel_wakealarm)(int src_id,int rtc_id);

+int (*lynq_set_poweralarm)(unsigned long time_sec,int src_id);

+int (*lynq_set_wakealarm)(unsigned long time_sec,int srcid,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify);

 

 void *dlHandle_poweralarm = NULL;

 

@@ -48,10 +54,16 @@
     }

 }

 

+int lynq_wakealarm_add_callback(unsigned int src_id, int rtc_id)

+{

+    printf("wake alarm callback test \n");

+    return 0;

+}

+

+

 int main(int argc,char *argv[])

 {

 

-    int flag = 0; 

     int cmdIdx = 0;

     printf("Enter main function\n");

     

@@ -63,38 +75,53 @@
         return -1;

     }

 

-    poweralarm = (int (*)(char *buffer))dlsym(dlHandle_poweralarm, "poweralarm");

+    poweralarm = (int (*)(char *buffer,int src_ids))dlsym(dlHandle_poweralarm, "poweralarm");

     if(poweralarm == NULL)

     {

         printf("poweralarm is null\n");

         return -1;

     }

 

-   wakealarm = (int (*)(char *buffer))dlsym(dlHandle_poweralarm, "wakealarm");

+    wakealarm = (int (*)(char *buffer,int srcid,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify))dlsym(dlHandle_poweralarm, "wakealarm");

     if(wakealarm == NULL)

     {

         printf("wakealarm is null\n");

         return -1;

     }

-    lynq_set_poweralarm = (int (*)(unsigned long))dlsym(dlHandle_poweralarm,"lynq_set_poweralarm");

+    lynq_set_poweralarm = (int (*)(unsigned long,int src_id))dlsym(dlHandle_poweralarm,"lynq_set_poweralarm");

     if(lynq_set_poweralarm == NULL)

     {

         printf("lynq_set_poweralarm is null\n");

         return -1;

     }

-    lynq_set_wakealarm = (int (*)(unsigned long))dlsym(dlHandle_poweralarm,"lynq_set_wakealarm");

+    lynq_set_wakealarm = (int (*)(unsigned long,int srcid,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify))dlsym(dlHandle_poweralarm,"lynq_set_wakealarm");

     if(lynq_set_wakealarm == NULL)

     {

         printf("lynq_set_wakealarm is null\n");

         return -1;

     }

     

-    cancel_wakealarm = (int (*)())dlsym(dlHandle_poweralarm, "cancel_wakealarm");

+    cancel_wakealarm = (int (*)(int src_id,int rtc_id))dlsym(dlHandle_poweralarm, "cancel_wakealarm");

      if(cancel_wakealarm == NULL)

     {

         printf("cancel_wakealarm is null\n");

         return -1;

     }

+

+    lynq_rtc_service_init = (int(*)())dlsym(dlHandle_poweralarm,"lynq_rtc_service_init");

+    if(lynq_rtc_service_init == NULL)

+    {

+        printf("lynq_rtc_service_init is null\n");

+        return -1;

+    }

+

+    lynq_rtc_service_deinit = (int (*)())dlsym(dlHandle_poweralarm,"lynq_rtc_service_deinit");

+    if(lynq_rtc_service_deinit == NULL)

+    {

+        printf("lynq_rtc_service_deinit is null \n");

+        return -1;

+    }

+    

     print_help();

     while(1)

     {

@@ -111,11 +138,16 @@
                 break;

             case 1:

                 {

+                    src_id = lynq_rtc_service_init();

+                    break;

+                }

+            case 2:

+                {

                     int ret = 0;

                     char tmp_time[32] = {0};

                     printf("Set poweralarm time,e.g: 60 (seconds)\n");

                     scanf("%s",tmp_time);

-                    ret = poweralarm(tmp_time);

+                    ret = poweralarm(tmp_time,src_id);

                     if(ret != 0)

                     {

                         printf("set poweralarm failed\n");

@@ -123,13 +155,15 @@
                     }

                 break;

                 }

-            case 2:

+            case 3:

                 {

                     int ret = 0;

                     char tmp_time[32]={0};

-                    printf("Set wakealarm time ,e.g: 60 (seconds)\n");

-                    scanf("%s",tmp_time);

-                    ret = wakealarm(tmp_time);

+                    int rtc_id = 0;

+                    printf("Set wakealarm time ,e.g: 60  1 (seconds)\n");

+                    scanf("%s%d",tmp_time,&rtc_id);

+                   

+                    ret = wakealarm(tmp_time,src_id,rtc_id,lynq_wakealarm_add_callback);

                     if(ret != 0)

                     {

                         printf("set wakealarm failed\n");

@@ -137,10 +171,13 @@
                     }

                     break;

                 }

-             case 3:

+             case 4:

                 {

                     int ret = 0;

-                    ret = cancel_wakealarm();

+                    int rtc_id = 0;

+                    printf("Please input you want cancel rtc timer rtc id\n");

+                    scanf("%d",&rtc_id);

+                    ret = cancel_wakealarm(src_id,rtc_id);

                     if(ret != 0)

                     {

                         printf("Cancel_wakealarm failed!!!");

@@ -148,13 +185,13 @@
                     }

                     break;

                 }

-             case 4:

+             case 5:

                 { 

                    int ret = 0; 

                    unsigned long time_sec = 0;

-                   printf("Input time_sec you want poweralarm,e.g:60 (seconds)\n");

+                   printf("Input time_sec you want poweralarm,e.g: 60 (seconds)\n");

                    scanf("%lu",&time_sec);

-                   ret =lynq_set_poweralarm(time_sec);

+                   ret =lynq_set_poweralarm(time_sec,src_id);

                    printf("ret is %d\n",ret);

                    if(ret != 0)

                    {

@@ -163,25 +200,40 @@
                    }

                    break;

                 }

-            case 5:

-                { 

+            case 6:

+                 { 

                    int ret = 0; 

                    unsigned long time_sec = 0;

-                   printf("Input time_sec you want wakealarm,e.g:60 (seconds)\n");

-                   scanf("%lu",&time_sec);

-                   ret =lynq_set_wakealarm(time_sec);

+                   int rtc_id;

+                   printf("Input time_sec you want wakealarm,e.g:60  1(seconds)\n");

+                   scanf("%lu%d",&time_sec,&rtc_id);

+                   ret =lynq_set_wakealarm(time_sec,src_id,rtc_id,lynq_wakealarm_add_callback);

                    if(ret != 0)

                    {

                         printf("lynq_set_wakealarm failed\n");

                         return -1;

                    }

                    break;

-               }

+                }

+            case 7:

+                {

+                    int ret  = -1;

+                    printf("rtc servce deinit !!!!!!!!!!!!");

+                    ret = lynq_rtc_service_deinit();

+                    if(ret != 0)

+                    {

+                        printf("lynq rtc service deinit failed \n");

+                        return -1;

+

+                    }

+                    break;

+                }

                 

             default:

                 break;

         }

     }

+

     return 0;

 

 }

diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/include/libpoweralarm.h b/cap/zx297520v3/src/lynq/lib/libpoweralarm/include/libpoweralarm.h
index 54191a6..4110fba 100755
--- a/cap/zx297520v3/src/lynq/lib/libpoweralarm/include/libpoweralarm.h
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/include/libpoweralarm.h
@@ -15,11 +15,17 @@
     extern "C" {

 #endif

 

-ssize_t poweralarm(char * buffer);

-ssize_t wakealarm(char *buffer);

-ssize_t cancel_wakealarm(void);

-int lynq_set_wakealarm(unsigned long  time_sec);

-int lynq_set_poweralarm(unsigned long time_sec);

+typedef int (*lynq_wakealarm_add_cb)(unsigned int src_id, int rtc_id);

+int lynq_rtc_service_init(void);

+int lynq_rtc_service_deinit(void);

+ssize_t poweralarm(char *buffer,int src_id);

+ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify );

+ssize_t cancel_wakealarm(int src_id, int rtc_id);

+

+int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify );

+int  lynq_set_poweralarm(unsigned long time_sec,int src_id);

+

+

 

 

 #ifdef __cplusplus

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