native,ioe: add uart
This commit is contained in:
parent
81ac173949
commit
493a0650ce
3 changed files with 36 additions and 1 deletions
|
@ -7,6 +7,7 @@ static bool ioe_init_done = false;
|
||||||
void __am_timer_init();
|
void __am_timer_init();
|
||||||
void __am_gpu_init();
|
void __am_gpu_init();
|
||||||
void __am_input_init();
|
void __am_input_init();
|
||||||
|
void __am_uart_init();
|
||||||
void __am_audio_init();
|
void __am_audio_init();
|
||||||
void __am_disk_init();
|
void __am_disk_init();
|
||||||
void __am_input_config(AM_INPUT_CONFIG_T *);
|
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_config(AM_GPU_CONFIG_T *);
|
||||||
void __am_gpu_status(AM_GPU_STATUS_T *);
|
void __am_gpu_status(AM_GPU_STATUS_T *);
|
||||||
void __am_gpu_fbdraw(AM_GPU_FBDRAW_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_config(AM_AUDIO_CONFIG_T *);
|
||||||
void __am_audio_ctrl(AM_AUDIO_CTRL_T *);
|
void __am_audio_ctrl(AM_AUDIO_CTRL_T *);
|
||||||
void __am_audio_status(AM_AUDIO_STATUS_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_config(AM_DISK_CONFIG_T *cfg);
|
||||||
void __am_disk_status(AM_DISK_STATUS_T *stat);
|
void __am_disk_status(AM_DISK_STATUS_T *stat);
|
||||||
void __am_disk_blkio(AM_DISK_BLKIO_T *io);
|
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; }
|
static void __am_net_config (AM_NET_CONFIG_T *cfg) { cfg->present = false; }
|
||||||
|
|
||||||
typedef void (*handler_t)(void *buf);
|
typedef void (*handler_t)(void *buf);
|
||||||
|
@ -38,6 +41,8 @@ static void *lut[128] = {
|
||||||
[AM_GPU_FBDRAW ] = __am_gpu_fbdraw,
|
[AM_GPU_FBDRAW ] = __am_gpu_fbdraw,
|
||||||
[AM_GPU_STATUS ] = __am_gpu_status,
|
[AM_GPU_STATUS ] = __am_gpu_status,
|
||||||
[AM_UART_CONFIG ] = __am_uart_config,
|
[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_CONFIG] = __am_audio_config,
|
||||||
[AM_AUDIO_CTRL ] = __am_audio_ctrl,
|
[AM_AUDIO_CTRL ] = __am_audio_ctrl,
|
||||||
[AM_AUDIO_STATUS] = __am_audio_status,
|
[AM_AUDIO_STATUS] = __am_audio_status,
|
||||||
|
@ -63,6 +68,7 @@ void __am_ioe_init() {
|
||||||
__am_timer_init();
|
__am_timer_init();
|
||||||
__am_gpu_init();
|
__am_gpu_init();
|
||||||
__am_input_init();
|
__am_input_init();
|
||||||
|
__am_uart_init();
|
||||||
__am_audio_init();
|
__am_audio_init();
|
||||||
__am_disk_init();
|
__am_disk_init();
|
||||||
ioe_init_done = true;
|
ioe_init_done = true;
|
||||||
|
|
28
am/src/native/ioe/uart.c
Normal file
28
am/src/native/ioe/uart.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include <am.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ AM_SRCS := native/trm.c \
|
||||||
native/ioe/input.c \
|
native/ioe/input.c \
|
||||||
native/ioe/timer.c \
|
native/ioe/timer.c \
|
||||||
native/ioe/gpu.c \
|
native/ioe/gpu.c \
|
||||||
|
native/ioe/uart.c \
|
||||||
native/ioe/audio.c \
|
native/ioe/audio.c \
|
||||||
native/ioe/disk.c \
|
native/ioe/disk.c \
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue