Skip to content

Commit 19d3534

Browse files
committed
Added Pending SV (Service Call) and SysTick flags
1 parent 062147b commit 19d3534

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/peripheral/scb.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ impl VectActive {
297297
mod scb_consts {
298298
pub const SCB_CCR_IC_MASK: u32 = (1 << 17);
299299
pub const SCB_CCR_DC_MASK: u32 = (1 << 16);
300+
301+
pub const SCB_ICSR_PENDSVSET_MASK: u32 = 1 << 28;
302+
pub const SCB_ICSR_PENDSVCLR_MASK: u32 = 1 << 27;
303+
304+
pub const SCB_ICSR_PENDSTSET_MASK: u32 = 1 << 26;
305+
pub const SCB_ICSR_PENDSTCLR_MASK: u32 = 1 << 25;
300306
}
301307

302308
#[cfg(not(armv6m))]
@@ -576,6 +582,56 @@ impl SCB {
576582
::asm::dsb();
577583
::asm::isb();
578584
}
585+
586+
/// Pending SV Flag
587+
///
588+
/// return true if PendSV exception is pending, otherwise false
589+
#[inline]
590+
pub fn is_pendsv() -> bool {
591+
// NOTE(unsafe) atomic read with no side effects
592+
unsafe { (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSVSET_MASK != 0 }
593+
}
594+
595+
/// Changes PendSV exception state to pending Set Pending SV Flag
596+
#[inline]
597+
pub fn set_pendsv(&mut self) {
598+
unsafe {
599+
self.icsr.write(SCB_ICSR_PENDSVSET_MASK);
600+
}
601+
}
602+
603+
/// Removes the pending state from the PendSV exception
604+
#[inline]
605+
pub fn clear_pendsv(&mut self) {
606+
unsafe {
607+
self.icsr.write(SCB_ICSR_PENDSVCLR_MASK);
608+
}
609+
}
610+
611+
/// ICSR SysTick flag
612+
///
613+
/// return true if SysTick exception is pending, otherwise false
614+
#[inline]
615+
pub fn is_systick_pending() -> bool {
616+
// NOTE(unsafe) atomic read with no side effects
617+
unsafe { (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSTSET_MASK != 0 }
618+
}
619+
620+
/// Changes SysTick exception state to pending
621+
#[inline]
622+
pub fn set_systick_pending(&mut self) {
623+
unsafe {
624+
self.icsr.write(SCB_ICSR_PENDSTSET_MASK);
625+
}
626+
}
627+
628+
/// Removes the pending state from the SysTick exception
629+
#[inline]
630+
pub fn clear_systick_pending(&mut self) {
631+
unsafe {
632+
self.icsr.write(SCB_ICSR_PENDSTCLR_MASK);
633+
}
634+
}
579635
}
580636

581637
const SCB_SCR_SLEEPDEEP: u32 = 0x1 << 2;

0 commit comments

Comments
 (0)