Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
21615 Discussions

How to use functions in packages on testbench code.

Altera_Forum
Honored Contributor II
1,384 Views

Hi all, 

How to use functions in the packages to testbench to give inputs a and b code.  

 

function to_max(a, b : integer) return integer is 

variable output :integer; 

begin 

if (a > b)then 

output := a; 

return output ; 

else 

output := b; 

return output; 

end if; 

 

Thanks in advance  

Regards 

Raghavendra
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
540 Views

include it as all other packages. e.g.: use work.my_functions.all

0 Kudos
Altera_Forum
Honored Contributor II
540 Views

eg: 

 

package my_function is  

function to_max(a, b : integer) return integer is 

variable output :integer; 

begin 

if (a > b)then 

output := a; 

return output ; 

else 

output := b; 

return output; 

end if; 

end package my_functions 

 

library ieee 

library work 

use work.my_functions.all 

 

entity test_program is 

port ( 

x,y : in integer; 

y : out integer 

); 

 

architecture beh of test_program is 

begin 

y =to_max(x,y) ; 

end architecture beh; 

 

not synthesizable code but this is just a guide. hope it helps
0 Kudos
Altera_Forum
Honored Contributor II
540 Views

Thanks..How can i use in testbench code.

0 Kudos
Altera_Forum
Honored Contributor II
540 Views

 

--- Quote Start ---  

Thanks..How can i use in testbench code. 

--- Quote End ---  

 

 

1. Start by reading the two replies that you got to your question when you first posted it. 

2. If you're still confused, then ask a question about where you are confused by those two replies 

3. Don't ask the same question twice, when it was answered the first time. 

 

KJ
0 Kudos
Reply