blob: a26bb2f33ca8198b3c453b703b625075e5629daf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use crate::cpu::*;
const UART0_DR: u32 = 0x3F201000;
const UART0_FR: u32 = 0x3F201018;
const UART0_CR: u32 = 0x3F201030;
const UART0_ICR: u32 = 0x3F201044;
const UART0_IBRD: u32 = 0x3F201024;
const UART0_FBRD: u32 = 0x3F201028;
const UART0_LCRH: u32 = 0x3F20102C;
const UART0_IMSC: u32 = 0x3F201038;
const GPPUD: u32 = 0x3F200094;
const GPPUDCLK0: u32 = 0x3F200098;
pub fn uart_init() {
store32(UART0_CR, 0);
store32(GPPUD, 0);
spin_for_n_cycles(150);
store32(GPPUDCLK0, (1 << 14) | (1 << 15));
spin_for_n_cycles(150);
store32(GPPUDCLK0, 0);
store32(UART0_ICR, 0x7FF);
store32(UART0_IBRD, 9);
store32(UART0_FBRD, 49);
store32(UART0_LCRH, (1<<4) | (1<<5) | (1<<6));
store32(UART0_IMSC, (1<<1) | (1<<4) | (1<<5) | (1<<6) | (1<<7) | (1<<8) | (1<<9) | (1<<10));
store32(UART0_CR, (1<<0) | (1<<8) | (1<<9));
}
pub fn write_char(ch: u8) {
while load32(UART0_FR) & 0x20 != 0 {
nop();
}
store32(UART0_DR, ch as u32);
}
|