-
Notifications
You must be signed in to change notification settings - Fork 118
implemented yield_wait_for #575
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
Open
addrian-77
wants to merge
7
commits into
tock:master
Choose a base branch
from
WyliodrinEmbeddedIoT:add/yield_wait_for
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
abfadd9
implemented yield_wait_for
addrian-77 87e1f26
fixed ci errors
addrian-77 ccf45b6
fix: resolve ci errors
addrian-77 9eae354
fix: resolve safety error
addrian-77 37f950f
refactor: remove useless conversion
addrian-77 9ef5b4c
refactor: changed definition to return values
addrian-77 c69a075
refactor: removed redundant argument
addrian-77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //! An extremely simple libtock-rs example. Register button events. | ||
| #![no_main] | ||
| #![no_std] | ||
|
|
||
| use core::fmt::Write; | ||
| use libtock::buttons::{ButtonListener, Buttons}; | ||
| use libtock::console::Console; | ||
| use libtock::leds::Leds; | ||
| use libtock::runtime::{set_main, stack_size}; | ||
| use libtock_platform::share; | ||
| // use libtock_runtime::TockSyscalls; | ||
|
|
||
| set_main! {main} | ||
| stack_size! {0x1000} | ||
|
|
||
| fn main() { | ||
| writeln!(Console::writer(), "main!").unwrap(); | ||
| let listener = ButtonListener(|button, _state| { | ||
| let _ = Leds::toggle(button); | ||
| // writeln!(Console::writer(), "button {:?}: {:?}", button, state).unwrap(); | ||
| }); | ||
| if let Ok(buttons_count) = Buttons::count() { | ||
| writeln!(Console::writer(), "button count: {}", buttons_count).unwrap(); | ||
|
|
||
| share::scope(|subscribe| { | ||
| Buttons::register_listener(&listener, subscribe).unwrap(); | ||
| // Enable interrupts for each button press. | ||
| for i in 0..buttons_count { | ||
| Buttons::enable_interrupts(i).unwrap(); | ||
| } | ||
|
|
||
| // Wait for buttons to be pressed. | ||
| loop { | ||
| let driver_number: u32 = 0x3; | ||
| let subscribe_number: u32 = 0; | ||
| let (status, state) = Buttons::wait_for_button(driver_number, subscribe_number); | ||
| writeln!( | ||
| Console::writer(), | ||
| "Button pressed (yield_wait_for), status: {:?}, state: {:?}", | ||
| status, | ||
| state | ||
| ) | ||
| .unwrap(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,50 @@ pub(super) fn yield_wait() { | |
| ); | ||
| } | ||
|
|
||
| pub(super) unsafe fn yield_wait_for( | ||
| r0: libtock_platform::Register, | ||
| driver_number: libtock_platform::Register, | ||
| subscribe_number: libtock_platform::Register, | ||
| ) -> ( | ||
| libtock_platform::Register, | ||
| libtock_platform::Register, | ||
| libtock_platform::Register, | ||
| ) { | ||
| let upcall_found = KERNEL_DATA.with(|refcell| { | ||
| let mut refmut = refcell.borrow_mut(); | ||
| let kernel_data = refmut | ||
| .as_mut() | ||
| .expect("yield-wait-for called but no fake::Kernel exists"); | ||
|
|
||
| kernel_data.syscall_log.push(SyscallLogEntry::YieldWaitFor); | ||
|
|
||
| match kernel_data.expected_syscalls.pop_front() { | ||
| None => false, | ||
| Some(ExpectedSyscall::YieldWaitFor { driver, subscribe }) | ||
| if <libtock_platform::Register as From<u32>>::from(driver) == driver_number | ||
| && <libtock_platform::Register as From<u32>>::from(subscribe) | ||
| == subscribe_number => | ||
| { | ||
| true | ||
| } | ||
| Some(expected_syscall) => { | ||
| kernel_data.expected_syscalls.push_front(expected_syscall); | ||
| false | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| if upcall_found { | ||
| return (r0, driver_number, subscribe_number); | ||
| } | ||
|
|
||
| assert!( | ||
| invoke_next_upcall(), | ||
| "yield-wait-for called with no queueued upcall" | ||
| ); | ||
| (r0, driver_number, subscribe_number) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this unittest, this function basically returns the same thing everytime, is this okay? What should happen if we don't have the expected upcall? |
||
|
|
||
| // Pops the next upcall off the kernel data's upcall queue and invokes it, or | ||
| // does nothing if the upcall queue was entry. The return value indicates | ||
| // whether an upcall was run. Panics if no kernel data is present. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
yield-wait-fordoes not trigger the callback, it returns the arguments for the callback whenyield-for-returns.