11pub use super :: Interrupt ;
22use super :: { BuildError , SvdError , ValidateLevel } ;
33
4+ /// Description of the custom exceptions in the device.
5+ pub mod exception;
6+ pub use exception:: Exception ;
7+
48/// Description of HARTs in the device.
59pub mod hart;
610pub use hart:: Hart ;
@@ -25,6 +29,13 @@ pub struct Riscv {
2529 ) ]
2630 pub core_interrupts : Vec < Interrupt > ,
2731
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+
2839 /// Priority level enumeration values
2940 #[ cfg_attr(
3041 feature = "serde" ,
@@ -44,6 +55,7 @@ pub struct Riscv {
4455#[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
4556pub struct RiscvBuilder {
4657 core_interrupts : Option < Vec < Interrupt > > ,
58+ exceptions : Option < Vec < Exception > > ,
4759 priorities : Option < Vec < Priority > > ,
4860 harts : Option < Vec < Hart > > ,
4961}
@@ -52,6 +64,7 @@ impl From<Riscv> for RiscvBuilder {
5264 fn from ( riscv : Riscv ) -> Self {
5365 Self {
5466 core_interrupts : Some ( riscv. core_interrupts ) ,
67+ exceptions : Some ( riscv. exceptions ) ,
5568 priorities : Some ( riscv. priorities ) ,
5669 harts : Some ( riscv. harts ) ,
5770 }
@@ -65,6 +78,12 @@ impl RiscvBuilder {
6578 self
6679 }
6780
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+
6887 /// Set the priority level enumeration values
6988 pub fn priorities ( mut self , priorities : Vec < Priority > ) -> Self {
7089 self . priorities = Some ( priorities) ;
@@ -80,12 +99,18 @@ impl RiscvBuilder {
8099 /// Validate and build a [`Riscv`].
81100 pub fn build ( self , lvl : ValidateLevel ) -> Result < Riscv , SvdError > {
82101 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+ } ,
89114 harts : self
90115 . harts
91116 . ok_or_else ( || BuildError :: Uninitialized ( "harts" . to_string ( ) ) ) ?,
@@ -110,6 +135,9 @@ impl Riscv {
110135 if let Some ( core_interrupts) = builder. core_interrupts {
111136 self . core_interrupts = core_interrupts;
112137 }
138+ if let Some ( exceptions) = builder. exceptions {
139+ self . exceptions = exceptions;
140+ }
113141 if let Some ( priorities) = builder. priorities {
114142 self . priorities = priorities;
115143 }
@@ -124,12 +152,16 @@ impl Riscv {
124152 /// # Errors
125153 ///
126154 /// - If any of the core interrupt enumeration values are invalid
155+ /// - If any of the exception enumeration values are invalid
127156 /// - If any of the priority level enumeration values are invalid
128157 /// - If any of the HART enumeration values are invalid
129158 pub fn validate ( & self , lvl : ValidateLevel ) -> Result < ( ) , SvdError > {
130159 for ci in & self . core_interrupts {
131160 ci. validate ( lvl) ?;
132161 }
162+ for e in & self . exceptions {
163+ e. validate ( lvl) ?;
164+ }
133165 for p in & self . priorities {
134166 p. validate ( lvl) ?;
135167 }
0 commit comments