0
votes

First, I want to instantiate a bunch of generic buffers using genvar in system verilog where each instantance basically contains what the value of the index is, to make them have different names so I can tie them to an 8 bit bus, one buffer per bit.

The code may not be syntactically correct, but this is what I want to do:

genvar i;
generate
  for (i=0; i<7; i=i+1)
  begin 
   IBUFDS IBUFDS_[actual_value_of_i_here]_clk
    (
     .I (input1_reg[fire_actual_value_of_i_here_starter]),      
    .IB (input1b_reg[actual_value_of_i_here_starter]),
    .O  (output_reg[actual_value_of_i_here_starter])
     );
 end
endgenerate

I want the end result to look something like this, from 0 to 7.

IBUFDS IBUFDS_[0]_clk
    (
     .I (input1_reg[fire_0_starter]),       
    .IB (input1b_reg[fire_0_starter),
    .O  (output_reg[fire_0_starter)
     );


IBUFDS IBUFDS_[1]_clk
    (
     .I (input1_reg[fire_1_starter]),       
    .IB (input1b_reg[fire_1_starter]),
    .O  (output_reg[fire_1_starter])
     );

I don't know how to pass in the index i such that it's used in the name of the instance as well as inserted in the signal that it's connected to.

Second: I also want to do something more advanced, where in the instance name I have some array with 8 values such as farm_array[chicken, rooster, cow... etc] and I pull out string values and enter them in the instance name so the end result looks like this for example:

IBUFDS IBUFDS_chicken_0_clk
    (
     .I (input1_reg[fire_0_starter]),       
    .IB (input1b_reg[fire_0_starter),
     .O  (output_reg[fire_0_starter)
 );



IBUFDS IBUFDS_rooster_1_clk
    (
      .I (input1_reg[fire_1_starter]),      
      .IB (input1b_reg[fire_1_starter]),
      .O  (output_reg[fire_1_starter])
     );

How do I pass in string values from that array into the genvar?

1

1 Answers

0
votes

First: You don't need strings. genvar can get you close to what you want

genvar i;
generate
  for (i=0; i<7; i=i+1)
  begin : IBUFDS_
   IBUFDS clk
    (
     .I (input1_reg[i]),       
    .IB (input1b_reg[i]),
    .O  (output_reg[i])
     );
 end
endgenerate

This generates code that looks like as if you instantiations as follows

IBUFDS IBUFDS_[0].clk
    (
     .I (input1_reg[0]),        
    .IB (input1b_reg[0]),
    .O  (output_reg[0])
     );


IBUFDS IBUFDS_[1].clk
    (
     .I (input1_reg[1]),        
    .IB (input1b_reg[1]),
    .O  (output_reg[1])
     );

Note that the [0] and [1] are embedded in the symbolic instance names, you cannot use a expression like you would in an array index that evalutes to 0 and 1.

Second: There is no way to build an instance name with a string. The best you could do is to define a macro

 `define inst(name,number) IBUFDS IBUFDS_``name \
        ( \
         .I (input1_reg[number]),  \      
        .IB (input1b_reg[number]), \
        .O  (output_reg[number])   \
         );

`inst(chicken,0)
`inst(roster,1);