1.1 --- a/pkg/devices/lib/rtc/include/rtc-x1600.h Thu Nov 16 01:15:40 2023 +0100
1.2 +++ b/pkg/devices/lib/rtc/include/rtc-x1600.h Thu Nov 16 17:48:32 2023 +0100
1.3 @@ -52,6 +52,10 @@
1.4
1.5 void alarm_enable();
1.6
1.7 + void wakeup_alarm_disable();
1.8 +
1.9 + void wakeup_alarm_enable();
1.10 +
1.11 uint32_t get_seconds();
1.12
1.13 void set_seconds(uint32_t seconds);
1.14 @@ -62,6 +66,8 @@
1.15
1.16 void set_regulator(uint32_t base, uint32_t adjustment);
1.17
1.18 + void hibernate();
1.19 +
1.20 void power_down();
1.21 };
1.22
1.23 @@ -83,6 +89,10 @@
1.24
1.25 void x1600_rtc_alarm_enable(void *rtc);
1.26
1.27 +void x1600_rtc_wakeup_alarm_disable(void *rtc);
1.28 +
1.29 +void x1600_rtc_wakeup_alarm_enable(void *rtc);
1.30 +
1.31 uint32_t x1600_rtc_get_seconds(void *rtc);
1.32
1.33 void x1600_rtc_set_seconds(void *rtc, uint32_t seconds);
1.34 @@ -93,6 +103,8 @@
1.35
1.36 void x1600_rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment);
1.37
1.38 +void x1600_rtc_hibernate(void *rtc);
1.39 +
1.40 void x1600_rtc_power_down(void *rtc);
1.41
1.42 EXTERN_C_END
2.1 --- a/pkg/devices/lib/rtc/src/x1600.cc Thu Nov 16 01:15:40 2023 +0100
2.2 +++ b/pkg/devices/lib/rtc/src/x1600.cc Thu Nov 16 17:48:32 2023 +0100
2.3 @@ -193,7 +193,21 @@
2.4 Rtc_x1600_chip::alarm_enable()
2.5 {
2.6 write_enable();
2.7 - _regs[Rtc_control] = _regs[Rtc_control] | Control_alarm_enable;
2.8 + _regs[Rtc_control] = (_regs[Rtc_control] & ~Control_alarm) | Control_alarm_enable;
2.9 +}
2.10 +
2.11 +void
2.12 +Rtc_x1600_chip::wakeup_alarm_disable()
2.13 +{
2.14 + write_enable();
2.15 + _regs[Hibernate_wakeup_control] = _regs[Hibernate_wakeup_control] & ~Rtc_alarm_wakeup_enable;
2.16 +}
2.17 +
2.18 +void
2.19 +Rtc_x1600_chip::wakeup_alarm_enable()
2.20 +{
2.21 + write_enable();
2.22 + _regs[Hibernate_wakeup_control] = _regs[Hibernate_wakeup_control] | Rtc_alarm_wakeup_enable;
2.23 }
2.24
2.25 uint32_t
2.26 @@ -240,6 +254,14 @@
2.27 }
2.28
2.29 void
2.30 +Rtc_x1600_chip::hibernate()
2.31 +{
2.32 + alarm_enable();
2.33 + wakeup_alarm_enable();
2.34 + power_down();
2.35 +}
2.36 +
2.37 +void
2.38 Rtc_x1600_chip::power_down()
2.39 {
2.40 write_enable();
2.41 @@ -301,6 +323,11 @@
2.42 static_cast<Rtc_x1600_chip *>(rtc)->set_regulator(base, adjustment);
2.43 }
2.44
2.45 +void x1600_rtc_hibernate(void *rtc)
2.46 +{
2.47 + static_cast<Rtc_x1600_chip *>(rtc)->hibernate();
2.48 +}
2.49 +
2.50 void x1600_rtc_power_down(void *rtc)
2.51 {
2.52 static_cast<Rtc_x1600_chip *>(rtc)->power_down();
3.1 --- a/pkg/landfall-examples/hw_info/common.h Thu Nov 16 01:15:40 2023 +0100
3.2 +++ b/pkg/landfall-examples/hw_info/common.h Thu Nov 16 17:48:32 2023 +0100
3.3 @@ -181,6 +181,8 @@
3.4
3.5 void rtc_set_alarm_seconds(void *rtc, uint32_t seconds);
3.6
3.7 +void rtc_hibernate(void *rtc);
3.8 +
3.9 void rtc_power_down(void *rtc);
3.10
3.11 void rtc_set_regulator(void *rtc, uint32_t base, uint32_t adjustment);
4.1 --- a/pkg/landfall-examples/hw_info/hw_info.c Thu Nov 16 01:15:40 2023 +0100
4.2 +++ b/pkg/landfall-examples/hw_info/hw_info.c Thu Nov 16 17:48:32 2023 +0100
4.3 @@ -1115,6 +1115,22 @@
4.4
4.5 /* RTC operations. */
4.6
4.7 +static void rtc_reset(void *rtc, void *cpm)
4.8 +{
4.9 + unsigned int seconds;
4.10 +
4.11 + if (!read_number("Seconds", &seconds))
4.12 + return;
4.13 +
4.14 + /* NOTE: Assuming EXCLK/512 as RTC source. */
4.15 +
4.16 + uint32_t rtc_seconds = rtc_get_seconds(rtc);
4.17 + uint32_t value = seconds * cpm_get_frequency(cpm, Clock_external) / 512;
4.18 +
4.19 + rtc_set_alarm_seconds(rtc, rtc_seconds + value);
4.20 + rtc_hibernate(rtc);
4.21 +}
4.22 +
4.23 static void _rtc_set_seconds(void *rtc, int alarm)
4.24 {
4.25 unsigned int seconds;
4.26 @@ -1436,7 +1452,7 @@
4.27 list_memory_regions();
4.28 }
4.29
4.30 -static void handle_rtc(void *rtc)
4.31 +static void handle_rtc(void *rtc, void *cpm)
4.32 {
4.33 char *token;
4.34
4.35 @@ -1452,15 +1468,17 @@
4.36 printf("seconds = %d\n", rtc_get_alarm_seconds(rtc));
4.37 else if (!strcmp(token, "p") || !strcmp(token, "power-down"))
4.38 rtc_power_down(rtc);
4.39 + else if (!strcmp(token, "r") || !strcmp(token, "reset"))
4.40 + rtc_reset(rtc, cpm);
4.41 else if (!strcmp(token, "s") || !strcmp(token, "set"))
4.42 _rtc_set_seconds(rtc, 0);
4.43 else if (!strcmp(token, "sa") || !strcmp(token, "set-alarm"))
4.44 _rtc_set_seconds(rtc, 1);
4.45 else
4.46 - printf("rtc disable | enable | get | get-alarm | power-down | set | set-alarm\n");
4.47 + printf("rtc disable | enable | get | get-alarm | power-down | reset | set | set-alarm\n");
4.48 }
4.49 else
4.50 - printf("rtc disable | enable | get | get-alarm | power-down | set | set-alarm\n");
4.51 + printf("rtc disable | enable | get | get-alarm | power-down | reset | set | set-alarm\n");
4.52 }
4.53
4.54 static void handle_spi(void *spi, void *gpio[])
4.55 @@ -1646,7 +1664,7 @@
4.56 /* RTC commands. */
4.57
4.58 else if (!strcmp(token, "r") || !strcmp(token, "rtc"))
4.59 - handle_rtc(rtc);
4.60 + handle_rtc(rtc, cpm);
4.61
4.62 /* SPI commands. */
4.63
5.1 --- a/pkg/landfall-examples/hw_info/jz4780.c Thu Nov 16 01:15:40 2023 +0100
5.2 +++ b/pkg/landfall-examples/hw_info/jz4780.c Thu Nov 16 17:48:32 2023 +0100
5.3 @@ -372,6 +372,11 @@
5.4 x1600_rtc_set_alarm_seconds(rtc, seconds);
5.5 }
5.6
5.7 +void rtc_hibernate(void *rtc)
5.8 +{
5.9 + x1600_rtc_hibernate(rtc);
5.10 +}
5.11 +
5.12 void rtc_power_down(void *rtc)
5.13 {
5.14 x1600_rtc_power_down(rtc);
6.1 --- a/pkg/landfall-examples/hw_info/x1600.c Thu Nov 16 01:15:40 2023 +0100
6.2 +++ b/pkg/landfall-examples/hw_info/x1600.c Thu Nov 16 17:48:32 2023 +0100
6.3 @@ -361,6 +361,11 @@
6.4 x1600_rtc_set_alarm_seconds(rtc, seconds);
6.5 }
6.6
6.7 +void rtc_hibernate(void *rtc)
6.8 +{
6.9 + x1600_rtc_hibernate(rtc);
6.10 +}
6.11 +
6.12 void rtc_power_down(void *rtc)
6.13 {
6.14 x1600_rtc_power_down(rtc);