Software APIs
ret_sram_testutils.h
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 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_RET_SRAM_TESTUTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_RET_SRAM_TESTUTILS_H_
7 
8 #include <stdint.h>
9 
10 #include "sw/device/lib/base/status.h"
11 
12 /**
13  * This provides a number of counters and a scratch array.
14  * They will be preserved across reset, and cleared on POR.
15  *
16  * All data read must be initialized, or ECC errors will be triggered.
17  */
18 enum {
19  /**
20  * The number of 32-bit counters.
21  */
22  kRetSramTestutilsNumberOfCounters = 4,
23 
24  /**
25  * The size of the scratch array in 32-bit words.
26  */
27  kRetSramTestutilsScratchSizeAsInts = 256
28 };
29 
30 /**
31  * Initialise the retention SRAM test utilities location.
32  * Must be called before other ret_ram_testutils functions can be used.
33  */
34 void ret_sram_testutils_init(void);
35 
36 /**
37  * Clears the value of a counter in retention sram.
38  *
39  * @param counter Counter ID, [0..kRetSramTestutilsNumberOfCounters].
40  * @return The status of the operation.
41  */
43 status_t ret_sram_testutils_counter_clear(size_t counter);
44 
45 /**
46  * Returns the value of a counter in retention sram.
47  *
48  * @param counter Counter ID, [0..kRetSramTestutilsNumberOfCounters].
49  * @param[out] Value of the counter.
50  * @return The status of the operation.
51  */
53 status_t ret_sram_testutils_counter_get(size_t counter, uint32_t *value);
54 
55 /**
56  * Increments the value of a counter in retention sram.
57  *
58  * @param counter Counter ID, [0..kRetSramTestutilsNumberOfCounters].
59  * @return The status of the operation.
60  */
62 status_t ret_sram_testutils_counter_increment(size_t counter);
63 
64 /**
65  * Sets the value of a counter in retention sram.
66  *
67  * @param counter Counter ID, [0..kRetSramTestutilsNumberOfCounters].
68  * @param Value of the counter.
69  * @return The status of the operation.
70  */
72 status_t ret_sram_testutils_counter_set(size_t counter, uint32_t value);
73 
74 /**
75  * Read data from the scratch array.
76  *
77  * @param offset The starting offset to be read as int32s.
78  * @param size Number of uint32 words to be read.
79  * @param[out] dest Where to place the data read.
80  * @return The status of the operation.
81  */
83 status_t ret_sram_testutils_scratch_read(size_t offset, size_t size,
84  uint32_t *dest);
85 
86 /**
87  * Write data to the scratch array.
88  *
89  * @param offset The starting offset to be written as int32s.
90  * @param size Number of uint32 words to be written.
91  * @param src The address of the data to be written.
92  * @return The status of the operation.
93  */
95 status_t ret_sram_testutils_scratch_write(size_t offset, size_t size,
96  uint32_t *src);
97 
98 /**
99  * Read rom identity from retention_sram and indicate
100  * whether current test platform uses test_rom.c or not.
101  *
102  * @param true : current test platform uses test_rom.c
103  * false : current test platform doesn't use test_rom.c
104  * which can imply it uses rom.c
105  */
107 status_t ret_sram_testutils_is_testrom(bool *is_testrom);
108 
109 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RET_SRAM_TESTUTILS_H_