diff options
author | 2018-10-03 20:17:54 +0000 | |
---|---|---|
committer | 2018-10-03 20:17:54 +0000 | |
commit | e3b7357002f0fa739253c78623f825e0e8a7f1ab (patch) | |
tree | 2ca71df33c77a5a431381ac53168add2d9725ee0 /src | |
parent | 062147bf5787c3c624fbf9d2f113afa549628635 (diff) | |
parent | 2cb6f4ba35b40337d6406acf5b565ccd0fb652c0 (diff) | |
download | cortex-m-e3b7357002f0fa739253c78623f825e0e8a7f1ab.tar.gz cortex-m-e3b7357002f0fa739253c78623f825e0e8a7f1ab.tar.zst cortex-m-e3b7357002f0fa739253c78623f825e0e8a7f1ab.zip |
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 <qwerty19106@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/peripheral/scb.rs | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/src/peripheral/scb.rs b/src/peripheral/scb.rs index 939d5a7..e773c9c 100644 --- a/src/peripheral/scb.rs +++ b/src/peripheral/scb.rs @@ -7,9 +7,9 @@ use volatile_register::RW; #[cfg(not(armv6m))] use super::cpuid::CsselrCacheType; #[cfg(not(armv6m))] -use super::CPUID; -#[cfg(not(armv6m))] use super::CBP; +#[cfg(not(armv6m))] +use super::CPUID; use super::SCB; /// Register block @@ -604,13 +604,18 @@ impl SCB { /// Initiate a system reset request to reset the MCU pub fn system_reset(&mut self) -> ! { ::asm::dsb(); - unsafe { self.aircr.modify(|r| - SCB_AIRCR_VECTKEY | // otherwise the write is ignored + unsafe { + self.aircr.modify( + |r| { + SCB_AIRCR_VECTKEY | // otherwise the write is ignored r & SCB_AIRCR_PRIGROUP_MASK | // keep priority group unchanged - SCB_AIRCR_SYSRESETREQ // set the bit - ) }; + SCB_AIRCR_SYSRESETREQ + }, // set the bit + ) + }; ::asm::dsb(); - loop { // wait for the reset + loop { + // wait for the reset ::asm::nop(); // avoid rust-lang/rust#28728 } } @@ -619,6 +624,9 @@ impl SCB { const SCB_ICSR_PENDSVSET: u32 = 1 << 28; const SCB_ICSR_PENDSVCLR: u32 = 1 << 27; +const SCB_ICSR_PENDSTSET: u32 = 1 << 26; +const SCB_ICSR_PENDSTCLR: u32 = 1 << 25; + impl SCB { /// Set the PENDSVSET bit in the ICSR register which will pend the PendSV interrupt pub fn set_pendsv() { @@ -629,9 +637,7 @@ impl SCB { /// Check if PENDSVSET bit in the ICSR register is set meaning PendSV interrupt is pending pub fn is_pendsv_pending() -> bool { - unsafe { - (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSVSET == SCB_ICSR_PENDSVSET - } + unsafe { (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSVSET == SCB_ICSR_PENDSVSET } } /// Set the PENDSVCLR bit in the ICSR register which will clear a pending PendSV interrupt @@ -640,4 +646,26 @@ impl SCB { (*Self::ptr()).icsr.write(SCB_ICSR_PENDSVCLR); } } + + /// Set the PENDSTCLR bit in the ICSR register which will clear a pending SysTick interrupt + #[inline] + pub fn set_pendst() { + unsafe { + (*Self::ptr()).icsr.write(SCB_ICSR_PENDSTSET); + } + } + + /// Check if PENDSTSET bit in the ICSR register is set meaning SysTick interrupt is pending + #[inline] + pub fn is_pendst_pending() -> bool { + unsafe { (*Self::ptr()).icsr.read() & SCB_ICSR_PENDSTSET == SCB_ICSR_PENDSTSET } + } + + /// Set the PENDSTCLR bit in the ICSR register which will clear a pending SysTick interrupt + #[inline] + pub fn clear_pendst() { + unsafe { + (*Self::ptr()).icsr.write(SCB_ICSR_PENDSTCLR); + } + } } |