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

Couldn't assign the register value to output port. #1566

Open
clin15-logi opened this issue Feb 27, 2025 · 5 comments
Open

Couldn't assign the register value to output port. #1566

clin15-logi opened this issue Feb 27, 2025 · 5 comments
Labels

Comments

@clin15-logi
Copy link

clin15-logi commented Feb 27, 2025

Here is my code. May I know why the r_dac_en couldn't assign to output port o_dac_en?

def __init__(self):
        super().__init__({

            # Output port
            'o_dac_en': Out(1)
        })
# end def __init__


def elaborate(self, platform):
       self.r_dac_en       = Signal(1, reset_less=True)





m.d.comb += [self.o_dac_en.eq(self.r_dac_en)]

with m.FSM(init="IDLE_STATE", domain="sync"):
         with m.State("IDLE_STATE"):
            m.d.sync += [
                self.r_dac_en.eq(0),
  
            ]

            with m.If(self.pulse_cnt != 0):
                m.next = "DAC_ENABLE_STATE"
  
            with m.Else():
                m.next = "IDLE_STATE"
  
           with m.State("DAC_ENABLE_STATE"):
            m.d.sync += [
                self.r_dac_en.eq(1),
  
            ]
          
          m.d.comb += self.pulse_cnt_clr.eq(0)

          m.next = "IDLE_STATE"
          
          return m

Verilog output:

  output o_dac_en;
  reg o_dac_en = 1'h0;
  wire r_dac_en;

  assign r_dac_en = o_dac_en;

  always @(posedge clk)
    o_dac_en <= \$16 ;

  always @* begin
    \$16  = o_dac_en;
    casez (fsm_state)
      2'h0:
          \$16  = 1'h0;
      2'h1:
          \$16  = 1'h1;
      2'h2:
          \$16  = 1'h0;
    endcase
  end

@whitequark
Copy link
Member

The way your code is written, you could swap r_dac_en and o_dac_en without any change in behavior. Because Amaranth is a compiler that outputs Verilog, not merely a Verilog preprocessor, it transforms your code in a way that preserves its behavior, but not necessarily its syntactic structure. The output appears correct to me.

@clin15-logi
Copy link
Author

Do you mean replace the o_dac_en to r_dac_en in the FSM?

@whitequark
Copy link
Member

I mean that if you swap them in the Verilog output the behavior will be the same.

@clin15-logi
Copy link
Author

Ok, why I write this kind of code, cause I didn't find any way to use like reset_less=true for In/Out port. Any suggestion? Thanks.

@whitequark
Copy link
Member

Amaranth does not guarantee that any one of an equivalent set of names will end up as a reg when you synchronously assign to it, only that one of them will. If you have a task that requires a name to be declared as a reg you will have to achieve it in some other way; without knowing which task it is I cannot give further suggestions.

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

No branches or pull requests

2 participants