Software APIs
spi_host_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_SPI_HOST_TESTUTILS_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_SPI_HOST_TESTUTILS_H_
7 
8 #include <assert.h>
9 #include <stdint.h>
10 
11 #include "dt/dt_api.h" // Generated
12 #include "sw/device/lib/base/status.h"
15 
16 typedef enum spi_pinmux_platform_id {
17  kSpiPinmuxPlatformIdCw310 = 0,
18  kSpiPinmuxPlatformIdCw340,
19  kSpiPinmuxPlatformIdTeacup,
20  kSpiPinmuxPlatformIdCount,
21 } spi_pinmux_platform_id_t;
22 
23 /**
24  * Configure the pad attributes of SPI Host 0.
25  *
26  * @return A status_t indicating success or failure configuring the pad
27  * attributes.
28  */
30 status_t spi_host_testutils_configure_host0_pad_attrs(dif_pinmux_t *pinmux);
31 
32 /**
33  * Return True if spi host is active.
34  *
35  * @param spi_host A spi host handle.
36  * @return `Ok(res)` Where `res` is true if spi host is active, or `kInternal`
37  * in case of an error.
38  */
40 static inline status_t spi_host_testutils_is_active(dif_spi_host_t *spi_host) {
42  TRY(dif_spi_host_get_status(spi_host, &status));
43  return OK_STATUS(status.active);
44 }
45 
46 /**
47  * Flush the rx fifo.
48  *
49  * @param spi_host A spi host handle.
50  * @return The result of the operation.
51  */
53 status_t spi_host_testutils_flush(dif_spi_host_t *spi_host);
54 
55 #if defined(OPENTITAN_IS_EARLGREY)
56 /**
57  * Connect the spi host 1 to the BoB.
58  *
59  * @param pinmux A pinmux handle.
60  * @param csb_outsel The chip select pin, this should be one of the eight
61  * devices in the BoB connected to the bus. See ::dt_pad_t in the generated
62  * `dt_api.h` header, or similar top-specific ::top_{name}_pinmux_mio_out_t,
63  * which is not autogenerated.
64  * @param platform_id The ID of the platform where the test in running.
65  * @return The result of the operation.
66  */
68 status_t spi_host1_pinmux_connect_to_bob(const dif_pinmux_t *pinmux,
69  dt_pad_t csb_outsel,
70  spi_pinmux_platform_id_t platform_id);
71 #elif defined(OPENTITAN_IS_DARJEELING)
72 // Darjeeling only has a single SPI host
73 #else
74 #error "spi_host_testutils does not support this top"
75 #endif
76 
77 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_SPI_HOST_TESTUTILS_H_