diff options
-rw-r--r-- | board/hatch_fp/build.mk | 1 | ||||
-rw-r--r-- | board/nocturne_fp/build.mk | 1 | ||||
-rw-r--r-- | board/nucleo-dartmonkey/build.mk | 1 | ||||
-rw-r--r-- | board/nucleo-f412zg/build.mk | 1 | ||||
-rw-r--r-- | chip/stm32/clock-f.c | 1 | ||||
-rw-r--r-- | test/build.mk | 1 | ||||
-rw-r--r-- | test/stm32f_rtc.c | 52 | ||||
-rw-r--r-- | test/stm32f_rtc.tasklist | 9 |
8 files changed, 67 insertions, 0 deletions
diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk index 93c40a530d..4ba4410e27 100644 --- a/board/hatch_fp/build.mk +++ b/board/hatch_fp/build.mk @@ -20,3 +20,4 @@ test-list-y=\ rtc \ sha256 \ sha256_unrolled \ + stm32f_rtc \ diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk index 3bc105df9a..8bb7855fcd 100644 --- a/board/nocturne_fp/build.mk +++ b/board/nocturne_fp/build.mk @@ -21,3 +21,4 @@ test-list-y=\ rtc \ sha256 \ sha256_unrolled \ + stm32f_rtc \ diff --git a/board/nucleo-dartmonkey/build.mk b/board/nucleo-dartmonkey/build.mk index 6bc55bd88d..1dcee54164 100644 --- a/board/nucleo-dartmonkey/build.mk +++ b/board/nucleo-dartmonkey/build.mk @@ -19,3 +19,4 @@ test-list-y=\ rtc \ sha256 \ sha256_unrolled \ + stm32f_rtc \ diff --git a/board/nucleo-f412zg/build.mk b/board/nucleo-f412zg/build.mk index 26b10c5c63..9b2f59c7d9 100644 --- a/board/nucleo-f412zg/build.mk +++ b/board/nucleo-f412zg/build.mk @@ -18,3 +18,4 @@ test-list-y=\ rtc \ sha256 \ sha256_unrolled \ + stm32f_rtc \ diff --git a/chip/stm32/clock-f.c b/chip/stm32/clock-f.c index 90ada3eeba..f65716aa9e 100644 --- a/chip/stm32/clock-f.c +++ b/chip/stm32/clock-f.c @@ -313,6 +313,7 @@ void reset_rtc_alarm(struct rtc_time_reg *rtc) rtc_lock_regs(); } +test_mockable_static void __rtc_alarm_irq(void) { struct rtc_time_reg rtc; diff --git a/test/build.mk b/test/build.mk index 2c7bc455f7..0cc3f964da 100644 --- a/test/build.mk +++ b/test/build.mk @@ -151,6 +151,7 @@ sha256-y=sha256.o sha256_unrolled-y=sha256.o shmalloc-y=shmalloc.o static_if-y=static_if.o +stm32f_rtc-y=stm32f_rtc.o stress-y=stress.o system-y=system.o thermal-y=thermal.o diff --git a/test/stm32f_rtc.c b/test/stm32f_rtc.c new file mode 100644 index 0000000000..9224b9f757 --- /dev/null +++ b/test/stm32f_rtc.c @@ -0,0 +1,52 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "clock-f.h" +#include "test_util.h" + +static volatile uint32_t rtc_fired; +static struct rtc_time_reg rtc_irq; +static const int rtc_delay_ms = 500; + +/* Override default RTC interrupt handler */ +void __rtc_alarm_irq(void) +{ + atomic_add(&rtc_fired, 1); + reset_rtc_alarm(&rtc_irq); +} + +test_static int test_rtc_alarm(void) +{ + struct rtc_time_reg rtc; + uint32_t rtc_diff_us; + uint32_t rtc_diff_ms; + const int delay_us = rtc_delay_ms * MSEC; + + set_rtc_alarm(0, delay_us, &rtc, 0); + + msleep(2 * rtc_delay_ms); + + /* Make sure the interrupt fired exactly once. */ + TEST_EQ(1, atomic_read_clear(&rtc_fired), "%d"); + + rtc_diff_us = get_rtc_diff(&rtc, &rtc_irq); + + ccprintf("rtc_diff_us: %d\n", rtc_diff_us); + + /* Assume we'll always fire within 1 ms. May need to be adjusted if + * this doesn't hold. + */ + rtc_diff_ms = rtc_diff_us / MSEC; + TEST_EQ(rtc_diff_ms, rtc_delay_ms, "%d"); + + return EC_SUCCESS; +} + +void run_test(void) +{ + RUN_TEST(test_rtc_alarm); + + test_print_result(); +} diff --git a/test/stm32f_rtc.tasklist b/test/stm32f_rtc.tasklist new file mode 100644 index 0000000000..51734f058d --- /dev/null +++ b/test/stm32f_rtc.tasklist @@ -0,0 +1,9 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST /* no tasks */ |