mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +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) {
|
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);
|
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 {
|
loop {
|
||||||
let msg = xous::receive_message(sid).unwrap();
|
let msg = xous::receive_message(sid).unwrap();
|
||||||
log::trace!("rtc callback got msg: {:?}", msg);
|
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
|
///// 1. add your module here, and pull its namespace into the local crate
|
||||||
mod echo; use echo::*;
|
mod echo; use echo::*;
|
||||||
mod test; use test::*;
|
//mod test; use test::*;
|
||||||
mod sleep; use sleep::*;
|
mod sleep; use sleep::*;
|
||||||
mod sensors; use sensors::*;
|
mod sensors; use sensors::*;
|
||||||
mod callback; use callback::*;
|
//mod callback; use callback::*;
|
||||||
mod rtc_cmd; use rtc_cmd::*;
|
mod rtc_cmd; use rtc_cmd::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -70,10 +70,10 @@ pub struct CmdEnv {
|
||||||
common_env: CommonEnv,
|
common_env: CommonEnv,
|
||||||
lastverb: String::<256>,
|
lastverb: String::<256>,
|
||||||
///// 2. declare storage for your command here.
|
///// 2. declare storage for your command here.
|
||||||
test_cmd: Test,
|
//test_cmd: Test,
|
||||||
sleep_cmd: Sleep,
|
sleep_cmd: Sleep,
|
||||||
sensors_cmd: Sensors,
|
sensors_cmd: Sensors,
|
||||||
callback_cmd: CallBack,
|
//callback_cmd: CallBack,
|
||||||
rtc_cmd: RtcCmd,
|
rtc_cmd: RtcCmd,
|
||||||
}
|
}
|
||||||
impl CmdEnv {
|
impl CmdEnv {
|
||||||
|
|
@ -88,10 +88,10 @@ impl CmdEnv {
|
||||||
},
|
},
|
||||||
lastverb: String::<256>::new(),
|
lastverb: String::<256>::new(),
|
||||||
///// 3. initialize your storage, by calling new()
|
///// 3. initialize your storage, by calling new()
|
||||||
test_cmd: Test::new(),
|
//test_cmd: Test::new(),
|
||||||
sleep_cmd: Sleep::new(),
|
sleep_cmd: Sleep::new(),
|
||||||
sensors_cmd: Sensors::new(),
|
sensors_cmd: Sensors::new(),
|
||||||
callback_cmd: CallBack::new(),
|
//callback_cmd: CallBack::new(),
|
||||||
rtc_cmd: RtcCmd::new(&xns),
|
rtc_cmd: RtcCmd::new(&xns),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,10 +103,10 @@ impl CmdEnv {
|
||||||
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
||||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||||
&mut echo_cmd,
|
&mut echo_cmd,
|
||||||
&mut self.test_cmd,
|
//&mut self.test_cmd,
|
||||||
&mut self.sleep_cmd,
|
&mut self.sleep_cmd,
|
||||||
&mut self.sensors_cmd,
|
&mut self.sensors_cmd,
|
||||||
&mut self.callback_cmd,
|
//&mut self.callback_cmd,
|
||||||
&mut self.rtc_cmd,
|
&mut self.rtc_cmd,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,16 @@
|
||||||
use crate::{ShellCmdApi,CommonEnv};
|
use crate::{ShellCmdApi,CommonEnv};
|
||||||
use xous_ipc::String;
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct RtcCmd {
|
pub struct RtcCmd {
|
||||||
rtc: rtc::Rtc,
|
rtc: rtc::Rtc,
|
||||||
|
|
@ -8,8 +18,9 @@ pub struct RtcCmd {
|
||||||
impl RtcCmd {
|
impl RtcCmd {
|
||||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||||
let mut rtc = rtc::Rtc::new(&xns).unwrap();
|
let mut rtc = rtc::Rtc::new(&xns).unwrap();
|
||||||
|
rtc.hook_rtc_callback(dt_callback).unwrap();
|
||||||
RtcCmd {
|
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> {
|
fn process(&mut self, args: String::<1024>, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut ret = String::<1024>::new();
|
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(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
"hook" => {
|
|
||||||
write!(ret, "{}", "Hooked RTC responder...").unwrap();
|
|
||||||
self.rtc.hook_rtc_callback(dt_callback).unwrap();
|
|
||||||
}
|
|
||||||
"get" => {
|
"get" => {
|
||||||
write!(ret, "{}", "Requesting DateTime from RTC...").unwrap();
|
write!(ret, "{}", "Requesting DateTime from RTC...").unwrap();
|
||||||
self.rtc.request_datetime().unwrap();
|
self.rtc.request_datetime().unwrap();
|
||||||
|
|
@ -119,16 +126,26 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
|
||||||
}
|
}
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static mut CB_CONN: Option<xous::CID> = None;
|
fn callback(&mut self, msg: &xous::MessageEnvelope, _env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
pub fn dt_callback(dt: rtc::DateTime) {
|
use core::fmt::Write;
|
||||||
if let Some(conn) = unsafe{CB_CONN} {
|
|
||||||
// interesting: log calls in the callback cause the kernel to panic
|
let buffer = unsafe { xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
log::info!("got datetime: {:?}", dt);
|
let dt = buffer.to_original::<rtc::DateTime, _>().unwrap();
|
||||||
let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap();
|
/*
|
||||||
buf.lend(conn, 0xdeadbeef).unwrap();
|
let dt = rtc::DateTime {
|
||||||
} else {
|
seconds: 0,
|
||||||
log::info!("callback not set, but got datetime: {:?}", dt);
|
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() {
|
fn test_thread() {
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
let ticktimer = ticktimer_server::Ticktimer::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]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
|
|
@ -263,7 +263,7 @@ fn xmain() -> ! {
|
||||||
let mut update_repl = false;
|
let mut update_repl = false;
|
||||||
|
|
||||||
if false {
|
if false {
|
||||||
xous::create_thread_0(test_thread);
|
xous::create_thread_0(test_thread).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
log::trace!("starting main loop");
|
log::trace!("starting main loop");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue