1- use crate :: { svd:: Peripheral , util, Config } ;
1+ use crate :: { svd:: Peripheral , util, Settings } ;
22use anyhow:: Result ;
33use log:: debug;
44use proc_macro2:: TokenStream ;
55use quote:: quote;
66use std:: { collections:: HashMap , fmt:: Write , str:: FromStr } ;
77
8- pub fn is_riscv_peripheral ( p : & Peripheral , c : & Config ) -> bool {
8+ pub fn is_riscv_peripheral ( p : & Peripheral , s : & Settings ) -> bool {
99 // TODO cleaner implementation of this
10- match & c . riscv_config {
10+ match & s . riscv_config {
1111 Some ( c) => {
1212 c. clint . as_ref ( ) . is_some_and ( |clint| clint. name == p. name )
1313 || c. plic . as_ref ( ) . is_some_and ( |plic| plic. name == p. name )
@@ -20,16 +20,16 @@ pub fn is_riscv_peripheral(p: &Peripheral, c: &Config) -> bool {
2020pub fn render (
2121 peripherals : & [ Peripheral ] ,
2222 device_x : & mut String ,
23- config : & Config ,
23+ settings : & Settings ,
2424) -> Result < TokenStream > {
2525 let mut mod_items = TokenStream :: new ( ) ;
2626
27- if let Some ( c) = config . riscv_config . as_ref ( ) {
28- if let Some ( i ) = c. core_interrupts . as_ref ( ) {
27+ if let Some ( c) = settings . riscv_config . as_ref ( ) {
28+ if ! c. core_interrupts . is_empty ( ) {
2929 debug ! ( "Rendering target-specific core interrupts" ) ;
3030 writeln ! ( device_x, "/* Core interrupt sources and trap handlers */" ) ?;
3131 let mut interrupts = vec ! [ ] ;
32- for interrupt in i . iter ( ) {
32+ for interrupt in c . core_interrupts . iter ( ) {
3333 let name = TokenStream :: from_str ( & interrupt. name ) . unwrap ( ) ;
3434 let value = TokenStream :: from_str ( & format ! ( "{}" , interrupt. value) ) . unwrap ( ) ;
3535 let description = interrupt. description ( ) ;
@@ -58,11 +58,11 @@ pub fn render(
5858 mod_items. extend ( quote ! { pub use riscv:: interrupt:: Interrupt as CoreInterrupt ; } ) ;
5959 }
6060
61- if let Some ( e ) = c. exceptions . as_ref ( ) {
61+ if ! c. exceptions . is_empty ( ) {
6262 debug ! ( "Rendering target-specific exceptions" ) ;
6363 writeln ! ( device_x, "/* Exception sources */" ) ?;
6464 let mut exceptions = vec ! [ ] ;
65- for exception in e . iter ( ) {
65+ for exception in c . exceptions . iter ( ) {
6666 let name = TokenStream :: from_str ( & exception. name ) . unwrap ( ) ;
6767 let value = TokenStream :: from_str ( & format ! ( "{}" , exception. value) ) . unwrap ( ) ;
6868 let description = exception. description ( ) ;
@@ -87,9 +87,9 @@ pub fn render(
8787 mod_items. extend ( quote ! { pub use riscv:: interrupt:: Exception ; } ) ;
8888 }
8989
90- if let Some ( p ) = c. priorities . as_ref ( ) {
90+ if ! c. priorities . is_empty ( ) {
9191 debug ! ( "Rendering target-specific priority levels" ) ;
92- let priorities = p . iter ( ) . map ( |priority| {
92+ let priorities = c . priorities . iter ( ) . map ( |priority| {
9393 let name = TokenStream :: from_str ( & priority. name ) . unwrap ( ) ;
9494 let value = TokenStream :: from_str ( & format ! ( "{}" , priority. value) ) . unwrap ( ) ;
9595 let description = priority. description ( ) ;
@@ -109,9 +109,9 @@ pub fn render(
109109 } ) ;
110110 }
111111
112- if let Some ( h ) = c. harts . as_ref ( ) {
112+ if ! c. harts . is_empty ( ) {
113113 debug ! ( "Rendering target-specific HART IDs" ) ;
114- let harts = h . iter ( ) . map ( |hart| {
114+ let harts = c . harts . iter ( ) . map ( |hart| {
115115 let name = TokenStream :: from_str ( & hart. name ) . unwrap ( ) ;
116116 let value = TokenStream :: from_str ( & format ! ( "{}" , hart. value) ) . unwrap ( ) ;
117117 let description = hart. description ( ) ;
@@ -205,13 +205,14 @@ pub fn render(
205205 }
206206
207207 let mut riscv_peripherals = TokenStream :: new ( ) ;
208- if let Some ( c) = & config. riscv_config {
209- let harts = match & c. harts {
210- Some ( harts) => harts
208+ if let Some ( c) = & settings. riscv_config {
209+ let harts = match c. harts . is_empty ( ) {
210+ true => vec ! [ ] ,
211+ false => c
212+ . harts
211213 . iter ( )
212214 . map ( |h| ( TokenStream :: from_str ( & h. name ) . unwrap ( ) , h. value ) )
213215 . collect :: < Vec < _ > > ( ) ,
214- None => vec ! [ ] ,
215216 } ;
216217 if let Some ( clint) = & c. clint {
217218 let p = peripherals. iter ( ) . find ( |& p| p. name == clint. name ) . unwrap ( ) ;
@@ -286,7 +287,7 @@ pub fn render(
286287 fn plic_handler( ) {
287288 let claim = crate :: PLIC :: #ctx. claim( ) ;
288289 if let Some ( s) = claim. claim:: <ExternalInterrupt >( ) {
289- unsafe { _dispatch_core_interrupt ( s. number( ) ) }
290+ unsafe { _dispatch_external_interrupt ( s. number( ) ) }
290291 claim. complete( s) ;
291292 }
292293 }
0 commit comments