[Feature][T106][RTC] Add a new retry 20 times,if set rtc fail.
Only Configure :No
Affected branch:master
Affected module:rtc
Is it affected on both ZXIC and MTK:only ZXIC
Self-test: Yes
Doc Update: No
Change-Id: I18e3c2e82722db14eb5d29e70002f828b436476e
diff --git a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
index 8c91c57..975c942 100755
--- a/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
+++ b/cap/zx297520v3/src/lynq/lib/libpoweralarm/libpoweralarm.cpp
@@ -114,11 +114,13 @@
unsigned long time_sec = 0;
int ret = 0;
char *buf_bak = buffer;
- time_t tmp_time = 0;
-
+
struct tm *wake_arlarm = NULL;
- tmp_time = time(NULL);
- localtime(&tmp_time);
+ struct tm wake_arlarm_tm;
+ char time_str[80] = {0};
+ int retry_count = 0;
+ const int MAX_RETRIES = 20;
+ memset(&wake_arlarm_tm, 0, sizeof(wake_arlarm_tm));
if(buffer == NULL)
{
@@ -139,7 +141,6 @@
}
}
-
buffer = buf_bak;
time_sec = strtoul(buffer,NULL,10);
if(time_sec < MIN_TIME || time_sec > MAX_TIME || errno == ERANGE)
@@ -148,22 +149,32 @@
return -1;
}
- tmp_time += time_sec;
- wake_arlarm = localtime(&tmp_time);
-
- LYINFLOG("Set wakealarm %lu seconds ",time_sec);
-
- ret = sc_rtc_timer_add_utc(src_id, rtc_id,wake_arlarm,0,wakealarm_notify);
- if(ret < 0)
+ while (retry_count < MAX_RETRIES)
{
- LYINFLOG("Add rtc timer failed!!!!");
- return -1;
+
+ time_t tmp_time = 0;
+ tmp_time = time(NULL);
+ tmp_time += time_sec;
+ wake_arlarm = localtime_r(&tmp_time,&wake_arlarm_tm);
+
+ strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", wake_arlarm);
+
+ ret = sc_rtc_timer_add_utc(src_id, rtc_id, wake_arlarm, 0, wakealarm_notify);
+ if (ret >= 0)
+ {
+ LYINFLOG("wakealarm set Wake alarm time success: %s\n", time_str);
+ LYINFLOG("Add rtc timer succeeded after %d attempts.", retry_count);
+ return 0;
+ }
+ retry_count++;
+ LYINFLOG("wakealarm set Wake alarm time: %s\n", time_str);
+ LYINFLOG("Add rtc timer failed. Retrying (%d/%d)...", retry_count, MAX_RETRIES);
+ usleep(10000);
+
}
- LYINFLOG("Set wakealarm success !!!");
-
- return 0;
-
+ LYINFLOG("Add rtc timer failed after %d attempts!!!!", MAX_RETRIES);
+ return -1;
}
@@ -340,11 +351,13 @@
int lynq_set_wakealarm(unsigned long time_sec,int src_id,int rtc_id,lynq_wakealarm_add_cb wakealarm_notify )
{
int ret = 0;
-
- time_t tmp_time = 0;
struct tm *wake_arlarm = NULL;
- tmp_time = time(NULL);
- localtime(&tmp_time);
+ char time_str[80] = {0};
+ int retry_count = 0;
+ const int MAX_RETRIES = 20;
+
+ struct tm wake_arlarm_tm;
+ memset(&wake_arlarm_tm, 0, sizeof(wake_arlarm_tm));
if(time_sec < MIN_TIME || time_sec > MAX_TIME)
{
@@ -352,23 +365,29 @@
return -1;
}
- LYINFLOG("lynq_set_wakealarm %lu seconds ",time_sec);
-
- tmp_time += time_sec;
- wake_arlarm = localtime(&tmp_time);
- LYINFLOG("Set wakealarm %lu seconds ",time_sec);
-
- ret = sc_rtc_timer_add_utc(src_id, rtc_id,wake_arlarm,0,wakealarm_notify);
- if(ret < 0)
+ while (retry_count < MAX_RETRIES)
{
- LYINFLOG("Add rtc timer failed!!!!");
- return -1;
- }
-
- LYINFLOG("Set wakealarm success !!!");
-
- return 0;
+ time_t tmp_time = 0;
+ tmp_time = time(NULL);
+ tmp_time += time_sec;
+ wake_arlarm = localtime_r(&tmp_time,&wake_arlarm_tm);
+ strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", wake_arlarm);
+
+ ret = sc_rtc_timer_add_utc(src_id, rtc_id, wake_arlarm, 0, wakealarm_notify);
+ if (ret >= 0)
+ {
+ LYINFLOG("Wake alarm time success: %s\n", time_str);
+ LYINFLOG("Add rtc timer succeeded after %d attempts.", retry_count);
+ return 0;
+ }
+ retry_count++;
+ LYINFLOG("Wake alarm time: %s\n", time_str);
+ LYINFLOG("Add rtc timer failed. Retrying (%d/%d)...", retry_count, MAX_RETRIES);
+ usleep(10000);
+ }
+ LYINFLOG("Add rtc timer failed after %d attempts!!!!", MAX_RETRIES);
+ return -1;
}