mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
awful intermediate refactor of cramium-console
transitioning this from a mere test stub into something more fully fledged, but encountered a problem in the kernel along the way. so, we're committing this pile of poop so we can swap over to a new branch and put out the kernel fire before resuming with the refactor.
This commit is contained in:
parent
34cfc7db5b
commit
870326a497
2 changed files with 171 additions and 43 deletions
|
|
@ -12,10 +12,16 @@ xous-api-ticktimer = "0.9.56"
|
||||||
xous = "0.9.60"
|
xous = "0.9.60"
|
||||||
log-server = { package = "xous-api-log", version = "0.1.56" }
|
log-server = { package = "xous-api-log", version = "0.1.56" }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
|
num-derive = { version = "0.3.3", default-features = false }
|
||||||
|
num-traits = { version = "0.2.14", default-features = false }
|
||||||
|
|
||||||
xous-pio = { path = "../../libs/xous-pio", optional = true }
|
xous-pio = { path = "../../libs/xous-pio", optional = true }
|
||||||
xous-pl230 = { path = "../../libs/xous-pl230", optional = true }
|
xous-pl230 = { path = "../../libs/xous-pl230", optional = true }
|
||||||
# this is temporary, until we get GAM/modals pulled in
|
# this is temporary, until we get GAM/modals pulled in
|
||||||
graphics-server = { path = "../graphics-server" }
|
graphics-server = { path = "../graphics-server" }
|
||||||
|
modals = { path = "../modals" }
|
||||||
|
gam = { path = "../gam" }
|
||||||
|
locales = { path = "../../locales" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
"cramium-fpga" = ["utralib/cramium-fpga", "xous-pl230/cramium-fpga"]
|
"cramium-fpga" = ["utralib/cramium-fpga", "xous-pl230/cramium-fpga"]
|
||||||
|
|
@ -23,4 +29,5 @@ graphics-server = { path = "../graphics-server" }
|
||||||
"hwsim" = []
|
"hwsim" = []
|
||||||
"pio-test" = ["xous-pio"]
|
"pio-test" = ["xous-pio"]
|
||||||
"pl230-test" = ["xous-pl230"]
|
"pl230-test" = ["xous-pl230"]
|
||||||
|
"message-passing-test" = []
|
||||||
default = []
|
default = []
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,25 @@
|
||||||
|
use std::fmt::Write;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
use graphics_server::api::GlyphStyle;
|
||||||
|
use graphics_server::Gid;
|
||||||
|
use graphics_server::*;
|
||||||
|
use locales::t;
|
||||||
|
use num_traits::*;
|
||||||
use utralib::generated::*;
|
use utralib::generated::*;
|
||||||
|
|
||||||
|
const SERVER_NAME_STATUS_GID: &str = "_Status bar GID receiver_";
|
||||||
|
const SERVER_NAME_STATUS: &str = "_Status_";
|
||||||
|
|
||||||
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
|
pub(crate) enum StatusOpcode {
|
||||||
|
Quit,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// - create_server_with_address can OOM without recovery -- figure out how to fix this.
|
||||||
|
// - clean up the mess here
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
log::set_max_level(log::LevelFilter::Info);
|
log::set_max_level(log::LevelFilter::Info);
|
||||||
|
|
@ -71,62 +92,162 @@ fn main() {
|
||||||
log::info!("resuming console tests");
|
log::info!("resuming console tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
let tt = xous_api_ticktimer::Ticktimer::new().unwrap();
|
#[cfg(feature = "message-passing-test")]
|
||||||
let mut total = 0;
|
{
|
||||||
let mut iter = 0;
|
let tt = xous_api_ticktimer::Ticktimer::new().unwrap();
|
||||||
log::info!("running message passing test");
|
let mut total = 0;
|
||||||
loop {
|
let mut iter = 0;
|
||||||
// this conjures a scalar message
|
log::info!("running message passing test");
|
||||||
#[cfg(feature = "hwsim")]
|
loop {
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter);
|
// this conjures a scalar message
|
||||||
let now = tt.elapsed_ms();
|
#[cfg(feature = "hwsim")]
|
||||||
#[cfg(feature = "hwsim")]
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter);
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x2222_0000 + iter);
|
let now = tt.elapsed_ms();
|
||||||
total += now;
|
#[cfg(feature = "hwsim")]
|
||||||
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x2222_0000 + iter);
|
||||||
|
total += now;
|
||||||
|
|
||||||
if iter >= 8 && iter < 12 {
|
if iter >= 8 && iter < 12 {
|
||||||
|
#[cfg(feature = "hwsim")]
|
||||||
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D001);
|
||||||
|
tt.sleep_ms(1).ok();
|
||||||
|
} else if iter >= 12 && iter < 13 {
|
||||||
|
#[cfg(feature = "hwsim")]
|
||||||
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002);
|
||||||
|
tt.sleep_ms(2).ok();
|
||||||
|
} else if iter >= 13 && iter < 14 {
|
||||||
|
#[cfg(feature = "hwsim")]
|
||||||
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002);
|
||||||
|
tt.sleep_ms(3).ok();
|
||||||
|
} else if iter >= 14 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// something lame to just conjure a memory message
|
||||||
#[cfg(feature = "hwsim")]
|
#[cfg(feature = "hwsim")]
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D001);
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter);
|
||||||
tt.sleep_ms(1).ok();
|
let version = tt.get_version();
|
||||||
} else if iter >= 12 && iter < 13 {
|
|
||||||
#[cfg(feature = "hwsim")]
|
#[cfg(feature = "hwsim")]
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002);
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter);
|
||||||
tt.sleep_ms(2).ok();
|
total += version.len() as u64;
|
||||||
} else if iter >= 13 && iter < 14 {
|
iter += 1;
|
||||||
#[cfg(feature = "hwsim")]
|
#[cfg(feature = "hwsim")]
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002);
|
core_csr.wfo(utra::main::REPORT_REPORT, now as u32);
|
||||||
tt.sleep_ms(3).ok();
|
log::info!("message passing test progress: {}ms", tt.elapsed_ms());
|
||||||
} else if iter >= 14 {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "hwsim")]
|
||||||
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x6969_6969);
|
||||||
|
println!("Elapsed: {}", total);
|
||||||
|
#[cfg(feature = "hwsim")]
|
||||||
|
core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_c0de);
|
||||||
|
|
||||||
// something lame to just conjure a memory message
|
|
||||||
#[cfg(feature = "hwsim")]
|
#[cfg(feature = "hwsim")]
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter);
|
core_csr.wfo(utra::main::SUCCESS_SUCCESS, 1);
|
||||||
let version = tt.get_version();
|
tt.sleep_ms(4).ok();
|
||||||
#[cfg(feature = "hwsim")]
|
#[cfg(feature = "hwsim")]
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter);
|
core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation
|
||||||
total += version.len() as u64;
|
log::info!("message passing test done at {}ms!", tt.elapsed_ms());
|
||||||
iter += 1;
|
|
||||||
#[cfg(feature = "hwsim")]
|
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, now as u32);
|
|
||||||
log::info!("message passing test progress: {}ms", tt.elapsed_ms());
|
|
||||||
}
|
}
|
||||||
#[cfg(feature = "hwsim")]
|
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x6969_6969);
|
|
||||||
println!("Elapsed: {}", total);
|
|
||||||
#[cfg(feature = "hwsim")]
|
|
||||||
core_csr.wfo(utra::main::REPORT_REPORT, 0x600d_c0de);
|
|
||||||
|
|
||||||
#[cfg(feature = "hwsim")]
|
thread::spawn(move || {
|
||||||
core_csr.wfo(utra::main::SUCCESS_SUCCESS, 1);
|
let mut count = 0;
|
||||||
tt.sleep_ms(4).ok();
|
loop {
|
||||||
#[cfg(feature = "hwsim")]
|
log::info!("Still alive! #{}", count);
|
||||||
core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation
|
count += 1;
|
||||||
log::info!("message passing test done at {}ms!", tt.elapsed_ms());
|
std::thread::sleep(std::time::Duration::from_millis(2000));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let xns = xous_api_names::XousNames::new().unwrap();
|
let xns = xous_api_names::XousNames::new().unwrap();
|
||||||
|
|
||||||
|
let status_gam_getter =
|
||||||
|
xns.register_name(SERVER_NAME_STATUS_GID, Some(1)).expect("can't register server");
|
||||||
|
let mut canvas_gid: [u32; 4] = [0; 4];
|
||||||
|
// wait until we're assigned a GID -- this is a one-time message from the GAM
|
||||||
|
let msg = xous::receive_message(status_gam_getter).unwrap();
|
||||||
|
log::trace!("GID assignment message: {:?}", msg);
|
||||||
|
xous::msg_scalar_unpack!(msg, g0, g1, g2, g3, {
|
||||||
|
canvas_gid[0] = g0 as u32;
|
||||||
|
canvas_gid[1] = g1 as u32;
|
||||||
|
canvas_gid[2] = g2 as u32;
|
||||||
|
canvas_gid[3] = g3 as u32;
|
||||||
|
});
|
||||||
|
match xns.unregister_server(status_gam_getter) {
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("couldn't unregister getter server: {:?}", e);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
xous::destroy_server(status_gam_getter).unwrap();
|
||||||
|
|
||||||
|
let status_gid: Gid = Gid::new(canvas_gid);
|
||||||
|
// Expected connections:
|
||||||
|
// - from keyboard
|
||||||
|
// - from USB HID
|
||||||
|
let status_sid = xns.register_name(SERVER_NAME_STATUS, Some(2)).unwrap();
|
||||||
|
// create a connection for callback hooks
|
||||||
|
let cb_cid = xous::connect(status_sid).unwrap();
|
||||||
|
|
||||||
|
let gam = gam::Gam::new(&xns).expect("|status: can't connect to GAM");
|
||||||
|
// screensize is controlled by the GAM, it's set in main.rs near the top
|
||||||
|
let screensize = gam.get_canvas_bounds(status_gid).expect("|status: Couldn't get canvas size");
|
||||||
|
|
||||||
|
// build security status textview
|
||||||
|
let mut security_tv = TextView::new(
|
||||||
|
status_gid,
|
||||||
|
TextBounds::BoundingBox(Rectangle::new(
|
||||||
|
Point::new(0, screensize.y / 2 + 1),
|
||||||
|
Point::new(screensize.x, screensize.y),
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
security_tv.style = GlyphStyle::Tall; // was: Regular, but not available on this target
|
||||||
|
security_tv.draw_border = false;
|
||||||
|
security_tv.margin = Point::new(0, 0);
|
||||||
|
security_tv.token = gam.claim_token(gam::STATUS_BAR_NAME).expect("couldn't request token"); // this is a shared magic word to identify this process
|
||||||
|
security_tv.clear_area = true;
|
||||||
|
security_tv.invert = true;
|
||||||
|
write!(&mut security_tv, "{}", t!("secnote.startup", locales::LANG)).unwrap();
|
||||||
|
gam.post_textview(&mut security_tv).unwrap();
|
||||||
|
gam.draw_line(
|
||||||
|
status_gid,
|
||||||
|
Line::new_with_style(
|
||||||
|
Point::new(0, screensize.y),
|
||||||
|
screensize,
|
||||||
|
DrawStyle::new(PixelColor::Light, PixelColor::Light, 1),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
log::trace!("status redraw## initial");
|
||||||
|
gam.redraw().unwrap(); // initial boot redraw
|
||||||
|
|
||||||
|
// ------------------ start a 'gutter' thread to handle incoming events while we go through the
|
||||||
|
// boot/autoupdate process
|
||||||
|
let gutter = thread::spawn({
|
||||||
|
let gutter_sid = status_sid.clone();
|
||||||
|
move || {
|
||||||
|
loop {
|
||||||
|
let msg = xous::receive_message(gutter_sid).unwrap();
|
||||||
|
let opcode: Option<StatusOpcode> = FromPrimitive::from_usize(msg.body.id());
|
||||||
|
log::info!("Guttering {:?}", opcode);
|
||||||
|
match opcode {
|
||||||
|
Some(StatusOpcode::Quit) => {
|
||||||
|
xous::return_scalar(msg.sender, 1).ok();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => (), // ignore everything else.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
log::info!("starting modal");
|
||||||
|
let modals = modals::Modals::new(&xns).unwrap();
|
||||||
|
modals.show_notification("This is a test", Some("This is a test")).ok();
|
||||||
|
log::info!("exiting modal");
|
||||||
|
|
||||||
let mut ball = Ball::new(&xns);
|
let mut ball = Ball::new(&xns);
|
||||||
|
log::info!("starting ball");
|
||||||
loop {
|
loop {
|
||||||
ball.update();
|
ball.update();
|
||||||
/* // for testing full-frame graphics drawing
|
/* // for testing full-frame graphics drawing
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue