b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | #include <stdlib.h> |
| 3 | |
| 4 | #include "mbtk_alarm.h" |
| 5 | #include "lynq_alarm.h" |
| 6 | #include "mbtk_str.h" |
| 7 | #include "lynq-qser-autosuspend.h" |
| 8 | #include "mbtk_utils.h" |
| 9 | |
| 10 | |
| 11 | |
| 12 | bool rtc_flag = FALSE; |
| 13 | int lynq_rtc_service_init(void) |
| 14 | { |
| 15 | int ret = 0; |
| 16 | if(!rtc_flag) |
| 17 | { |
| 18 | rtc_flag = TRUE; |
| 19 | ret = 1; |
| 20 | } |
| 21 | else |
| 22 | { |
| 23 | ret = -1; |
| 24 | } |
| 25 | return ret; |
| 26 | } |
| 27 | |
| 28 | int lynq_rtc_service_deinit(void) |
| 29 | { |
| 30 | int ret = 0; |
| 31 | if(rtc_flag) |
| 32 | { |
| 33 | rtc_flag = FALSE; |
| 34 | ret = 0; |
| 35 | } |
| 36 | else{ |
| 37 | ret = -1; |
| 38 | } |
| 39 | |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | void mbtk_info_callback_func1(const void* data, int data_len) |
| 44 | { |
| 45 | mbtk_system("echo 456 > /data/test1.txt"); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify ) |
| 51 | { |
| 52 | UNUSED(time_sec); |
| 53 | if(time_sec < 1 || time_sec > pow(2, 28)) { |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | if(!rtc_flag) |
| 58 | { |
| 59 | return -1; |
| 60 | } |
| 61 | |
| 62 | qser_suspend_timer_set(time_sec, mbtk_info_callback_func1); |
| 63 | |
| 64 | return 0; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | //int lynq_set_poweralarm(unsigned long time_sec) |
| 69 | int lynq_set_poweralarm(unsigned long time_sec,int src_id) |
| 70 | { |
| 71 | UNUSED(time_sec); |
| 72 | if(time_sec < 1 || time_sec > pow(2, 28)) { |
| 73 | return -1; |
| 74 | } |
| 75 | char buf[50] ={0}; |
| 76 | sprintf(buf, "rtcwake -d rtc0 -s %ld -m on &", time_sec); |
| 77 | mbtk_system(buf); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | // min:1 max:2^28 |
| 83 | ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify ) |
| 84 | { |
| 85 | UNUSED(buffer); |
| 86 | if(str_empty(buffer)) { |
| 87 | return -1; |
| 88 | } |
| 89 | return lynq_set_wakealarm(atol(buffer), src_id, rtc_id, wakealarm_notify); |
| 90 | } |
| 91 | |
| 92 | // min:1 max:2^28 |
| 93 | ssize_t poweralarm(char *buffer,int src_id) |
| 94 | { |
| 95 | UNUSED(buffer); |
| 96 | if(str_empty(buffer)) { |
| 97 | return -1; |
| 98 | } |
| 99 | return lynq_set_poweralarm(atol(buffer), 0); |
| 100 | } |
| 101 | |
| 102 | ssize_t cancel_wakealarm(int src_id, int rtc_id) |
| 103 | { |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | |