amaranth icon indicating copy to clipboard operation
amaranth copied to clipboard

[RFC] Allow DiffPairs and Pins to be inverted individually

Open anuejn opened this issue 5 years ago • 15 comments

Currently, DiffPairs and Pins can be either inverted completely or not at all. This is a problem in corner cases where the hardware inverts some parts of a logical Bundle of ios (for example to ease routing in case of differential pairs; see #386).

I hereby propose to extend the Platform DSL in the following way:

  • Add a invert= kwarg to the constructor of DiffPairs
  • Allow Tuples of booleans of the width of the pin list to be passed to the invert= kwarg of both DiffPairs and Pins. Each bool in the tuple then controls the inversion of one pin / differential pair.

anuejn avatar Oct 20 '20 09:10 anuejn

Right, this is the obvious solution. The main issue I see with it is that when you have a lot of diffpairs, it can be hard to correlate the booleans in the invert= tuple with the actual diffpairs.

whitequark avatar Oct 20 '20 10:10 whitequark

As an alternative I was wondering if something like DiffPairs("A1 !A2", "B1 !B2") would work. The ! sigils would then have to match in both the P and the N pin lists. Of course, invert=True should still invert all of them, and conversely, it probably makes sense to accept ! for single-ended pins too.

whitequark avatar Oct 20 '20 10:10 whitequark

I like putting it in the pin list string(s), it's compact but I think also quite clear. Maybe "~A1" would be a better match to the nmigen negation syntax?

adamgreig avatar Oct 20 '20 10:10 adamgreig

Sure, ~ is fine by me.

whitequark avatar Oct 20 '20 10:10 whitequark

I also really like that idea :)

anuejn avatar Oct 20 '20 10:10 anuejn

Sounds great. I'll bring this up on the next meeting but I think you can start implementing it as it seems unlikely anyone's going to be opposed.

whitequark avatar Oct 20 '20 10:10 whitequark

sounds good :)

anuejn avatar Oct 20 '20 10:10 anuejn

I think we should support similar syntax for the use with connectors (which can be routed through e.g. inverted level shifters or have crossed differential pairs). So I think it would be nice to have syntax elements in connectors that can say "invert this signal if it is a diff pair" or "invert this signal always".

I propose that we use ~ for always invert and ? for invert in differential pairs in connectors.

anuejn avatar Oct 21 '20 09:10 anuejn

I would like to avoid introducing that functionality (and the associated syntactic burden) until someone actually needs it.

whitequark avatar Oct 21 '20 09:10 whitequark

/me needs the latter (inverted differential pairs in connectors)

anuejn avatar Oct 21 '20 09:10 anuejn

Okay. I still think it should be done separately because while this one is fairly straightforward (it's just a way to write a tuple that's less error prone than usual), what you request with connectors requires completely rethinking the way we do connectors.

whitequark avatar Oct 21 '20 10:10 whitequark

Okay I see that. So I will implement this RFC as-is and go with out of tree hacks for now. If I really need this feature to become upstream I will write another RFC :)

anuejn avatar Oct 21 '20 10:10 anuejn

I think we can do it upstream; I said earlier that I'd like to avoid introducing it because it sounded theoretical (which is usually bad because features done in abstract tend to not survive collision with reality). If you actually hit that problem I think we can certainly add it. Let's discuss the connector semantics on the next meeting?

whitequark avatar Oct 21 '20 10:10 whitequark

Okay :+1:

anuejn avatar Oct 21 '20 10:10 anuejn

We discussed inversion of connector signals at the last meeting. Because inversion of single ended signals is rarely needed and can also complicate things even further (you have to keep track of two layers of inversion rather than one), we decided that we would implement inversion in connectors but only for diff pairs. Connecting a single-ended signal to an inverted connector pin would be a hard error. If it turns out to be worth the complexity in the future we can always accept it.

whitequark avatar Oct 26 '20 18:10 whitequark