summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2011-10-24 10:46:26 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2011-10-24 10:46:26 -0700
commit7860a64e420b61c28d101bf5998ae1381094d78f (patch)
treec3f52dc8a72b9ac86e056f98bb0caad43701668b
parent059b4334719577821e2cac0c2bfa90ca4552d622 (diff)
parent85e3256d32395b951089e59cb2f5bdc51a8b1ab4 (diff)
downloadchrome-ec-7860a64e420b61c28d101bf5998ae1381094d78f.tar.gz
Merge "Start implementing host-side EcUart module"
-rw-r--r--cros_ec/Makefile4
-rw-r--r--cros_ec/chip_stub/ec_uart.c41
-rw-r--r--cros_ec/test/ec_os_test.c33
3 files changed, 54 insertions, 24 deletions
diff --git a/cros_ec/Makefile b/cros_ec/Makefile
index f34db019c3..dce7c20dbf 100644
--- a/cros_ec/Makefile
+++ b/cros_ec/Makefile
@@ -18,9 +18,9 @@ all: $(TESTPROGS)
clean:
rm -f $(TESTPROGS)
-ec_os_test: test/ec_os_test.c chip_stub/ec_os.c
+ec_os_test: test/ec_os_test.c chip_stub/ec_os.c chip_stub/ec_uart.c
gcc $(CFLAGS) -o ec_os_test \
- test/ec_os_test.c chip_stub/ec_os.c
+ test/ec_os_test.c chip_stub/ec_os.c chip_stub/ec_uart.c
fakemain: test/fakemain.c $(LIB_SRCS) $(STUB_SRCS)
gcc $(CFLAGS) -o fakemain test/fakemain.c \
diff --git a/cros_ec/chip_stub/ec_uart.c b/cros_ec/chip_stub/ec_uart.c
index f76691169a..744e964f4a 100644
--- a/cros_ec/chip_stub/ec_uart.c
+++ b/cros_ec/chip_stub/ec_uart.c
@@ -3,39 +3,70 @@
* found in the LICENSE file.
*/
-/* UART module for Chrome EC, empty implementation */
+/* UART module for Chrome EC, emulated/linux implementation */
+
+#include <stdio.h>
+#include <stdarg.h>
#include "ec_uart.h"
+static void (*uart_input_callback)(void) = NULL;
+static int uart_input_callback_char = -1;
+static FILE *uart_stream = NULL;
+
+
+EcError EcUartInit(void) {
+ uart_stream = stdout;
+ return EC_SUCCESS;
+}
+
+
EcError EcUartPrintf(const char* format, ...) {
- return EC_ERROR_UNIMPLEMENTED;
+ va_list args;
+
+ va_start(args, format);
+ /* TODO; for now, printf() will be pretty close */
+ /* TODO: fixed-sizes for integers won't work because int is 64-bit
+ * by default on desktop Linux. I don't distinguish between %d
+ * (int) and %d (int32_t). */
+ /* TODO: support for pointers (%p) */
+ vfprintf(uart_stream, format, args);
+ va_end(args);
+
+ return EC_SUCCESS;
}
EcError EcUartPuts(const char* outstr) {
- return EC_ERROR_UNIMPLEMENTED;
+ fputs(outstr, uart_stream);
+ return EC_SUCCESS;
}
-void EcUartFlush(void) {
+void EcUartFlushOutput(void) {
+ fflush(uart_stream);
}
void EcUartFlushInput(void) {
+ /* TODO */
}
int EcUartPeek(int c) {
+ /* TODO */
return -1;
}
int EcUartGets(char* dest, int size) {
- *dest = 0;
+ /* TODO */
return 0;
}
void EcUartRegisterHasInputCallback(UartHasInputCallback callback, int c) {
+ uart_input_callback = callback;
+ uart_input_callback_char = c;
}
diff --git a/cros_ec/test/ec_os_test.c b/cros_ec/test/ec_os_test.c
index f34ccec4d3..6eda412b04 100644
--- a/cros_ec/test/ec_os_test.c
+++ b/cros_ec/test/ec_os_test.c
@@ -5,10 +5,8 @@
/* Basic test for EcOs objects */
-#include <stdio.h>
-#include <stdint.h>
-
#include "ec_os.h"
+#include "ec_uart.h"
EcTask t1, t2, t3, t4;
EcSemaphore sem;
@@ -24,7 +22,7 @@ void Thread1(void* arg) {
EcSemaphoreWait(&sem, EC_OS_FOREVER);
/* Do some work */
EcTaskSleep(5000);
- fprintf(stderr, "Hello from thread1: %s\n", (char*)arg);
+ EcUartPrintf("Hello from thread1: %s\n", (char*)arg);
EcSemaphorePost(&sem);
/* Two rapid posts to SWI, to see that they merge */
@@ -35,7 +33,7 @@ void Thread1(void* arg) {
}
EcTaskSleep(500000);
- fprintf(stderr, "Goodbye from thread1\n");
+ EcUartPrintf("Goodbye from thread1\n");
}
@@ -46,7 +44,7 @@ void Thread2(void* arg) {
EcSemaphoreWait(&sem, EC_OS_FOREVER);
/* Do some work */
EcTaskSleep(5000);
- fprintf(stderr, "Hello from thread2: %s\n", (char*)arg);
+ EcUartPrintf("Hello from thread2: %s\n", (char*)arg);
EcSemaphorePost(&sem);
/* Post events */
@@ -57,7 +55,7 @@ void Thread2(void* arg) {
}
EcTaskSleep(50000);
- fprintf(stderr, "Goodbye from thread2\n");
+ EcUartPrintf("Goodbye from thread2\n");
}
@@ -68,43 +66,44 @@ void Thread3(void* arg) {
/* Wait for any of the bits to be set */
EcEventWaitAny(&ev1, 0x1c, &got_bits, EC_OS_FOREVER);
- fprintf(stderr, "Event thread 3 got bits: 0x%x\n", got_bits);
+ EcUartPrintf("Event thread 3 got bits: 0x%x\n", got_bits);
}
- fprintf(stderr, "Goodbye from event thread 3\n");
+ EcUartPrintf("Goodbye from event thread 3\n");
}
void Thread4(void* arg) {
/* Wait on event bit from creation and a few posted bits. */
EcEventWaitAll(&ev2, 0x10e, EC_OS_FOREVER);
- fprintf(stderr, "Event thread 4 got all bits\n");
- fprintf(stderr, "Goodbye from event thread 4\n");
+ EcUartPrintf("Event thread 4 got all bits\n");
+ EcUartPrintf("Goodbye from event thread 4\n");
}
void SwiFunc(void* arg, uint32_t bits) {
- fprintf(stderr, "Hello from SWI with bits=0x%x\n", bits);
+ EcUartPrintf("Hello from SWI with bits=0x%x\n", bits);
}
void TimerFunc(void* arg) {
- fprintf(stderr, "Hello from timer: %s\n", (char*)arg);
+ EcUartPrintf("Hello from timer: %s\n", (char*)arg);
/* Start the one-shot timer. */
EcTimerStart(&timer2);
}
void OneTimerFunc(void* arg) {
- fprintf(stderr, "Hello from one-shot timer: %s\n", (char*)arg);
+ EcUartPrintf("Hello from one-shot timer: %s\n", (char*)arg);
/* Stop the periodic timer */
EcTimerStop(&timer1);
}
int main(void) {
- fprintf(stderr, "Hello, world.\n");
-
EcOsInit();
+ EcUartInit();
+
+ EcUartPrintf("Hello, world.\n");
EcTaskCreate(&t1, EC_TASK_PRIORITY_DEFAULT, 0, Thread1, "Foo1");
EcTaskCreate(&t2, EC_TASK_PRIORITY_DEFAULT, 0, Thread2, "Foo2");
@@ -121,7 +120,7 @@ int main(void) {
EcEventCreate(&ev1, 0);
EcEventCreate(&ev2, 0x100);
- fprintf(stderr, "EcOs objects created.\n");
+ EcUartPrintf("EcOs objects created.\n");
EcOsStart();