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:
bunnie 2024-05-23 14:51:48 +08:00
parent 34cfc7db5b
commit 870326a497
2 changed files with 171 additions and 43 deletions

View file

@ -12,10 +12,16 @@ xous-api-ticktimer = "0.9.56"
xous = "0.9.60"
log-server = { package = "xous-api-log", version = "0.1.56" }
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-pl230 = { path = "../../libs/xous-pl230", optional = true }
# this is temporary, until we get GAM/modals pulled in
graphics-server = { path = "../graphics-server" }
modals = { path = "../modals" }
gam = { path = "../gam" }
locales = { path = "../../locales" }
[features]
"cramium-fpga" = ["utralib/cramium-fpga", "xous-pl230/cramium-fpga"]
@ -23,4 +29,5 @@ graphics-server = { path = "../graphics-server" }
"hwsim" = []
"pio-test" = ["xous-pio"]
"pl230-test" = ["xous-pl230"]
"message-passing-test" = []
default = []

View file

@ -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::*;
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() {
log_server::init_wait().unwrap();
log::set_max_level(log::LevelFilter::Info);
@ -71,62 +92,162 @@ fn main() {
log::info!("resuming console tests");
}
let tt = xous_api_ticktimer::Ticktimer::new().unwrap();
let mut total = 0;
let mut iter = 0;
log::info!("running message passing test");
loop {
// this conjures a scalar message
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter);
let now = tt.elapsed_ms();
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x2222_0000 + iter);
total += now;
#[cfg(feature = "message-passing-test")]
{
let tt = xous_api_ticktimer::Ticktimer::new().unwrap();
let mut total = 0;
let mut iter = 0;
log::info!("running message passing test");
loop {
// this conjures a scalar message
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x1111_0000 + iter);
let now = tt.elapsed_ms();
#[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")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D001);
tt.sleep_ms(1).ok();
} else if iter >= 12 && iter < 13 {
core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter);
let version = tt.get_version();
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002);
tt.sleep_ms(2).ok();
} else if iter >= 13 && iter < 14 {
core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter);
total += version.len() as u64;
iter += 1;
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x5133_D002);
tt.sleep_ms(3).ok();
} else if iter >= 14 {
break;
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);
// something lame to just conjure a memory message
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x3333_0000 + iter);
let version = tt.get_version();
core_csr.wfo(utra::main::SUCCESS_SUCCESS, 1);
tt.sleep_ms(4).ok();
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::REPORT_REPORT, 0x4444_0000 + iter);
total += version.len() as u64;
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());
core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation
log::info!("message passing test done at {}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")]
core_csr.wfo(utra::main::SUCCESS_SUCCESS, 1);
tt.sleep_ms(4).ok();
#[cfg(feature = "hwsim")]
core_csr.wfo(utra::main::DONE_DONE, 1); // this should stop the simulation
log::info!("message passing test done at {}ms!", tt.elapsed_ms());
thread::spawn(move || {
let mut count = 0;
loop {
log::info!("Still alive! #{}", count);
count += 1;
std::thread::sleep(std::time::Duration::from_millis(2000));
}
});
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);
log::info!("starting ball");
loop {
ball.update();
/* // for testing full-frame graphics drawing