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