Question about _rtc_get_time

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Question about _rtc_get_time

跳至解决方案
1,476 次查看
rogerchaplin
Contributor II

I'm looking at the _rtc_get_time source code in srtc.c for MQX 4.1.0 (I'm using it in a VF65GS10 project) and believe I may have found a bug. Here is the code:

    uint32_t tmp = 0;

    do {

        *time = tmp;

        tmp   = (snvs->LPSRTCMR << 17) | (snvs->LPSRTCLR >> 15) ;

    } while (tmp != *time);

This is apparently trying to achieve a coherent read of the two RTC registers by continually reading them until it obtains two consecutive identical values. However, this code will always go through the do/while only one time, because of the way the tmp variable is initialized. To operate correctly the first line should instead be:

    uint32_t tmp = (snvs->LPSRTCMR << 17) | (snvs->LPSRTCLR >> 15) ;

Am I missing something here?

标记 (1)
0 项奖励
回复
1 解答
1,316 次查看
matthewkendall
Contributor V

On the contrary, it is guaranteed to go through the loop at least twice, because at the end of the first iteration *time will be zero and tmp will be the result of reading the registers (presumably non-zero). Thus the condition evaluates as true and it loops.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,316 次查看
rogerchaplin
Contributor II

Thanks for the reply. I must have been having a bad logic day.

0 项奖励
回复
1,317 次查看
matthewkendall
Contributor V

On the contrary, it is guaranteed to go through the loop at least twice, because at the end of the first iteration *time will be zero and tmp will be the result of reading the registers (presumably non-zero). Thus the condition evaluates as true and it loops.

0 项奖励
回复