blob: 461a04586283f2c06a785344e255d0fcbfdbac6c [file] [log] [blame]
b.liub21bd8d2023-12-28 19:07:21 +08001#include <math.h>
2#include <stdlib.h>
3
b.liu5fa9e772023-11-23 18:00:55 +08004#include "mbtk_alarm.h"
b.liu4e243dc2023-11-27 11:20:00 +08005#include "lynq_alarm.h"
b.liub21bd8d2023-12-28 19:07:21 +08006#include "mbtk_str.h"
b.liu5fa9e772023-11-23 18:00:55 +08007
luojian9b9a9282024-07-04 18:56:21 +08008
9bool rtc_flag = FALSE;
10int lynq_rtc_service_init(void)
11{
12 int ret = 0;
13 if(!rtc_flag)
14 {
15 rtc_flag = TRUE;
16 ret = 1;
17 }
18 else
19 {
20 ret = -1;
21 }
22 return ret;
23}
24
25int lynq_rtc_service_deinit(void)
26{
27 int ret = 0;
28 if(rtc_flag)
29 {
30 rtc_flag = FALSE;
31 ret = 0;
32 }
33 else{
34 ret = -1;
35 }
36
37 return ret;
38}
39
40int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
b.liu5fa9e772023-11-23 18:00:55 +080041{
42 UNUSED(time_sec);
b.liub21bd8d2023-12-28 19:07:21 +080043 if(time_sec < 1 || time_sec > pow(2, 28)) {
44 return -1;
45 }
b.liu5fa9e772023-11-23 18:00:55 +080046
luojian9b9a9282024-07-04 18:56:21 +080047 return -1;
b.liu5fa9e772023-11-23 18:00:55 +080048}
49
luojian9b9a9282024-07-04 18:56:21 +080050//int lynq_set_poweralarm(unsigned long time_sec)
51int lynq_set_poweralarm(unsigned long time_sec,int src_id)
b.liu5fa9e772023-11-23 18:00:55 +080052{
53 UNUSED(time_sec);
b.liub21bd8d2023-12-28 19:07:21 +080054 if(time_sec < 1 || time_sec > pow(2, 28)) {
55 return -1;
56 }
luojian9b9a9282024-07-04 18:56:21 +080057 char buf[50] ={0};
58 sprintf(buf, "rtcwake -d rtc0 -s %d -m on &", time_sec);
59 system(buf);
b.liu5fa9e772023-11-23 18:00:55 +080060
61 return 0;
62}
63
b.liub21bd8d2023-12-28 19:07:21 +080064// min:1 max:2^28
luojian9b9a9282024-07-04 18:56:21 +080065ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
b.liu5fa9e772023-11-23 18:00:55 +080066{
67 UNUSED(buffer);
b.liub21bd8d2023-12-28 19:07:21 +080068 if(str_empty(buffer)) {
69 return -1;
70 }
luojian9b9a9282024-07-04 18:56:21 +080071 return lynq_set_wakealarm(atol(buffer), src_id, rtc_id, wakealarm_notify);
b.liu5fa9e772023-11-23 18:00:55 +080072}
73
b.liub21bd8d2023-12-28 19:07:21 +080074// min:1 max:2^28
luojian9b9a9282024-07-04 18:56:21 +080075ssize_t poweralarm(char *buffer,int src_id)
b.liu5fa9e772023-11-23 18:00:55 +080076{
77 UNUSED(buffer);
b.liub21bd8d2023-12-28 19:07:21 +080078 if(str_empty(buffer)) {
79 return -1;
80 }
luojian9b9a9282024-07-04 18:56:21 +080081 return lynq_set_poweralarm(atol(buffer), 0);
b.liu5fa9e772023-11-23 18:00:55 +080082}
83
luojian9b9a9282024-07-04 18:56:21 +080084ssize_t cancel_wakealarm(int src_id, int rtc_id)
b.liu5fa9e772023-11-23 18:00:55 +080085{
luojian9b9a9282024-07-04 18:56:21 +080086 return -1;
87}
88