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?
已解决! 转到解答。
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.
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.