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

Subversion Repositories axi_master

[/] [axi_master/] [trunk/] [src/] [gen/] [prgen_rand.v] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 eyalhoc
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
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
/////////////////////////////////////////////////////////////////////
29
 
30
function integer rand_chance;
31
      input [31:0] chance_true;
32
 
33
      begin
34
         if (chance_true > 100)
35
           begin
36
              $display("RAND_CHANCE-E-: fatal error, rand_chance called with percent chance larger than 100.\tTime: %0d ns", $time);
37
              $finish;
38
           end
39
         rand_chance = (rand(1,100) <= chance_true);
40
      end
41
endfunction // rand_chance
42
 
43
 
44
function integer rand;
45
      input [31:0] min;
46
      input [31:0] max;
47
 
48
      integer      range;
49
      begin
50
         if (min > max)
51
           begin
52
              $display("RAND-E-: fatal error, rand was called with min larger than max.\tTime: %0d ns", $time);
53
              $finish;
54
           end
55
 
56
         range = (max - min) + 1;
57
         if (range == 0) range = -1;
58
         rand  = min + ($random % range);
59
      end
60
endfunction // rand
61
 
62
 
63
function integer align;
64
      input [31:0]  num;
65
      input [31:0]  align_size;
66
 
67
      integer       align;
68
      begin
69
         align = num - (num % align_size);
70
      end
71
endfunction
72
 
73
 
74
function integer rand_align;
75
      input [31:0] min;
76
      input [31:0] max;
77
      input [31:0] align;
78
 
79
      integer      rand_align;
80
      begin
81
         rand_align = rand(min, max);
82
 
83
         if (rand_align > align)
84
           rand_align = align(rand_align, align);
85
      end
86
endfunction
87
 

powered by: WebSVN 2.1.0

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