1
1
pub use super :: Interrupt ;
2
2
use super :: { BuildError , SvdError , ValidateLevel } ;
3
3
4
+ /// Description of the custom exceptions in the device.
5
+ pub mod exception;
6
+ pub use exception:: Exception ;
7
+
4
8
/// Description of HARTs in the device.
5
9
pub mod hart;
6
10
pub use hart:: Hart ;
@@ -25,6 +29,13 @@ pub struct Riscv {
25
29
) ]
26
30
pub core_interrupts : Vec < Interrupt > ,
27
31
32
+ /// Exception enumeration values
33
+ #[ cfg_attr(
34
+ feature = "serde" ,
35
+ serde( default , skip_serializing_if = "Vec::is_empty" )
36
+ ) ]
37
+ pub exceptions : Vec < Exception > ,
38
+
28
39
/// Priority level enumeration values
29
40
#[ cfg_attr(
30
41
feature = "serde" ,
@@ -44,6 +55,7 @@ pub struct Riscv {
44
55
#[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
45
56
pub struct RiscvBuilder {
46
57
core_interrupts : Option < Vec < Interrupt > > ,
58
+ exceptions : Option < Vec < Exception > > ,
47
59
priorities : Option < Vec < Priority > > ,
48
60
harts : Option < Vec < Hart > > ,
49
61
}
@@ -52,6 +64,7 @@ impl From<Riscv> for RiscvBuilder {
52
64
fn from ( riscv : Riscv ) -> Self {
53
65
Self {
54
66
core_interrupts : Some ( riscv. core_interrupts ) ,
67
+ exceptions : Some ( riscv. exceptions ) ,
55
68
priorities : Some ( riscv. priorities ) ,
56
69
harts : Some ( riscv. harts ) ,
57
70
}
@@ -65,6 +78,12 @@ impl RiscvBuilder {
65
78
self
66
79
}
67
80
81
+ /// Set the exception enumeration values
82
+ pub fn exceptions ( mut self , exceptions : Vec < Exception > ) -> Self {
83
+ self . exceptions = Some ( exceptions) ;
84
+ self
85
+ }
86
+
68
87
/// Set the priority level enumeration values
69
88
pub fn priorities ( mut self , priorities : Vec < Priority > ) -> Self {
70
89
self . priorities = Some ( priorities) ;
@@ -80,12 +99,18 @@ impl RiscvBuilder {
80
99
/// Validate and build a [`Riscv`].
81
100
pub fn build ( self , lvl : ValidateLevel ) -> Result < Riscv , SvdError > {
82
101
let riscv = Riscv {
83
- core_interrupts : self
84
- . core_interrupts
85
- . ok_or_else ( || BuildError :: Uninitialized ( "core_interrupts" . to_string ( ) ) ) ?,
86
- priorities : self
87
- . priorities
88
- . ok_or_else ( || BuildError :: Uninitialized ( "priorities" . to_string ( ) ) ) ?,
102
+ core_interrupts : match self . core_interrupts {
103
+ Some ( core_interrupts) => core_interrupts,
104
+ None => Vec :: new ( ) ,
105
+ } ,
106
+ exceptions : match self . exceptions {
107
+ Some ( exceptions) => exceptions,
108
+ None => Vec :: new ( ) ,
109
+ } ,
110
+ priorities : match self . priorities {
111
+ Some ( priorities) => priorities,
112
+ None => Vec :: new ( ) ,
113
+ } ,
89
114
harts : self
90
115
. harts
91
116
. ok_or_else ( || BuildError :: Uninitialized ( "harts" . to_string ( ) ) ) ?,
@@ -110,6 +135,9 @@ impl Riscv {
110
135
if let Some ( core_interrupts) = builder. core_interrupts {
111
136
self . core_interrupts = core_interrupts;
112
137
}
138
+ if let Some ( exceptions) = builder. exceptions {
139
+ self . exceptions = exceptions;
140
+ }
113
141
if let Some ( priorities) = builder. priorities {
114
142
self . priorities = priorities;
115
143
}
@@ -124,12 +152,16 @@ impl Riscv {
124
152
/// # Errors
125
153
///
126
154
/// - If any of the core interrupt enumeration values are invalid
155
+ /// - If any of the exception enumeration values are invalid
127
156
/// - If any of the priority level enumeration values are invalid
128
157
/// - If any of the HART enumeration values are invalid
129
158
pub fn validate ( & self , lvl : ValidateLevel ) -> Result < ( ) , SvdError > {
130
159
for ci in & self . core_interrupts {
131
160
ci. validate ( lvl) ?;
132
161
}
162
+ for e in & self . exceptions {
163
+ e. validate ( lvl) ?;
164
+ }
133
165
for p in & self . priorities {
134
166
p. validate ( lvl) ?;
135
167
}
0 commit comments