-
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 4 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,44 @@ | ||
//! 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| { | ||
// Subscribe to the button callback. | ||
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; | ||
Buttons::wait_for_button(driver_number, subscribe_number); | ||
writeln!(Console::writer(), "button pressed (yield_wait_for)").unwrap(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,6 +35,19 @@ impl<S: RawSyscalls> Syscalls for S { | |||||
} | ||||||
} | ||||||
|
||||||
fn yield_wait_for(driver_number: u32, subscribe_number: u32) { | ||||||
|
fn yield_wait_for(driver_number: u32, subscribe_number: u32) { | |
fn yield_wait_for(driver_number: u32, subscribe_number: u32) -> (u32, u32, u32) { |
yield-wait-for
returns values instead of calling an upcall, all registers return. This is similar to yield-no-wait
, but it only returns r1
.
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.
The first u32 is always 3, and the rest are driver_number and subscribe_number?
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,44 @@ pub(super) fn yield_wait() { | |
); | ||
} | ||
|
||
pub(super) unsafe fn yield_wait_for( | ||
driver_number: libtock_platform::Register, | ||
subscribe_number: 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; | ||
} | ||
|
||
assert!( | ||
invoke_next_upcall(), | ||
"yield-wait-for called with no queueued upcall" | ||
); | ||
} | ||
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. | ||
|
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.