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
15#if (MODULE_MEGAWIFI == 1 && MODULE_EVERDRIVE == 0)
16
18#define UART_BASE 0xA130C1
19
21#define UART_CLK 24000000LU
22
25#define UART_BR 1500000LU
26//#define UART_BR 500000LU
27//#define UART_BR 750000LU
28//#define UART_BR 115200
29
31#define UART_TX_FIFO_LEN 16
32
34#define DivWithRounding(dividend, divisor) ((((dividend)*2/(divisor))+1)/2)
36#define UART_DLM_VAL (DivWithRounding(UART_CLK, 16 * UART_BR)>>8)
37//#define UART_DLM_VAL ((UART_CLK/16/UART_BR)>>8)
39#define UART_DLL_VAL (DivWithRounding(UART_CLK, 16 * UART_BR) & 0xFF)
40//#define UART_DLL_VAL ((UART_CLK/16/UART_BR)&0xFF)
41
50#define UART_RHR (*((volatile uint8_t*)(UART_BASE + 0)))
52#define UART_THR (*((volatile uint8_t*)(UART_BASE + 0)))
54#define UART_IER (*((volatile uint8_t*)(UART_BASE + 2)))
56#define UART_FCR (*((volatile uint8_t*)(UART_BASE + 4)))
58#define UART_ISR (*((volatile uint8_t*)(UART_BASE + 4)))
60#define UART_LCR (*((volatile uint8_t*)(UART_BASE + 6)))
62#define UART_MCR (*((volatile uint8_t*)(UART_BASE + 8)))
64#define UART_LSR (*((volatile uint8_t*)(UART_BASE + 10)))
66#define UART_MSR (*((volatile uint8_t*)(UART_BASE + 12)))
68#define UART_SPR (*((volatile uint8_t*)(UART_BASE + 14)))
70#define UART_DLL (*((volatile uint8_t*)(UART_BASE + 0)))
72#define UART_DLM (*((volatile uint8_t*)(UART_BASE + 2)))
74
76typedef struct {
77 uint8_t IER;
78 uint8_t FCR;
79 uint8_t LCR;
80 uint8_t MCR;
81} UartShadow;
82
84extern UartShadow sh;
85
90#define UART_MCR__DTR 0x01
91#define UART_MCR__RTS 0x02
92#define UART_MCR__OUT1 0x04
93#define UART_MCR__OUT2 0x08
95
99#define UART_MSR__DSR 0x20
101
102/************************************************************************/
107void uart_init(void);
108
109/************************************************************************/
115#define uart_tx_ready() (UART_LSR & 0x20)
116
117/************************************************************************/
122#define uart_rx_ready() (UART_LSR & 0x01)
123
124/************************************************************************/
130#define uart_putc(c) do{UART_RHR = (c);}while(0);
131
132/************************************************************************/
138#define uart_getc() (UART_RHR)
139
140/************************************************************************/
146#define uart_set(reg, val) do{sh.reg = (val);UART_##reg = (val);}while(0)
147
148/************************************************************************/
154#define uart_get(reg) (sh.reg)
155
156/************************************************************************/
162#define uart_set_bits(reg, val) do{sh.reg |= (val); \
163 UART_##reg = sh.reg;}while(0)
164
165/************************************************************************/
171#define uart_clr_bits(reg, val) do{sh.reg &= ~(val); \
172 UART_##reg = sh.reg;}while(0)
173
174/************************************************************************/
177#define uart_reset_fifos() uart_set_bits(FCR, 0x07)
178
179/************************************************************************/
185#define uart_test(reg, val) reg = val; \
186 if (reg != val) return MW_ERR
187
188#endif // MODULE_MEGAWIFI
189
190#endif /*_16C550_H_*/
191
193
Types definition.