b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | #include <stdlib.h> |
| 3 | |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 4 | #include "mbtk_alarm.h" |
b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 5 | #include "lynq_alarm.h" |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 6 | #include "mbtk_str.h" |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 7 | |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 8 | |
| 9 | bool rtc_flag = FALSE; |
| 10 | int 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 | |
| 25 | int 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 | |
| 40 | int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify ) |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 41 | { |
| 42 | UNUSED(time_sec); |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 43 | if(time_sec < 1 || time_sec > pow(2, 28)) { |
| 44 | return -1; |
| 45 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 46 | |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 47 | return -1; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 48 | } |
| 49 | |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 50 | //int lynq_set_poweralarm(unsigned long time_sec) |
| 51 | int lynq_set_poweralarm(unsigned long time_sec,int src_id) |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 52 | { |
| 53 | UNUSED(time_sec); |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 54 | if(time_sec < 1 || time_sec > pow(2, 28)) { |
| 55 | return -1; |
| 56 | } |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 57 | char buf[50] ={0}; |
| 58 | sprintf(buf, "rtcwake -d rtc0 -s %d -m on &", time_sec); |
| 59 | system(buf); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 64 | // min:1 max:2^28 |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 65 | ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify ) |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 66 | { |
| 67 | UNUSED(buffer); |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 68 | if(str_empty(buffer)) { |
| 69 | return -1; |
| 70 | } |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 71 | return lynq_set_wakealarm(atol(buffer), src_id, rtc_id, wakealarm_notify); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 72 | } |
| 73 | |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 74 | // min:1 max:2^28 |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 75 | ssize_t poweralarm(char *buffer,int src_id) |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 76 | { |
| 77 | UNUSED(buffer); |
b.liu | b21bd8d | 2023-12-28 19:07:21 +0800 | [diff] [blame] | 78 | if(str_empty(buffer)) { |
| 79 | return -1; |
| 80 | } |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 81 | return lynq_set_poweralarm(atol(buffer), 0); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 82 | } |
| 83 | |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 84 | ssize_t cancel_wakealarm(int src_id, int rtc_id) |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 85 | { |
luojian | 9b9a928 | 2024-07-04 18:56:21 +0800 | [diff] [blame] | 86 | return -1; |
| 87 | } |
| 88 | |