[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 16/23] test/unit: add spi-tester
From: |
Octavian Purdila |
Subject: |
[RFC PATCH 16/23] test/unit: add spi-tester |
Date: |
Mon, 5 Aug 2024 13:17:11 -0700 |
Add a simple SPI peripheral that echoes back received data. Useful for
testing SPI controllers.
Signed-off-by: Octavian Purdila <tavip@google.com>
---
tests/unit/spi_tester.c | 60 +++++++++++++++++++++++++++++++++++++++++
tests/unit/spi_tester.h | 32 ++++++++++++++++++++++
2 files changed, 92 insertions(+)
create mode 100644 tests/unit/spi_tester.c
create mode 100644 tests/unit/spi_tester.h
diff --git a/tests/unit/spi_tester.c b/tests/unit/spi_tester.c
new file mode 100644
index 0000000000..7bccc680cc
--- /dev/null
+++ b/tests/unit/spi_tester.c
@@ -0,0 +1,60 @@
+/*
+ * Simple SPI peripheral echo device used for SPI controller testing.
+ *
+ * Copyright (c) 2024 Google LLC.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "spi_tester.h"
+
+static uint32_t spi_tester_transfer(SSIPeripheral *dev, uint32_t value)
+{
+ SpiTesterState *s = SPI_TESTER(dev);
+
+ if (s->cs) {
+ return 0;
+ }
+
+ return value;
+}
+
+static void spi_tester_realize(SSIPeripheral *d, Error **errp)
+{
+}
+
+static int spi_tester_set_cs(SSIPeripheral *dev, bool select)
+{
+ SpiTesterState *s = SPI_TESTER(dev);
+
+ s->cs = select;
+
+ return 0;
+}
+
+static void spi_tester_class_init(ObjectClass *klass, void *data)
+{
+ SSIPeripheralClass *k = SSI_PERIPHERAL_CLASS(klass);
+
+ k->realize = spi_tester_realize;
+ k->transfer = spi_tester_transfer;
+ k->set_cs = spi_tester_set_cs;
+ k->cs_polarity = SSI_CS_LOW;
+}
+
+static const TypeInfo spi_tester_info = {
+ .name = TYPE_SPI_TESTER,
+ .parent = TYPE_SSI_PERIPHERAL,
+ .instance_size = sizeof(SpiTesterState),
+ .class_init = spi_tester_class_init,
+};
+
+static void spi_tester_register_types(void)
+{
+ type_register_static(&spi_tester_info);
+}
+
+type_init(spi_tester_register_types)
diff --git a/tests/unit/spi_tester.h b/tests/unit/spi_tester.h
new file mode 100644
index 0000000000..16e08d2b5c
--- /dev/null
+++ b/tests/unit/spi_tester.h
@@ -0,0 +1,32 @@
+/*
+ * Simple SPI peripheral device used for SPI controller testing.
+ *
+ * Copyright (c) 2024 Google LLC.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TESTS_UNIT_SPI_TESTER_H
+#define TESTS_UNIT_SPI_TESTER_H
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qemu/module.h"
+#include "qemu/bswap.h"
+#include "hw/irq.h"
+#include "hw/ssi/ssi.h"
+#include "qemu/timer.h"
+#include "hw/qdev-properties.h"
+
+#define TYPE_SPI_TESTER "spi-tester"
+#define SPI_TESTER(obj) OBJECT_CHECK(SpiTesterState, (obj), TYPE_SPI_TESTER)
+
+typedef struct {
+ SSIPeripheral ssidev;
+ bool cs;
+} SpiTesterState;
+
+#endif /* TESTS_UNIT_SPI_TESTER_H */
--
2.46.0.rc2.264.g509ed76dc8-goog
- [RFC PATCH 06/23] hw/misc: add basic flexcomm device model, (continued)
- [RFC PATCH 06/23] hw/misc: add basic flexcomm device model, Octavian Purdila, 2024/08/05
- [RFC PATCH 08/23] test/unit: add register access macros and functions, Octavian Purdila, 2024/08/05
- [RFC PATCH 07/23] tests/unit: add system bus mock, Octavian Purdila, 2024/08/05
- [RFC PATCH 09/23] test/unit: add flexcomm unit test, Octavian Purdila, 2024/08/05
- [RFC PATCH 11/23] test/unit: add flexcomm usart unit test, Octavian Purdila, 2024/08/05
- [RFC PATCH 10/23] hw/char: add support for flexcomm usart, Octavian Purdila, 2024/08/05
- [RFC PATCH 12/23] hw/i2c: add support for flexcomm i2c, Octavian Purdila, 2024/08/05
- [RFC PATCH 13/23] test/unit: add i2c-tester, Octavian Purdila, 2024/08/05
- [RFC PATCH 14/23] test/unit: add unit tests for flexcomm i2c, Octavian Purdila, 2024/08/05
- [RFC PATCH 15/23] hw/ssi: add support for flexcomm spi, Octavian Purdila, 2024/08/05
- [RFC PATCH 16/23] test/unit: add spi-tester,
Octavian Purdila <=
- [RFC PATCH 18/23] hw/misc: add support for RT500's clock controller, Octavian Purdila, 2024/08/05
- [RFC PATCH 17/23] test/unit: add unit tests for flexcomm spi, Octavian Purdila, 2024/08/05
- [RFC PATCH 19/23] test/unit: add unit tests for RT500's clock controller, Octavian Purdila, 2024/08/05
- [RFC PATCH 21/23] hw/misc: add support for RT500 reset controller, Octavian Purdila, 2024/08/05
- [RFC PATCH 22/23] hw/arm: add basic support for the RT500 SoC, Octavian Purdila, 2024/08/05
- [RFC PATCH 20/23] hw/ssi: add support for flexspi, Octavian Purdila, 2024/08/05