| 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 wlan_micro_packet_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 := 4; |
| 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 |
function data_gen (count : natural) return std_logic_vector is |
| 62 |
variable msw, lsw : std_logic_vector(15 downto 0); |
| 63 |
begin |
| 64 |
msw := (others =>'0');--std_logic_vector(to_signed(count+1, 16)); |
| 65 |
lsw := std_logic_vector(to_signed(count, 16)); |
| 66 |
|
| 67 |
return (msw & lsw); |
| 68 |
end function data_gen; |
| 69 |
|
| 70 |
function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is |
| 71 |
begin |
| 72 |
return (rxdata = data_gen(count)); |
| 73 |
end function data_check; |
| 74 |
|
| 75 |
type integer_array_t is array(natural range <>) of std_logic_vector(31 downto 0); |
| 76 |
constant TX_PACKET_54_ONE : integer_array_t := ( |
| 77 |
x"00000000", x"00020000", x"009a000a", x"00000000", x"000000D4", |
| 78 |
x"e110b470", x"000012e5"); |
| 79 |
|
| 80 |
constant TX_PACKET_54_TWO : integer_array_t := ( |
| 81 |
x"00000240", x"00020001", x"009a0036", x"00000000", x"02000207", |
| 82 |
x"04000300", x"06000500", x"08000700", x"0a000900", x"0c000b00", |
| 83 |
x"0e000d00", x"0f010f00", x"02010101", x"04010301", x"06010501", |
| 84 |
x"08010701", x"0a010901", x"0c010b01"); |
| 85 |
|
| 86 |
constant TX_PACKET_54_THREE : integer_array_t := ( |
| 87 |
x"00000340", x"00020002", x"009a0036", x"00000000", x"02000207", |
| 88 |
x"04000300", x"06000500", x"08000700", x"0a000900", x"0c000b00", |
| 89 |
x"0e000d00", x"0f010f00", x"02010101", x"04010301", x"06010501", |
| 90 |
x"08010701" , x"0a010901" , x"0c010b01"); |
| 91 |
|
| 92 |
constant TX_PACKET_54_FOUR : integer_array_t := ( |
| 93 |
x"00000340", x"00020001", x"009a0036", x"00000000", x"02000207", |
| 94 |
x"04000300", x"06000500", x"08000700", x"0a000900", x"0c000b00", |
| 95 |
x"0e000d00", x"0f010f00", x"02010101", x"04010301", x"06010501", |
| 96 |
x"08010701", x"0a010901", x"0c010b01"); |
| 97 |
|
| 98 |
begin |
| 99 |
|
| 100 |
-- DCLK which isn't used |
| 101 |
fx3_ctl(9) <= '0'; |
| 102 |
|
| 103 |
fx3_ctl(3 downto 0) <= (others => 'Z'); |
| 104 |
|
| 105 |
-- Create a 100MHz clock output |
| 106 |
fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0'; |
| 107 |
|
| 108 |
-- Doneness |
| 109 |
done <= rx_done and tx_done; |
| 110 |
|
| 111 |
rx_sample_stream : process |
| 112 |
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; |
| 113 |
variable count : natural := START_COUNT; |
| 114 |
variable req_time : time; |
| 115 |
begin |
| 116 |
gpif_state_rx <= IDLE; |
| 117 |
dma0_rx_reqx <= '1'; |
| 118 |
dma1_rx_reqx <= '1'; |
| 119 |
dma_rx_enable <= '0'; |
| 120 |
rx_data <= (others => 'U'); |
| 121 |
|
| 122 |
wait until rising_edge(fx3_pclk) and system_reset = '0'; |
| 123 |
|
| 124 |
nop(fx3_pclk, 1000); |
| 125 |
|
| 126 |
wait until rising_edge(fx3_pclk) and fx3_rx_en = '1'; |
| 127 |
|
| 128 |
wait for 30 us; |
| 129 |
|
| 130 |
for j in 1 to ITERATIONS loop |
| 131 |
dma_rx_enable <= '1'; |
| 132 |
|
| 133 |
for i in 1 to BLOCKS_PER_ITERATION loop |
| 134 |
dma0_rx_reqx <= '0'; |
| 135 |
req_time := now; |
| 136 |
wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1'; |
| 137 |
wait until rising_edge( fx3_pclk ); |
| 138 |
dma0_rx_reqx <= '1'; |
| 139 |
|
| 140 |
report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time); |
| 141 |
|
| 142 |
for i in 1 to BLOCK_SIZE loop |
| 143 |
gpif_state_rx <= RX_SAMPLES; |
| 144 |
rx_data <= fx3_gpif; |
| 145 |
wait until rising_edge( fx3_pclk ); |
| 146 |
|
| 147 |
--assert data_check(count, rx_data) severity failure; |
| 148 |
|
| 149 |
count := (count + 1) mod 2048; |
| 150 |
gpif_state_rx <= IDLE; |
| 151 |
rx_data <= (others => 'X'); |
| 152 |
end loop; |
| 153 |
end loop; |
| 154 |
|
| 155 |
dma_rx_enable <= '0'; |
| 156 |
wait for 10 us; |
| 157 |
end loop; |
| 158 |
|
| 159 |
report "Done with RX sample stream"; |
| 160 |
rx_done <= true; |
| 161 |
wait; |
| 162 |
end process; |
| 163 |
|
| 164 |
tx_sample_stream : process |
| 165 |
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS; |
| 166 |
variable count : natural := START_COUNT; |
| 167 |
variable timestamp_cntr : natural := 100; |
| 168 |
variable header_len : natural := 0; |
| 169 |
variable packet_len : natural := 0; |
| 170 |
variable data_out : std_logic_vector(31 downto 0); |
| 171 |
variable req_time : time; |
| 172 |
begin |
| 173 |
gpif_state_tx <= IDLE; |
| 174 |
dma2_tx_reqx <= '1'; |
| 175 |
dma3_tx_reqx <= '1'; |
| 176 |
dma_tx_enable <= '0'; |
| 177 |
fx3_gpif <= (others =>'Z'); |
| 178 |
|
| 179 |
wait until rising_edge(fx3_pclk) and system_reset = '0'; |
| 180 |
|
| 181 |
nop(fx3_pclk, 1000); |
| 182 |
|
| 183 |
wait until rising_edge(fx3_pclk) and fx3_tx_en = '1'; |
| 184 |
|
| 185 |
wait for 10 us; |
| 186 |
|
| 187 |
for k in 1 to ITERATIONS loop |
| 188 |
dma_tx_enable <= '1'; |
| 189 |
|
| 190 |
for j in 1 to BLOCKS_PER_ITERATION loop |
| 191 |
header_len := 0; |
| 192 |
dma3_tx_reqx <= '0'; |
| 193 |
req_time := now; |
| 194 |
wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1'; |
| 195 |
wait until rising_edge( fx3_pclk ); |
| 196 |
wait until rising_edge( fx3_pclk ); |
| 197 |
wait until rising_edge( fx3_pclk ); |
| 198 |
dma3_tx_reqx <= '1'; |
| 199 |
|
| 200 |
report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time); |
| 201 |
|
| 202 |
|
| 203 |
if( fx3_tx_meta_en = '1') then |
| 204 |
header_len := 4; |
| 205 |
|
| 206 |
for i in 1 to 4 loop |
| 207 |
case (i) is |
| 208 |
when 1 => |
| 209 |
if( j = 1) then |
| 210 |
packet_len := TX_PACKET_54_ONE'length; |
| 211 |
elsif( j = 2 ) then |
| 212 |
packet_len := TX_PACKET_54_TWO'length; |
| 213 |
elsif( j = 3 ) then |
| 214 |
packet_len := TX_PACKET_54_THREE'length; |
| 215 |
else |
| 216 |
packet_len := TX_PACKET_54_FOUR'length; |
| 217 |
end if; |
| 218 |
data_out := x"1000" & std_logic_vector(to_unsigned(packet_len, 16)); |
| 219 |
when 2 => |
| 220 |
--data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32)); |
| 221 |
--timestamp_cntr := timestamp_cntr + 300; |
| 222 |
data_out := (others => '0'); |
| 223 |
when 3 => |
| 224 |
data_out := (others => '0'); |
| 225 |
when 4 => |
| 226 |
data_out := (others => '1'); |
| 227 |
end case; |
| 228 |
|
| 229 |
gpif_state_tx <= TX_META; |
| 230 |
fx3_gpif <= data_out; |
| 231 |
tx_data <= data_out; |
| 232 |
wait until rising_edge( fx3_pclk ); |
| 233 |
|
| 234 |
gpif_state_tx <= IDLE; |
| 235 |
tx_data <= (others => 'X'); |
| 236 |
end loop; |
| 237 |
end if; |
| 238 |
count := 0; |
| 239 |
|
| 240 |
for i in 0 to packet_len-1 loop |
| 241 |
gpif_state_tx <= TX_SAMPLES; |
| 242 |
if( j = 1 ) then |
| 243 |
data_out := std_logic_vector(TX_PACKET_54_ONE(i)); |
| 244 |
elsif( j = 2 ) then |
| 245 |
data_out := std_logic_vector(TX_PACKET_54_TWO(i)); |
| 246 |
elsif( j = 3 ) then |
| 247 |
data_out := std_logic_vector(TX_PACKET_54_THREE(i)); |
| 248 |
else |
| 249 |
data_out := std_logic_vector(TX_PACKET_54_FOUR(i)); |
| 250 |
end if; |
| 251 |
fx3_gpif <= data_out(31 downto 0); |
| 252 |
tx_data <= data_out(31 downto 0); |
| 253 |
wait until rising_edge( fx3_pclk ); |
| 254 |
|
| 255 |
count := (count + 1) mod 2048; |
| 256 |
gpif_state_tx <= IDLE; |
| 257 |
tx_data <= (others => 'X'); |
| 258 |
end loop; |
| 259 |
|
| 260 |
fx3_gpif <= (others =>'Z'); |
| 261 |
nop(fx3_pclk, 10); |
| 262 |
end loop; |
| 263 |
|
| 264 |
wait for 8 ms; |
| 265 |
dma_tx_enable <= '0'; |
| 266 |
wait for 10 us; |
| 267 |
end loop; |
| 268 |
|
| 269 |
report "Done with TX sample stream"; |
| 270 |
tx_done <= true; |
| 271 |
wait; |
| 272 |
end process; |
| 273 |
|
| 274 |
reset_system : process |
| 275 |
begin |
| 276 |
system_reset <= '1'; |
| 277 |
dma_idle <= '0'; |
| 278 |
nop( fx3_pclk, 100 ); |
| 279 |
system_reset <= '0'; |
| 280 |
nop( fx3_pclk, 10 ); |
| 281 |
dma_idle <= '1'; |
| 282 |
wait; |
| 283 |
end process; |
| 284 |
|
| 285 |
-- TODO: UART Interface |
| 286 |
fx3_uart_txd <= '1'; |
| 287 |
fx3_uart_cts <= '1'; |
| 288 |
|
| 289 |
assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE) |
| 290 |
or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE) |
| 291 |
or (gpif_state_rx = IDLE and gpif_state_tx = IDLE) |
| 292 |
report "gpif_state_rx and gpif_state_tx cannot both be non-idle" |
| 293 |
severity failure; |
| 294 |
|
| 295 |
end architecture wlan_micro_packet_dma; |