-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.adb
58 lines (48 loc) · 1.39 KB
/
main.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--
-- Copyright 2021 (C) Jeremy Grosser
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with HAL.Real_Time_Clock; use HAL.Real_Time_Clock;
with RP.Timer; use RP.Timer;
with RP.Device;
with RP.Clock;
with RP.GPIO;
with Pico;
-- Helper methods for formatting date and time as an ISO 8601 string
with Text_Format;
with Ada.Text_IO;
procedure Main is
-- Try to trigger a Y2K bug
Date : RTC_Date :=
(Day_Of_Week => Sunday,
Year => 99,
Month => December,
Day => 31);
Time : RTC_Time :=
(Hour => 23,
Min => 59,
Sec => 50);
T : RP.Timer.Time;
begin
RP.Clock.Initialize (Pico.XOSC_Frequency);
RP.Device.Timer.Enable;
Pico.LED.Configure (RP.GPIO.Output);
RP.Device.RTC.Configure;
RP.Device.RTC.Set (Time, Date);
-- Wait a couple seconds after setting the time to ensure it reads back
-- correctly.
T := RP.Timer.Clock + Ticks_Per_Second * 2;
RP.Device.Timer.Delay_Until (T);
loop
RP.Device.RTC.Get (Time, Date);
-- Printing over semihosting I/O is slow enough that we occasionally
-- lose a second. If you're using this for anything important, consider
-- using a UART for output instead.
Ada.Text_IO.Put_Line
(Text_Format.To_String (Time, Date));
Pico.LED.Toggle;
T := T + Ticks_Per_Second;
RP.Device.Timer.Delay_Until (T);
end loop;
end Main;