mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
get non-blocking gas gauge checking working
This commit is contained in:
parent
bb6dcd07a4
commit
b568d86153
6 changed files with 45 additions and 37 deletions
|
|
@ -142,8 +142,8 @@ impl Into<Message> for Opcode {
|
|||
let raw_stats: [usize; 2] = stats.into();
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: ComState::STAT_RETURN.verb as usize,
|
||||
arg1: raw_stats[1],
|
||||
arg2: raw_stats[0],
|
||||
arg1: raw_stats[0],
|
||||
arg2: raw_stats[1],
|
||||
arg3: 0,
|
||||
arg4: 0,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,10 +14,15 @@ use log::{error, info};
|
|||
|
||||
use com_rs::*;
|
||||
|
||||
use xous::CID;
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct WorkRequest {
|
||||
work: ComSpec,
|
||||
sender: xous::MessageSender,
|
||||
sender: CID,
|
||||
}
|
||||
|
||||
fn return_battstats(cid: CID, stats: api::BattStats) -> Result<(), xous::Error> {
|
||||
xous::send_message(cid, crate::api::Opcode::BattStatsReturn(stats).into()).map(|_| ())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "none")]
|
||||
|
|
@ -29,6 +34,7 @@ mod implementation {
|
|||
use utralib::generated::*;
|
||||
use xous::CID;
|
||||
use log::{error, info};
|
||||
use crate::return_battstats;
|
||||
|
||||
#[macro_use]
|
||||
use heapless::Vec;
|
||||
|
|
@ -55,10 +61,6 @@ mod implementation {
|
|||
xc.csr.wo(utra::com::EV_PENDING, xc.csr.r(utra::com::EV_PENDING));
|
||||
}
|
||||
|
||||
fn return_battstats(cid: CID, stats: BattStats) -> Result<(), xous::Error> {
|
||||
xous::send_message(cid, crate::api::Opcode::BattStatsReturn(stats).into()).map(|_| ())
|
||||
}
|
||||
|
||||
impl XousCom {
|
||||
pub fn new() -> XousCom {
|
||||
let csr = xous::syscall::map_memory(
|
||||
|
|
@ -127,15 +129,13 @@ mod implementation {
|
|||
self.txrx(tx)
|
||||
}
|
||||
|
||||
|
||||
pub fn process_queue(&mut self) {
|
||||
fn process_queue(&mut self) {
|
||||
if !self.workqueue.is_empty() && !self.busy {
|
||||
self.busy = true;
|
||||
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless")
|
||||
if work_descriptor.work.verb == ComState::STAT.verb {
|
||||
let stats = self.get_battstats();
|
||||
return_battstats(work_descriptor.sender, stats).expect("Could not return BattStatsNb value");
|
||||
info!("Returned BattStatsNb value");
|
||||
} else {
|
||||
error!("unimplemented work queue responder 0x{:x}", work_descriptor.work.verb);
|
||||
}
|
||||
|
|
@ -168,13 +168,15 @@ mod implementation {
|
|||
use crate::api::BattStats;
|
||||
use crate::WorkRequest;
|
||||
use log::{error, info};
|
||||
use com_rs::*;
|
||||
use crate::return_battstats;
|
||||
|
||||
#[macro_use]
|
||||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
|
||||
pub struct XousCom {
|
||||
workqueue: Vec<WorkRequest, U64>,
|
||||
pub workqueue: Vec<WorkRequest, U64>,
|
||||
busy: bool,
|
||||
}
|
||||
|
||||
|
|
@ -205,8 +207,7 @@ mod implementation {
|
|||
let work_descriptor = self.workqueue.swap_remove(0); // not quite FIFO, but Vec does not support FIFO (best we can do with "heapless")
|
||||
if work_descriptor.work.verb == ComState::STAT.verb {
|
||||
let stats = self.get_battstats();
|
||||
shell::return_battstats(work_descriptor.sender, stats).expect("Could not return BattStatsNb value");
|
||||
info!("Returned BattStatsNb value");
|
||||
return_battstats(work_descriptor.sender, stats).expect("Could not return BattStatsNb value");
|
||||
} else {
|
||||
error!("unimplemented work queue responder 0x{:x}", work_descriptor.work.verb);
|
||||
}
|
||||
|
|
@ -223,6 +224,8 @@ fn xmain() -> ! {
|
|||
println!("COM Init");
|
||||
log_server::init_wait().unwrap();
|
||||
|
||||
let shell_id = xous::SID::from_bytes(b"shell ").unwrap();
|
||||
let shell_conn = xous::connect(shell_id).unwrap();
|
||||
let com_server =
|
||||
xous::create_server(b"com ").expect("Couldn't create COM server");
|
||||
|
||||
|
|
@ -252,8 +255,7 @@ fn xmain() -> ! {
|
|||
info!("COM: done returning batt stats request");
|
||||
}
|
||||
Opcode::BattStatsNb => {
|
||||
info!("COM: batt stats non-blocking request received");
|
||||
com.workqueue.push(WorkRequest { work: ComState::STAT, sender: envelope.sender }).unwrap();
|
||||
com.workqueue.push(WorkRequest { work: ComState::STAT, sender: shell_conn }).unwrap();
|
||||
}
|
||||
_ => error!("unknown opcode"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,6 @@ utralib = { path = "../../utralib"}
|
|||
|
||||
[features]
|
||||
debugprint = []
|
||||
#default = []
|
||||
default = ["debugprint"]
|
||||
logging = []
|
||||
default = ["logging"]
|
||||
#default = ["debugprint"]
|
||||
|
|
|
|||
|
|
@ -40,7 +40,9 @@ impl XousLoggerBacking {
|
|||
}
|
||||
if let Some(ref mut buf) = self.buffer {
|
||||
buf.clear();
|
||||
write!(buf, "{} - {}", record.level(), record.args()).unwrap();
|
||||
if cfg!(feature="logging") {
|
||||
write!(buf, "{} - {}", record.level(), record.args()).unwrap();
|
||||
}
|
||||
buf.lend(self.conn, 1).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,12 +123,14 @@ fn shell_main() -> ! {
|
|||
timer::init();
|
||||
log_server::init_wait().unwrap();
|
||||
|
||||
let shell_server = xous::create_server(b"shell ").expect("Couldn't create Shell server");
|
||||
|
||||
// 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();
|
||||
let log_server_id = xous::SID::from_bytes(b"xous-log-server ").unwrap();
|
||||
let com_id = xous::SID::from_bytes(b"com ").unwrap();
|
||||
let shell_id = xous::SID::from_bytes(b"shel ").unwrap();
|
||||
let shell_id = xous::SID::from_bytes(b"shell ").unwrap();
|
||||
|
||||
println!("SHELL: Attempting to connect to servers...");
|
||||
let log_conn = xous::connect(log_server_id).unwrap();
|
||||
|
|
@ -173,7 +175,7 @@ fn shell_main() -> ! {
|
|||
)
|
||||
.expect("couldn't map GPIO CSR range");
|
||||
let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
|
||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0);
|
||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 1);
|
||||
}
|
||||
|
||||
graphics_server::set_style(
|
||||
|
|
@ -190,10 +192,10 @@ fn shell_main() -> ! {
|
|||
loop {
|
||||
// update battery status periodically
|
||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
||||
info!("SHELL: {}ms", elapsed_time);
|
||||
if elapsed_time - last_time > 500 {
|
||||
last_time = elapsed_time;
|
||||
batt_stats = get_batt_stats(com_conn).expect("Can't get battery stats from COM");
|
||||
info!("Requesting batt stats from COM");
|
||||
get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
||||
}
|
||||
} else {
|
||||
error!("error requesting ticktimer!")
|
||||
|
|
@ -225,15 +227,16 @@ fn shell_main() -> ! {
|
|||
|
||||
graphics_server::flush(graphics_conn).expect("unable to draw to screen");
|
||||
|
||||
/*
|
||||
let envelope = xous::receive_message(shell_id).unwrap();
|
||||
if let Ok(opcode) = com::api::Opcode::try_from(&envelope.body) {
|
||||
match opcode {
|
||||
com::api::Opcode::BattStatsReturn(stats) => {
|
||||
batt_stats = stats;
|
||||
},
|
||||
_ => error!("SHELL: received unexpected opcode"),
|
||||
let envelope = xous::try_receive_message(shell_server).unwrap();
|
||||
if envelope.is_some() {
|
||||
if let Ok(opcode) = com::api::Opcode::try_from(&envelope.unwrap().body) {
|
||||
match opcode {
|
||||
com::api::Opcode::BattStatsReturn(stats) => {
|
||||
batt_stats = stats;
|
||||
},
|
||||
_ => error!("SHELL: received unexpected opcode"),
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,11 +281,11 @@ fn xmain() -> ! {
|
|||
let mut ticktimer = XousTickTimer::new(ticktimer_client);
|
||||
|
||||
loop {
|
||||
info!("TickTimer: waiting for message");
|
||||
//info!("TickTimer: waiting for message");
|
||||
let envelope = xous::receive_message(ticktimer_server).unwrap();
|
||||
info!("TickTimer: Message: {:?}", envelope);
|
||||
//info!("TickTimer: Message: {:?}", envelope);
|
||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||
info!("TickTimer: Opcode: {:?}", opcode);
|
||||
//info!("TickTimer: Opcode: {:?}", opcode);
|
||||
match opcode {
|
||||
Opcode::Reset => {
|
||||
info!("TickTimer: reset called");
|
||||
|
|
@ -293,14 +293,14 @@ fn xmain() -> ! {
|
|||
}
|
||||
Opcode::ElapsedMs => {
|
||||
let time = ticktimer.elapsed_ms();
|
||||
info!("TickTimer: returning time of {:?}", time);
|
||||
//info!("TickTimer: returning time of {:?}", time);
|
||||
xous::return_scalar2(
|
||||
envelope.sender,
|
||||
(time & 0xFFFF_FFFFu64) as usize,
|
||||
((time >> 32) & 0xFFF_FFFFu64) as usize,
|
||||
)
|
||||
.expect("TickTimer: couldn't return time request");
|
||||
info!("TickTimer: done returning value");
|
||||
//info!("TickTimer: done returning value");
|
||||
}
|
||||
Opcode::SleepMs(ms) => recalculate_sleep(
|
||||
&mut ticktimer,
|
||||
|
|
@ -312,7 +312,7 @@ fn xmain() -> ! {
|
|||
),
|
||||
Opcode::RecalculateSleep => {
|
||||
recalculate_sleep(&mut ticktimer, &mut sleep_heap, None);
|
||||
info!("TickTimer: Done recalculating");
|
||||
//info!("TickTimer: Done recalculating");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue