81 lines
3.3 KiB
C
81 lines
3.3 KiB
C
#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);
|
|
}
|