mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
some progress, but check in to recreate previous crash
This commit is contained in:
parent
a9de4782c5
commit
856934c2c9
4 changed files with 45 additions and 27 deletions
|
|
@ -102,6 +102,7 @@ impl Drop for Rtc {
|
|||
|
||||
fn rtc_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||
log::trace!("rtc callback server started");
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
log::trace!("rtc callback got msg: {:?}", msg);
|
||||
|
|
|
|||
|
|
@ -59,10 +59,10 @@ pub struct CommonEnv {
|
|||
|
||||
///// 1. add your module here, and pull its namespace into the local crate
|
||||
mod echo; use echo::*;
|
||||
mod test; use test::*;
|
||||
//mod test; use test::*;
|
||||
mod sleep; use sleep::*;
|
||||
mod sensors; use sensors::*;
|
||||
mod callback; use callback::*;
|
||||
//mod callback; use callback::*;
|
||||
mod rtc_cmd; use rtc_cmd::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -70,10 +70,10 @@ pub struct CmdEnv {
|
|||
common_env: CommonEnv,
|
||||
lastverb: String::<256>,
|
||||
///// 2. declare storage for your command here.
|
||||
test_cmd: Test,
|
||||
//test_cmd: Test,
|
||||
sleep_cmd: Sleep,
|
||||
sensors_cmd: Sensors,
|
||||
callback_cmd: CallBack,
|
||||
//callback_cmd: CallBack,
|
||||
rtc_cmd: RtcCmd,
|
||||
}
|
||||
impl CmdEnv {
|
||||
|
|
@ -88,10 +88,10 @@ impl CmdEnv {
|
|||
},
|
||||
lastverb: String::<256>::new(),
|
||||
///// 3. initialize your storage, by calling new()
|
||||
test_cmd: Test::new(),
|
||||
//test_cmd: Test::new(),
|
||||
sleep_cmd: Sleep::new(),
|
||||
sensors_cmd: Sensors::new(),
|
||||
callback_cmd: CallBack::new(),
|
||||
//callback_cmd: CallBack::new(),
|
||||
rtc_cmd: RtcCmd::new(&xns),
|
||||
}
|
||||
}
|
||||
|
|
@ -103,10 +103,10 @@ impl CmdEnv {
|
|||
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||
&mut echo_cmd,
|
||||
&mut self.test_cmd,
|
||||
//&mut self.test_cmd,
|
||||
&mut self.sleep_cmd,
|
||||
&mut self.sensors_cmd,
|
||||
&mut self.callback_cmd,
|
||||
//&mut self.callback_cmd,
|
||||
&mut self.rtc_cmd,
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
use crate::{ShellCmdApi,CommonEnv};
|
||||
use xous_ipc::String;
|
||||
|
||||
pub fn dt_callback(dt: rtc::DateTime) {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap();
|
||||
|
||||
// interesting: log calls in the callback cause the kernel to panic
|
||||
//log::info!("got datetime: {:?}", dt);
|
||||
let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap();
|
||||
buf.lend(callback_conn, 0xdeadbeef).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RtcCmd {
|
||||
rtc: rtc::Rtc,
|
||||
|
|
@ -8,8 +18,9 @@ pub struct RtcCmd {
|
|||
impl RtcCmd {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||
let mut rtc = rtc::Rtc::new(&xns).unwrap();
|
||||
rtc.hook_rtc_callback(dt_callback).unwrap();
|
||||
RtcCmd {
|
||||
rtc: rtc,
|
||||
rtc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,16 +30,12 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
let mut ret = String::<1024>::new();
|
||||
let helpstring = "rtc options: set, get, hook";
|
||||
let helpstring = "rtc options: set, get";
|
||||
|
||||
let mut tokens = args.as_str().unwrap().split(' ');
|
||||
|
||||
if let Some(sub_cmd) = tokens.next() {
|
||||
match sub_cmd {
|
||||
"hook" => {
|
||||
write!(ret, "{}", "Hooked RTC responder...").unwrap();
|
||||
self.rtc.hook_rtc_callback(dt_callback).unwrap();
|
||||
}
|
||||
"get" => {
|
||||
write!(ret, "{}", "Requesting DateTime from RTC...").unwrap();
|
||||
self.rtc.request_datetime().unwrap();
|
||||
|
|
@ -119,16 +126,26 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
|||
}
|
||||
Ok(Some(ret))
|
||||
}
|
||||
}
|
||||
|
||||
static mut CB_CONN: Option<xous::CID> = None;
|
||||
pub fn dt_callback(dt: rtc::DateTime) {
|
||||
if let Some(conn) = unsafe{CB_CONN} {
|
||||
// interesting: log calls in the callback cause the kernel to panic
|
||||
log::info!("got datetime: {:?}", dt);
|
||||
let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap();
|
||||
buf.lend(conn, 0xdeadbeef).unwrap();
|
||||
} else {
|
||||
log::info!("callback not set, but got datetime: {:?}", dt);
|
||||
fn callback(&mut self, msg: &xous::MessageEnvelope, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
use core::fmt::Write;
|
||||
|
||||
let buffer = unsafe { xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let dt = buffer.to_original::<rtc::DateTime, _>().unwrap();
|
||||
/*
|
||||
let dt = rtc::DateTime {
|
||||
seconds: 0,
|
||||
minutes: 0,
|
||||
hours: 0,
|
||||
days: 0,
|
||||
months: 0,
|
||||
years: 0,
|
||||
weekday: rtc::Weekday::Friday,
|
||||
};*/
|
||||
let mut ret = String::<1024>::new();
|
||||
//write!(ret, "{}", dt.hours);
|
||||
write!(ret, "{}:{}:{}, {}/{}/{}, {:?}", dt.hours, dt.minutes, dt.seconds, dt.months, dt.days, dt.years, dt.weekday).unwrap();
|
||||
Ok(Some(ret))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -232,8 +232,6 @@ fn imef_cb(s: String::<4000>) {
|
|||
}
|
||||
//////////////////
|
||||
|
||||
pub(crate) const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_";
|
||||
|
||||
fn test_thread() {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let ticktimer = ticktimer_server::Ticktimer::new().unwrap();
|
||||
|
|
@ -245,6 +243,8 @@ fn test_thread() {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_";
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
|
|
@ -263,7 +263,7 @@ fn xmain() -> ! {
|
|||
let mut update_repl = false;
|
||||
|
||||
if false {
|
||||
xous::create_thread_0(test_thread);
|
||||
xous::create_thread_0(test_thread).unwrap();
|
||||
}
|
||||
|
||||
log::trace!("starting main loop");
|
||||
|
|
|
|||
Loading…
Reference in a new issue