OpenCores
URL https://opencores.org/ocsvn/axi_slave/axi_slave/trunk

Subversion Repositories axi_slave

[/] [axi_slave/] [trunk/] [src/] [gen/] [prgen_rand.v] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 eyalhoc
<##//////////////////////////////////////////////////////////////////
2 2 eyalhoc
////                                                             ////
3
////  Author: Eyal Hochberg                                      ////
4
////          eyal@provartec.com                                 ////
5
////                                                             ////
6
////  Downloaded from: http://www.opencores.org                  ////
7
/////////////////////////////////////////////////////////////////////
8
////                                                             ////
9
//// Copyright (C) 2010 Provartec LTD                            ////
10
//// www.provartec.com                                           ////
11
//// info@provartec.com                                          ////
12
////                                                             ////
13
//// This source file may be used and distributed without        ////
14
//// restriction provided that this copyright statement is not   ////
15
//// removed from the file and that any derivative work contains ////
16
//// the original copyright notice and the associated disclaimer.////
17
////                                                             ////
18
//// This source file is free software; you can redistribute it  ////
19
//// and/or modify it under the terms of the GNU Lesser General  ////
20
//// Public License as published by the Free Software Foundation.////
21
////                                                             ////
22
//// This source is distributed in the hope that it will be      ////
23
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
24
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
25
//// PURPOSE.  See the GNU Lesser General Public License for more////
26
//// details. http://www.gnu.org/licenses/lgpl.html              ////
27
////                                                             ////
28 13 eyalhoc
//////////////////////////////////////////////////////////////////##>
29 6 eyalhoc
 
30
OUTFILE prgen_rand.v
31
 
32
function integer rand_chance;
33
      input [31:0] chance_true;
34
 
35
      begin
36
         if (chance_true > 100)
37
           begin
38
              $display("RAND_CHANCE-E-: fatal error, rand_chance called with percent chance larger than 100.\tTime: %0d ns", $time);
39
              $finish;
40
           end
41
         rand_chance = (rand(1,100) <= chance_true);
42
      end
43
endfunction // rand_chance
44
 
45
 
46
function integer rand;
47
      input [31:0] min;
48
      input [31:0] max;
49
 
50
      integer      range;
51
      begin
52
         if (min > max)
53
           begin
54
              $display("RAND-E-: fatal error, rand was called with min larger than max.\tTime: %0d ns", $time);
55
              $finish;
56
           end
57
 
58
         range = (max - min) + 1;
59
         if (range == 0) range = -1;
60
         rand  = min + ($random % range);
61
      end
62
endfunction // rand
63
 
64
 
65
function integer align;
66
      input [31:0]  num;
67
      input [31:0]  align_size;
68
 
69
      begin
70
         align = num - (num % align_size);
71
      end
72
endfunction
73
 
74
 
75
function integer rand_align;
76
      input [31:0] min;
77
      input [31:0] max;
78 10 eyalhoc
      input [31:0] align_val;
79 6 eyalhoc
 
80
      begin
81
         rand_align = rand(min, max);
82
 
83 10 eyalhoc
         if (rand_align > align_val)
84
           rand_align = align(rand_align, align_val);
85 6 eyalhoc
      end
86
endfunction
87
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.