summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic (Chun-Ju) Yang <victoryang@chromium.org>2014-01-06 15:11:20 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-01-06 12:40:51 +0000
commita0cb64374a629dbaf0415b0abbbb7882c46fe80b (patch)
treedcda285fecdafbec045f021a789eb62ec1d3acc4
parentcdcaf6ed8a1d18bdedb72fb665263c0dbff0ac8e (diff)
downloadchrome-ec-a0cb64374a629dbaf0415b0abbbb7882c46fe80b.tar.gz
Process emulator UART events in interrupt context
Currently emulator UART input/output are processed in various context, including UART thread, individual tasks, and tests. By moving the processing to interrupt context, the way it works resemble real chips more. Also, this provides a cleaner cut between emulated UART device and UART processing code. BUG=chrome-os-partner:23804 TEST=make buildall BRANCH=None Change-Id: I58127e66f4058a68d37be9029e9ddbbd798381c6 Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/181590 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--chip/host/uart.c27
-rw-r--r--core/host/task.c9
2 files changed, 25 insertions, 11 deletions
diff --git a/chip/host/uart.c b/chip/host/uart.c
index ce8310f171..b39232833b 100644
--- a/chip/host/uart.c
+++ b/chip/host/uart.c
@@ -13,6 +13,7 @@
#include "common.h"
#include "queue.h"
#include "task.h"
+#include "test_util.h"
#include "uart.h"
#include "util.h"
@@ -66,16 +67,20 @@ const char *test_get_captured_console(void)
return (const char *)capture_buf;
}
+static void uart_interrupt(void)
+{
+ uart_process_input();
+ uart_process_output();
+}
+
static void trigger_interrupt(void)
{
- /*
- * TODO(crosbug.com/p/23804): Check global interrupt status when we
- * have interrupt support.
- */
- if (!int_disabled) {
- uart_process_input();
- uart_process_output();
- }
+ if (int_disabled)
+ return;
+ if (task_start_called())
+ task_trigger_test_interrupt(uart_interrupt);
+ else
+ uart_interrupt();
}
int uart_init_done(void)
@@ -177,9 +182,9 @@ void *uart_monitor_stdin(void *d)
}
tcsetattr(0, TCSANOW, &org_settings);
/*
- * TODO(crosbug.com/p/23804): Trigger emulated interrupt when
- * we have interrupt support. Also, we will need a condition
- * variable to indicate the character has been read.
+ * Trigger emulated interrupt to process input. Keyboard
+ * input while interrupt handler runs is queued by the
+ * system.
*/
trigger_interrupt();
}
diff --git a/core/host/task.c b/core/host/task.c
index 23d16bd802..bb4b073997 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -13,6 +13,7 @@
#include "atomic.h"
#include "common.h"
+#include "console.h"
#include "task.h"
#include "task_id.h"
#include "test_util.h"
@@ -35,6 +36,7 @@ static struct emu_task_t tasks[TASK_ID_COUNT];
static pthread_cond_t scheduler_cond;
static pthread_mutex_t run_lock;
static task_id_t running_task_id;
+static int task_started;
static sem_t interrupt_sem;
static pthread_mutex_t interrupt_lock;
@@ -280,11 +282,18 @@ static int fast_forward(void)
}
}
+int task_start_called(void)
+{
+ return task_started;
+}
+
void task_scheduler(void)
{
int i;
timestamp_t now;
+ task_started = 1;
+
while (1) {
now = get_time();
i = TASK_ID_COUNT - 1;