Commit Graph

186 Commits

Author SHA1 Message Date
Sean Anderson d1834e2b7a axis_replay_buffer: Don't say we're ready during reset
We can't actually accept data during reset, so don't assert ready.
Modify the testbench to try to send data while the core is reset, so we
can verify that it doesn't get accepted.

Fixes: 52325f2 ("Add AXI stream replay buffer")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 15:36:36 -04:00
Sean Anderson 9cdbd5f2a8 axis_mii_tx: Don't reset lfsr
The value of the lfsr does not matter, as long as it keeps ticking. Use
initial instead of resetting it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 15:24:57 -04:00
Sean Anderson 13ee4899a3 doc: Expand interfaces documentation
Expand a bit on the AXI stream and Wishbone interfaces, documenting the
particular choices we use. The reset signalling could likely also use
some further documentation, but I have deferred that until I have gone
though all the cores and fixed bugs.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 15:12:17 -04:00
Sean Anderson 12b98c8d46 doc: Move interface documentation to its own document
This is more detailed technical documentation, and doesn't really need
to go at the top-level.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 15:00:50 -04:00
Sean Anderson d150d88249 README: Add a section on licensing
Add a section documenting the license used for this project.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 14:58:14 -04:00
Sean Anderson d5717a3053 doc: Add an index page
Add an index page linking to the rest of the documentation (cuyrrently
just one document).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 14:27:42 -04:00
Sean Anderson 7d93f91dd3 mdio_regs: Test OUI mapping to PHYID
The OUI in the PHY ID is "bit-reversed," AKA each byte is bit reversed,
but the overall order is the same. This is a bit more complex than I
initially thought. Fix the mapping, and use a non-zero OUI for testing.

Fixes: d9602b6 ("Add MII management functions")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 14:11:56 -04:00
Sean Anderson 508b090983 led_blinker: Decrease blink speed to 15 Hz
15 Hz is more obviously "blinky" than 30 Hz (at least at 50% duty cycle).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 14:06:04 -04:00
Sean Anderson 01f9d96173 Add LED example
Add a small LED example to let me test the blinker functionality.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 14:05:29 -04:00
Sean Anderson 8887f774d0 rtl: Document calculation of LFSRs
Document how the LFSR initial values are generated. Also fix several
off-by-one errors (where the documented cycles was not quite right).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-15 13:44:20 -04:00
Sean Anderson c5df9ff5d5 Add script to calculate LFSR values
Add a script to calculate the initial value to load into an LFSR based
on how many cycles it should run for. The calculation is based on [1].
It takes advantage of the commutative and properties of exclusive or to
recursively break down the number of steps. This lets us achieve an
O(log(n)) runtime by caching our results. There's an alternative version
of this algoritm which stores bits by value (0x100) instead of position
(8). It's probably easier to do things that way in C or verilog, but
this was more elegant in python. When calculating the number of cycles,
we subtract one to get the number of cycles instead of the number of
steps.

[1] https://www.eevblog.com/forum/projects/algorithm-for-calculating-previous-states-of-lfsr-counters/msg2524395/#msg2524395

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-14 01:29:04 -04:00
Sean Anderson cd5a4b28a0 hub: Add option to register wishbone bus
Add an option to register the wishbone busses post-mux. This can help
achieve timing, since the phys are often in different parts of the FPGA.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-06 22:11:29 -05:00
Sean Anderson 9ea09f539a hub: Increase elastic buffer size
If the input and output clock enables are exactly aligned, the elastic
buffer can overflow (as it waits for 2 entries before offering, and
there's a cycle of latency). Increase the size so we don't run into that
situation.

Fixes: b351beb ("Add hub")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-06 22:11:05 -05:00
Sean Anderson 52bc62814e Add wishbone register
This module registers all signals on a wishbone bus. This increases
latency/decreases throughput, but the wishbone cores here are just for
management, so that's not really critical.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-06 22:00:41 -05:00
Sean Anderson db4c225db5 Support ENABLE_COUNTERS in hub
It's convenient to be able to adjust this parameter if the counters ever
end up on the critical path. Support adjusting it from hub.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 20:47:46 -05:00
Sean Anderson 66945f11d9 Makefile: Include example dependencies
Examples have dependencies too!

Fixes: 45b134b ("Add examples")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 20:45:55 -05:00
Sean Anderson 4b8aa53d12 Makefile: Add --no-print-critical-path-source to nextpnr arguments
This makes critical paths much more readable.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 20:44:58 -05:00
Sean Anderson db41a68f1a mdio_regs: Delay counter signals by one clock
The counters in this module end up on the critical path a lot.  The
counters themselves take 3-4 ns to compute, but routing the increment
signal to the counter eats up a lot of slack. Register the increment signal
for a clock to let it cross the FPGA without affecting the counter timing.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 20:35:35 -05:00
Sean Anderson 003e5e4b79 mdio_regs: Fix ack/err generation
ack/err can only be combinatorial if data_read is also combinatorial.
I suspect doing that will kill my Fmax, so register ack/err.

Fixes: d9602b6 ("Add MII management functions")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 20:30:14 -05:00
Sean Anderson 924079cabd Add reset synchronizer
Add a reset synchronizer to ensure synchronous reset release. There is
also a glitch filter to reject spurious resets. It will reject pulses
shorter than 5 ns (or around 1.25 ns per LUT).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 16:59:17 -05:00
Sean Anderson 5f331a403c Add UART-WIshbone bridge
Add a basic bridge for debugging. It's around 50% efficient, but this
could be increased to 66% with the addition of some FIFOs. The limiting
factor is the constant overhead of the request/status bytes. If we used
a wider bus, we could get better efficiency.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 14:59:24 -05:00
Sean Anderson 2c2527e8d9 axis_replay_buffer: Fix slave handshaking
Handshaking happens on the rising edge based on the current values of
ready/valid. Fix the current (incorrect) logic. Additionally, modify the
testbench to properly stimulate AXI stream cores. This will catch
several handshaking failures fixed in previous commits.

Fixes: 52325f2 ("Add AXI stream replay buffer")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 14:30:27 -05:00
Sean Anderson 58cebe5ac2 uart_tx: Fix AXIS handshaking
AXI stream data is transferred based on the current values of the signals,
not the previous ones. This will cause problems if the other end isn't
valid all the time. Fix this, and amend the testbench to test it.

Fixes: e44d381 ("Add UART transmit module")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 14:30:07 -05:00
Sean Anderson 1bbb6d7f41 axis_wb_bridge: Fix wishbone handshaking
The wishbone transfer logic is incorrect. We need to use signals from the
current cycle, not the previous one.

Fixes: 7514231 ("Add AXIS-Wishbone bridge")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 14:30:05 -05:00
Sean Anderson a5d1eff22b tb: axis_mii_tx: Fix failures on newer versions of cocotb
Since cocotb/cocotb#2793, writes happen before the clock instead of
after the clock. This breaks the collision test, since we test for
differing behavior over a difference of 1 ns. Fix the failure by
applying an adjustment for newer versions.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 13:26:35 -05:00
Sean Anderson ec04874781 tb: phy_core: Make signal_status more robust
signal_status and must be low for a rising edge before it goes high. At
the moment we depend on ClockEnable to wait for a rising edge. Instead,
wait for a falling edge explicitly. This makes this test less
dependent on how tx_ce is generated.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 00:13:13 -05:00
Sean Anderson 19a588bd81 Makefile: Reduce cocotb width
Newer versions of cocotb have excessively-wide logging defaults. Reduce
it to something reasonable.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 00:03:49 -05:00
Sean Anderson 139baaffcf tb: Use correct width for Xs
In several cases, not the number of Xs did not match the number of bits.
Correct this.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-05 00:03:18 -05:00
Sean Anderson 601cccd3dc uart_rx: Add state machine debug
Add a textual description of the state machine for easier debugging.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 16:43:32 -05:00
Sean Anderson 067029ad3b uart_rx: Fix incorrect handshaking
AXI stream is transferred exactly on the rising edge of the clock. Use
the current value of the signals for this, instead of past values.
Simulate a slower slave to ensure this is tested.

Fixes: a549fca ("Add UART receive module")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 16:43:22 -05:00
Sean Anderson 10a4199381 axis_wb_bridge: Fix AXIS master
The AXI stream master doesn't cope with slaves that aren't ready all the
time. There are two separate issues: first, the data was only valid for one
cycle. Second, the handshake logic was incorrect. Rectify these, and modify
the testbench to test for this condition.

Fixes: 7514231 ("Add AXIS-Wishbone bridge")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 14:32:04 -05:00
Sean Anderson d2b4351899 axis_wb_bridge: Use DATA_WIDTH parameter
This was defined but left unused. Use it for the width of various
registers.

Fixes: 7514231 ("Add AXIS-Wishbone bridge")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 14:30:26 -05:00
Sean Anderson 587a567188 tb: uart_rx: Export putchar
This function is useful for other testbenches. Export it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 14:29:31 -05:00
Sean Anderson d89fd13238 tb: uart_tx: Check stop bit
Ensure that the stop bit is asserted at the end of each character.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 13:39:09 -05:00
Sean Anderson 7110eee136 tb: uart_tx: Export getchar
This function is useful for other testbenches. Export it.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 13:38:38 -05:00
Sean Anderson d44c5b257e uart_tx: Add reset
Add a reset to match uart_rx.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 12:37:54 -05:00
Sean Anderson f09b89adeb phy_internal: Disable coltest without wishbone
When the wishbone management interface is disabled, disable coltest.

Fixes: b351beb ("Add hub")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 12:29:46 -05:00
Sean Anderson 3b49fedb6d mdio_regs: Simplify conditions
Instead of duplicating the cyc/stb condition everywhere, just reuse the
one from ack.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-04 12:28:34 -05:00
Sean Anderson 2b7e4f9f16 Add action to deploy documentation
This adds a basic action to deploy generated documentation.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-01 20:14:22 -05:00
Sean Anderson 75142311f2 Add AXIS-Wishbone bridge
This adds the core of the UART-Wishbone bridge. The protocol has
a variable-length address phase to help reduce overhead. Multiple
in-flight commands are not supported, although this could be resolved
with some FIFOs.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-01 20:14:22 -05:00
Sean Anderson 0f6d4b166f tb: mii_elastic_buffer: Remove unnecessary try/except
The value will be checked for Xs in the following comparison.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-01 19:19:31 -05:00
Sean Anderson bc78d56f05 tb: util: Use RisingEdge for ClockEnable
Signals modified by cocotb tasks may not be visible to other tasks on
the same clock cycle. This was causing issues for recv_packet, because
it might not see the same values for ready/valid driven by ClockEnable
that the DUT sees. This was worked around by sampling on the RisingEdge.
However, this can cause recv_packet to miss data. Fix this by using
RisingEdge for ClockEnable, so everything can be sampled on the
FallingEdge.

Fixes: 52325f2 ("Add AXI stream replay buffer")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-01 19:19:31 -05:00
Sean Anderson 69dd68822c tb: mdio: Export wb_read/write/err
These functions are useful for other testbenches. Export them so they
can be reused.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-03-01 19:19:31 -05:00
Sean Anderson a549fca957 Add UART receive module
Add the recieve half of the UART. It's more or less the inverse of the
transmit half, except we manage the state explicitly. I originally did
this in hopes that yosys would recode the FSM, but it doesn't like the
subtraction in the D* states. I left in the async reset anyway since it
reduces the LUT count.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-28 23:50:36 -05:00
Sean Anderson 3f61f85a1f tb: axis_mii_buffer: Export recv_packet
Export recv_packet for use by other testbenches. This is mostly
straightforward, except we need the ability to manually specify when
last should be asserted (to handle replays).

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-28 22:26:05 -05:00
Sean Anderson e44d381c20 Add UART transmit module
I join everyone and their mother in creating my own UART. 8n1 only, and 2
baud rates. Accepts AXI-stream.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-28 22:26:05 -05:00
Sean Anderson 81de945030 Makefile: Silence warnings about array sensitivity
Icarus verilog complains if you are sensitive to every element in an
array:

rtl/mii_elastic_buffer.v:78: warning: @* is sensitive to all 5 words in array 'data'.

This makes sense if you intend to synthesize this array to a block RAM,
but not really if it's supposed to be registers. Silence this warning.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson e27d79b7c1 Add a README
It is high time to add some documentation.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson c5fc850587 Makefile: Define ICEPACK
This is necessary for creating bitstreams.

Fixes: 5cf02e9 ("Support building actual bitstreams")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00
Sean Anderson 165b60b7b2 Makefile: Add some missing modules
Add some modules to test with which were previously missing.

Fixes: b68e131 ("Add a basic hub")
Fixes: 0495ae3 ("Add TX MAC (most of it)")
Signed-off-by: Sean Anderson <seanga2@gmail.com>
2023-02-20 23:34:10 -05:00