-
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
abfadd9
87e1f26
ccf45b6
9eae354
37f950f
9ef5b4c
c69a075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! 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(); | ||
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.
|
||
// Enable interrupts for each button press. | ||
for i in 0..buttons_count { | ||
Buttons::enable_interrupts(i).unwrap(); | ||
} | ||
|
||
// Wait for buttons to be pressed. | ||
loop { | ||
for i in 0..buttons_count { | ||
let driver_number: u32 = 0x3; | ||
let subscribe_number: u32 = i as u32; | ||
let (status, state) = Buttons::wait_for_button(driver_number, subscribe_number); | ||
writeln!( | ||
Console::writer(), | ||
"Button pressed (yield_wait_for), status: {:?}, state: {:?}", | ||
status, | ||
state | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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. | ||
|
Uh oh!
There was an error while loading. Please reload this page.