diff options
author | 2022-05-17 18:39:30 +0000 | |
---|---|---|
committer | 2022-05-17 18:39:30 +0000 | |
commit | 1a24c725d2c6889b68056f4804b588611271c1fd (patch) | |
tree | f81f8a85fe9331216a3203542d2ee6da3f4d90a3 /macros | |
parent | 6896749f7b8d35a53e359cf90758e2790ad95b19 (diff) | |
parent | cd445165c50a46042e0cf17eb0081879f9cf4d52 (diff) | |
download | rtic-1a24c725d2c6889b68056f4804b588611271c1fd.tar.gz rtic-1a24c725d2c6889b68056f4804b588611271c1fd.tar.zst rtic-1a24c725d2c6889b68056f4804b588611271c1fd.zip |
Merge #641
641: More ergonomic error from static asserts messages r=perlindgren a=korken89
Closes #634
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'macros')
-rw-r--r-- | macros/src/codegen/pre_init.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 91c99912..ae2fd050 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -49,8 +49,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream Some((&task.args.priority, &task.args.binds)) } })) { + let es = format!( + "Maximum priority used by interrupt vector '{}' is more than supported by hardware", + name + ); // Compile time assert that this priority is supported by the device - stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];)); + stmts.push(quote!( + const _: () = assert!((1 << #nvic_prio_bits) >= #priority as usize, #es); + )); stmts.push(quote!( core.NVIC.set_priority( @@ -72,8 +78,14 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream None } }) { + let es = format!( + "Maximum priority used by interrupt vector '{}' is more than supported by hardware", + name + ); // Compile time assert that this priority is supported by the device - stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];)); + stmts.push(quote!( + const _: () = assert!((1 << #nvic_prio_bits) >= #priority as usize, #es); + )); stmts.push(quote!(core.SCB.set_priority( rtic::export::SystemHandler::#name, @@ -90,8 +102,15 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream }; let binds = &monotonic.args.binds; + let name = &monotonic.ident; + let es = format!( + "Maximum priority used by monotonic '{}' is more than supported by hardware", + name + ); // Compile time assert that this priority is supported by the device - stmts.push(quote!(let _ = [(); ((1 << #nvic_prio_bits) - #priority as usize)];)); + stmts.push(quote!( + const _: () = assert!((1 << #nvic_prio_bits) >= #priority as usize, #es); + )); let mono_type = &monotonic.ty; |