diff --git a/Cargo.lock b/Cargo.lock index 6a6f56d97..654576a4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,6 +297,7 @@ name = "codec" version = "0.1.0" dependencies = [ "heapless", + "llio", "log", "log-server", "num-derive", @@ -304,6 +305,7 @@ dependencies = [ "susres", "ticktimer-server", "utralib", + "volatile", "xous", "xous-names", ] @@ -1558,6 +1560,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "volatile" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4c2dbd44eb8b53973357e6e207e370f0c1059990df850aca1eca8947cf464f0" + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/emulation/renode.svd b/emulation/renode.svd index d999c129c..302ed503c 100644 --- a/emulation/renode.svd +++ b/emulation/renode.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x64fe00d9 + 0x5129ab27 32 @@ -1090,7 +1090,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 - 0x05 + 0x06 32 @@ -1697,10 +1697,26 @@ upon the completion of one byte of data transfer.]]> + + CORE_RESET + 0x0018 + 0x00 + 32 + + + reset + 0 + [0:0] + 0 + + + + EV_STATUS - 0x0018 + 0x001c 0x00 32 @@ -1723,7 +1739,7 @@ upon the completion of one byte of data transfer.]]> EV_PENDING - 0x001c + 0x0020 0x00 32 @@ -1747,7 +1763,7 @@ clear or else it will re-trigger.]]> EV_ENABLE - 0x0020 + 0x0024 0x00 32 @@ -1770,7 +1786,7 @@ clear or else it will re-trigger.]]> 0 - 0x24 + 0x28 registers @@ -3101,7 +3117,7 @@ inject too fast.]]> SEED1 0x0000 - 0x6ec50873 + 0x5f5e319d 32 @@ -3116,7 +3132,7 @@ inject too fast.]]> SEED0 0x0004 - 0x7ff788bf + 0x1a7dec69 32 diff --git a/precursors/soc.svd b/precursors/soc.svd index d999c129c..302ed503c 100644 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x64fe00d9 + 0x5129ab27 32 @@ -1090,7 +1090,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 - 0x05 + 0x06 32 @@ -1697,10 +1697,26 @@ upon the completion of one byte of data transfer.]]> + + CORE_RESET + 0x0018 + 0x00 + 32 + + + reset + 0 + [0:0] + 0 + + + + EV_STATUS - 0x0018 + 0x001c 0x00 32 @@ -1723,7 +1739,7 @@ upon the completion of one byte of data transfer.]]> EV_PENDING - 0x001c + 0x0020 0x00 32 @@ -1747,7 +1763,7 @@ clear or else it will re-trigger.]]> EV_ENABLE - 0x0020 + 0x0024 0x00 32 @@ -1770,7 +1786,7 @@ clear or else it will re-trigger.]]> 0 - 0x24 + 0x28 registers @@ -3101,7 +3117,7 @@ inject too fast.]]> SEED1 0x0000 - 0x6ec50873 + 0x5f5e319d 32 @@ -3116,7 +3132,7 @@ inject too fast.]]> SEED0 0x0004 - 0x7ff788bf + 0x1a7dec69 32 diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index f5490ea60..b601c38c8 100644 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/llio/src/i2c.rs b/services/llio/src/i2c.rs index f3cbb14a0..59c66a759 100644 --- a/services/llio/src/i2c.rs +++ b/services/llio/src/i2c.rs @@ -72,7 +72,8 @@ impl I2cStateMachine { // reset our state parameter self.state = I2cState::Idle; self.index = 0; - // now we're ready to move on and try a new transaction. We hope! Maybe the block should be reset?? TBD. Need to understand the nature of the timeouts better, if and when they do happen. + // reset the block - this resest just the state machine and not the prescaler or interrupt enable configs + self.i2c_csr.wfo(utra::i2c::CORE_RESET_RESET, 1); } self.error = false; self.timestamp = now; @@ -132,7 +133,7 @@ impl I2cStateMachine { }; } fn report_timeout(&mut self) { - log::trace!("timeout"); + log::error!("I2C timeout on transaction {:?}", self.transaction); let mut timeout = I2cTransaction::new(); timeout.status = I2cStatus::ResponseTimeout; if let Some(listener) = self.listener { @@ -176,128 +177,9 @@ impl I2cStateMachine { self.i2c_csr.r(utra::i2c::PRESCALE), ); } - #[cfg(feature = "non_irq_handler")] - pub fn handler(&mut self) { - 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 - self.state = I2cState::Idle; - self.index = 0; - self.timestamp = now; - return; - } - self.timestamp = now; - - match self.state { - I2cState::Write => { - log::trace!("I2C handler: WRITE"); - if let Some(txbuf) = self.transaction.txbuf { - // 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 - self.i2c_csr.wo(utra::i2c::COMMAND, - self.i2c_csr.ms(utra::i2c::COMMAND_WR, 1) | - self.i2c_csr.ms(utra::i2c::COMMAND_STO, 1) - ); - } else { - self.i2c_csr.wfo(utra::i2c::COMMAND_WR, 1); - } - self.index += 1; - } 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; - self.i2c_csr.wo(utra::i2c::COMMAND, - self.i2c_csr.ms(utra::i2c::COMMAND_WR, 1) | - self.i2c_csr.ms(utra::i2c::COMMAND_STA, 1) - ); - } else { - self.report_write_done(); - 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"); - } - }, - I2cState::Read => { - log::trace!("I2C handler: READ"); - if let Some(mut rxbuf) = self.transaction.rxbuf { - 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]); - self.transaction.rxbuf = Some(rxbuf); - } - if self.index < self.transaction.rxlen { - if self.index == (self.transaction.rxlen - 1) { - self.i2c_csr.wo(utra::i2c::COMMAND, - self.i2c_csr.ms(utra::i2c::COMMAND_RD, 1) | - self.i2c_csr.ms(utra::i2c::COMMAND_STO, 1) | - self.i2c_csr.ms(utra::i2c::COMMAND_ACK, 1) - ); - } else { - self.i2c_csr.wfo(utra::i2c::COMMAND_RD, 1); - } - self.index += 1; - } else { - log::trace!("I2C handler: read done {:?}", self.transaction); - self.report_read_done(); - self.state = I2cState::Idle; - self.listener = None; - } - } else { - // 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!"); - } - } - } // interrupt context-friendly handler pub fn handler_i(&mut self) -> I2cHandlerReport { - /* // can't check timeouts in an interrupt handler - // 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 - self.state = I2cState::Idle; - self.index = 0; - self.timestamp = now; - return; - } - self.timestamp = now;*/ - let mut report = I2cHandlerReport::InProgress; match self.state { diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index cf7afa741..57ea9c586 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -4,7 +4,6 @@ mod api; use api::*; mod i2c; -use i2c::*; use log::{error, info}; @@ -135,8 +134,6 @@ mod implementation { } impl Llio { - pub fn get_i2c_base(&self) -> *mut u32 { self.i2c_csr.base } - pub fn new(handler_conn: xous::CID, gpio_base: *mut u32) -> Llio { let crg_csr = xous::syscall::map_memory( xous::MemoryAddress::new(utra::crg::HW_CRG_BASE), @@ -488,8 +485,6 @@ mod implementation { Llio { } } - pub fn get_i2c_base(&self) -> *mut u32 { 0 as *mut u32 } - pub fn suspend(&self) {} pub fn resume(&self) {} pub fn gpio_dout(&self, _d: u32) {} @@ -551,7 +546,9 @@ mod implementation { pub fn usb_int_ena(self, _ena: bool) { } - pub fn i2c_handler(&mut self) { + pub fn i2c_report_write_done(&mut self) { + } + pub fn i2c_report_read_done(&mut self) { } pub fn i2c_initiate(&mut self, i2c_txrx: I2cTransaction) -> I2cStatus { I2cStatus::ResponseInProgress diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index d999c129c..302ed503c 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x64fe00d9 + 0x5129ab27 32 @@ -1090,7 +1090,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 - 0x05 + 0x06 32 @@ -1697,10 +1697,26 @@ upon the completion of one byte of data transfer.]]> + + CORE_RESET + 0x0018 + 0x00 + 32 + + + reset + 0 + [0:0] + 0 + + + + EV_STATUS - 0x0018 + 0x001c 0x00 32 @@ -1723,7 +1739,7 @@ upon the completion of one byte of data transfer.]]> EV_PENDING - 0x001c + 0x0020 0x00 32 @@ -1747,7 +1763,7 @@ clear or else it will re-trigger.]]> EV_ENABLE - 0x0020 + 0x0024 0x00 32 @@ -1770,7 +1786,7 @@ clear or else it will re-trigger.]]> 0 - 0x24 + 0x28 registers @@ -3101,7 +3117,7 @@ inject too fast.]]> SEED1 0x0000 - 0x6ec50873 + 0x5f5e319d 32 @@ -3116,7 +3132,7 @@ inject too fast.]]> SEED0 0x0004 - 0x7ff788bf + 0x1a7dec69 32