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

Subversion Repositories ahb_slave

[/] [ahb_slave/] [trunk/] [src/] [gen/] [prgen_rand.v] - Diff between revs 9 and 11

Only display areas with differences | Details | Blame | View Log

Rev 9 Rev 11
/////////////////////////////////////////////////////////////////////
<##//////////////////////////////////////////////////////////////////
////                                                             ////
////                                                             ////
////  Author: Eyal Hochberg                                      ////
////  Author: Eyal Hochberg                                      ////
////          eyal@provartec.com                                 ////
////          eyal@provartec.com                                 ////
////                                                             ////
////                                                             ////
////  Downloaded from: http://www.opencores.org                  ////
////  Downloaded from: http://www.opencores.org                  ////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////                                                             ////
////                                                             ////
//// Copyright (C) 2010 Provartec LTD                            ////
//// Copyright (C) 2010 Provartec LTD                            ////
//// www.provartec.com                                           ////
//// www.provartec.com                                           ////
//// info@provartec.com                                          ////
//// info@provartec.com                                          ////
////                                                             ////
////                                                             ////
//// This source file may be used and distributed without        ////
//// This source file may be used and distributed without        ////
//// restriction provided that this copyright statement is not   ////
//// restriction provided that this copyright statement is not   ////
//// removed from the file and that any derivative work contains ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
//// the original copyright notice and the associated disclaimer.////
////                                                             ////
////                                                             ////
//// This source file is free software; you can redistribute it  ////
//// This source file is free software; you can redistribute it  ////
//// and/or modify it under the terms of the GNU Lesser General  ////
//// and/or modify it under the terms of the GNU Lesser General  ////
//// Public License as published by the Free Software Foundation.////
//// Public License as published by the Free Software Foundation.////
////                                                             ////
////                                                             ////
//// This source is distributed in the hope that it will be      ////
//// This source is distributed in the hope that it will be      ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
//// PURPOSE.  See the GNU Lesser General Public License for more////
//// PURPOSE.  See the GNU Lesser General Public License for more////
//// details. http://www.gnu.org/licenses/lgpl.html              ////
//// details. http://www.gnu.org/licenses/lgpl.html              ////
////                                                             ////
////                                                             ////
/////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////##>
 
 
OUTFILE prgen_rand.v
OUTFILE prgen_rand.v
 
 
function integer rand_chance;
function integer rand_chance;
      input [31:0] chance_true;
      input [31:0] chance_true;
 
 
      begin
      begin
         if (chance_true > 100)
         if (chance_true > 100)
           begin
           begin
              $display("RAND_CHANCE-E-: fatal error, rand_chance called with percent chance larger than 100.\tTime: %0d ns", $time);
              $display("RAND_CHANCE-E-: fatal error, rand_chance called with percent chance larger than 100.\tTime: %0d ns", $time);
              $finish;
              $finish;
           end
           end
         rand_chance = (rand(1,100) <= chance_true);
         rand_chance = (rand(1,100) <= chance_true);
      end
      end
endfunction // rand_chance
endfunction // rand_chance
 
 
 
 
function integer rand;
function integer rand;
      input [31:0] min;
      input [31:0] min;
      input [31:0] max;
      input [31:0] max;
 
 
      integer      range;
      integer      range;
      begin
      begin
         if (min > max)
         if (min > max)
           begin
           begin
              $display("RAND-E-: fatal error, rand was called with min larger than max.\tTime: %0d ns", $time);
              $display("RAND-E-: fatal error, rand was called with min larger than max.\tTime: %0d ns", $time);
              $finish;
              $finish;
           end
           end
 
 
         range = (max - min) + 1;
         range = (max - min) + 1;
         if (range == 0) range = -1;
         if (range == 0) range = -1;
         rand  = min + ($random % range);
         rand  = min + ($random % range);
      end
      end
endfunction // rand
endfunction // rand
 
 
 
 
function integer align;
function integer align;
      input [31:0]  num;
      input [31:0]  num;
      input [31:0]  align_size;
      input [31:0]  align_size;
 
 
      begin
      begin
         align = num - (num % align_size);
         align = num - (num % align_size);
      end
      end
endfunction
endfunction
 
 
 
 
function integer rand_align;
function integer rand_align;
      input [31:0] min;
      input [31:0] min;
      input [31:0] max;
      input [31:0] max;
      input [31:0] align_val;
      input [31:0] align_val;
 
 
      begin
      begin
         rand_align = rand(min, max);
         rand_align = rand(min, max);
 
 
         if (rand_align > align_val)
         if (rand_align > align_val)
           rand_align = align(rand_align, align_val);
           rand_align = align(rand_align, align_val);
      end
      end
endfunction
endfunction
 
 
 
 

powered by: WebSVN 2.1.0

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