1 |
c62f5734
|
Christian Daniel
|
---------------------------------------------------------------------------------------------------
|
2 |
|
|
-- Filename : usbrx_toplevel.vhd
|
3 |
|
|
-- Project : OsmoSDR FPGA Firmware Testbench
|
4 |
|
|
-- Purpose : Decimation Filter Stimulus
|
5 |
|
|
---------------------------------------------------------------------------------------------------
|
6 |
|
|
|
7 |
|
|
-----------------------------------------------------------------------------------
|
8 |
|
|
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
|
9 |
|
|
-- written by Matthias Kleffel --
|
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 as version 3 of the License, or --
|
14 |
|
|
-- --
|
15 |
|
|
-- This program is distributed in the hope that it will be useful, --
|
16 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
17 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
18 |
|
|
-- GNU General Public License V3 for more details. --
|
19 |
|
|
-- --
|
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 |
|
|
|
24 |
|
|
|
25 |
|
|
library ieee;
|
26 |
|
|
use ieee.std_logic_1164.all;
|
27 |
|
|
use ieee.std_logic_misc.all;
|
28 |
|
|
use ieee.numeric_std.all;
|
29 |
|
|
use ieee.math_real.all;
|
30 |
|
|
library work;
|
31 |
|
|
use work.all;
|
32 |
|
|
use work.mt_toolbox.all;
|
33 |
|
|
use work.mt_filter.all;
|
34 |
|
|
use work.usbrx.all;
|
35 |
|
|
|
36 |
|
|
entity tb_filter is
|
37 |
|
|
end tb_filter;
|
38 |
|
|
|
39 |
|
|
architecture rtl of tb_filter is
|
40 |
|
|
|
41 |
|
|
-- common
|
42 |
|
|
signal clk : std_logic := '1';
|
43 |
|
|
signal reset : std_logic := '1';
|
44 |
|
|
|
45 |
|
|
-- config
|
46 |
|
|
signal config : usbrx_fil_config_t;
|
47 |
|
|
|
48 |
|
|
-- input
|
49 |
|
|
signal in_clk : std_logic;
|
50 |
|
|
signal in_i : signed(15 downto 0);
|
51 |
|
|
signal in_q : signed(15 downto 0);
|
52 |
|
|
|
53 |
|
|
-- output
|
54 |
|
|
signal out_clk : std_logic;
|
55 |
|
|
signal out_i : signed(15 downto 0);
|
56 |
|
|
signal out_q : signed(15 downto 0);
|
57 |
|
|
|
58 |
|
|
begin
|
59 |
|
|
|
60 |
|
|
-- generate clock
|
61 |
|
|
clk <= not clk after 500ns / 100.0;
|
62 |
|
|
reset <= '1', '0' after 123ns;
|
63 |
|
|
|
64 |
|
|
-- set config
|
65 |
|
|
config.decim <= "110";
|
66 |
|
|
|
67 |
|
|
-- input control
|
68 |
|
|
process
|
69 |
|
|
variable t : real := 0.0;
|
70 |
|
|
variable f : real := 1.0;
|
71 |
|
|
begin
|
72 |
|
|
in_clk <= '0';
|
73 |
|
|
in_i <= to_signed(0,16);
|
74 |
|
|
in_q <= to_signed(0,16);
|
75 |
|
|
wait until rising_edge(clk) and reset='0';
|
76 |
|
|
|
77 |
|
|
loop
|
78 |
|
|
-- wait some time
|
79 |
|
|
for i in 0 to 38 loop
|
80 |
|
|
wait until rising_edge(clk);
|
81 |
|
|
end loop;
|
82 |
|
|
|
83 |
|
|
-- get sample data
|
84 |
|
|
in_i <= to_signed(integer(cos(t)*10000.0),16);
|
85 |
|
|
in_q <= to_signed(0,16);
|
86 |
|
|
|
87 |
|
|
-- input sample
|
88 |
|
|
in_clk <= '1';
|
89 |
|
|
wait until rising_edge(clk);
|
90 |
|
|
in_clk <= '0';
|
91 |
|
|
|
92 |
|
|
-- update time
|
93 |
|
|
t := t + f/2000000.0*2.0*MATH_PI;
|
94 |
|
|
if t >= 2.0*MATH_PI then
|
95 |
|
|
t := t - 2.0*MATH_PI;
|
96 |
|
|
end if;
|
97 |
|
|
|
98 |
|
|
-- update frequency
|
99 |
|
|
f := f + 1.0;
|
100 |
|
|
if f>1000000.0 then
|
101 |
|
|
f := 1.0;
|
102 |
|
|
end if;
|
103 |
|
|
end loop;
|
104 |
|
|
|
105 |
|
|
wait;
|
106 |
|
|
end process;
|
107 |
|
|
|
108 |
|
|
-- create filter core
|
109 |
|
|
uut: entity usbrx_decimate
|
110 |
|
|
port map (
|
111 |
|
|
-- common
|
112 |
|
|
clk => clk,
|
113 |
|
|
reset => reset,
|
114 |
|
|
|
115 |
|
|
-- config
|
116 |
|
|
config => config,
|
117 |
|
|
|
118 |
|
|
-- input
|
119 |
|
|
in_clk => in_clk,
|
120 |
|
|
in_i => in_i,
|
121 |
|
|
in_q => in_q,
|
122 |
|
|
|
123 |
|
|
-- output
|
124 |
|
|
out_clk => out_clk,
|
125 |
|
|
out_i => out_i,
|
126 |
|
|
out_q => out_q
|
127 |
|
|
);
|
128 |
|
|
|
129 |
|
|
end rtl;
|
130 |
|
|
|
131 |
|
|
|