Skip to content

Commit

Permalink
[dv/dpi] Fix pipe implementation
Browse files Browse the repository at this point in the history
Fix some SPI dpi corner cases.
Fix Uart drain error.

Signed-off-by: Daniel Beitel <[email protected]>
  • Loading branch information
dbeitel-opentitan committed Feb 9, 2024
1 parent 8bb0d97 commit 31274bb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
24 changes: 15 additions & 9 deletions hw/dv/dpi/spidpi/spidpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,14 @@ static void xfer_respond_next_trans(void *ctx_void) {
char value[16];

strcat(ctx->xfer_buf_out, "{\"Read\":{\"data\":[");
for (int i = 0; i < (ctx->nmax - 1); i++) {
sprintf(value, "%u,", (uint8_t)ctx->buf[i]);
if (ctx->nmax > 0) {
for (int i = 0; i < (ctx->nmax - 1); i++) {
sprintf(value, "%u,", (uint8_t)ctx->buf[i]);
strcat(ctx->xfer_buf_out, value);
}
sprintf(value, "%u", (uint8_t)ctx->buf[ctx->nmax - 1]);
strcat(ctx->xfer_buf_out, value);
}
sprintf(value, "%u", (uint8_t)ctx->buf[ctx->nmax - 1]);
strcat(ctx->xfer_buf_out, value);
strcat(ctx->xfer_buf_out, "]}}");
} else {
assert(false && "Response to No transaction not supported.");
Expand Down Expand Up @@ -310,7 +312,7 @@ static void xfer_respond(void *ctx_void, bool error) {
}
} else {
int rv = write(ctx->host, ctx->xfer_buf_out, count);
assert(rv == 1 && "write() failed.");
assert(rv == count && "write() failed.");
}
}

Expand Down Expand Up @@ -557,10 +559,14 @@ char spidpi_tick(void *ctx_void, const svLogicVecVal *d2p_data) {
ctx->driving = set_sck | (ctx->driving & ~P2D_SCK);
break;
case SP_CSFALL:
// CSB low, drive SDI to first bit
ctx->driving =
(set_sck | (ctx->buf[ctx->nout] & ctx->bout) ? P2D_SDI : 0);
ctx->state = SP_DMOVE;
if (ctx->nmax > 0) {
// CSB low, drive SDI to first bit
ctx->driving =
(set_sck | (ctx->buf[ctx->nout] & ctx->bout) ? P2D_SDI : 0);
ctx->state = SP_DMOVE;
} else {
ctx->state = SP_CSRISE;
}
break;
case SP_CSRISE:
xfer_respond_next_trans(ctx);
Expand Down
2 changes: 1 addition & 1 deletion hw/top_darjeeling/dv/verilator/chip_sim_tb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module chip_sim_tb (
.FREQ('d500_000)
) u_uart (
.clk_i (clk_i),
.rst_ni (rst_ni),
.rst_ni (cio_gpio_rst_n),
.tx_o (cio_uart_rx_p2d),
.rx_i (cio_uart_tx_d2p)
);
Expand Down
4 changes: 2 additions & 2 deletions sw/host/opentitanlib/src/transport/verilator/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::rc::Rc;
use std::time::{Duration, Instant};

use crate::io::gpio::{GpioError, GpioPin};
use crate::io::jtag::{Jtag, JtagParams};
use crate::io::spi::Target;
use crate::io::uart::Uart;
use crate::transport::verilator::gpio::{GpioInner, VerilatorGpioPin};
Expand All @@ -21,9 +22,8 @@ use crate::transport::verilator::uart::VerilatorUart;
use crate::transport::{
Capabilities, Capability, Transport, TransportError, TransportInterfaceType,
};
use crate::util::parse_int::ParseInt;
use crate::io::jtag::{Jtag, JtagParams};
use crate::util::openocd::OpenOcdServer;
use crate::util::parse_int::ParseInt;

pub(crate) struct Inner {
uart: Option<Rc<dyn Uart>>,
Expand Down
7 changes: 4 additions & 3 deletions sw/host/opentitanlib/src/transport/verilator/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fs::File;
use std::fs::OpenOptions;
use std::io;
use std::io::{ErrorKind, Read, Write};
use std::io::{Seek, SeekFrom};
//use std::io::{Seek, SeekFrom};
use std::net::TcpStream;
use std::time::Duration;

Expand Down Expand Up @@ -290,8 +290,9 @@ impl Uart for VerilatorUart {
} else {
return Err(anyhow!("TCP socket not connected")).context("UART reset error");
}
} else if let Some(ref ref_pipe) = self.pipe {
ref_pipe.borrow_mut().seek(SeekFrom::End(0))?;
// TODO: Seek on pipe causes error. Find a different method for draining pipe
} else if let Some(ref _ref_pipe) = self.pipe {
//ref_pipe.borrow_mut().seek(SeekFrom::End(0))?;
} else {
return Err(anyhow!("Pipe not opened")).context("UART reset error");
}
Expand Down

0 comments on commit 31274bb

Please sign in to comment.