soc/interconnect/wishbone: Add Wishbone CDC#2158
Open
david-sawatzke wants to merge 1 commit into
Open
Conversation
Owner
|
Thanks @david-sawatzke, I'll try to review it soon. I also have an alternative version not yet upstreamed based on stream.ClockDomainCrosssing, that I used for a project recently, it would be interesting to compare each: from migen import *
from litex.gen import *
from litex.gen.genlib.misc import WaitTimer
from litex.soc.interconnect import stream
# Wishbone Clock Crossing --------------------------------------------------------------------------
# This module is a simple/minimal clock crossing module for Wishbone transactions.
class WishboneClockCrossing(LiteXModule):
def __init__(self, platform, wb_from, cd_from, wb_to, cd_to):
# S2M CDC (cd_from -> cd_to).
# ---------------------------
self.cdc_s2m = cdc_s2m = stream.ClockDomainCrossing(
layout = [
("we", 1),
("adr", 32),
("sel", 4),
("dat_w", 32),
],
cd_from = cd_from,
cd_to = cd_to,
)
# M2S CDC (cd_to -> cd_from).
# ---------------------------
self.cdc_m2s = cdc_m2s = stream.ClockDomainCrossing(
layout = [
("err", 1),
("dat_r", 32),
],
cd_from = cd_to,
cd_to = cd_from,
)
# Cross FSM.
# ----------
self.cross_fsm = cross_fsm = ClockDomainsRenamer(cd_from)(FSM(reset_state="IDLE"))
cross_fsm.act("IDLE",
If(wb_from.cyc & wb_from.stb,
NextState("SEND")
)
)
cross_fsm.act("SEND",
# Send request to CDC.
cdc_s2m.sink.valid.eq(1),
cdc_s2m.sink.we.eq(wb_from.we),
cdc_s2m.sink.adr.eq(wb_from.adr),
cdc_s2m.sink.sel.eq(wb_from.sel),
cdc_s2m.sink.dat_w.eq(wb_from.dat_w),
If(cdc_s2m.sink.ready,
NextState("RECEIVE")
)
)
cross_fsm.act("RECEIVE",
# Get response from CDC.
cdc_m2s.source.ready.eq(1),
If(cdc_m2s.source.valid,
wb_from.ack.eq(1),
wb_from.err.eq(cdc_m2s.source.err),
wb_from.dat_r.eq(cdc_m2s.source.dat_r),
NextState("IDLE")
)
)
# Access FSM.
# -----------
self.access_fsm = access_fsm = ClockDomainsRenamer(cd_to)(FSM(reset_state="IDLE"))
self.access_timer = access_timer = ClockDomainsRenamer(cd_to)(WaitTimer(64))
access_fsm.act("IDLE",
If(cdc_s2m.source.valid,
NextState("ACCESS")
)
)
access_fsm.act("ACCESS",
access_timer.wait.eq(1),
# Perform Wishbone access.
wb_to.cyc.eq(1),
wb_to.stb.eq(1),
wb_to.we.eq(cdc_s2m.source.we),
wb_to.adr.eq(cdc_s2m.source.adr),
wb_to.sel.eq(cdc_s2m.source.sel),
wb_to.dat_w.eq(cdc_s2m.source.dat_w),
If(wb_to.ack | access_timer.done,
# Send response back through CDC.
cdc_s2m.source.ready.eq(1),
cdc_m2s.sink.valid.eq(1),
cdc_m2s.sink.err.eq(wb_to.err),
cdc_m2s.sink.dat_r.eq(wb_to.dat_r),
# Err on Timeout.
If(access_timer.done,
cdc_m2s.sink.err.eq(1),
cdc_m2s.sink.dat_r.eq(0xffffffff)
),
NextState("IDLE")
)
) |
Contributor
Author
|
Taking a quick look:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a wishbone CDC implementation. Inspired by BusSynchronizer, uses the PulseSynchronizer to begin/end transaction and ensure all bus bits are stable.
Most of it is handling the WB interface definitions to generate interfaces and signals for both directions.