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>
This commit is contained in:
Vic (Chun-Ju) Yang
2014-01-06 15:11:20 +08:00
committed by chrome-internal-fetch
parent cdcaf6ed8a
commit a0cb64374a
2 changed files with 25 additions and 11 deletions

View File

@@ -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();
}

View File

@@ -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;