mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
attempt to add a ticktimer server
This commit is contained in:
parent
2fdc83b588
commit
98f648f30f
9 changed files with 180 additions and 6 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -720,6 +720,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bitflags",
|
||||
"graphics-server",
|
||||
"ticktimer-server",
|
||||
"utralib",
|
||||
"xous",
|
||||
]
|
||||
|
|
@ -797,6 +798,15 @@ dependencies = [
|
|||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ticktimer-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"embedded-graphics",
|
||||
"utralib",
|
||||
"xous",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tools"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ members = [
|
|||
"examples/shell",
|
||||
"examples/graphics-server",
|
||||
"examples/log-server",
|
||||
"examples/ticktimer-server",
|
||||
"svd2utra",
|
||||
"xtask",
|
||||
]
|
||||
|
|
@ -13,6 +14,7 @@ default-members = [
|
|||
"examples/shell",
|
||||
"examples/log-server",
|
||||
"examples/graphics-server",
|
||||
"examples/ticktimer-server",
|
||||
]
|
||||
|
||||
# These packages have custom RUSTFLAGS, so if they
|
||||
|
|
@ -24,7 +26,7 @@ exclude = [
|
|||
"loader",
|
||||
|
||||
# Exclude UTRA, since it is machine-generated.
|
||||
"utra",
|
||||
"utralib",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ description = "Shell test program"
|
|||
bitflags = "1.2.1"
|
||||
xous = { path = "../../xous-rs" }
|
||||
graphics-server = { path = "../graphics-server" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
|
|
|||
|
|
@ -40,14 +40,16 @@ fn shell_main() -> ! {
|
|||
|
||||
// let log_server_id = xous::SID::from_bytes(b"xous-logs-output").unwrap();
|
||||
let graphics_server_id = xous::SID::from_bytes(b"graphics-server ").unwrap();
|
||||
let ticktimer_server_id = xous::SID::from_bytes(b"ticktimer-server").unwrap();
|
||||
|
||||
println!("SHELL: Attempting to connect to servers...");
|
||||
let log_conn = 100;//ensure_connection(log_server_id);
|
||||
let graphics_conn = ensure_connection(graphics_server_id);
|
||||
let ticktimer_conn = ensure_connection(ticktimer_server_id);
|
||||
|
||||
println!(
|
||||
"SHELL: Connected to Log server: {} Graphics server: {}",
|
||||
log_conn, graphics_conn
|
||||
"SHELL: Connected to Log server: {} Graphics server: {} Ticktimer server: {}",
|
||||
log_conn, graphics_conn, ticktimer_conn,
|
||||
);
|
||||
|
||||
assert_ne!(
|
||||
|
|
@ -55,6 +57,11 @@ fn shell_main() -> ! {
|
|||
"SHELL: graphics and log connections are the same!"
|
||||
);
|
||||
|
||||
assert_ne!(
|
||||
ticktimer_conn, graphics_conn,
|
||||
"SHELL: graphics and ticktimer connections are the same!"
|
||||
);
|
||||
|
||||
let mut counter: usize = 0;
|
||||
// let ls = logstr::LogStr::new();
|
||||
let mut lfsr = 0xace1u32;
|
||||
|
|
@ -86,6 +93,9 @@ fn shell_main() -> ! {
|
|||
// lfsr = move_lfsr(lfsr);
|
||||
|
||||
loop {
|
||||
let elapsed_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||
println!("elapsed time: {}ms", elapsed_time);
|
||||
|
||||
match graphics_server::set_style(
|
||||
graphics_conn,
|
||||
5,
|
||||
|
|
|
|||
13
examples/ticktimer-server/Cargo.toml
Normal file
13
examples/ticktimer-server/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "ticktimer-server"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Provide high-resolution, non-rollover system time"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
embedded-graphics = "0.6"
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
44
examples/ticktimer-server/src/api.rs
Normal file
44
examples/ticktimer-server/src/api.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use xous::{Message, ScalarMessage};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Opcode {
|
||||
/// Reset the timer
|
||||
Reset,
|
||||
/// Get the elapsed time in milliseconds
|
||||
ElapsedMs,
|
||||
}
|
||||
|
||||
impl<'a> core::convert::TryFrom<&'a Message> for Opcode {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: &'a Message) -> Result<Self, Self::Error> {
|
||||
match message {
|
||||
Message::Scalar(m) => match m.id {
|
||||
1 => Ok(Opcode::Reset),
|
||||
2 => Ok(Opcode::ElapsedMs),
|
||||
_ => Err("unrecognized opcode"),
|
||||
},
|
||||
_ => Err("unhandled message type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Message> for Opcode {
|
||||
fn into(self) -> Message {
|
||||
match self {
|
||||
Opcode::Reset => Message::Scalar(ScalarMessage {
|
||||
id: 1,
|
||||
arg1: 0,
|
||||
arg2: 0,
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
}),
|
||||
Opcode::ElapsedMs => Message::Scalar(ScalarMessage {
|
||||
id: 2,
|
||||
arg1: 0,
|
||||
arg2: 0,
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
18
examples/ticktimer-server/src/lib.rs
Normal file
18
examples/ticktimer-server/src/lib.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
pub mod api;
|
||||
|
||||
use xous::{try_send_message, CID, Error};
|
||||
|
||||
pub fn elapsed_ms(cid: CID) -> Result<u64, Error> {
|
||||
let response = try_send_message(cid, api::Opcode::ElapsedMs.into())?;
|
||||
if let xous::Result::Scalar2(upper, lower) = response {
|
||||
Ok(upper as u64 | ((lower as u64) << 32))
|
||||
} else {
|
||||
panic!("unexpected return value"); // or return Err(xous::Result::InternalError)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(cid: CID) -> Result<(), xous::Error> {
|
||||
try_send_message(cid, api::Opcode::Reset.into()).map(|_| ())
|
||||
}
|
||||
76
examples/ticktimer-server/src/main.rs
Normal file
76
examples/ticktimer-server/src/main.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
use api::Opcode;
|
||||
|
||||
use utralib::generated::*;
|
||||
|
||||
use core::convert::TryFrom;
|
||||
|
||||
pub struct XousTickTimer {
|
||||
csr: xous::MemoryRange,
|
||||
}
|
||||
|
||||
const TICKS_PER_MS: u64 = 1;
|
||||
|
||||
impl XousTickTimer {
|
||||
pub fn new() -> XousTickTimer {
|
||||
let ctrl = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::ticktimer::HW_TICKTIMER_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Tick Timer CSR range");
|
||||
|
||||
XousTickTimer { csr: ctrl }
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
let mut tt = CSR::new(self.csr.as_mut_ptr() as *mut u32);
|
||||
tt.wfo(utra::ticktimer::CONTROL_RESET, 0b1);
|
||||
tt.wo(utra::ticktimer::CONTROL, 0); // not paused, not reset -> free-run
|
||||
}
|
||||
|
||||
pub fn raw_ticktime(&self) -> u64 {
|
||||
let mut tt = CSR::new(self.csr.as_mut_ptr() as *mut u32);
|
||||
let mut time: u64 = tt.r(utra::ticktimer::TIME0) as u64;
|
||||
time |= (tt.r(utra::ticktimer::TIME1) as u64) << 32;
|
||||
|
||||
time
|
||||
}
|
||||
|
||||
pub fn elapsed_ms(&self) -> u64 {
|
||||
self.raw_ticktime() / TICKS_PER_MS
|
||||
}
|
||||
}
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
// Create a new ticktimer object
|
||||
let ticktimer = XousTickTimer::new();
|
||||
|
||||
let ticktimer_server = xous::create_server(b"ticktimer-server").expect("Couldn't create Ticktimer server");
|
||||
loop {
|
||||
let envelope = xous::receive_message(ticktimer_server).unwrap();
|
||||
// println!("TickTimer: Message: {:?}", envelope);
|
||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||
// println!("TickTimer: Opcode: {:?}", opcode);
|
||||
match opcode {
|
||||
Opcode::Reset => {
|
||||
ticktimer.reset();
|
||||
},
|
||||
Opcode::ElapsedMs => {
|
||||
let time = ticktimer.elapsed_ms();
|
||||
xous::return_scalar2(envelope.sender,
|
||||
(time & 0xFFFF_FFFFu64) as usize,
|
||||
((time >> 32) & 0xFFF_FFFFu64) as usize,
|
||||
).expect("TickTimer: couldn't return time request");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// println!("Couldn't convert opcode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ fn build_hw_image(debug: bool, svd: Option<String>) -> Result<(), DynError> {
|
|||
|
||||
let kernel = build_kernel(debug)?;
|
||||
let mut init = vec![];
|
||||
for pkg in &["shell", "graphics-server"] {
|
||||
for pkg in &["shell", "graphics-server", "ticktimer-server"] {
|
||||
init.push(build(pkg, debug, Some(TARGET), None)?);
|
||||
}
|
||||
let loader = build("loader", debug, Some(TARGET), Some("loader".into()))?;
|
||||
|
|
@ -144,7 +144,7 @@ fn build_hw_image(debug: bool, svd: Option<String>) -> Result<(), DynError> {
|
|||
fn image(debug: bool) -> Result<(), DynError> {
|
||||
let kernel = build_kernel(debug)?;
|
||||
let mut init = vec![];
|
||||
for pkg in &["shell", "log-server", "graphics-server"] {
|
||||
for pkg in &["shell", "log-server", "graphics-server", "ticktimer-server"] {
|
||||
init.push(build(pkg, debug, Some(TARGET), None)?);
|
||||
}
|
||||
build("loader", debug, Some(TARGET), Some("loader".into()))?;
|
||||
|
|
@ -161,7 +161,7 @@ fn image(debug: bool) -> Result<(), DynError> {
|
|||
|
||||
fn run(debug: bool) -> Result<(), DynError> {
|
||||
let stream = if debug { "debug" } else { "release" };
|
||||
let init = ["shell", "log-server", "graphics-server"];
|
||||
let init = ["shell", "log-server", "graphics-server", "ticktimer-server"];
|
||||
|
||||
// let mut init_paths = vec![];
|
||||
for pkg in &init {
|
||||
|
|
|
|||
Loading…
Reference in a new issue