SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
16c550.h
1/************************************************************************/
9
10#ifndef _16C550_H_
11#define _16C550_H_
12
13#include "types.h"
14#include "mw-msg.h"
15
17#define UART_BASE 0xA130C1
18
20#define UART_CLK 24000000LU
21
24#define UART_BR 1500000LU
25//#define UART_BR 500000LU
26//#define UART_BR 750000LU
27//#define UART_BR 115200
28
30#define UART_TX_FIFO_LEN 16
31
32#define UART_BUFLEN 1460
33
35#define DivWithRounding(dividend, divisor) ((((dividend)*2/(divisor))+1)/2)
37#define UART_DLM_VAL (DivWithRounding(UART_CLK, 16 * UART_BR)>>8)
38//#define UART_DLM_VAL ((UART_CLK/16/UART_BR)>>8)
40#define UART_DLL_VAL (DivWithRounding(UART_CLK, 16 * UART_BR) & 0xFF)
41//#define UART_DLL_VAL ((UART_CLK/16/UART_BR)&0xFF)
42
51#define UART_RHR (*((volatile uint8_t*)(UART_BASE + 0)))
53#define UART_THR (*((volatile uint8_t*)(UART_BASE + 0)))
55#define UART_IER (*((volatile uint8_t*)(UART_BASE + 2)))
57#define UART_FCR (*((volatile uint8_t*)(UART_BASE + 4)))
59#define UART_ISR (*((volatile uint8_t*)(UART_BASE + 4)))
61#define UART_LCR (*((volatile uint8_t*)(UART_BASE + 6)))
63#define UART_MCR (*((volatile uint8_t*)(UART_BASE + 8)))
65#define UART_LSR (*((volatile uint8_t*)(UART_BASE + 10)))
67#define UART_MSR (*((volatile uint8_t*)(UART_BASE + 12)))
69#define UART_SPR (*((volatile uint8_t*)(UART_BASE + 14)))
71#define UART_DLL (*((volatile uint8_t*)(UART_BASE + 0)))
73#define UART_DLM (*((volatile uint8_t*)(UART_BASE + 2)))
75
76
78typedef struct {
79 uint8_t IER;
80 uint8_t FCR;
81 uint8_t LCR;
82 uint8_t MCR;
84
86extern UartShadow sh;
87
92#define UART_MCR__DTR 0x01
93#define UART_MCR__RTS 0x02
94#define UART_MCR__OUT1 0x04
95#define UART_MCR__OUT2 0x08
97
101#define UART_MSR__DSR 0x20
103
104
108#define MW__RESET UART_MCR__DTR
109#define MW__PRG UART_MCR__RTS
110#define MW__DCD UART_MSR__DSR
112
113/************************************************************************/
118void uart_init(void);
119
120/************************************************************************/
124
125/************************************************************************/
132
133/************************************************************************/
139
140/************************************************************************/
146void uart_putc(u8 c);
147
148/************************************************************************/
155
156/************************************************************************/
162#define uart_set(reg, val) do{sh.reg = (val);UART_##reg = (val);}while(0)
163
164/************************************************************************/
170#define uart_get(reg) (sh.reg)
171
172/************************************************************************/
178#define uart_set_bits(reg, val) do{sh.reg |= (val); \
179 UART_##reg = sh.reg;}while(0)
180
181/************************************************************************/
187#define uart_clr_bits(reg, val) do{sh.reg &= ~(val); \
188 UART_##reg = sh.reg;}while(0)
189
190/************************************************************************/
194
195/************************************************************************/
201#define uart_test(reg, val) reg = val;
202//
203// if (reg != val) return MW_ERR
204
205void uart_reset(void);
206
207void uart_start(void);
208
209/************************************************************************/
216void uart_line_sync(void);
217
218#endif /*_16C550_H_*/
219
221
void uart_reset_fifos()
Reset TX and RX FIFOs.
void uart_init(void)
Initializes the driver. The baud rate is set to UART_BR, and the UART FIFOs are enabled....
void uart_line_sync(void)
Sends syncrhonization frame.
bool uart_tx_ready()
Checks if UART transmit register/FIFO is ready. In FIFO mode, up to 16 characters can be loaded each ...
bool uart_is_present(void)
Check if uart is present.
void uart_putc(u8 c)
Sends a character. Please make sure there is room in the transmit register/FIFO by calling uart_rx_re...
u8 uart_getc()
Returns a received character. Please make sure data is available by calling uart_rx_ready() before us...
bool uart_rx_ready()
Checks if UART receive register/FIFO has data available.
UartShadow sh
Uart shadow registers. Do NOT access directly!
MegaWiFi command message definitions.
Structure with the shadow registers.
Definition 16c550.h:78
uint8_t MCR
Modem Control Register.
Definition 16c550.h:82
uint8_t FCR
FIFO Control Register.
Definition 16c550.h:80
uint8_t LCR
Line Control Register.
Definition 16c550.h:81
uint8_t IER
Interrupt Enable Register.
Definition 16c550.h:79
Types definition.
unsigned char u8
Definition types.h:95