How to 'assign' a value to an output reg in Verilog?

后端 未结 4 1980
生来不讨喜
生来不讨喜 2020-12-15 02:09

( insert really basic question disclaimer here )

More specifically, I have the following declaration:

output reg icache_ram_rw

And

4条回答
  •  自闭症患者
    2020-12-15 02:41

    The assign statement is used for driving wires.

    If you've somethings declared as a reg, then you have to give it values inside a procedure ( always or initial blocks ). It's best practice to only set values of regs in the same always block. eg:

    always @( * ) begin // combo logic block
       if( some_condition ) begin
          icache_ram_rw = 1'b0;
       end else begin
          icache_ram_rw = something_else;
     end
    

    There are important differences between regs and wires that you should read up on.

    I've a feeling though that you'll need some clocked logic if you're driving RAM signals. In this case, you'll need code that looks something like this:

    // some parameter definitions to make logic 'read' clearer.
    localparam READ = 1'b0; 
    localparam WRITE = 1'b1;
    
    // standard clocked logic 'template' that synthesis tools recognise.
    always @( posedge clk or negedge resetb )
      if( !resetb ) begin  // asynchronous active low reset
         icache_ram_rw <= READ;
      end else if( some_enable_condition ) begin
         icache_ram_rw <= WRITE;
      end else begin
         icache_ram_rw <= READ;
      end
    

提交回复
热议问题