crashing on load when logger is in callback

This commit is contained in:
bunnie 2021-04-08 23:07:02 +08:00
parent 0fa3d3c969
commit a9de4782c5
6 changed files with 66 additions and 19 deletions

View file

@ -1328,10 +1328,10 @@ register to disable individual events.]]></description>
<register> <register>
<name>GIT_GITREV</name> <name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev <description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``79ae30c6``, so this value is 2041458886, which should be enough to check out ``844488ab``, so this value is 2219083947, which should be enough to check out
the exact git version used to build this firmware.]]></description> the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset> <addressOffset>0x0014</addressOffset>
<resetValue>0x79ae30c6</resetValue> <resetValue>0x844488ab</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -1348,7 +1348,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description> beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset> <addressOffset>0x0018</addressOffset>
<resetValue>0x10</resetValue> <resetValue>0x11</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -3060,7 +3060,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED1</name> <name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description> <description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset> <addressOffset>0x0000</addressOffset>
<resetValue>0x505c16c1</resetValue> <resetValue>0x7f01c208</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -3075,7 +3075,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED0</name> <name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description> <description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset> <addressOffset>0x0004</addressOffset>
<resetValue>0x578f7014</resetValue> <resetValue>0x5a7fce0a</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>

View file

@ -82,7 +82,7 @@ pub struct I2cTransaction {
} }
impl I2cTransaction { impl I2cTransaction {
pub fn new() -> Self { pub fn new() -> Self {
I2cTransaction{ bus_addr: 0, txbuf: None, txlen: 0, rxbuf: None, rxlen: 0, timeout_ms: 100, status: I2cStatus::Uninitialized, listener: None, callback_id: 0 } I2cTransaction{ bus_addr: 0, txbuf: None, txlen: 0, rxbuf: None, rxlen: 0, timeout_ms: 500, status: I2cStatus::Uninitialized, listener: None, callback_id: 0 }
} }
} }

View file

@ -61,7 +61,7 @@ impl I2cStateMachine {
} }
} }
pub fn initiate(&mut self, transaction: I2cTransaction ) -> I2cStatus { pub fn initiate(&mut self, transaction: I2cTransaction ) -> I2cStatus {
log::trace!("I2C initated with {:?}", transaction); log::trace!("I2C initated with {:x?}", transaction);
// sanity-check the bounds limits // sanity-check the bounds limits
if transaction.txlen > 258 || transaction.rxlen > 258 { if transaction.txlen > 258 || transaction.rxlen > 258 {
return I2cStatus::ResponseFormatError return I2cStatus::ResponseFormatError
@ -70,6 +70,7 @@ impl I2cStateMachine {
let now = self.ticktimer.elapsed_ms(); let now = self.ticktimer.elapsed_ms();
if self.state != I2cState::Idle && ((now - self.timestamp) < self.transaction.timeout_ms as u64) { if self.state != I2cState::Idle && ((now - self.timestamp) < self.transaction.timeout_ms as u64) {
// we're in a transaction that hadn't timed out, can't accept a new one // we're in a transaction that hadn't timed out, can't accept a new one
log::trace!("bus is busy");
I2cStatus::ResponseBusy I2cStatus::ResponseBusy
} else { } else {
if self.state != I2cState::Idle { if self.state != I2cState::Idle {
@ -99,6 +100,7 @@ impl I2cStateMachine {
self.i2c_csr.ms(utra::i2c::COMMAND_WR, 1) | self.i2c_csr.ms(utra::i2c::COMMAND_WR, 1) |
self.i2c_csr.ms(utra::i2c::COMMAND_STA, 1) self.i2c_csr.ms(utra::i2c::COMMAND_STA, 1)
); );
self.trace();
I2cStatus::ResponseInProgress I2cStatus::ResponseInProgress
} else if let Some(_rxbuf) = self.transaction.rxbuf { } else if let Some(_rxbuf) = self.transaction.rxbuf {
// initiate bus address with read bit set // initiate bus address with read bit set
@ -109,19 +111,24 @@ impl I2cStateMachine {
self.i2c_csr.ms(utra::i2c::COMMAND_WR, 1) | self.i2c_csr.ms(utra::i2c::COMMAND_WR, 1) |
self.i2c_csr.ms(utra::i2c::COMMAND_STA, 1) self.i2c_csr.ms(utra::i2c::COMMAND_STA, 1)
); );
self.trace();
I2cStatus::ResponseInProgress I2cStatus::ResponseInProgress
} else { } else {
// no buffers specified, erase everything and go to idle // no buffers specified, erase everything and go to idle
self.state = I2cState::Idle; self.state = I2cState::Idle;
self.transaction = I2cTransaction::new(); self.transaction = I2cTransaction::new();
self.trace();
I2cStatus::ResponseFormatError I2cStatus::ResponseFormatError
} }
} else { } else {
log::trace!("initiation format error");
self.trace();
I2cStatus::ResponseFormatError // the status field was not formatted correctly to accept the transaction I2cStatus::ResponseFormatError // the status field was not formatted correctly to accept the transaction
} }
} }
} }
fn report_nack(&mut self) { fn report_nack(&mut self) {
log::trace!("NACK");
// report the NACK situation to the listener // report the NACK situation to the listener
let mut nack = I2cTransaction::new(); let mut nack = I2cTransaction::new();
nack.status = I2cStatus::ResponseNack; nack.status = I2cStatus::ResponseNack;
@ -130,6 +137,7 @@ impl I2cStateMachine {
}; };
} }
fn report_timeout(&mut self) { fn report_timeout(&mut self) {
log::trace!("timeout");
let mut timeout = I2cTransaction::new(); let mut timeout = I2cTransaction::new();
timeout.status = I2cStatus::ResponseTimeout; timeout.status = I2cStatus::ResponseTimeout;
if let Some(listener) = self.listener { if let Some(listener) = self.listener {
@ -137,6 +145,7 @@ impl I2cStateMachine {
}; };
} }
fn report_write_done(&mut self) { fn report_write_done(&mut self) {
log::trace!("write_done");
// report the end of a write-only transaction to all the listeners // report the end of a write-only transaction to all the listeners
let mut ack = I2cTransaction::new(); let mut ack = I2cTransaction::new();
ack.status = I2cStatus::ResponseWriteOk; ack.status = I2cStatus::ResponseWriteOk;
@ -145,6 +154,7 @@ impl I2cStateMachine {
}; };
} }
fn report_read_done(&mut self) { fn report_read_done(&mut self) {
log::trace!("read_done");
// report the result of a read transaction to all the listeners // report the result of a read transaction to all the listeners
self.transaction.status = I2cStatus::ResponseReadOk; self.transaction.status = I2cStatus::ResponseReadOk;
if let Some(listener) = self.listener { if let Some(listener) = self.listener {
@ -158,11 +168,22 @@ impl I2cStateMachine {
true true
} }
} }
fn trace(&self) {
log::trace!("I2C trace: PENDING: {:x}, ENABLE: {:x}, CMD: {:x}, STATUS: {:x}, CONTROL: {:x}, PRESCALE: {:x}",
self.i2c_csr.r(utra::i2c::EV_PENDING),
self.i2c_csr.r(utra::i2c::EV_ENABLE),
self.i2c_csr.r(utra::i2c::COMMAND),
self.i2c_csr.r(utra::i2c::STATUS),
self.i2c_csr.r(utra::i2c::CONTROL),
self.i2c_csr.r(utra::i2c::PRESCALE),
);
}
pub fn handler(&mut self) { pub fn handler(&mut self) {
log::trace!("I2C handler called"); self.trace();
// check if the transaction had actually timed out // check if the transaction had actually timed out
let now = self.ticktimer.elapsed_ms(); let now = self.ticktimer.elapsed_ms();
if now - self.timestamp > self.transaction.timeout_ms as u64 { if now - self.timestamp > self.transaction.timeout_ms as u64 {
log::error!("I2C transaction timed out: {}ms elapsed", now - self.timestamp);
// previous transaction had timed out... // previous transaction had timed out...
self.report_timeout(); self.report_timeout();
// reset our state parameter // reset our state parameter
@ -177,14 +198,19 @@ impl I2cStateMachine {
I2cState::Write => { I2cState::Write => {
log::trace!("I2C handler: WRITE"); log::trace!("I2C handler: WRITE");
if let Some(txbuf) = self.transaction.txbuf { if let Some(txbuf) = self.transaction.txbuf {
// check ack bit // check ack bit--this actually doesn't seem to work, so excise the code
if self.i2c_csr.rf(utra::i2c::STATUS_RXACK) != 1 { if false {
self.state = I2cState::Idle; if self.i2c_csr.rf(utra::i2c::STATUS_RXACK) != 1 {
self.transaction = I2cTransaction::new(); /*
self.report_nack(); self.state = I2cState::Idle;
self.transaction = I2cTransaction::new();
self.report_nack();*/
log::trace!("got NACK, ignoring");
}
} }
// send next byte if there is one // send next byte if there is one
if self.index < self.transaction.txlen { if self.index < self.transaction.txlen {
log::trace!("write->write");
self.i2c_csr.wfo(utra::i2c::TXR_TXR, txbuf[self.index as usize] as u32); self.i2c_csr.wfo(utra::i2c::TXR_TXR, txbuf[self.index as usize] as u32);
if self.index == (self.transaction.txlen - 1) && self.transaction.rxbuf.is_none() { if self.index == (self.transaction.txlen - 1) && self.transaction.rxbuf.is_none() {
// send a stop bit if this is the very last in the series // send a stop bit if this is the very last in the series
@ -199,6 +225,7 @@ impl I2cStateMachine {
} else { } else {
if let Some(_rxbuf) = self.transaction.rxbuf { if let Some(_rxbuf) = self.transaction.rxbuf {
// initiate bus address with read bit set // initiate bus address with read bit set
log::trace!("write->read");
self.state = I2cState::Read; self.state = I2cState::Read;
self.i2c_csr.wfo(utra::i2c::TXR_TXR, (self.transaction.bus_addr << 1 | 1) as u32); self.i2c_csr.wfo(utra::i2c::TXR_TXR, (self.transaction.bus_addr << 1 | 1) as u32);
self.index = 0; self.index = 0;
@ -211,6 +238,7 @@ impl I2cStateMachine {
self.state = I2cState::Idle; self.state = I2cState::Idle;
} }
} }
self.trace();
} else { } else {
// we should never get here, because txbuf was checked as Some() by the setup routine // we should never get here, because txbuf was checked as Some() by the setup routine
log::error!("LLIO|I2C: illegal write state"); log::error!("LLIO|I2C: illegal write state");
@ -222,6 +250,7 @@ impl I2cStateMachine {
if self.index > 0 { if self.index > 0 {
// we are re-entering from a previous call, store the read value from the previous call // we are re-entering from a previous call, store the read value from the previous call
rxbuf[self.index as usize - 1] = self.i2c_csr.rf(utra::i2c::RXR_RXR) as u8; rxbuf[self.index as usize - 1] = self.i2c_csr.rf(utra::i2c::RXR_RXR) as u8;
log::trace!("READ got 0x{:02x}", rxbuf[self.index as usize - 1]);
} }
if self.index < self.transaction.rxlen { if self.index < self.transaction.rxlen {
if self.index == (self.transaction.rxlen - 1) { if self.index == (self.transaction.rxlen - 1) {
@ -244,6 +273,7 @@ impl I2cStateMachine {
// we should never get here, because rxbuf was checked as Some() by the setup routine // we should never get here, because rxbuf was checked as Some() by the setup routine
log::error!("LLIO|I2C: illegal read state"); log::error!("LLIO|I2C: illegal read state");
} }
self.trace();
}, },
I2cState::Idle => { I2cState::Idle => {
log::error!("LLIO|I2C: received interrupt event when no transaciton pending!"); log::error!("LLIO|I2C: received interrupt event when no transaciton pending!");

View file

@ -27,7 +27,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
match sub_cmd { match sub_cmd {
"hook" => { "hook" => {
write!(ret, "{}", "Hooked RTC responder...").unwrap(); write!(ret, "{}", "Hooked RTC responder...").unwrap();
//self.rtc.hook_rtc_callback(dt_callback).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();
@ -124,6 +124,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd {
static mut CB_CONN: Option<xous::CID> = None; static mut CB_CONN: Option<xous::CID> = None;
pub fn dt_callback(dt: rtc::DateTime) { pub fn dt_callback(dt: rtc::DateTime) {
if let Some(conn) = unsafe{CB_CONN} { if let Some(conn) = unsafe{CB_CONN} {
// interesting: log calls in the callback cause the kernel to panic
log::info!("got datetime: {:?}", dt); log::info!("got datetime: {:?}", dt);
let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap(); let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap();
buf.lend(conn, 0xdeadbeef).unwrap(); buf.lend(conn, 0xdeadbeef).unwrap();

View file

@ -234,6 +234,17 @@ fn imef_cb(s: String::<4000>) {
pub(crate) const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_"; 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();
ticktimer.sleep_ms(5000);
let rtc = rtc::Rtc::new(&xns).unwrap();
loop {
rtc.request_datetime().unwrap();
ticktimer.sleep_ms(2000);
}
}
#[xous::xous_main] #[xous::xous_main]
fn xmain() -> ! { fn xmain() -> ! {
log_server::init_wait().unwrap(); log_server::init_wait().unwrap();
@ -250,6 +261,11 @@ fn xmain() -> ! {
let mut repl = Repl::new(&xns, SERVER_NAME_SHELLCHAT); let mut repl = Repl::new(&xns, SERVER_NAME_SHELLCHAT);
let mut update_repl = false; let mut update_repl = false;
if false {
xous::create_thread_0(test_thread);
}
log::trace!("starting main loop"); log::trace!("starting main loop");
loop { loop {
let msg = xous::receive_message(shch_sid).unwrap(); let msg = xous::receive_message(shch_sid).unwrap();

View file

@ -1328,10 +1328,10 @@ register to disable individual events.]]></description>
<register> <register>
<name>GIT_GITREV</name> <name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev <description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``79ae30c6``, so this value is 2041458886, which should be enough to check out ``844488ab``, so this value is 2219083947, which should be enough to check out
the exact git version used to build this firmware.]]></description> the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset> <addressOffset>0x0014</addressOffset>
<resetValue>0x79ae30c6</resetValue> <resetValue>0x844488ab</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -1348,7 +1348,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description> beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset> <addressOffset>0x0018</addressOffset>
<resetValue>0x10</resetValue> <resetValue>0x11</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -3060,7 +3060,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED1</name> <name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description> <description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset> <addressOffset>0x0000</addressOffset>
<resetValue>0x505c16c1</resetValue> <resetValue>0x7f01c208</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>
@ -3075,7 +3075,7 @@ again until the interrupt is serviced.]]></description>
<name>SEED0</name> <name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description> <description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset> <addressOffset>0x0004</addressOffset>
<resetValue>0x578f7014</resetValue> <resetValue>0x5a7fce0a</resetValue>
<size>32</size> <size>32</size>
<fields> <fields>
<field> <field>