summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/host/board.c9
-rw-r--r--chip/host/build.mk2
-rw-r--r--chip/host/gpio.c6
-rw-r--r--chip/host/spi_master.c42
-rw-r--r--chip/host/trng.c36
5 files changed, 94 insertions, 1 deletions
diff --git a/board/host/board.c b/board/host/board.c
index 58e895a6f2..086a6f1359 100644
--- a/board/host/board.c
+++ b/board/host/board.c
@@ -14,6 +14,7 @@
#include "motion_sense.h"
#include "motion_lid.h"
#include "power_button.h"
+#include "spi.h"
#include "temp_sensor.h"
#include "timer.h"
#include "util.h"
@@ -58,6 +59,14 @@ const struct i2c_port_t i2c_ports[] = {
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
#endif
+#ifdef CONFIG_SPI_MASTER
+/* SPI devices */
+const struct spi_device_t spi_devices[] = {
+};
+
+const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices);
+#endif
+
#ifdef TEST_BUILD
/* Poor source of entropy for testing purpose. */
int board_get_entropy(void *buffer, int len)
diff --git a/chip/host/build.mk b/chip/host/build.mk
index dc7ba91560..2e62f8f3d0 100644
--- a/chip/host/build.mk
+++ b/chip/host/build.mk
@@ -9,7 +9,7 @@
CORE:=host
chip-y=system.o gpio.o uart.o persistence.o flash.o lpc.o reboot.o i2c.o \
- clock.o
+ clock.o spi_master.o trng.o
chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
chip-$(CONFIG_USB_PD_TCPC)+=usb_pd_phy.o
diff --git a/chip/host/gpio.c b/chip/host/gpio.c
index 343e780bd0..6033902720 100644
--- a/chip/host/gpio.c
+++ b/chip/host/gpio.c
@@ -62,6 +62,12 @@ test_mockable int gpio_enable_interrupt(enum gpio_signal signal)
return EC_SUCCESS;
}
+test_mockable int gpio_disable_interrupt(enum gpio_signal signal)
+{
+ gpio_interrupt_enabled[signal] = 0;
+ return EC_SUCCESS;
+}
+
test_mockable int gpio_clear_pending_interrupt(enum gpio_signal signal)
{
return EC_SUCCESS;
diff --git a/chip/host/spi_master.c b/chip/host/spi_master.c
new file mode 100644
index 0000000000..83bde96163
--- /dev/null
+++ b/chip/host/spi_master.c
@@ -0,0 +1,42 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Dummy Master SPI driver for unit test.
+ */
+
+#include <stdint.h>
+
+#include "common.h"
+#include "gpio.h"
+
+#include "spi.h"
+
+test_mockable int spi_enable(int port, int enable)
+{
+ return EC_SUCCESS;
+}
+
+test_mockable int spi_transaction(const struct spi_device_t *spi_device,
+ const uint8_t *txdata, int txlen,
+ uint8_t *rxdata, int rxlen)
+{
+ return EC_SUCCESS;
+}
+
+test_mockable int spi_transaction_async(const struct spi_device_t *spi_device,
+ const uint8_t *txdata, int txlen,
+ uint8_t *rxdata, int rxlen)
+{
+ return EC_SUCCESS;
+}
+
+test_mockable int spi_transaction_flush(const struct spi_device_t *spi_device)
+{
+ return EC_SUCCESS;
+}
+
+test_mockable int spi_transaction_wait(const struct spi_device_t *spi_device)
+{
+ return EC_SUCCESS;
+}
diff --git a/chip/host/trng.c b/chip/host/trng.c
new file mode 100644
index 0000000000..e27dc9d607
--- /dev/null
+++ b/chip/host/trng.c
@@ -0,0 +1,36 @@
+
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Dummy TRNG driver for unit test.
+ *
+ * Although a TRNG is designed to be anything but predictable,
+ * this implementation strives to be as predictable and defined
+ * as possible to allow reproducing unit tests and fuzzer crashes.
+ */
+
+#include <stdint.h>
+#include <stdlib.h> /* Only valid for host */
+
+#include "common.h"
+
+static unsigned int seed;
+
+test_mockable void init_trng(void)
+{
+ seed = 0;
+ srand(seed);
+}
+
+test_mockable void exit_trng(void)
+{
+}
+
+test_mockable void rand_bytes(void *buffer, size_t len)
+{
+ uint8_t *b, *end;
+
+ for (b = buffer, end = b+len; b != end; b++)
+ *b = (uint8_t)rand_r(&seed);
+}