diff --git a/am/src/native/ioe.c b/am/src/native/ioe.c index 0cd02c7..273e67e 100644 --- a/am/src/native/ioe.c +++ b/am/src/native/ioe.c @@ -7,6 +7,7 @@ static bool ioe_init_done = false; void __am_timer_init(); void __am_gpu_init(); void __am_input_init(); +void __am_uart_init(); void __am_audio_init(); void __am_disk_init(); void __am_input_config(AM_INPUT_CONFIG_T *); @@ -17,6 +18,9 @@ void __am_input_keybrd(AM_INPUT_KEYBRD_T *); void __am_gpu_config(AM_GPU_CONFIG_T *); void __am_gpu_status(AM_GPU_STATUS_T *); void __am_gpu_fbdraw(AM_GPU_FBDRAW_T *); +void __am_uart_config(AM_UART_CONFIG_T *); +void __am_uart_tx(AM_UART_TX_T *); +void __am_uart_rx(AM_UART_RX_T *); void __am_audio_config(AM_AUDIO_CONFIG_T *); void __am_audio_ctrl(AM_AUDIO_CTRL_T *); void __am_audio_status(AM_AUDIO_STATUS_T *); @@ -24,7 +28,6 @@ void __am_audio_play(AM_AUDIO_PLAY_T *); void __am_disk_config(AM_DISK_CONFIG_T *cfg); void __am_disk_status(AM_DISK_STATUS_T *stat); void __am_disk_blkio(AM_DISK_BLKIO_T *io); -static void __am_uart_config(AM_UART_CONFIG_T *cfg) { cfg->present = false; } static void __am_net_config (AM_NET_CONFIG_T *cfg) { cfg->present = false; } typedef void (*handler_t)(void *buf); @@ -38,6 +41,8 @@ static void *lut[128] = { [AM_GPU_FBDRAW ] = __am_gpu_fbdraw, [AM_GPU_STATUS ] = __am_gpu_status, [AM_UART_CONFIG ] = __am_uart_config, + [AM_UART_TX ] = __am_uart_tx, + [AM_UART_RX ] = __am_uart_rx, [AM_AUDIO_CONFIG] = __am_audio_config, [AM_AUDIO_CTRL ] = __am_audio_ctrl, [AM_AUDIO_STATUS] = __am_audio_status, @@ -63,6 +68,7 @@ void __am_ioe_init() { __am_timer_init(); __am_gpu_init(); __am_input_init(); + __am_uart_init(); __am_audio_init(); __am_disk_init(); ioe_init_done = true; diff --git a/am/src/native/ioe/uart.c b/am/src/native/ioe/uart.c new file mode 100644 index 0000000..88a262c --- /dev/null +++ b/am/src/native/ioe/uart.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include + +void __am_uart_init() { + int ret = fcntl(STDIN_FILENO, F_GETFL); + assert(ret != -1); + int flag = ret | O_NONBLOCK; + ret = fcntl(STDIN_FILENO, F_SETFL, flag); + assert(ret != -1); +} + +void __am_uart_config(AM_UART_CONFIG_T *cfg) { + cfg->present = true; +} + +void __am_uart_tx(AM_UART_TX_T *uart) { + putchar(uart->data); +} + +void __am_uart_rx(AM_UART_RX_T *uart) { + int ret = fgetc(stdin); + if (ret == EOF) ret = -1; + uart->data = ret; +} diff --git a/scripts/native.mk b/scripts/native.mk index 1a8fd03..e6ebe04 100644 --- a/scripts/native.mk +++ b/scripts/native.mk @@ -8,6 +8,7 @@ AM_SRCS := native/trm.c \ native/ioe/input.c \ native/ioe/timer.c \ native/ioe/gpu.c \ + native/ioe/uart.c \ native/ioe/audio.c \ native/ioe/disk.c \