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

Subversion Repositories ahb_slave

[/] [ahb_slave/] [trunk/] [src/] [gen/] [prgen_rand.v] - Blame information for rev 5

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

Line No. Rev Author Line
1 4 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
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
      integer       align;
70
      begin
71
         align = num - (num % align_size);
72
      end
73
endfunction
74
 
75
 
76
function integer rand_align;
77
      input [31:0] min;
78
      input [31:0] max;
79
      input [31:0] align;
80
 
81
      integer      rand_align;
82
      begin
83
         rand_align = rand(min, max);
84
 
85
         if (rand_align > align)
86
           rand_align = align(rand_align, align);
87
      end
88
endfunction
89
 

powered by: WebSVN 2.1.0

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