Skip to content

Commit d697485

Browse files
committed
update
1 parent 904ee32 commit d697485

File tree

10 files changed

+355
-104
lines changed

10 files changed

+355
-104
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[workspace]
22
members = ["any-uart", "hello"]
33
resolver = "3"
4+
exclude = ["dtb"]

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn phys_to_virt(addr: usize) -> *mut u8 {
2525
addr as *mut u8
2626
}
2727

28-
if let Some((mut tx, _rx)) = any_uart::init(NonNull::new(dtb_addr).unwrap(), phys_to_virt) {
28+
if let Some(mut uart) = any_uart::init(NonNull::new(dtb_addr).unwrap(), phys_to_virt) {
29+
let mut tx = uart.tx.take().unwrap();
2930
let _ = tx.write_str_blocking("Hello, world!\n");
3031
}
3132
```
@@ -37,5 +38,5 @@ cargo install ostool
3738
# test with qemu
3839
cargo test -p hello --test test -- --show-output
3940
# test with uboot
40-
cargo test -p hello --test test -- --show-output --uboot
41+
cargo test --release -p hello --test test -- --show-output --uboot
4142
```

any-uart/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
[package]
22
name = "any-uart"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2024"
55
authors = ["周睿 <[email protected]>"]
66
description = "Init early console from device tree, mostly for Arm"
7-
keywords = ["pl011", "no-std", "earlycon", "dtb", "arm"]
7+
keywords = ["pl011", "8250", "no-std", "earlycon", "dtb", "arm"]
88
license = "MIT"
99
categories = ["no-std", "embedded", "hardware-support"]
1010
repository = "https://github.com/rcore-os/any-uart"
1111
readme = "../README.md"
1212

13+
[features]
14+
alloc = []
15+
16+
1317
[dependencies]
1418
fdt-parser = "0.4"
1519
embedded-hal-nb = "1.0"
20+
bitflags = "2.8"

any-uart/src/api.rs

Whitespace-only changes.

any-uart/src/aux_mini.rs

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
1-
use core::sync::atomic::{Ordering, fence};
2-
3-
use crate::{Console, Error, UartData};
1+
use crate::{Console, ErrorKind, IrqEvent, UartData};
42

53
pub struct AuxMini {}
64

75
impl Console for AuxMini {
8-
fn put(uart: UartData, byte: u8) -> Result<(), Error> {
9-
const TXFF: u32 = 1 << 5;
10-
6+
fn put(uart: UartData, byte: u8) -> Result<(), ErrorKind> {
117
unsafe {
12-
let state = uart.reg_u8(0x24) as *const u32;
13-
14-
if state.read_volatile() & TXFF != 0 {
15-
return Err(Error::WouldBlock);
16-
}
17-
fence(Ordering::Release);
188
let data = uart.reg::<u32>(0);
199
data.write_volatile(byte as _);
20-
2110
Ok(())
2211
}
2312
}
2413

25-
fn get(uart: UartData) -> Result<u8, Error> {
26-
const RX_READY: u32 = 1 << 0;
27-
let state = uart.reg_u8(0x24) as *const u32;
28-
29-
// Wait until there is data in the FIFO
14+
fn get(uart: UartData) -> Result<u8, ErrorKind> {
3015
unsafe {
31-
if state.read_volatile() & RX_READY == 0 {
32-
return Err(Error::WouldBlock);
33-
}
3416
let data = uart.reg::<u32>(0);
3517

3618
Ok(data.read_volatile() as _)
3719
}
3820
}
21+
22+
fn set_irq_enable(_uart: UartData, _enable: bool) {
23+
todo!()
24+
}
25+
26+
fn get_irq_enable(_uart: UartData) -> bool {
27+
todo!()
28+
}
29+
30+
fn clean_irq_event(_uart: UartData, _event: IrqEvent) {
31+
todo!()
32+
}
33+
34+
fn can_put(uart: UartData) -> bool {
35+
const TXFF: u32 = 1 << 5;
36+
let state = uart.reg_u8(0x24) as *const u32;
37+
unsafe { state.read_volatile() & TXFF == 0 }
38+
}
39+
40+
fn can_get(uart: UartData) -> bool {
41+
const RX_READY: u32 = 1 << 0;
42+
let state = uart.reg_u8(0x24) as *const u32;
43+
unsafe { state.read_volatile() & RX_READY != 0 }
44+
}
45+
46+
fn get_irq_event(_uart: UartData) -> IrqEvent {
47+
todo!()
48+
}
3949
}

0 commit comments

Comments
 (0)