Software APIs
sw
device
silicon_creator
rom
e2e
shutdown_watchdog
hang_test.c
1
// Copyright lowRISC contributors (OpenTitan project).
2
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3
// SPDX-License-Identifier: Apache-2.0
4
5
#include <
stdbool.h
>
6
7
#include "
sw/device/lib/dif/dif_aon_timer.h
"
8
#include "
sw/device/lib/runtime/ibex.h
"
9
#include "
sw/device/lib/runtime/log.h
"
10
#include "
sw/device/lib/testing/test_framework/ottf_main.h
"
11
12
#include "
hw/top_earlgrey/sw/autogen/top_earlgrey.h
"
13
14
OTTF_DEFINE_TEST_CONFIG();
15
16
void
print_progress(
const
char
*prefix, dif_aon_timer_t *aon_timer,
17
ibex_timeout_t
*timeout) {
18
uint32_t count;
19
CHECK_DIF_OK(
dif_aon_timer_watchdog_get_count
(aon_timer, &count));
20
uint64_t elapsed =
ibex_timeout_elapsed
(timeout);
21
elapsed =
udiv64_slow
(elapsed, 1000, NULL);
22
LOG_INFO
(
"%s: after %d ms, watchdog count=%d"
, prefix, (uint32_t)elapsed,
23
count);
24
}
25
26
bool
test_main
(
void
) {
27
dif_aon_timer_t aon_timer;
28
CHECK_DIF_OK(dif_aon_timer_init(
29
mmio_region_from_addr
(
TOP_EARLGREY_AON_TIMER_AON_BASE_ADDR
), &aon_timer));
30
/* Pet the watchdog to have make sure that we start from a known value */
31
CHECK_DIF_OK(
dif_aon_timer_watchdog_pet
(&aon_timer));
32
ibex_timeout_t
timeout =
ibex_timeout_init
(HANG_SECS * 1000000);
33
while
(!
ibex_timeout_check
(&timeout)) {
34
// Print a status message every 100ms.
35
ibex_timeout_t
inter_tmo =
ibex_timeout_init
(100000);
36
while
(!
ibex_timeout_check
(&inter_tmo)) {
37
}
38
print_progress(
"Status"
, &aon_timer, &timeout);
39
}
40
// Print final status.
41
print_progress(
"Wait done"
, &aon_timer, &timeout);
42
return
true
;
43
}
Return to
OpenTitan Documentation