| 1 |
-- Copyright (c) 2017 Nuand LLC |
| 2 |
-- |
| 3 |
-- Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 |
-- of this software and associated documentation files (the "Software"), to deal |
| 5 |
-- in the Software without restriction, including without limitation the rights |
| 6 |
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 |
-- copies of the Software, and to permit persons to whom the Software is |
| 8 |
-- furnished to do so, subject to the following conditions: |
| 9 |
-- |
| 10 |
-- The above copyright notice and this permission notice shall be included in |
| 11 |
-- all copies or substantial portions of the Software. |
| 12 |
-- |
| 13 |
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 |
-- THE SOFTWARE. |
| 20 |
|
| 21 |
library ieee; |
| 22 |
use ieee.std_logic_1164.all; |
| 23 |
use ieee.numeric_std.all; |
| 24 |
|
| 25 |
library work; |
| 26 |
use work.bladerf_p.all; |
| 27 |
use work.fifo_readwrite_p.all; |
| 28 |
|
| 29 |
entity tx is |
| 30 |
generic ( |
| 31 |
NUM_STREAMS : natural := 2 |
| 32 |
); |
| 33 |
port ( |
| 34 |
tx_reset : in std_logic; |
| 35 |
tx_clock : in std_logic; |
| 36 |
tx_enable : in std_logic; |
| 37 |
|
| 38 |
meta_en : in std_logic := '0'; |
| 39 |
timestamp_reset : out std_logic := '1'; |
| 40 |
usb_speed : in std_logic; |
| 41 |
tx_underflow_led : out std_logic := '1'; |
| 42 |
tx_timestamp : in unsigned(63 downto 0); |
| 43 |
|
| 44 |
-- Triggering |
| 45 |
trigger_arm : in std_logic; |
| 46 |
trigger_fire : in std_logic; |
| 47 |
trigger_master : in std_logic; |
| 48 |
trigger_line : inout std_logic; -- this is not good, should be in/out/oe |
| 49 |
|
| 50 |
-- Packing modes |
| 51 |
eight_bit_mode_en : in std_logic := '0'; |
| 52 |
highly_packed_mode_en : in std_logic := '0'; |
| 53 |
|
| 54 |
-- Packet from host via FX3 |
| 55 |
packet_en : in std_logic; |
| 56 |
packet_empty : out std_logic; |
| 57 |
packet_control : out packet_control_t; |
| 58 |
packet_ready : in std_logic; |
| 59 |
|
| 60 |
-- Samples from host via FX3 |
| 61 |
sample_fifo_wclock : in std_logic; |
| 62 |
sample_fifo_wreq : in std_logic; |
| 63 |
sample_fifo_wdata : in std_logic_vector(TX_FIFO_T_DEFAULT.wdata'range); |
| 64 |
sample_fifo_wempty : out std_logic; |
| 65 |
sample_fifo_wfull : out std_logic; |
| 66 |
sample_fifo_wused : out std_logic_vector(TX_FIFO_T_DEFAULT.wused'range); |
| 67 |
|
| 68 |
-- Metadata from host via FX3 |
| 69 |
meta_fifo_wclock : in std_logic; |
| 70 |
meta_fifo_wreq : in std_logic; |
| 71 |
meta_fifo_wdata : in std_logic_vector(META_FIFO_TX_T_DEFAULT.wdata'range); |
| 72 |
meta_fifo_wempty : out std_logic; |
| 73 |
meta_fifo_wfull : out std_logic; |
| 74 |
meta_fifo_wused : out std_logic_vector(META_FIFO_TX_T_DEFAULT.wused'range); |
| 75 |
|
| 76 |
-- Digital Loopback Interface |
| 77 |
loopback_enabled : in std_logic; |
| 78 |
loopback_fifo_wclock : out std_logic; |
| 79 |
loopback_fifo_wreq : out std_logic; |
| 80 |
loopback_fifo_wdata : out std_logic_vector(LOOPBACK_FIFO_T_DEFAULT.wdata'range); |
| 81 |
loopback_fifo_wfull : in std_logic; |
| 82 |
loopback_fifo_wused : in std_logic_vector(LOOPBACK_FIFO_T_DEFAULT.wused'range); |
| 83 |
|
| 84 |
-- RFFE Interface |
| 85 |
dac_controls : in sample_controls_t(0 to NUM_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE); |
| 86 |
dac_streams : out sample_streams_t(0 to NUM_STREAMS-1) := (others => ZERO_SAMPLE) |
| 87 |
); |
| 88 |
end entity; |
| 89 |
|
| 90 |
architecture arch of tx is |
| 91 |
|
| 92 |
signal sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT; |
| 93 |
signal meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT; |
| 94 |
|
| 95 |
signal trigger_arm_sync : std_logic; |
| 96 |
signal trigger_line_sync : std_logic; |
| 97 |
signal sample_fifo_rempty_untriggered : std_logic; |
| 98 |
|
| 99 |
signal sample_fifo_holdoff : std_logic; |
| 100 |
signal sample_fifo_holdoff_i : std_logic; |
| 101 |
|
| 102 |
begin |
| 103 |
|
| 104 |
set_timestamp_reset : process(tx_clock, tx_reset) |
| 105 |
begin |
| 106 |
if( tx_reset = '1' ) then |
| 107 |
timestamp_reset <= '1'; |
| 108 |
elsif( rising_edge(tx_clock) ) then |
| 109 |
if( meta_en = '1' ) then |
| 110 |
timestamp_reset <= '0'; |
| 111 |
else |
| 112 |
timestamp_reset <= '1'; |
| 113 |
end if; |
| 114 |
end if; |
| 115 |
end process; |
| 116 |
|
| 117 |
-- TX sample fifo |
| 118 |
sample_fifo.aclr <= tx_reset; |
| 119 |
sample_fifo.rclock <= tx_clock; |
| 120 |
U_tx_sample_fifo : entity work.tx_fifo |
| 121 |
generic map ( |
| 122 |
LPM_NUMWORDS => 2**(sample_fifo.wused'length) |
| 123 |
) port map ( |
| 124 |
aclr => sample_fifo.aclr, |
| 125 |
|
| 126 |
wrclk => sample_fifo_wclock, |
| 127 |
wrreq => sample_fifo_wreq, |
| 128 |
data => sample_fifo_wdata, |
| 129 |
wrempty => sample_fifo_wempty, |
| 130 |
wrfull => sample_fifo_wfull, |
| 131 |
wrusedw => sample_fifo_wused, |
| 132 |
|
| 133 |
rdclk => sample_fifo.rclock, |
| 134 |
rdreq => sample_fifo.rreq, |
| 135 |
q => sample_fifo.rdata, |
| 136 |
rdempty => sample_fifo_rempty_untriggered, |
| 137 |
rdfull => sample_fifo.rfull, |
| 138 |
rdusedw => sample_fifo.rused |
| 139 |
); |
| 140 |
|
| 141 |
-- TX metadata fifo |
| 142 |
meta_fifo.aclr <= tx_reset; |
| 143 |
meta_fifo.rclock <= tx_clock; |
| 144 |
U_tx_meta_fifo : entity work.tx_meta_fifo |
| 145 |
generic map ( |
| 146 |
LPM_NUMWORDS => 2**(meta_fifo.wused'length) |
| 147 |
) port map ( |
| 148 |
aclr => meta_fifo.aclr, |
| 149 |
|
| 150 |
wrclk => meta_fifo_wclock, |
| 151 |
wrreq => meta_fifo_wreq, |
| 152 |
data => meta_fifo_wdata, |
| 153 |
wrempty => meta_fifo_wempty, |
| 154 |
wrfull => meta_fifo_wfull, |
| 155 |
wrusedw => meta_fifo_wused, |
| 156 |
|
| 157 |
rdclk => meta_fifo.rclock, |
| 158 |
rdreq => meta_fifo.rreq, |
| 159 |
q => meta_fifo.rdata, |
| 160 |
rdempty => meta_fifo.rempty, |
| 161 |
rdfull => meta_fifo.rfull, |
| 162 |
rdusedw => meta_fifo.rused |
| 163 |
); |
| 164 |
|
| 165 |
loopback_fifo_wclock <= tx_clock; |
| 166 |
|
| 167 |
loopback_proc : process( tx_clock ) |
| 168 |
begin |
| 169 |
if( rising_edge(tx_clock) ) then |
| 170 |
loopback_fifo_wdata <= sample_fifo.rdata; |
| 171 |
loopback_fifo_wreq <= sample_fifo.rreq and loopback_enabled; |
| 172 |
end if; |
| 173 |
end process; |
| 174 |
|
| 175 |
-- Pass through loopback_fifo_wfull immediately |
| 176 |
sample_fifo_holdoff <= sample_fifo_holdoff_i or |
| 177 |
(loopback_enabled and loopback_fifo_wfull); |
| 178 |
|
| 179 |
-- Persist sample fifo holdoff for a number of clocks, to give time for |
| 180 |
-- the FIFO to drain properly |
| 181 |
sample_fifo_holdoff_proc : process( tx_clock ) |
| 182 |
variable backoff_downcount : natural range 0 to 3; |
| 183 |
begin |
| 184 |
if( rising_edge(tx_clock) ) then |
| 185 |
sample_fifo_holdoff_i <= '0'; |
| 186 |
|
| 187 |
if( loopback_enabled = '1' ) then |
| 188 |
if( backoff_downcount /= 0 ) then |
| 189 |
backoff_downcount := backoff_downcount - 1; |
| 190 |
sample_fifo_holdoff_i <= '1'; |
| 191 |
end if; |
| 192 |
|
| 193 |
if( loopback_fifo_wfull = '1' ) then |
| 194 |
backoff_downcount := 3; |
| 195 |
sample_fifo_holdoff_i <= '1'; |
| 196 |
end if; |
| 197 |
end if; |
| 198 |
end if; |
| 199 |
end process; |
| 200 |
|
| 201 |
|
| 202 |
U_fifo_reader : entity work.fifo_reader |
| 203 |
generic map ( |
| 204 |
NUM_STREAMS => NUM_STREAMS, |
| 205 |
FIFO_READ_THROTTLE => 0, |
| 206 |
FIFO_USEDW_WIDTH => sample_fifo.rused'length, |
| 207 |
FIFO_DATA_WIDTH => sample_fifo.rdata'length, |
| 208 |
META_FIFO_USEDW_WIDTH => meta_fifo.rused'length, |
| 209 |
META_FIFO_DATA_WIDTH => meta_fifo.rdata'length |
| 210 |
) |
| 211 |
port map ( |
| 212 |
clock => tx_clock, |
| 213 |
reset => tx_reset, |
| 214 |
enable => tx_enable, |
| 215 |
|
| 216 |
usb_speed => usb_speed, |
| 217 |
meta_en => meta_en, |
| 218 |
packet_en => packet_en, |
| 219 |
timestamp => tx_timestamp, |
| 220 |
|
| 221 |
eight_bit_mode_en => eight_bit_mode_en, |
| 222 |
highly_packed_mode_en => highly_packed_mode_en, |
| 223 |
|
| 224 |
fifo_empty => sample_fifo.rempty, |
| 225 |
fifo_usedw => sample_fifo.rused, |
| 226 |
fifo_data => sample_fifo.rdata, |
| 227 |
fifo_read => sample_fifo.rreq, |
| 228 |
fifo_holdoff => sample_fifo_holdoff, |
| 229 |
|
| 230 |
packet_control => packet_control, |
| 231 |
packet_empty => packet_empty, |
| 232 |
packet_ready => packet_ready, |
| 233 |
|
| 234 |
meta_fifo_empty => meta_fifo.rempty, |
| 235 |
meta_fifo_usedw => meta_fifo.rused, |
| 236 |
meta_fifo_data => meta_fifo.rdata, |
| 237 |
meta_fifo_read => meta_fifo.rreq, |
| 238 |
|
| 239 |
in_sample_controls => dac_controls, |
| 240 |
out_samples => dac_streams, |
| 241 |
|
| 242 |
underflow_led => tx_underflow_led, |
| 243 |
underflow_count => open, |
| 244 |
underflow_duration => x"ffff" |
| 245 |
); |
| 246 |
|
| 247 |
txtrig : entity work.trigger(async) |
| 248 |
generic map ( |
| 249 |
DEFAULT_OUTPUT => '1' |
| 250 |
) |
| 251 |
port map ( |
| 252 |
armed => trigger_arm_sync, -- in sl |
| 253 |
fired => trigger_fire, -- in sl |
| 254 |
master => trigger_master, -- in sl |
| 255 |
trigger_in => trigger_line_sync, -- in sl |
| 256 |
trigger_out => trigger_line, -- out sl |
| 257 |
signal_in => sample_fifo_rempty_untriggered, -- in sl |
| 258 |
signal_out => sample_fifo.rempty -- out sl |
| 259 |
); |
| 260 |
|
| 261 |
|
| 262 |
U_reset_sync_txtrig_arm : entity work.reset_synchronizer |
| 263 |
generic map ( |
| 264 |
INPUT_LEVEL => '0', |
| 265 |
OUTPUT_LEVEL => '0' |
| 266 |
) |
| 267 |
port map ( |
| 268 |
clock => tx_clock, |
| 269 |
async => trigger_arm, |
| 270 |
sync => trigger_arm_sync |
| 271 |
); |
| 272 |
|
| 273 |
U_sync_txtrig_trigger : entity work.synchronizer |
| 274 |
generic map ( |
| 275 |
RESET_LEVEL => '0' |
| 276 |
) |
| 277 |
port map ( |
| 278 |
reset => tx_reset, |
| 279 |
clock => tx_clock, |
| 280 |
async => trigger_line, |
| 281 |
sync => trigger_line_sync |
| 282 |
); |
| 283 |
|
| 284 |
end architecture; |