Skip to content

Add SysTick flags #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions src/peripheral/scb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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() {
Expand All @@ -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
Expand All @@ -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);
}
}
}