Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20785 Discussions

How to use functions in packages on testbench code.

Altera_Forum
Honored Contributor II
1,150 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
306 Views

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

0 Kudos
Altera_Forum
Honored Contributor II
306 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
306 Views

Thanks..How can i use in testbench code.

0 Kudos
Altera_Forum
Honored Contributor II
306 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