RTC.Active
Posted: Sun Apr 11, 2021 7:36 am
I think there are two issues with RTC.Active().
Issue 1)
On 1 Jan 2032, Clock() will start to return negative values, so the RTC will not be installed thereafter. If no external device is connected to the SPI device, Clock() will read, via SPI, seven 0FFH bytes, as the MISO line is pulled high. Clock() will then return 0954A5965H, which is a value that will never be returned with the RTC hardware present (see DS3234 datasheet, page 12). Hence I use
Issue 2)
The problem here is at the one minute roll-over, where the value returned by Clock() changes by 5, not 1, as the output of a simple test program confirms:
Hence, there's a small chance each minute that the check will result in ok = FALSE, even with the RTC installed. To keep things simple, I just check if the Clock() value even changes, ie.
I think that's sufficiently safe. One could also check for a difference of 1 or 5.
Finally, as an aside, regarding the loop condition
I think the ABS function is not required, but does not hurt. Note that Kernel.Time() will start to return negative values at the roll-over point (080000000H).
To confirm, here's the output from a small test program with values around the roll-over point.
Case 1: ticks0 and ticks1 are positive:
Case 2: ticks0 and ticks1 are both negative:
Case 3: ticks0 is positive and ticks1 becomes negative:
The above applies to the August 2020 release of Embedded Oberon (Embedded200812.img).
Issue 1)
Code: Select all
dt0 := Clock(); ok := dt0 > 0;
Code: Select all
dt0 := Clock(); ok := dt0 # 0954A5965H;
Code: Select all
ok := dt1 - dt0 = 1
Code: Select all
time Clock()
08:18:57 1427539129
08:18:58 1427539130
08:18:59 1427539131
08:19:00 1427539136
08:19:01 1427539137
08:19:02 1427539138
08:19:03 1427539139
Code: Select all
ok := dt1 # dt0
Code: Select all
ok := (dt1 - dt0 = 1) OR (dt1 - dt0 = 5)
Code: Select all
ABS(ticks1 - ticks0) > 1010
To confirm, here's the output from a small test program with values around the roll-over point.
Case 1: ticks0 and ticks1 are positive:
Code: Select all
ticks1 ticks0 ticks1 - ticks0
7FFFFFF1 2147483633 7FFFFFF0 2147483632 1
7FFFFFF2 2147483634 7FFFFFF0 2147483632 2
7FFFFFF3 2147483635 7FFFFFF0 2147483632 3
7FFFFFF4 2147483636 7FFFFFF0 2147483632 4
7FFFFFF5 2147483637 7FFFFFF0 2147483632 5
7FFFFFF6 2147483638 7FFFFFF0 2147483632 6
7FFFFFF7 2147483639 7FFFFFF0 2147483632 7
7FFFFFF8 2147483640 7FFFFFF0 2147483632 8
Code: Select all
ticks1 ticks0 ticks1 - ticks0
80000001 -2147483647 80000000 -2147483648 1
80000002 -2147483646 80000000 -2147483648 2
80000003 -2147483645 80000000 -2147483648 3
80000004 -2147483644 80000000 -2147483648 4
80000005 -2147483643 80000000 -2147483648 5
80000006 -2147483642 80000000 -2147483648 6
80000007 -2147483641 80000000 -2147483648 7
80000008 -2147483640 80000000 -2147483648 8
Code: Select all
ticks1 ticks0 ticks1 - ticks0
7FFFFFFC 2147483644 7FFFFFFB 2147483643 1
7FFFFFFD 2147483645 7FFFFFFB 2147483643 2
7FFFFFFE 2147483646 7FFFFFFB 2147483643 3
7FFFFFFF 2147483647 7FFFFFFB 2147483643 4
80000000 -2147483648 7FFFFFFB 2147483643 5
80000001 -2147483647 7FFFFFFB 2147483643 6
80000002 -2147483646 7FFFFFFB 2147483643 7
80000003 -2147483645 7FFFFFFB 2147483643 8