Skip to content
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

Move deferred call mechanism to kernel #935

Merged
merged 3 commits into from May 26, 2018
Merged

Move deferred call mechanism to kernel #935

merged 3 commits into from May 26, 2018

Conversation

bradjc
Copy link
Contributor

@bradjc bradjc commented May 16, 2018

Pull Request Overview

The DeferredCall struct allows chip peripherals to register callbacks with the chip scheduler if the hardware doesn't provide interrupts. It is currently only used in the sam4l flash driver, which needs to generate a read_done callback even though there is no interrupt for reading flash.

This PR moves that module to the kernel crate so that multiple chips can use it. This is in support of the nrf52 flash driver which will need to use it. It also updates the SAM4L to use the moved version.

Testing Strategy

This pull request was tested by making sure that hail compiles.

TODO or Help Wanted

n/a

Documentation Updated

  • Kernel: Updated the relevant files in /docs, or no updates are required.
  • Userland: Added/updated the application README, if needed.

Formatting

  • Ran make formatall.

@bradjc bradjc added kernel P-Upkeep This a relatively minor change, or one that is limited in scope, and requires less scrutiny. labels May 16, 2018
@bradjc bradjc requested a review from alevy May 16, 2018 01:49
static DEFERRED_CALL: AtomicUsize = AtomicUsize::new(0);
//! Definition of Deferred Call tasks.
//!
//! Deferred calls also peripheral drivers to register pseudo interrupts.
Copy link
Contributor

Choose a reason for hiding this comment

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

also -> allow?

use core::sync::atomic::Ordering;

static DEFERRED_CALL: AtomicUsize = AtomicUsize::new(0);
//! Definition of Deferred Call tasks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this file be renamed since it only has deferred call primitives?

/// Represents a way to generate an asynchronous call without a hardware interrupt.
pub struct DeferredCall<T>(T);

impl<T: Into<usize> + TryFrom<usize> + Copy> DeferredCall<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a requirement that the range of T is from 0 to 31, but that isn't enforced in this interface or documented anywhere.

brghena
brghena previously approved these changes May 17, 2018
@bradjc
Copy link
Contributor Author

bradjc commented May 18, 2018

Since core::sync::atomic doesn't seem to exist for thumbv6, any thoughts on what I should do? It could go in its own crate, but that is annoying. Is there an alternative to core::sync::atomic::AtomicUsize?

@phil-levis phil-levis added P-Significant This is a substancial change that requires review from all core developers. and removed P-Upkeep This a relatively minor change, or one that is limited in scope, and requires less scrutiny. labels May 22, 2018
@bradjc
Copy link
Contributor Author

bradjc commented May 24, 2018

Ok I did some more googling and found that japaric ran into this issue as well. In rust-embedded/heapless#5 they end up implementing their own AtomicUsize, which I basically copied.

I tested with the nonvolatile storage test app and it passed.

brghena
brghena previously approved these changes May 25, 2018
alevy
alevy previously approved these changes May 25, 2018
This supports chips that need to create fake interrupts for peripherals
that don't support interrupts in order to implement a HIL.
Since thumbv6 doesn't suppport AtomicUsize provided by rust
(unless rust-lang/rust#45085 gets implemented
I guess), we create our own based on
https://github.com/japaric/heapless/blob/master/src/ring_buffer/mod.rs.

This allows it to compile for all of our boards.
@bradjc
Copy link
Contributor Author

bradjc commented May 25, 2018

Rebased. Couple approvals, 10 days old, lets say last call on this one.

@bradjc bradjc added the last-call Final review period for a pull request. label May 25, 2018
@bradjc bradjc merged commit 138a1c9 into master May 26, 2018
@bradjc bradjc deleted the deferred_call branch May 26, 2018 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel last-call Final review period for a pull request. P-Significant This is a substancial change that requires review from all core developers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants