mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
move more crates into standard formatting
This commit is contained in:
parent
c0ce66ee51
commit
323b2ed261
3 changed files with 108 additions and 66 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
ignore = [
|
ignore = [
|
||||||
"services/aes-test",
|
"services/aes-test",
|
||||||
"services/graphics-server",
|
"services/graphics-server",
|
||||||
"services/log-server",
|
|
||||||
"services/ticktimer-server",
|
|
||||||
"services/com",
|
"services/com",
|
||||||
"services/xous-names",
|
"services/xous-names",
|
||||||
"services/keyboard",
|
"services/keyboard",
|
||||||
|
|
@ -14,8 +12,6 @@ ignore = [
|
||||||
"services/ime-frontend",
|
"services/ime-frontend",
|
||||||
"services/ime-plugin-shell",
|
"services/ime-plugin-shell",
|
||||||
"services/shellchat",
|
"services/shellchat",
|
||||||
"imports/blitstr-ref",
|
|
||||||
"imports/com_rs-ref",
|
|
||||||
"services/ime-plugin-api",
|
"services/ime-plugin-api",
|
||||||
"services/content-plugin-api",
|
"services/content-plugin-api",
|
||||||
"services/llio",
|
"services/llio",
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
|
|
||||||
use xous::{send_message, Error, CID};
|
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
use xous::{send_message, Error, CID};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Ticktimer {
|
pub struct Ticktimer {
|
||||||
|
|
@ -13,36 +13,52 @@ impl Ticktimer {
|
||||||
pub fn new() -> Result<Self, Error> {
|
pub fn new() -> Result<Self, Error> {
|
||||||
REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
|
REFCOUNT.store(REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
|
||||||
let conn = xous::connect(xous::SID::from_bytes(b"ticktimer-server").unwrap())?;
|
let conn = xous::connect(xous::SID::from_bytes(b"ticktimer-server").unwrap())?;
|
||||||
Ok(Ticktimer {
|
Ok(Ticktimer { conn })
|
||||||
conn,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// note special case for elapsed_ms() is "infalliable". it really should never fail so get rid of the Error
|
/// note special case for elapsed_ms() is "infalliable". it really should never fail so get rid of the Error
|
||||||
pub fn elapsed_ms(&self) -> u64 {
|
pub fn elapsed_ms(&self) -> u64 {
|
||||||
let response = send_message(self.conn,
|
let response = send_message(
|
||||||
xous::Message::new_blocking_scalar(api::Opcode::ElapsedMs.to_usize().unwrap(),
|
self.conn,
|
||||||
0, 0, 0, 0,
|
xous::Message::new_blocking_scalar(
|
||||||
)).expect("Ticktimer: failure to send message to Ticktimer");
|
api::Opcode::ElapsedMs.to_usize().unwrap(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.expect("Ticktimer: failure to send message to Ticktimer");
|
||||||
if let xous::Result::Scalar2(upper, lower) = response {
|
if let xous::Result::Scalar2(upper, lower) = response {
|
||||||
upper as u64 | ((lower as u64) << 32)
|
upper as u64 | ((lower as u64) << 32)
|
||||||
} else {
|
} else {
|
||||||
panic!("Ticktimer elapsed_ms(): unexpected return value: {:#?}", response);
|
panic!(
|
||||||
|
"Ticktimer elapsed_ms(): unexpected return value: {:#?}",
|
||||||
|
response
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sleep_ms(&self, ms: usize) -> Result<(), Error> {
|
pub fn sleep_ms(&self, ms: usize) -> Result<(), Error> {
|
||||||
send_message(self.conn,
|
send_message(
|
||||||
xous::Message::new_blocking_scalar(api::Opcode::SleepMs.to_usize().unwrap(),
|
self.conn,
|
||||||
ms,
|
xous::Message::new_blocking_scalar(
|
||||||
0, 0, 0)
|
api::Opcode::SleepMs.to_usize().unwrap(),
|
||||||
).map(|_| ())
|
ms,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ping_wdt(&self) {
|
pub fn ping_wdt(&self) {
|
||||||
send_message(self.conn,
|
send_message(
|
||||||
xous::Message::new_scalar(api::Opcode::PingWdt.to_usize().unwrap(), 0, 0, 0, 0)
|
self.conn,
|
||||||
).expect("Couldn't send WDT ping");
|
xous::Message::new_scalar(api::Opcode::PingWdt.to_usize().unwrap(), 0, 0, 0, 0),
|
||||||
|
)
|
||||||
|
.expect("Couldn't send WDT ping");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
@ -51,7 +67,9 @@ impl Drop for Ticktimer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the connection.
|
// de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the connection.
|
||||||
if REFCOUNT.load(Ordering::Relaxed) == 0 {
|
if REFCOUNT.load(Ordering::Relaxed) == 0 {
|
||||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
unsafe {
|
||||||
|
xous::disconnect(self.conn).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
#![cfg_attr(not(target_os = "none"), allow(dead_code))]
|
#![cfg_attr(not(target_os = "none"), allow(dead_code))]
|
||||||
|
|
||||||
#![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)]
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
|
|
||||||
use std::collections::BinaryHeap;
|
|
||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
|
use std::collections::BinaryHeap;
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
|
||||||
|
|
@ -56,15 +55,15 @@ impl core::cmp::PartialEq for SleepRequest {
|
||||||
mod implementation {
|
mod implementation {
|
||||||
const TICKS_PER_MS: u64 = 1;
|
const TICKS_PER_MS: u64 = 1;
|
||||||
use super::SleepRequest;
|
use super::SleepRequest;
|
||||||
use utralib::generated::*;
|
|
||||||
use susres::{RegManager, RegOrField, SuspendResume};
|
use susres::{RegManager, RegOrField, SuspendResume};
|
||||||
|
use utralib::generated::*;
|
||||||
|
|
||||||
pub struct XousTickTimer {
|
pub struct XousTickTimer {
|
||||||
csr: utralib::CSR<u32>,
|
csr: utralib::CSR<u32>,
|
||||||
current_response: Option<SleepRequest>,
|
current_response: Option<SleepRequest>,
|
||||||
connection: xous::CID,
|
connection: xous::CID,
|
||||||
ticktimer_sr_manager: RegManager::<{utra::ticktimer::TICKTIMER_NUMREGS}>,
|
ticktimer_sr_manager: RegManager<{ utra::ticktimer::TICKTIMER_NUMREGS }>,
|
||||||
wdt_sr_manager: RegManager::<{utra::wdt::WDT_NUMREGS}>,
|
wdt_sr_manager: RegManager<{ utra::wdt::WDT_NUMREGS }>,
|
||||||
wdt: utralib::CSR<u32>,
|
wdt: utralib::CSR<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,12 +108,17 @@ mod implementation {
|
||||||
// This is dangerous and may return an error if the queue is full.
|
// This is dangerous and may return an error if the queue is full.
|
||||||
// Which is fine, because the queue is always recalculated any time a message arrives.
|
// Which is fine, because the queue is always recalculated any time a message arrives.
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
xous::try_send_message(xtt.connection,
|
xous::try_send_message(
|
||||||
|
xtt.connection,
|
||||||
xous::Message::Scalar(xous::ScalarMessage {
|
xous::Message::Scalar(xous::ScalarMessage {
|
||||||
id: crate::api::Opcode::RecalculateSleep.to_usize().unwrap(),
|
id: crate::api::Opcode::RecalculateSleep.to_usize().unwrap(),
|
||||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0
|
arg1: 0,
|
||||||
})
|
arg2: 0,
|
||||||
).ok();
|
arg3: 0,
|
||||||
|
arg4: 0,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XousTickTimer {
|
impl XousTickTimer {
|
||||||
|
|
@ -171,18 +175,24 @@ mod implementation {
|
||||||
#[cfg(feature = "watchdog")]
|
#[cfg(feature = "watchdog")]
|
||||||
{
|
{
|
||||||
xtt.wdt.wfo(utra::wdt::EV_ENABLE_SOFT_INT, 1);
|
xtt.wdt.wfo(utra::wdt::EV_ENABLE_SOFT_INT, 1);
|
||||||
xtt.wdt_sr_manager.push(RegOrField::Reg(utra::wdt::EV_ENABLE), None);
|
xtt.wdt_sr_manager
|
||||||
|
.push(RegOrField::Reg(utra::wdt::EV_ENABLE), None);
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "watchdog"))]
|
#[cfg(not(feature = "watchdog"))]
|
||||||
{
|
{
|
||||||
xtt.wdt.wfo(utra::wdt::EV_ENABLE_SOFT_INT, 0);
|
xtt.wdt.wfo(utra::wdt::EV_ENABLE_SOFT_INT, 0);
|
||||||
xtt.wdt_sr_manager.push(RegOrField::Reg(utra::wdt::EV_ENABLE), None);
|
xtt.wdt_sr_manager
|
||||||
|
.push(RegOrField::Reg(utra::wdt::EV_ENABLE), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
xtt.ticktimer_sr_manager.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET0), None);
|
xtt.ticktimer_sr_manager
|
||||||
xtt.ticktimer_sr_manager.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET1), None);
|
.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET0), None);
|
||||||
xtt.ticktimer_sr_manager.push_fixed_value(RegOrField::Reg(utra::ticktimer::EV_PENDING), 0xFFFF_FFFF);
|
xtt.ticktimer_sr_manager
|
||||||
xtt.ticktimer_sr_manager.push(RegOrField::Reg(utra::ticktimer::EV_ENABLE), None);
|
.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET1), None);
|
||||||
|
xtt.ticktimer_sr_manager
|
||||||
|
.push_fixed_value(RegOrField::Reg(utra::ticktimer::EV_PENDING), 0xFFFF_FFFF);
|
||||||
|
xtt.ticktimer_sr_manager
|
||||||
|
.push(RegOrField::Reg(utra::ticktimer::EV_ENABLE), None);
|
||||||
|
|
||||||
xtt
|
xtt
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +274,11 @@ mod implementation {
|
||||||
pub fn check_wdt(&mut self) {
|
pub fn check_wdt(&mut self) {
|
||||||
let state = self.wdt.r(utra::wdt::STATE);
|
let state = self.wdt.r(utra::wdt::STATE);
|
||||||
if state & self.wdt.ms(utra::wdt::STATE_DISARMED, 1) == 0 {
|
if state & self.wdt.ms(utra::wdt::STATE_DISARMED, 1) == 0 {
|
||||||
log::info!("{} WDT is not disarmed, state: 0x{:x}", self.elapsed_ms(), state);
|
log::info!(
|
||||||
|
"{} WDT is not disarmed, state: 0x{:x}",
|
||||||
|
self.elapsed_ms(),
|
||||||
|
state
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -297,8 +311,15 @@ mod implementation {
|
||||||
#[cfg(feature = "watchdog")]
|
#[cfg(feature = "watchdog")]
|
||||||
self.wdt.wfo(utra::wdt::INTERRUPT_INTERRUPT, 1);
|
self.wdt.wfo(utra::wdt::INTERRUPT_INTERRUPT, 1);
|
||||||
|
|
||||||
log::trace!("ticktimer enable: {}", self.csr.r(utra::ticktimer::EV_ENABLE));
|
log::trace!(
|
||||||
log::trace!("ticktimer time/target: {}/{}", self.csr.r(utra::ticktimer::TIME0), self.csr.r(utra::ticktimer::MSLEEP_TARGET0));
|
"ticktimer enable: {}",
|
||||||
|
self.csr.r(utra::ticktimer::EV_ENABLE)
|
||||||
|
);
|
||||||
|
log::trace!(
|
||||||
|
"ticktimer time/target: {}/{}",
|
||||||
|
self.csr.r(utra::ticktimer::TIME0),
|
||||||
|
self.csr.r(utra::ticktimer::MSLEEP_TARGET0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -306,8 +327,8 @@ mod implementation {
|
||||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||||
mod implementation {
|
mod implementation {
|
||||||
use super::SleepRequest;
|
use super::SleepRequest;
|
||||||
use std::convert::TryInto;
|
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum SleepComms {
|
enum SleepComms {
|
||||||
|
|
@ -350,8 +371,11 @@ mod implementation {
|
||||||
cid,
|
cid,
|
||||||
xous::Message::Scalar(xous::ScalarMessage {
|
xous::Message::Scalar(xous::ScalarMessage {
|
||||||
id: crate::api::Opcode::RecalculateSleep.to_usize().unwrap(),
|
id: crate::api::Opcode::RecalculateSleep.to_usize().unwrap(),
|
||||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0
|
arg1: 0,
|
||||||
})
|
arg2: 0,
|
||||||
|
arg3: 0,
|
||||||
|
arg4: 0,
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
timeout = None;
|
timeout = None;
|
||||||
|
|
@ -435,14 +459,15 @@ mod implementation {
|
||||||
pub fn reset_wdt(&self) {
|
pub fn reset_wdt(&self) {
|
||||||
// dummy function, does nothing
|
// dummy function, does nothing
|
||||||
}
|
}
|
||||||
pub fn register_suspend_listener(&self, _opcode: u32, _cid: xous::CID) -> Result<(), xous::Error> {
|
pub fn register_suspend_listener(
|
||||||
|
&self,
|
||||||
|
_opcode: u32,
|
||||||
|
_cid: xous::CID,
|
||||||
|
) -> Result<(), xous::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn suspend(&self) {
|
pub fn suspend(&self) {}
|
||||||
}
|
pub fn resume(&self) {}
|
||||||
pub fn resume(&self) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -472,8 +497,7 @@ fn recalculate_sleep(
|
||||||
|
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(feature = "debug-print")]
|
||||||
info!("Modified, the request was: {:?}", request);
|
info!("Modified, the request was: {:?}", request);
|
||||||
sleep_heap
|
sleep_heap.push(Reverse(request));
|
||||||
.push(Reverse(request));
|
|
||||||
} else {
|
} else {
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(feature = "debug-print")]
|
||||||
info!("No new sleep request");
|
info!("No new sleep request");
|
||||||
|
|
@ -512,8 +536,10 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
// register a suspend/resume listener
|
// register a suspend/resume listener
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
let sr_cid = xous::connect(ticktimer_server).expect("couldn't create suspend callback connection");
|
let sr_cid =
|
||||||
let mut susres = susres::Susres::new(&xns, api::Opcode::SuspendResume as u32, sr_cid).expect("couldn't create suspend/resume object");
|
xous::connect(ticktimer_server).expect("couldn't create suspend callback connection");
|
||||||
|
let mut susres = susres::Susres::new(&xns, api::Opcode::SuspendResume as u32, sr_cid)
|
||||||
|
.expect("couldn't create suspend/resume object");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
#[cfg(feature = "watchdog")]
|
#[cfg(feature = "watchdog")]
|
||||||
|
|
@ -534,29 +560,31 @@ fn xmain() -> ! {
|
||||||
.expect("couldn't return time request");
|
.expect("couldn't return time request");
|
||||||
}
|
}
|
||||||
Some(api::Opcode::SleepMs) => xous::msg_blocking_scalar_unpack!(msg, ms, _, _, _, {
|
Some(api::Opcode::SleepMs) => xous::msg_blocking_scalar_unpack!(msg, ms, _, _, _, {
|
||||||
recalculate_sleep(
|
recalculate_sleep(
|
||||||
&mut ticktimer,
|
&mut ticktimer,
|
||||||
&mut sleep_heap,
|
&mut sleep_heap,
|
||||||
Some(SleepRequest {
|
Some(SleepRequest {
|
||||||
msec: ms as i64,
|
msec: ms as i64,
|
||||||
sender: msg.sender,
|
sender: msg.sender,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
Some(api::Opcode::RecalculateSleep) => {
|
Some(api::Opcode::RecalculateSleep) => {
|
||||||
recalculate_sleep(&mut ticktimer, &mut sleep_heap, None);
|
recalculate_sleep(&mut ticktimer, &mut sleep_heap, None);
|
||||||
},
|
}
|
||||||
Some(api::Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
Some(api::Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, {
|
||||||
ticktimer.suspend();
|
ticktimer.suspend();
|
||||||
susres.suspend_until_resume(token).expect("couldn't execute suspend/resume");
|
susres
|
||||||
|
.suspend_until_resume(token)
|
||||||
|
.expect("couldn't execute suspend/resume");
|
||||||
ticktimer.resume();
|
ticktimer.resume();
|
||||||
}),
|
}),
|
||||||
Some(api::Opcode::PingWdt) => {
|
Some(api::Opcode::PingWdt) => {
|
||||||
ticktimer.reset_wdt();
|
ticktimer.reset_wdt();
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
error!("couldn't convert opcode");
|
error!("couldn't convert opcode");
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue