Software APIs
spi_host_flash_test_impl.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_TESTS_SPI_HOST_FLASH_TEST_IMPL_H_
6 #define OPENTITAN_SW_DEVICE_TESTS_SPI_HOST_FLASH_TEST_IMPL_H_
7 
8 #include "sw/device/lib/base/status.h"
10 #include "sw/device/lib/testing/spi_flash_testutils.h"
11 
12 /**
13  * Send the sw_reset command.
14  *
15  * @param spi A spi host handler.
16  * @return status_t containing either OK or an error.
17  */
18 status_t test_software_reset(dif_spi_host_t *spi);
19 
20 /**
21  * Read the sfdp header and check the signature.
22  *
23  * @param spi A spi host handler.
24  * @return status_t containing either OK or an error.
25  */
26 status_t test_read_sfdp(dif_spi_host_t *spi);
27 
28 /**
29  * Send the sector erase command, read a page that it was erased.
30  *
31  * @param spi A spi host handler.
32  * @return status_t containing either OK or an error.
33  */
34 status_t test_sector_erase(dif_spi_host_t *spi);
35 
36 /**
37  * Read jedec and check the device_id and manufacturer_id.
38  *
39  * @param spi A spi host handler.
40  * @param device_id The expected device_id.
41  * @param manufacture_id The expected manufacture_id.
42  * @return status_t containing either OK or an error.
43  */
44 status_t test_read_jedec(dif_spi_host_t *spi, uint16_t manufacture_id);
45 
46 /**
47  * Send the enable quad mode command.
48  *
49  * @param spi A spi host handler.
50  * @return status_t containing either OK or an error.
51  */
52 status_t test_enable_quad_mode(dif_spi_host_t *spi);
53 
54 /**
55  * Program a complete page and read it back to verify.
56  *
57  * @param spi A spi host handler.
58  * @return status_t containing either OK or an error.
59  */
60 status_t test_page_program(dif_spi_host_t *spi);
61 
62 /**
63  * Perform a fast read operation.
64  *
65  * @param spi A spi host handler.
66  * @return status_t containing either OK or an error.
67  */
68 status_t test_fast_read(dif_spi_host_t *spi);
69 
70 /**
71  * Perform a dual read operation.
72  *
73  * @param spi A spi host handler.
74  * @return status_t containing either OK or an error.
75  */
76 status_t test_dual_read(dif_spi_host_t *spi);
77 
78 /**
79  * Perform a quad read operation.
80  *
81  * @param spi A spi host handler.
82  * @return status_t containing either OK or an error.
83  */
84 status_t test_quad_read(dif_spi_host_t *spi);
85 
86 /**
87  * Check if the flash supports 4-byte addressing.
88  *
89  * @param spi A spi host handler.
90  * @return True if 4-byte addressing mode is supported.
91  */
92 bool is_4_bytes_address_mode_supported(void);
93 
94 /**
95  * Enable 4-byte addressing mode, write and read to a page that needs 4 bytes to
96  * be addressed and disables the 4-bytes addressing mode.
97  *
98  * @param spi A spi host handler.
99  * @return status_t containing either OK or an error.
100  */
101 status_t test_4bytes_address(dif_spi_host_t *spi);
102 
103 /**
104  * Write and read in order to compare a page using quad mode.
105  *
106  * @param spi A spi host handler.
107  * @param opcode The opcode used by the part-number for quad page program.
108  * @param page_program_mode The width of the transaction sections (opcode,
109  * address and data).
110  * @return status_t containing either OK or an error.
111  */
112 status_t test_page_program_quad(
113  dif_spi_host_t *spi, uint8_t opcode,
114  spi_flash_testutils_transaction_width_mode_t page_program_mode);
115 
116 /**
117  * Erase a 32kB block and read it back to check if was erased.
118  *
119  * @param spi A spi host handler.
120  * @return status_t containing either OK or an error.
121  */
122 status_t test_erase_32k_block(dif_spi_host_t *spi);
123 
124 /**
125  * Erase a 64kB block and read it back to check if was erased.
126  *
127  * @param spi A spi host handler.
128  * @return status_t containing either OK or an error.
129  */
130 status_t test_erase_64k_block(dif_spi_host_t *spi);
131 
132 #endif // OPENTITAN_SW_DEVICE_TESTS_SPI_HOST_FLASH_TEST_IMPL_H_