Skip to content

Commit

Permalink
Merge pull request #136 from luojia65/luojia65/mctl
Browse files Browse the repository at this point in the history
[rust] rearrange mctl driver, move clock init into #[entry], code cleanup
  • Loading branch information
luojia65 authored Oct 3, 2024
2 parents e6ad6aa + 0b15258 commit e7a058d
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 218 deletions.
44 changes: 27 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions board/100ask-d1-h-rs/src/bin/init-dram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use panic_halt as _;
use syterkit::{entry, mctl, println, Clocks, Peripherals};

#[entry]
fn main(_p: Peripherals, _c: Clocks) {
fn main(p: Peripherals, _c: Clocks) {
println!("DDR Init");
let ram_size = mctl::init();
let ram_size = mctl::init(&p.ccu);
println!("{}M 🐏", ram_size);
}
4 changes: 2 additions & 2 deletions board/100ask-d1-h-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
use panic_halt as _;
use syterkit::{clock_dump, entry, println, show_banner, Clocks, Peripherals};

#[entry]
#[entry] // This macro would initialize system clocks.
fn main(p: Peripherals, _c: Clocks) {
// Display the bootloader banner.
show_banner();

// Initialize the DRAM.
let dram_size = syterkit::mctl::init();
let dram_size = syterkit::mctl::init(&p.ccu);
println!("DRAM size: {}M 🐏", dram_size);

// Dump information about the system clocks.
Expand Down
1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ embedded-hal = "1.0.0"
embedded-io = "0.6.1"
spin = "0.9"
syterkit-macros = { path = "macros" }
embedded-time = "0.12.1"

[build-dependencies]
rustc_version = "0.4.1"
Expand Down
13 changes: 8 additions & 5 deletions rust/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
quote!(
#[export_name = "main"]
pub fn main() {
let (allwinner_rt_p, c) = ::syterkit::allwinner_rt::__rom_init_params();
let (allwinner_rt_p, _allwinner_rt_c) = ::syterkit::allwinner_rt::__rom_init_params();
let c = ::syterkit::__clock_init(&allwinner_rt_p.ccu);
let (p, uart0, tx, rx) = ::syterkit::Peripherals::configure_uart0(allwinner_rt_p);
let mut serial = ::syterkit::allwinner_hal::uart::Serial::new(uart0, (tx, rx), ::syterkit::allwinner_hal::uart::Config::default(), &c, &p.ccu);
unsafe {
*::syterkit::CONSOLE.lock() = Some(::syterkit::SyterKitConsole { inner: serial })
};
let serial = ::syterkit::allwinner_hal::uart::Serial::new(uart0, (tx, rx), ::syterkit::allwinner_hal::uart::Config::default(), &c, &p.ccu);
let (serial_out, stdin) = serial.split();
{
*::syterkit::STDOUT.lock() = Some(::syterkit::SyterKitStdoutInner { inner: serial_out });
*::syterkit::STDIN.lock() = Some(::syterkit::SyterKitStdinInner { inner: stdin });
}
unsafe { __syterkit_macros__main(p, c) }
}
#[allow(non_snake_case)]
Expand Down
26 changes: 5 additions & 21 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
#![no_std]
use allwinner_hal::{gpio::Function, uart::Serial};
use allwinner_rt::soc::d1::UART0;
use embedded_io::Write;
use spin::Mutex;

#[macro_use]
mod macros;

pub mod mctl;
pub mod soc;
mod stdio;

pub use allwinner_hal::ccu::Clocks;
pub use syterkit_macros::entry;

#[cfg(feature = "sun20iw1")]
pub use soc::sun20iw1::{clock_dump, Peripherals};
pub use soc::sun20iw1::{__clock_init, clock_dump, Peripherals};

/// Print SyterKit banner.
pub fn show_banner() {
Expand All @@ -35,24 +32,11 @@ pub fn show_banner() {
println!();
}

#[doc(hidden)]
pub static CONSOLE: Mutex<Option<SyterKitConsole<'static>>> = Mutex::new(None);

#[doc(hidden)]
pub struct SyterKitConsole<'a> {
pub inner: Serial<UART0, 0, (Function<'a, 'B', 8, 6>, Function<'a, 'B', 9, 6>)>,
}

unsafe impl<'a> Send for SyterKitConsole<'a> {}
pub use stdio::{stdin, stdout, Stdin, Stdout};

// macro internal, used in `print` and `println` macros in `macros.rs`.
// macro internal code, used by `print` and `println`.
#[doc(hidden)]
#[inline]
pub fn _print(args: core::fmt::Arguments) {
if let Some(serial) = &mut *CONSOLE.lock() {
serial.inner.write_fmt(args).unwrap();
}
}
pub use stdio::_print;

// macro internal code, used in `entry` proc macro.
#[doc(hidden)]
Expand Down
Loading

0 comments on commit e7a058d

Please sign in to comment.