@@ -108,6 +108,19 @@ impl<P: Plic> PLIC<P> {
108108 unsafe { CTX :: new ( hart_id. number ( ) as _ ) }
109109 }
110110
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+
111124 /// Returns the PLIC HART context for the current HART.
112125 ///
113126 /// # Note
@@ -146,7 +159,7 @@ impl<P: Plic> CTX<P> {
146159 ///
147160 /// The context number must be valid for the target device.
148161 #[ inline]
149- pub ( crate ) unsafe fn new ( context : u16 ) -> Self {
162+ const unsafe fn new ( context : u16 ) -> Self {
150163 Self {
151164 context : context as _ ,
152165 _marker : core:: marker:: PhantomData ,
@@ -195,8 +208,8 @@ pub(crate) mod test {
195208 crate :: plic_codegen!(
196209 PLIC ,
197210 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
200213
201214 let plic = PLIC :: new ( ) ;
202215 let priorities = plic. priorities ( ) ;
0 commit comments