summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
Diffstat (limited to 'chip')
-rw-r--r--chip/host/build.mk12
-rw-r--r--chip/host/config.h51
-rw-r--r--chip/host/gpio.c24
-rw-r--r--chip/host/keyboard_raw.c46
-rw-r--r--chip/host/system.c74
-rw-r--r--chip/host/uart.c86
6 files changed, 293 insertions, 0 deletions
diff --git a/chip/host/build.mk b/chip/host/build.mk
new file mode 100644
index 0000000000..ddcbefdb0b
--- /dev/null
+++ b/chip/host/build.mk
@@ -0,0 +1,12 @@
+# -*- makefile -*-
+# Copyright (c) 2013 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.
+#
+# emulator specific files build
+#
+
+CORE:=host
+
+chip-y=system.o gpio.o uart.o
+chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
diff --git a/chip/host/config.h b/chip/host/config.h
new file mode 100644
index 0000000000..7f2df4e467
--- /dev/null
+++ b/chip/host/config.h
@@ -0,0 +1,51 @@
+/* Copyright (c) 2013 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.
+ */
+
+/* Chip config header file */
+
+#ifndef __CONFIG_H
+#define __CONFIG_H
+
+/* Memory mapping */
+#define CONFIG_FLASH_BASE 0x08000000
+#define CONFIG_FLASH_PHYSICAL_SIZE 0x00020000
+#define CONFIG_FLASH_SIZE CONFIG_FLASH_PHYSICAL_SIZE
+#define CONFIG_FLASH_BANK_SIZE 0x1000
+#define CONFIG_FLASH_ERASE_SIZE 0x0400 /* erase bank size */
+#define CONFIG_FLASH_WRITE_SIZE 0x0002 /* minimum write size */
+#define CONFIG_RAM_BASE 0x20000000
+#define CONFIG_RAM_SIZE 0x00002000
+
+/* Size of one firmware image in flash */
+#define CONFIG_FW_IMAGE_SIZE (64 * 1024)
+
+#define CONFIG_FW_RO_OFF 0
+#define CONFIG_FW_RO_SIZE (CONFIG_FW_IMAGE_SIZE \
+ - CONFIG_SECTION_FLASH_PSTATE_SIZE)
+#define CONFIG_FW_RW_OFF CONFIG_FW_IMAGE_SIZE
+#define CONFIG_FW_RW_SIZE CONFIG_FW_IMAGE_SIZE
+
+#define CONFIG_SECTION_RO_OFF CONFIG_FW_RO_OFF
+#define CONFIG_SECTION_RO_SIZE CONFIG_FW_RO_SIZE
+#define CONFIG_SECTION_RW_OFF CONFIG_FW_RW_OFF
+#define CONFIG_SECTION_RW_SIZE CONFIG_FW_RW_SIZE
+#define CONFIG_SECTION_WP_RO_OFF CONFIG_FW_RO_OFF
+#define CONFIG_SECTION_WP_RO_SIZE CONFIG_FW_IMAGE_SIZE
+
+/*
+ * Put this after RO to give RW more space. This also makes RO write protect
+ * region contiguous.
+ */
+#define CONFIG_SECTION_FLASH_PSTATE_SIZE (1 * CONFIG_FLASH_BANK_SIZE)
+#define CONFIG_SECTION_FLASH_PSTATE_OFF CONFIG_FW_RO_OFF + CONFIG_FW_RO_SIZE
+
+/* Maximum number of deferrable functions */
+#define DEFERRABLE_MAX_COUNT 8
+
+/* Interval between HOOK_TICK notifications */
+#define HOOK_TICK_INTERVAL (250 * MSEC)
+
+#endif /* __CONFIG_H */
+
diff --git a/chip/host/gpio.c b/chip/host/gpio.c
new file mode 100644
index 0000000000..03cfaa4aed
--- /dev/null
+++ b/chip/host/gpio.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 2013 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.
+ */
+
+/* GPIO module for emulator */
+
+#include "common.h"
+#include "gpio.h"
+
+test_mockable void gpio_pre_init(void)
+{
+ /* Nothing */
+}
+
+test_mockable int gpio_get_level(enum gpio_signal signal)
+{
+ return 0;
+}
+
+test_mockable void gpio_set_level(enum gpio_signal signal, int value)
+{
+ /* Nothing */
+}
diff --git a/chip/host/keyboard_raw.c b/chip/host/keyboard_raw.c
new file mode 100644
index 0000000000..561a72aafa
--- /dev/null
+++ b/chip/host/keyboard_raw.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2013 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.
+ */
+
+/* Raw keyboard I/O layer for emulator */
+
+#include "common.h"
+#include "keyboard_config.h"
+#include "keyboard_raw.h"
+#include "keyboard_scan.h"
+#include "task.h"
+#include "util.h"
+
+test_mockable void keyboard_raw_init(void)
+{
+ /* Nothing */
+}
+
+test_mockable void keyboard_raw_task_start(void)
+{
+ /* Nothing */
+}
+
+test_mockable void keyboard_raw_drive_column(int out)
+{
+ /* Nothing */
+}
+
+test_mockable int keyboard_raw_read_rows(void)
+{
+ /* Nothing pressed */
+ return 0;
+}
+
+test_mockable void keyboard_raw_enable_interrupt(int enable)
+{
+ /* Nothing */
+}
+
+test_mockable void keyboard_raw_gpio_interrupt(enum gpio_signal signal)
+{
+#ifdef HAS_TASK_KEYSCAN
+ task_wake(TASK_ID_KEYSCAN);
+#endif
+}
diff --git a/chip/host/system.c b/chip/host/system.c
new file mode 100644
index 0000000000..50da8db9c0
--- /dev/null
+++ b/chip/host/system.c
@@ -0,0 +1,74 @@
+/* Copyright (c) 2013 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.
+ */
+
+/* System module for emulator */
+
+#include <stdlib.h>
+
+#include "host_test.h"
+#include "system.h"
+
+#define SHARED_MEM_SIZE 512 /* bytes */
+char __shared_mem_buf[SHARED_MEM_SIZE];
+
+test_mockable void system_reset(int flags)
+{
+ exit(EXIT_CODE_RESET | flags);
+}
+
+test_mockable void system_hibernate(uint32_t seconds, uint32_t microseconds)
+{
+ exit(EXIT_CODE_HIBERNATE);
+}
+
+test_mockable int system_is_locked(void)
+{
+ return 0;
+}
+
+test_mockable int system_jumped_to_this_image(void)
+{
+ return 0;
+}
+
+test_mockable uint32_t system_get_reset_flags(void)
+{
+ return RESET_FLAG_POWER_ON;
+}
+
+const char *system_get_chip_vendor(void)
+{
+ return "chromeos";
+}
+
+const char *system_get_chip_name(void)
+{
+ return "emu";
+}
+
+const char *system_get_chip_revision(void)
+{
+ return "";
+}
+
+int system_get_vbnvcontext(uint8_t *block)
+{
+ return EC_ERROR_UNIMPLEMENTED;
+}
+
+int system_set_vbnvcontext(const uint8_t *block)
+{
+ return EC_ERROR_UNIMPLEMENTED;
+}
+
+int system_usable_ram_end(void)
+{
+ return (int)(__shared_mem_buf + SHARED_MEM_SIZE);
+}
+
+void system_pre_init(void)
+{
+ /* Nothing */
+}
diff --git a/chip/host/uart.c b/chip/host/uart.c
new file mode 100644
index 0000000000..cbae79974b
--- /dev/null
+++ b/chip/host/uart.c
@@ -0,0 +1,86 @@
+/* Copyright (c) 2013 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.
+ */
+
+/* UART driver for emulator */
+
+#include <stdio.h>
+
+#include "board.h"
+#include "config.h"
+#include "task.h"
+#include "uart.h"
+
+static int stopped;
+static int int_disabled;
+static int init_done;
+
+static void trigger_interrupt(void)
+{
+ if (!int_disabled)
+ uart_process();
+}
+
+int uart_init_done(void)
+{
+ return init_done;
+}
+
+void uart_tx_start(void)
+{
+ stopped = 0;
+ trigger_interrupt();
+}
+
+void uart_tx_stop(void)
+{
+ stopped = 1;
+}
+
+int uart_tx_stopped(void)
+{
+ return stopped;
+}
+
+void uart_tx_flush(void)
+{
+ /* Nothing */
+}
+
+int uart_tx_ready(void)
+{
+ return 1;
+}
+
+int uart_rx_available(void)
+{
+ return 0;
+}
+
+void uart_write_char(char c)
+{
+ printf("%c", c);
+ fflush(stdout);
+}
+
+int uart_read_char(void)
+{
+ /* Should never be called for now */
+ return 0;
+}
+
+void uart_disable_interrupt(void)
+{
+ int_disabled = 1;
+}
+
+void uart_enable_interrupt(void)
+{
+ int_disabled = 0;
+}
+
+void uart_init(void)
+{
+ init_done = 1;
+}