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

Adds IRQ State types #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jonathanpallant
Copy link
Contributor

Some bike shedding required on the names, but...

These types help you move a singleton from the main thread into an interrupt handler. The global variable is a Mutex<RefCell<Option>> and the local variable is designed to go into an #[interrupt] and is a plain Option that relies on the interrupt macro to give you an &mut Option<T>.

This application for the nRF52840 makes use of these types: https://github.com/ferrous-systems/rust-exercises/tree/7e6d9e6029ad9a31b0c75d233dda6921cd8421f0/nrf52-code/puzzle-fw

Tests compilation across a selection of targets, to ensure no raw CAS operations are included (only via portable-atomic, which can use critical-section to emulate them)
@thejpster
Copy link

@jamesmunns any thoughts on this one?

@jamesmunns
Copy link
Owner

@thejpster I haven't had the chance to fully digest this, since this isn't a data structure or pattern I typically use in any of my projects.

It seems sort of like a oneshot channel plus a lazy static, and a lazy static that specifically requires the cortex-m interrupt transform that is only sound on single core devices?

@thejpster
Copy link

That's a fair first approximation. The caching into an IRQ-local variable saves you the cost of a lock to peek in the channel on subsequent interrupts.

I have thoughts on static mut I'll put in the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants