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
Conversation
chips/sam4l/src/helpers.rs
Outdated
static DEFERRED_CALL: AtomicUsize = AtomicUsize::new(0); | ||
//! Definition of Deferred Call tasks. | ||
//! | ||
//! Deferred calls also peripheral drivers to register pseudo interrupts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also -> allow?
chips/sam4l/src/helpers.rs
Outdated
use core::sync::atomic::Ordering; | ||
|
||
static DEFERRED_CALL: AtomicUsize = AtomicUsize::new(0); | ||
//! Definition of Deferred Call tasks. |
There was a problem hiding this comment.
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?
kernel/src/common/deferred_call.rs
Outdated
/// 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> { |
There was a problem hiding this comment.
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.
Since |
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. |
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.
Rebased. Couple approvals, 10 days old, lets say last call on this one. |
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
/docs
, or no updates are required.Formatting
make formatall
.