Software APIs
rv_core_ibex_testutils.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 #include <stdint.h>
7 
8 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
11 
12 #define MODULE_ID MAKE_MODULE_ID('r', 'v', 'c')
13 
14 bool rv_core_ibex_testutils_is_rnd_data_valid(
15  const dif_rv_core_ibex_t *rv_core_ibex) {
16  dif_rv_core_ibex_rnd_status_t rnd_status;
17  dif_result_t res = dif_rv_core_ibex_get_rnd_status(rv_core_ibex, &rnd_status);
18  return (res == kDifOk) && (rnd_status & kDifRvCoreIbexRndStatusValid);
19 }
20 
21 status_t rv_core_ibex_testutils_get_rnd_data(
22  const dif_rv_core_ibex_t *rv_core_ibex, uint32_t timeout_usec,
23  uint32_t *rnd_data) {
24  IBEX_TRY_SPIN_FOR(rv_core_ibex_testutils_is_rnd_data_valid(rv_core_ibex),
25  timeout_usec);
26 
27  TRY(dif_rv_core_ibex_read_rnd_data(rv_core_ibex, rnd_data));
28  TRY_CHECK(*rnd_data != 0);
29  TRY_CHECK(*rnd_data != UINT32_MAX);
30  return OK_STATUS();
31 }