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

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-ip/] [core/] [GECKO3COM_simple_prng_tb.vhd] - Blame information for rev 30

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

Line No. Rev Author Line
1 29 nussgipfel
--  GECKO3COM IP Core
2
--
3
--  Copyright (C) 2009 by
4
--   ___    ___   _   _
5
--  (  _ \ (  __)( ) ( )
6
--  | (_) )| (   | |_| |   Bern University of Applied Sciences
7
--  |  _ < |  _) |  _  |   School of Engineering and
8
--  | (_) )| |   | | | |   Information Technology
9
--  (____/ (_)   (_) (_)
10
--
11
--  This program is free software: you can redistribute it and/or modify
12
--  it under the terms of the GNU General Public License as published by
13
--  the Free Software Foundation, either version 3 of the License, or
14
--  (at your option) any later version.
15
--
16
--  This program is distributed in the hope that it will be useful,
17
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
--  GNU General Public License for more details. 
20
--  You should have received a copy of the GNU General Public License
21
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
--
23
--  URL to the project description: 
24
--    http://labs.ti.bfh.ch/gecko/wiki/systems/gecko3com/start
25
--------------------------------------------------------------------------------
26
--
27
--  Author:  Christoph Zimmermann
28
--  Date of creation: 26. February 2010
29
--  Description:
30
--      Small testbench to simulate the pseudo random number generator used in
31
--      the GECKO3COM_simple_test module.
32
--
33
--      The file output is not usable for our case. To compare the data we
34
--      receive through USB we use the output from GECKO3COM_simple_prng_tb.c
35
--
36
--  Tool versions:      11.1
37
--  Dependencies:
38
--
39
--------------------------------------------------------------------------------
40
 
41
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
use ieee.std_logic_arith.all;
45
 
46
library std;
47
use std.textio.all;
48
 
49
 
50
entity GECKO3COM_simple_prng_tb is
51
end GECKO3COM_simple_prng_tb;
52
 
53
architecture simulation of GECKO3COM_simple_prng_tb is
54
 
55
  -- simulation constants
56
  constant C_SIM_DURATION : time := 80080 ns;  -- duration of simulation
57
  constant CLK_PERIOD     : time := 20 ns;
58
 
59
 
60
  -- signals
61
  signal sim_stoped      : boolean := false;
62
  signal sim_clk         : std_logic;
63
  signal sim_rst         : std_logic;
64
  signal s_prng_en       : std_logic;
65
  signal s_prng_feedback : std_logic;
66
  signal s_prng_data     : std_logic_vector(31 downto 0);
67
 
68
 
69
begin  -- simulation
70
 
71
  sim_stoped <= true after C_SIM_DURATION;
72
 
73
  -----------------------------------------------------------------------------
74
  -- Design maps
75
  ----------------------------------------------------------------------------- 
76
 
77
  sim_prng_en : process (sim_clk, sim_rst)
78
  begin
79
    if sim_rst = '0' then               -- asynchronous reset (active low)
80
      s_prng_en <= '0';
81
    elsif sim_clk'event and sim_clk = '1' then  -- rising clock edge
82
      s_prng_en <= '1';
83
    end if;
84
  end process sim_prng_en;
85
 
86
 
87
  -- purpose: linear shift register for the pseude random number
88
  --          generator (PRNG)
89
  -- type   : sequential
90
  -- inputs : i_sysclk, i_nReset, s_prng_en, s_prng_feedback
91
  -- outputs: s_prng_data
92
  prng_shiftregister : process (sim_clk, sim_rst)
93
  begin  -- process prng_shiftregister
94
    if sim_rst = '0' then               -- asynchronous reset (active low)
95
      s_prng_data <= "01010101010101010101010101010101";
96
    elsif sim_clk'event and sim_clk = '1' then  -- rising clock edge
97
      if s_prng_en = '1' then
98
        s_prng_data(31 downto 1) <= s_prng_data(30 downto 0);
99
        s_prng_data(0)           <= s_prng_feedback;
100
      end if;
101
    end if;
102
  end process prng_shiftregister;
103
 
104
  -- purpose: feedback polynom for the pseudo random number generator (PRNG)
105
  -- inputs : s_prng_data
106
  -- outputs: s_prng_feedback
107
  s_prng_feedback <= s_prng_data(15) xor s_prng_data(13) xor s_prng_data(12)
108
                     xor s_prng_data(10);
109
 
110
 
111
 
112
  -----------------------------------------------------------------------------
113
  -- CLK process
114
  -----------------------------------------------------------------------------
115
  clk_process : process
116
  begin
117
    sim_clk <= '0';
118
    wait for CLK_PERIOD/2;
119
    sim_clk <= '1';
120
    wait for CLK_PERIOD/2;
121
    if sim_stoped then
122
      wait;
123
    end if;
124
  end process;
125
 
126
  rst_process : process
127
  begin
128
    sim_rst <= '0';
129
    wait for 2*CLK_PERIOD;
130
    sim_rst <= '1';
131
    wait;
132
  end process;
133
 
134
  -----------------------------------------------------------------------------
135
  -- write file process
136
  -----------------------------------------------------------------------------
137
 
138
  write_input : process
139
    type bin_file is file of bit_vector(31 downto 0);
140
    file c_file_handle  : bin_file;
141
    --type char_file is file of character;
142
    --file c_file_handle  : char_file;
143
    variable C          : character := 'W';
144
    variable char_count : integer   := 0;
145
  begin
146
    file_open(c_file_handle, "GECKO3COM_simple_prng_tb.txt", write_mode);
147
 
148
    while sim_stoped = false loop
149
      write(c_file_handle, to_bitvector(s_prng_data));
150
      --write(c_file_handle, C);
151
      char_count := char_count + 1;
152
      wait until sim_clk = '1';
153
    end loop;
154
 
155
    file_close(c_file_handle);
156
 
157
  end process;
158
 
159
end simulation;

powered by: WebSVN 2.1.0

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