diff --git a/emulation/renode.svd b/emulation/renode.svd index 9d394f73c..f2e49861b 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -1328,10 +1328,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x79ae30c6 + 0x844488ab 32 @@ -1348,7 +1348,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x10 + 0x11 32 @@ -3060,7 +3060,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x505c16c1 + 0x7f01c208 32 @@ -3075,7 +3075,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x578f7014 + 0x5a7fce0a 32 diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index b2fafb224..00ef19e43 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -82,7 +82,7 @@ pub struct I2cTransaction { } impl I2cTransaction { 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 } } } diff --git a/services/llio/src/i2c.rs b/services/llio/src/i2c.rs index 25f719356..d0e17186f 100644 --- a/services/llio/src/i2c.rs +++ b/services/llio/src/i2c.rs @@ -61,7 +61,7 @@ impl I2cStateMachine { } } 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 if transaction.txlen > 258 || transaction.rxlen > 258 { return I2cStatus::ResponseFormatError @@ -70,6 +70,7 @@ impl I2cStateMachine { let now = self.ticktimer.elapsed_ms(); 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 + log::trace!("bus is busy"); I2cStatus::ResponseBusy } else { 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_STA, 1) ); + self.trace(); I2cStatus::ResponseInProgress } else if let Some(_rxbuf) = self.transaction.rxbuf { // 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_STA, 1) ); + self.trace(); I2cStatus::ResponseInProgress } else { // no buffers specified, erase everything and go to idle self.state = I2cState::Idle; self.transaction = I2cTransaction::new(); + self.trace(); I2cStatus::ResponseFormatError } } else { + log::trace!("initiation format error"); + self.trace(); I2cStatus::ResponseFormatError // the status field was not formatted correctly to accept the transaction } } } fn report_nack(&mut self) { + log::trace!("NACK"); // report the NACK situation to the listener let mut nack = I2cTransaction::new(); nack.status = I2cStatus::ResponseNack; @@ -130,6 +137,7 @@ impl I2cStateMachine { }; } fn report_timeout(&mut self) { + log::trace!("timeout"); let mut timeout = I2cTransaction::new(); timeout.status = I2cStatus::ResponseTimeout; if let Some(listener) = self.listener { @@ -137,6 +145,7 @@ impl I2cStateMachine { }; } fn report_write_done(&mut self) { + log::trace!("write_done"); // report the end of a write-only transaction to all the listeners let mut ack = I2cTransaction::new(); ack.status = I2cStatus::ResponseWriteOk; @@ -145,6 +154,7 @@ impl I2cStateMachine { }; } fn report_read_done(&mut self) { + log::trace!("read_done"); // report the result of a read transaction to all the listeners self.transaction.status = I2cStatus::ResponseReadOk; if let Some(listener) = self.listener { @@ -158,11 +168,22 @@ impl I2cStateMachine { 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) { - log::trace!("I2C handler called"); + self.trace(); // check if the transaction had actually timed out let now = self.ticktimer.elapsed_ms(); 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... self.report_timeout(); // reset our state parameter @@ -177,14 +198,19 @@ impl I2cStateMachine { I2cState::Write => { log::trace!("I2C handler: WRITE"); if let Some(txbuf) = self.transaction.txbuf { - // check ack bit - if self.i2c_csr.rf(utra::i2c::STATUS_RXACK) != 1 { - self.state = I2cState::Idle; - self.transaction = I2cTransaction::new(); - self.report_nack(); + // check ack bit--this actually doesn't seem to work, so excise the code + if false { + if self.i2c_csr.rf(utra::i2c::STATUS_RXACK) != 1 { + /* + self.state = I2cState::Idle; + self.transaction = I2cTransaction::new(); + self.report_nack();*/ + log::trace!("got NACK, ignoring"); + } } // send next byte if there is one 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); 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 @@ -199,6 +225,7 @@ impl I2cStateMachine { } else { if let Some(_rxbuf) = self.transaction.rxbuf { // initiate bus address with read bit set + log::trace!("write->read"); self.state = I2cState::Read; self.i2c_csr.wfo(utra::i2c::TXR_TXR, (self.transaction.bus_addr << 1 | 1) as u32); self.index = 0; @@ -211,6 +238,7 @@ impl I2cStateMachine { self.state = I2cState::Idle; } } + self.trace(); } else { // we should never get here, because txbuf was checked as Some() by the setup routine log::error!("LLIO|I2C: illegal write state"); @@ -222,6 +250,7 @@ impl I2cStateMachine { if self.index > 0 { // 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; + log::trace!("READ got 0x{:02x}", rxbuf[self.index as usize - 1]); } if self.index < self.transaction.rxlen { 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 log::error!("LLIO|I2C: illegal read state"); } + self.trace(); }, I2cState::Idle => { log::error!("LLIO|I2C: received interrupt event when no transaciton pending!"); diff --git a/services/shellchat/src/cmds/rtc_cmd.rs b/services/shellchat/src/cmds/rtc_cmd.rs index 2eba86f46..5873bdc6b 100644 --- a/services/shellchat/src/cmds/rtc_cmd.rs +++ b/services/shellchat/src/cmds/rtc_cmd.rs @@ -27,7 +27,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd { match sub_cmd { "hook" => { write!(ret, "{}", "Hooked RTC responder...").unwrap(); - //self.rtc.hook_rtc_callback(dt_callback).unwrap(); + self.rtc.hook_rtc_callback(dt_callback).unwrap(); } "get" => { write!(ret, "{}", "Requesting DateTime from RTC...").unwrap(); @@ -124,6 +124,7 @@ impl<'a> ShellCmdApi<'a> for RtcCmd { static mut CB_CONN: Option = 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(); diff --git a/services/shellchat/src/main.rs b/services/shellchat/src/main.rs index 1cc8e9164..801d947b9 100644 --- a/services/shellchat/src/main.rs +++ b/services/shellchat/src/main.rs @@ -234,6 +234,17 @@ 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(); + ticktimer.sleep_ms(5000); + let rtc = rtc::Rtc::new(&xns).unwrap(); + loop { + rtc.request_datetime().unwrap(); + ticktimer.sleep_ms(2000); + } +} + #[xous::xous_main] fn xmain() -> ! { log_server::init_wait().unwrap(); @@ -250,6 +261,11 @@ fn xmain() -> ! { let mut repl = Repl::new(&xns, SERVER_NAME_SHELLCHAT); let mut update_repl = false; + + if false { + xous::create_thread_0(test_thread); + } + log::trace!("starting main loop"); loop { let msg = xous::receive_message(shch_sid).unwrap(); diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index 9d394f73c..f2e49861b 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -1328,10 +1328,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x79ae30c6 + 0x844488ab 32 @@ -1348,7 +1348,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x10 + 0x11 32 @@ -3060,7 +3060,7 @@ again until the interrupt is serviced.]]> SEED1 0x0000 - 0x505c16c1 + 0x7f01c208 32 @@ -3075,7 +3075,7 @@ again until the interrupt is serviced.]]> SEED0 0x0004 - 0x578f7014 + 0x5a7fce0a 32