l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 1 | /*******************************************************
|
| 2 | *
|
| 3 | * @brief: none
|
| 4 | * @details: Add wakealrm and poweralarm api code
|
| 5 | * @author: l.yang
|
| 6 | * @date: 2023.8.17
|
| 7 | * @version: V1.0
|
| 8 | * @copyright: Copyright (c) MobileTek
|
| 9 | *
|
| 10 | *********************************************/
|
| 11 |
|
| 12 | #include<stdio.h>
|
| 13 | #include<stdlib.h>
|
| 14 | #include<unistd.h>
|
| 15 | #include<stdbool.h>
|
| 16 | #include<log/log.h>
|
| 17 | #include "liblog/lynq_deflog.h"
|
| 18 | #include <include/libpoweralarm.h>
|
| 19 | #include <pthread.h>
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 20 | #include <string.h>
|
| 21 | #include <errno.h>
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 22 |
|
| 23 | #ifdef __cplusplus
|
| 24 | extern "C" {
|
| 25 | #endif
|
| 26 |
|
l.yang | c9fc6df | 2024-06-20 14:16:23 +0800 | [diff] [blame] | 27 | #include "sc_rtc_timer.h"
|
| 28 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 29 | #define USER_LOG_TAG "LYNQ_POWERALARM"
|
| 30 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 31 | #define MIN_TIME 1
|
| 32 | #define MAX_TIME 268435456
|
| 33 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 34 |
|
l.yang | c9fc6df | 2024-06-20 14:16:23 +0800 | [diff] [blame] | 35 | //typedef int (*sc_rtc_timer_exp_cb)(unsigned int src_id, int rtc_id);
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 36 | typedef int (*lynq_wakealarm_add_cb)(unsigned int src_id, int rtc_id);
|
| 37 |
|
l.yang | c9fc6df | 2024-06-20 14:16:23 +0800 | [diff] [blame] | 38 | /*
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 39 | extern int sc_rtc_timer_init(void);
|
| 40 | extern int sc_rtc_timer_uninit(void );
|
| 41 | extern int sc_rtc_timer_add(int srcid, int rtc_id, unsigned long ulSec, sc_rtc_timer_exp_cb rtc_notify);
|
| 42 | extern int sc_rtc_timer_del(int srcid, int rtc_id);
|
| 43 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 44 | extern int sc_rtc_timer_add_utc(int srcid, int rtc_id, struct tm *utc_sec, int wakeup, sc_rtc_timer_exp_cb rtc_notify);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 45 |
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 46 | extern int sc_rtc_get_poweroff_alarm_modid(int src_id,char *name);
|
| 47 |
|
| 48 | 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);
|
| 49 |
|
l.yang | c9fc6df | 2024-06-20 14:16:23 +0800 | [diff] [blame] | 50 | */
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 51 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 52 | /*****************************************
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 53 | * @brief:lynq_rtc_service_init
|
| 54 | * @param count [IN]:NA
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 55 | * @param sum [OUT]:NA
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 56 | * @return :success src_id, failed -1
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 57 | * @todo:
|
| 58 | * @see:NA
|
| 59 | * @warning:
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 60 | *****************************************/
|
| 61 | int lynq_rtc_service_init(void)
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 62 | {
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 63 | int src_id = -1;
|
| 64 |
|
| 65 | LYLOGSET(LOG_INFO);
|
| 66 | LYLOGEINIT(USER_LOG_TAG);
|
| 67 |
|
| 68 | src_id = sc_rtc_timer_init();
|
| 69 | if (src_id <= 0)
|
| 70 | {
|
| 71 | LYERRLOG("rtc_timer_init fail!");
|
| 72 | return -1;
|
| 73 | }
|
| 74 | return src_id;
|
| 75 |
|
| 76 | }
|
| 77 |
|
| 78 | /*****************************************
|
| 79 | * @brief:lynq_rtc_service_init
|
| 80 | * @param count [IN]:NA
|
| 81 | * @param sum [OUT]:NA
|
| 82 | * @return :success src_id, failed -1
|
| 83 | * @todo:
|
| 84 | * @see:NA
|
| 85 | * @warning:
|
| 86 | *****************************************/
|
| 87 | int lynq_rtc_service_deinit(void)
|
| 88 | {
|
| 89 | int ret = -1;
|
| 90 | ret = sc_rtc_timer_uninit();
|
| 91 | if(ret != 0)
|
| 92 | {
|
| 93 | LYINFLOG("Deinit failed!!!");
|
| 94 | return -1;
|
| 95 | }
|
| 96 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 97 | return 0;
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 98 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 99 | }
|
| 100 |
|
| 101 |
|
| 102 | /*****************************************
|
| 103 | * @brief:Set wakealarm time
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 104 | * @param count [IN]:char *buffer,int src_id ...
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 105 | * @param sum [OUT]:NA
|
| 106 | * @return :success 0, failed -1
|
| 107 | * @todo:
|
| 108 | * @see:NA
|
| 109 | * @warning:
|
| 110 | ******************************************/
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 111 | ssize_t wakealarm(char *buffer,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 112 | {
|
| 113 | unsigned long time_sec = 0;
|
| 114 | int ret = 0;
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 115 | char *buf_bak = buffer;
|
| 116 | time_t tmp_time = 0;
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 117 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 118 | struct tm *wake_arlarm = NULL;
|
| 119 | tmp_time = time(NULL);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 120 | localtime(&tmp_time);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 121 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 122 | if(buffer == NULL)
|
| 123 | {
|
| 124 | LYINFLOG("Bad input parameter,exit!!!!");
|
| 125 | return -1;
|
| 126 | }
|
| 127 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 128 | while(*buffer != '\0' )
|
| 129 | {
|
| 130 | if((*buffer < '0') || (*buffer > '9'))
|
| 131 | {
|
| 132 | LYERRLOG("Illeagel input buffer , there is invalid character!!!!");
|
| 133 | return -1;
|
| 134 | }
|
| 135 | else
|
| 136 | {
|
| 137 | buffer++;
|
| 138 | }
|
| 139 | }
|
| 140 |
|
| 141 |
|
| 142 | buffer = buf_bak;
|
| 143 | time_sec = strtoul(buffer,NULL,10);
|
| 144 | if(time_sec < MIN_TIME || time_sec > MAX_TIME || errno == ERANGE)
|
| 145 | {
|
| 146 | LYERRLOG("Illeagle input: too large or too small !!!");
|
| 147 | return -1;
|
| 148 | }
|
| 149 |
|
| 150 | tmp_time += time_sec;
|
| 151 | wake_arlarm = localtime(&tmp_time);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 152 |
|
l.yang | 4c4e738 | 2023-08-22 16:13:09 +0800 | [diff] [blame] | 153 | LYINFLOG("Set wakealarm %lu seconds ",time_sec);
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 154 |
|
| 155 | ret = sc_rtc_timer_add_utc(src_id, rtc_id,wake_arlarm,0,wakealarm_notify);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 156 | if(ret < 0)
|
| 157 | {
|
| 158 | LYINFLOG("Add rtc timer failed!!!!");
|
| 159 | return -1;
|
| 160 | }
|
| 161 |
|
| 162 | LYINFLOG("Set wakealarm success !!!");
|
| 163 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 164 | return 0;
|
| 165 |
|
| 166 | }
|
| 167 |
|
| 168 |
|
| 169 | /*****************************************
|
| 170 | * @brief:set poweralarm time
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 171 | * @param count [IN]:char *buffer, int srcid
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 172 | * @param sum [OUT]:NA
|
| 173 | * @return :success 0, failed -1
|
| 174 | * @todo:
|
| 175 | * @see:NA
|
| 176 | * @warning:
|
| 177 | ******************************************/
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 178 | ssize_t poweralarm(char *buffer,int src_id )
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 179 | {
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 180 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 181 | unsigned long time_sec = 0;
|
| 182 | int ret = 0;
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 183 | char *buf_bak = buffer;
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 184 |
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 185 | int alarmid = 0;
|
| 186 | char username[8] = "user";
|
| 187 | time_t tmp_time = 0;
|
| 188 | struct tm *power_arlarm = NULL;
|
| 189 | tmp_time = time(NULL);
|
| 190 | localtime(&tmp_time);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 191 | LYLOGSET(LOG_INFO);
|
| 192 | LYLOGEINIT(USER_LOG_TAG);
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 193 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 194 | if(buffer == NULL)
|
| 195 | {
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 196 | LYERRLOG("Bad input parameter,exit!!!!");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 197 | return -1;
|
| 198 | }
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 199 |
|
| 200 | while(*buffer != '\0' )
|
| 201 | {
|
| 202 | if(( *buffer < '0' )|| ( *buffer > '9'))
|
| 203 | {
|
| 204 | LYERRLOG("Illeagel input buffer , there is invalid character!!!!");
|
| 205 | return -1;
|
| 206 | }
|
| 207 | else
|
| 208 | {
|
| 209 | buffer++;
|
| 210 | }
|
| 211 | }
|
| 212 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 213 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 214 | buffer = buf_bak;
|
| 215 | time_sec = strtoul(buffer,NULL,10);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 216 |
|
| 217 | tmp_time += time_sec;
|
| 218 | power_arlarm = localtime(&tmp_time);
|
| 219 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 220 | if(time_sec < MIN_TIME || time_sec > MAX_TIME || errno == ERANGE)
|
| 221 | {
|
| 222 | LYERRLOG("Illeagle input: too large or too small !!!");
|
| 223 | return -1;
|
| 224 | }
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 225 |
|
l.yang | 4c4e738 | 2023-08-22 16:13:09 +0800 | [diff] [blame] | 226 | LYINFLOG("Set poweralarm %lu seconds",time_sec);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 227 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 228 |
|
| 229 | alarmid = sc_rtc_get_poweroff_alarm_modid(src_id, username);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 230 | if(alarmid < 0)
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 231 | {
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 232 | LYERRLOG("Get poweroff alarm id failed !!!");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 233 | return -1;
|
| 234 | }
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 235 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 236 | ret = sc_rtc_add_poweroff_alarm(src_id, alarmid, 0, power_arlarm, NULL);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 237 | if(ret < 0)
|
| 238 | {
|
| 239 | LYERRLOG("Set power alarm failed !!!");
|
| 240 | return -1;
|
| 241 | }
|
| 242 | LYINFLOG("Set power alarm success !!!!");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 243 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 244 | return 0;
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 245 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 246 | }
|
| 247 |
|
| 248 | /**********************************************
|
| 249 | * @brief:cancel_wakealarm,
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 250 | * @param count [IN]:int src_id, int rtc_id
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 251 | * @param sum [OUT]:NA
|
| 252 | * @return :success 0, failed -1
|
| 253 | * @todo:
|
| 254 | * @see:NA
|
| 255 | * @warning:
|
| 256 | ********************************************/
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 257 | ssize_t cancel_wakealarm(int src_id, int rtc_id)
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 258 | {
|
| 259 | int ret = 0;
|
| 260 |
|
| 261 | LYINFLOG("Enter cancel_wakealarm ");
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 262 | ret = sc_rtc_timer_del(src_id, rtc_id);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 263 | if(ret < 0)
|
| 264 | {
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 265 | LYERRLOG("Del wakealarm failed!!!");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 266 | return -1;
|
| 267 | }
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 268 | LYINFLOG("Cancel success ");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 269 | return 0;
|
| 270 |
|
| 271 | }
|
| 272 |
|
| 273 |
|
| 274 | /*****************************************
|
| 275 | * @brief:lynq_set_poweralarm
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 276 | * @param count [IN]:unsigned long time_sec , int src_id
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 277 | * @param sum [OUT]:NA
|
| 278 | * @return :success 0, failed -1
|
| 279 | * @todo:
|
| 280 | * @see:NA
|
| 281 | * @warning:
|
| 282 | ******************************************/
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 283 | int lynq_set_poweralarm(unsigned long time_sec,int src_id)
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 284 | {
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 285 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 286 | int ret = 0;
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 287 | int alarmid = 0;
|
| 288 | char username[8] = "user";
|
| 289 |
|
| 290 | time_t tmp_time = 0;
|
| 291 | struct tm *power_arlarm = NULL;
|
| 292 | tmp_time = time(NULL);
|
| 293 | localtime(&tmp_time);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 294 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 295 |
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 296 | tmp_time += time_sec;
|
| 297 | power_arlarm = localtime(&tmp_time);
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 298 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 299 | if(time_sec < MIN_TIME || time_sec > MAX_TIME )
|
| 300 | {
|
| 301 | LYERRLOG("Illeagle input: too large or too small !!!");
|
| 302 | return -1;
|
| 303 | }
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 304 |
|
| 305 | LYINFLOG("lynq_set_poweralarm %lu seconds",time_sec);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 306 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 307 |
|
| 308 | alarmid = sc_rtc_get_poweroff_alarm_modid(src_id, username);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 309 | if(alarmid < 0)
|
| 310 | {
|
| 311 | LYERRLOG("Get poweroff alarm id failed !!!");
|
| 312 | return -1;
|
| 313 | }
|
| 314 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 315 | ret = sc_rtc_add_poweroff_alarm(src_id, alarmid, 0, power_arlarm, NULL);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 316 | if(ret < 0)
|
| 317 | {
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 318 | LYERRLOG("Set power alarm failed !!!");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 319 | return -1;
|
| 320 | }
|
| 321 |
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 322 | LYINFLOG("Set power alarm success !!!!");
|
| 323 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 324 | return 0;
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 325 |
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 326 |
|
| 327 | }
|
| 328 |
|
| 329 |
|
| 330 | /*****************************************
|
| 331 | * @brief:lynq_set_wakealarm
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 332 | * @param count [IN]:unsigned long time_sec,....
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 333 | * @param sum [OUT]:NA
|
| 334 | * @return :success 0, failed -1
|
| 335 | * @todo:
|
| 336 | * @see:NA
|
| 337 | * @warning:
|
| 338 | ******************************************/
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 339 | int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 340 | {
|
| 341 | int ret = 0;
|
l.yang | 4c4e738 | 2023-08-22 16:13:09 +0800 | [diff] [blame] | 342 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 343 | time_t tmp_time = 0;
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 344 | struct tm *wake_arlarm = NULL;
|
| 345 | tmp_time = time(NULL);
|
l.yang | 989cbdb | 2023-09-18 11:29:39 +0800 | [diff] [blame] | 346 | localtime(&tmp_time);
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 347 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 348 | if(time_sec < MIN_TIME || time_sec > MAX_TIME)
|
| 349 | {
|
| 350 | LYERRLOG("Illeagle input: too large or too small !!!");
|
| 351 | return -1;
|
| 352 | }
|
| 353 |
|
l.yang | 4c4e738 | 2023-08-22 16:13:09 +0800 | [diff] [blame] | 354 | LYINFLOG("lynq_set_wakealarm %lu seconds ",time_sec);
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 355 |
|
l.yang | 168f8d2 | 2023-09-06 14:16:13 +0800 | [diff] [blame] | 356 | tmp_time += time_sec;
|
| 357 | wake_arlarm = localtime(&tmp_time);
|
| 358 | LYINFLOG("Set wakealarm %lu seconds ",time_sec);
|
| 359 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 360 | ret = sc_rtc_timer_add_utc(src_id, rtc_id,wake_arlarm,0,wakealarm_notify);
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 361 | if(ret < 0)
|
| 362 | {
|
| 363 | LYINFLOG("Add rtc timer failed!!!!");
|
| 364 | return -1;
|
| 365 | }
|
| 366 |
|
| 367 | LYINFLOG("Set wakealarm success !!!");
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 368 |
|
| 369 | return 0;
|
| 370 |
|
| 371 | }
|
| 372 |
|
l.yang | 3a9c661 | 2023-11-14 11:28:02 +0800 | [diff] [blame] | 373 |
|
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 374 | DEFINE_LYNQ_LIB_LOG(LYNQ_POWERALARM)
|
l.yang | b488ebc | 2023-08-21 17:58:00 +0800 | [diff] [blame] | 375 |
|
| 376 | #ifdef __cplusplus
|
| 377 | }
|
| 378 | #endif
|
| 379 |
|