| 1 |
-- Copyright (c) 2019 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 |
use ieee.math_real.all; |
| 25 |
use ieee.math_complex.all; |
| 26 |
|
| 27 |
library work; |
| 28 |
use work.util.all; |
| 29 |
use work.fx3_gpif_p.all; |
| 30 |
|
| 31 |
architecture micro_dma of fx3_model is |
| 32 |
|
| 33 |
constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0); |
| 34 |
constant START_COUNT : natural := 32; |
| 35 |
constant BLOCKS_PER_ITERATION : natural := 3; |
| 36 |
constant ITERATIONS : natural := 4; |
| 37 |
|
| 38 |
-- Control mapping |
| 39 |
alias dma0_rx_ack is fx3_ctl( 0); |
| 40 |
alias dma1_rx_ack is fx3_ctl( 1); |
| 41 |
alias dma2_tx_ack is fx3_ctl( 2); |
| 42 |
alias dma3_tx_ack is fx3_ctl( 3); |
| 43 |
alias dma_rx_enable is fx3_ctl( 4); |
| 44 |
alias dma_tx_enable is fx3_ctl( 5); |
| 45 |
alias dma_idle is fx3_ctl( 6); |
| 46 |
alias system_reset is fx3_ctl( 7); |
| 47 |
alias dma0_rx_reqx is fx3_ctl( 8); |
| 48 |
alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk |
| 49 |
alias dma2_tx_reqx is fx3_ctl(10); |
| 50 |
alias dma3_tx_reqx is fx3_ctl(11); |
| 51 |
|
| 52 |
type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES); |
| 53 |
signal gpif_state_rx, gpif_state_tx : gpif_state_t; |
| 54 |
|
| 55 |
signal rx_done : boolean := false; |
| 56 |
signal tx_done : boolean := false; |
| 57 |
|
| 58 |
signal rx_data : std_logic_vector(31 downto 0); |
| 59 |
signal tx_data : std_logic_vector(31 downto 0); |
| 60 |
|
| 61 |
-- Generates packed samples |
| 62 |
-- The host will pack SC16Q11 samples into an SC12Q11 format. Every 3 gpif_in |
| 63 |
-- cycles contain 4 SC12Q11 IQ pairs. |
| 64 |
-- |
| 65 |
-- Packing order: |
| 66 |
-- Buffer 1: [--Sample1(8)--|----------Sample0(24)----------] |
| 67 |
-- Buffer 2: [------Sample2(16)------|------Sample1(16)-----] |
| 68 |
-- Buffer 3: [----------Sample3(24)----------|--Sample2(8)--] |
| 69 |
function data_gen_packed(cycle : natural) return std_logic_vector is |
| 70 |
variable four_sample_buffer : std_logic_vector(95 downto 0) := (others => '0'); |
| 71 |
variable buffer_offset : integer := 0; |
| 72 |
variable sample_value_ref : integer := 0; |
| 73 |
variable I : std_logic_vector(11 downto 0) := (others => '0'); |
| 74 |
variable Q : std_logic_vector(11 downto 0) := (others => '0'); |
| 75 |
begin |
| 76 |
sample_value_ref := cycle / 3; |
| 77 |
for j in 0 to 3 loop |
| 78 |
Q := std_logic_vector(to_signed(8*sample_value_ref+2*j+1, 12)); |
| 79 |
I := std_logic_vector(to_signed(8*sample_value_ref+2*j, 12)); |
| 80 |
four_sample_buffer := Q & I & four_sample_buffer(95 downto 24); |
| 81 |
end loop; |
| 82 |
|
| 83 |
buffer_offset := (cycle mod 3) * 32; |
| 84 |
return four_sample_buffer(31+buffer_offset downto buffer_offset); |
| 85 |
end function data_gen_packed; |
| 86 |
|
| 87 |
impure function data_gen (count : natural) return std_logic_vector is |
| 88 |
variable eight_bit_msw_i : std_logic_vector(7 downto 0); |
| 89 |
variable eight_bit_msw_q : std_logic_vector(7 downto 0); |
| 90 |
variable eight_bit_lsw_i : std_logic_vector(7 downto 0); |
| 91 |
variable eight_bit_lsw_q : std_logic_vector(7 downto 0); |
| 92 |
variable msw, lsw : std_logic_vector(15 downto 0); |
| 93 |
begin |
| 94 |
if( eight_bit_mode_en = '1' ) then |
| 95 |
eight_bit_lsw_i := std_logic_vector(to_unsigned(count, 8)); |
| 96 |
eight_bit_lsw_q := std_logic_vector(to_unsigned(count+1, 8)); |
| 97 |
eight_bit_msw_i := std_logic_vector(to_unsigned(count+2, 8)); |
| 98 |
eight_bit_msw_q := std_logic_vector(to_unsigned(count+3, 8)); |
| 99 |
lsw := eight_bit_lsw_q & eight_bit_lsw_i; |
| 100 |
msw := eight_bit_msw_q & eight_bit_msw_i; |
| 101 |
else |
| 102 |
msw := std_logic_vector(to_signed(count+1, 16)); |
| 103 |
lsw := std_logic_vector(to_signed(count, 16)); |
| 104 |
end if; |
| 105 |
|
| 106 |
return (msw & lsw); |
| 107 |
end function data_gen; |
| 108 |
|
| 109 |
impure function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is |
| 110 |
begin |
| 111 |
return (rxdata = data_gen(count)); |
| 112 |
end function data_check; |
| 113 |
|
| 114 |
begin |
| 115 |
|
| 116 |
-- DCLK which isn't used |
| 117 |
fx3_ctl(9) <= '0'; |
| 118 |
|
| 119 |
fx3_ctl(3 downto 0) <= (others => 'Z'); |
| 120 |
|
| 121 |
-- Create a 100MHz clock output |
| 122 |
fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0'; |
| 123 |
|
| 124 |
-- Doneness |
| 125 |
done <= rx_done and tx_done; |
| 126 |
|
| 127 |
rx_sample_stream : process |
| 128 |
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; |
| 129 |
variable count : natural := START_COUNT; |
| 130 |
variable req_time : time; |
| 131 |
begin |
| 132 |
gpif_state_rx <= IDLE; |
| 133 |
dma0_rx_reqx <= '1'; |
| 134 |
dma1_rx_reqx <= '1'; |
| 135 |
dma_rx_enable <= '0'; |
| 136 |
rx_data <= (others => 'U'); |
| 137 |
|
| 138 |
wait until rising_edge(fx3_pclk) and system_reset = '0'; |
| 139 |
|
| 140 |
nop(fx3_pclk, 1000); |
| 141 |
|
| 142 |
wait until rising_edge(fx3_pclk) and fx3_rx_en = '1'; |
| 143 |
|
| 144 |
wait for 30 us; |
| 145 |
|
| 146 |
for j in 1 to ITERATIONS loop |
| 147 |
dma_rx_enable <= '1'; |
| 148 |
|
| 149 |
for i in 1 to BLOCKS_PER_ITERATION loop |
| 150 |
dma0_rx_reqx <= '0'; |
| 151 |
req_time := now; |
| 152 |
wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1'; |
| 153 |
wait until rising_edge( fx3_pclk ); |
| 154 |
dma0_rx_reqx <= '1'; |
| 155 |
|
| 156 |
report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time); |
| 157 |
|
| 158 |
for i in 1 to BLOCK_SIZE loop |
| 159 |
gpif_state_rx <= RX_SAMPLES; |
| 160 |
rx_data <= fx3_gpif; |
| 161 |
wait until rising_edge( fx3_pclk ); |
| 162 |
|
| 163 |
--assert data_check(count, rx_data) severity failure; |
| 164 |
|
| 165 |
count := (count + 1) mod 2048; |
| 166 |
gpif_state_rx <= IDLE; |
| 167 |
rx_data <= (others => 'X'); |
| 168 |
end loop; |
| 169 |
end loop; |
| 170 |
|
| 171 |
dma_rx_enable <= '0'; |
| 172 |
wait for 10 us; |
| 173 |
end loop; |
| 174 |
|
| 175 |
report "Done with RX sample stream"; |
| 176 |
rx_done <= true; |
| 177 |
wait; |
| 178 |
end process; |
| 179 |
|
| 180 |
tx_sample_stream : process |
| 181 |
constant TIME_BETWEEN_ITERATIONS : natural := 7000; |
| 182 |
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; |
| 183 |
variable count : natural := START_COUNT; |
| 184 |
variable cycle : natural := 0; |
| 185 |
variable timestamp_cntr : natural := 400; |
| 186 |
variable header_len : natural := 0; |
| 187 |
variable data_out : std_logic_vector(31 downto 0); |
| 188 |
variable req_time : time; |
| 189 |
begin |
| 190 |
gpif_state_tx <= IDLE; |
| 191 |
dma2_tx_reqx <= '1'; |
| 192 |
dma3_tx_reqx <= '1'; |
| 193 |
dma_tx_enable <= '0'; |
| 194 |
fx3_gpif <= (others =>'Z'); |
| 195 |
|
| 196 |
wait until rising_edge(fx3_pclk) and system_reset = '0'; |
| 197 |
|
| 198 |
nop(fx3_pclk, 1000); |
| 199 |
|
| 200 |
wait until rising_edge(fx3_pclk) and fx3_tx_en = '1'; |
| 201 |
|
| 202 |
wait for 30 us; |
| 203 |
|
| 204 |
for k in 1 to ITERATIONS loop |
| 205 |
dma_tx_enable <= '1'; |
| 206 |
|
| 207 |
for j in 1 to BLOCKS_PER_ITERATION loop |
| 208 |
header_len := 0; |
| 209 |
dma3_tx_reqx <= '0'; |
| 210 |
req_time := now; |
| 211 |
wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1'; |
| 212 |
wait until rising_edge( fx3_pclk ); |
| 213 |
wait until rising_edge( fx3_pclk ); |
| 214 |
wait until rising_edge( fx3_pclk ); |
| 215 |
dma3_tx_reqx <= '1'; |
| 216 |
|
| 217 |
report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time); |
| 218 |
|
| 219 |
|
| 220 |
if( fx3_tx_meta_en = '1') then |
| 221 |
header_len := 4; |
| 222 |
|
| 223 |
for i in 1 to 4 loop |
| 224 |
case (i) is |
| 225 |
when 1 => |
| 226 |
data_out := x"00000000"; |
| 227 |
when 2 => |
| 228 |
data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32)); |
| 229 |
if (j = BLOCKS_PER_ITERATION) then |
| 230 |
timestamp_cntr := timestamp_cntr + TIME_BETWEEN_ITERATIONS; |
| 231 |
else |
| 232 |
timestamp_cntr := timestamp_cntr + 254; |
| 233 |
end if; |
| 234 |
when 3 => |
| 235 |
data_out := (others => '0'); |
| 236 |
when 4 => |
| 237 |
data_out := (others => '1'); |
| 238 |
end case; |
| 239 |
|
| 240 |
gpif_state_tx <= TX_META; |
| 241 |
fx3_gpif <= data_out; |
| 242 |
tx_data <= data_out; |
| 243 |
wait until rising_edge( fx3_pclk ); |
| 244 |
|
| 245 |
gpif_state_tx <= IDLE; |
| 246 |
tx_data <= (others => 'X'); |
| 247 |
end loop; |
| 248 |
end if; |
| 249 |
count := 0; |
| 250 |
|
| 251 |
for i in 1 to (BLOCK_SIZE - header_len) loop |
| 252 |
gpif_state_tx <= TX_SAMPLES; |
| 253 |
data_out := data_gen(count); |
| 254 |
if packed_mode_en = '1' then |
| 255 |
data_out := data_gen_packed(cycle); |
| 256 |
end if; |
| 257 |
|
| 258 |
if( eight_bit_mode_en = '1' or packed_mode_en = '1' ) then |
| 259 |
fx3_gpif <= data_out; |
| 260 |
tx_data <= data_out; |
| 261 |
else |
| 262 |
fx3_gpif <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0); |
| 263 |
tx_data <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0); |
| 264 |
end if; |
| 265 |
wait until rising_edge( fx3_pclk ); |
| 266 |
|
| 267 |
cycle := cycle + 1; |
| 268 |
count := (count + 4) mod 128 when eight_bit_mode_en = '1' else |
| 269 |
(count + 2) mod 2048; |
| 270 |
gpif_state_tx <= IDLE; |
| 271 |
tx_data <= (others => 'X'); |
| 272 |
end loop; |
| 273 |
|
| 274 |
fx3_gpif <= (others =>'Z'); |
| 275 |
nop(fx3_pclk, 10); |
| 276 |
end loop; |
| 277 |
|
| 278 |
wait for 1.5 ms; |
| 279 |
dma_tx_enable <= '0'; |
| 280 |
wait for 10 us; |
| 281 |
end loop; |
| 282 |
|
| 283 |
report "Done with TX sample stream"; |
| 284 |
tx_done <= true; |
| 285 |
wait; |
| 286 |
end process; |
| 287 |
|
| 288 |
reset_system : process |
| 289 |
begin |
| 290 |
system_reset <= '1'; |
| 291 |
dma_idle <= '0'; |
| 292 |
nop( fx3_pclk, 100 ); |
| 293 |
system_reset <= '0'; |
| 294 |
nop( fx3_pclk, 10 ); |
| 295 |
dma_idle <= '1'; |
| 296 |
wait; |
| 297 |
end process; |
| 298 |
|
| 299 |
-- TODO: UART Interface |
| 300 |
fx3_uart_txd <= '1'; |
| 301 |
fx3_uart_cts <= '1'; |
| 302 |
|
| 303 |
assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE) |
| 304 |
or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE) |
| 305 |
or (gpif_state_rx = IDLE and gpif_state_tx = IDLE) |
| 306 |
report "gpif_state_rx and gpif_state_tx cannot both be non-idle" |
| 307 |
severity failure; |
| 308 |
|
| 309 |
end architecture micro_dma; |
| 310 |
|
| 311 |
architecture micro_packet_dma of fx3_model is |
| 312 |
|
| 313 |
constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0); |
| 314 |
constant START_COUNT : natural := 32; |
| 315 |
constant BLOCKS_PER_ITERATION : natural := 4; |
| 316 |
constant ITERATIONS : natural := 4; |
| 317 |
|
| 318 |
-- Control mapping |
| 319 |
alias dma0_rx_ack is fx3_ctl( 0); |
| 320 |
alias dma1_rx_ack is fx3_ctl( 1); |
| 321 |
alias dma2_tx_ack is fx3_ctl( 2); |
| 322 |
alias dma3_tx_ack is fx3_ctl( 3); |
| 323 |
alias dma_rx_enable is fx3_ctl( 4); |
| 324 |
alias dma_tx_enable is fx3_ctl( 5); |
| 325 |
alias dma_idle is fx3_ctl( 6); |
| 326 |
alias system_reset is fx3_ctl( 7); |
| 327 |
alias dma0_rx_reqx is fx3_ctl( 8); |
| 328 |
alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk |
| 329 |
alias dma2_tx_reqx is fx3_ctl(10); |
| 330 |
alias dma3_tx_reqx is fx3_ctl(11); |
| 331 |
|
| 332 |
type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES); |
| 333 |
signal gpif_state_rx, gpif_state_tx : gpif_state_t; |
| 334 |
|
| 335 |
signal rx_done : boolean := false; |
| 336 |
signal tx_done : boolean := false; |
| 337 |
|
| 338 |
signal rx_data : std_logic_vector(31 downto 0); |
| 339 |
signal tx_data : std_logic_vector(31 downto 0); |
| 340 |
|
| 341 |
function data_gen (count : natural) return std_logic_vector is |
| 342 |
variable msw, lsw : std_logic_vector(15 downto 0); |
| 343 |
begin |
| 344 |
msw := (others =>'0');--std_logic_vector(to_signed(count+1, 16)); |
| 345 |
lsw := std_logic_vector(to_signed(count, 16)); |
| 346 |
|
| 347 |
return (msw & lsw); |
| 348 |
end function data_gen; |
| 349 |
|
| 350 |
function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is |
| 351 |
begin |
| 352 |
return (rxdata = data_gen(count)); |
| 353 |
end function data_check; |
| 354 |
|
| 355 |
begin |
| 356 |
|
| 357 |
-- DCLK which isn't used |
| 358 |
fx3_ctl(9) <= '0'; |
| 359 |
|
| 360 |
fx3_ctl(3 downto 0) <= (others => 'Z'); |
| 361 |
|
| 362 |
-- Create a 100MHz clock output |
| 363 |
fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0'; |
| 364 |
|
| 365 |
-- Doneness |
| 366 |
done <= rx_done and tx_done; |
| 367 |
|
| 368 |
rx_sample_stream : process |
| 369 |
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; |
| 370 |
variable count : natural := START_COUNT; |
| 371 |
variable req_time : time; |
| 372 |
begin |
| 373 |
gpif_state_rx <= IDLE; |
| 374 |
dma0_rx_reqx <= '1'; |
| 375 |
dma1_rx_reqx <= '1'; |
| 376 |
dma_rx_enable <= '0'; |
| 377 |
rx_data <= (others => 'U'); |
| 378 |
|
| 379 |
wait until rising_edge(fx3_pclk) and system_reset = '0'; |
| 380 |
|
| 381 |
nop(fx3_pclk, 1000); |
| 382 |
|
| 383 |
wait until rising_edge(fx3_pclk) and fx3_rx_en = '1'; |
| 384 |
|
| 385 |
wait for 30 us; |
| 386 |
|
| 387 |
for j in 1 to ITERATIONS loop |
| 388 |
dma_rx_enable <= '1'; |
| 389 |
|
| 390 |
for i in 1 to BLOCKS_PER_ITERATION loop |
| 391 |
dma0_rx_reqx <= '0'; |
| 392 |
req_time := now; |
| 393 |
wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1'; |
| 394 |
wait until rising_edge( fx3_pclk ); |
| 395 |
dma0_rx_reqx <= '1'; |
| 396 |
|
| 397 |
report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time); |
| 398 |
|
| 399 |
for i in 1 to BLOCK_SIZE loop |
| 400 |
gpif_state_rx <= RX_SAMPLES; |
| 401 |
rx_data <= fx3_gpif; |
| 402 |
wait until rising_edge( fx3_pclk ); |
| 403 |
|
| 404 |
--assert data_check(count, rx_data) severity failure; |
| 405 |
|
| 406 |
count := (count + 1) mod 2048; |
| 407 |
gpif_state_rx <= IDLE; |
| 408 |
rx_data <= (others => 'X'); |
| 409 |
end loop; |
| 410 |
end loop; |
| 411 |
|
| 412 |
dma_rx_enable <= '0'; |
| 413 |
wait for 10 us; |
| 414 |
end loop; |
| 415 |
|
| 416 |
report "Done with RX sample stream"; |
| 417 |
rx_done <= true; |
| 418 |
wait; |
| 419 |
end process; |
| 420 |
|
| 421 |
tx_sample_stream : process |
| 422 |
constant TIME_BETWEEN_ITERATIONS : natural := 4556; |
| 423 |
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; |
| 424 |
variable count : natural := START_COUNT; |
| 425 |
variable timestamp_cntr : natural := 250; |
| 426 |
variable header_len : natural := 0; |
| 427 |
variable packet_len : natural := 0; |
| 428 |
variable data_out : std_logic_vector(31 downto 0); |
| 429 |
variable req_time : time; |
| 430 |
begin |
| 431 |
gpif_state_tx <= IDLE; |
| 432 |
dma2_tx_reqx <= '1'; |
| 433 |
dma3_tx_reqx <= '1'; |
| 434 |
dma_tx_enable <= '0'; |
| 435 |
fx3_gpif <= (others =>'Z'); |
| 436 |
|
| 437 |
wait until rising_edge(fx3_pclk) and system_reset = '0'; |
| 438 |
|
| 439 |
nop(fx3_pclk, 1000); |
| 440 |
|
| 441 |
wait until rising_edge(fx3_pclk) and fx3_tx_en = '1'; |
| 442 |
|
| 443 |
wait for 30 us; |
| 444 |
|
| 445 |
for k in 1 to ITERATIONS loop |
| 446 |
dma_tx_enable <= '1'; |
| 447 |
|
| 448 |
for j in 1 to BLOCKS_PER_ITERATION loop |
| 449 |
header_len := 0; |
| 450 |
dma3_tx_reqx <= '0'; |
| 451 |
req_time := now; |
| 452 |
wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1'; |
| 453 |
wait until rising_edge( fx3_pclk ); |
| 454 |
wait until rising_edge( fx3_pclk ); |
| 455 |
wait until rising_edge( fx3_pclk ); |
| 456 |
dma3_tx_reqx <= '1'; |
| 457 |
|
| 458 |
report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time); |
| 459 |
|
| 460 |
|
| 461 |
packet_len := 36; |
| 462 |
if( fx3_tx_meta_en = '1') then |
| 463 |
header_len := 4; |
| 464 |
|
| 465 |
for i in 1 to 4 loop |
| 466 |
case (i) is |
| 467 |
when 1 => |
| 468 |
data_out := x"100000" & std_logic_vector(to_unsigned(packet_len-1, 8)); |
| 469 |
when 2 => |
| 470 |
data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32)); |
| 471 |
if (j = BLOCKS_PER_ITERATION) then |
| 472 |
timestamp_cntr := timestamp_cntr + TIME_BETWEEN_ITERATIONS; |
| 473 |
else |
| 474 |
timestamp_cntr := timestamp_cntr + 50; |
| 475 |
end if; |
| 476 |
when 3 => |
| 477 |
data_out := (others => '0'); |
| 478 |
when 4 => |
| 479 |
data_out := (others => '1'); |
| 480 |
end case; |
| 481 |
|
| 482 |
gpif_state_tx <= TX_META; |
| 483 |
fx3_gpif <= data_out; |
| 484 |
tx_data <= data_out; |
| 485 |
wait until rising_edge( fx3_pclk ); |
| 486 |
|
| 487 |
gpif_state_tx <= IDLE; |
| 488 |
tx_data <= (others => 'X'); |
| 489 |
end loop; |
| 490 |
end if; |
| 491 |
count := 0; |
| 492 |
|
| 493 |
for i in 1 to packet_len loop |
| 494 |
gpif_state_tx <= TX_SAMPLES; |
| 495 |
data_out := data_gen(count); |
| 496 |
fx3_gpif <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0); |
| 497 |
tx_data <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0); |
| 498 |
wait until rising_edge( fx3_pclk ); |
| 499 |
|
| 500 |
count := (count + 1) mod 2048; |
| 501 |
gpif_state_tx <= IDLE; |
| 502 |
tx_data <= (others => 'X'); |
| 503 |
end loop; |
| 504 |
|
| 505 |
fx3_gpif <= (others =>'Z'); |
| 506 |
nop(fx3_pclk, 10); |
| 507 |
end loop; |
| 508 |
|
| 509 |
wait for 1 ms; |
| 510 |
dma_tx_enable <= '0'; |
| 511 |
wait for 10 us; |
| 512 |
end loop; |
| 513 |
|
| 514 |
report "Done with TX sample stream"; |
| 515 |
tx_done <= true; |
| 516 |
wait; |
| 517 |
end process; |
| 518 |
|
| 519 |
reset_system : process |
| 520 |
begin |
| 521 |
system_reset <= '1'; |
| 522 |
dma_idle <= '0'; |
| 523 |
nop( fx3_pclk, 100 ); |
| 524 |
system_reset <= '0'; |
| 525 |
nop( fx3_pclk, 10 ); |
| 526 |
dma_idle <= '1'; |
| 527 |
wait; |
| 528 |
end process; |
| 529 |
|
| 530 |
-- TODO: UART Interface |
| 531 |
fx3_uart_txd <= '1'; |
| 532 |
fx3_uart_cts <= '1'; |
| 533 |
|
| 534 |
assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE) |
| 535 |
or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE) |
| 536 |
or (gpif_state_rx = IDLE and gpif_state_tx = IDLE) |
| 537 |
report "gpif_state_rx and gpif_state_tx cannot both be non-idle" |
| 538 |
severity failure; |
| 539 |
|
| 540 |
end architecture micro_packet_dma; |