Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

question regarding usage of Generic in VHDL

Status
Not open for further replies.

habbas33

Newbie level 5
Newbie level 5
Joined
Oct 19, 2008
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,346
hi

I am little confused regarding the generic usage in vhdl... I am trying to understand some reference code and I found this...

Code:
generic (
    APPDATA_WIDTH : integer := 64
    );

port (
    clk0,rst0 :in std_logic;
    rd_data_out  : out  std_logic_vector(APPDATA_WIDTH-1 downto 0);
    wr_data_in      : in    std_logic_vector(APPDATA_WIDTH -1 downto 0);
);

in_sel_proc : process(clk0,rst0)
begin
   if (rst0 = '1') then
     ...
   elsif(clk0= '1' and clk0'event) then
   rd_data_out <=wr_data_in(127 downto 1) & '0'; -- this wr_data_in is declared 128 bit in outside module from where it is given as an input    
 end if;

my confusion is that if data width assigned using generic (appdata_width) is 64 bit, how we can assign 128 bit data to the bus.
the code is synthesizeable and implementable and does not show any error.
 

If datawidth is 64, then you can assign only 64 bits to the bus.
If you want to assign 128 bits, then change the generic value to 128.
 

yeah but this is not my code and it is working for 128 bit. I am not sure why that is the reason I put the question...
 

It looks like the designer added a generic, and then chose to ignore that generic in the code.

ie. a bug

If you set the generic to anything other than 128 it will not compile due to width missmatches.
 

my confusion is that if data width assigned using generic (appdata_width) is 64 bit, how we can assign 128 bit data to the bus.
the code is synthesizeable and implementable and does not show any error.

The value "64" in the code is only the default value, and as already pointed out, it can't work. The only explanation is that the default value is overridden when the component is instantiated. Look at the instasntiation code, it must set the generic to 128.
 

In any case it's an example of bad coding. APPDATA_WIDTH should be used in all places that depend on the actual datawidth of in/out port.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top