1 |
c62f5734
|
Christian Daniel
|
---------------------------------------------------------------------------------------------------
|
2 |
|
|
-- Filename : usbrx_regbank.vhd
|
3 |
|
|
-- Project : OsmoSDR FPGA Firmware
|
4 |
|
|
-- Purpose : Registerbank
|
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 |
|
|
library ieee;
|
25 |
|
|
use ieee.std_logic_1164.all;
|
26 |
|
|
use ieee.numeric_std.all;
|
27 |
|
|
library work;
|
28 |
|
|
use work.all;
|
29 |
|
|
use work.mt_toolbox.all;
|
30 |
|
|
use work.usbrx.all;
|
31 |
|
|
|
32 |
|
|
entity usbrx_regbank is
|
33 |
|
|
port(
|
34 |
|
|
-- common
|
35 |
|
|
clk : in std_logic;
|
36 |
|
|
reset : in std_logic;
|
37 |
|
|
|
38 |
|
|
-- config
|
39 |
|
|
cfg_pwm : out usbrx_pwm_config_t;
|
40 |
83340d0b
|
Christian Daniel
|
cfg_gpio : out usbrx_gpio_config_t;
|
41 |
c62f5734
|
Christian Daniel
|
cfg_adc : out usbrx_adc_config_t;
|
42 |
|
|
cfg_ssc : out usbrx_ssc_config_t;
|
43 |
|
|
cfg_fil : out usbrx_fil_config_t;
|
44 |
|
|
cfg_off : out usbrx_off_config_t;
|
45 |
|
|
|
46 |
83340d0b
|
Christian Daniel
|
-- status
|
47 |
|
|
stat_ref : in usbrx_ref_status_t;
|
48 |
|
|
stat_gpio : in usbrx_gpio_status_t;
|
49 |
|
|
|
50 |
c62f5734
|
Christian Daniel
|
-- SPI interface
|
51 |
|
|
spi_ncs : in std_logic;
|
52 |
|
|
spi_sclk : in std_logic;
|
53 |
|
|
spi_mosi : in std_logic;
|
54 |
|
|
spi_miso : out std_logic
|
55 |
|
|
);
|
56 |
|
|
end usbrx_regbank;
|
57 |
|
|
|
58 |
|
|
architecture rtl of usbrx_regbank is
|
59 |
|
|
|
60 |
|
|
-- bus interface
|
61 |
|
|
signal bus_rena : std_logic;
|
62 |
|
|
signal bus_wena : std_logic;
|
63 |
|
|
signal bus_addr : unsigned(6 downto 0);
|
64 |
|
|
signal bus_rdata : std_logic_vector(31 downto 0);
|
65 |
|
|
signal bus_wdata : std_logic_vector(31 downto 0);
|
66 |
|
|
|
67 |
|
|
-- registers
|
68 |
|
|
signal reg_pwm1 : std_logic_vector(31 downto 0);
|
69 |
|
|
signal reg_pwm2 : std_logic_vector(31 downto 0);
|
70 |
|
|
signal reg_adc : std_logic_vector(15 downto 0);
|
71 |
|
|
signal reg_ssc1 : std_logic_vector(0 downto 0);
|
72 |
|
|
signal reg_ssc2 : std_logic_vector(7 downto 0);
|
73 |
|
|
signal reg_fil : std_logic_vector(2 downto 0);
|
74 |
|
|
signal reg_off : std_logic_vector(31 downto 0);
|
75 |
83340d0b
|
Christian Daniel
|
signal reg_gain : std_logic_vector(31 downto 0);
|
76 |
|
|
signal reg_swap : std_logic_vector(0 downto 0);
|
77 |
|
|
signal reg_ioe : std_logic_vector(10 downto 0);
|
78 |
|
|
signal reg_iod : std_logic_vector(10 downto 0);
|
79 |
c62f5734
|
Christian Daniel
|
|
80 |
|
|
-- avoid block-ram inference
|
81 |
|
|
attribute syn_romstyle : string;
|
82 |
|
|
attribute syn_romstyle of rtl : architecture is "logic";
|
83 |
|
|
|
84 |
|
|
begin
|
85 |
|
|
|
86 |
|
|
-- SPI slave
|
87 |
|
|
spi: entity usbrx_spi
|
88 |
|
|
port map (
|
89 |
|
|
-- common
|
90 |
|
|
clk => clk,
|
91 |
|
|
reset => reset,
|
92 |
|
|
|
93 |
|
|
-- SPI interface
|
94 |
|
|
spi_ncs => spi_ncs,
|
95 |
|
|
spi_sclk => spi_sclk,
|
96 |
|
|
spi_mosi => spi_mosi,
|
97 |
|
|
spi_miso => spi_miso,
|
98 |
|
|
|
99 |
|
|
-- bus interface
|
100 |
|
|
bus_rena => bus_rena,
|
101 |
|
|
bus_wena => bus_wena,
|
102 |
|
|
bus_addr => bus_addr,
|
103 |
|
|
bus_rdata => bus_rdata,
|
104 |
|
|
bus_wdata => bus_wdata
|
105 |
|
|
);
|
106 |
|
|
|
107 |
|
|
-- handle requests
|
108 |
|
|
process(reset, clk)
|
109 |
|
|
begin
|
110 |
|
|
if reset = '1' then
|
111 |
|
|
bus_rdata <= (others=>'0');
|
112 |
|
|
reg_pwm1 <= x"17701F3F";
|
113 |
|
|
reg_pwm2 <= x"07D01F3F";
|
114 |
|
|
reg_adc <= x"0401";
|
115 |
|
|
reg_ssc1 <= "0";
|
116 |
|
|
reg_ssc2 <= x"01";
|
117 |
|
|
reg_fil <= "011";
|
118 |
|
|
reg_off <= x"00000000";
|
119 |
83340d0b
|
Christian Daniel
|
reg_gain <= x"80008000";
|
120 |
|
|
reg_swap <= "0";
|
121 |
|
|
reg_ioe <= "00000000000";
|
122 |
|
|
reg_iod <= "00000000000";
|
123 |
c62f5734
|
Christian Daniel
|
elsif rising_edge(clk) then
|
124 |
|
|
-- output zeros by default
|
125 |
|
|
bus_rdata <= (others=>'0');
|
126 |
|
|
|
127 |
|
|
-- handle requests
|
128 |
|
|
case to_integer(bus_addr) is
|
129 |
|
|
when 0 =>
|
130 |
|
|
-- identification
|
131 |
|
|
bus_rdata <= x"DEADBEEF";
|
132 |
|
|
|
133 |
|
|
when 1 =>
|
134 |
|
|
-- PWM #1
|
135 |
|
|
bus_rdata <= reg_pwm1;
|
136 |
|
|
if bus_wena='1' then
|
137 |
|
|
reg_pwm1 <= bus_wdata(31 downto 0);
|
138 |
|
|
end if;
|
139 |
|
|
|
140 |
|
|
when 2 =>
|
141 |
|
|
-- PWM #2
|
142 |
|
|
bus_rdata <= reg_pwm2;
|
143 |
|
|
if bus_wena='1' then
|
144 |
|
|
reg_pwm2 <= bus_wdata(31 downto 0);
|
145 |
|
|
end if;
|
146 |
|
|
|
147 |
|
|
when 3 =>
|
148 |
|
|
-- ADC interface
|
149 |
|
|
bus_rdata <= to_slv32(reg_adc);
|
150 |
|
|
if bus_wena='1' then
|
151 |
|
|
reg_adc <= bus_wdata(15 downto 0);
|
152 |
|
|
end if;
|
153 |
|
|
|
154 |
|
|
when 4 =>
|
155 |
|
|
-- SSC interface
|
156 |
|
|
bus_rdata( 0 downto 0) <= reg_ssc1;
|
157 |
|
|
bus_rdata(15 downto 8) <= reg_ssc2;
|
158 |
|
|
if bus_wena='1' then
|
159 |
|
|
reg_ssc1 <= bus_wdata( 0 downto 0);
|
160 |
|
|
reg_ssc2 <= bus_wdata(15 downto 8);
|
161 |
|
|
end if;
|
162 |
|
|
|
163 |
|
|
when 5 =>
|
164 |
83340d0b
|
Christian Daniel
|
-- <unused>
|
165 |
|
|
null;
|
166 |
c62f5734
|
Christian Daniel
|
|
167 |
|
|
when 6 =>
|
168 |
|
|
-- decimation filter
|
169 |
|
|
bus_rdata <= to_slv32(reg_fil);
|
170 |
|
|
if bus_wena='1' then
|
171 |
|
|
reg_fil <= bus_wdata(2 downto 0);
|
172 |
|
|
end if;
|
173 |
|
|
|
174 |
|
|
when 7 =>
|
175 |
83340d0b
|
Christian Daniel
|
-- sample offset
|
176 |
c62f5734
|
Christian Daniel
|
bus_rdata <= reg_off;
|
177 |
|
|
if bus_wena='1' then
|
178 |
|
|
reg_off <= bus_wdata(31 downto 0);
|
179 |
|
|
end if;
|
180 |
83340d0b
|
Christian Daniel
|
when 8 =>
|
181 |
|
|
-- sample gain
|
182 |
|
|
bus_rdata <= reg_gain;
|
183 |
|
|
if bus_wena='1' then
|
184 |
|
|
reg_gain <= bus_wdata(31 downto 0);
|
185 |
|
|
end if;
|
186 |
|
|
when 9 =>
|
187 |
|
|
-- sample swap
|
188 |
|
|
bus_rdata(0 downto 0) <= reg_swap;
|
189 |
|
|
if bus_wena='1' then
|
190 |
|
|
reg_swap <= bus_wdata( 0 downto 0);
|
191 |
|
|
end if;
|
192 |
|
|
|
193 |
|
|
when 10 =>
|
194 |
|
|
-- GPIO - output enable
|
195 |
|
|
bus_rdata(10 downto 0) <= reg_ioe;
|
196 |
|
|
if bus_wena='1' then
|
197 |
|
|
reg_ioe <= bus_wdata(10 downto 0);
|
198 |
|
|
end if;
|
199 |
|
|
when 11 =>
|
200 |
|
|
-- GPIO - output data
|
201 |
|
|
bus_rdata(10 downto 0) <= reg_iod;
|
202 |
|
|
if bus_wena='1' then
|
203 |
|
|
reg_iod <= bus_wdata(10 downto 0);
|
204 |
|
|
end if;
|
205 |
|
|
when 12 =>
|
206 |
|
|
-- GPIO - input data
|
207 |
|
|
bus_rdata(10 downto 0) <= stat_gpio.idata;
|
208 |
|
|
|
209 |
|
|
when 13 =>
|
210 |
|
|
-- reference frequency
|
211 |
|
|
bus_rdata(24 downto 0) <= std_logic_vector(stat_ref.lsb);
|
212 |
|
|
bus_rdata(31 downto 25) <= std_logic_vector(stat_ref.msb);
|
213 |
c62f5734
|
Christian Daniel
|
|
214 |
|
|
when others =>
|
215 |
|
|
-- invalid address
|
216 |
|
|
null;
|
217 |
|
|
end case;
|
218 |
|
|
end if;
|
219 |
|
|
end process;
|
220 |
|
|
|
221 |
|
|
-- map registers to config
|
222 |
|
|
cfg_pwm.freq0 <= unsigned(reg_pwm1(15 downto 0));
|
223 |
|
|
cfg_pwm.freq1 <= unsigned(reg_pwm2(15 downto 0));
|
224 |
|
|
cfg_pwm.duty0 <= unsigned(reg_pwm1(31 downto 16));
|
225 |
|
|
cfg_pwm.duty1 <= unsigned(reg_pwm2(31 downto 16));
|
226 |
|
|
cfg_adc.clkdiv <= unsigned(reg_adc( 7 downto 0));
|
227 |
|
|
cfg_adc.acqlen <= unsigned(reg_adc(15 downto 8));
|
228 |
|
|
cfg_ssc.tmode <= reg_ssc1(0);
|
229 |
|
|
cfg_ssc.clkdiv <= unsigned(reg_ssc2);
|
230 |
|
|
cfg_fil.decim <= unsigned(reg_fil);
|
231 |
|
|
cfg_fil.decim <= unsigned(reg_fil);
|
232 |
|
|
cfg_off.ioff <= signed(reg_off(15 downto 0));
|
233 |
|
|
cfg_off.qoff <= signed(reg_off(31 downto 16));
|
234 |
83340d0b
|
Christian Daniel
|
cfg_off.igain <= unsigned(reg_gain(15 downto 0));
|
235 |
|
|
cfg_off.qgain <= unsigned(reg_gain(31 downto 16));
|
236 |
|
|
cfg_off.swap <= reg_swap(0);
|
237 |
|
|
cfg_gpio.oena <= reg_ioe;
|
238 |
|
|
cfg_gpio.odata <= reg_iod;
|
239 |
c62f5734
|
Christian Daniel
|
|
240 |
|
|
end rtl;
|