930电子网

 找回密码
 立即注册
艾克姆科技推出最新产品STC32G12K128开发板
查看: 11440|回复: 1

关于rtc_update中重复开启RTC1问题

[复制链接]

57

主题

80

帖子

366

积分

中级会员

Rank: 3Rank: 3

积分
366
发表于 2020-9-28 18:10:44 | 显示全部楼层 |阅读模式
static void rtc_update(drv_rtc_t const * const  p_instance)
{
    while(1)
    {
        app_timer_t * p_next = sortlist_peek();
        bool rtc_reconf = false;
        if (p_next) //Candidate for active timer
        {
            if (mp_active_timer == NULL)
            {
                //There is no active timer so candidate will become active timer.
                rtc_reconf = true;
            }
            else if (p_next->end_val < mp_active_timer->end_val)
            {
                //Candidate has shorter timeout than current active timer. Candidate will replace active timer.
                //Active timer is put back into sorted list.
                rtc_reconf = true;
                if (mp_active_timer->active)
                {
                    NRF_LOG_INST_DEBUG(mp_active_timer->p_log, "Timer preempted.");
                    nrf_sortlist_add(&m_app_timer_sortlist, &mp_active_timer->list_item);
                }
            }
            if (rtc_reconf)
            {
                bool rerun;
                p_next = sortlist_pop();
                NRF_LOG_INST_DEBUG(p_next->p_log, "Activating timer (CC:%d/%08x).", p_next->end_val, p_next->end_val);
                if (rtc_schedule(p_next, &rerun))
                {
                    if (!APP_TIMER_KEEPS_RTC_ACTIVE && (mp_active_timer == NULL))
                    {                              
           drv_rtc_start(p_instance);           
                    }
                    mp_active_timer = p_next;
                    if (rerun == false)
                    {
                        //RTC was successfully updated and sortlist was not updated. Function can be terminated.
            //printf("RTC was successfully updated\n");
                        break;
                    }
                }
                else
                {
                    //If RTC driver indicated that timeout already occured a new candidate will be taken from sorted list.
                    //NRF_LOG_INST_DEBUG(p_next->p_log,"Timer expired before scheduled to RTC.");
          //printf("Timer expired before scheduled to RTC\n");
                    mp_active_timer = NULL;
                }
            }
            else
            {
                //RTC will not be updated. Function can terminate.
                break;
            }
        }
        else //No candidate for active timer.
        {
            if (!APP_TIMER_KEEPS_RTC_ACTIVE && (mp_active_timer == NULL))
            {
                drv_rtc_stop(p_instance);
            }
            break;
        }
    }
}
其中代码片段:
if (rtc_schedule(p_next, &rerun))
                {
                    if (!APP_TIMER_KEEPS_RTC_ACTIVE && (mp_active_timer == NULL))
                    {                              
           drv_rtc_start(p_instance);           
                    }
                    mp_active_timer = p_next;
                    if (rerun == false)
                    {
                        //RTC was successfully updated and sortlist was not updated. Function can be terminated.
            //printf("RTC was successfully updated\n");
                        break;
                    }
                }
}
rtc_schedule后,每次都会 drv_rtc_start(p_instance),重新启动RTC1计数器,会清零Counter吗

回复

使用道具 举报

52

主题

339

帖子

6487

积分

版主

Rank: 7Rank: 7Rank: 7

积分
6487
发表于 2020-9-30 16:11:06 | 显示全部楼层
启动前,已经执行了STOP任务,STOP任务会清零Counter的。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|官方淘宝店|930电子网 ( 皖ICP备16000695号-2 )

GMT+8, 2024-4-30 20:54 , Processed in 0.064410 second(s), 21 queries .

快速回复 返回顶部 返回列表