summaryrefslogtreecommitdiff
path: root/cros_ec/chip_stub/ec_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'cros_ec/chip_stub/ec_uart.c')
-rw-r--r--cros_ec/chip_stub/ec_uart.c41
1 files changed, 36 insertions, 5 deletions
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;
}