Skip to content

Commit

Permalink
Merge pull request #130 from Placebo27/placebo/ddrinit
Browse files Browse the repository at this point in the history
[board] refactor directory, add init-dram case macro module for 100ask-d1-h-rs
  • Loading branch information
luojia65 committed Sep 24, 2024
2 parents 9161599 + ef24c9f commit 8baa3e5
Show file tree
Hide file tree
Showing 12 changed files with 2,423 additions and 41 deletions.
57 changes: 48 additions & 9 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[workspace]
resolver = "2"
members = ["board/100ask-d1-h-rs", "board/100ask-d1-h-rs/xtask"]
members = [
"board/100ask-d1-h-rs",
"board/100ask-d1-h-rs/macros",
"board/100ask-d1-h-rs/xtask",
]
default-members = ["board/100ask-d1-h-rs/xtask"]
24 changes: 23 additions & 1 deletion board/100ask-d1-h-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,30 @@ allwinner-hal = { git = "https://github.com/rustsbi/allwinner-hal" }
allwinner-rt = { git = "https://github.com/rustsbi/allwinner-hal" }
embedded-hal = "1.0.0"
embedded-io = "0.6.1"
spin = "0.9"
syterkit-macros = { path = "macros" }

[lib]
name = "syterkit_100ask_d1_h"
test = false
bench = false

[[bin]]
name = "syterkit-100ask-d1-h"
name = "hello-world"
test = false
bench = false

[[bin]]
name = "init-dram"
test = false
bench = false

[[bin]]
name = "led-lightup"
test = false
bench = false

[features]
default = ["nezha"]
nezha = []
lichee = []
2 changes: 1 addition & 1 deletion board/100ask-d1-h-rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("cargo:rustc-link-arg=-Tallwinner-rt.ld");
}
}
15 changes: 15 additions & 0 deletions board/100ask-d1-h-rs/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "syterkit-macros"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
quote = "1.0"
proc-macro2 = "1.0"

[dependencies.syn]
version = "1.0"
features = ["extra-traits", "full"]
101 changes: 101 additions & 0 deletions board/100ask-d1-h-rs/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use proc_macro2::Span;
use quote::quote;
use syn::{
parse, parse_macro_input, spanned::Spanned, FnArg, ItemFn, ReturnType, Type, Visibility,
};

use proc_macro::TokenStream;

/// ROM stage function entry.
#[proc_macro_attribute]
pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
let f = parse_macro_input!(input as ItemFn);

// check the function arguments
if f.sig.inputs.len() != 2 {
return parse::Error::new(
f.sig.inputs.last().unwrap().span(),
"`#[entry]` function should include exactly two parameters",
)
.to_compile_error()
.into();
}

for arg in &f.sig.inputs {
match arg {
FnArg::Receiver(_) => {
return parse::Error::new(arg.span(), "invalid argument")
.to_compile_error()
.into();
}
FnArg::Typed(t) => {
if let Type::Path(_p) = &*t.ty {
// empty
} else {
return parse::Error::new(t.ty.span(), "argument type must be a path")
.to_compile_error()
.into();
}
}
}
}

// check the function signature
let valid_signature = f.sig.constness.is_none()
&& f.sig.asyncness.is_none()
&& f.vis == Visibility::Inherited
&& f.sig.abi.is_none()
&& f.sig.generics.params.is_empty()
&& f.sig.generics.where_clause.is_none()
&& f.sig.variadic.is_none()
&& match f.sig.output {
ReturnType::Default => true,
_ => false,
};

if !valid_signature {
return parse::Error::new(
f.span(),
"`#[entry]` function must have signature `[unsafe] fn(p: Peripherals, c: Clocks)`",
)
.to_compile_error()
.into();
}

if !args.is_empty() {
return parse::Error::new(Span::call_site(), "This attribute accepts no arguments")
.to_compile_error()
.into();
}

let attrs = f.attrs;
let unsafety = f.sig.unsafety;
let args = f.sig.inputs;
let stmts = f.block.stmts;
let ret = f.sig.output;

quote!(
#[export_name = "main"]
pub fn main() {
let (p, c) = ::allwinner_rt::__rom_init_params();
let (__p, __uart0, __tx, __rx) = ::syterkit_100ask_d1_h::Peripherals::configure_uart0(p);
unsafe { __syterkit_macros__main(__p, c, __uart0, __tx, __rx) }
}
#[allow(non_snake_case)]
#[inline]
#(#attrs)*
#unsafety fn __syterkit_macros__main(
#args,
__uart0: ::allwinner_rt::soc::d1::UART0,
__tx: ::allwinner_hal::gpio::Function<'static, 'B', 8, 6>,
__rx: ::allwinner_hal::gpio::Function<'static, 'B', 9, 6>
) #ret {
let mut __serial = ::allwinner_hal::uart::Serial::new(__uart0, (__tx, __rx), ::allwinner_hal::uart::Config::default(), &c, &p.ccu);
unsafe {
*::syterkit_100ask_d1_h::CONSOLE.lock() = Some(::syterkit_100ask_d1_h::SyterKitConsole { inner: __serial })
};
#(#stmts)*
}
)
.into()
}
10 changes: 10 additions & 0 deletions board/100ask-d1-h-rs/src/bin/hello-world.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_std]
#![no_main]

use panic_halt as _;
use syterkit_100ask_d1_h::{entry, println, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
println!("Hello World!");
}
11 changes: 11 additions & 0 deletions board/100ask-d1-h-rs/src/bin/init-dram.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![no_std]
#![no_main]
use panic_halt as _;
use syterkit_100ask_d1_h::{entry, mctl, println, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
println!("DDR Init");
let ram_size = mctl::init();
println!("{}M 🐏", ram_size);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![no_std]
#![no_main]
use allwinner_hal::uart::{Config, Serial};
use allwinner_rt::{entry, Clocks, Peripherals};

use embedded_hal::digital::{InputPin, OutputPin};
use embedded_io::Write;
use panic_halt as _;
use syterkit_100ask_d1_h::{entry, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, c: Clocks) {
Expand All @@ -19,10 +18,4 @@ fn main(p: Peripherals, c: Clocks) {
pb0.with_output(|pad| pad.set_high()).unwrap();

let _input_high = pb0.is_high();

let tx = p.gpio.pb8.into_function::<6>();
let rx = p.gpio.pb9.into_function::<6>();
let mut serial = Serial::new(p.uart0, (tx, rx), Config::default(), &c, &p.ccu);

writeln!(serial, "Hello World!").unwrap();
}
Loading

0 comments on commit 8baa3e5

Please sign in to comment.