@@ -108,6 +108,19 @@ impl<P: Plic> PLIC<P> {
108
108
unsafe { CTX :: new ( hart_id. number ( ) as _ ) }
109
109
}
110
110
111
+ /// Returns the PLIC HART context for HART 0.
112
+ ///
113
+ /// # Note
114
+ ///
115
+ /// According to the RISC-V specification, HART 0 is mandatory.
116
+ /// Thus, this function is specially useful in single-HART mode, where HART 0 is the only HART available.
117
+ /// In multi-HART mode, it is recommended to use [`PLIC::ctx`] or [`PLIC::ctx_mhartid`] instead.
118
+ #[ inline]
119
+ pub const fn ctx0 ( self ) -> CTX < P > {
120
+ // SAFETY: HART 0 is mandatory
121
+ unsafe { CTX :: new ( 0 ) }
122
+ }
123
+
111
124
/// Returns the PLIC HART context for the current HART.
112
125
///
113
126
/// # Note
@@ -146,7 +159,7 @@ impl<P: Plic> CTX<P> {
146
159
///
147
160
/// The context number must be valid for the target device.
148
161
#[ inline]
149
- pub ( crate ) unsafe fn new ( context : u16 ) -> Self {
162
+ const unsafe fn new ( context : u16 ) -> Self {
150
163
Self {
151
164
context : context as _ ,
152
165
_marker : core:: marker:: PhantomData ,
@@ -195,8 +208,8 @@ pub(crate) mod test {
195
208
crate :: plic_codegen!(
196
209
PLIC ,
197
210
base 0x0C00_0000 ,
198
- harts [ HartId :: H0 => 0 , HartId :: H1 => 1 , HartId :: H2 => 2 ]
199
- ) ;
211
+ harts [ HartId :: H1 => 1 , HartId :: H2 => 2 ]
212
+ ) ; // We skip HART 0 to get advantage of const ctx0 method
200
213
201
214
let plic = PLIC :: new ( ) ;
202
215
let priorities = plic. priorities ( ) ;
0 commit comments