@@ -198,10 +198,41 @@ __force_inline static void __mem_fence_release(void) {
198198// #endif
199199}
200200
201- /* ! \brief Save and disable interrupts
201+ /* ! \brief Explicitly disable interrupts on the calling core
202202 * \ingroup hardware_sync
203+ */
204+ __force_inline static uint32_t disable_interrupts (void ) {
205+ #ifdef __riscv
206+ __compiler_memory_barrier ();
207+ riscv_clear_csr (mstatus, 8 );
208+ __compiler_memory_barrier ();
209+ #else
210+ pico_default_asm_volatile ( " cpsid i" :: " memory" );
211+ #endif
212+ }
213+
214+ /* ! \brief Explicitly enable interrupts on the calling core
215+ * \ingroup hardware_sync
216+ */
217+ __force_inline static uint32_t enable_interrupts (void ) {
218+ #ifdef __riscv
219+ __compiler_memory_barrier ();
220+ riscv_set_csr (mstatus, 8 );
221+ __compiler_memory_barrier ();
222+ #else
223+ pico_default_asm_volatile ( " cpsie i" :: " memory" );
224+ #endif
225+ }
226+
227+ /* ! \brief Disable interrupts on the calling core, returning the previous interrupt state
228+ * \ingroup hardware_sync
229+ *
230+ * This method is commonly paired with \ref restore_interrupts_from_disabled() to temporarily
231+ * disable interrupts around a piece of code, without needing to care whether interrupts
232+ * were previously enabled
203233 *
204- * \return The prior interrupt enable status for restoration later via restore_interrupts()
234+ * \return The prior interrupt enable status for restoration later via \ref restore_interrupts_from_disabled()
235+ * or \ref restore_interrupts()
205236 */
206237__force_inline static uint32_t save_and_disable_interrupts (void ) {
207238 uint32_t status;
@@ -219,7 +250,7 @@ __force_inline static uint32_t save_and_disable_interrupts(void) {
219250 return status;
220251}
221252
222- /* ! \brief Restore interrupts to a specified state
253+ /* ! \brief Restore interrupts to a specified state on the calling core
223254 * \ingroup hardware_sync
224255 *
225256 * \param status Previous interrupt status from save_and_disable_interrupts()
@@ -238,10 +269,10 @@ __force_inline static void restore_interrupts(uint32_t status) {
238269#endif
239270}
240271
241- /* ! \brief Restore interrupts to a specified state with restricted transitions
272+ /* ! \brief Restore interrupts to a specified state on the calling core with restricted transitions
242273 * \ingroup hardware_sync
243274 *
244- * This method should only be used when the interrupt state is known to be disabled,
275+ * This method should only be used when the current interrupt state is known to be disabled,
245276 * e.g. when paired with \ref save_and_disable_interrupts()
246277 *
247278 * \param status Previous interrupt status from save_and_disable_interrupts()
0 commit comments