Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour of Record.connect() #257

Closed
akukulanski opened this issue Oct 22, 2019 · 5 comments
Closed

Unexpected behaviour of Record.connect() #257

akukulanski opened this issue Oct 22, 2019 · 5 comments
Labels

Comments

@akukulanski
Copy link

Hi,
We saw that connect() won't connect the input and output records, nevertheless the signals are connected if they are individually described. Is that an expected behaviour?

class AxiStream(Record):
    def __init__(self, width, direction=None, name=None, fields=None):
        self.width = width
        if direction == 'sink':
            layout = [('TDATA', width, Direction.FANIN),
                      ('TVALID', 1, Direction.FANIN),
                      ('TREADY', 1, Direction.FANOUT),
                      ('TLAST', 1, Direction.FANIN)]
        elif direction == 'source':
            layout = [('TDATA', width, Direction.FANOUT),
                      ('TVALID', 1, Direction.FANOUT),
                      ('TREADY', 1, Direction.FANIN),
                      ('TLAST', 1, Direction.FANOUT)]
        Record.__init__(self, layout, name=name, fields=fields)

class DummyCore(Elaboratable):
    def __init__(self, width_in, width_out):
        self.input = AxiStream(width_in, 'sink', name='INPUT')
        self.output = AxiStream(width_out, 'source', name='OUTPUT')
    def elaborate(self, platform):
        m = Module()
        comb = m.d.comb
        #comb += self.output.connect(self.input) # does not connect the signals
        comb += self.output.TDATA.eq(self.input.TDATA)
        comb += self.output.TVALID.eq(self.input.TVALID)
        comb += self.output.TLAST.eq(self.input.TLAST)
        comb += self.input.TREADY.eq(self.output.TREADY)
        return m

Thanks,
@akukulanski, @andresdemski

@whitequark
Copy link
Contributor

The direction of connect goes the other way around: it's m.d.comb += input.connect(output1, output2, ...)

@jordens
Copy link
Member

jordens commented Oct 23, 2019

This confuses me each time. Maybe there is a better name for connect().

@whitequark
Copy link
Contributor

As I've said on IRC earlier, IMO we should deprecate connect and Direction entirely and rather have bus-specific interconnect modules.

@akukulanski
Copy link
Author

The direction of connect goes the other way around: it's m.d.comb += input.connect(output1, output2, ...)

Inverting that doesn't make the difference. Here are the variants: https://github.com/akukulanski/nmigen_testcase

The confussion cames from the ambiguity that a module's port with FANIN (sink) has FANOUT (source) from inside the module. That's what makes that .connect() from inside a module has the opposite behaviour from what one would expect.

As I've said on IRC earlier, IMO we should deprecate connect and Direction entirely and rather have bus-specific interconnect modules.

Agree!

@sbourdeauducq
Copy link
Member

This confuses me each time.

I remember it by considering how it is used in the CSR bus with OR-multiplexing: initiator.connect(target1, target2, ...)
But yes, it can be confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants