Skip to content

Commit e3b7357

Browse files
Merge #116
116: Add SysTick flags r=adamgreig a=qwerty19106 CMSIS core headers contains SCB_ICSR_PENDSVSET_*** and SCB_ICSR_PENDSTSET_*** definitions, which I need in my projects. In CMSIS it is used to check, set and clear this flags (rtx_core_cm.h and os_systick.c). I suggest adding it to scb.rs. I put initial commit, but I need help to add compiler barriers where its are needed. For details, see CMSIS: [CMSIS_5/CMSIS/Core/Include/core_cm3.h](https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/Core/Include/core_cm3.h) (or other core_cm{X}.h) [CMSIS_5/CMSIS/RTOS2/RTX/Source/rtx_core_cm.h)](https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/RTOS2/RTX/Source/rtx_core_cm.h) [CMSIS_5/CMSIS/RTOS2/Source/os_systick.c)](https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/RTOS2/Source/os_systick.c) FIX: I have not seen that PENDSV is already added. I review PENDST code to be like PENDSV. Co-authored-by: qwerty19106 <[email protected]>
2 parents 062147b + 2cb6f4b commit e3b7357

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/peripheral/scb.rs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use volatile_register::RW;
77
#[cfg(not(armv6m))]
88
use super::cpuid::CsselrCacheType;
99
#[cfg(not(armv6m))]
10-
use super::CPUID;
11-
#[cfg(not(armv6m))]
1210
use super::CBP;
11+
#[cfg(not(armv6m))]
12+
use super::CPUID;
1313
use super::SCB;
1414

1515
/// Register block
@@ -604,13 +604,18 @@ impl SCB {
604604
/// Initiate a system reset request to reset the MCU
605605
pub fn system_reset(&mut self) -> ! {
606606
::asm::dsb();
607-
unsafe { self.aircr.modify(|r|
608-
SCB_AIRCR_VECTKEY | // otherwise the write is ignored
607+
unsafe {
608+
self.aircr.modify(
609+
|r| {
610+
SCB_AIRCR_VECTKEY | // otherwise the write is ignored
609611
r & SCB_AIRCR_PRIGROUP_MASK | // keep priority group unchanged
610-
SCB_AIRCR_SYSRESETREQ // set the bit
611-
) };
612+
SCB_AIRCR_SYSRESETREQ
613+
}, // set the bit
614+
)
615+
};
612616
::asm::dsb();
613-
loop { // wait for the reset
617+
loop {
618+
// wait for the reset
614619
::asm::nop(); // avoid rust-lang/rust#28728
615620
}
616621
}
@@ -619,6 +624,9 @@ impl SCB {
619624
const SCB_ICSR_PENDSVSET: u32 = 1 << 28;
620625
const SCB_ICSR_PENDSVCLR: u32 = 1 << 27;
621626

627+
const SCB_ICSR_PENDSTSET: u32 = 1 << 26;
628+
const SCB_ICSR_PENDSTCLR: u32 = 1 << 25;
629+
622630
impl SCB {
623631
/// Set the PENDSVSET bit in the ICSR register which will pend the PendSV interrupt
624632
pub fn set_pendsv() {
@@ -629,9 +637,7 @@ impl SCB {
629637

630638
/// Check if PENDSVSET bit in the ICSR register is set meaning PendSV interrupt is pending
631639
pub fn is_pendsv_pending() -> bool {
632-
unsafe {
633-
(*Self::ptr()).icsr.read() & SCB_ICSR_PENDSVSET == SCB_ICSR_PENDSVSET
634-
}
640+
unsafe { (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSVSET == SCB_ICSR_PENDSVSET }
635641
}
636642

637643
/// Set the PENDSVCLR bit in the ICSR register which will clear a pending PendSV interrupt
@@ -640,4 +646,26 @@ impl SCB {
640646
(*Self::ptr()).icsr.write(SCB_ICSR_PENDSVCLR);
641647
}
642648
}
649+
650+
/// Set the PENDSTCLR bit in the ICSR register which will clear a pending SysTick interrupt
651+
#[inline]
652+
pub fn set_pendst() {
653+
unsafe {
654+
(*Self::ptr()).icsr.write(SCB_ICSR_PENDSTSET);
655+
}
656+
}
657+
658+
/// Check if PENDSTSET bit in the ICSR register is set meaning SysTick interrupt is pending
659+
#[inline]
660+
pub fn is_pendst_pending() -> bool {
661+
unsafe { (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSTSET == SCB_ICSR_PENDSTSET }
662+
}
663+
664+
/// Set the PENDSTCLR bit in the ICSR register which will clear a pending SysTick interrupt
665+
#[inline]
666+
pub fn clear_pendst() {
667+
unsafe {
668+
(*Self::ptr()).icsr.write(SCB_ICSR_PENDSTCLR);
669+
}
670+
}
643671
}

0 commit comments

Comments
 (0)