|
|
|
ASIC/FPGA Design and Verification Out Source Services
GHDL c interfaces and extensions random number generation.
-
Based on the
example,
I created a makefile and changed some of the source code to run in a
standalone mode. I have also found this
page
to be helpful.
This
work
may also interest you.
-
This c code generates random numbers for a VHDL test-bench. So far I did
random numbers for VHDL benches in a very cumbersome way:
Simili vhdl simulator test bench with
uniform random.
VHDL function, which generates
random numbers.
-
I created a function that receives a seed, which it will use only once, and
sample size and probability. The function then generates a number and
returns boolean if in range.
-
//random generator for GHDL
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/io.h>
char srand_f = 1;
int g_rand_c(int seed, int Pmax, int Prob) {
int rnum;
if(srand_f) {
srand( (unsigned)seed);
srand_f = 0;
}
rnum = rand() % Pmax;
return rnum > Prob ? 1 : 0;
}
-
--Part of the VHDL bench
...
package pkg_g_rand is
function g_rand (seed, Pmax, Prob: integer) return integer;
attribute foreign of g_rand : function is "VHPIDIRECT g_rand_c";
end pkg_g_rand;
package body pkg_g_rand is
function g_rand (seed, Pmax, Prob: integer) return integer is
begin
assert false report "VHPI" severity failure;
end;
end pkg_g_rand;
...
-
The code can be downloaded from:
code
|
| |