哪位大神帮看看V3S RTC这程序是否正确?为保时钟差这么大?(32768-32000)/32768->2.34%
/*
* This RTC count flow on sun8iw8 platform.
* 32.768KHz--- --- [32768 count] ---
* \/ \___[seconds reg]
* /\ /
* 32KHz --- --- [32000 count] ---
*
* We can calculate how much seconds missing, call sunxi_rtc_fixup.
*/
void sunxi_rtc_fixup(unsigned long long*org_time, unsigned long long *time)
{
unsigned long long delta;
unsigned long long t1, t2;
bool out;
if (!time)
return;
if (!org_time)
{
t1 = (unsigned long long)(V3S_RTC->GP_DATA[6]&(~0x80000000)) << 32; /*readl( base + SUNXI_GPDATA_REG(6))*/
t1 |= (unsigned long)V3S_RTC->GP_DATA[7]; /*readl( base + SUNXI_GPDATA_REG(7))*/
}
else
{
t1 = *org_time;
}
t2 = *time;
out = V3S_RTC->LOSC_CTRL & SUN6I_LOSC_CTRL_EXT_OSC; //if used external 32768Hz oscillator
delta = (t2 > t1) ? (t2 - t1) : (t1 - t2);
delta = (delta * (OSC_ORG - OSC_32K)) / OSC_ORG;
if (out)
*time -= delta;
else
*time += delta;
}
离线