Software APIs
ibex_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 #include "sw/device/lib/base/ibex.h"
5 
8 #include "sw/device/lib/base/status.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
13 
14 #include "rv_core_ibex_regs.h"
15 
16 OTTF_DEFINE_TEST_CONFIG();
17 
18 static status_t ibex_entropy_test(void) {
19  // Read the initial value of the RND_DATA CSR.
20  uint32_t rnd_data0 = ibex_rnd_data_read();
21  // Wait for RND_DATA to be valid again and check if RND_STATUS is as expected.
22  ibex_wait_rnd_valid();
23  uint32_t rnd_status = ibex_rnd_status_read();
24  TRY_CHECK(bitfield_bit32_read(rnd_status,
25  RV_CORE_IBEX_RND_STATUS_RND_DATA_VALID_BIT));
26  // Read RND_DATA again and check if it changed.
27  uint32_t rnd_data1 = ibex_rnd_data_read();
28  TRY_CHECK(rnd_data0 != rnd_data1);
29 
30  return OK_STATUS();
31 }
32 
33 bool test_main(void) {
34  status_t result = OK_STATUS();
35  // Test RND_DATA and RND_STATUS CSR access.
36  EXECUTE_TEST(result, ibex_entropy_test);
37  return status_ok(result);
38 }