Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Feb 26, 2022
1 parent 3c71a47 commit e4c2bc0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
26 changes: 26 additions & 0 deletions earth/dev_tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ int tty_write(const char *format, ...)
return r < 0 ? r : fflush(stdout);
}


/* definitions for controlling UART in tty, copied from metal/uart.h */
struct metal_uart;
struct metal_uart_vtable {
void (*init)(struct metal_uart *uart, int baud_rate);
int (*putc)(struct metal_uart *uart, int c);
int (*txready)(struct metal_uart *uart);
int (*getc)(struct metal_uart *uart, int *c);
int (*get_baud_rate)(struct metal_uart *uart);
int (*set_baud_rate)(struct metal_uart *uart, int baud_rate);
};

struct metal_uart {
const struct metal_uart_vtable *vtable;
};

struct metal_uart *metal_uart_get_device(unsigned int device_num);
__inline__ void metal_uart_init(struct metal_uart *uart, int baud_rate) {
uart->vtable->init(uart, baud_rate);
}

__inline__ int metal_uart_getc(struct metal_uart *uart, int *c) {
return uart->vtable->getc(uart, c);
}


int tty_init() {
struct metal_uart* uart;
uart = metal_uart_get_device(0);
Expand Down
35 changes: 0 additions & 35 deletions earth/earth.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,3 @@ int mmu_init();
int mmu_alloc(int* frame_no, int* addr);
int mmu_map(int pid, int page_no, int frame_no, int flag);
int mmu_switch(int pid);


/* definitions for controlling UART in tty, copied from metal/uart.h */
struct metal_uart;
struct metal_uart_vtable {
void (*init)(struct metal_uart *uart, int baud_rate);
int (*putc)(struct metal_uart *uart, int c);
int (*txready)(struct metal_uart *uart);
int (*getc)(struct metal_uart *uart, int *c);
int (*get_baud_rate)(struct metal_uart *uart);
int (*set_baud_rate)(struct metal_uart *uart, int baud_rate);
struct metal_interrupt *(*controller_interrupt)(struct metal_uart *uart);
int (*get_interrupt_id)(struct metal_uart *uart);
int (*tx_interrupt_enable)(struct metal_uart *uart);
int (*tx_interrupt_disable)(struct metal_uart *uart);
int (*rx_interrupt_enable)(struct metal_uart *uart);
int (*rx_interrupt_disable)(struct metal_uart *uart);
int (*set_tx_watermark)(struct metal_uart *uart, size_t length);
size_t (*get_tx_watermark)(struct metal_uart *uart);
int (*set_rx_watermark)(struct metal_uart *uart, size_t length);
size_t (*get_rx_watermark)(struct metal_uart *uart);
};

struct metal_uart {
const struct metal_uart_vtable *vtable;
};

struct metal_uart *metal_uart_get_device(unsigned int device_num);
__inline__ void metal_uart_init(struct metal_uart *uart, int baud_rate) {
uart->vtable->init(uart, baud_rate);
}

__inline__ int metal_uart_getc(struct metal_uart *uart, int *c) {
return uart->vtable->getc(uart, c);
}

0 comments on commit e4c2bc0

Please sign in to comment.