Skip to content

Commit

Permalink
Add ILA to i2cWb and debug print statements to fmc-clock binary
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddemoll committed Apr 29, 2024
1 parent 79f71bc commit 8560f30
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
54 changes: 52 additions & 2 deletions bittide/src/Bittide/Wishbone.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Bittide.SharedTypes

import Clash.Cores.UART (uart, ValidBaud)
import Clash.Cores.Experimental.I2C
import Clash.Cores.Xilinx.Ila (ila, ilaConfig, IlaConfig(..), Depth)
import Clash.Cores.Xilinx.Ila (ila, ilaConfig, IlaConfig(..), Depth (..))
import Clash.Sized.Vector.ToTuple
import Clash.Util.Interpolate

Expand Down Expand Up @@ -492,7 +492,7 @@ i2cWb ::
i2cWb = case (cancelMulDiv @nBytes @8) of
Dict -> Circuit go
where
go ((wbM2S, i2cIn), _) = ((wbS2M, pure ()), i2cOut)
go ((wbM2S, i2cIn), _) = i2cWbIla `hwSeqX` ((wbS2M, pure ()), i2cOut)
where
-- Wishbone interface consists of:
-- 0. i2c data Read-Write
Expand Down Expand Up @@ -531,6 +531,56 @@ i2cWb = case (cancelMulDiv @nBytes @8) of
(dOut,hostAck,busy,al,ackOut,i2cOut) =
i2c hasClock hasReset smReset (fromEnable hasEnable) clkDiv claimBus i2cOp ackIn i2cIn

onChange :: (HiddenClockResetEnable dom, Eq a, NFDataX a) => Signal dom a -> Signal dom Bool
onChange x = (Just <$> x) ./=. register Nothing (Just <$> x)

capture :: Signal dom Bool
capture = withClockResetEnable hasClock hasReset enableGen $
onChange $ bundle
( isJust <$> i2cOp
, wbAck
, flagsRead
, isJust <$> transAddr
, hostAck
, busy
, al
, ackOut
, ackIn
, claimBus
)

i2cWbIla :: Signal dom ()
i2cWbIla = setName @"i2cWbIla" $ ila
((ilaConfig $
"trigger_2"
:> "capture_2"
:> "i2cOp"
:> "wbAck"
:> "flagsRead"
:> "transAddr"
:> "hostAck"
:> "busy"
:> "al"
:> "ackOut"
:> "ackIn"
:> "claimBus"
:> Nil
) { depth = D16384 })
hasClock
(pure True :: Signal dom Bool)
capture
-- Debug signals
i2cOp
wbAck
flagsRead
transAddr
hostAck
busy
al
ackOut
ackIn
claimBus

-- Wishbone accessible register circuit which can only be written to from the circuit.
statusRegWb ::
forall dom a nBytes addrW .
Expand Down
25 changes: 23 additions & 2 deletions firmware-binaries/fmc-clock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,22 @@ pub fn configure_clock_chip(
for line in si534x_config.lines() {
if !parser.is_done() {
let old_state = parser.state;
if let Ok(Some(ConfigEntry { page, addr, data })) = parser.parse_line(line) {
si534x.write_byte(page, addr, data)?;
match parser.parse_line(line) {
Ok(Some(ConfigEntry { page, addr, data })) => {
si534x.write_byte(page, addr, data)?;
uwriteln!(uart, "Wrote: {:2X} {:2X} {:2X}", page, addr, data).unwrap();
}
Ok(None) => {}
Err(e) => {
uwriteln!(uart, "Error: {:?}", e).unwrap();
}
}
if old_state == ParserState::Preamble && parser.state == ParserState::PostPreambleDelay
{
// Wait 300ms after writing the preamble
uwriteln!(uart, "Waiting 300 ms after preamble...").unwrap();
clock.wait(Duration::from_millis(300));
uwriteln!(uart, "Done waiting").unwrap();
}
}
}
Expand Down Expand Up @@ -221,6 +230,18 @@ fn main() -> ! {
control_reg.set_clock_init_done();
}

// Try to read and write the page number
match si534x.read_byte(0x0, 0x01) {
Ok(d) => uwriteln!(uart, "Current page: {:2X}", d).unwrap(),
Err(e) => uwriteln!(uart, "ERROR: {:?}", e).unwrap(),
}
_ = si534x.set_page(0x1);
match si534x.read_byte(0x1, 0x01) {
Ok(d) => uwriteln!(uart, "Current page: {:2X}", d).unwrap(),
Err(e) => uwriteln!(uart, "ERROR: {:?}", e).unwrap(),
}
uwriteln!(uart, "Checked pages, continuing...").unwrap();

// Do the FInc FDec tests
let mut last_status_reg;
let mut sub_test = Test::Idle;
Expand Down

0 comments on commit 8560f30

Please sign in to comment.