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.

compile package and entity

Status
Not open for further replies.

B21hasni

Junior Member level 3
Joined
Jun 10, 2018
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
252
how can I compile package and entity together,
the package is
Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;

package ALU is
	function addition (A,B: std_logic_vector) return std_logic_vector;
	function subtraction (A,B: std_logic_vector) return std_logic_vector;
	function multiplication (A,B: std_logic_vector) return std_logic_vector;
	function pass_A (A: std_logic_vector) return std_logic_vector;
	function Logical_AND (A,B: std_logic_vector) return std_logic_vector;
	function Logical_OR (A,B: std_logic_vector) return std_logic_vector;
	function shift_R (A: std_logic_vector) return std_logic_vector;
	function shift_L (A: std_logic_vector) return std_logic_vector;
		
end ALU;

package body ALU is
	function addition (A,B: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := A+B;
	return Y;
	end function;
	
	function subtraction (A,B: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := A-B;
	return Y;
	end function;
	
	function multiplication (A,B: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (31 downto 0);
	begin
	Y := A*B;
	return Y;
	end function;
	
	function pass_A (A: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := A;
	return Y;
	end function;

	function Logical_AND (A,B: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := A AND B;
	return Y;
	end function;

	function Logical_OR (A,B: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := A OR B;
	return Y;
	end function;

	function shift_R (A: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := '0'& Y(15 downto 1);
	return Y;
	end function;


	function shift_L (A: std_logic_vector) return std_logic_vector is
	variable Y: std_logic_vector (15 downto 0);
	begin
	Y := Y(14 downto 0)&'0';
	return Y;
	end function;

end package body;


the entity is
Code:
library ieee;
use ieee.std_logic_1164.all;
use work.ALU.all;

entity ALU_test is
	port(sel: in std_logic_vector(3 downto 0);
		A,B: in std_logic_vector (15 downto 0);
		Y: out std_logic_vector (31 downto 0));

end ALU_test;

architecture beh of ALU_test is
begin
	process(sel,A,B)
	begin
	if sel = "0000" then
	Y (15 downto 0) <= pass_A(A);
		elsif sel="0001" then
	Y (15 downto 0)<= Logical_AND (A,B);
		elsif sel="0010" then
	Y (15 downto 0) <= Logical_OR (A,B);
		elsif sel="0011" then
	Y (15 downto 0) <= addition (A,B);
		elsif sel= "0100" then
	Y (15 downto 0) <= subtraction (A,B);
		elsif sel="0101" then
	Y <= multiplication (A,B);
		elsif sel= "0110" then
	Y (15 downto 0) <= Shift_L (A);
		elsif sel="0111" then
	Y (15 downto 0)<= Shift_R (A);
	end if;
	end process;
end beh;

I have tried but I got this messege
Error (10481): VHDL Use Clause error at alu_test.vhd(3): design library "work" does not contain primary unit "ALU". Verify that the primary unit exists in the library and has been successfully compiled.
 

You need to add package file to the project and make sure that this file is added to the library "work".
Also at the end of package file there should be:
Code:
end package body [B][U]ALU[/U][/B];

You also need to add the following statements to the alu_test.vhd:
Code:
[B][U]library work[/U][/B];
use work.ALU.all;
 

I did not get it
I need more clarity
 

You need to add package file to the project and make sure that this file is added to the library "work".
Also at the end of package file there should be:
Code:
end package body [B][U]ALU[/U][/B];

You also need to add the following statements to the alu_test.vhd:
Code:
[B][U]library work[/U][/B];
use work.ALU.all;

This is not need. The work library is not a discrete library, it is just the current working library. So adding library work doesnt do anything.

@B21hasni

The error suggests you did not compile the ALU package before ALU_test, or you did not compile it into the same library.
 

how can I compile them in the same library????
 

Unless you specify a library, they will both be compiled into the work library.
Where is your compile script?
Have you even compiled the ALU package?
 

Unless you specify a library, they will both be compiled into the work library.
Where is your compile script?
Have you even compiled the ALU package?

Is there any way to specify a library with a literal name of "work" when compiling an entity into a non-work library? I recall this being a reason why having multiple libraries fell out of favor at the last FPGA place I worked.
 

Most tools require that you create a work library before anything will compile. But then you can map any library to any folder (and set the name during mapping).
If you dont specify a library, tools compile to "work" by default (unless you're Xilinx and it defaults to Xil_defaultlib as they used to make work an explicit library, against the VHDL LRM)
 

Hi,

Just to chip in.

I think it is has to do with elaboration. Run analysis and elaboration on the package and try to compile both again.
 

I used Quartus Prime 15.1 Lite Edition software to compile the design.
I haven't compiled ALU package before
 

Using Quartus, the package source must be added to the project. Apparently you didn't.
 

Using Quartus, the package source must be added to the project. Apparently you didn't.

How can I add the package source to the Project??
 

See Project/Add current file to project, similarly the add/remove files dialog below.
 

the code in ALU package use work.ALU.all;

what does this line
Code:
use work.ALU.all;
mean?
what does it function?
 

Re: the code in ALU package use work.ALU.all;

It makes the contents of the ALU package from the work library visible
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top