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 2 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
28 changes: 28 additions & 0 deletions src/peripheral/scb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,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 @@ -640,4 +643,29 @@ 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_systick(&mut self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about calling this set_systick when just above we have set_pendsv. Really this one should be set_pendst or we need to rename both (causing a major version change). Same applies to is_systick_pending and clear_systick_pending. I'd prefer just using pendst here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, set_pendst looks better.

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_systick_pending() -> bool {
unsafe {
(*Self::ptr()).icsr.read() & SCB_ICSR_PENDSTSET == SCB_ICSR_PENDSTSET
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: One blank line too many.

/// Set the PENDSTCLR bit in the ICSR register which will clear a pending SysTick interrupt
#[inline]
pub fn clear_systick_pending(&mut self) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this operation require exclusive access to SCB (&mut self)? With clear_pendsv() it wasn't required because setting just the PENDSTCLR bit doesn't affect any other bits in the register, so you can't have data races.

Copy link
Contributor Author

@qwerty19106 qwerty19106 Oct 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exclusive access to SCB is not required. I think that clear_systick_pending needs to change analogiously.

unsafe {
(*Self::ptr()).icsr.write(SCB_ICSR_PENDSTCLR);
}
}
}