Question about _rtc_get_time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about _rtc_get_time

Jump to solution
631 Views
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?

Tags (1)
0 Kudos
1 Solution
471 Views
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.

View solution in original post

0 Kudos
2 Replies
471 Views
rogerchaplin
Contributor II

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

0 Kudos
472 Views
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 Kudos