summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/stm32/clock-stm32f4.c6
-rw-r--r--chip/stm32/config-stm32f4.h11
-rw-r--r--test/stm32f_rtc.c24
3 files changed, 35 insertions, 6 deletions
diff --git a/chip/stm32/clock-stm32f4.c b/chip/stm32/clock-stm32f4.c
index 401c06be1c..b30edc1fa2 100644
--- a/chip/stm32/clock-stm32f4.c
+++ b/chip/stm32/clock-stm32f4.c
@@ -438,12 +438,6 @@ static int dsleep_recovery_margin_us = 1000000;
#define STOP_MODE_LATENCY 50 /* us */
/* PLL_LOCK_LATENCY: delay to switch from HSI to PLL */
#define PLL_LOCK_LATENCY 150 /* us */
-/*
- * SET_RTC_MATCH_DELAY: max time to set RTC match alarm. If we set the alarm
- * in the past, it will never wake up and cause a watchdog.
- */
-#define SET_RTC_MATCH_DELAY 120 /* us */
-
void low_power_init(void)
{
diff --git a/chip/stm32/config-stm32f4.h b/chip/stm32/config-stm32f4.h
index 46303444fc..ee1d594116 100644
--- a/chip/stm32/config-stm32f4.h
+++ b/chip/stm32/config-stm32f4.h
@@ -73,3 +73,14 @@
/* DFU Address */
#define STM32_DFU_BASE 0x1fff0000
+
+/*
+ * SET_RTC_MATCH_DELAY: max time to set RTC match alarm. If we set the alarm
+ * in the past, it will never wake up and cause a watchdog.
+ *
+ * This value is minimal time for which we can set RTC match alarm. It was
+ * obtained by setting the alarm and checking if the alarm interrupt was
+ * triggered. Unit test test_rtc_match_delay is responsible for verifying if
+ * setting the RTC match alarm with this value will generate the interrupt.
+ */
+#define SET_RTC_MATCH_DELAY 200 /* us */
diff --git a/test/stm32f_rtc.c b/test/stm32f_rtc.c
index 36c67f004e..b9b48ec043 100644
--- a/test/stm32f_rtc.c
+++ b/test/stm32f_rtc.c
@@ -53,11 +53,35 @@ test_static int test_rtc_alarm(void)
return EC_SUCCESS;
}
+static const int rtc_match_delay_iterations = 5000;
+
+test_static int test_rtc_match_delay(void)
+{
+ struct rtc_time_reg rtc;
+ int i;
+
+ atomic_clear(&rtc_fired);
+ for (i = 0; i < rtc_match_delay_iterations; i++) {
+ set_rtc_alarm(0, SET_RTC_MATCH_DELAY, &rtc, 0);
+ usleep(2 * SET_RTC_MATCH_DELAY);
+ }
+
+ ccprintf("Expected number of RTC alarm interrupts %d\n",
+ rtc_match_delay_iterations);
+ ccprintf("Actual number of RTC alarm interrupts %d\n", rtc_fired);
+
+ /* Make sure each set_rtc_alarm() generated the interrupt. */
+ TEST_EQ(rtc_match_delay_iterations, atomic_clear(&rtc_fired), "%d");
+
+ return EC_SUCCESS;
+}
+
void run_test(int argc, char **argv)
{
test_reset();
RUN_TEST(test_rtc_alarm);
+ RUN_TEST(test_rtc_match_delay);
test_print_result();
}