mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
debugging ticktimer
This commit is contained in:
parent
1bb674f6b5
commit
6e6a8a4b08
10 changed files with 162 additions and 30 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -281,6 +281,7 @@ dependencies = [
|
||||||
name = "log-server"
|
name = "log-server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"utralib",
|
||||||
"xous",
|
"xous",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,7 @@ xous = { path = "../../xous-rs" }
|
||||||
|
|
||||||
#[target.'cfg(any(windows, unix))'.dependencies]
|
#[target.'cfg(any(windows, unix))'.dependencies]
|
||||||
#pancurses = "*"
|
#pancurses = "*"
|
||||||
|
|
||||||
|
|
||||||
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
|
utralib = { path = "../../utralib"}
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,7 @@ ticktimer-server = { path = "../ticktimer-server" }
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = { path = "../../utralib"}
|
utralib = { path = "../../utralib"}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
debugprint = []
|
||||||
|
default = [] # "debugprint"
|
||||||
|
|
|
||||||
|
|
@ -42,33 +42,35 @@ pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
impl Uart {
|
impl Uart {
|
||||||
pub fn putc(&self, c: u8) {
|
pub fn putc(&self, c: u8) {
|
||||||
unsafe {
|
if cfg!(feature = "debugprint") {
|
||||||
if DEFAULT_UART_ADDR as usize == 0 {
|
unsafe {
|
||||||
let uart = xous::syscall::map_memory(
|
if DEFAULT_UART_ADDR as usize == 0 {
|
||||||
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
let uart = xous::syscall::map_memory(
|
||||||
None,
|
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||||
4096,
|
None,
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
4096,
|
||||||
)
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
.expect("couldn't map uart");
|
)
|
||||||
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
.expect("couldn't map uart");
|
||||||
println!("Mapped UART @ {:08x}", uart.addr.get());
|
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
||||||
// core::mem::forget(uart);
|
println!("Mapped UART @ {:08x}", uart.addr.get());
|
||||||
|
// core::mem::forget(uart);
|
||||||
|
|
||||||
println!("Allocating IRQ...");
|
println!("Allocating IRQ...");
|
||||||
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
self.enable_rx();
|
self.enable_rx();
|
||||||
}
|
}
|
||||||
let base = DEFAULT_UART_ADDR;
|
let base = DEFAULT_UART_ADDR;
|
||||||
let mut uart_csr = CSR::new(DEFAULT_UART_ADDR as *mut u32);
|
let mut uart_csr = CSR::new(DEFAULT_UART_ADDR as *mut u32);
|
||||||
|
|
||||||
// Wait until TXFULL is `0`
|
// Wait until TXFULL is `0`
|
||||||
while uart_csr.r(utra::console::TXFULL) != 0 {}
|
while uart_csr.r(utra::console::TXFULL) != 0 {}
|
||||||
uart_csr.wo(utra::console::RXTX, c as u32);
|
uart_csr.wo(utra::console::RXTX, c as u32);
|
||||||
/*
|
/*
|
||||||
while base.add(1).read_volatile() != 0 {}
|
while base.add(1).read_volatile() != 0 {}
|
||||||
base.add(0).write_volatile(c as usize)*/
|
base.add(0).write_volatile(c as usize)*/
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_rx(&self) {
|
pub fn enable_rx(&self) {
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,10 @@ fn shell_main() -> ! {
|
||||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0);
|
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
//let elapsed_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
//println!("loop");
|
||||||
//println!("elapsed time: {}ms", elapsed_time);
|
println!("ticktimer request");
|
||||||
|
let elapsed_time = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||||
|
println!("elapsed time: {}ms", elapsed_time);
|
||||||
|
|
||||||
// println!("Sending a scalar message with id {}...", counter + 4096);
|
// println!("Sending a scalar message with id {}...", counter + 4096);
|
||||||
// match xous::syscall::send_message(
|
// match xous::syscall::send_message(
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ const TIMER_BASE: usize = utra::timer0::HW_TIMER0_BASE; // claim the same addres
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
fn timer_tick(_irq_no: usize, _arg: *mut usize) {
|
fn timer_tick(_irq_no: usize, _arg: *mut usize) {
|
||||||
println!(">>> Timer tick");
|
//println!(">>> Timer tick");
|
||||||
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
||||||
|
|
||||||
xous::rsyscall(xous::SysCall::ReturnToParentI(xous::PID::new(1).unwrap(), 0)).expect("couldn't return to parent");
|
xous::rsyscall(xous::SysCall::ReturnToParentI(xous::PID::new(1).unwrap(), 0)).expect("couldn't return to parent");
|
||||||
|
|
||||||
// acknowledge the timer
|
// acknowledge the timer
|
||||||
timer.wfo(utra::timer0::EV_PENDING_PENDING, 0b1);
|
timer.wfo(utra::timer0::EV_PENDING_PENDING, 0b1);
|
||||||
println!("<<< Returning from timer_tick()");
|
//println!("<<< Returning from timer_tick()");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,7 @@ embedded-graphics = "0.6"
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = { path = "../../utralib"}
|
utralib = { path = "../../utralib"}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
debugprint = []
|
||||||
|
default = ["debugprint"]
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ impl Into<Message> for Opcode {
|
||||||
arg3: 0,
|
arg3: 0,
|
||||||
arg4: 0,
|
arg4: 0,
|
||||||
}),
|
}),
|
||||||
Opcode::ElapsedMs => Message::Scalar(ScalarMessage {
|
Opcode::ElapsedMs => Message::BlockingScalar(ScalarMessage {
|
||||||
id: 2,
|
id: 2,
|
||||||
arg1: 0,
|
arg1: 0,
|
||||||
arg2: 0,
|
arg2: 0,
|
||||||
|
|
|
||||||
108
examples/ticktimer-server/src/debug.rs
Normal file
108
examples/ticktimer-server/src/debug.rs
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
use core::fmt::{Error, Write};
|
||||||
|
|
||||||
|
use utralib::generated::*;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! print
|
||||||
|
{
|
||||||
|
($($args:tt)+) => ({
|
||||||
|
use core::fmt::Write;
|
||||||
|
let _ = write!(crate::debug::DEFAULT, $($args)+);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! println
|
||||||
|
{
|
||||||
|
() => ({
|
||||||
|
print!("\r\n")
|
||||||
|
});
|
||||||
|
($fmt:expr) => ({
|
||||||
|
print!(concat!($fmt, "\r\n"))
|
||||||
|
});
|
||||||
|
($fmt:expr, $($args:tt)+) => ({
|
||||||
|
print!(concat!($fmt, "\r\n"), $($args)+)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn handle_irq(irq_no: usize, arg: *mut usize) {
|
||||||
|
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
|
||||||
|
|
||||||
|
while let Some(c) = crate::debug::DEFAULT.getc() {
|
||||||
|
print!("0x{:02x}", c);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Uart {}
|
||||||
|
|
||||||
|
pub static mut DEFAULT_UART_ADDR: *mut usize = 0x0000_0000 as *mut usize;
|
||||||
|
|
||||||
|
pub const DEFAULT: Uart = Uart {};
|
||||||
|
|
||||||
|
impl Uart {
|
||||||
|
pub fn putc(&self, c: u8) {
|
||||||
|
if cfg!(feature = "debugprint") {
|
||||||
|
unsafe {
|
||||||
|
if DEFAULT_UART_ADDR as usize == 0 {
|
||||||
|
let uart = xous::syscall::map_memory(
|
||||||
|
xous::MemoryAddress::new(utra::console::HW_CONSOLE_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map uart");
|
||||||
|
DEFAULT_UART_ADDR = uart.as_mut_ptr() as _;
|
||||||
|
println!("Mapped UART @ {:08x}", uart.addr.get());
|
||||||
|
// core::mem::forget(uart);
|
||||||
|
|
||||||
|
println!("Allocating IRQ...");
|
||||||
|
xous::claim_interrupt(utra::console::CONSOLE_IRQ, handle_irq, core::ptr::null_mut::<usize>()).expect("unable to allocate IRQ");
|
||||||
|
self.enable_rx();
|
||||||
|
}
|
||||||
|
let base = DEFAULT_UART_ADDR;
|
||||||
|
let mut uart_csr = CSR::new(DEFAULT_UART_ADDR as *mut u32);
|
||||||
|
|
||||||
|
// Wait until TXFULL is `0`
|
||||||
|
while uart_csr.r(utra::console::TXFULL) != 0 {}
|
||||||
|
uart_csr.wo(utra::console::RXTX, c as u32);
|
||||||
|
/*
|
||||||
|
while base.add(1).read_volatile() != 0 {}
|
||||||
|
base.add(0).write_volatile(c as usize)*/
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enable_rx(&self) {
|
||||||
|
unsafe {
|
||||||
|
// let base = DEFAULT_UART_ADDR;
|
||||||
|
// base.add(5).write_volatile(base.add(5).read_volatile() | 2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getc(&self) -> Option<u8> {
|
||||||
|
// unsafe {
|
||||||
|
// let base = DEFAULT_UART_ADDR;
|
||||||
|
// // If EV_PENDING_RX is 1, return the pending character.
|
||||||
|
// // Otherwise, return None.
|
||||||
|
// match base.add(4).read_volatile() & 2 {
|
||||||
|
// 0 => None,
|
||||||
|
// ack => {
|
||||||
|
// let c = Some(base.add(0).read_volatile() as u8);
|
||||||
|
// base.add(4).write_volatile(ack);
|
||||||
|
// c
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Write for Uart {
|
||||||
|
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||||
|
for c in s.bytes() {
|
||||||
|
self.putc(c);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
#![cfg_attr(target_os = "none", no_std)]
|
||||||
#![cfg_attr(target_os = "none", no_main)]
|
#![cfg_attr(target_os = "none", no_main)]
|
||||||
|
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod debug;
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
use api::Opcode;
|
use api::Opcode;
|
||||||
|
|
||||||
|
|
@ -53,7 +57,9 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
let ticktimer_server = xous::create_server(b"ticktimer-server").expect("Couldn't create Ticktimer server");
|
let ticktimer_server = xous::create_server(b"ticktimer-server").expect("Couldn't create Ticktimer server");
|
||||||
loop {
|
loop {
|
||||||
|
println!("TickTimer: waiting for message");
|
||||||
let envelope = xous::receive_message(ticktimer_server).unwrap();
|
let envelope = xous::receive_message(ticktimer_server).unwrap();
|
||||||
|
println!("TickTimer: got message");
|
||||||
// println!("TickTimer: Message: {:?}", envelope);
|
// println!("TickTimer: Message: {:?}", envelope);
|
||||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||||
// println!("TickTimer: Opcode: {:?}", opcode);
|
// println!("TickTimer: Opcode: {:?}", opcode);
|
||||||
|
|
@ -63,6 +69,7 @@ fn xmain() -> ! {
|
||||||
},
|
},
|
||||||
Opcode::ElapsedMs => {
|
Opcode::ElapsedMs => {
|
||||||
let time = ticktimer.elapsed_ms();
|
let time = ticktimer.elapsed_ms();
|
||||||
|
println!("TickTimer: returning time of {:?}", time);
|
||||||
xous::return_scalar2(envelope.sender,
|
xous::return_scalar2(envelope.sender,
|
||||||
(time & 0xFFFF_FFFFu64) as usize,
|
(time & 0xFFFF_FFFFu64) as usize,
|
||||||
((time >> 32) & 0xFFF_FFFFu64) as usize,
|
((time >> 32) & 0xFFF_FFFFu64) as usize,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue