mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
state before refactor of status to own process
This commit is contained in:
parent
c9d7b1c504
commit
96a19baa8d
7 changed files with 91 additions and 38 deletions
|
|
@ -164,6 +164,14 @@ pub extern "C" fn kmain() {
|
|||
None => {
|
||||
#[cfg(feature = "debug-print")]
|
||||
println!("NO RUNNABLE TASKS FOUND, entering idle state");
|
||||
|
||||
#[cfg(feature = "debug-print")]
|
||||
SystemServices::with(|system_services| {
|
||||
for test_idx in 0..system_services.processes.len() {
|
||||
println!("{:?}", system_services.processes[test_idx]);
|
||||
}
|
||||
});
|
||||
|
||||
// Special case for testing: idle can return `false` to indicate exit
|
||||
if !arch::idle() {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -788,10 +788,14 @@ impl SystemServices {
|
|||
can_resume: bool,
|
||||
) -> Result<TID, xous_kernel::Error> {
|
||||
let previous_pid = self.current_pid();
|
||||
// println!(
|
||||
// "KERNEL({},{}): Activating process {} thread {}",
|
||||
// previous_pid, previous_tid, new_pid, new_tid
|
||||
// );
|
||||
|
||||
let debug = false;
|
||||
if debug {
|
||||
println!(
|
||||
"\n\r KERNEL({},{}): Activating process {} thread {}",
|
||||
previous_pid, previous_tid, new_pid, new_tid
|
||||
);
|
||||
}
|
||||
|
||||
// Save state if the PID has changed. This will activate the new memory
|
||||
// space.
|
||||
|
|
@ -820,18 +824,19 @@ impl SystemServices {
|
|||
// "PID {}: Looking for a valid context in the mask {:08b}, curent context {} ({:08b})",
|
||||
// new_pid, x, new.current_context, new.current_context
|
||||
// );
|
||||
new_tid = 0; //new.current_thread as usize;
|
||||
//new_tid = 0;
|
||||
new_tid = new.current_thread as usize;
|
||||
while x & (1 << new_tid) == 0 {
|
||||
new_tid += 1;
|
||||
if new_tid > arch::process::MAX_THREAD {
|
||||
// new_tid = 0;
|
||||
// }
|
||||
// // If we've looped around, return an error.
|
||||
// if new_tid == new.current_thread as usize {
|
||||
new_tid = 0;
|
||||
} else if new_tid == new.current_thread as usize {
|
||||
// If we've looped around, return an error.
|
||||
println!("Looked through all contexts and couldn't find one that was ready");
|
||||
return Err(xous_kernel::Error::ProcessNotFound);
|
||||
}
|
||||
}
|
||||
new.current_thread = new_tid as _;
|
||||
// println!(" -- picked thread {}", new_tid);
|
||||
} else if x & (1 << new_tid) == 0 {
|
||||
println!(
|
||||
|
|
@ -880,13 +885,14 @@ impl SystemServices {
|
|||
let previous = self
|
||||
.get_process_mut(previous_pid)
|
||||
.expect("couldn't get previous pid");
|
||||
let _oldstate = previous.state; // for tracking state in the debug print after the following closure
|
||||
previous.state = match previous.state {
|
||||
// If the previous process had exactly one thread that can be
|
||||
// run, then the Running thread list will be 0. In that case,
|
||||
// we will either need to Sleep this process, or mark it as
|
||||
// being Ready to run.
|
||||
ProcessState::Running(x) if x == 0 => {
|
||||
if can_resume {
|
||||
if can_resume /*|| advance_thread*/ {
|
||||
ProcessState::Ready(1 << previous_tid)
|
||||
} else {
|
||||
ProcessState::Sleeping
|
||||
|
|
@ -896,17 +902,18 @@ impl SystemServices {
|
|||
// Convert the previous process into "Ready", and include the
|
||||
// current context number only if `can_resume` is `true`.
|
||||
ProcessState::Running(x) => {
|
||||
// if can_resume {
|
||||
// ProcessState::Ready(x | (1 << previous_tid))
|
||||
// } else {
|
||||
ProcessState::Ready(x)
|
||||
// }
|
||||
if can_resume {
|
||||
ProcessState::Ready(x | (1 << previous_tid))
|
||||
} else {
|
||||
ProcessState::Ready(x)
|
||||
}
|
||||
}
|
||||
other => panic!(
|
||||
"previous process PID {} was in an invalid state (not Running): {:?}",
|
||||
previous_pid, other
|
||||
),
|
||||
};
|
||||
if debug {println!(" KERNEL|STATE: state change from {:?} -> {:?}", _oldstate, previous.state);}
|
||||
// if advance_thread {
|
||||
// previous.current_thread += 1;
|
||||
// if previous.current_thread as TID > arch::process::MAX_CONTEXT {
|
||||
|
|
@ -924,6 +931,10 @@ impl SystemServices {
|
|||
// }
|
||||
// return Ok(new_tid);
|
||||
// }
|
||||
|
||||
// we can get here if we're activating a new thread in the same process
|
||||
//return Ok(new_tid);
|
||||
|
||||
let new = self.get_process_mut(new_pid)?; /*
|
||||
new.state = match new.state {
|
||||
ProcessState::Running(x) if (x & 1 << new_tid) == 0 => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,18 @@ use crate::services::SystemServices;
|
|||
use core::mem;
|
||||
use xous_kernel::*;
|
||||
|
||||
/// This is the context that called SwitchTo
|
||||
/* Quoth Xobs:
|
||||
The idea behind SWITCHTO_CALLER was that you'd have a process act as a scheduler,
|
||||
where it would know all of its children processes. It would call SwitchTo(pid, tid)
|
||||
on its children, which would call Yield or WaitEvent as necessary that would then
|
||||
cause execution to return to the parent process.
|
||||
|
||||
If the timer hit, it would call ReturnToParent() which would also return to the caller.
|
||||
|
||||
Currently (as of Mar 2021) this functionality isn't being used, it's just returning
|
||||
back to the kernel, e.g. (PID,TID) = (1,1)
|
||||
*/
|
||||
/// This is the PID/TID of the last person that called SwitchTo
|
||||
static mut SWITCHTO_CALLER: Option<(PID, TID)> = None;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
|
@ -36,6 +47,7 @@ fn do_yield(_pid: PID, tid: TID) -> SysCallResult {
|
|||
.take()
|
||||
.expect("yielded when no parent context was present")
|
||||
};
|
||||
//println!("\n\r ***YIELD CALLED***");
|
||||
SystemServices::with_mut(|ss| {
|
||||
// TODO: Advance thread
|
||||
ss.activate_process_thread(tid, parent_pid, parent_ctx, true)
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ fn add_chat_layout(gfx_conn: xous::CID, trng_conn: xous::CID, canvases: &mut Fnv
|
|||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
let debug1 = true; // debug level 1 - most general level
|
||||
log_server::init_wait().unwrap();
|
||||
info!("GAM: my PID is {}", xous::process::id());
|
||||
|
||||
|
|
@ -140,13 +141,14 @@ fn xmain() -> ! {
|
|||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||
info!("GAM: entering main loop");
|
||||
loop {
|
||||
// /*
|
||||
let maybe_env = xous::try_receive_message(gam_sid).unwrap();
|
||||
info!("GAM: Maybe Message: {:?}", maybe_env);
|
||||
match maybe_env {
|
||||
Some(envelope) => {
|
||||
info!("GAM: Message: {:?}", envelope);
|
||||
Some(envelope) => { // */
|
||||
let envelope = xous::receive_message(gam_sid).unwrap();
|
||||
if debug1 {info!("GAM: Message: {:?}", envelope); }
|
||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||
info!("GAM: Opcode: {:?}", opcode);
|
||||
if debug1 {info!("GAM: Opcode: {:?}", opcode);}
|
||||
match opcode {
|
||||
Opcode::ClearCanvas(gid) => {
|
||||
match canvases.get(&gid) {
|
||||
|
|
@ -182,16 +184,14 @@ fn xmain() -> ! {
|
|||
let value = unsafe {
|
||||
archived_value_mut::<api::Opcode>(Pin::new(buf.as_mut()), m.id as usize)
|
||||
};
|
||||
use rkyv::Write;
|
||||
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||
match &*value {
|
||||
rkyv::Archived::<api::Opcode>::RenderTextView(rtv) => {
|
||||
let mut tv = rtv.unarchive();
|
||||
info!("GAM: rendertextview {:?}", tv);
|
||||
if debug1{info!("GAM: rendertextview {:?}", tv);}
|
||||
match tv.get_op() {
|
||||
TextOp::Nop => (),
|
||||
TextOp::Render | TextOp::ComputeBounds => {
|
||||
info!("GAM: render request for {:?}", tv);
|
||||
if debug1{info!("GAM: render request for {:?}", tv);}
|
||||
if tv.get_op() == TextOp::ComputeBounds {
|
||||
tv.dry_run = true;
|
||||
} else {
|
||||
|
|
@ -204,8 +204,16 @@ fn xmain() -> ! {
|
|||
// set the clip rectangle according to the canvas' location
|
||||
tv.clip_rect = Some(canvas.clip_rect().into());
|
||||
|
||||
// you have to clone the tv object, because if you don't the same block of
|
||||
// memory gets passed on to the graphics_server(). Which is efficient, but,
|
||||
// the call will automatically Drop() the memory, which causes a panic when
|
||||
// this routine returns.
|
||||
let mut tv_clone = tv.clone();
|
||||
// issue the draw command
|
||||
graphics_server::draw_textview(gfx_conn, &mut tv).expect("GAM: text view draw could not complete.");
|
||||
graphics_server::draw_textview(gfx_conn, &mut tv_clone).expect("GAM: text view draw could not complete.");
|
||||
// copy back the fields that we want to be mutable
|
||||
tv.cursor = tv_clone.cursor;
|
||||
tv.bounds_computed = tv_clone.bounds_computed;
|
||||
} else {
|
||||
info!("GAM: attempt to draw TextView on non-drawable canvas. Not fatal, but request ignored.");
|
||||
}
|
||||
|
|
@ -230,13 +238,12 @@ fn xmain() -> ! {
|
|||
match &*value {
|
||||
rkyv::Archived::<api::Opcode>::RenderObject(rtv) => {
|
||||
let obj: GamObject = rtv.unarchive();
|
||||
info!("GAM: renderobject {:?}", obj);
|
||||
if debug1{info!("GAM: renderobject {:?}", obj);}
|
||||
if let Some(canvas) = canvases.get_mut(&obj.canvas) {
|
||||
// first, figure out if we should even be drawing to this canvas.
|
||||
if canvas.is_drawable() {
|
||||
match obj.obj {
|
||||
GamObjectType::Line(line) => {
|
||||
info!("GAM: drawing line {:?}", line);
|
||||
graphics_server::draw_line(gfx_conn, line);
|
||||
},
|
||||
GamObjectType::Circ(circ) => {
|
||||
|
|
@ -255,21 +262,24 @@ fn xmain() -> ! {
|
|||
} else {
|
||||
info!("GAM: bogus GID in Object, not doing anything in response to draw request.");
|
||||
}
|
||||
if debug1{info!("GAM: leaving RenderObject");}
|
||||
},
|
||||
_ => panic!("GAM: invalid borrow message"),
|
||||
};
|
||||
} else {
|
||||
panic!("GAM: unhandled message {:?}", envelope);
|
||||
}
|
||||
// /*
|
||||
},
|
||||
_ => xous::yield_slice(),
|
||||
// envelope implements Drop(), which includes a call to syscall::return_memory(self.sender, message.buf)
|
||||
}
|
||||
|
||||
} // */
|
||||
//graphics_server::flush(gfx_conn).expect("GAM: couldn't flush buffer to screen");
|
||||
///*
|
||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
||||
if elapsed_time - last_time > 33 { // rate limit updates to 30fps
|
||||
graphics_server::flush(gfx_conn).expect("GAM: couldn't flush buffer to screen");
|
||||
}
|
||||
}
|
||||
}//*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use core::convert::TryFrom;
|
|||
use blitstr_ref as blitstr;
|
||||
|
||||
pub fn status_thread(canvas_gid: [u32; 4]) {
|
||||
let debug1 = false;
|
||||
let status_gid: Gid = Gid::new(canvas_gid);
|
||||
|
||||
info!("GAM|status: registering GAM|status thread");
|
||||
|
|
@ -57,12 +58,22 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
style_dark
|
||||
)).expect("GAM|status: Can't draw border line");
|
||||
|
||||
com::request_battstat_events(xous::names::SERVER_NAME_STATUS, com_conn).expect("GAM|status: couldn't request events from COM");
|
||||
loop {
|
||||
/*
|
||||
if debug1{info!("GAM|status: periodic tasks: updating uptime, requesting battstats");}
|
||||
let elapsed_time = ticktimer_server::elapsed_ms(ticktimer_conn).expect("GAM|status: error requesting uptime");
|
||||
com::get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
||||
uptime_tv.clear_str();
|
||||
write!(&mut uptime_tv, "Up {:02}:{:02}:{:02}",
|
||||
(elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, (elapsed_time / 1000) % 60).expect("GAM|status: can't write string");
|
||||
if debug1{info!("GAM|status: requesting draw of '{}'", uptime_tv);}
|
||||
gam::post_textview(gam_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime");*/
|
||||
|
||||
let maybe_env = xous::try_receive_message(status_sid).unwrap();
|
||||
match maybe_env {
|
||||
Some(envelope) => {
|
||||
info!("GAM|status: Message: {:?}", envelope);
|
||||
let envelope = xous::receive_message(status_sid).unwrap();
|
||||
if debug1{info!("GAM|status: Message: {:?}", envelope);}
|
||||
if let Ok(opcode) = com::api::Opcode::try_from(&envelope.body) {
|
||||
match opcode {
|
||||
com::api::Opcode::BattStatsEvent(s) => {
|
||||
|
|
@ -86,16 +97,18 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
_ => xous::yield_slice(),
|
||||
}
|
||||
|
||||
//ticktimer_server::sleep_ms(ticktimer_conn, 1000).expect("couldn't sleep");
|
||||
|
||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
||||
if elapsed_time - last_time > 500 {
|
||||
//info!("GAM|status: size of TextView type: {} bytes", core::mem::size_of::<TextView>());
|
||||
// info!("GAM|status: periodic tasks: updating uptime, requesting battstats");
|
||||
if debug1{info!("GAM|status: periodic tasks: updating uptime, requesting battstats");}
|
||||
last_time = elapsed_time;
|
||||
com::get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
||||
uptime_tv.clear_str();
|
||||
write!(&mut uptime_tv, "Up {:02}:{:02}:{:02}",
|
||||
(elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, (elapsed_time / 1000) % 60).expect("GAM|status: can't write string");
|
||||
info!("GAM|status: requesting draw of '{}'", uptime_tv);
|
||||
if debug1{info!("GAM|status: requesting draw of '{}'", uptime_tv);}
|
||||
gam::post_textview(gam_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime");
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use core::fmt::Write;
|
|||
|
||||
pub fn draw_line(cid: CID, line: Line) -> Result<(), xous::Error> {
|
||||
let m: xous::Message = api::Opcode::Line(line).into();
|
||||
log::info!("GFX|LIB: api encoded line as {:?}", m);
|
||||
//log::info!("GFX|LIB: api encoded line as {:?}", m);
|
||||
send_message(cid, m).map(|_| ())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ fn xmain() -> ! {
|
|||
display.redraw();
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
info!("GFX: Message: {:?}", msg);
|
||||
//info!("GFX: Message: {:?}", msg);
|
||||
if let xous::Message::Borrow(m) = &msg.body {
|
||||
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
||||
let bytes = Pin::new(buf.as_ref());
|
||||
|
|
@ -138,7 +138,7 @@ fn xmain() -> ! {
|
|||
};
|
||||
//use rkyv::Write;
|
||||
//let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||
let debugtv: bool = true;
|
||||
let debugtv: bool = false;
|
||||
match &*value {
|
||||
rkyv::Archived::<api::Opcode>::DrawTextView(rtv) => {
|
||||
let mut tv = rtv.unarchive();
|
||||
|
|
@ -244,7 +244,6 @@ fn xmain() -> ! {
|
|||
op::rectangle(display.native_buffer(), r)
|
||||
}
|
||||
Opcode::Line(l) => {
|
||||
info!("GFX: line: {:?}", l);
|
||||
op::line(display.native_buffer(), l);
|
||||
}
|
||||
Opcode::Rectangle(r) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue