[Bugfix][T106BUG-83] add rtc wakealarm and poweralarm api
Only Configure:No
Affected branch:master
Affected module:Rtc
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Need
Change-Id: I153112218065ee7e7af928c4805745d2c8896d91
diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
new file mode 100755
index 0000000..79629a7
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
@@ -0,0 +1,269 @@
+/*******************************************************
+*
+* @brief: none
+* @details: Add wakealrm and poweralarm api code
+* @author: l.yang
+* @date: 2023.8.17
+* @version: V1.0
+* @copyright: Copyright (c) MobileTek
+*
+*********************************************/
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<unistd.h>
+#include<stdbool.h>
+#include<log/log.h>
+#include "liblog/lynq_deflog.h"
+#include <include/libpoweralarm.h>
+#include <pthread.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define USER_LOG_TAG "LYNQ_POWERALARM"
+
+
+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);
+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);
+extern int sc_rtc_timer_del(int srcid, int rtc_id);
+
+
+
+/*****************************************
+* @brief:sc_rtc_timer_add_cb
+* @param count [IN]:src_id, rtc_id,
+* @param sum [OUT]:NA
+* @return :0
+* @todo:
+* @see:NA
+* @warning:
+******************************************/
+int sc_rtc_timer_add_cb(unsigned int src_id, int rtc_id)
+{
+ return 0;
+}
+
+
+/*****************************************
+* @brief:Set wakealarm time
+* @param count [IN]:buffer,
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:
+* @see:NA
+* @warning:
+******************************************/
+ssize_t wakealarm(char *buffer)
+{
+ unsigned long time_sec = 0;
+ int ret = 0;
+
+ LYLOGSET(LOG_INFO);
+ LYLOGEINIT(USER_LOG_TAG);
+
+ if(buffer == NULL)
+ {
+ LYINFLOG("Bad input parameter,exit!!!!");
+ return -1;
+ }
+
+ time_sec = atol(buffer);
+
+ LYINFLOG("Set wakealarm %ld 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(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
+ if(ret < 0)
+ {
+ LYINFLOG("Add rtc timer failed!!!!");
+ return -1;
+ }
+
+ LYINFLOG("Set wakealarm success !!!");
+
+ ret = sc_rtc_timer_uninit();
+ if(ret != 0)
+ {
+ LYINFLOG("Deinit failed");
+ }
+
+ return 0;
+
+}
+
+
+/*****************************************
+* @brief:set poweralarm time
+* @param count [IN]:buffer,
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:
+* @see:NA
+* @warning:
+******************************************/
+ssize_t poweralarm(char *buffer)
+{
+ int srcid = 0;
+ unsigned long time_sec = 0;
+ int ret = 0;
+
+ LYLOGSET(LOG_INFO);
+ LYLOGEINIT(USER_LOG_TAG);
+
+ if(buffer == NULL)
+ {
+ LYINFLOG("Bad input parameter,exit!!!!");
+ return -1;
+ }
+
+ time_sec = atol(buffer);
+
+ LYINFLOG("Set poweralarm %ld seconds",time_sec);
+ srcid = sc_rtc_timer_init();
+ if (srcid <= 0)
+ {
+ LYINFLOG("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)
+ {
+ LYINFLOG("Add rtc timer failed!!!!");
+ return -1;
+ }
+
+ LYINFLOG("Set poweralarm success !!!");
+
+ ret = sc_rtc_timer_uninit();
+ if(ret != 0)
+ {
+ LYINFLOG("Deinit failed");
+ }
+
+ return 0;
+
+}
+
+/**********************************************
+* @brief:cancel_wakealarm,
+* @param count [IN]:void
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:
+* @see:NA
+* @warning:
+********************************************/
+ssize_t cancel_wakealarm(void)
+{
+ int ret = 0;
+
+ LYINFLOG("Enter cancel_wakealarm ");
+ ret = sc_rtc_timer_del(wk_srcid, wk_rtc_id);
+ if(ret < 0)
+ {
+ LYINFLOG("Del wakealarm failed!!!");
+ return -1;
+ }
+
+ return 0;
+
+}
+
+
+/*****************************************
+* @brief:lynq_set_poweralarm
+* @param count [IN]:unsigned long time_sec
+* @param sum [OUT]:NA
+* @return :success 0, failed -1
+* @todo:
+* @see:NA
+* @warning:
+******************************************/
+int lynq_set_poweralarm(unsigned long time_sec)
+{
+
+ int ret = 0;
+ int srcid = 0;
+ LYINFLOG("lynq_set_poweralarm %ld seconds",time_sec);
+ srcid = sc_rtc_timer_init();
+ if (srcid <= 0)
+ {
+ LYINFLOG("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)
+ {
+ LYINFLOG("Add rtc timer failed!!!!");
+ return -1;
+ }
+
+ LYINFLOG("Set poweralarm success !!!");
+
+ ret = sc_rtc_timer_uninit();
+ if(ret != 0)
+ {
+ LYINFLOG("Deinit failed");
+ }
+
+ return 0;
+
+}
+
+
+/*****************************************
+* @brief:lynq_set_wakealarm
+* @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 ret = 0;
+ LYINFLOG("lynq_set_wakealarm %ld 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(wk_srcid, wk_rtc_id, time_sec, sc_rtc_timer_add_cb);
+ if(ret < 0)
+ {
+ LYINFLOG("Add rtc timer failed!!!!");
+ return -1;
+ }
+
+ LYINFLOG("Set wakealarm success !!!");
+
+ ret = sc_rtc_timer_uninit();
+ if(ret != 0)
+ {
+ LYINFLOG("Deinit failed!!!");
+ }
+
+ return 0;
+
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+