RTC相关应用
📎 原始文档:https://www.kdocs.cn/l/chKEmHayQacC RTC相关应用
一、RTC应用
- 相关配置
相关结构体说明:
#if TCFG_RTC_ENABLE
const struct rtc_dev_data rtc_data = {
.port = (u8)-1,
.edge = 0, //0 leading edge, 1 falling edge
.port_en = false,
.rtc_ldo = false,//使用内部ldo 供电 :如果RTCVDD外部没有供电需要把改位置1
.clk_res = RTC_CLK_RES_SEL, //rtc时钟源选择:CLK_SEL_32K/CLK_SEL_12M/CLK_SEL_24M
};
#endif
如果需要设置闹钟功能需要把假时钟打开
2. 对应的事件处理 
二、案例分析
- 虚拟RTC软关机跑时(LZK)
说明
虚拟RTC实际上是使用定时器进行模拟RTC功能去实现跑时。由于定时器的特性会存在计时溢出的可能,所以在实际应用中软关机后会存在定时唤醒校准的机制才能保证计时正常不会溢出。
- 所以对于软关机的方案需要针对这种情况做出特殊处理保证不会因为校准唤醒尔开机(下面会提供一个API函数可以针对这种情况进行判断)
API函数
/*******************************
区分是定时唤醒还是闹钟唤醒:
0 代表是其他唤醒 包括vir_rtc_trim_time的唤醒
1 为闹钟唤醒
!!!!需要在power_init之后获取
*******************************/
u8 get_vir_alm_wakeup_flag()
AC696N_soundbox_sdk_release_1.5.0 【金山文档】 696N添加虚拟RTC软关机跑时
https://kdocs.cn/l/coosx4ym3uUwAC696N_soundbox_sdk_release_1.7.0 696N添加虚拟RTC软关机跑时——1.7.0.zip
AC695N_soundbox_sdk_release_3.1.0 修改内容:
【金山文档】 AC695X添加虚拟RTC软关机跑时_3.1.0SDK
https://kdocs.cn/l/cohyBZqgNz80
demo
ac695n_soundbox_sdk(feature_虚拟RTC软关机跑时_3.1.0_2b7e30b8).7z
- 手机同步时间
- 安卓手机同步时间补丁 【金山文档】 安卓手机同步时间补丁
安卓手机同步时间补丁.otl - AC695 iphone 手机同步手机时间接口
///获取手机的日期和时间, 苹果可以;
///安卓需要打上安卓手机同步时间补丁;
///建议此函数放在bt_function_select_init函数所在的同一个C文件里
void __attribute__((weak)) phone_date_and_time_feedback(u8 *data, u16 len)
{
put_buf(data, len);
puts(data);
}
注意: 连接好手机后, 半秒或者一秒后调用如下语句, 就可以从上面的函数打印看到时间!
user_send_cmd_prepare(USER_CTRL_HFP_GET_PHONE_DATE_TIME, 0, NULL);
FAQ
- AC695N_soundbox_sdk_release_3.1.0
- 外挂32K时钟,软关机时钟不走 检查程序上rtc_clk变量有没有置1。如下:
- AC695N_soundbox_sdk_release_3.0.6 软关机后,时钟不走
// SDK\apps\soundbox\task_manager\rtc\alarm_api.c
int dat;
dat = p33_rx_1byte(R3_OSL_CON);
dat |= BIT(0);
dat |= BIT(1);
p33_tx_1byte(R3_OSL_CON,dat);
dat = p33_rx_1byte(R3_OSL_CON);
dat |= BIT(0);
dat |= BIT(1);
p33_tx_1byte(R3_OSL_CON,dat);


3. AC6958C 外挂rtc不走时间问题是晶振没有开通接到rtc模块,软件上修改后测试OK 

- AC695N解决RTC模块上电电流过大概率导致卡在devices_init里RTC线程复位问题
//此函数放在程序中device_init();函数调用之前。
void set_p3_rtc_con(void)
{
int dat;
dat = p33_rx_1byte(P3_ANA_CON2);
dat |= BIT(0);
dat |= BIT(1);
dat |= BIT(2);
p33_tx_1byte(P3_ANA_CON2,dat);
}
RTC模块上电电流过大,有概率导致卡在devices_init里复位,是因为有些芯片的RTC模块上电所需的驱动电流过高,导致内部的RTC电电压检测pending一直为1,没清0,while住,从而看门狗复位。
5. AC701N 音箱SDK解决RTC模块cpu_reset();后RTC会重置问题 解决思想是:写时间到ram中去,写时间到不复位的区域
jl701n_soundbox_release_v1.3.0 复位后重置RTC问题解决办法.otl
- AC695RTC断电上电后,有概率不跑set_rtc_default_time导致初始时间错误 解决办法:
对初始化后的时间做个过滤的动作,参考代码:
void user_check_default_time()
{
struct sys_time current_time;
get_sys_time(¤t_time);
if(current_time.year < 2023 || current_time.year > 2053){
printf("current_time.year == %d\n",current_time.year);
set_rtc_default_time(¤t_time);
rtc_update_time_api(¤t_time);
}
else if(current_time.month < 1 || current_time.month > 12){
set_rtc_default_time(¤t_time);
rtc_update_time_api(¤t_time);
}
else if(current_time.day < 1 || current_time.day > 31){
set_rtc_default_time(¤t_time);
rtc_update_time_api(¤t_time);
}
else if(current_time.hour < 0 || current_time.hour > 23){
set_rtc_default_time(¤t_time);
rtc_update_time_api(¤t_time);
}
else if(current_time.min < 0 || current_time.min > 59){
set_rtc_default_time(¤t_time);
rtc_update_time_api(¤t_time);
}
else if(current_time.sec < 0 || current_time.sec > 59){
set_rtc_default_time(¤t_time);
rtc_update_time_api(¤t_time);
}
else{
}
}
本文档为保密信息,未经授权,请勿转发或告知第三方。非常感谢!
This electronic documentation and any attachments are confidential and may be legally privileged or otherwise protected from disclosure. If you are not the intended recipient, please do not disclose the contents to anyone。
Thank you for your cooperation!
解析权归杰理所有!
The analysis right belongs to JieLi Technology Co., Ltd.