arm uart: Convert new uart code to classes
* This makes things a little more flexible and the interface to use the uarts cleaner. * May want to make a generic Uart wrapper class in uart.h / uart.cpp and call drivers as needed from there.
This commit is contained in:
@@ -15,32 +15,8 @@
|
||||
#include "uart_pl011.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct uart_info {
|
||||
addr_t base;
|
||||
|
||||
// Pointers to functions based on port type
|
||||
void (*init)(addr_t base);
|
||||
void (*init_early)(void);
|
||||
void (*init_port)(addr_t base, uint baud);
|
||||
int (*putchar)(addr_t base, char c);
|
||||
int (*getchar)(addr_t base, bool wait);
|
||||
void (*flush_tx)(addr_t base);
|
||||
void (*flush_rx)(addr_t base);
|
||||
};
|
||||
|
||||
|
||||
uart_info* uart_create(void);
|
||||
void uart_destroy();
|
||||
addr_t uart_base_port(int port);
|
||||
addr_t uart_debug_port(void);
|
||||
addr_t uart_base_debug();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -24,24 +24,31 @@
|
||||
#define __DEV_UART_8250_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
void uart_8250_init_port(addr_t base, uint baud);
|
||||
void uart_8250_init_early(void);
|
||||
void uart_8250_init(addr_t base);
|
||||
int uart_8250_putchar(addr_t base, char c);
|
||||
int uart_8250_getchar(addr_t base, bool wait);
|
||||
void uart_8250_flush_tx(addr_t base);
|
||||
void uart_8250_flush_rx(addr_t base);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
class Uart8250 {
|
||||
public:
|
||||
Uart8250(addr_t base);
|
||||
~Uart8250();
|
||||
|
||||
void InitEarly();
|
||||
void Init();
|
||||
void InitPort(uint32 baud);
|
||||
|
||||
int PutChar(char c);
|
||||
int GetChar(bool wait);
|
||||
|
||||
void FlushTx();
|
||||
void FlushRx();
|
||||
|
||||
private:
|
||||
void WriteUart(uint32 reg, unsigned char data);
|
||||
unsigned char ReadUart(uint32 reg);
|
||||
|
||||
addr_t fUARTBase;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
#define PL01x_DR 0x00 // Data read or written
|
||||
@@ -86,21 +87,27 @@
|
||||
// TODO: Other PL01x registers + values?
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
void uart_pl011_init_port(addr_t base, uint baud);
|
||||
void uart_pl011_init_early(void);
|
||||
void uart_pl011_init(addr_t base);
|
||||
int uart_pl011_putchar(addr_t base, char c);
|
||||
int uart_pl011_getchar(addr_t base, bool wait);
|
||||
void uart_pl011_flush_tx(addr_t base);
|
||||
void uart_pl011_flush_rx(addr_t base);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
class UartPL011 {
|
||||
public:
|
||||
UartPL011(addr_t base);
|
||||
~UartPL011();
|
||||
|
||||
void InitEarly();
|
||||
void Init();
|
||||
void InitPort(uint32 baud);
|
||||
|
||||
int PutChar(char c);
|
||||
int GetChar(bool wait);
|
||||
|
||||
void FlushTx();
|
||||
void FlushRx();
|
||||
|
||||
private:
|
||||
void WriteUart(uint32 reg, unsigned char data);
|
||||
unsigned char ReadUart(uint32 reg);
|
||||
|
||||
addr_t fUARTBase;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user