-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from Placebo27/placebo/ddrinit
[board] refactor directory, add init-dram case macro module for 100ask-d1-h-rs
- Loading branch information
Showing
12 changed files
with
2,423 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
println!("cargo:rustc-link-arg=-Tallwinner-rt.ld"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.