1
- use crate :: { svd:: Peripheral , util, Config } ;
1
+ use crate :: { svd:: Peripheral , util, Settings } ;
2
2
use anyhow:: Result ;
3
3
use log:: debug;
4
4
use proc_macro2:: TokenStream ;
5
5
use quote:: quote;
6
6
use std:: { collections:: HashMap , fmt:: Write , str:: FromStr } ;
7
7
8
- pub fn is_riscv_peripheral ( p : & Peripheral , c : & Config ) -> bool {
8
+ pub fn is_riscv_peripheral ( p : & Peripheral , s : & Settings ) -> bool {
9
9
// TODO cleaner implementation of this
10
- match & c . riscv_config {
10
+ match & s . riscv_config {
11
11
Some ( c) => {
12
12
c. clint . as_ref ( ) . is_some_and ( |clint| clint. name == p. name )
13
13
|| 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 {
20
20
pub fn render (
21
21
peripherals : & [ Peripheral ] ,
22
22
device_x : & mut String ,
23
- config : & Config ,
23
+ settings : & Settings ,
24
24
) -> Result < TokenStream > {
25
25
let mut mod_items = TokenStream :: new ( ) ;
26
26
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 ( ) {
29
29
debug ! ( "Rendering target-specific core interrupts" ) ;
30
30
writeln ! ( device_x, "/* Core interrupt sources and trap handlers */" ) ?;
31
31
let mut interrupts = vec ! [ ] ;
32
- for interrupt in i . iter ( ) {
32
+ for interrupt in c . core_interrupts . iter ( ) {
33
33
let name = TokenStream :: from_str ( & interrupt. name ) . unwrap ( ) ;
34
34
let value = TokenStream :: from_str ( & format ! ( "{}" , interrupt. value) ) . unwrap ( ) ;
35
35
let description = interrupt. description ( ) ;
@@ -58,11 +58,11 @@ pub fn render(
58
58
mod_items. extend ( quote ! { pub use riscv:: interrupt:: Interrupt as CoreInterrupt ; } ) ;
59
59
}
60
60
61
- if let Some ( e ) = c. exceptions . as_ref ( ) {
61
+ if ! c. exceptions . is_empty ( ) {
62
62
debug ! ( "Rendering target-specific exceptions" ) ;
63
63
writeln ! ( device_x, "/* Exception sources */" ) ?;
64
64
let mut exceptions = vec ! [ ] ;
65
- for exception in e . iter ( ) {
65
+ for exception in c . exceptions . iter ( ) {
66
66
let name = TokenStream :: from_str ( & exception. name ) . unwrap ( ) ;
67
67
let value = TokenStream :: from_str ( & format ! ( "{}" , exception. value) ) . unwrap ( ) ;
68
68
let description = exception. description ( ) ;
@@ -87,9 +87,9 @@ pub fn render(
87
87
mod_items. extend ( quote ! { pub use riscv:: interrupt:: Exception ; } ) ;
88
88
}
89
89
90
- if let Some ( p ) = c. priorities . as_ref ( ) {
90
+ if ! c. priorities . is_empty ( ) {
91
91
debug ! ( "Rendering target-specific priority levels" ) ;
92
- let priorities = p . iter ( ) . map ( |priority| {
92
+ let priorities = c . priorities . iter ( ) . map ( |priority| {
93
93
let name = TokenStream :: from_str ( & priority. name ) . unwrap ( ) ;
94
94
let value = TokenStream :: from_str ( & format ! ( "{}" , priority. value) ) . unwrap ( ) ;
95
95
let description = priority. description ( ) ;
@@ -109,9 +109,9 @@ pub fn render(
109
109
} ) ;
110
110
}
111
111
112
- if let Some ( h ) = c. harts . as_ref ( ) {
112
+ if ! c. harts . is_empty ( ) {
113
113
debug ! ( "Rendering target-specific HART IDs" ) ;
114
- let harts = h . iter ( ) . map ( |hart| {
114
+ let harts = c . harts . iter ( ) . map ( |hart| {
115
115
let name = TokenStream :: from_str ( & hart. name ) . unwrap ( ) ;
116
116
let value = TokenStream :: from_str ( & format ! ( "{}" , hart. value) ) . unwrap ( ) ;
117
117
let description = hart. description ( ) ;
@@ -205,13 +205,14 @@ pub fn render(
205
205
}
206
206
207
207
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
211
213
. iter ( )
212
214
. map ( |h| ( TokenStream :: from_str ( & h. name ) . unwrap ( ) , h. value ) )
213
215
. collect :: < Vec < _ > > ( ) ,
214
- None => vec ! [ ] ,
215
216
} ;
216
217
if let Some ( clint) = & c. clint {
217
218
let p = peripherals. iter ( ) . find ( |& p| p. name == clint. name ) . unwrap ( ) ;
@@ -286,7 +287,7 @@ pub fn render(
286
287
fn plic_handler( ) {
287
288
let claim = crate :: PLIC :: #ctx. claim( ) ;
288
289
if let Some ( s) = claim. claim:: <ExternalInterrupt >( ) {
289
- unsafe { _dispatch_core_interrupt ( s. number( ) ) }
290
+ unsafe { _dispatch_external_interrupt ( s. number( ) ) }
290
291
claim. complete( s) ;
291
292
}
292
293
}
0 commit comments