mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add the initial templates
This commit is contained in:
parent
f15266c070
commit
c984756539
11 changed files with 366 additions and 0 deletions
26
services/cb-test-c1/Cargo.toml
Normal file
26
services/cb-test-c1/Cargo.toml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
[package]
|
||||
name = "cb-test-c1"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Callback Test Client 1"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
heapless = "0.5.6"
|
||||
log-server = { path = "../log-server" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
xous-names = { path = "../xous-names" }
|
||||
log = "0.4"
|
||||
xous-ipc = {path = "../../xous-ipc"}
|
||||
|
||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
num-traits = {version = "0.2", default-features = false}
|
||||
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
||||
[features]
|
||||
default = []
|
||||
8
services/cb-test-c1/src/api.rs
Normal file
8
services/cb-test-c1/src/api.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pub(crate) const SERVER_NAME_TRNG: &str = "_Callback test client 1_";
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
/// Get one or two 32-bit words of TRNG data
|
||||
GetTrng,
|
||||
}
|
||||
5
services/cb-test-c1/src/lib.rs
Normal file
5
services/cb-test-c1/src/lib.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
pub mod api;
|
||||
use xous::{CID, send_message};
|
||||
use num_traits::ToPrimitive;
|
||||
50
services/cb-test-c1/src/main.rs
Normal file
50
services/cb-test-c1/src/main.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use log::info;
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let trng_sid = xns.register_name(api::SERVER_NAME_TRNG).expect("can't register server");
|
||||
log::trace!("registered with NS -- {:?}", trng_sid);
|
||||
|
||||
#[cfg(target_os = "none")]
|
||||
let trng = Trng::new();
|
||||
|
||||
#[cfg(not(target_os = "none"))]
|
||||
let mut trng = Trng::new();
|
||||
|
||||
// pump the TRNG hardware to clear the first number out, sometimes it is 0 due to clock-sync issues on the fifo
|
||||
trng.get_trng(2);
|
||||
log::trace!("ready to accept requests");
|
||||
|
||||
loop {
|
||||
let msg = xous::receive_message(trng_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(api::Opcode::GetTrng) => xous::msg_blocking_scalar_unpack!(msg, count, _, _, _, {
|
||||
let val: [u32; 2] = trng.get_trng(count);
|
||||
xous::return_scalar2(msg.sender, val[0] as _, val[1] as _)
|
||||
.expect("couldn't return GetTrng request");
|
||||
}),
|
||||
None => {
|
||||
log::error!("couldn't convert opcode");
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up our program
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
xns.unregister_server(trng_sid).unwrap();
|
||||
xous::destroy_server(trng_sid).unwrap();
|
||||
log::trace!("quitting");
|
||||
xous::terminate_process(); loop {}
|
||||
}
|
||||
26
services/cb-test-c2/Cargo.toml
Normal file
26
services/cb-test-c2/Cargo.toml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
[package]
|
||||
name = "cb-test-c2"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Callback Test Client 2"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
heapless = "0.5.6"
|
||||
log-server = { path = "../log-server" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
xous-names = { path = "../xous-names" }
|
||||
log = "0.4"
|
||||
xous-ipc = {path = "../../xous-ipc"}
|
||||
|
||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
num-traits = {version = "0.2", default-features = false}
|
||||
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
||||
[features]
|
||||
default = []
|
||||
8
services/cb-test-c2/src/api.rs
Normal file
8
services/cb-test-c2/src/api.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pub(crate) const SERVER_NAME_TRNG: &str = "_Callback test client 2_";
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum Opcode {
|
||||
/// Get one or two 32-bit words of TRNG data
|
||||
GetTrng,
|
||||
}
|
||||
5
services/cb-test-c2/src/lib.rs
Normal file
5
services/cb-test-c2/src/lib.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
pub mod api;
|
||||
use xous::{CID, send_message};
|
||||
use num_traits::ToPrimitive;
|
||||
50
services/cb-test-c2/src/main.rs
Normal file
50
services/cb-test-c2/src/main.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use log::info;
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let trng_sid = xns.register_name(api::SERVER_NAME_TRNG).expect("can't register server");
|
||||
log::trace!("registered with NS -- {:?}", trng_sid);
|
||||
|
||||
#[cfg(target_os = "none")]
|
||||
let trng = Trng::new();
|
||||
|
||||
#[cfg(not(target_os = "none"))]
|
||||
let mut trng = Trng::new();
|
||||
|
||||
// pump the TRNG hardware to clear the first number out, sometimes it is 0 due to clock-sync issues on the fifo
|
||||
trng.get_trng(2);
|
||||
log::trace!("ready to accept requests");
|
||||
|
||||
loop {
|
||||
let msg = xous::receive_message(trng_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(api::Opcode::GetTrng) => xous::msg_blocking_scalar_unpack!(msg, count, _, _, _, {
|
||||
let val: [u32; 2] = trng.get_trng(count);
|
||||
xous::return_scalar2(msg.sender, val[0] as _, val[1] as _)
|
||||
.expect("couldn't return GetTrng request");
|
||||
}),
|
||||
None => {
|
||||
log::error!("couldn't convert opcode");
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// clean up our program
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
xns.unregister_server(trng_sid).unwrap();
|
||||
xous::destroy_server(trng_sid).unwrap();
|
||||
log::trace!("quitting");
|
||||
xous::terminate_process(); loop {}
|
||||
}
|
||||
27
services/cb-test-srv/Cargo.toml
Normal file
27
services/cb-test-srv/Cargo.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[package]
|
||||
name = "cb-test-srv"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Callback test server"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
xous-names = { path = "../xous-names" }
|
||||
log-server = { path = "../log-server" }
|
||||
log = "0.4"
|
||||
benchmark-target = { path = "../benchmark-target" }
|
||||
|
||||
xous-ipc = {path = "../../xous-ipc"}
|
||||
num-derive = {version = "0.3", default-features = false}
|
||||
num-traits = {version = "0.2", default-features = false}
|
||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = {path = "../../utralib"}
|
||||
|
||||
[target.'cfg(any(windows,unix))'.dependencies]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
10
services/cb-test-srv/src/api.rs
Normal file
10
services/cb-test-srv/src/api.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use num_traits::{ToPrimitive, FromPrimitive};
|
||||
|
||||
pub(crate) const SERVER_NAME: &str = "_Callback test server_";
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub enum Opcode {
|
||||
RegisterListener,
|
||||
UnregisterListener,
|
||||
Tick,
|
||||
}
|
||||
151
services/cb-test-srv/src/main.rs
Normal file
151
services/cb-test-srv/src/main.rs
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
use api::*;
|
||||
|
||||
fn pump_thread() {
|
||||
log::info!("starting pump thread");
|
||||
|
||||
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let server_conn = xns.request_connection_blocking(api::SERVER_NAME).expect("can't connect to main program");
|
||||
let mut last_time: u64 = ticktimer.elapsed_ms();
|
||||
let mut start_sent = false;
|
||||
loop {
|
||||
let elapsed_time = ticktimer.elapsed_ms();
|
||||
if false {
|
||||
if elapsed_time - last_time > 500 && !start_sent {
|
||||
last_time = elapsed_time;
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Start.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
start_sent = true;
|
||||
} else if elapsed_time - last_time > 10_000 && start_sent {
|
||||
last_time = elapsed_time;
|
||||
start_sent = false;
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Stop.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
}
|
||||
} else {
|
||||
// send a start loop message
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Start.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
ticktimer.sleep_ms(10_000).expect("couldn't sleep");
|
||||
// send a stop loop message
|
||||
xous::send_message(shell_conn,
|
||||
xous::Message::new_scalar(Opcode::Stop.to_usize().unwrap(), 0, 0, 0, 0)).expect("BENCHMARK|stopwatch: couldn't send Start message");
|
||||
// give a moment for the result to update
|
||||
ticktimer.sleep_ms(500).expect("couldn't sleep");
|
||||
}
|
||||
xous::yield_slice();
|
||||
}
|
||||
}
|
||||
|
||||
#[xous::xous_main]
|
||||
fn shell_main() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
info!("BENCHMARK: my PID is {}", xous::process::id());
|
||||
|
||||
info!("BENCHMARK: ticktimer");
|
||||
let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer");
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let shell_server = xns.register_name(SERVER_NAME_SHELL).expect("BENCHMARK: can't register server");
|
||||
|
||||
let gfx = graphics_server::Gfx::new(&xns).unwrap();
|
||||
let target_conn = xns.request_connection_blocking(benchmark_target::api::SERVER_NAME_BENCHMARK).expect("BENCHMARK: can't connect to COM");
|
||||
|
||||
xous::create_thread_0(stopwatch_thread).unwrap();
|
||||
info!("BENCHMARK: stopwatch thread started");
|
||||
|
||||
let screensize = gfx.screen_size().expect("Couldn't get screen size");
|
||||
|
||||
let font_h: i16 = gfx.glyph_height_hint(GlyphStyle::Small).expect("couldn't get glyph height") as i16;
|
||||
|
||||
let status_clipregion =
|
||||
Rectangle::new_coords_with_style(4, 0, screensize.x, font_h as i16 * 4, DrawStyle::new(PixelColor::Light, PixelColor::Light, 1));
|
||||
|
||||
gfx.draw_rectangle(Rectangle::new_with_style(Point::new(0, 0), screensize,
|
||||
DrawStyle::new(PixelColor::Light, PixelColor::Light, 0)
|
||||
))
|
||||
.expect("unable to clear region");
|
||||
|
||||
let mut result_tv = TextView::new(graphics_server::Gid::new([0, 0, 0, 0]),
|
||||
TextBounds::BoundingBox(Rectangle::new(Point::new(0,0),
|
||||
Point::new(screensize.x, screensize.y - 1))));
|
||||
result_tv.set_op(TextOp::Render);
|
||||
result_tv.clip_rect = Some(status_clipregion.into());
|
||||
result_tv.untrusted = false;
|
||||
result_tv.style = blitstr::GlyphStyle::Small;
|
||||
result_tv.draw_border = false;
|
||||
result_tv.margin = Point::new(3, 0);
|
||||
write!(result_tv, "Initializing...").expect("couldn't init text");
|
||||
gfx.draw_textview(&mut result_tv).unwrap();
|
||||
|
||||
gfx.flush().expect("unable to draw to screen");
|
||||
|
||||
let mut start_time: u64 = 0;
|
||||
let mut stop_time: u64 = 0;
|
||||
let mut update_result: bool = false;
|
||||
let mut count: u32 = 0;
|
||||
let mut check_count: u32 = 0;
|
||||
loop {
|
||||
let maybe_env = xous::try_receive_message(shell_server).unwrap();
|
||||
match maybe_env {
|
||||
Some(envelope) => {
|
||||
info!("BENCHMARK: Message: {:?}", envelope);
|
||||
match FromPrimitive::from_usize(envelope.body.id()) {
|
||||
Some(Opcode::Start) => {
|
||||
start_time = ticktimer.elapsed_ms();
|
||||
},
|
||||
Some(Opcode::Stop) => {
|
||||
stop_time = ticktimer.elapsed_ms();
|
||||
update_result = true;
|
||||
},
|
||||
None => {
|
||||
error!("BENCHMARK: couldn't convert opcode");
|
||||
}
|
||||
}
|
||||
}
|
||||
None => (), // don't yield, we are trying to run the loop as fast as we can...
|
||||
}
|
||||
|
||||
// actual benchmark
|
||||
// get a scalar message
|
||||
if true {
|
||||
// measured at 1479.2 iterations per second in this loop (hardware); 55/s (hosted)
|
||||
|
||||
// xous v0.8
|
||||
// 29729 per 10s = 2972.9/s (hardware)
|
||||
// 485 per 10s = 48.5/s (hosted)
|
||||
count = benchmark_target::test_scalar(target_conn, count).expect("BENCHMARK: couldn't send test message");
|
||||
check_count = check_count + 1;
|
||||
} else {
|
||||
// works on hosted mode, 35/s (hosted)
|
||||
// measured at 762.6 iterations per second (hardware)
|
||||
|
||||
// xous v0.8
|
||||
// 9,928 per 10s = 992.8/s (hardware)
|
||||
// 243 per 10s = 24.3/s (hosted)
|
||||
count = benchmark_target::test_memory(target_conn, count).expect("BENCHMARK: couldn't send test message");
|
||||
check_count = check_count + 1;
|
||||
}
|
||||
|
||||
if update_result {
|
||||
update_result = false;
|
||||
|
||||
gfx.draw_rectangle(status_clipregion)
|
||||
.expect("unable to clear region");
|
||||
|
||||
result_tv.clear_str();
|
||||
write!(&mut result_tv, "Elapsed: {}, count: {}, check: {}",
|
||||
stop_time - start_time, count, check_count).unwrap();
|
||||
gfx.draw_textview(&mut result_tv).unwrap();
|
||||
gfx.flush().expect("unable to draw to screen");
|
||||
|
||||
count = 0;
|
||||
check_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue