diag: trace RTC synchronization and WSS clock state
This commit is contained in:
@@ -12,6 +12,7 @@ MAKEFILE_PATH :=$(subst $(strip \),/,$(abspath $(lastword $(MAKEFILE_LIST))))
|
||||
SRC_FILES+= \
|
||||
quec_kernel_shim_api.c \
|
||||
ql_user_api_map.c \
|
||||
talkingq_time_diag.c \
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
@@ -30,6 +30,7 @@ WHEN WHO WHAT, WHERE, WHY
|
||||
#include "ql_keypad.h"
|
||||
#include "ql_rtc.h"
|
||||
#include "ql_time.h"
|
||||
#include "../../../ql-config/config/talkingq_time_diag.h"
|
||||
#include "ql_power.h"
|
||||
#include "ql_nw.h"
|
||||
#include "ql_platform.h"
|
||||
@@ -103,6 +104,7 @@ ql_open_api_list vUserAPITable[] __attribute__((used, section("DDR_USER_API_TABL
|
||||
{
|
||||
{0x60BCEA5A, (void*)ql_user_api_map_test},
|
||||
{0xFFFFFFFF, (void*)quec_kernel_api_test},
|
||||
{TALKINGQ_TIME_DIAG_API_HASH, (void *)talkingq_time_diag_snapshot_v1},
|
||||
|
||||
#ifdef QL_MBEDTLS
|
||||
/************************************************************************************************
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "ql_type.h"
|
||||
#include "quec_cust_feature.h"
|
||||
#include "pmic.h"
|
||||
#include "pmic_rtc.h"
|
||||
#include "quec_rtc.h"
|
||||
#include "ql_rtos.h"
|
||||
#include "../../../ql-config/config/talkingq_time_diag.h"
|
||||
|
||||
/* SDK globals are linked by name, never by firmware-specific RAM addresses. */
|
||||
extern unsigned char m_rtc_app_sys_keeping_synced;
|
||||
extern PMIC_RTC_OFFSET_STORAGE m_pmic_rtc_offset_storage_type;
|
||||
#ifdef NTP
|
||||
extern int get_ntp_time_type(void);
|
||||
extern int GetNTPStatus(void);
|
||||
extern int talkingq_ntp_diag_ready(void);
|
||||
#endif
|
||||
#ifdef QUEC_GNSS_NTP
|
||||
extern int quec_get_rtc_status(void);
|
||||
extern int quec_get_nw_status(void);
|
||||
extern char *get_ntp_server_ip(void);
|
||||
extern char ntp_sync_cnt;
|
||||
extern char ntp_dns_gain;
|
||||
#endif
|
||||
|
||||
int talkingq_time_diag_snapshot_v1(talkingq_time_diag_snapshot *out, unsigned int size)
|
||||
{
|
||||
if (out == NULL || size != sizeof(*out)) return -1;
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->abi_version = TALKINGQ_TIME_DIAG_ABI_VERSION;
|
||||
out->sample_ticks = ql_rtos_get_systicks();
|
||||
out->ntp_type = out->ntp_status = out->ntp_ready = -1;
|
||||
out->gnss_rtc_status = out->gnss_cid = -1;
|
||||
out->ntp_triggers = out->ntp_dns_attempted = -1;
|
||||
out->rtc_initialized = pmic_rtc_INIT_FLAG_GET() ? 1U : 0U;
|
||||
if (!out->rtc_initialized) return 0;
|
||||
|
||||
/* Read raw RTC storage, not PMIC_RTC_GetTime_Count(): that getter can
|
||||
* enable APP-follow-SYS and would disturb the boot state under diagnosis. */
|
||||
out->app_follows_sys = m_rtc_app_sys_keeping_synced;
|
||||
out->app_ever_configured = pmic_userdata_get_app_rtc_ever_configed() ? 1U : 0U;
|
||||
out->offset_storage = (int)m_pmic_rtc_offset_storage_type;
|
||||
out->sys_offset = PM812_RTC_GET_32B_SYS_OFFSET();
|
||||
out->app_offset = PM812_RTC_GET_32B_APP_OFFSET();
|
||||
out->counter = PM812_RTC_GET_32B_COUNTER();
|
||||
out->network_tz_minutes = GetTimeZone();
|
||||
out->rtc_tz_hours = PMIC_RTC_GetTimezone();
|
||||
out->rtc_source = (int)quec_get_rtc_source();
|
||||
#ifdef NTP
|
||||
out->ntp_type = get_ntp_time_type();
|
||||
out->ntp_status = GetNTPStatus();
|
||||
out->ntp_ready = talkingq_ntp_diag_ready();
|
||||
#endif
|
||||
#ifdef QUEC_GNSS_NTP
|
||||
out->gnss_rtc_status = quec_get_rtc_status();
|
||||
out->gnss_cid = quec_get_nw_status();
|
||||
out->ntp_triggers = (unsigned char)ntp_sync_cnt;
|
||||
out->ntp_dns_attempted = (unsigned char)ntp_dns_gain;
|
||||
snprintf(out->ntp_server, sizeof(out->ntp_server), "%.31s", get_ntp_server_ip());
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void talkingq_time_diag_trace(const char *phase)
|
||||
{
|
||||
talkingq_time_diag_snapshot s;
|
||||
if (talkingq_time_diag_snapshot_v1(&s, sizeof(s)) != 0) return;
|
||||
printf("[TIME-DIAG] kernel phase=%s build=%s %s rtc_init=%u "
|
||||
"counter=%lu sys_offset=%lu app_offset=%lu follows_sys=%u app_ever=%u "
|
||||
"storage=%d\r\n",
|
||||
phase, __DATE__, __TIME__, s.rtc_initialized,
|
||||
(unsigned long)s.counter, (unsigned long)s.sys_offset,
|
||||
(unsigned long)s.app_offset, s.app_follows_sys, s.app_ever_configured,
|
||||
s.offset_storage);
|
||||
printf("[TIME-DIAG] kernel phase=%s ticks=%u net_tz_min=%d rtc_tz_hour=%d source=%d "
|
||||
"ntp_type=%d ntp_status=%d ntp_ready=%d gnss_rtc=%d triggers=%d\r\n",
|
||||
phase, s.sample_ticks, s.network_tz_minutes, s.rtc_tz_hours, s.rtc_source,
|
||||
s.ntp_type, s.ntp_status, s.ntp_ready, s.gnss_rtc_status, s.ntp_triggers);
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "quec_sockets.h"
|
||||
#include "gps_app.h"
|
||||
#include "quec_mfpr_api.h"
|
||||
#include "../../../ql-config/config/talkingq_time_diag.h"
|
||||
|
||||
#define GPS_VIA_UART
|
||||
|
||||
@@ -415,6 +416,8 @@ void quec_gps_nw_status_monitor(void * argv)
|
||||
{
|
||||
int cid_num = 0;
|
||||
struct sockaddr sockaddr = {0};
|
||||
int last_type = -1, last_status = -1, last_rtc = -1;
|
||||
int current_type, current_status, dns_ret;
|
||||
while(1)
|
||||
{
|
||||
cid_num = quec_gps_get_cid_act();
|
||||
@@ -429,13 +432,18 @@ void quec_gps_nw_status_monitor(void * argv)
|
||||
memcpy(&gps_nw_ctx_ptr.gps_ip4_addr, &(((struct sockaddr_in *)&sockaddr)->sin_addr), sizeof(struct in_addr));
|
||||
quec_rtos_task_sleep_s(2);
|
||||
if(!ntp_dns_gain){
|
||||
quec_gps_ntp_set_server(quec_gps_cfg->ntp_url);
|
||||
dns_ret = quec_gps_ntp_set_server(quec_gps_cfg->ntp_url);
|
||||
printf("[TIME-DIAG] gnss_ntp_dns cid=%d server=%.31s rc=%d ip=%.31s\r\n",
|
||||
cid_num, quec_gps_cfg->ntp_url, dns_ret, get_ntp_server_ip());
|
||||
ntp_dns_gain++;
|
||||
}
|
||||
/*限制成功激活pdp后ntp的同步次数*/
|
||||
if((gps_nw_ctx_ptr.rtc_status !=1)&&(ntp_sync_cnt < 10))
|
||||
{
|
||||
get_ntp_time_internal();
|
||||
printf("[TIME-DIAG] gnss_ntp_trigger cid=%d attempt=%u ntp_type=%d ntp_status=%d\r\n",
|
||||
cid_num, (unsigned int)(unsigned char)ntp_sync_cnt + 1U,
|
||||
get_ntp_time_type(), GetNTPStatus());
|
||||
get_ntp_time_internal();
|
||||
ntp_sync_cnt++;
|
||||
GPS_LOGD("Ntp sync cnt:%d!!!",ntp_sync_cnt);
|
||||
}
|
||||
@@ -453,6 +461,15 @@ void quec_gps_nw_status_monitor(void * argv)
|
||||
{
|
||||
gps_nw_ctx_ptr.rtc_status = 1;
|
||||
}
|
||||
current_type = get_ntp_time_type();
|
||||
current_status = GetNTPStatus();
|
||||
if (current_type != last_type || current_status != last_status ||
|
||||
gps_nw_ctx_ptr.rtc_status != last_rtc) {
|
||||
talkingq_time_diag_trace("gnss-time-state");
|
||||
last_type = current_type;
|
||||
last_status = current_status;
|
||||
last_rtc = gps_nw_ctx_ptr.rtc_status;
|
||||
}
|
||||
//RTI_LOG("Found an active pdp %d:%d:%d:%d:%d:%d!!!",tm.tm_year,tm.tm_mon,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);
|
||||
}
|
||||
}
|
||||
@@ -472,6 +489,7 @@ int quec_get_nw_status(void)
|
||||
int gps_nw_active(void)
|
||||
{
|
||||
int cid_num = 0;
|
||||
int dns_ret;
|
||||
cid_num = quec_gps_get_cid_act();
|
||||
struct sockaddr sockaddr = {0};
|
||||
if(cid_num>0)
|
||||
@@ -483,7 +501,9 @@ int gps_nw_active(void)
|
||||
quec_soc_get_ipv4v6_local_addr(cid_num, AF_INET, &sockaddr);
|
||||
memcpy(&gps_nw_ctx_ptr.gps_ip4_addr, &(((struct sockaddr_in *)&sockaddr)->sin_addr), sizeof(struct in_addr));
|
||||
if(!ntp_dns_gain){
|
||||
quec_gps_ntp_set_server(quec_gps_cfg->ntp_url);
|
||||
dns_ret = quec_gps_ntp_set_server(quec_gps_cfg->ntp_url);
|
||||
printf("[TIME-DIAG] gnss_ntp_dns cid=%d server=%.31s rc=%d ip=%.31s\r\n",
|
||||
cid_num, quec_gps_cfg->ntp_url, dns_ret, get_ntp_server_ip());
|
||||
ntp_dns_gain++;
|
||||
}
|
||||
GPS_LOGI("Found an active pdp!!!");
|
||||
|
||||
@@ -77,6 +77,7 @@ static const char rcsid[] = "$OpenBSD: rdate.c,v 1.22 2004/02/18 20:10:53 jmc Ex
|
||||
#endif
|
||||
#include "utltime.h"
|
||||
#include "quec_cust_feature.h"
|
||||
#include "../../../ql-config/config/talkingq_time_diag.h"
|
||||
/* there are systems without libutil; for portability */
|
||||
#ifdef HAVE_UTIL_H
|
||||
#include <util.h>
|
||||
@@ -204,6 +205,11 @@ int GetNTPStatus(void)
|
||||
return NTP_SYNC_SUCCESS;
|
||||
}
|
||||
|
||||
int talkingq_ntp_diag_ready(void)
|
||||
{
|
||||
return NtpFlagRef != NULL && NTPTaskRef != NULL;
|
||||
}
|
||||
|
||||
static unsigned int ntp_retry_timer[] = {
|
||||
(1 * 1000 / 5), /*2 sec*/
|
||||
(10 * 1000 / 5), /*10 sec*/
|
||||
@@ -278,11 +284,14 @@ extern char *get_ntp_server_ip(void);
|
||||
while(try_times > 0 && count < 8)
|
||||
{
|
||||
--try_times;
|
||||
printf("[TIME-DIAG] ntp_request attempt=%d server=%.31s\r\n",
|
||||
3 - try_times, strlen(hname) > 0 ? hname : hname_default);
|
||||
if(strlen(hname) > 0)
|
||||
ret = ntp_client(hname, family, &new, &adjust, corrleaps);
|
||||
else
|
||||
ret = ntp_client(hname_default, family, &new, &adjust, corrleaps);
|
||||
|
||||
printf("[TIME-DIAG] ntp_result attempt=%d rc=%d\r\n", 3 - try_times, ret);
|
||||
if(ret != 0)
|
||||
{
|
||||
continue;
|
||||
@@ -297,6 +306,7 @@ extern char *get_ntp_server_ip(void);
|
||||
if (new.tv_sec > 60 * 60 * 24 * 365)
|
||||
{
|
||||
SaveNTPParameters(ltm);
|
||||
printf("[TIME-DIAG] ntp_rtc_written epoch=%ld\r\n", (long)tim);
|
||||
break;
|
||||
}
|
||||
OSATaskSleep(200);
|
||||
@@ -311,6 +321,7 @@ extern char *get_ntp_server_ip(void);
|
||||
|
||||
SetNTPStatus(2);//failed
|
||||
}
|
||||
talkingq_time_diag_trace("ntp-finished");
|
||||
|
||||
}
|
||||
|
||||
@@ -325,12 +336,14 @@ void NTP_Init_Internal(void)
|
||||
str = psm_get_wrapper("Debug", NULL, "debug_ntp_disable");
|
||||
if (str && strcmp(str, "1") == 0)
|
||||
{
|
||||
printf("[TIME-DIAG] ntp_init skipped debug_ntp_disable=1\r\n");
|
||||
free(str);
|
||||
return;
|
||||
}
|
||||
if (str)
|
||||
free(str);
|
||||
|
||||
printf("[TIME-DIAG] ntp_init debug_ntp_disable=0\r\n");
|
||||
/* Ntp Flag initialize. */
|
||||
status = OSAFlagCreate(&NtpFlagRef);
|
||||
ASSERT(status == OS_SUCCESS);
|
||||
|
||||
Reference in New Issue
Block a user