jl701n_soundbox_release_v1.3.0 复位后重置RTC问题解决办法
📎 原始文档:https://www.kdocs.cn/l/cjeUU3zIk9ge jl701n_soundbox_release_v1.3.0 复位后重置RTC问题解决办法
使用该方法有一个弊端,在反复开关机时会丢节拍,会少1-2s,频繁开关机后,累积起来的丢失的时间就会更多。
①改写set_rtc_default_time接口函数
u8 set_rtc_default_time(struct sys_time *t)
{
#if (defined(CONFIG_CPU_BR28))
extern bool read_p11_sys_time(struct sys_time * t);
if (read_p11_sys_time(t)) {
g_printf("rtc_read_sys_time: %d-%d-%d %d:%d:%d\n",
t->year, t->month, t->day, t->hour, t->min, t->sec);
return 1;
}
#else
t->year = 2019;
t->month = 5;
t->day = 5;
t->hour = 18;
t->min = 18;
t->sec = 18;
#endif
return 0;
}
②增加代码
struct p11_sys_time {
u32 mask;
struct sys_time ram_time;
};
static struct p11_sys_time *p11_rtc_time = 0;

#if (defined(CONFIG_CPU_BR28))
static int write_p11_sys_time(int param)
{
struct sys_time cur_time;
if (p11_rtc_time) {
get_sys_time(&cur_time);
memcpy(&p11_rtc_time->ram_time, &cur_time, sizeof(struct sys_time));
p11_rtc_time->mask = 0x12345678;
}
printf("write_p11_sys_time \n");
return 0;
}
static void write_p11_sys_time_by_timer(void *priv)
{
int argv[3];
argv[0] = (int)write_p11_sys_time;
argv[1] = 1;
os_taskq_post_type("app_core", Q_CALLBACK, 3, argv);
}
bool read_p11_sys_time(struct sys_time *t)
{
if (p11_rtc_time && (p11_rtc_time->mask == 0x12345678)) {
memcpy(t, &p11_rtc_time->ram_time, sizeof(struct sys_time));
return true;
}
return false;
}
void p11_sys_time_init()
{
ASSERT(P11_HEAP_SIZE >= sizeof(struct sys_time));
//在p11开辟一片空间暂存时间变量
p11_rtc_time = (struct p11_sys_time *)(P11_HEAP_BEGIN + P11_HEAP_SIZE - sizeof(struct p11_sys_time));
sys_s_hi_timer_add(NULL, write_p11_sys_time_by_timer, 2000);
}
#endif
③增加定时写入RAM中的定时器初始化
#if TCFG_RTC_ENABLE
extern void p11_sys_time_init();
p11_sys_time_init();
#endif