summaryrefslogtreecommitdiff
path: root/chip/host
diff options
context:
space:
mode:
Diffstat (limited to 'chip/host')
-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
4 files changed, 85 insertions, 1 deletions
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);
+}