Compare commits
41 commits
master
...
dev-sc16-q
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13a573508d | ||
|
|
6364f25b36 | ||
|
|
69bf713502 | ||
|
|
88a110e269 | ||
|
|
1a1ca5c4a8 | ||
|
|
fcc6b644aa | ||
|
|
ed1292dd7e | ||
|
|
fb95949eba | ||
|
|
caa254a724 | ||
|
|
01082ec1b3 | ||
|
|
b86be34e0c | ||
|
|
de0e10e583 | ||
|
|
a9108732fe | ||
|
|
261c6a6f00 | ||
|
|
224109e7ee | ||
|
|
0789be9bbe | ||
|
|
b691245739 | ||
|
|
2c85c7be36 | ||
|
|
caf37834ee | ||
|
|
cb8a2e574b | ||
|
|
2e710ea634 | ||
|
|
5ba9b6d916 | ||
|
|
350ebbee43 | ||
|
|
2c2c4c1505 | ||
|
|
71f9cd4e9f | ||
|
|
e6bbdd69cc | ||
|
|
b0ed92eae8 | ||
|
|
0da168b823 | ||
|
|
8f2280b771 | ||
|
|
af1b2ebc7a | ||
|
|
f3010f8249 | ||
|
|
af67f86333 | ||
|
|
3c8bf68067 | ||
|
|
0dd41a3fa5 | ||
|
|
b20607fd82 | ||
|
|
ad10742e1e | ||
|
|
efbebc8e88 | ||
|
|
afd2da9cda | ||
|
|
5daf75c84e | ||
|
|
6fac4cd672 | ||
|
|
ebfb49095b |
88 changed files with 3334 additions and 161 deletions
|
|
@ -6,6 +6,11 @@ hosted on GitHub: https://github.com/nuand/bladeRF
|
|||
================================================================================
|
||||
|
||||
|
||||
v2.5.0 (2024-07-30)
|
||||
--------------------------------
|
||||
* Bumped GPIF DMA buffer size to 8192 bytes
|
||||
* Reduced the number of GPIF DMA buffers to 11 per channel
|
||||
|
||||
v2.4.0 (2020-08-01)
|
||||
--------------------------------
|
||||
* Add ability to send short packets to FX3 from FPGA
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../host/cmake/modules)
|
|||
|
||||
# Update these definitions when updating the firmware version
|
||||
set(VERSION_INFO_MAJOR 2)
|
||||
set(VERSION_INFO_MINOR 4)
|
||||
set(VERSION_INFO_MINOR 5)
|
||||
set(VERSION_INFO_PATCH 0)
|
||||
|
||||
if(NOT DEFINED VERSION_INFO_EXTRA)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ Adjust the paths as necessary on your system, depending where you installed the
|
|||
```
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake -DFX3_INSTALL_PATH=/opt/cypress/fx3_sdk -DCMAKE_TOOLCHAIN_FILE=../cmake/fx3-toolchain.cmake ../
|
||||
$ cmake -DFX3_INSTALL_PATH=/opt/cypress/fx3_firmware_linux -DCMAKE_TOOLCHAIN_FILE=../cmake/fx3-toolchain.cmake ../
|
||||
$ make
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -290,8 +290,8 @@ static void NuandRFLinkStart(void)
|
|||
}
|
||||
|
||||
CyU3PMemSet((uint8_t *)&dmaCfg, 0, sizeof(dmaCfg));
|
||||
dmaCfg.size = size * 2;
|
||||
dmaCfg.count = 22;
|
||||
dmaCfg.size = size * 8;
|
||||
dmaCfg.count = 11;
|
||||
dmaCfg.prodSckId = BLADE_RF_SAMPLE_EP_PRODUCER_USB_SOCKET;
|
||||
dmaCfg.consSckId = CY_U3P_PIB_SOCKET_3;
|
||||
dmaCfg.dmaMode = CY_U3P_DMA_MODE_BYTE;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ proc compile_fx3_gpif { root } {
|
|||
vlib work
|
||||
|
||||
vcom -2008 -work work [file join $root ./synthesis/set_clear_ff.vhd]
|
||||
vcom -2008 -work work [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd]
|
||||
vcom -2008 -work work [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif.vhd]
|
||||
vcom -2008 -work work [file join $root ./simulation/util.vhd]
|
||||
vcom -2008 -work work [file join $root ./simulation/fx3_model.vhd]
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ proc compile_nuand { root platform } {
|
|||
|
||||
vcom -work nuand -2008 [file join $root ./synthesis/tb/atsc_tx_tb.vhd]
|
||||
|
||||
vcom -work nuand -2008 [file join $root ../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd]
|
||||
vcom -work nuand -2008 [file join $root ./simulation/fx3_model.vhd]
|
||||
vcom -work nuand -2008 [file join $root ./simulation/lms6002d_model.vhd]
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ library ieee;
|
|||
|
||||
library work;
|
||||
use work.util.all;
|
||||
use work.fx3_gpif_p.all;
|
||||
|
||||
|
||||
entity fx3_model is
|
||||
port (
|
||||
|
|
@ -40,6 +42,7 @@ entity fx3_model is
|
|||
fx3_tx_en : in std_logic;
|
||||
fx3_tx_meta_en : in std_logic;
|
||||
eight_bit_mode_en : in std_logic := '0';
|
||||
packed_mode_en : in std_logic := '0';
|
||||
done : out boolean
|
||||
);
|
||||
end entity ; -- fx3_model
|
||||
|
|
@ -102,7 +105,7 @@ begin
|
|||
done <= rx_done and tx_done;
|
||||
|
||||
rx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable req_time : time;
|
||||
begin
|
||||
|
|
@ -155,7 +158,7 @@ begin
|
|||
end process;
|
||||
|
||||
tx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable timestamp_cntr : natural := 80;
|
||||
variable header_len : natural := 0;
|
||||
|
|
@ -201,7 +204,7 @@ begin
|
|||
data_out := x"12341234";
|
||||
when 2 =>
|
||||
data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32));
|
||||
timestamp_cntr := timestamp_cntr + 508 * 2;
|
||||
timestamp_cntr := timestamp_cntr + (GPIF_BUF_SIZE_SS-4) * 2;
|
||||
when 3 =>
|
||||
data_out := (others => '0');
|
||||
when 4 =>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ library nuand ;
|
|||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
library std ;
|
||||
use std.env.all ;
|
||||
|
|
@ -435,8 +436,8 @@ begin
|
|||
wait until reset = '0' ;
|
||||
end if ;
|
||||
while true loop
|
||||
wait until rising_edge(fx3_clock) and unsigned(rx_sample_fifo.rused) > 512 ;
|
||||
for i in 1 to 512 loop
|
||||
wait until rising_edge(fx3_clock) and unsigned(rx_sample_fifo.rused) > GPIF_BUF_SIZE_SS;
|
||||
for i in 1 to GPIF_BUF_SIZE_SS loop
|
||||
rx_sample_fifo.rreq <= '1' ;
|
||||
nop( fx3_clock, 1 ) ;
|
||||
if( CHECK_OVERFLOW ) then
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ library ieee;
|
|||
|
||||
library work;
|
||||
use work.fifo_readwrite_p.all;
|
||||
use work.fx3_gpif_p.all;
|
||||
|
||||
entity fifo_reader is
|
||||
generic (
|
||||
|
|
@ -43,6 +44,7 @@ entity fifo_reader is
|
|||
meta_en : in std_logic;
|
||||
packet_en : in std_logic;
|
||||
eight_bit_mode_en : in std_logic;
|
||||
highly_packed_mode_en : in std_logic;
|
||||
timestamp : in unsigned(63 downto 0);
|
||||
|
||||
fifo_usedw : in std_logic_vector(FIFO_USEDW_WIDTH-1 downto 0);
|
||||
|
|
@ -71,8 +73,8 @@ end entity;
|
|||
|
||||
architecture simple of fifo_reader is
|
||||
|
||||
constant DMA_BUF_SIZE_SS : natural := 512;
|
||||
constant DMA_BUF_SIZE_HS : natural := 256;
|
||||
constant DMA_BUF_SIZE_SS : natural := GPIF_BUF_SIZE_SS;
|
||||
constant DMA_BUF_SIZE_HS : natural := GPIF_BUF_SIZE_HS;
|
||||
|
||||
signal dma_buf_size : natural range DMA_BUF_SIZE_HS to DMA_BUF_SIZE_SS := DMA_BUF_SIZE_SS;
|
||||
signal underflow_detected : std_logic := '0';
|
||||
|
|
@ -141,6 +143,10 @@ architecture simple of fifo_reader is
|
|||
fifo_read : std_logic;
|
||||
out_samples : sample_streams_t(out_samples'range);
|
||||
eight_bit_sample_sel: std_logic;
|
||||
|
||||
-- Highly packed mode signals
|
||||
packed_buffer : std_logic_vector(47 downto 0);
|
||||
packed_cycle : integer range 0 to 3;
|
||||
end record;
|
||||
|
||||
constant FIFO_FSM_RESET_VALUE : fifo_fsm_t := (
|
||||
|
|
@ -156,7 +162,9 @@ architecture simple of fifo_reader is
|
|||
packet_data_cache => (others => '0'),
|
||||
fifo_read => '0',
|
||||
out_samples => (others => ZERO_SAMPLE),
|
||||
eight_bit_sample_sel => '0'
|
||||
eight_bit_sample_sel => '0',
|
||||
packed_buffer => (others => '0'),
|
||||
packed_cycle => 0
|
||||
);
|
||||
|
||||
signal fifo_current : fifo_fsm_t := FIFO_FSM_RESET_VALUE;
|
||||
|
|
@ -418,6 +426,67 @@ begin
|
|||
return rv;
|
||||
end function;
|
||||
|
||||
-- --------------------------------------------------------------------
|
||||
-- MIMO UNPACKER: STEP 1 of 5 (SC12Q11 Highly Packed Mode)
|
||||
-- --------------------------------------------------------------------
|
||||
-- The sample FIFO output is a wide data bus that contains multiple
|
||||
-- 12-bit I/Q samples packed across multiple cycles. This procedure unpacks
|
||||
-- data from a 64-bit wide bus across three cycles to extract eight 12-bit I/Q pairs.
|
||||
--
|
||||
-- The packing scheme for 12-bit samples across three 64-bit cycles:
|
||||
-- Cycle 1: | 63:60 | 59:48 | 47:36 | 35:24 | 23:12 | 11:0 | Bit indices
|
||||
-- | Q0' | I0 | Q1 | I1 | Q0 | I0 | Samples
|
||||
-- [-----][--------full 12-bit samples-----------]
|
||||
-- 4-bit
|
||||
-- overlap
|
||||
--
|
||||
-- Cycle 2: | 63:56 | 55:44 | 43:32 | 31:20 | 19:8 | 7:0 | Bit indices
|
||||
-- | I1' | Q0 | I0 | Q1 | I1 | Q0' | Samples
|
||||
-- [-----][--------full 12-bit samples--------][---]
|
||||
-- 8-bit 8-bit
|
||||
-- overlap overlap
|
||||
--
|
||||
-- Cycle 3: | 63:52 | 51:40 | 39:28 | 27:16 | 15:4 | 3:0 | Bit indices
|
||||
-- | Q1 | I1 | Q0 | I0 | Q1 | I1' | Samples
|
||||
-- [--------full 12-bit samples-----------][-----]
|
||||
-- 4-bit
|
||||
-- overlap
|
||||
--
|
||||
-- Note: Samples with apostrophes (') indicate partial samples that span
|
||||
-- across cycle boundaries. The complete samples are reconstructed by
|
||||
-- combining these partial segments from different cycles.
|
||||
procedure unpack_sc12q11(
|
||||
signal data : in std_logic_vector(63 downto 0);
|
||||
signal previous_data : in std_logic_vector(47 downto 0);
|
||||
signal cycle : in integer;
|
||||
variable rv : out sample_streams_t
|
||||
) is
|
||||
constant OFFSET_UNIT : natural := 24;
|
||||
begin
|
||||
for i in rv'range loop
|
||||
rv(i).data_i := resize(signed(shift_right(unsigned(data),i*OFFSET_UNIT)(11 downto 0)),rv(i).data_i'length);
|
||||
rv(i).data_q := resize(signed(shift_right(unsigned(data),i*OFFSET_UNIT)(23 downto 12)),rv(i).data_q'length);
|
||||
rv(i).data_v := '0';
|
||||
end loop;
|
||||
|
||||
if (cycle = 1) then
|
||||
rv(0).data_i := resize(signed(previous_data(43 downto 32)),rv(0).data_i'length);
|
||||
rv(0).data_q := resize(signed(data(7 downto 0) & previous_data(47 downto 44)),rv(0).data_q'length);
|
||||
rv(1).data_i := resize(signed(shift_right(unsigned(data),8)(11 downto 0)),rv(1).data_i'length);
|
||||
rv(1).data_q := resize(signed(shift_right(unsigned(data),8)(23 downto 12)),rv(1).data_q'length);
|
||||
elsif (cycle = 2) then
|
||||
rv(0).data_i := resize(signed(previous_data(27 downto 16)),rv(0).data_i'length);
|
||||
rv(0).data_q := resize(signed(previous_data(39 downto 28)),rv(0).data_q'length);
|
||||
rv(1).data_i := resize(signed(fifo_data(3 downto 0) & previous_data(47 downto 40)), rv(1).data_i'length);
|
||||
rv(1).data_q := resize(signed(fifo_data(15 downto 4)), rv(1).data_q'length);
|
||||
elsif (cycle = 3) then
|
||||
rv(0).data_i := resize(signed(previous_data(11 downto 0)),rv(0).data_i'length);
|
||||
rv(0).data_q := resize(signed(previous_data(23 downto 12)),rv(0).data_q'length);
|
||||
rv(1).data_i := resize(signed(previous_data(35 downto 24)),rv(0).data_i'length);
|
||||
rv(1).data_q := resize(signed(previous_data(47 downto 36)),rv(0).data_q'length);
|
||||
end if;
|
||||
end procedure;
|
||||
|
||||
-- --------------------------------------------------------------------
|
||||
-- MIMO UNPACKER: STEP 3 of 5
|
||||
-- --------------------------------------------------------------------
|
||||
|
|
@ -458,7 +527,14 @@ begin
|
|||
|
||||
fifo_future.packet_control.data_valid <= '0';
|
||||
-- MIMO UNPACKER: STEP 1 of 5
|
||||
if( eight_bit_mode_en = '1') then
|
||||
if (highly_packed_mode_en = '1' and NUM_STREAMS = 2) then
|
||||
unpack_sc12q11(
|
||||
data => fifo_data,
|
||||
previous_data => fifo_current.packed_buffer,
|
||||
cycle => fifo_current.packed_cycle,
|
||||
rv => unpacked
|
||||
);
|
||||
elsif (eight_bit_mode_en = '1') then
|
||||
unpacked := unpack_eight_bit_mode(fifo_current.sample_controls_reg, fifo_data, fifo_current.eight_bit_sample_sel);
|
||||
else
|
||||
unpacked := unpack(fifo_current.sample_controls_reg, fifo_data);
|
||||
|
|
@ -493,7 +569,11 @@ begin
|
|||
-- still need to be processed (not including the first). This becomes the number of clock
|
||||
-- cycles to wait before asserting the FIFO read request to get a new batch of samples.
|
||||
fifo_future.samples_left_init <= NUM_STREAMS - fifo_current.enabled_channels;
|
||||
fifo_future.samples_left <= NUM_STREAMS - fifo_current.enabled_channels;
|
||||
|
||||
if (fifo_current.samples_left = FIFO_FSM_RESET_VALUE.samples_left) then
|
||||
fifo_future.samples_left <= NUM_STREAMS - fifo_current.enabled_channels;
|
||||
fifo_future.ch_shift <= 0;
|
||||
end if;
|
||||
|
||||
if( packet_en = '1' ) then
|
||||
fifo_future.state <= READ_PACKET;
|
||||
|
|
@ -561,11 +641,16 @@ begin
|
|||
if( fifo_current.samples_left = 0 ) then
|
||||
fifo_future.samples_left <= fifo_current.samples_left_init;
|
||||
fifo_future.ch_shift <= 0;
|
||||
fifo_future.fifo_read <= read_req;
|
||||
if( eight_bit_mode_en = '1' ) then
|
||||
fifo_future.fifo_read <= read_req and fifo_current.eight_bit_sample_sel;
|
||||
fifo_future.eight_bit_sample_sel <= not fifo_current.eight_bit_sample_sel;
|
||||
else
|
||||
fifo_future.fifo_read <= read_req;
|
||||
elsif (highly_packed_mode_en = '1' and NUM_STREAMS = 2) then
|
||||
fifo_future.packed_cycle <= (fifo_current.packed_cycle + 1) mod 4;
|
||||
fifo_future.packed_buffer <= fifo_data(fifo_data'high downto fifo_data'high-47);
|
||||
if read_req = '1' and fifo_current.packed_cycle = 3 then
|
||||
fifo_future.fifo_read <= '0';
|
||||
end if;
|
||||
end if;
|
||||
else
|
||||
-- MIMO UNPACKER: STEP 5 of 5
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ library ieee;
|
|||
|
||||
library work;
|
||||
use work.fifo_readwrite_p.all;
|
||||
use work.fx3_gpif_p.all;
|
||||
|
||||
entity fifo_writer is
|
||||
generic (
|
||||
|
|
@ -42,6 +43,7 @@ entity fifo_writer is
|
|||
meta_en : in std_logic;
|
||||
packet_en : in std_logic;
|
||||
eight_bit_mode_en : in std_logic := '0';
|
||||
highly_packed_mode_en : in std_logic;
|
||||
timestamp : in unsigned(63 downto 0);
|
||||
mini_exp : in std_logic_vector(1 downto 0);
|
||||
|
||||
|
|
@ -70,8 +72,8 @@ end entity;
|
|||
|
||||
architecture simple of fifo_writer is
|
||||
|
||||
constant DMA_BUF_SIZE_SS : natural := 512;
|
||||
constant DMA_BUF_SIZE_HS : natural := 256;
|
||||
constant DMA_BUF_SIZE_SS : natural := GPIF_BUF_SIZE_SS;
|
||||
constant DMA_BUF_SIZE_HS : natural := GPIF_BUF_SIZE_HS;
|
||||
|
||||
signal dma_buf_size : natural range DMA_BUF_SIZE_HS to DMA_BUF_SIZE_SS := DMA_BUF_SIZE_SS;
|
||||
|
||||
|
|
@ -118,6 +120,8 @@ architecture simple of fifo_writer is
|
|||
fifo_clear : std_logic;
|
||||
fifo_write : std_logic;
|
||||
fifo_data : unsigned(fifo_data'range);
|
||||
fifo_12b_buf : unsigned(95 downto 0);
|
||||
write_cycle : natural range 0 to 3;
|
||||
samples_left : natural range 0 to in_sample_controls'length;
|
||||
in_sample_controls_r: sample_controls_t(0 to NUM_STREAMS-1);
|
||||
in_samples_r : sample_streams_t(0 to NUM_STREAMS-1);
|
||||
|
|
@ -129,6 +133,8 @@ architecture simple of fifo_writer is
|
|||
fifo_clear => '1',
|
||||
fifo_write => '0',
|
||||
fifo_data => (others => '-'),
|
||||
fifo_12b_buf => (others => '-'),
|
||||
write_cycle => 0,
|
||||
samples_left => 0,
|
||||
in_sample_controls_r=> (others => SAMPLE_CONTROL_DISABLE),
|
||||
in_samples_r => (others => ZERO_SAMPLE),
|
||||
|
|
@ -187,7 +193,7 @@ begin
|
|||
meta_fifo_used_v := unsigned(meta_fifo_full & meta_fifo_usedw);
|
||||
meta_fifo_used_v_r <= meta_fifo_used_v;
|
||||
|
||||
if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v_r) > ( dma_buf_size * 4 )) and
|
||||
if( fifo_full = '0' and ((FIFO_MAX - fifo_used_v_r) > ( dma_buf_size )) and
|
||||
( ( meta_en = '1' and meta_fifo_full = '0' and ( META_MAX - 4 ) > meta_fifo_used_v_r )
|
||||
or (meta_en = '0') ) ) then
|
||||
fifo_enough <= true;
|
||||
|
|
@ -293,7 +299,7 @@ begin
|
|||
meta_future.dma_downcount <= meta_current.dma_downcount - NUM_STREAMS;
|
||||
end if;
|
||||
|
||||
if( meta_current.dma_downcount <= NUM_STREAMS ) then
|
||||
if( meta_current.dma_downcount <= 2 ) then
|
||||
-- Look for 2 because of the 2 cycles passing
|
||||
-- through IDLE and META_WRITE after this.
|
||||
-- 8bit format requires an additional 2 cycle delay.
|
||||
|
|
@ -430,6 +436,57 @@ begin
|
|||
return rv;
|
||||
end function;
|
||||
|
||||
|
||||
-- --------------------------------------------------------------------
|
||||
-- MIMO PACKER: STEP 1 of 3 (SC12Q11 Highly Packed Mode)
|
||||
-- --------------------------------------------------------------------
|
||||
-- This block receives samples as an array of sample streams, one
|
||||
-- element per channel. These streams need to be packed into a single,
|
||||
-- wide bus that is written to a FIFO and delivered to the host.
|
||||
-- For SC12Q11 (SC16_Q11_PACKED) format, each I and Q sample is 12 bits wide.
|
||||
--
|
||||
-- This packing scheme efficiently utilizes the available bandwidth
|
||||
-- for the SC12Q11 format, allowing for 8 complete IQ pairs every 3 cycles.
|
||||
--
|
||||
-- The packing process fills 3 cycles of a 64-bit buffer with 8 24b IQ pairs:
|
||||
-- Cycle 1: | 63:60 | 59:48 | 47:36 | 35:24 | 23:12 | 11:0 | Bit indices
|
||||
-- | Q0' | I0 | Q1 | I1 | Q0 | I0 | Samples
|
||||
-- [-----][--------full 12-bit samples-----------]
|
||||
-- 4-bit
|
||||
-- overlap
|
||||
--
|
||||
-- Cycle 2: | 63:56 | 55:44 | 43:32 | 31:20 | 19:8 | 7:0 | Bit indices
|
||||
-- | I1' | Q0 | I0 | Q1 | I1 | Q0' | Samples
|
||||
-- [-----][--------full 12-bit samples--------][---]
|
||||
-- 8-bit 8-bit
|
||||
-- overlap overlap
|
||||
--
|
||||
-- Cycle 3: | 63:52 | 51:40 | 39:28 | 27:16 | 15:4 | 3:0 | Bit indices
|
||||
-- | Q1 | I1 | Q0 | I0 | Q1 | I1' | Samples
|
||||
-- [--------full 12-bit samples-----------][-----]
|
||||
-- 4-bit
|
||||
-- overlap
|
||||
--
|
||||
-- Note: Samples with apostrophes (') indicate partial samples that span
|
||||
-- across cycle boundaries. The complete samples are reconstructed by
|
||||
-- combining these partial segments from different cycles.
|
||||
function pack_sc12q11( sc : sample_controls_t;
|
||||
ss : sample_streams_t;
|
||||
d : unsigned ) return unsigned is
|
||||
constant IQ_PAIR_LEN : positive := 24;
|
||||
variable rv : unsigned(d'range) := (others => '0');
|
||||
begin
|
||||
rv := d;
|
||||
for i in sc'range loop
|
||||
if( (sc(i).enable = '1') and (ss(i).data_v = '1') ) then
|
||||
rv := unsigned(ss(i).data_q(11 downto 0)) &
|
||||
unsigned(ss(i).data_i(11 downto 0)) &
|
||||
rv(rv'high downto rv'low+IQ_PAIR_LEN);
|
||||
end if;
|
||||
end loop;
|
||||
return rv;
|
||||
end function;
|
||||
|
||||
procedure handle_fifo_write(
|
||||
signal fifo_current : in fifo_fsm_t;
|
||||
signal meta_current : in meta_fsm_t;
|
||||
|
|
@ -457,11 +514,18 @@ begin
|
|||
if( write_req = '1' ) then
|
||||
if( fifo_current.samples_left = 0 ) then
|
||||
fifo_future.samples_left <= NUM_STREAMS - count_enabled_channels(in_sample_controls);
|
||||
fifo_future.fifo_write <= write_req;
|
||||
|
||||
if( eight_bit_mode_en = '1' ) then
|
||||
fifo_future.fifo_write <= write_req and fifo_current.eight_bit_delay;
|
||||
fifo_future.eight_bit_delay <= not fifo_current.eight_bit_delay;
|
||||
else
|
||||
fifo_future.fifo_write <= write_req;
|
||||
end if;
|
||||
|
||||
if( highly_packed_mode_en = '1' ) then
|
||||
fifo_future.write_cycle <= (fifo_current.write_cycle + 1) mod 4;
|
||||
if fifo_current.write_cycle = 0 then
|
||||
fifo_future.fifo_write <= '0';
|
||||
end if;
|
||||
end if;
|
||||
else
|
||||
-- MIMO PACKER: STEP 3 of 3
|
||||
|
|
@ -487,14 +551,33 @@ begin
|
|||
|
||||
-- MIMO PACKER: STEP 1 of 3
|
||||
if( packet_en = '0' ) then
|
||||
fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r,
|
||||
fifo_current.in_samples_r,
|
||||
fifo_current.fifo_data);
|
||||
|
||||
if( highly_packed_mode_en = '1' ) then
|
||||
fifo_future.fifo_12b_buf <= pack_sc12q11(
|
||||
sc => in_sample_controls,
|
||||
ss => in_samples,
|
||||
d => fifo_current.fifo_12b_buf
|
||||
);
|
||||
|
||||
if fifo_current.write_cycle = 1 then
|
||||
fifo_future.fifo_data <= fifo_current.fifo_12b_buf(
|
||||
fifo_data'length-1 downto fifo_current.fifo_12b_buf'low);
|
||||
elsif fifo_current.write_cycle = 2 then
|
||||
fifo_future.fifo_data <= fifo_current.fifo_12b_buf(
|
||||
fifo_data'length-1+16 downto fifo_current.fifo_12b_buf'low+16);
|
||||
elsif fifo_current.write_cycle = 3 then
|
||||
fifo_future.fifo_data <= fifo_current.fifo_12b_buf(
|
||||
fifo_data'length-1+32 downto fifo_current.fifo_12b_buf'low+32);
|
||||
end if;
|
||||
end if;
|
||||
|
||||
if( eight_bit_mode_en = '1' ) then
|
||||
fifo_future.fifo_data <= pack_eight_bit_mode(fifo_current.in_sample_controls_r,
|
||||
fifo_current.in_samples_r,
|
||||
fifo_current.fifo_data);
|
||||
else
|
||||
fifo_future.fifo_data <= pack(fifo_current.in_sample_controls_r,
|
||||
fifo_current.in_samples_r,
|
||||
fifo_current.fifo_data);
|
||||
end if;
|
||||
end if;
|
||||
|
||||
|
|
@ -576,10 +659,13 @@ begin
|
|||
if( fifo_full = '1' or ( meta_current.meta_written = '0' and meta_en = '1') ) then
|
||||
fifo_future.fifo_write <= '0';
|
||||
fifo_future.state <= HOLDOFF;
|
||||
fifo_future.write_cycle <= fifo_current.write_cycle;
|
||||
fifo_future.fifo_12b_buf <= fifo_current.fifo_12b_buf;
|
||||
end if;
|
||||
|
||||
when HOLDOFF =>
|
||||
|
||||
fifo_future.write_cycle <= fifo_current.write_cycle;
|
||||
fifo_future.fifo_12b_buf <= fifo_current.fifo_12b_buf;
|
||||
if( fifo_enough ) then
|
||||
fifo_future.state <= WRITE_SAMPLES;
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip pll_r
|
|||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sync/vhdl/ps_sync.vhd]]
|
||||
|
||||
# Implementation Details
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx-adsb.vhd]]
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sy
|
|||
set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip tone_generator/tone_generator.qip]]
|
||||
|
||||
# Implementation Details
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]]
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ set_global_assignment -name QIP_FILE [file normalize [file join $nuand_ip pll_r
|
|||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip ps_sync/vhdl/ps_sync.vhd]]
|
||||
|
||||
# Implementation Details
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]]
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synth
|
|||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip rfic_spi_controller/vhdl/rfic_spi_controller.vhd]]
|
||||
|
||||
# Implementation Details
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/tx.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/rx.vhd]]
|
||||
|
|
|
|||
|
|
@ -71,11 +71,10 @@ set_false_path -from exp_present -to *
|
|||
set_false_path -from pwr_status -to *
|
||||
|
||||
# JTAG settings
|
||||
create_clock -name {altera_reserved_tck} -period 100 [get_ports {altera_reserved_tck}]
|
||||
set_clock_groups -asynchronous -group {altera_reserved_tck}
|
||||
set_false_path -from [get_ports {altera_reserved_tms}]
|
||||
set_false_path -from [get_ports {altera_reserved_tdi}]
|
||||
set_false_path -to [get_ports {altera_reserved_tdo}]
|
||||
set_clock_groups -exclusive -group [get_clocks altera_reserved_tck]
|
||||
set_input_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tdi]
|
||||
set_input_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tms]
|
||||
set_output_delay -clock [get_clocks altera_reserved_tck] 2.0 [get_ports altera_reserved_tdo]
|
||||
|
||||
# Exceptions
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ compile_nuand ../../../ip/nuand bladerf-micro
|
|||
|
||||
vcom -work nuand -2008 ../vhdl/tb/nios_system.vhd
|
||||
|
||||
vcom -work nuand -2008 ../../../platforms/common/bladerf/vhdl/fx3_gpif_p.vhd
|
||||
vcom -work nuand -2008 ../../../platforms/common/bladerf/vhdl/fx3_gpif.vhd
|
||||
|
||||
vcom -work nuand -2008 ../vhdl/bladerf_p.vhd
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
source ../../../ip/nuand/nuand.do
|
||||
|
||||
vcom -work nuand -2008 ../vhdl/rx.vhd
|
||||
vcom -work nuand -2008 ../vhdl/tx.vhd
|
||||
|
||||
vlib rtl_work
|
||||
vcom -work rtl_work -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd
|
||||
|
||||
compile_nuand ../../../ip/nuand bladerf-micro
|
||||
|
||||
vcom -work nuand -2008 ../vhdl/tb/fx3_model_fifo_stress.vhd
|
||||
vcom -work nuand -2008 ../vhdl/tb/fx3_gpif_iq_8bit_fifo_stress_tb.vhd
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
source ../../../ip/nuand/nuand.do
|
||||
|
||||
# vcom -work nuand -2008 ../vhdl/rx.vhd
|
||||
# vcom -work nuand -2008 ../vhdl/tx.vhd
|
||||
|
||||
# vlib rtl_work
|
||||
# vcom -work rtl_work -2008 ../../../ip/altera/fx3_pll/fx3_pll.vhd
|
||||
|
||||
# compile_nuand ../../../ip/nuand bladerf-micro
|
||||
|
||||
vcom -work nuand -2008 ../../../ip/nuand/simulation/fx3_model.vhd
|
||||
vcom -work nuand -2008 ../vhdl/tb/fx3_model.vhd
|
||||
vcom -work nuand -2008 ../vhdl/tb/fx3_gpif_iq_packed_tb.vhd
|
||||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#define FPGA_VERSION_ID 0x7777
|
||||
#define FPGA_VERSION_MAJOR 0
|
||||
#define FPGA_VERSION_MINOR 15
|
||||
#define FPGA_VERSION_PATCH 3
|
||||
#define FPGA_VERSION_MINOR 16
|
||||
#define FPGA_VERSION_PATCH 0
|
||||
#define FPGA_VERSION ((uint32_t)( FPGA_VERSION_MAJOR | \
|
||||
(FPGA_VERSION_MINOR << 8) | \
|
||||
(FPGA_VERSION_PATCH << 16) ) )
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ architecture hosted_bladerf of bladerf is
|
|||
signal eightbit_en_tx : std_logic;
|
||||
signal eightbit_en_rx : std_logic;
|
||||
|
||||
signal highly_packed_en_txrx : std_logic;
|
||||
|
||||
signal packet_en_pclk : std_logic;
|
||||
signal packet_en_tx : std_logic;
|
||||
signal packet_en_rx : std_logic;
|
||||
|
|
@ -567,6 +569,7 @@ begin
|
|||
|
||||
-- Eightbit mode
|
||||
eight_bit_mode_en => eightbit_en_tx,
|
||||
highly_packed_mode_en => highly_packed_en_txrx,
|
||||
|
||||
-- Packet FIFO
|
||||
packet_en => packet_en_tx,
|
||||
|
|
@ -641,8 +644,9 @@ begin
|
|||
trigger_master => rx_trigger_ctl.master,
|
||||
trigger_line => rx_trigger_line,
|
||||
|
||||
-- Eightbit mode
|
||||
-- Packed modes
|
||||
eight_bit_mode_en => eightbit_en_rx,
|
||||
highly_packed_mode_en => highly_packed_en_txrx,
|
||||
|
||||
-- Packet FIFO
|
||||
packet_en => packet_en_rx,
|
||||
|
|
@ -859,6 +863,17 @@ begin
|
|||
sync => eightbit_en_tx
|
||||
);
|
||||
|
||||
U_sync_highly_packed_en_txrx : entity work.synchronizer
|
||||
generic map (
|
||||
RESET_LEVEL => '0'
|
||||
)
|
||||
port map (
|
||||
reset => '0',
|
||||
clock => ad9361.clock,
|
||||
async => nios_gpio.o.highly_packed_en,
|
||||
sync => highly_packed_en_txrx
|
||||
);
|
||||
|
||||
U_sync_packet_en_pclk : entity work.synchronizer
|
||||
generic map (
|
||||
RESET_LEVEL => '0'
|
||||
|
|
|
|||
|
|
@ -168,11 +168,11 @@ package bladerf_p is
|
|||
|
||||
constant TX_FIFO_WWIDTH : natural := 32; -- write side data width
|
||||
constant TX_FIFO_RWIDTH : natural := 64; -- read side data width
|
||||
constant TX_FIFO_LENGTH : natural := 16384; -- samples
|
||||
constant TX_FIFO_LENGTH : natural := 8192; -- samples
|
||||
|
||||
constant RX_FIFO_WWIDTH : natural := 64; -- write side data width
|
||||
constant RX_FIFO_RWIDTH : natural := 32; -- read side data width
|
||||
constant RX_FIFO_LENGTH : natural := 4096; -- samples
|
||||
constant RX_FIFO_LENGTH : natural := 8192; -- samples
|
||||
|
||||
constant ADSB_FIFO_WWIDTH : natural := 128; -- write side data width
|
||||
constant ADSB_FIFO_RWIDTH : natural := 32; -- read side data width
|
||||
|
|
@ -184,11 +184,11 @@ package bladerf_p is
|
|||
|
||||
constant META_FIFO_TX_WWIDTH : natural := 32; -- write side data width
|
||||
constant META_FIFO_TX_RWIDTH : natural := 128; -- read side data width
|
||||
constant META_FIFO_TX_LENGTH : natural := 512; -- 32-bit words
|
||||
constant META_FIFO_TX_LENGTH : natural := 2048; -- 32-bit words
|
||||
|
||||
constant META_FIFO_RX_WWIDTH : natural := 128; -- write side data width
|
||||
constant META_FIFO_RX_RWIDTH : natural := 32; -- read side data width
|
||||
constant META_FIFO_RX_LENGTH : natural := 512; -- 32-bit words
|
||||
constant META_FIFO_RX_LENGTH : natural := 2048; -- 32-bit words
|
||||
|
||||
type tx_fifo_t is record
|
||||
aclr : std_logic;
|
||||
|
|
@ -307,6 +307,7 @@ package bladerf_p is
|
|||
type nios_gpo_t is record
|
||||
xb_mode : std_logic_vector(1 downto 0);
|
||||
eightbit_en : std_logic;
|
||||
highly_packed_en: std_logic;
|
||||
packet_en : std_logic;
|
||||
si_clock_sel : std_logic;
|
||||
ufl_clock_oe : std_logic;
|
||||
|
|
@ -518,6 +519,7 @@ package body bladerf_p is
|
|||
variable rv : std_logic_vector(31 downto 0) := (others => 'U');
|
||||
begin
|
||||
rv(31 downto 30) := x.xb_mode;
|
||||
rv(21) := x.highly_packed_en;
|
||||
rv(20) := x.eightbit_en;
|
||||
rv(19) := x.packet_en;
|
||||
rv(18) := x.si_clock_sel;
|
||||
|
|
@ -597,6 +599,7 @@ package body bladerf_p is
|
|||
variable rv : nios_gpo_t;
|
||||
begin
|
||||
rv.xb_mode := x(31 downto 30);
|
||||
rv.highly_packed_en:= x(21);
|
||||
rv.eightbit_en := x(20);
|
||||
rv.packet_en := x(19);
|
||||
rv.si_clock_sel := x(18);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ entity rx is
|
|||
|
||||
-- 8-bit mode
|
||||
eight_bit_mode_en : in std_logic := '0';
|
||||
highly_packed_mode_en : in std_logic := '0';
|
||||
|
||||
-- Packet to host via FX3
|
||||
packet_en : in std_logic;
|
||||
|
|
@ -251,6 +252,7 @@ begin
|
|||
packet_ready => packet_ready,
|
||||
|
||||
eight_bit_mode_en => eight_bit_mode_en,
|
||||
highly_packed_mode_en => highly_packed_mode_en,
|
||||
|
||||
meta_fifo_full => meta_fifo.wfull,
|
||||
meta_fifo_usedw => meta_fifo.wused,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,840 @@
|
|||
-- Copyright (c) 2024 Nuand LLC
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
-- of this software and associated documentation files (the "Software"), to deal
|
||||
-- in the Software without restriction, including without limitation the rights
|
||||
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
-- copies of the Software, and to permit persons to whom the Software is
|
||||
-- furnished to do so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in
|
||||
-- all copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
-- THE SOFTWARE.
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
library rtl_work;
|
||||
|
||||
library altera_lnsim;
|
||||
use altera_lnsim.altera_pll;
|
||||
|
||||
library nuand;
|
||||
use nuand.util.all ;
|
||||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
|
||||
entity fx3_gpif_iq_8bit_fifo_stress is
|
||||
generic (
|
||||
-- For bladeRF2 (2x2 MIMO):
|
||||
NUM_MIMO_STREAMS : natural := 2;
|
||||
FIFO_READER_READ_THROTTLE : natural := 0;
|
||||
|
||||
ENABLE_CHANNEL_0 : std_logic := '1';
|
||||
ENABLE_CHANNEL_1 : std_logic := '0';
|
||||
EIGHT_BIT_MODE_EN : std_logic := '1'
|
||||
);
|
||||
end entity;
|
||||
|
||||
architecture arch of fx3_gpif_iq_8bit_fifo_stress is
|
||||
|
||||
-- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock
|
||||
constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0);
|
||||
|
||||
-- For reasons unknown, simulation of this system in ModelSim requires that
|
||||
-- wrreq and data be asserted shortly before the rising clock edge. Sigh...
|
||||
constant FIFO_WORKAROUND : time := 1 ps;
|
||||
|
||||
type fx3_control_t is record
|
||||
usb_speed : std_logic;
|
||||
tx_enable : std_logic;
|
||||
rx_enable : std_logic;
|
||||
meta_enable : std_logic;
|
||||
packet : std_logic;
|
||||
end record;
|
||||
|
||||
type fx3_gpif_t is record
|
||||
gpif_in : std_logic_vector(31 downto 0);
|
||||
gpif_out : std_logic_vector(31 downto 0);
|
||||
gpif_oe : std_logic;
|
||||
ctl_in : std_logic_vector(12 downto 0);
|
||||
ctl_out : std_logic_vector(12 downto 0);
|
||||
ctl_oe : std_logic_vector(12 downto 0);
|
||||
end record;
|
||||
|
||||
signal sys_rst : std_logic := '1';
|
||||
signal done : boolean := false;
|
||||
|
||||
signal fx3_pclk : std_logic := '1';
|
||||
signal fx3_pclk_pll : std_logic := '1';
|
||||
signal sys_clk : std_logic := '1';
|
||||
|
||||
signal pll_reset : std_logic := '0';
|
||||
signal pll_locked : std_logic := '0';
|
||||
signal fx3_control : fx3_control_t;
|
||||
signal fx3_gpif : fx3_gpif_t;
|
||||
signal fx3_gpif_i : std_logic_vector(31 downto 0);
|
||||
signal fx3_ctl_i : std_logic_vector(12 downto 0);
|
||||
|
||||
-- Control mapping
|
||||
alias dma0_rx_ack is fx3_ctl_i( 0);
|
||||
alias dma1_rx_ack is fx3_ctl_i( 1);
|
||||
alias dma2_tx_ack is fx3_ctl_i( 2);
|
||||
alias dma3_tx_ack is fx3_ctl_i( 3);
|
||||
alias dma_rx_enable is fx3_ctl_i( 4);
|
||||
alias dma_tx_enable is fx3_ctl_i( 5);
|
||||
alias dma_idle is fx3_ctl_i( 6);
|
||||
alias system_reset is fx3_ctl_i( 7);
|
||||
alias dma0_rx_reqx is fx3_ctl_i( 8);
|
||||
alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk
|
||||
alias dma2_tx_reqx is fx3_ctl_i(10);
|
||||
alias dma3_tx_reqx is fx3_ctl_i(11);
|
||||
|
||||
signal loopback_i : signed(15 downto 0) := (others =>'0');
|
||||
signal loopback_q : signed(15 downto 0) := (others =>'0');
|
||||
signal loopback_valid : std_logic := '0';
|
||||
signal loopback_enabled : std_logic := '0';
|
||||
|
||||
signal tx_clock : std_logic := '1' ;
|
||||
signal rx_clock : std_logic := '1' ;
|
||||
|
||||
signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
|
||||
signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
|
||||
signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
|
||||
signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
|
||||
signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
|
||||
|
||||
signal rx_mux_i : signed(15 downto 0);
|
||||
signal rx_mux_q : signed(15 downto 0);
|
||||
signal rx_mux_valid : std_logic;
|
||||
|
||||
signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' );
|
||||
signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' );
|
||||
|
||||
constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ;
|
||||
constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
|
||||
constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
|
||||
|
||||
signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
|
||||
signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
|
||||
signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
|
||||
signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
|
||||
|
||||
signal tx_reset : std_logic := '0';
|
||||
signal tx_ts_reset : std_logic := '0';
|
||||
signal rx_reset : std_logic := '0';
|
||||
signal rx_ts_reset : std_logic := '0';
|
||||
|
||||
signal meta_en_tx : std_logic := '0';
|
||||
signal meta_en_rx : std_logic := '0';
|
||||
|
||||
signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT;
|
||||
signal tx_packet_control : packet_control_t;
|
||||
|
||||
signal trigger_signal_sync_tb : std_logic;
|
||||
signal adc_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' );
|
||||
|
||||
function data_gen (count : natural) return std_logic_vector is
|
||||
variable msw, lsw : std_logic_vector(15 downto 0);
|
||||
begin
|
||||
msw := std_logic_vector(to_signed(count, 16));
|
||||
lsw := std_logic_vector(to_signed(-count, 16));
|
||||
|
||||
return (msw & lsw);
|
||||
end function data_gen;
|
||||
|
||||
signal rx_packet_ready : std_logic;
|
||||
|
||||
begin
|
||||
|
||||
-- ========================================================================
|
||||
-- Brief summary of data flow
|
||||
-- ========================================================================
|
||||
--
|
||||
-- Simulated samples flow from fx3_model's TX side to its RX side. The
|
||||
-- validity of the data is checked there.
|
||||
--
|
||||
-- entity U_fx3_model FX3 model, TX process
|
||||
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '0'
|
||||
-- process register_gpif
|
||||
-- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA)
|
||||
-- entity U_fx3_gpif GPIF implementation, write side
|
||||
-- signal tx_sample_fifo.w* TX fifo, write side
|
||||
-- entity U_tx_sample_fifo
|
||||
-- signal tx_sample_fifo.r* TX fifo, read side
|
||||
-- process tx_mux
|
||||
-- signal loopback_fifo.w* Loopback fifo, write side
|
||||
-- entity U_rx_loopback_fifo
|
||||
-- signal loopback_fifo.r* Loopback fifo, read side
|
||||
-- process loopback_fifo_control
|
||||
-- signal loopback_{i,q,valid}
|
||||
-- process rx_mux
|
||||
-- signal rx_mux_{i,q,valid}
|
||||
-- entity U_fifo_writer
|
||||
-- signal rx_sample_fifo.w* RX fifo, write side
|
||||
-- entity U_rx_sample_fifo
|
||||
-- signal rx_sample_fifo.r* RX fifo, read side
|
||||
-- entity U_fx3_gpif GPIF implementation, read side
|
||||
-- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3)
|
||||
-- process register_gpif
|
||||
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '1'
|
||||
-- entity U_fx3_model FX3 model, RX process
|
||||
|
||||
|
||||
-- ========================================================================
|
||||
-- Instantiations
|
||||
-- ========================================================================
|
||||
|
||||
-- Unit under test
|
||||
-- Clock domain: fx3_pclk_pll
|
||||
U_fx3_gpif : entity nuand.fx3_gpif
|
||||
port map (
|
||||
pclk => fx3_pclk_pll,
|
||||
reset => sys_rst,
|
||||
usb_speed => fx3_control.usb_speed,
|
||||
gpif_in => fx3_gpif.gpif_in,
|
||||
gpif_out => fx3_gpif.gpif_out,
|
||||
gpif_oe => fx3_gpif.gpif_oe,
|
||||
ctl_in => fx3_gpif.ctl_in,
|
||||
ctl_out => fx3_gpif.ctl_out,
|
||||
ctl_oe => fx3_gpif.ctl_oe,
|
||||
tx_enable => fx3_control.tx_enable,
|
||||
rx_enable => fx3_control.rx_enable,
|
||||
meta_enable => fx3_control.meta_enable,
|
||||
packet_enable => fx3_control.packet,
|
||||
tx_fifo_write => tx_sample_fifo.wreq,
|
||||
tx_fifo_full => tx_sample_fifo.wfull,
|
||||
tx_fifo_empty => tx_sample_fifo.wempty,
|
||||
tx_fifo_usedw => tx_sample_fifo.wused,
|
||||
tx_fifo_data => tx_sample_fifo.wdata,
|
||||
tx_timestamp => tx_timestamp,
|
||||
tx_meta_fifo_write => tx_meta_fifo.wreq,
|
||||
tx_meta_fifo_full => tx_meta_fifo.wfull,
|
||||
tx_meta_fifo_empty => tx_meta_fifo.wempty,
|
||||
tx_meta_fifo_usedw => tx_meta_fifo.wused,
|
||||
tx_meta_fifo_data => tx_meta_fifo.wdata,
|
||||
rx_fifo_read => rx_sample_fifo.rreq,
|
||||
rx_fifo_full => rx_sample_fifo.rfull,
|
||||
rx_fifo_empty => rx_sample_fifo.rempty,
|
||||
rx_fifo_usedw => rx_sample_fifo.rused,
|
||||
rx_fifo_data => rx_sample_fifo.rdata,
|
||||
rx_meta_fifo_read => rx_meta_fifo.rreq,
|
||||
rx_meta_fifo_full => rx_meta_fifo.rfull,
|
||||
rx_meta_fifo_empty => rx_meta_fifo.rempty,
|
||||
rx_meta_fifo_usedr => rx_meta_fifo.rused,
|
||||
rx_meta_fifo_data => rx_meta_fifo.rdata
|
||||
);
|
||||
|
||||
-- Discrete control signals for fx3_gpif
|
||||
fx3_control.usb_speed <= '0';
|
||||
fx3_control.meta_enable <= '0';
|
||||
fx3_control.packet <= '0';
|
||||
|
||||
U_pkt_gen : entity nuand.rx_packet_generator
|
||||
port map(
|
||||
rx_clock => rx_clock,
|
||||
rx_reset => rx_reset,
|
||||
|
||||
rx_enable => fx3_control.rx_enable,
|
||||
rx_packet_enable => fx3_control.packet,
|
||||
|
||||
rx_packet_ready => rx_packet_ready,
|
||||
|
||||
rx_packet_control => rx_packet_control
|
||||
|
||||
);
|
||||
|
||||
|
||||
meta_en_tx <= fx3_control.meta_enable;
|
||||
meta_en_rx <= fx3_control.meta_enable;
|
||||
|
||||
increment_tx_ts : process(tx_clock)
|
||||
variable ping : boolean := true ;
|
||||
begin
|
||||
if( rising_edge(tx_clock) ) then
|
||||
ping := not ping ;
|
||||
if( ping = true ) then
|
||||
tx_timestamp <= tx_timestamp + 1 ;
|
||||
end if ;
|
||||
end if ;
|
||||
end process ;
|
||||
|
||||
increment_rx_ts : process(rx_clock)
|
||||
variable ping : boolean := true ;
|
||||
begin
|
||||
if( rising_edge(rx_clock) ) then
|
||||
ping := not ping ;
|
||||
if( ping = true ) then
|
||||
rx_timestamp <= rx_timestamp + 1 ;
|
||||
end if ;
|
||||
end if ;
|
||||
end process ;
|
||||
|
||||
-- Model of FX3's GPIF interface
|
||||
-- Clock domain: fx3_pclk (source)
|
||||
U_fx3_model : entity nuand.fx3_model(micro_dma_fifo_stress)
|
||||
port map (
|
||||
fx3_pclk => fx3_pclk,
|
||||
fx3_gpif => fx3_gpif_i,
|
||||
fx3_ctl => fx3_ctl_i,
|
||||
fx3_uart_rxd => '0',
|
||||
fx3_uart_txd => open,
|
||||
fx3_uart_cts => open,
|
||||
fx3_rx_en => '1',
|
||||
fx3_rx_meta_en => meta_en_rx,
|
||||
fx3_tx_en => '1',
|
||||
fx3_tx_meta_en => meta_en_tx,
|
||||
eight_bit_mode_en => EIGHT_BIT_MODE_EN,
|
||||
done => done
|
||||
);
|
||||
|
||||
-- Generate phase-shifted PLL clock
|
||||
U_fx3_pll : entity rtl_work.fx3_pll
|
||||
port map (
|
||||
inclk0 => fx3_pclk,
|
||||
areset => pll_reset,
|
||||
c0 => fx3_pclk_pll,
|
||||
locked => pll_locked
|
||||
);
|
||||
|
||||
tx_clock <= not tx_clock after TX_HALF_PERIOD ;
|
||||
rx_clock <= not rx_clock after RX_HALF_PERIOD ;
|
||||
|
||||
|
||||
-- Reset handler
|
||||
sys_rst <= '0' after 100 ns;
|
||||
|
||||
-- Generate system clock
|
||||
sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
|
||||
|
||||
|
||||
tx_reset <= sys_rst;
|
||||
tx_ts_reset <= sys_rst;
|
||||
rx_reset <= sys_rst;
|
||||
rx_ts_reset <= sys_rst;
|
||||
|
||||
meta_en_tx <= fx3_control.meta_enable;
|
||||
meta_en_rx <= fx3_control.meta_enable;
|
||||
|
||||
-- TX Submodule
|
||||
U_tx : entity work.tx
|
||||
generic map (
|
||||
NUM_STREAMS => dac_controls'length
|
||||
)
|
||||
port map (
|
||||
tx_reset => tx_reset,
|
||||
tx_clock => tx_clock,
|
||||
tx_enable => fx3_control.tx_enable,
|
||||
|
||||
meta_en => meta_en_tx,
|
||||
timestamp_reset => tx_ts_reset,
|
||||
usb_speed => fx3_control.usb_speed,
|
||||
tx_underflow_led => open,
|
||||
tx_timestamp => tx_timestamp,
|
||||
|
||||
-- Triggering
|
||||
trigger_arm => '0',
|
||||
trigger_fire => '0',
|
||||
trigger_master => '0',
|
||||
trigger_line => open,
|
||||
|
||||
-- Packet FIFO
|
||||
packet_en => fx3_control.packet,
|
||||
packet_empty => open,
|
||||
packet_control => tx_packet_control,
|
||||
packet_ready => '1',
|
||||
|
||||
-- 8-bit mode
|
||||
eight_bit_mode_en => EIGHT_BIT_MODE_EN,
|
||||
|
||||
-- Samples from host via FX3
|
||||
sample_fifo_wclock => fx3_pclk_pll,
|
||||
sample_fifo_wreq => tx_sample_fifo.wreq,
|
||||
sample_fifo_wdata => tx_sample_fifo.wdata,
|
||||
sample_fifo_wempty => tx_sample_fifo.wempty,
|
||||
sample_fifo_wfull => tx_sample_fifo.wfull,
|
||||
sample_fifo_wused => tx_sample_fifo.wused,
|
||||
|
||||
-- Metadata from host via FX3
|
||||
meta_fifo_wclock => fx3_pclk_pll,
|
||||
meta_fifo_wreq => tx_meta_fifo.wreq,
|
||||
meta_fifo_wdata => tx_meta_fifo.wdata,
|
||||
meta_fifo_wempty => tx_meta_fifo.wempty,
|
||||
meta_fifo_wfull => tx_meta_fifo.wfull,
|
||||
meta_fifo_wused => tx_meta_fifo.wused,
|
||||
|
||||
-- Digital Loopback Interface
|
||||
loopback_enabled => '0',
|
||||
loopback_fifo_wdata => loopback_fifo.wdata,
|
||||
loopback_fifo_wreq => loopback_fifo.wreq,
|
||||
loopback_fifo_wfull => loopback_fifo.wfull,
|
||||
loopback_fifo_wused => loopback_fifo.wused,
|
||||
|
||||
-- RFFE Interface
|
||||
dac_controls => dac_controls,
|
||||
dac_streams => dac_streams
|
||||
);
|
||||
|
||||
-- RX Submodule
|
||||
U_rx : entity work.rx
|
||||
generic map (
|
||||
NUM_STREAMS => adc_controls'length
|
||||
)
|
||||
port map (
|
||||
rx_reset => rx_reset,
|
||||
rx_clock => rx_clock,
|
||||
rx_enable => fx3_control.rx_enable,
|
||||
|
||||
meta_en => meta_en_rx,
|
||||
timestamp_reset => rx_ts_reset,
|
||||
usb_speed => fx3_control.usb_speed,
|
||||
rx_mux_sel => to_unsigned(0, 3),
|
||||
rx_overflow_led => open,
|
||||
rx_timestamp => rx_timestamp,
|
||||
|
||||
-- Triggering
|
||||
trigger_arm => '0',
|
||||
trigger_fire => '0',
|
||||
trigger_master => '0',
|
||||
trigger_line => open,
|
||||
trigger_signal_sync_tb => trigger_signal_sync_tb,
|
||||
|
||||
-- Packet FIFO
|
||||
packet_en => fx3_control.packet,
|
||||
packet_control => rx_packet_control,
|
||||
packet_ready => rx_packet_ready,
|
||||
|
||||
-- 8-bit mode
|
||||
eight_bit_mode_en => EIGHT_BIT_MODE_EN,
|
||||
|
||||
-- Samples to host via FX3
|
||||
sample_fifo_rclock => fx3_pclk_pll,
|
||||
sample_fifo_raclr => not fx3_control.rx_enable,
|
||||
sample_fifo_rreq => rx_sample_fifo.rreq,
|
||||
sample_fifo_rdata => rx_sample_fifo.rdata,
|
||||
sample_fifo_rempty => rx_sample_fifo.rempty,
|
||||
sample_fifo_rfull => rx_sample_fifo.rfull,
|
||||
sample_fifo_rused => rx_sample_fifo.rused,
|
||||
|
||||
-- Mini expansion signals
|
||||
mini_exp => "00",
|
||||
|
||||
-- Metadata to host via FX3
|
||||
meta_fifo_rclock => fx3_pclk_pll,
|
||||
meta_fifo_raclr => not fx3_control.rx_enable,
|
||||
meta_fifo_rreq => rx_meta_fifo.rreq,
|
||||
meta_fifo_rdata => rx_meta_fifo.rdata,
|
||||
meta_fifo_rempty => rx_meta_fifo.rempty,
|
||||
meta_fifo_rfull => rx_meta_fifo.rfull,
|
||||
meta_fifo_rused => rx_meta_fifo.rused,
|
||||
|
||||
-- Digital Loopback Interface
|
||||
loopback_fifo_wenabled => open,
|
||||
loopback_fifo_wreset => tx_reset,
|
||||
loopback_fifo_wclock => tx_clock,
|
||||
loopback_fifo_wdata => loopback_fifo.wdata,
|
||||
loopback_fifo_wreq => loopback_fifo.wreq,
|
||||
loopback_fifo_wfull => loopback_fifo.wfull,
|
||||
loopback_fifo_wused => loopback_fifo.wused,
|
||||
|
||||
-- RFFE Interface
|
||||
adc_controls => adc_controls,
|
||||
adc_streams => adc_streams
|
||||
);
|
||||
|
||||
-- ========================================================================
|
||||
-- Data converters
|
||||
-- ========================================================================
|
||||
|
||||
gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
|
||||
-- The TX side of the AD9361 HDL is a FIFO pull interface
|
||||
-- that expects a readahead FIFO. It toggles the data request
|
||||
-- signal every other cycle. This behavior is mimicked here.
|
||||
process( tx_clock, sys_rst )
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
dac_controls <= (
|
||||
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
|
||||
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
|
||||
);
|
||||
elsif( rising_edge(tx_clock) ) then
|
||||
for i in dac_controls'range loop
|
||||
dac_controls(i) <= (
|
||||
enable => dac_controls(i).enable,
|
||||
data_req => not dac_controls(i).data_req );
|
||||
end loop;
|
||||
end if;
|
||||
end process;
|
||||
else generate
|
||||
dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
|
||||
end generate;
|
||||
|
||||
gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
|
||||
process( rx_clock, sys_rst )
|
||||
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
|
||||
constant COUNT_RESET : integer := 0;
|
||||
variable count : integer range -2047 to 2047 := COUNT_RESET;
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
count := COUNT_RESET;
|
||||
adc_controls <= (
|
||||
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
|
||||
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
|
||||
);
|
||||
elsif( rising_edge(rx_clock) ) then
|
||||
for i in adc_controls'range loop
|
||||
adc_controls(i) <= (
|
||||
enable => adc_controls(i).enable,
|
||||
data_req => not adc_controls(i).data_req );
|
||||
if( adc_controls(i).enable = '1') then
|
||||
if( adc_streams(i).data_v = '1' ) then
|
||||
if( EIGHT_BIT_MODE_EN = '1' ) then
|
||||
adc_streams(i).data_i <= "0000" & to_signed(count, 8) & SIGMA_DELTA_BITS;
|
||||
adc_streams(i).data_q <= "0000" & to_signed(-count, 8) & SIGMA_DELTA_BITS;
|
||||
count := (count + 1) mod 128;
|
||||
else
|
||||
adc_streams(i).data_i <= to_signed(count, 16);
|
||||
adc_streams(i).data_q <= to_signed(-count, 16);
|
||||
count := (count + 1) mod 2048;
|
||||
end if;
|
||||
end if;
|
||||
adc_streams(i).data_v <= not adc_streams(i).data_v;
|
||||
end if;
|
||||
end loop;
|
||||
end if;
|
||||
end process;
|
||||
else generate
|
||||
adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
|
||||
end generate;
|
||||
|
||||
-- ========================================================================
|
||||
-- Processes
|
||||
-- ========================================================================
|
||||
|
||||
-- FX3 GPIF bidirectional signal control
|
||||
-- Adapted from same process in bladerf-hosted.vhd
|
||||
register_gpif : process(sys_rst, fx3_pclk_pll)
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
fx3_gpif_i <= (others => 'Z');
|
||||
fx3_gpif.gpif_in <= (others => 'Z');
|
||||
elsif( rising_edge(fx3_pclk_pll) ) then
|
||||
fx3_gpif.gpif_in <= fx3_gpif_i;
|
||||
|
||||
if( fx3_gpif.gpif_oe = '1' ) then
|
||||
fx3_gpif_i <= fx3_gpif.gpif_out;
|
||||
else
|
||||
fx3_gpif_i <= (others =>'Z');
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- FX3 CTL bidirectional signals
|
||||
-- Adapted from same generator in bladerf-hosted.vhd
|
||||
generate_ctl : for i in fx3_ctl_i'range generate
|
||||
fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
|
||||
end generate;
|
||||
|
||||
fx3_gpif.ctl_in <= fx3_ctl_i;
|
||||
|
||||
-- Controller for loopback FIFO
|
||||
-- Stripped-down version of same process from rx.vhd
|
||||
loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
loopback_enabled <= '0';
|
||||
loopback_fifo.rreq <= '0';
|
||||
loopback_i <= (others => '0');
|
||||
loopback_q <= (others => '0');
|
||||
loopback_valid <= '0';
|
||||
elsif( rising_edge(loopback_fifo.rclock) ) then
|
||||
loopback_enabled <= '0';
|
||||
loopback_fifo.rreq <= '0';
|
||||
loopback_i <= loopback_i;
|
||||
loopback_q <= loopback_q;
|
||||
loopback_valid <= '0';
|
||||
|
||||
-- Is loopback enabled?
|
||||
loopback_enabled <= fx3_control.rx_enable;
|
||||
|
||||
-- Do the loopback
|
||||
loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
|
||||
loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
|
||||
loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
|
||||
|
||||
-- Read from the FIFO if req'd
|
||||
loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- RX multiplexer
|
||||
-- Stripped-down version of same process from rx.vhd
|
||||
rx_mux : process(sys_rst, sys_clk)
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
rx_mux_i <= (others =>'0');
|
||||
rx_mux_q <= (others =>'0');
|
||||
rx_mux_valid <= '0';
|
||||
elsif( rising_edge(sys_clk) ) then
|
||||
rx_mux_i <= loopback_i;
|
||||
rx_mux_q <= loopback_q;
|
||||
rx_mux_valid <= loopback_valid;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- TX multiplexer
|
||||
-- Stripped-down version of mimo_channel_sel_mux from tx.vhd
|
||||
--tx_mux : process( sys_clk )
|
||||
--begin
|
||||
-- if( rising_edge(sys_clk) ) then
|
||||
-- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
|
||||
|
||||
-- loopback_fifo.wdata <= tx_sample_fifo.rdata;
|
||||
-- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
|
||||
-- end if;
|
||||
--end process;
|
||||
|
||||
|
||||
-- ========================================================================
|
||||
-- Verification
|
||||
-- ========================================================================
|
||||
print_config: process
|
||||
begin
|
||||
wait until rising_edge(fx3_control.tx_enable);
|
||||
report lf&
|
||||
"[CONFIG] EIGHT_BIT_MODE_EN: " & std_logic'image(EIGHT_BIT_MODE_EN) &lf&
|
||||
"[CONFIG] ENABLE_CHANNEL_0: " & std_logic'image(ENABLE_CHANNEL_0) &lf&
|
||||
"[CONFIG] ENABLE_CHANNEL_1: " & std_logic'image(ENABLE_CHANNEL_1);
|
||||
end process print_config;
|
||||
|
||||
|
||||
--
|
||||
-- Check for metavalues
|
||||
-- We should never see metavalues written to the FIFOs
|
||||
--
|
||||
check_fifo_write : process(fx3_pclk_pll) is
|
||||
begin
|
||||
if( rising_edge(fx3_pclk_pll) ) then
|
||||
if( tx_sample_fifo.wreq = '1' and fx3_control.meta_enable = '0' ) then
|
||||
for i in tx_sample_fifo.wdata'range loop
|
||||
assert tx_sample_fifo.wdata(i) = '0' or tx_sample_fifo.wdata(i) = '1'
|
||||
severity failure;
|
||||
end loop;
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
check_fifo_read : process(fx3_pclk_pll) is
|
||||
begin
|
||||
if( rising_edge(fx3_pclk_pll) ) then
|
||||
if( rx_sample_fifo.rreq = '1' ) then
|
||||
for i in rx_sample_fifo.rdata'range loop
|
||||
assert rx_sample_fifo.rdata(i) = '0' or rx_sample_fifo.rdata(i) = '1'
|
||||
severity failure;
|
||||
end loop;
|
||||
end if;
|
||||
end if;
|
||||
end process check_fifo_read;
|
||||
|
||||
--
|
||||
-- Check for fullness on FIFOs
|
||||
--
|
||||
assert(rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
|
||||
assert(tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
|
||||
assert(loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
|
||||
|
||||
--
|
||||
-- Tx Sample Check
|
||||
--
|
||||
look_for_dropped_tx_samples : process(tx_clock) is
|
||||
constant MESSAGES_PER_ITERATION : natural := 7; --Provided in fx3_model
|
||||
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
|
||||
variable current_message_count : natural := 1;
|
||||
variable iq_value : signed (15 downto 0) := x"0000";
|
||||
variable expected_sample_i : signed (15 downto 0);
|
||||
variable expected_sample_q : signed (15 downto 0);
|
||||
variable failure_count : natural := 0;
|
||||
begin
|
||||
for i in dac_controls'range loop
|
||||
if( rising_edge(tx_clock)
|
||||
and dac_controls(i).enable = '1'
|
||||
and dac_streams(i).data_v = '1'
|
||||
and fx3_control.tx_enable = '1' )
|
||||
then
|
||||
if( EIGHT_BIT_MODE_EN = '1' ) then
|
||||
expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
|
||||
expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
|
||||
|
||||
assert ( dac_streams(i).data_i = expected_sample_i )
|
||||
report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " &
|
||||
"expected_sample_i: " & to_hstring(expected_sample_i)
|
||||
severity warning;
|
||||
assert ( dac_streams(i).data_q = expected_sample_q )
|
||||
report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " &
|
||||
"expected_sample_q: " & to_hstring(expected_sample_q)
|
||||
severity warning;
|
||||
|
||||
if ( dac_streams(i).data_i /= expected_sample_i or dac_streams(i).data_q /= expected_sample_q ) then
|
||||
failure_count := failure_count + 1;
|
||||
if ( failure_count >= 6 ) then
|
||||
report "tx fail count tolerance exceeded" severity failure;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
iq_value := (iq_value + 2) mod 128;
|
||||
else
|
||||
expected_sample_i := iq_value;
|
||||
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
|
||||
|
||||
assert(dac_streams(i).data_i = expected_sample_i)
|
||||
report "dac_streams("&to_string(i)&").data_i: " & to_hstring(dac_streams(i).data_i) & " | " &
|
||||
"expected_sample_i: " & to_hstring(expected_sample_i)
|
||||
severity failure;
|
||||
assert(dac_streams(i).data_q = expected_sample_q)
|
||||
report "dac_streams("&to_string(i)&").data_q: " & to_hstring(dac_streams(i).data_q) & " | " &
|
||||
"expected_sample_q: " & to_hstring(expected_sample_q)
|
||||
severity failure;
|
||||
|
||||
-- Set iq values based on blocks received
|
||||
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
|
||||
if( iq_value = x"03FE" ) then
|
||||
iq_value := x"0000";
|
||||
if( current_message_count < MESSAGES_PER_ITERATION ) then
|
||||
current_message_count := current_message_count + 1;
|
||||
else
|
||||
current_message_count := 1;
|
||||
end if;
|
||||
else
|
||||
iq_value := (iq_value + 2) mod 2048;
|
||||
end if;
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
end process look_for_dropped_tx_samples;
|
||||
|
||||
--
|
||||
-- Rx Sample Check
|
||||
--
|
||||
first_rx_val_at_mux: process
|
||||
-- Catches and saves the first sample of
|
||||
-- each rx enabled burst seen by the mux
|
||||
begin
|
||||
for i in adc_controls'range loop
|
||||
if( adc_controls(i).enable = '1') then
|
||||
if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1' ) then
|
||||
adc_stream_val_at_rx_enable <= adc_streams(i).data_i - 1;
|
||||
else
|
||||
adc_stream_val_at_rx_enable <= adc_streams(i).data_i;
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
wait until rising_edge(trigger_signal_sync_tb);
|
||||
end process first_rx_val_at_mux;
|
||||
|
||||
look_for_dropped_rx_samples: process(fx3_pclk_pll)
|
||||
variable rx_val : integer := 0;
|
||||
|
||||
variable q_expected : std_logic_vector (15 downto 0);
|
||||
variable i_expected : std_logic_vector (15 downto 0);
|
||||
variable q_out : std_logic_vector (15 downto 0);
|
||||
variable i_out : std_logic_vector (15 downto 0);
|
||||
|
||||
variable q0_expected_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable i0_expected_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable q1_expected_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable i1_expected_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable q0_out_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable i0_out_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable q1_out_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
variable i1_out_eight_bit_mode : std_logic_vector (7 downto 0);
|
||||
|
||||
variable previous_adc_stream_val_at_rx_enable : signed (15 downto 0) := ( others => '0');
|
||||
variable fail_count: natural := 0;
|
||||
variable both_channels_en : std_logic;
|
||||
begin
|
||||
if( previous_adc_stream_val_at_rx_enable /= adc_stream_val_at_rx_enable ) then
|
||||
rx_val := to_integer(adc_stream_val_at_rx_enable (15 downto 4)) when EIGHT_BIT_MODE_EN else
|
||||
to_integer(adc_stream_val_at_rx_enable);
|
||||
previous_adc_stream_val_at_rx_enable := adc_stream_val_at_rx_enable;
|
||||
end if;
|
||||
|
||||
if( rising_edge(fx3_pclk_pll)
|
||||
and fx3_gpif.gpif_oe = '1'
|
||||
and fx3_control.rx_enable = '1' ) then
|
||||
if( EIGHT_BIT_MODE_EN = '1') then
|
||||
-- The +-1 ch1 offset in SISO mode will not reach 128
|
||||
both_channels_en := ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1;
|
||||
q1_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val - 1, 8)) when both_channels_en else
|
||||
std_logic_vector(to_signed(-((rx_val + 1) mod 128), 8));
|
||||
i1_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val + 1, 8)) when both_channels_en else
|
||||
std_logic_vector(to_signed((rx_val + 1) mod 128, 8));
|
||||
q0_expected_eight_bit_mode := std_logic_vector(to_signed(-rx_val, 8));
|
||||
i0_expected_eight_bit_mode := std_logic_vector(to_signed(rx_val, 8));
|
||||
|
||||
q1_out_eight_bit_mode := fx3_gpif.gpif_out(31 downto 24);
|
||||
i1_out_eight_bit_mode := fx3_gpif.gpif_out(23 downto 16);
|
||||
q0_out_eight_bit_mode := fx3_gpif.gpif_out(15 downto 8);
|
||||
i0_out_eight_bit_mode := fx3_gpif.gpif_out(7 downto 0);
|
||||
|
||||
if( q1_out_eight_bit_mode /= q1_expected_eight_bit_mode or
|
||||
i1_out_eight_bit_mode /= i1_expected_eight_bit_mode or
|
||||
q0_out_eight_bit_mode /= q0_expected_eight_bit_mode or
|
||||
i0_out_eight_bit_mode /= i0_expected_eight_bit_mode) then
|
||||
fail_count := fail_count + 1;
|
||||
report "-----------------------------";
|
||||
if( fail_count > 3 ) then
|
||||
report "rx fail count tolerance exceeded" severity failure;
|
||||
end if;
|
||||
end if;
|
||||
|
||||
assert ( q1_out_eight_bit_mode = q1_expected_eight_bit_mode )
|
||||
report "data_q1: " & to_hstring(q1_out_eight_bit_mode) & " | " &
|
||||
"expected: " & to_hstring(q1_expected_eight_bit_mode)
|
||||
severity warning;
|
||||
assert ( i1_out_eight_bit_mode = i1_expected_eight_bit_mode )
|
||||
report "data_i1: " & to_hstring(i1_out_eight_bit_mode) & " | " &
|
||||
"expected: " & to_hstring(i1_expected_eight_bit_mode)
|
||||
severity warning;
|
||||
assert ( q0_out_eight_bit_mode = q0_expected_eight_bit_mode )
|
||||
report "data_q0: " & to_hstring(q0_out_eight_bit_mode) & " | " &
|
||||
"expected: " & to_hstring(q0_expected_eight_bit_mode)
|
||||
severity warning;
|
||||
assert ( i0_out_eight_bit_mode = i0_expected_eight_bit_mode )
|
||||
report "data_i0: " & to_hstring(i0_out_eight_bit_mode) & " | " &
|
||||
"expected: " & to_hstring(i0_expected_eight_bit_mode)
|
||||
severity warning;
|
||||
|
||||
-- 128 limit set by gen_adc_controls above
|
||||
rx_val := (rx_val + 2) mod 128;
|
||||
else
|
||||
q_expected := std_logic_vector(to_signed(-rx_val, 16));
|
||||
i_expected := std_logic_vector(to_signed(rx_val, 16));
|
||||
q_out := fx3_gpif.gpif_out(31 downto 16);
|
||||
i_out := fx3_gpif.gpif_out(15 downto 0);
|
||||
|
||||
assert(q_out = q_expected)
|
||||
report "data_q: " & to_hstring(q_out) & " | " &
|
||||
"expected: " & to_hstring(q_expected)
|
||||
severity failure;
|
||||
assert(i_out = i_expected)
|
||||
report "data_i: " & to_hstring(i_out) & " | " &
|
||||
"expected: " & to_hstring(i_expected)
|
||||
severity failure;
|
||||
|
||||
-- 2047 limit set by gen_adc_controls above
|
||||
rx_val := (rx_val + 1) mod 2048;
|
||||
end if;
|
||||
end if;
|
||||
end process look_for_dropped_rx_samples;
|
||||
|
||||
end architecture;
|
||||
|
|
@ -32,6 +32,7 @@ library nuand;
|
|||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity fx3_gpif_iq_8bit_tb is
|
||||
generic (
|
||||
|
|
@ -659,6 +660,7 @@ begin
|
|||
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
|
||||
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
|
||||
variable current_message_count : natural := 1;
|
||||
variable valid_sample_count : natural := 0;
|
||||
variable iq_value : signed (15 downto 0) := x"0000";
|
||||
variable expected_sample_i : signed (15 downto 0);
|
||||
variable expected_sample_q : signed (15 downto 0);
|
||||
|
|
@ -670,6 +672,7 @@ begin
|
|||
and dac_streams(i).data_v = '1'
|
||||
and fx3_control.tx_enable = '1' )
|
||||
then
|
||||
valid_sample_count := valid_sample_count + 1;
|
||||
if( EIGHT_BIT_MODE_EN = '1' ) then
|
||||
expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
|
||||
expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
|
||||
|
|
@ -706,7 +709,7 @@ begin
|
|||
|
||||
-- Set iq values based on blocks received
|
||||
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
|
||||
if( iq_value = x"03FE" ) then
|
||||
if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then
|
||||
iq_value := x"0000";
|
||||
if( current_message_count < MESSAGES_PER_ITERATION ) then
|
||||
current_message_count := current_message_count + 1;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,681 @@
|
|||
-- Copyright (c) 2024 Nuand LLC
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
-- of this software and associated documentation files (the "Software"), to deal
|
||||
-- in the Software without restriction, including without limitation the rights
|
||||
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
-- copies of the Software, and to permit persons to whom the Software is
|
||||
-- furnished to do so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in
|
||||
-- all copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
-- THE SOFTWARE.
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
library rtl_work;
|
||||
|
||||
library altera_lnsim;
|
||||
use altera_lnsim.altera_pll;
|
||||
|
||||
library nuand;
|
||||
use nuand.util.all ;
|
||||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity fx3_gpif_iq_packed_tb is
|
||||
generic (
|
||||
-- For bladeRF2 (2x2 MIMO):
|
||||
NUM_MIMO_STREAMS : natural := 2;
|
||||
FIFO_READER_READ_THROTTLE : natural := 0;
|
||||
|
||||
ENABLE_CHANNEL_0 : std_logic := '1';
|
||||
ENABLE_CHANNEL_1 : std_logic := '1'
|
||||
);
|
||||
end entity;
|
||||
|
||||
architecture arch of fx3_gpif_iq_packed_tb is
|
||||
|
||||
-- bladerf-hosted uses ad9361.clock (125 MHz) for rx_clock and tx_clock
|
||||
constant SYSCLK_HALF_PERIOD : time := 1 sec * (1.0/125.0e6/2.0);
|
||||
|
||||
-- For reasons unknown, simulation of this system in ModelSim requires that
|
||||
-- wrreq and data be asserted shortly before the rising clock edge. Sigh...
|
||||
constant FIFO_WORKAROUND : time := 1 ps;
|
||||
|
||||
type fx3_control_t is record
|
||||
usb_speed : std_logic;
|
||||
tx_enable : std_logic;
|
||||
rx_enable : std_logic;
|
||||
meta_enable : std_logic;
|
||||
packet : std_logic;
|
||||
highly_packed_mode : std_logic;
|
||||
end record;
|
||||
|
||||
type fx3_gpif_t is record
|
||||
gpif_in : std_logic_vector(31 downto 0);
|
||||
gpif_out : std_logic_vector(31 downto 0);
|
||||
gpif_oe : std_logic;
|
||||
ctl_in : std_logic_vector(12 downto 0);
|
||||
ctl_out : std_logic_vector(12 downto 0);
|
||||
ctl_oe : std_logic_vector(12 downto 0);
|
||||
end record;
|
||||
|
||||
signal sys_rst : std_logic := '1';
|
||||
signal done : boolean := false;
|
||||
|
||||
signal fx3_pclk : std_logic := '1';
|
||||
signal fx3_pclk_pll : std_logic := '1';
|
||||
signal sys_clk : std_logic := '1';
|
||||
|
||||
signal pll_reset : std_logic := '0';
|
||||
signal pll_locked : std_logic := '0';
|
||||
signal fx3_control : fx3_control_t;
|
||||
signal fx3_gpif : fx3_gpif_t;
|
||||
signal fx3_gpif_i : std_logic_vector(31 downto 0);
|
||||
signal fx3_ctl_i : std_logic_vector(12 downto 0);
|
||||
|
||||
-- Control mapping
|
||||
alias dma0_rx_ack is fx3_ctl_i( 0);
|
||||
alias dma1_rx_ack is fx3_ctl_i( 1);
|
||||
alias dma2_tx_ack is fx3_ctl_i( 2);
|
||||
alias dma3_tx_ack is fx3_ctl_i( 3);
|
||||
alias dma_rx_enable is fx3_ctl_i( 4);
|
||||
alias dma_tx_enable is fx3_ctl_i( 5);
|
||||
alias dma_idle is fx3_ctl_i( 6);
|
||||
alias system_reset is fx3_ctl_i( 7);
|
||||
alias dma0_rx_reqx is fx3_ctl_i( 8);
|
||||
alias dma1_rx_reqx is fx3_ctl_i(12); -- due to 9 being connected to dclk
|
||||
alias dma2_tx_reqx is fx3_ctl_i(10);
|
||||
alias dma3_tx_reqx is fx3_ctl_i(11);
|
||||
|
||||
signal loopback_i : signed(15 downto 0) := (others =>'0');
|
||||
signal loopback_q : signed(15 downto 0) := (others =>'0');
|
||||
signal loopback_valid : std_logic := '0';
|
||||
signal loopback_enabled : std_logic := '0';
|
||||
|
||||
signal tx_clock : std_logic := '1' ;
|
||||
signal rx_clock : std_logic := '1' ;
|
||||
|
||||
signal rx_sample_fifo : rx_fifo_t := RX_FIFO_T_DEFAULT;
|
||||
signal tx_sample_fifo : tx_fifo_t := TX_FIFO_T_DEFAULT;
|
||||
signal loopback_fifo : loopback_fifo_t := LOOPBACK_FIFO_T_DEFAULT;
|
||||
signal rx_meta_fifo : meta_fifo_rx_t := META_FIFO_RX_T_DEFAULT;
|
||||
signal tx_meta_fifo : meta_fifo_tx_t := META_FIFO_TX_T_DEFAULT;
|
||||
|
||||
signal rx_mux_i : signed(15 downto 0);
|
||||
signal rx_mux_q : signed(15 downto 0);
|
||||
signal rx_mux_valid : std_logic;
|
||||
|
||||
signal tx_timestamp : unsigned(63 downto 0) := ( others => '0' );
|
||||
signal rx_timestamp : unsigned(63 downto 0) := ( others => '0' );
|
||||
|
||||
constant FX3_HALF_PERIOD : time := 1.0/(100.0e6)/2.0*1 sec ;
|
||||
constant TX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
|
||||
constant RX_HALF_PERIOD : time := 1.0/(9.0e6)/2.0*1 sec ;
|
||||
|
||||
signal dac_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
|
||||
signal dac_streams : sample_streams_t(dac_controls'range) := (others => ZERO_SAMPLE);
|
||||
signal adc_controls : sample_controls_t(0 to NUM_MIMO_STREAMS-1) := (others => SAMPLE_CONTROL_DISABLE);
|
||||
signal adc_streams : sample_streams_t(adc_controls'range) := (others => ZERO_SAMPLE);
|
||||
|
||||
signal tx_reset : std_logic := '0';
|
||||
signal tx_ts_reset : std_logic := '0';
|
||||
signal rx_reset : std_logic := '0';
|
||||
signal rx_ts_reset : std_logic := '0';
|
||||
|
||||
signal meta_en_tx : std_logic := '0';
|
||||
signal meta_en_rx : std_logic := '0';
|
||||
|
||||
signal rx_packet_control : packet_control_t := PACKET_CONTROL_DEFAULT;
|
||||
signal tx_packet_control : packet_control_t;
|
||||
|
||||
signal trigger_signal_sync_tb : std_logic;
|
||||
signal dac_stream_val_at_rx_enable : signed(15 downto 0) := ( others => '0' );
|
||||
|
||||
function data_gen (count : natural) return std_logic_vector is
|
||||
variable msw, lsw : std_logic_vector(15 downto 0);
|
||||
begin
|
||||
msw := std_logic_vector(to_signed(count, 16));
|
||||
lsw := std_logic_vector(to_signed(-count, 16));
|
||||
|
||||
return (msw & lsw);
|
||||
end function data_gen;
|
||||
|
||||
signal rx_packet_ready : std_logic;
|
||||
|
||||
begin
|
||||
|
||||
-- ========================================================================
|
||||
-- Brief summary of data flow
|
||||
-- ========================================================================
|
||||
--
|
||||
-- Simulated samples flow from fx3_model's TX side to its RX side. The
|
||||
-- validity of the data is checked there.
|
||||
--
|
||||
-- entity U_fx3_model FX3 model, TX process
|
||||
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '0'
|
||||
-- process register_gpif
|
||||
-- signal fx3_gpif.gpif_in Demuxed GPIF interface (FX3 -> FPGA)
|
||||
-- entity U_fx3_gpif GPIF implementation, write side
|
||||
-- signal tx_sample_fifo.w* TX fifo, write side
|
||||
-- entity U_tx_sample_fifo
|
||||
-- signal tx_sample_fifo.r* TX fifo, read side
|
||||
-- process tx_mux
|
||||
-- signal loopback_fifo.w* Loopback fifo, write side
|
||||
-- entity U_rx_loopback_fifo
|
||||
-- signal loopback_fifo.r* Loopback fifo, read side
|
||||
-- process loopback_fifo_control
|
||||
-- signal loopback_{i,q,valid}
|
||||
-- process rx_mux
|
||||
-- signal rx_mux_{i,q,valid}
|
||||
-- entity U_fifo_writer
|
||||
-- signal rx_sample_fifo.w* RX fifo, write side
|
||||
-- entity U_rx_sample_fifo
|
||||
-- signal rx_sample_fifo.r* RX fifo, read side
|
||||
-- entity U_fx3_gpif GPIF implementation, read side
|
||||
-- signal fx3_gpif.gpif_out Demuxed GPIF interface (FPGA -> FX3)
|
||||
-- process register_gpif
|
||||
-- signal fx3_gpif_i fx3_gpif.gpif_oe is '1'
|
||||
-- entity U_fx3_model FX3 model, RX process
|
||||
|
||||
|
||||
-- ========================================================================
|
||||
-- Instantiations
|
||||
-- ========================================================================
|
||||
|
||||
-- Unit under test
|
||||
-- Clock domain: fx3_pclk_pll
|
||||
U_fx3_gpif : entity nuand.fx3_gpif
|
||||
port map (
|
||||
pclk => fx3_pclk_pll,
|
||||
reset => sys_rst,
|
||||
usb_speed => fx3_control.usb_speed,
|
||||
gpif_in => fx3_gpif.gpif_in,
|
||||
gpif_out => fx3_gpif.gpif_out,
|
||||
gpif_oe => fx3_gpif.gpif_oe,
|
||||
ctl_in => fx3_gpif.ctl_in,
|
||||
ctl_out => fx3_gpif.ctl_out,
|
||||
ctl_oe => fx3_gpif.ctl_oe,
|
||||
tx_enable => fx3_control.tx_enable,
|
||||
rx_enable => fx3_control.rx_enable,
|
||||
meta_enable => fx3_control.meta_enable,
|
||||
packet_enable => fx3_control.packet,
|
||||
tx_fifo_write => tx_sample_fifo.wreq,
|
||||
tx_fifo_full => tx_sample_fifo.wfull,
|
||||
tx_fifo_empty => tx_sample_fifo.wempty,
|
||||
tx_fifo_usedw => tx_sample_fifo.wused,
|
||||
tx_fifo_data => tx_sample_fifo.wdata,
|
||||
tx_timestamp => tx_timestamp,
|
||||
tx_meta_fifo_write => tx_meta_fifo.wreq,
|
||||
tx_meta_fifo_full => tx_meta_fifo.wfull,
|
||||
tx_meta_fifo_empty => tx_meta_fifo.wempty,
|
||||
tx_meta_fifo_usedw => tx_meta_fifo.wused,
|
||||
tx_meta_fifo_data => tx_meta_fifo.wdata,
|
||||
rx_fifo_read => rx_sample_fifo.rreq,
|
||||
rx_fifo_full => rx_sample_fifo.rfull,
|
||||
rx_fifo_empty => rx_sample_fifo.rempty,
|
||||
rx_fifo_usedw => rx_sample_fifo.rused,
|
||||
rx_fifo_data => rx_sample_fifo.rdata,
|
||||
rx_meta_fifo_read => rx_meta_fifo.rreq,
|
||||
rx_meta_fifo_full => rx_meta_fifo.rfull,
|
||||
rx_meta_fifo_empty => rx_meta_fifo.rempty,
|
||||
rx_meta_fifo_usedr => rx_meta_fifo.rused,
|
||||
rx_meta_fifo_data => rx_meta_fifo.rdata
|
||||
);
|
||||
|
||||
-- Discrete control signals for fx3_gpif
|
||||
fx3_control.usb_speed <= '0';
|
||||
fx3_control.meta_enable <= '0';
|
||||
fx3_control.packet <= '0';
|
||||
fx3_control.highly_packed_mode <= '1';
|
||||
|
||||
U_pkt_gen : entity nuand.rx_packet_generator
|
||||
port map(
|
||||
rx_clock => rx_clock,
|
||||
rx_reset => rx_reset,
|
||||
rx_enable => fx3_control.rx_enable,
|
||||
rx_packet_enable => fx3_control.packet,
|
||||
rx_packet_ready => rx_packet_ready,
|
||||
rx_packet_control => rx_packet_control
|
||||
);
|
||||
|
||||
|
||||
meta_en_tx <= fx3_control.meta_enable;
|
||||
meta_en_rx <= fx3_control.meta_enable;
|
||||
|
||||
increment_tx_ts : process(tx_clock)
|
||||
variable ping : boolean := true ;
|
||||
begin
|
||||
if( rising_edge(tx_clock) ) then
|
||||
ping := not ping ;
|
||||
if( ping = true ) then
|
||||
tx_timestamp <= tx_timestamp + 1 ;
|
||||
end if ;
|
||||
end if ;
|
||||
end process ;
|
||||
|
||||
increment_rx_ts : process(rx_clock)
|
||||
variable ping : boolean := true ;
|
||||
begin
|
||||
if( rising_edge(rx_clock) ) then
|
||||
ping := not ping ;
|
||||
if( ping = true ) then
|
||||
rx_timestamp <= rx_timestamp + 1 ;
|
||||
end if ;
|
||||
end if ;
|
||||
end process ;
|
||||
|
||||
-- Model of FX3's GPIF interface
|
||||
-- Clock domain: fx3_pclk (source)
|
||||
U_fx3_model : entity nuand.fx3_model(micro_dma)
|
||||
port map (
|
||||
fx3_pclk => fx3_pclk,
|
||||
fx3_gpif => fx3_gpif_i,
|
||||
fx3_ctl => fx3_ctl_i,
|
||||
fx3_uart_rxd => '0',
|
||||
fx3_uart_txd => open,
|
||||
fx3_uart_cts => open,
|
||||
fx3_rx_en => '1',
|
||||
fx3_rx_meta_en => meta_en_rx,
|
||||
fx3_tx_en => '1',
|
||||
fx3_tx_meta_en => meta_en_tx,
|
||||
packed_mode_en => fx3_control.highly_packed_mode,
|
||||
done => done
|
||||
);
|
||||
|
||||
-- Generate phase-shifted PLL clock
|
||||
U_fx3_pll : entity rtl_work.fx3_pll
|
||||
port map (
|
||||
inclk0 => fx3_pclk,
|
||||
areset => pll_reset,
|
||||
c0 => fx3_pclk_pll,
|
||||
locked => pll_locked
|
||||
);
|
||||
|
||||
tx_clock <= not tx_clock after TX_HALF_PERIOD ;
|
||||
rx_clock <= not rx_clock after RX_HALF_PERIOD ;
|
||||
|
||||
|
||||
-- Reset handler
|
||||
sys_rst <= '0' after 100 ns;
|
||||
|
||||
-- Generate system clock
|
||||
sys_clk <= not sys_clk after SYSCLK_HALF_PERIOD when not done else '0';
|
||||
|
||||
|
||||
tx_reset <= sys_rst;
|
||||
tx_ts_reset <= sys_rst;
|
||||
rx_reset <= sys_rst;
|
||||
rx_ts_reset <= sys_rst;
|
||||
|
||||
meta_en_tx <= fx3_control.meta_enable;
|
||||
meta_en_rx <= fx3_control.meta_enable;
|
||||
|
||||
-- TX Submodule
|
||||
U_tx : entity work.tx
|
||||
generic map (
|
||||
NUM_STREAMS => dac_controls'length
|
||||
)
|
||||
port map (
|
||||
tx_reset => tx_reset,
|
||||
tx_clock => tx_clock,
|
||||
tx_enable => fx3_control.tx_enable,
|
||||
|
||||
meta_en => meta_en_tx,
|
||||
timestamp_reset => tx_ts_reset,
|
||||
usb_speed => fx3_control.usb_speed,
|
||||
tx_underflow_led => open,
|
||||
tx_timestamp => tx_timestamp,
|
||||
|
||||
-- Packing modes
|
||||
highly_packed_mode_en => fx3_control.highly_packed_mode,
|
||||
|
||||
-- Triggering
|
||||
trigger_arm => '0',
|
||||
trigger_fire => '0',
|
||||
trigger_master => '0',
|
||||
trigger_line => open,
|
||||
|
||||
-- Packet FIFO
|
||||
packet_en => fx3_control.packet,
|
||||
packet_empty => open,
|
||||
packet_control => tx_packet_control,
|
||||
packet_ready => '1',
|
||||
|
||||
-- Samples from host via FX3
|
||||
sample_fifo_wclock => fx3_pclk_pll,
|
||||
sample_fifo_wreq => tx_sample_fifo.wreq,
|
||||
sample_fifo_wdata => tx_sample_fifo.wdata,
|
||||
sample_fifo_wempty => tx_sample_fifo.wempty,
|
||||
sample_fifo_wfull => tx_sample_fifo.wfull,
|
||||
sample_fifo_wused => tx_sample_fifo.wused,
|
||||
|
||||
-- Metadata from host via FX3
|
||||
meta_fifo_wclock => fx3_pclk_pll,
|
||||
meta_fifo_wreq => tx_meta_fifo.wreq,
|
||||
meta_fifo_wdata => tx_meta_fifo.wdata,
|
||||
meta_fifo_wempty => tx_meta_fifo.wempty,
|
||||
meta_fifo_wfull => tx_meta_fifo.wfull,
|
||||
meta_fifo_wused => tx_meta_fifo.wused,
|
||||
|
||||
-- Digital Loopback Interface
|
||||
loopback_enabled => '0',
|
||||
loopback_fifo_wdata => loopback_fifo.wdata,
|
||||
loopback_fifo_wreq => loopback_fifo.wreq,
|
||||
loopback_fifo_wfull => loopback_fifo.wfull,
|
||||
loopback_fifo_wused => loopback_fifo.wused,
|
||||
|
||||
-- RFFE Interface
|
||||
dac_controls => dac_controls,
|
||||
dac_streams => dac_streams
|
||||
);
|
||||
|
||||
-- RX Submodule
|
||||
U_rx : entity work.rx
|
||||
generic map (
|
||||
NUM_STREAMS => adc_controls'length
|
||||
)
|
||||
port map (
|
||||
highly_packed_mode_en => fx3_control.highly_packed_mode,
|
||||
rx_reset => rx_reset,
|
||||
rx_clock => rx_clock,
|
||||
rx_enable => fx3_control.rx_enable,
|
||||
|
||||
meta_en => meta_en_rx,
|
||||
timestamp_reset => rx_ts_reset,
|
||||
usb_speed => fx3_control.usb_speed,
|
||||
rx_mux_sel => to_unsigned(0, 3),
|
||||
rx_overflow_led => open,
|
||||
rx_timestamp => rx_timestamp,
|
||||
|
||||
-- Triggering
|
||||
trigger_arm => '0',
|
||||
trigger_fire => '0',
|
||||
trigger_master => '0',
|
||||
trigger_line => open,
|
||||
trigger_signal_sync_tb => trigger_signal_sync_tb,
|
||||
|
||||
-- Packet FIFO
|
||||
packet_en => fx3_control.packet,
|
||||
packet_control => rx_packet_control,
|
||||
packet_ready => rx_packet_ready,
|
||||
|
||||
-- Samples to host via FX3
|
||||
sample_fifo_rclock => fx3_pclk_pll,
|
||||
sample_fifo_raclr => not fx3_control.rx_enable,
|
||||
sample_fifo_rreq => rx_sample_fifo.rreq,
|
||||
sample_fifo_rdata => rx_sample_fifo.rdata,
|
||||
sample_fifo_rempty => rx_sample_fifo.rempty,
|
||||
sample_fifo_rfull => rx_sample_fifo.rfull,
|
||||
sample_fifo_rused => rx_sample_fifo.rused,
|
||||
|
||||
-- Mini expansion signals
|
||||
mini_exp => "00",
|
||||
|
||||
-- Metadata to host via FX3
|
||||
meta_fifo_rclock => fx3_pclk_pll,
|
||||
meta_fifo_raclr => not fx3_control.rx_enable,
|
||||
meta_fifo_rreq => rx_meta_fifo.rreq,
|
||||
meta_fifo_rdata => rx_meta_fifo.rdata,
|
||||
meta_fifo_rempty => rx_meta_fifo.rempty,
|
||||
meta_fifo_rfull => rx_meta_fifo.rfull,
|
||||
meta_fifo_rused => rx_meta_fifo.rused,
|
||||
|
||||
-- Digital Loopback Interface
|
||||
loopback_fifo_wenabled => open,
|
||||
loopback_fifo_wreset => tx_reset,
|
||||
loopback_fifo_wclock => tx_clock,
|
||||
loopback_fifo_wdata => loopback_fifo.wdata,
|
||||
loopback_fifo_wreq => loopback_fifo.wreq,
|
||||
loopback_fifo_wfull => loopback_fifo.wfull,
|
||||
loopback_fifo_wused => loopback_fifo.wused,
|
||||
|
||||
-- RFFE Interface
|
||||
adc_controls => adc_controls,
|
||||
adc_streams => adc_streams
|
||||
);
|
||||
|
||||
-- ========================================================================
|
||||
-- Data converters
|
||||
-- ========================================================================
|
||||
|
||||
gen_dac_controls : if( NUM_MIMO_STREAMS > 1 ) generate
|
||||
-- The TX side of the AD9361 HDL is a FIFO pull interface
|
||||
-- that expects a readahead FIFO. It toggles the data request
|
||||
-- signal every other cycle. This behavior is mimicked here.
|
||||
process( tx_clock, sys_rst )
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
dac_controls <= (
|
||||
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
|
||||
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
|
||||
);
|
||||
elsif( rising_edge(tx_clock) ) then
|
||||
for i in dac_controls'range loop
|
||||
dac_controls(i) <= (
|
||||
enable => dac_controls(i).enable,
|
||||
data_req => not dac_controls(i).data_req );
|
||||
end loop;
|
||||
end if;
|
||||
end process;
|
||||
else generate
|
||||
dac_controls <= (others => SAMPLE_CONTROL_ENABLE);
|
||||
end generate;
|
||||
|
||||
gen_adc_controls : if( NUM_MIMO_STREAMS > 1 ) generate
|
||||
process( rx_clock, sys_rst )
|
||||
constant COUNT_RESET : integer := 0;
|
||||
variable count : integer range -2047 to 2047 := COUNT_RESET;
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
count := COUNT_RESET;
|
||||
adc_controls <= (
|
||||
0 => (enable => ENABLE_CHANNEL_0, data_req => '1'),
|
||||
1 => (enable => ENABLE_CHANNEL_1, data_req => '1')
|
||||
);
|
||||
elsif( rising_edge(rx_clock) ) then
|
||||
for i in adc_controls'range loop
|
||||
adc_controls(i) <= (
|
||||
enable => adc_controls(i).enable,
|
||||
data_req => not adc_controls(i).data_req );
|
||||
if( adc_controls(i).enable = '1') then
|
||||
if( adc_streams(i).data_v = '1' ) then
|
||||
adc_streams(i).data_i <= to_signed(count, 16);
|
||||
adc_streams(i).data_q <= to_signed(-count, 16);
|
||||
if( count < 2047 ) then
|
||||
count := count + 1;
|
||||
else
|
||||
count := COUNT_RESET;
|
||||
end if;
|
||||
end if;
|
||||
adc_streams(i).data_v <= not adc_streams(i).data_v;
|
||||
end if;
|
||||
end loop;
|
||||
end if;
|
||||
end process;
|
||||
else generate
|
||||
adc_controls <= (others => SAMPLE_CONTROL_ENABLE);
|
||||
end generate;
|
||||
|
||||
-- ========================================================================
|
||||
-- Processes
|
||||
-- ========================================================================
|
||||
|
||||
-- FX3 GPIF bidirectional signal control
|
||||
-- Adapted from same process in bladerf-hosted.vhd
|
||||
register_gpif : process(sys_rst, fx3_pclk_pll)
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
fx3_gpif_i <= (others => 'Z');
|
||||
fx3_gpif.gpif_in <= (others => 'Z');
|
||||
elsif( rising_edge(fx3_pclk_pll) ) then
|
||||
fx3_gpif.gpif_in <= fx3_gpif_i;
|
||||
|
||||
if( fx3_gpif.gpif_oe = '1' ) then
|
||||
fx3_gpif_i <= fx3_gpif.gpif_out;
|
||||
else
|
||||
fx3_gpif_i <= (others =>'Z');
|
||||
end if;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- FX3 CTL bidirectional signals
|
||||
-- Adapted from same generator in bladerf-hosted.vhd
|
||||
generate_ctl : for i in fx3_ctl_i'range generate
|
||||
fx3_ctl_i(i) <= fx3_gpif.ctl_out(i) when fx3_gpif.ctl_oe(i) = '1' else 'Z';
|
||||
end generate;
|
||||
|
||||
fx3_gpif.ctl_in <= fx3_ctl_i;
|
||||
|
||||
-- Controller for loopback FIFO
|
||||
-- Stripped-down version of same process from rx.vhd
|
||||
loopback_fifo_control : process( sys_rst, loopback_fifo.rclock )
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
loopback_enabled <= '0';
|
||||
loopback_fifo.rreq <= '0';
|
||||
loopback_i <= (others => '0');
|
||||
loopback_q <= (others => '0');
|
||||
loopback_valid <= '0';
|
||||
elsif( rising_edge(loopback_fifo.rclock) ) then
|
||||
loopback_enabled <= '0';
|
||||
loopback_fifo.rreq <= '0';
|
||||
loopback_i <= loopback_i;
|
||||
loopback_q <= loopback_q;
|
||||
loopback_valid <= '0';
|
||||
|
||||
-- Is loopback enabled?
|
||||
loopback_enabled <= fx3_control.rx_enable;
|
||||
|
||||
-- Do the loopback
|
||||
loopback_i <= resize(signed(loopback_fifo.rdata(15 downto 0)), loopback_i'length);
|
||||
loopback_q <= resize(signed(loopback_fifo.rdata(31 downto 16)), loopback_q'length);
|
||||
loopback_valid <= loopback_fifo.rreq and not loopback_fifo.rempty;
|
||||
|
||||
-- Read from the FIFO if req'd
|
||||
loopback_fifo.rreq <= loopback_enabled and (not loopback_fifo.rempty);
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- RX multiplexer
|
||||
-- Stripped-down version of same process from rx.vhd
|
||||
rx_mux : process(sys_rst, sys_clk)
|
||||
begin
|
||||
if( sys_rst = '1' ) then
|
||||
rx_mux_i <= (others =>'0');
|
||||
rx_mux_q <= (others =>'0');
|
||||
rx_mux_valid <= '0';
|
||||
elsif( rising_edge(sys_clk) ) then
|
||||
rx_mux_i <= loopback_i;
|
||||
rx_mux_q <= loopback_q;
|
||||
rx_mux_valid <= loopback_valid;
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- TX multiplexer
|
||||
-- Stripped-down version of mimo_channel_sel_mux from tx.vhd
|
||||
--tx_mux : process( sys_clk )
|
||||
--begin
|
||||
-- if( rising_edge(sys_clk) ) then
|
||||
-- tx_sample_fifo.rreq <= not tx_sample_fifo.rempty;
|
||||
|
||||
-- loopback_fifo.wdata <= tx_sample_fifo.rdata;
|
||||
-- loopback_fifo.wreq <= tx_sample_fifo.rreq and not tx_sample_fifo.rempty;
|
||||
-- end if;
|
||||
--end process;
|
||||
|
||||
|
||||
-- ========================================================================
|
||||
-- Verification
|
||||
-- ========================================================================
|
||||
|
||||
--
|
||||
-- Check for fullness on FIFOs
|
||||
--
|
||||
assert (rx_sample_fifo.wfull = '0') report "rx_sample_fifo full (write)" severity warning;
|
||||
assert (tx_sample_fifo.wfull = '0') report "tx_sample_fifo full (write)" severity warning;
|
||||
assert (loopback_fifo.wfull = '0') report "loopback_fifo full (write)" severity warning;
|
||||
|
||||
-- Every three gpif transfers will contain 4 samples.
|
||||
-- Let's fill and check a 4 sample buffer every 3 pclk cycles.
|
||||
--
|
||||
-- Note: Failure expected after each fx3_model iteration since we lose
|
||||
-- sample continuity when fifo writer is disabled.
|
||||
look_for_dropped_rx_samples: process(fx3_pclk_pll)
|
||||
variable rx_val : integer;
|
||||
variable gpif_buffer_idx : integer range 0 to 2 := 0;
|
||||
variable buf_sc12q11 : std_logic_vector(3*fx3_gpif.gpif_out'length-1 downto 0) := (others => '0');
|
||||
begin
|
||||
-- Init rx_val
|
||||
if sys_rst = '1' then
|
||||
rx_val := 16#172# when ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1 else 16#B9#;
|
||||
end if;
|
||||
|
||||
if (rising_edge(fx3_pclk_pll)
|
||||
and fx3_gpif.gpif_oe = '1'
|
||||
and fx3_control.rx_enable = '1') then
|
||||
|
||||
-- Shift in the new samples
|
||||
buf_sc12q11 := fx3_gpif.gpif_out & buf_sc12q11(buf_sc12q11'length-1 downto fx3_gpif.gpif_out'length);
|
||||
|
||||
-- Checks the 4 sample buffer every 3 pclk cycles
|
||||
if gpif_buffer_idx = 2 then
|
||||
for i in 0 to 3 loop
|
||||
assert(signed(buf_sc12q11(11+24*i downto 24*i))) = to_signed(rx_val, 12)
|
||||
report "I expected: " & integer'image(rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(11+24*i downto 24*i))))
|
||||
severity failure;
|
||||
assert(signed(buf_sc12q11(23+24*i downto 12+24*i))) = to_signed(-1*rx_val, 12)
|
||||
report "Q expected: " & integer'image(-1*rx_val) & ", Actual: " & integer'image(to_integer(signed(buf_sc12q11(23+24*i downto 12+24*i))))
|
||||
severity failure;
|
||||
rx_val := (rx_val + 1) mod 2048;
|
||||
end loop;
|
||||
end if;
|
||||
|
||||
gpif_buffer_idx := (gpif_buffer_idx + 1) mod 3;
|
||||
end if;
|
||||
end process look_for_dropped_rx_samples;
|
||||
|
||||
look_for_dropped_tx_samples: process(tx_clock)
|
||||
variable tx_val : integer := 0;
|
||||
variable message_count : integer := 1;
|
||||
variable q_expected : integer := 0;
|
||||
variable valid_tx_count : integer := 0;
|
||||
begin
|
||||
if rising_edge(tx_clock) then
|
||||
for i in dac_controls'range loop
|
||||
if dac_streams(i).data_v = '1' then
|
||||
q_expected := tx_val+1 when fx3_control.highly_packed_mode = '1'
|
||||
else to_integer(to_signed(message_count,8) & to_signed(tx_val+1, 8));
|
||||
|
||||
assert(dac_streams(i).data_i = to_signed(tx_val, 16))
|
||||
report "TX("&integer'image(i)&") I expected: " & integer'image(tx_val) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_i)))
|
||||
severity failure;
|
||||
assert(dac_streams(i).data_q = q_expected)
|
||||
report "TX("&integer'image(i)&") Q expected: " & integer'image(q_expected) & ", Actual: " & integer'image(to_integer(signed(dac_streams(i).data_q)))
|
||||
severity failure;
|
||||
|
||||
-- A new message is received every 2048 samples
|
||||
valid_tx_count := valid_tx_count + 1;
|
||||
if valid_tx_count mod 2048 = 0 then
|
||||
message_count := message_count + 1;
|
||||
end if;
|
||||
|
||||
tx_val := (tx_val + 2) when tx_val < 2046 else -2048;
|
||||
end if;
|
||||
end loop;
|
||||
end if;
|
||||
end process look_for_dropped_tx_samples;
|
||||
|
||||
end architecture;
|
||||
|
|
@ -32,6 +32,7 @@ library nuand;
|
|||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity fx3_gpif_iq_tb is
|
||||
generic (
|
||||
|
|
@ -638,6 +639,7 @@ begin
|
|||
look_for_dropped_tx_samples : process(tx_clock) is
|
||||
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
|
||||
variable current_message_count : natural := 1;
|
||||
variable valid_sample_count : natural := 0;
|
||||
variable iq_value : signed (15 downto 0) := x"0000";
|
||||
variable expected_sample_q : signed (15 downto 0);
|
||||
variable expected_sample_i : signed (15 downto 0);
|
||||
|
|
@ -648,6 +650,7 @@ begin
|
|||
and dac_streams(i).data_v = '1'
|
||||
and fx3_control.tx_enable = '1' )
|
||||
then
|
||||
valid_sample_count := valid_sample_count + 1;
|
||||
expected_sample_i := iq_value;
|
||||
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
|
||||
|
||||
|
|
@ -662,7 +665,7 @@ begin
|
|||
|
||||
-- Set iq values based on blocks received
|
||||
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
|
||||
if( iq_value = x"03FE" ) then
|
||||
if( valid_sample_count mod GPIF_BUF_SIZE_SS = 0 ) then
|
||||
iq_value := x"0000";
|
||||
if( current_message_count < MESSAGES_PER_ITERATION ) then
|
||||
current_message_count := current_message_count + 1;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ library nuand;
|
|||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity fx3_gpif_meta_8bit_tb is
|
||||
generic (
|
||||
|
|
@ -696,7 +697,8 @@ begin
|
|||
look_for_dropped_tx_samples : process(tx_clock) is
|
||||
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
|
||||
constant SIGMA_DELTA_BITS : signed (3 downto 0) := "0000";
|
||||
variable dac_stream_back_to_0 : natural := 0;
|
||||
constant HEADER_LEN : natural := 4; -- In clk cycles
|
||||
variable valid_sample_count : natural := 0;
|
||||
variable current_message_count : natural := 1;
|
||||
variable iq_value : signed (15 downto 0) := x"0000";
|
||||
variable expected_sample_i : signed (15 downto 0);
|
||||
|
|
@ -709,6 +711,7 @@ begin
|
|||
and dac_streams(i).data_v = '1'
|
||||
and fx3_control.tx_enable = '1' )
|
||||
then
|
||||
valid_sample_count := valid_sample_count + 1;
|
||||
if( EIGHT_BIT_MODE_EN = '1' ) then
|
||||
expected_sample_i := iq_value (11 downto 0) & SIGMA_DELTA_BITS;
|
||||
expected_sample_q := iq_value (11 downto 0) + 1 & SIGMA_DELTA_BITS;
|
||||
|
|
@ -729,9 +732,16 @@ begin
|
|||
end if;
|
||||
end if;
|
||||
|
||||
dac_stream_back_to_0 := dac_stream_back_to_0 + 1 when iq_value = 0;
|
||||
iq_value := (iq_value + 2) mod 128 when dac_stream_back_to_0 mod 16 /= 0 else
|
||||
(iq_value + 2) mod 112;
|
||||
if( valid_sample_count mod (2*GPIF_BUF_SIZE_SS - 8) = 0 ) then
|
||||
iq_value := x"0000";
|
||||
if( current_message_count < MESSAGES_PER_ITERATION ) then
|
||||
current_message_count := current_message_count + 1;
|
||||
else
|
||||
current_message_count := 1;
|
||||
end if;
|
||||
else
|
||||
iq_value := (iq_value + 2) mod 128;
|
||||
end if;
|
||||
else
|
||||
expected_sample_i := iq_value;
|
||||
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
|
||||
|
|
@ -747,7 +757,7 @@ begin
|
|||
|
||||
-- Set iq values based on blocks received
|
||||
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
|
||||
if( iq_value = x"03F6" ) then
|
||||
if( valid_sample_count mod (GPIF_BUF_SIZE_SS - HEADER_LEN) = 0 ) then
|
||||
iq_value := x"0000";
|
||||
if( current_message_count < MESSAGES_PER_ITERATION ) then
|
||||
current_message_count := current_message_count + 1;
|
||||
|
|
@ -910,11 +920,11 @@ begin
|
|||
|
||||
-- Allows a 0 increment for the first ts assertion
|
||||
if( ENABLE_CHANNEL_0 = '1' and ENABLE_CHANNEL_1 = '1') then
|
||||
ts_increment := 254 when EIGHT_BIT_MODE_EN = '0'
|
||||
else 508;
|
||||
ts_increment := (GPIF_BUF_SIZE_SS-4)/2 when EIGHT_BIT_MODE_EN = '0'
|
||||
else (GPIF_BUF_SIZE_SS-4);
|
||||
else
|
||||
ts_increment := 508 when EIGHT_BIT_MODE_EN = '0'
|
||||
else 1016;
|
||||
ts_increment := (GPIF_BUF_SIZE_SS -4) when EIGHT_BIT_MODE_EN = '0'
|
||||
else 2*(GPIF_BUF_SIZE_SS -4);
|
||||
end if;
|
||||
|
||||
iteration := iteration + 1;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ library nuand;
|
|||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity fx3_gpif_meta_tb is
|
||||
generic (
|
||||
|
|
@ -683,8 +684,10 @@ begin
|
|||
end process tx_sample_start_check;
|
||||
|
||||
look_for_dropped_tx_samples : process(tx_clock) is
|
||||
constant HEADER_LEN : integer := 4; -- In clk cycles
|
||||
constant MESSAGES_PER_ITERATION : natural := 3; --Provided in fx3_model
|
||||
variable current_message_count : natural := 1;
|
||||
variable valid_sample_count : natural := 0;
|
||||
variable iq_value : signed (15 downto 0) := x"0000";
|
||||
variable expected_sample_q : signed (15 downto 0);
|
||||
variable expected_sample_i : signed (15 downto 0);
|
||||
|
|
@ -695,6 +698,7 @@ begin
|
|||
and dac_streams(i).data_v = '1'
|
||||
and fx3_control.tx_enable = '1' )
|
||||
then
|
||||
valid_sample_count := valid_sample_count + 1;
|
||||
expected_sample_i := iq_value;
|
||||
expected_sample_q := to_signed(current_message_count, 8) & (iq_value(7 downto 0) + 1);
|
||||
|
||||
|
|
@ -709,7 +713,7 @@ begin
|
|||
|
||||
-- Set iq values based on blocks received
|
||||
-- See tx_sample_stream's encoding scheme in fx3_model.vhd
|
||||
if( iq_value = x"03F6" ) then
|
||||
if( valid_sample_count mod (GPIF_BUF_SIZE_SS-HEADER_LEN) = 0 ) then
|
||||
iq_value := x"0000";
|
||||
if( current_message_count < MESSAGES_PER_ITERATION ) then
|
||||
current_message_count := current_message_count + 1;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ library ieee;
|
|||
|
||||
library work;
|
||||
use work.util.all;
|
||||
use work.fx3_gpif_p.all;
|
||||
|
||||
architecture micro_dma of fx3_model is
|
||||
|
||||
|
|
@ -57,6 +58,32 @@ architecture micro_dma of fx3_model is
|
|||
signal rx_data : std_logic_vector(31 downto 0);
|
||||
signal tx_data : std_logic_vector(31 downto 0);
|
||||
|
||||
-- Generates packed samples
|
||||
-- The host will pack SC16Q11 samples into an SC12Q11 format. Every 3 gpif_in
|
||||
-- cycles contain 4 SC12Q11 IQ pairs.
|
||||
--
|
||||
-- Packing order:
|
||||
-- Buffer 1: [--Sample1(8)--|----------Sample0(24)----------]
|
||||
-- Buffer 2: [------Sample2(16)------|------Sample1(16)-----]
|
||||
-- Buffer 3: [----------Sample3(24)----------|--Sample2(8)--]
|
||||
function data_gen_packed(cycle : natural) return std_logic_vector is
|
||||
variable four_sample_buffer : std_logic_vector(95 downto 0) := (others => '0');
|
||||
variable buffer_offset : integer := 0;
|
||||
variable sample_value_ref : integer := 0;
|
||||
variable I : std_logic_vector(11 downto 0) := (others => '0');
|
||||
variable Q : std_logic_vector(11 downto 0) := (others => '0');
|
||||
begin
|
||||
sample_value_ref := cycle / 3;
|
||||
for j in 0 to 3 loop
|
||||
Q := std_logic_vector(to_signed(8*sample_value_ref+2*j+1, 12));
|
||||
I := std_logic_vector(to_signed(8*sample_value_ref+2*j, 12));
|
||||
four_sample_buffer := Q & I & four_sample_buffer(95 downto 24);
|
||||
end loop;
|
||||
|
||||
buffer_offset := (cycle mod 3) * 32;
|
||||
return four_sample_buffer(31+buffer_offset downto buffer_offset);
|
||||
end function data_gen_packed;
|
||||
|
||||
impure function data_gen (count : natural) return std_logic_vector is
|
||||
variable eight_bit_msw_i : std_logic_vector(7 downto 0);
|
||||
variable eight_bit_msw_q : std_logic_vector(7 downto 0);
|
||||
|
|
@ -98,7 +125,7 @@ begin
|
|||
done <= rx_done and tx_done;
|
||||
|
||||
rx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable req_time : time;
|
||||
begin
|
||||
|
|
@ -151,9 +178,10 @@ begin
|
|||
end process;
|
||||
|
||||
tx_sample_stream : process
|
||||
constant TIME_BETWEEN_ITERATIONS : natural := 4593;
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant TIME_BETWEEN_ITERATIONS : natural := 7000;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable cycle : natural := 0;
|
||||
variable timestamp_cntr : natural := 400;
|
||||
variable header_len : natural := 0;
|
||||
variable data_out : std_logic_vector(31 downto 0);
|
||||
|
|
@ -223,7 +251,11 @@ begin
|
|||
for i in 1 to (BLOCK_SIZE - header_len) loop
|
||||
gpif_state_tx <= TX_SAMPLES;
|
||||
data_out := data_gen(count);
|
||||
if( eight_bit_mode_en = '1' ) then
|
||||
if packed_mode_en = '1' then
|
||||
data_out := data_gen_packed(cycle);
|
||||
end if;
|
||||
|
||||
if( eight_bit_mode_en = '1' or packed_mode_en = '1' ) then
|
||||
fx3_gpif <= data_out;
|
||||
tx_data <= data_out;
|
||||
else
|
||||
|
|
@ -232,6 +264,7 @@ begin
|
|||
end if;
|
||||
wait until rising_edge( fx3_pclk );
|
||||
|
||||
cycle := cycle + 1;
|
||||
count := (count + 4) mod 128 when eight_bit_mode_en = '1' else
|
||||
(count + 2) mod 2048;
|
||||
gpif_state_tx <= IDLE;
|
||||
|
|
@ -242,7 +275,7 @@ begin
|
|||
nop(fx3_pclk, 10);
|
||||
end loop;
|
||||
|
||||
wait for 1 ms;
|
||||
wait for 1.5 ms;
|
||||
dma_tx_enable <= '0';
|
||||
wait for 10 us;
|
||||
end loop;
|
||||
|
|
@ -333,7 +366,7 @@ begin
|
|||
done <= rx_done and tx_done;
|
||||
|
||||
rx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable req_time : time;
|
||||
begin
|
||||
|
|
@ -387,7 +420,7 @@ begin
|
|||
|
||||
tx_sample_stream : process
|
||||
constant TIME_BETWEEN_ITERATIONS : natural := 4556;
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable timestamp_cntr : natural := 250;
|
||||
variable header_len : natural := 0;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,280 @@
|
|||
-- Copyright (c) 2024 Nuand LLC
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
-- of this software and associated documentation files (the "Software"), to deal
|
||||
-- in the Software without restriction, including without limitation the rights
|
||||
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
-- copies of the Software, and to permit persons to whom the Software is
|
||||
-- furnished to do so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in
|
||||
-- all copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
-- THE SOFTWARE.
|
||||
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
use ieee.math_real.all;
|
||||
use ieee.math_complex.all;
|
||||
|
||||
library work;
|
||||
use work.util.all;
|
||||
use work.fx3_gpif_p.all;
|
||||
|
||||
architecture micro_dma_fifo_stress of fx3_model is
|
||||
|
||||
constant PCLK_HALF_PERIOD : time := 1 sec * (1.0/100.0e6/2.0);
|
||||
constant START_COUNT : natural := 32;
|
||||
constant BLOCKS_PER_ITERATION : natural := 7;
|
||||
constant ITERATIONS : natural := 4;
|
||||
|
||||
-- Control mapping
|
||||
alias dma0_rx_ack is fx3_ctl( 0);
|
||||
alias dma1_rx_ack is fx3_ctl( 1);
|
||||
alias dma2_tx_ack is fx3_ctl( 2);
|
||||
alias dma3_tx_ack is fx3_ctl( 3);
|
||||
alias dma_rx_enable is fx3_ctl( 4);
|
||||
alias dma_tx_enable is fx3_ctl( 5);
|
||||
alias dma_idle is fx3_ctl( 6);
|
||||
alias system_reset is fx3_ctl( 7);
|
||||
alias dma0_rx_reqx is fx3_ctl( 8);
|
||||
alias dma1_rx_reqx is fx3_ctl(12); -- due to 9 being connected to dclk
|
||||
alias dma2_tx_reqx is fx3_ctl(10);
|
||||
alias dma3_tx_reqx is fx3_ctl(11);
|
||||
|
||||
type gpif_state_t is (IDLE, TX_META, TX_SAMPLES, RX_SAMPLES);
|
||||
signal gpif_state_rx, gpif_state_tx : gpif_state_t;
|
||||
|
||||
signal rx_done : boolean := false;
|
||||
signal tx_done : boolean := false;
|
||||
|
||||
signal rx_data : std_logic_vector(31 downto 0);
|
||||
signal tx_data : std_logic_vector(31 downto 0);
|
||||
|
||||
impure function data_gen (count : natural) return std_logic_vector is
|
||||
variable eight_bit_msw_i : std_logic_vector(7 downto 0);
|
||||
variable eight_bit_msw_q : std_logic_vector(7 downto 0);
|
||||
variable eight_bit_lsw_i : std_logic_vector(7 downto 0);
|
||||
variable eight_bit_lsw_q : std_logic_vector(7 downto 0);
|
||||
variable msw, lsw : std_logic_vector(15 downto 0);
|
||||
begin
|
||||
if( eight_bit_mode_en = '1' ) then
|
||||
eight_bit_lsw_i := std_logic_vector(to_unsigned(count, 8));
|
||||
eight_bit_lsw_q := std_logic_vector(to_unsigned(count+1, 8));
|
||||
eight_bit_msw_i := std_logic_vector(to_unsigned(count+2, 8));
|
||||
eight_bit_msw_q := std_logic_vector(to_unsigned(count+3, 8));
|
||||
lsw := eight_bit_lsw_q & eight_bit_lsw_i;
|
||||
msw := eight_bit_msw_q & eight_bit_msw_i;
|
||||
else
|
||||
msw := std_logic_vector(to_signed(count+1, 16));
|
||||
lsw := std_logic_vector(to_signed(count, 16));
|
||||
end if;
|
||||
|
||||
return (msw & lsw);
|
||||
end function data_gen;
|
||||
|
||||
impure function data_check (count : natural ; rxdata : std_logic_vector(31 downto 0)) return boolean is
|
||||
begin
|
||||
return (rxdata = data_gen(count));
|
||||
end function data_check;
|
||||
|
||||
begin
|
||||
|
||||
-- DCLK which isn't used
|
||||
fx3_ctl(9) <= '0';
|
||||
|
||||
fx3_ctl(3 downto 0) <= (others => 'Z');
|
||||
|
||||
-- Create a 100MHz clock output
|
||||
fx3_pclk <= not fx3_pclk after PCLK_HALF_PERIOD when (not rx_done or not tx_done) else '0';
|
||||
|
||||
-- Doneness
|
||||
done <= rx_done and tx_done;
|
||||
|
||||
rx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable req_time : time;
|
||||
begin
|
||||
gpif_state_rx <= IDLE;
|
||||
dma0_rx_reqx <= '1';
|
||||
dma1_rx_reqx <= '1';
|
||||
dma_rx_enable <= '0';
|
||||
rx_data <= (others => 'U');
|
||||
|
||||
wait until rising_edge(fx3_pclk) and system_reset = '0';
|
||||
|
||||
nop(fx3_pclk, 1000);
|
||||
|
||||
wait until rising_edge(fx3_pclk) and fx3_rx_en = '1';
|
||||
|
||||
wait for 30 us;
|
||||
|
||||
for j in 1 to ITERATIONS loop
|
||||
dma_rx_enable <= '1';
|
||||
|
||||
for i in 1 to BLOCKS_PER_ITERATION loop
|
||||
dma0_rx_reqx <= '0';
|
||||
req_time := now;
|
||||
wait until rising_edge( fx3_pclk ) and dma0_rx_ack = '1';
|
||||
wait until rising_edge( fx3_pclk );
|
||||
dma0_rx_reqx <= '1';
|
||||
|
||||
report "RX iteration " & to_string(j) & " block " & to_string(i) & " delay " & to_string(now - req_time);
|
||||
|
||||
for i in 1 to BLOCK_SIZE loop
|
||||
gpif_state_rx <= RX_SAMPLES;
|
||||
rx_data <= fx3_gpif;
|
||||
wait until rising_edge( fx3_pclk );
|
||||
|
||||
--assert data_check(count, rx_data) severity failure;
|
||||
|
||||
count := (count + 1) mod 2048;
|
||||
gpif_state_rx <= IDLE;
|
||||
rx_data <= (others => 'X');
|
||||
end loop;
|
||||
end loop;
|
||||
|
||||
dma_rx_enable <= '0';
|
||||
wait for 10 us;
|
||||
end loop;
|
||||
|
||||
report "Done with RX sample stream";
|
||||
rx_done <= true;
|
||||
wait;
|
||||
end process;
|
||||
|
||||
tx_sample_stream : process
|
||||
constant TIME_BETWEEN_ITERATIONS : natural := 4593;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable timestamp_cntr : natural := 400;
|
||||
variable header_len : natural := 0;
|
||||
variable data_out : std_logic_vector(31 downto 0);
|
||||
variable req_time : time;
|
||||
begin
|
||||
gpif_state_tx <= IDLE;
|
||||
dma2_tx_reqx <= '1';
|
||||
dma3_tx_reqx <= '1';
|
||||
dma_tx_enable <= '0';
|
||||
fx3_gpif <= (others =>'Z');
|
||||
|
||||
wait until rising_edge(fx3_pclk) and system_reset = '0';
|
||||
|
||||
nop(fx3_pclk, 1000);
|
||||
|
||||
wait until rising_edge(fx3_pclk) and fx3_tx_en = '1';
|
||||
|
||||
wait for 30 us;
|
||||
|
||||
for k in 1 to ITERATIONS loop
|
||||
dma_tx_enable <= '1';
|
||||
|
||||
for fifo_stress_idx in 1 to 3 loop
|
||||
for j in 1 to BLOCKS_PER_ITERATION loop
|
||||
header_len := 0;
|
||||
dma3_tx_reqx <= '0';
|
||||
req_time := now;
|
||||
wait until rising_edge( fx3_pclk ) and dma3_tx_ack = '1';
|
||||
wait until rising_edge( fx3_pclk );
|
||||
wait until rising_edge( fx3_pclk );
|
||||
wait until rising_edge( fx3_pclk );
|
||||
dma3_tx_reqx <= '1';
|
||||
|
||||
report "TX iteration " & to_string(k) & " block " & to_string(j) & " delay " & to_string(now - req_time);
|
||||
|
||||
|
||||
if( fx3_tx_meta_en = '1') then
|
||||
header_len := 4;
|
||||
|
||||
for i in 1 to 4 loop
|
||||
case (i) is
|
||||
when 1 =>
|
||||
data_out := x"00000000";
|
||||
when 2 =>
|
||||
data_out(31 downto 0) := std_logic_vector(to_signed(timestamp_cntr, 32));
|
||||
if (j = BLOCKS_PER_ITERATION) then
|
||||
timestamp_cntr := timestamp_cntr + TIME_BETWEEN_ITERATIONS;
|
||||
else
|
||||
timestamp_cntr := timestamp_cntr + 254;
|
||||
end if;
|
||||
when 3 =>
|
||||
data_out := (others => '0');
|
||||
when 4 =>
|
||||
data_out := (others => '1');
|
||||
end case;
|
||||
|
||||
gpif_state_tx <= TX_META;
|
||||
fx3_gpif <= data_out;
|
||||
tx_data <= data_out;
|
||||
wait until rising_edge( fx3_pclk );
|
||||
|
||||
gpif_state_tx <= IDLE;
|
||||
tx_data <= (others => 'X');
|
||||
end loop;
|
||||
end if;
|
||||
count := 0;
|
||||
|
||||
for i in 1 to (BLOCK_SIZE - header_len) loop
|
||||
gpif_state_tx <= TX_SAMPLES;
|
||||
data_out := data_gen(count);
|
||||
if( eight_bit_mode_en = '1' ) then
|
||||
fx3_gpif <= data_out;
|
||||
tx_data <= data_out;
|
||||
else
|
||||
fx3_gpif <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0);
|
||||
tx_data <= std_logic_vector(to_unsigned(j, 8)) & data_out(23 downto 0);
|
||||
end if;
|
||||
wait until rising_edge( fx3_pclk );
|
||||
|
||||
count := (count + 4) mod 128 when eight_bit_mode_en = '1' else
|
||||
(count + 2) mod 2048;
|
||||
gpif_state_tx <= IDLE;
|
||||
tx_data <= (others => 'X');
|
||||
end loop;
|
||||
|
||||
fx3_gpif <= (others =>'Z');
|
||||
nop(fx3_pclk, 10);
|
||||
end loop;
|
||||
wait for 10 us;
|
||||
end loop;
|
||||
|
||||
wait for 2 ms;
|
||||
dma_tx_enable <= '0';
|
||||
wait for 10 us;
|
||||
end loop;
|
||||
|
||||
report "Done with TX sample stream";
|
||||
tx_done <= true;
|
||||
wait;
|
||||
end process;
|
||||
|
||||
reset_system : process
|
||||
begin
|
||||
system_reset <= '1';
|
||||
dma_idle <= '0';
|
||||
nop( fx3_pclk, 100 );
|
||||
system_reset <= '0';
|
||||
nop( fx3_pclk, 10 );
|
||||
dma_idle <= '1';
|
||||
wait;
|
||||
end process;
|
||||
|
||||
-- TODO: UART Interface
|
||||
fx3_uart_txd <= '1';
|
||||
fx3_uart_cts <= '1';
|
||||
|
||||
assert (gpif_state_tx = IDLE and gpif_state_rx /= IDLE)
|
||||
or (gpif_state_rx = IDLE and gpif_state_tx /= IDLE)
|
||||
or (gpif_state_rx = IDLE and gpif_state_tx = IDLE)
|
||||
report "gpif_state_rx and gpif_state_tx cannot both be non-idle"
|
||||
severity failure;
|
||||
|
||||
end architecture micro_dma_fifo_stress;
|
||||
|
|
@ -32,6 +32,7 @@ library nuand;
|
|||
use nuand.fifo_readwrite_p.all;
|
||||
use nuand.common_dcfifo_p.all;
|
||||
use nuand.bladerf_p.all;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity rx_timestamp_tb is
|
||||
generic (
|
||||
|
|
@ -618,7 +619,8 @@ begin
|
|||
-- variable timestamp : unsigned(63 downto 0) := (others => '0');
|
||||
begin
|
||||
wait for 1 ns;
|
||||
delta_expected := to_unsigned(508, 64) when not EIGHT_BIT_MODE_EN else to_unsigned(1016, 64);
|
||||
delta_expected := to_unsigned(GPIF_BUF_SIZE_SS-HEADER_LEN, 64) when not EIGHT_BIT_MODE_EN
|
||||
else to_unsigned(2*(GPIF_BUF_SIZE_SS-HEADER_LEN), 64);
|
||||
|
||||
if (ENABLE_CHANNEL_0 and ENABLE_CHANNEL_1) then
|
||||
delta_expected := delta_expected/2;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ library ieee;
|
|||
|
||||
library work;
|
||||
use work.util.all;
|
||||
use work.fx3_gpif_p.all;
|
||||
|
||||
architecture wlan_micro_packet_dma of fx3_model is
|
||||
|
||||
|
|
@ -108,7 +109,7 @@ begin
|
|||
done <= rx_done and tx_done;
|
||||
|
||||
rx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable req_time : time;
|
||||
begin
|
||||
|
|
@ -161,7 +162,7 @@ begin
|
|||
end process;
|
||||
|
||||
tx_sample_stream : process
|
||||
constant BLOCK_SIZE : natural := 512;
|
||||
constant BLOCK_SIZE : natural := GPIF_BUF_SIZE_SS;
|
||||
variable count : natural := START_COUNT;
|
||||
variable timestamp_cntr : natural := 100;
|
||||
variable header_len : natural := 0;
|
||||
|
|
|
|||
|
|
@ -47,8 +47,9 @@ entity tx is
|
|||
trigger_master : in std_logic;
|
||||
trigger_line : inout std_logic; -- this is not good, should be in/out/oe
|
||||
|
||||
-- 8-bit mode
|
||||
eight_bit_mode_en : in std_logic := '0';
|
||||
-- Packing modes
|
||||
eight_bit_mode_en : in std_logic := '0';
|
||||
highly_packed_mode_en : in std_logic := '0';
|
||||
|
||||
-- Packet from host via FX3
|
||||
packet_en : in std_logic;
|
||||
|
|
@ -218,6 +219,7 @@ begin
|
|||
timestamp => tx_timestamp,
|
||||
|
||||
eight_bit_mode_en => eight_bit_mode_en,
|
||||
highly_packed_mode_en => highly_packed_mode_en,
|
||||
|
||||
fifo_empty => sample_fifo.rempty,
|
||||
fifo_usedw => sample_fifo.rused,
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn
|
|||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/fifo_writer.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/lms6002d.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-adsb.vhd]]
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn
|
|||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/fifo_writer.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/lms6002d.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-atsc_tx.vhd]]
|
||||
set_global_assignment -name QIP_FILE [file normalize nios_system/synthesis/nios_system.qip]
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip syn
|
|||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/lms6002d/vhdl/bladerf_agc.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip trigger/trigger.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/set_clear_ff.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif_p.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $common_dir vhdl/fx3_gpif.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $nuand_ip synthesis/rx_packet_generator.vhd]]
|
||||
set_global_assignment -name VHDL_FILE [file normalize [file join $here vhdl/bladerf-hosted.vhd]]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ vcom -work nuand -2008 ../../../ip/altera/rx_meta_fifo/rx_meta_fifo.vhd
|
|||
|
||||
vcom -work nuand -2008 ../vhdl/tb/nios_system.vhd
|
||||
|
||||
vcom -work nuand -2008 ../vhdl/fx3_gpif_p.vhd
|
||||
vcom -work nuand -2008 ../vhdl/fx3_gpif.vhd
|
||||
|
||||
vcom -work nuand -2008 ../vhdl/bladerf.vhd
|
||||
|
|
|
|||
|
|
@ -769,6 +769,7 @@ begin
|
|||
meta_en => meta_en_rx,
|
||||
packet_en => packet_en_rx,
|
||||
eight_bit_mode_en => '0',
|
||||
highly_packed_mode_en => '0',
|
||||
timestamp => rx_timestamp,
|
||||
mini_exp => mini_exp2 & mini_exp1,
|
||||
|
||||
|
|
@ -919,6 +920,7 @@ begin
|
|||
meta_en => meta_en_tx,
|
||||
packet_en => packet_en_tx,
|
||||
eight_bit_mode_en => '0',
|
||||
highly_packed_mode_en => '0',
|
||||
timestamp => tx_timestamp,
|
||||
|
||||
fifo_empty => tx_sample_fifo.rempty,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ library ieee;
|
|||
use ieee.std_logic_1164.all;
|
||||
use ieee.numeric_std.all;
|
||||
|
||||
library nuand;
|
||||
use nuand.fx3_gpif_p.all;
|
||||
|
||||
entity fx3_gpif is
|
||||
port (
|
||||
-- FX3 control signals
|
||||
|
|
@ -117,10 +120,6 @@ architecture sample_shuffler of fx3_gpif is
|
|||
constant META_DOWNCOUNT_RESET : natural := 4;
|
||||
constant FINI_DOWNCOUNT_RESET : natural := 10;
|
||||
|
||||
-- GPIF buf sizes for USB high-speed and super-speed
|
||||
constant GPIF_BUF_SIZE_HS : natural := 256;
|
||||
constant GPIF_BUF_SIZE_SS : natural := 512;
|
||||
|
||||
type dma_handshake_t is record
|
||||
rx0 : std_logic;
|
||||
rx1 : std_logic;
|
||||
|
|
@ -280,7 +279,7 @@ begin
|
|||
-- Can we not fit one more block of data in RX buffer?
|
||||
rx_fifo_critical <= (unsigned(rx_fifo_usedw) >= ((2**(rx_fifo_usedw'length-1) - gpif_buf_size)));
|
||||
-- Do we have room for one more block of data in the TX buffer?
|
||||
tx_fifo_enough <= (unsigned(tx_fifo_usedw) < ((2**(tx_fifo_usedw'length-1) - gpif_buf_size * 4))) and
|
||||
tx_fifo_enough <= (unsigned(tx_fifo_usedw) < ((2**(tx_fifo_usedw'length) - gpif_buf_size))) and
|
||||
(unsigned(tx_meta_fifo_usedw) < ((2**(tx_meta_fifo_usedw'length-1) - 4)));
|
||||
end if;
|
||||
end process calculate_fifo_waterlines;
|
||||
|
|
|
|||
27
hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd
Normal file
27
hdl/fpga/platforms/common/bladerf/vhdl/fx3_gpif_p.vhd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
-- Copyright (c) 2024 Nuand LLC
|
||||
--
|
||||
-- Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
-- of this software and associated documentation files (the "Software"), to deal
|
||||
-- in the Software without restriction, including without limitation the rights
|
||||
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
-- copies of the Software, and to permit persons to whom the Software is
|
||||
-- furnished to do so, subject to the following conditions:
|
||||
--
|
||||
-- The above copyright notice and this permission notice shall be included in
|
||||
-- all copies or substantial portions of the Software.
|
||||
--
|
||||
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
-- THE SOFTWARE.
|
||||
library ieee;
|
||||
use ieee.std_logic_1164.all;
|
||||
|
||||
package fx3_gpif_p is
|
||||
-- GPIF buf sizes for USB high-speed and super-speed
|
||||
constant GPIF_BUF_SIZE_HS : natural := 1024;
|
||||
constant GPIF_BUF_SIZE_SS : natural := 2048;
|
||||
end package fx3_gpif_p;
|
||||
|
|
@ -462,6 +462,18 @@ if [[ ${flow} == "full" ]]; then
|
|||
sha256sum $RBF > $RBF.sha256sum
|
||||
MD5SUM=$(cat $RBF.md5sum | awk '{ print $1 }')
|
||||
SHA256SUM=$(cat $RBF.sha256sum | awk '{ print $1 }')
|
||||
|
||||
GIT_HASH=$(git rev-parse --short HEAD)
|
||||
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
GIT_DIRTY=$(git diff --quiet && echo "clean" || echo "dirty")
|
||||
|
||||
cat << EOF > git_info.txt
|
||||
Git Information:
|
||||
Commit Hash: $GIT_HASH
|
||||
Branch: $GIT_BRANCH
|
||||
Working Directory: $GIT_DIRTY
|
||||
EOF
|
||||
|
||||
popd
|
||||
|
||||
echo ""
|
||||
|
|
@ -473,6 +485,10 @@ if [[ ${flow} == "full" ]]; then
|
|||
echo " MD5: $MD5SUM"
|
||||
echo " SHA256: $SHA256SUM"
|
||||
echo ""
|
||||
echo " Git Information:"
|
||||
echo " Commit: $GIT_HASH ($GIT_DIRTY)"
|
||||
echo " Branch: $GIT_BRANCH"
|
||||
echo ""
|
||||
cat "$BUILD_OUTPUT_DIR/$BUILD_NAME.fit.summary" | sed -e 's/^\(.\)/ \1/g'
|
||||
echo "##########################################################################"
|
||||
fi
|
||||
|
|
|
|||
1
host/examples/bladeRF-cli/sc16q11-packed-mimo/.gitignore
vendored
Normal file
1
host/examples/bladeRF-cli/sc16q11-packed-mimo/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
tx_samples.csv
|
||||
25
host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md
Normal file
25
host/examples/bladeRF-cli/sc16q11-packed-mimo/README.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# BladeRF CLI RX MIMO Packed
|
||||
|
||||
This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before running this example, ensure the Python environment is initialized and install the dependencies:
|
||||
|
||||
```bash
|
||||
python3 -m venv env
|
||||
source env/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
To run the example, execute the following command:
|
||||
|
||||
```bash
|
||||
./run.sh
|
||||
```
|
||||
|
||||
This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file.
|
||||
|
||||
The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection.
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import csv
|
||||
import sys
|
||||
|
||||
def generate_csv_normal(filename):
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
|
||||
# Generate numbers from 0 to 2047
|
||||
for i in range(0, 2048, 4):
|
||||
writer.writerow([i, i+1, i+2, i+3])
|
||||
|
||||
# Generate numbers from -2048 to -1
|
||||
for i in range(-2048, 0, 4):
|
||||
writer.writerow([i, i+1, i+2, i+3])
|
||||
|
||||
def generate_csv_cw(filename):
|
||||
cw_pattern = [
|
||||
[0, 2047],
|
||||
[2047, 0],
|
||||
[0, -2047],
|
||||
[-2047, 0]
|
||||
]
|
||||
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
for _ in range(2*4096):
|
||||
for sample in cw_pattern:
|
||||
# Duplicate the pattern for both channels
|
||||
writer.writerow(sample + sample)
|
||||
|
||||
if __name__ == "__main__":
|
||||
filename = 'tx_samples.csv'
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
|
||||
print("Usage: python generate_tx_samples.py [option]")
|
||||
print("Options:")
|
||||
print(" -h, --help Show this help message and exit")
|
||||
print(" cw Generate CSV file with CW pattern")
|
||||
print(" (no option) Generate CSV file with count pattern")
|
||||
sys.exit(0)
|
||||
elif sys.argv[1] == "cw":
|
||||
generate_csv_cw(filename)
|
||||
print(f"CSV file '{filename}' has been generated with CW pattern.")
|
||||
else:
|
||||
print(f"Unknown option: {sys.argv[1]}")
|
||||
print("Use -h or --help for usage information.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
generate_csv_normal(filename)
|
||||
print(f"CSV file '{filename}' has been generated with count pattern.")
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
contourpy==1.3.0
|
||||
cycler==0.12.1
|
||||
fonttools==4.54.1
|
||||
kiwisolver==1.4.7
|
||||
matplotlib==3.9.2
|
||||
numpy==2.1.1
|
||||
packaging==24.1
|
||||
pandas==2.2.3
|
||||
pillow==10.4.0
|
||||
pyparsing==3.1.4
|
||||
python-dateutil==2.9.0.post0
|
||||
pytz==2024.2
|
||||
six==1.16.0
|
||||
tzdata==2024.2
|
||||
3
host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh
Executable file
3
host/examples/bladeRF-cli/sc16q11-packed-mimo/run.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
set -e
|
||||
bladeRF-cli -s rx.txt
|
||||
python3 validate.py /tmp/data.csv
|
||||
8
host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt
Normal file
8
host/examples/bladeRF-cli/sc16q11-packed-mimo/rx.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set bitmode packed
|
||||
set rx_mux 12BIT_COUNTER
|
||||
# set frequency 915M
|
||||
set samplerate 61.44M
|
||||
rx config file=/tmp/data.csv format=csv n=40k channel=1,2
|
||||
# rx config file=/tmp/data.csv format=csv n=200k
|
||||
rx start
|
||||
rx wait
|
||||
6
host/examples/bladeRF-cli/sc16q11-packed-mimo/tx.txt
Normal file
6
host/examples/bladeRF-cli/sc16q11-packed-mimo/tx.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
set frequency 915M
|
||||
set samplerate 20M
|
||||
set bitmode packed
|
||||
tx config file=tx_samples.csv format=csv channel=1,2
|
||||
tx start
|
||||
tx wait
|
||||
100
host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py
Normal file
100
host/examples/bladeRF-cli/sc16q11-packed-mimo/validate.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import sys
|
||||
import ast
|
||||
|
||||
def import_data(file_path):
|
||||
try:
|
||||
# Read the CSV file without header
|
||||
df = pd.read_csv(file_path, header=None)
|
||||
|
||||
# Function to safely convert string representations of tuples to actual tuples
|
||||
def safe_eval(x):
|
||||
try:
|
||||
return ast.literal_eval(x)
|
||||
except:
|
||||
return x
|
||||
|
||||
# Apply safe_eval to all elements
|
||||
df = df.apply(lambda col: col.map(safe_eval))
|
||||
|
||||
# Rename columns based on the number of columns
|
||||
if df.shape[1] == 2:
|
||||
df.columns = ['I', 'Q']
|
||||
elif df.shape[1] == 4:
|
||||
df.columns = ['I1', 'Q1', 'I2', 'Q2']
|
||||
else:
|
||||
raise ValueError("CSV file must contain either two columns (single channel) or four columns (dual channel)")
|
||||
|
||||
# Extract numeric values from tuples if necessary
|
||||
for col in df.columns:
|
||||
if df[col].dtype == 'object':
|
||||
df[col] = df[col].apply(lambda x: x[0] if isinstance(x, (tuple, list)) else x)
|
||||
|
||||
# Convert to numeric, coercing errors to NaN
|
||||
df = df.apply(pd.to_numeric, errors='coerce')
|
||||
|
||||
# Drop any rows with NaN values
|
||||
df = df.dropna()
|
||||
|
||||
# Check if all columns are numeric
|
||||
for col in df.columns:
|
||||
if not pd.api.types.is_numeric_dtype(df[col]):
|
||||
raise ValueError(f"{col} samples must be numeric")
|
||||
|
||||
return df
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File '{file_path}' not found")
|
||||
sys.exit(1)
|
||||
except pd.errors.EmptyDataError:
|
||||
print(f"Error: File '{file_path}' is empty")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python validate.py <path_to_csv_file>")
|
||||
sys.exit(1)
|
||||
|
||||
file_path = sys.argv[1]
|
||||
df = import_data(file_path)
|
||||
|
||||
# Determine if it's single or dual channel
|
||||
is_dual_channel = 'I2' in df.columns
|
||||
|
||||
plt.figure(figsize=(12, 8))
|
||||
|
||||
if is_dual_channel:
|
||||
# Plot Channel 1
|
||||
plt.subplot(2, 1, 1)
|
||||
plt.plot(df.index, df['I1'], label='I (Ch1)', alpha=0.7)
|
||||
plt.plot(df.index, df['Q1'], label='Q (Ch1)', alpha=0.7)
|
||||
plt.ylabel('Amplitude (Ch1)')
|
||||
plt.title('I/Q Components Over Time - Channel 1')
|
||||
plt.legend(loc='upper right')
|
||||
plt.grid(True, alpha=0.3)
|
||||
|
||||
# Plot Channel 2
|
||||
plt.subplot(2, 1, 2)
|
||||
plt.plot(df.index, df['I2'], label='I (Ch2)', alpha=0.7)
|
||||
plt.plot(df.index, df['Q2'], label='Q (Ch2)', alpha=0.7)
|
||||
plt.xlabel('Sample Index')
|
||||
plt.ylabel('Amplitude (Ch2)')
|
||||
plt.title('I/Q Components Over Time - Channel 2')
|
||||
plt.legend(loc='upper right')
|
||||
plt.grid(True, alpha=0.3)
|
||||
else:
|
||||
# Plot Single Channel
|
||||
plt.plot(df.index, df['I'], label='I', alpha=0.7)
|
||||
plt.plot(df.index, df['Q'], label='Q', alpha=0.7)
|
||||
plt.xlabel('Sample Index')
|
||||
plt.ylabel('Amplitude')
|
||||
plt.title('I/Q Components Over Time - Single Channel')
|
||||
plt.legend(loc='upper right')
|
||||
plt.grid(True, alpha=0.3)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
1
host/examples/bladeRF-cli/sc16q11-packed-siso/.gitignore
vendored
Normal file
1
host/examples/bladeRF-cli/sc16q11-packed-siso/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
tx_samples.csv
|
||||
26
host/examples/bladeRF-cli/sc16q11-packed-siso/README.md
Normal file
26
host/examples/bladeRF-cli/sc16q11-packed-siso/README.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# BladeRF CLI RX SISO Packed
|
||||
|
||||
This example demonstrates how to configure and use the BladeRF CLI to aquire an RX stream of packed 16-bit samples.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before running this example, ensure the Python environment is initialized and install the dependencies:
|
||||
|
||||
```bash
|
||||
python3 -m venv env
|
||||
source env/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
To run the example, execute the following command:
|
||||
|
||||
```bash
|
||||
./run.sh
|
||||
```
|
||||
|
||||
This will execute the bladeRF-cli script that ingests samples from an internal 12b counter and writes them to a CSV file.
|
||||
|
||||
The Python script `validate.py` will then read the CSV file and plot the samples for visual inspection.
|
||||
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import csv
|
||||
import sys
|
||||
|
||||
def generate_csv_normal(filename):
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
|
||||
# Generate numbers from 0 to 2047
|
||||
for i in range(0, 2048, 2):
|
||||
writer.writerow([i, i+1])
|
||||
|
||||
# Generate numbers from -2048 to -1
|
||||
for i in range(-2048, 0, 2):
|
||||
writer.writerow([i, i+1])
|
||||
|
||||
def generate_csv_cw(filename):
|
||||
cw_pattern = [
|
||||
[0, 2047],
|
||||
[2047, 0],
|
||||
[0, -2047],
|
||||
[-2047, 0]
|
||||
]
|
||||
|
||||
with open(filename, 'w', newline='') as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
for _ in range(2*4096):
|
||||
for sample in cw_pattern:
|
||||
# Duplicate the pattern for both channels
|
||||
writer.writerow(sample)
|
||||
|
||||
if __name__ == "__main__":
|
||||
filename = 'tx_samples.csv'
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == "-h" or sys.argv[1] == "--help":
|
||||
print("Usage: python generate_tx_samples.py [option]")
|
||||
print("Options:")
|
||||
print(" -h, --help Show this help message and exit")
|
||||
print(" cw Generate CSV file with CW pattern")
|
||||
print(" (no option) Generate CSV file with count pattern")
|
||||
sys.exit(0)
|
||||
elif sys.argv[1] == "cw":
|
||||
generate_csv_cw(filename)
|
||||
print(f"CSV file '{filename}' has been generated with CW pattern.")
|
||||
else:
|
||||
print(f"Unknown option: {sys.argv[1]}")
|
||||
print("Use -h or --help for usage information.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
generate_csv_normal(filename)
|
||||
print(f"CSV file '{filename}' has been generated with count pattern.")
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
contourpy==1.3.0
|
||||
cycler==0.12.1
|
||||
fonttools==4.54.1
|
||||
kiwisolver==1.4.7
|
||||
matplotlib==3.9.2
|
||||
numpy==2.1.1
|
||||
packaging==24.1
|
||||
pandas==2.2.3
|
||||
pillow==10.4.0
|
||||
pyparsing==3.1.4
|
||||
python-dateutil==2.9.0.post0
|
||||
pytz==2024.2
|
||||
six==1.16.0
|
||||
tzdata==2024.2
|
||||
3
host/examples/bladeRF-cli/sc16q11-packed-siso/run.sh
Executable file
3
host/examples/bladeRF-cli/sc16q11-packed-siso/run.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
set -e
|
||||
bladeRF-cli -s rx.txt
|
||||
python3 validate.py /tmp/data.csv
|
||||
7
host/examples/bladeRF-cli/sc16q11-packed-siso/rx.txt
Normal file
7
host/examples/bladeRF-cli/sc16q11-packed-siso/rx.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
set frequency 915M
|
||||
set samplerate 20M
|
||||
set rx_mux 12BIT_COUNTER
|
||||
set bitmode packed
|
||||
rx config file=/tmp/data.csv format=csv n=200k
|
||||
rx start
|
||||
rx wait
|
||||
6
host/examples/bladeRF-cli/sc16q11-packed-siso/tx.txt
Normal file
6
host/examples/bladeRF-cli/sc16q11-packed-siso/tx.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
set frequency 915M
|
||||
set samplerate 20M
|
||||
set bitmode packed
|
||||
tx config file=tx_samples.csv format=csv
|
||||
tx start
|
||||
tx wait
|
||||
47
host/examples/bladeRF-cli/sc16q11-packed-siso/validate.py
Normal file
47
host/examples/bladeRF-cli/sc16q11-packed-siso/validate.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
def import_data(file_path):
|
||||
try:
|
||||
df = pd.read_csv(file_path, header=None, names=['I', 'Q'])
|
||||
|
||||
if df.shape[1] < 2:
|
||||
raise ValueError("CSV file must contain at least two columns for I and Q values")
|
||||
|
||||
# Check if the data is numeric
|
||||
if not (df['I'].dtype.kind in 'biufc' and df['Q'].dtype.kind in 'biufc'):
|
||||
raise ValueError("I and Q samples must be numeric")
|
||||
|
||||
return df
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"Error: File '{file_path}' not found")
|
||||
sys.exit(1)
|
||||
except pd.errors.EmptyDataError:
|
||||
print(f"Error: File '{file_path}' is empty")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python validate.py <path_to_csv_file>")
|
||||
sys.exit(1)
|
||||
|
||||
file_path = sys.argv[1]
|
||||
df = import_data(file_path)
|
||||
|
||||
# Plot I and Q components on the same graph
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.plot(df.index, df['I'], label='I', alpha=0.7)
|
||||
plt.plot(df.index, df['Q'], label='Q', alpha=0.7)
|
||||
plt.xlabel('Sample Index')
|
||||
plt.ylabel('Amplitude')
|
||||
plt.title('I/Q Components Over Time')
|
||||
plt.legend()
|
||||
plt.grid(True, alpha=0.3)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
|
@ -7,8 +7,8 @@ project(libbladeRF C)
|
|||
################################################################################
|
||||
|
||||
set(VERSION_INFO_MAJOR 2)
|
||||
set(VERSION_INFO_MINOR 5)
|
||||
set(VERSION_INFO_PATCH 1)
|
||||
set(VERSION_INFO_MINOR 6)
|
||||
set(VERSION_INFO_PATCH 0)
|
||||
set(LIBBLADERF_VERSION
|
||||
${VERSION_INFO_MAJOR}.${VERSION_INFO_MINOR}.${VERSION_INFO_PATCH})
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<tab type="mainpage" visible="yes" title=""/>
|
||||
<tab type="pages" visible="no" title="" intro=""/>
|
||||
<tab type="modules" visible="yes" title="API Sections" intro="libbladeRF is divided into the following sections. Click one of these section names to view information about the macros, enumerations, data structures, and functions within the section."/>
|
||||
<tab type="topics" visible="yes" title="API Sections" intro="libbladeRF is divided into the following sections. Click one of these section names to view information about the macros, enumerations, data structures, and functions within the section." force="!hasModules"/>
|
||||
<tab type="namespaces" visible="no" title="">
|
||||
<tab type="namespacelist" visible="yes" title="" intro=""/>
|
||||
<tab type="namespacemembers" visible="yes" title="" intro=""/>
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ int16_t *init(struct bladerf *dev, int16_t num_samples, bladerf_format format,
|
|||
* restricted to multiples of any particular size.
|
||||
*
|
||||
* The value for `num_samples` has no major restrictions here, while the
|
||||
* `buffer_size` below must be a multiple of 1024.
|
||||
* `buffer_size` below must be a multiple of 2048.
|
||||
*/
|
||||
int16_t *samples;
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ static int init_sync(struct bladerf *dev)
|
|||
* received.
|
||||
*/
|
||||
const unsigned int num_buffers = 16;
|
||||
const unsigned int buffer_size = 8192; /* Must be a multiple of 1024 */
|
||||
const unsigned int buffer_size = 8192; /* Must be a multiple of 2048 */
|
||||
const unsigned int num_transfers = 8;
|
||||
const unsigned int timeout_ms = 3500;
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ int16_t *init(struct bladerf *dev, int16_t num_samples)
|
|||
* restricted to multiples of any particular size.
|
||||
*
|
||||
* The value for `num_samples` has no major restrictions here, while the
|
||||
* `buffer_size` below must be a multiple of 1024.
|
||||
* `buffer_size` below must be a multiple of 2048.
|
||||
*/
|
||||
int16_t *samples;
|
||||
|
||||
|
|
|
|||
|
|
@ -1376,6 +1376,11 @@ int CALL_CONV bladerf_calibrate_dc(struct bladerf *dev,
|
|||
*/
|
||||
#define BLADERF_GPIO_8BIT_MODE (1 << 20)
|
||||
|
||||
/**
|
||||
* Enable highly packed mode
|
||||
*/
|
||||
#define BLADERF_GPIO_HIGHLY_PACKED_MODE (1 << 21)
|
||||
|
||||
/**
|
||||
* AGC enable control bit
|
||||
*
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
*
|
||||
* https://github.com/Nuand/bladeRF/blob/master/doc/development/versioning.md
|
||||
*/
|
||||
#define LIBBLADERF_API_VERSION (0x02050100)
|
||||
#define LIBBLADERF_API_VERSION (0x02060000)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -2140,6 +2140,22 @@ typedef enum {
|
|||
*/
|
||||
BLADERF_FORMAT_SC16_Q11,
|
||||
|
||||
/**
|
||||
* @brief Signed, Complex 16-bit Q11 using a 12-bit Q11 intermediate format.
|
||||
*
|
||||
* This format is a ::BLADERF_FORMAT_SC16_Q11 equivalent to the end user.
|
||||
* The difference lies in the intermediate SC12 Q11 packing format used by
|
||||
* the FPGA and libbladeRF. This intermediate format allows for a 33.3%
|
||||
* higher sample rate when bandwidth limited by the host interface. Synchronous
|
||||
* buffer length must be a multiple of 4096 samples.
|
||||
*
|
||||
* @note While this format allows for higher sample rates over bandwidth-limited
|
||||
* interfaces, it requires additional CPU processing for packing/unpacking. Users
|
||||
* should benchmark to determine if the increased sample rate outweighs the
|
||||
* added processing overhead for their specific use case.
|
||||
*/
|
||||
BLADERF_FORMAT_SC16_Q11_PACKED,
|
||||
|
||||
/**
|
||||
* This format is the same as the ::BLADERF_FORMAT_SC16_Q11 format, except
|
||||
* the first 4 samples in every <i>block*</i> of samples are replaced with
|
||||
|
|
@ -2217,6 +2233,13 @@ typedef enum {
|
|||
* USB 2.0 Hi-Speed or USB 3.0 SuperSpeed for packets for this streaming
|
||||
* format.
|
||||
*
|
||||
* @warning A packet length of (n*256-4) DWORDs will cause the synchronous
|
||||
* buffer it's filled into to indefinitely persist. For instance, if a
|
||||
* packet containing 252 DWORDs is filled into buffer N, buffer N will
|
||||
* always return that first 252 dword packet. It is recommended to avoid
|
||||
* these specific packet lengths (252, 508, 764, 1020, etc. DWORDs)
|
||||
* until this limitation is resolved.
|
||||
*
|
||||
* @see STREAMING_FORMAT_METADATA
|
||||
* @see The `src/streaming/metadata.h` header in the libbladeRF codebase.
|
||||
*/
|
||||
|
|
@ -2724,7 +2747,7 @@ int CALL_CONV bladerf_get_timestamp(struct bladerf *dev,
|
|||
* data stream. This must be greater than the
|
||||
* `num_xfers` parameter.
|
||||
* @param[in] buffer_size The size of the underlying stream buffers, in
|
||||
* samples. This value must be a multiple of 1024.
|
||||
* samples. This value must be a multiple of 2048.
|
||||
* Note that samples are only transferred when a
|
||||
* buffer of this size is filled.
|
||||
* @param[in] num_transfers The number of active USB transfers that may be
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ extern bool bladerf_usb_reset_device_on_open;
|
|||
#endif
|
||||
|
||||
/* Size of a host<->FPGA message in BYTES */
|
||||
#define USB_MSG_SIZE_SS 2048
|
||||
#define USB_MSG_SIZE_HS 1024
|
||||
#define USB_MSG_SIZE_SS 8192
|
||||
#define USB_MSG_SIZE_HS 4096
|
||||
|
||||
typedef enum {
|
||||
USB_TARGET_DEVICE,
|
||||
|
|
|
|||
|
|
@ -1115,6 +1115,12 @@ int bladerf_init_stream(struct bladerf_stream **stream,
|
|||
}
|
||||
}
|
||||
|
||||
if (format == BLADERF_FORMAT_SC16_Q11_PACKED) {
|
||||
log_error("%s: Async interface does not support SC16_Q11_PACKED format\n", __FUNCTION__);
|
||||
MUTEX_UNLOCK(&dev->lock);
|
||||
return BLADERF_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
status = dev->board->init_stream(stream, dev, callback, buffers,
|
||||
num_buffers, format, samples_per_buffer,
|
||||
num_transfers, data);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ static inline int requires_timestamps(bladerf_format format, bool *required)
|
|||
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
*required = false;
|
||||
break;
|
||||
|
||||
|
|
@ -123,6 +124,12 @@ int perform_format_config(struct bladerf *dev,
|
|||
gpio_val &= ~BLADERF_GPIO_8BIT_MODE;
|
||||
}
|
||||
|
||||
if (format == BLADERF_FORMAT_SC16_Q11_PACKED) {
|
||||
gpio_val |= BLADERF_GPIO_HIGHLY_PACKED_MODE;
|
||||
} else {
|
||||
gpio_val &= ~BLADERF_GPIO_HIGHLY_PACKED_MODE;
|
||||
}
|
||||
|
||||
CHECK_STATUS(dev->backend->config_gpio_write(dev, gpio_val));
|
||||
|
||||
board_data->module_format[dir] = format;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
static const struct compat fw_compat[] = {
|
||||
/* Firmware requires >= FPGA */
|
||||
{ VERSION(2, 5, 0), VERSION(0, 16, 0) },
|
||||
{ VERSION(2, 4, 0), VERSION(0, 6, 0) },
|
||||
{ VERSION(2, 3, 2), VERSION(0, 6, 0) },
|
||||
{ VERSION(2, 3, 1), VERSION(0, 6, 0) },
|
||||
|
|
@ -27,6 +28,7 @@ const struct version_compat_table bladerf2_fw_compat_table = {fw_compat, ARRAY_S
|
|||
|
||||
static const struct compat fpga_compat[] = {
|
||||
/* FPGA requires >= Firmware */
|
||||
{ VERSION(0, 16, 0), VERSION(2, 5, 0) },
|
||||
{ VERSION(0, 15, 3), VERSION(2, 4, 0) },
|
||||
{ VERSION(0, 15, 2), VERSION(2, 4, 0) },
|
||||
{ VERSION(0, 15, 1), VERSION(2, 4, 0) },
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ size_t _interleave_calc_bytes_per_sample(bladerf_format format)
|
|||
case BLADERF_FORMAT_SC8_Q7_META:
|
||||
return 2;
|
||||
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_META:
|
||||
case BLADERF_FORMAT_PACKET_META:
|
||||
|
|
@ -63,6 +64,7 @@ size_t _interleave_calc_metadata_bytes(bladerf_format format)
|
|||
case BLADERF_FORMAT_PACKET_META:
|
||||
return 0x10;
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,8 +52,10 @@ int async_init_stream(struct bladerf_stream **stream,
|
|||
return BLADERF_ERR_INVAL;
|
||||
}
|
||||
|
||||
if (samples_per_buffer < 1024 || samples_per_buffer % 1024 != 0) {
|
||||
log_error("samples_per_buffer must be multiples of 1024\n");
|
||||
buffer_size_bytes = samples_to_bytes(format, samples_per_buffer);
|
||||
if (buffer_size_bytes < USB_MSG_SIZE_SS || buffer_size_bytes % USB_MSG_SIZE_SS != 0) {
|
||||
log_error("Samples_per_buffer must be multiples of %u\n",
|
||||
bytes_to_samples(format, USB_MSG_SIZE_SS));
|
||||
return BLADERF_ERR_INVAL;
|
||||
}
|
||||
|
||||
|
|
@ -109,26 +111,6 @@ int async_init_stream(struct bladerf_stream **stream,
|
|||
}
|
||||
}
|
||||
|
||||
switch(format) {
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
case BLADERF_FORMAT_SC8_Q7_META:
|
||||
buffer_size_bytes = sc8q7_to_bytes(samples_per_buffer);
|
||||
break;
|
||||
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_META:
|
||||
buffer_size_bytes = sc16q11_to_bytes(samples_per_buffer);
|
||||
break;
|
||||
|
||||
case BLADERF_FORMAT_PACKET_META:
|
||||
buffer_size_bytes = samples_per_buffer;
|
||||
break;
|
||||
|
||||
default:
|
||||
status = BLADERF_ERR_INVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
lstream->buffers = calloc(num_buffers, sizeof(lstream->buffers[0]));
|
||||
if (lstream->buffers) {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,18 @@ static inline size_t sc16q11_to_bytes(size_t n_samples)
|
|||
return n_samples * sample_size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert SC16Q11 packed (SC12Q11) samples to bytes
|
||||
* I and Q are packed into 3 bytes. I and Q are 12 bits each.
|
||||
* That makes a sample 24 bits = 3 bytes.
|
||||
*/
|
||||
static inline size_t sc16q11_packed_to_bytes(size_t n_samples)
|
||||
{
|
||||
const size_t sample_size = 3*sizeof(int8_t);
|
||||
assert(n_samples <= (SIZE_MAX / sample_size));
|
||||
return n_samples * sample_size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert bytes to SC16Q11 samples
|
||||
*/
|
||||
|
|
@ -72,6 +84,9 @@ static inline size_t samples_to_bytes(bladerf_format format, size_t n)
|
|||
case BLADERF_FORMAT_SC8_Q7_META:
|
||||
return sc8q7_to_bytes(n);
|
||||
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
return sc16q11_packed_to_bytes(n);
|
||||
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_META:
|
||||
return sc16q11_to_bytes(n);
|
||||
|
|
@ -93,6 +108,7 @@ static inline size_t bytes_to_samples(bladerf_format format, size_t n)
|
|||
case BLADERF_FORMAT_SC8_Q7_META:
|
||||
return bytes_to_sc8q7(n);
|
||||
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_META:
|
||||
return bytes_to_sc16q11(n);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
* ~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* The FPGA handles data in units of "messages." These messages are
|
||||
* 1024 or 2048 bytes for USB 2.0 (Hi-Speed) or USB 3.0 (SuperSpeed),
|
||||
* 2048 or 8192 bytes for USB 2.0 (Hi-Speed) or USB 3.0 (SuperSpeed),
|
||||
* respectively.
|
||||
*
|
||||
* The first 16 bytes of the message form a header, which includes metadata
|
||||
|
|
|
|||
|
|
@ -141,6 +141,8 @@ int sync_init(struct bladerf_sync *sync,
|
|||
{
|
||||
int status = 0;
|
||||
size_t i, bytes_per_sample;
|
||||
size_t bytes_per_buffer;
|
||||
const size_t GPIF_BUF_SIZE = 8192;
|
||||
|
||||
if (num_transfers >= num_buffers) {
|
||||
return BLADERF_ERR_INVAL;
|
||||
|
|
@ -168,27 +170,22 @@ int sync_init(struct bladerf_sync *sync,
|
|||
}
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
case BLADERF_FORMAT_SC8_Q7_META:
|
||||
bytes_per_sample = 2;
|
||||
break;
|
||||
bytes_per_sample = samples_to_bytes(format, 1);
|
||||
bytes_per_buffer = samples_to_bytes(format, buffer_size);
|
||||
if (bytes_per_buffer < GPIF_BUF_SIZE || bytes_per_buffer % GPIF_BUF_SIZE != 0) {
|
||||
size_t original_size = buffer_size;
|
||||
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_META:
|
||||
case BLADERF_FORMAT_PACKET_META:
|
||||
bytes_per_sample = 4;
|
||||
break;
|
||||
/* Round up to the next multiple of GPIF_BUF_SIZE, ensuring at least one GPIF buffer */
|
||||
buffer_size = bytes_per_buffer == 0 ? GPIF_BUF_SIZE / bytes_per_sample :
|
||||
((bytes_per_buffer + GPIF_BUF_SIZE - 1) / GPIF_BUF_SIZE)
|
||||
* (GPIF_BUF_SIZE / bytes_per_sample);
|
||||
|
||||
default:
|
||||
log_debug("Invalid format value: %d\n", format);
|
||||
return BLADERF_ERR_INVAL;
|
||||
}
|
||||
log_warning("Requested buffer size %zu samples (%zu bytes) is invalid. "
|
||||
"Adjusting to %zu samples (%zu bytes).\n",
|
||||
original_size, samples_to_bytes(format, original_size),
|
||||
buffer_size, samples_to_bytes(format, buffer_size));
|
||||
|
||||
/* bladeRF GPIF DMA requirement */
|
||||
if ((bytes_per_sample * buffer_size) % 4096 != 0) {
|
||||
assert(!"Invalid buffer size");
|
||||
return BLADERF_ERR_INVAL;
|
||||
bytes_per_buffer = samples_to_bytes(format, buffer_size);
|
||||
}
|
||||
|
||||
/* Deinitialize sync handle if it's initialized */
|
||||
|
|
@ -539,6 +536,7 @@ int sync_rx(struct bladerf_sync *s, void *samples, unsigned num_samples,
|
|||
|
||||
switch (s->stream_config.format) {
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
s->state = SYNC_STATE_USING_BUFFER;
|
||||
break;
|
||||
|
|
@ -570,9 +568,24 @@ int sync_rx(struct bladerf_sync *s, void *samples, unsigned num_samples,
|
|||
samples_to_copy = uint_min(num_samples - samples_returned,
|
||||
samples_per_buffer - b->partial_off);
|
||||
|
||||
memcpy(samples_dest + samples2bytes(s, samples_returned),
|
||||
buf_src + samples2bytes(s, b->partial_off),
|
||||
samples2bytes(s, samples_to_copy));
|
||||
if (s->stream_config.format == BLADERF_FORMAT_SC16_Q11_PACKED) {
|
||||
// Unpack SC12Q11 samples to SC16Q11 directly into destination buffer
|
||||
size_t zz, jj;
|
||||
uint8_t *meta_sample_ptr = buf_src + samples2bytes(s, b->partial_off);
|
||||
int16_t *dest_ptr = (int16_t*)(samples_dest + (4*samples_returned));
|
||||
for (zz = 0, jj = 0; zz < 2*samples_to_copy; zz+=4, jj+=3) {
|
||||
dest_ptr[zz+0] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+0] & 0x0FFF) << 4) >> 4;
|
||||
dest_ptr[zz+1] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+1] & 0x00FF) << 8) >> 4
|
||||
| ((((uint16_t*)(meta_sample_ptr))[jj+0] & 0xF000) >> 12);
|
||||
dest_ptr[zz+2] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+2] & 0x000F) << 12) >> 4
|
||||
| ((((uint16_t*)(meta_sample_ptr))[jj+1] & 0xFF00)) >> 8;
|
||||
dest_ptr[zz+3] = (int16_t)((((uint16_t*)(meta_sample_ptr))[jj+2] & 0xFFF0)) >> 4;
|
||||
}
|
||||
} else {
|
||||
memcpy(samples_dest + samples2bytes(s, samples_returned),
|
||||
buf_src + samples2bytes(s, b->partial_off),
|
||||
samples2bytes(s, samples_to_copy));
|
||||
}
|
||||
|
||||
b->partial_off += samples_to_copy;
|
||||
samples_returned += samples_to_copy;
|
||||
|
|
@ -1054,6 +1067,7 @@ int sync_tx(struct bladerf_sync *s,
|
|||
|
||||
switch (s->stream_config.format) {
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
s->state = SYNC_STATE_USING_BUFFER;
|
||||
break;
|
||||
|
|
@ -1087,9 +1101,24 @@ int sync_tx(struct bladerf_sync *s,
|
|||
samples_to_copy = uint_min(num_samples - samples_written,
|
||||
samples_per_buffer - b->partial_off);
|
||||
|
||||
memcpy(buf_dest + samples2bytes(s, b->partial_off),
|
||||
samples_src + samples2bytes(s, samples_written),
|
||||
samples2bytes(s, samples_to_copy));
|
||||
if (s->stream_config.format == BLADERF_FORMAT_SC16_Q11_PACKED) {
|
||||
// Pack SC16Q11 samples to SC12Q11 directly into destination buffer
|
||||
size_t zz, jj;
|
||||
uint8_t *packed_dest = buf_dest + samples2bytes(s, b->partial_off);
|
||||
int16_t const *src_ptr = (int16_t const *)(samples_src + 2*sizeof(int16_t)*samples_written);
|
||||
for (zz = 0, jj = 0; zz < samples_to_copy * 2; zz += 4, jj += 3) {
|
||||
((uint16_t*)packed_dest)[jj+0] = src_ptr[zz+0] & 0x0FFF;
|
||||
((uint16_t*)packed_dest)[jj+0] |= (src_ptr[zz+1] << 12) & 0xF000;
|
||||
((uint16_t*)packed_dest)[jj+1] = (src_ptr[zz+1] >> 4) & 0x00FF;
|
||||
((uint16_t*)packed_dest)[jj+1] |= (src_ptr[zz+2] << 8) & 0xFF00;
|
||||
((uint16_t*)packed_dest)[jj+2] = (src_ptr[zz+2] >> 8) & 0x000F;
|
||||
((uint16_t*)packed_dest)[jj+2] |= (src_ptr[zz+3] << 4) & 0xFFF0;
|
||||
}
|
||||
} else {
|
||||
memcpy(buf_dest + samples2bytes(s, b->partial_off),
|
||||
samples_src + samples2bytes(s, samples_written),
|
||||
samples2bytes(s, samples_to_copy));
|
||||
}
|
||||
|
||||
b->partial_off += samples_to_copy;
|
||||
samples_written += samples_to_copy;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ add_subdirectory(test_ctrl)
|
|||
add_subdirectory(test_freq_hop)
|
||||
add_subdirectory(test_fw_check)
|
||||
add_subdirectory(test_open)
|
||||
add_subdirectory(test_packet)
|
||||
add_subdirectory(test_parse)
|
||||
add_subdirectory(test_peripheral_timing)
|
||||
add_subdirectory(test_gain_compare)
|
||||
|
|
@ -19,6 +20,7 @@ add_subdirectory(test_quick_retune)
|
|||
add_subdirectory(test_repeated_stream)
|
||||
add_subdirectory(test_rx_discont)
|
||||
add_subdirectory(test_scheduled_retune)
|
||||
add_subdirectory(test_streaming)
|
||||
add_subdirectory(test_sync)
|
||||
add_subdirectory(test_timestamps)
|
||||
add_subdirectory(test_tune_timing)
|
||||
|
|
|
|||
31
host/libraries/libbladeRF_test/test_packet/CMakeLists.txt
Normal file
31
host/libraries/libbladeRF_test/test_packet/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
project(libbladeRF_test_packet C)
|
||||
|
||||
set(INCLUDES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../common/include
|
||||
${libbladeRF_SOURCE_DIR}/include
|
||||
${BLADERF_HOST_COMMON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
# Checks if the include directories exist
|
||||
foreach(dir ${INCLUDES})
|
||||
if(NOT EXISTS ${dir})
|
||||
message(FATAL_ERROR "The include directory '${dir}' does not exist.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(SRC
|
||||
src/main.c
|
||||
${BLADERF_HOST_COMMON_SOURCE_DIR}/log.c
|
||||
${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c)
|
||||
|
||||
if(MSVC)
|
||||
set(SRC ${SRC}
|
||||
${BLADERF_HOST_COMMON_SOURCE_DIR}/windows/getopt_long.c
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(${INCLUDES})
|
||||
add_executable(${PROJECT_NAME} ${SRC})
|
||||
target_link_libraries(${PROJECT_NAME} libbladerf_shared)
|
||||
|
||||
207
host/libraries/libbladeRF_test/test_packet/src/main.c
Normal file
207
host/libraries/libbladeRF_test/test_packet/src/main.c
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include "test_common.h"
|
||||
#include "libbladeRF.h"
|
||||
#include "log.h"
|
||||
#include "conversions.h"
|
||||
|
||||
#define dword_t int32_t
|
||||
#define DYNAMIC_PACKET_LEN 0
|
||||
|
||||
typedef struct test {
|
||||
bladerf_frequency frequency;
|
||||
bladerf_sample_rate samplerate;
|
||||
bladerf_bandwidth bandwidth;
|
||||
|
||||
// Sync interface
|
||||
bladerf_channel channel;
|
||||
uint32_t num_buffers;
|
||||
uint32_t buffer_len;
|
||||
|
||||
// Packets
|
||||
size_t num_dwords;
|
||||
size_t num_packets;
|
||||
} test_t;
|
||||
|
||||
void test_config_init(test_t *t) {
|
||||
t->frequency = 915e6;
|
||||
t->samplerate = 10e6;
|
||||
t->bandwidth = 10e6;
|
||||
|
||||
t->channel = BLADERF_CHANNEL_TX(0);
|
||||
t->num_buffers = 512;
|
||||
t->buffer_len = 4096;
|
||||
|
||||
t->num_dwords = DYNAMIC_PACKET_LEN;
|
||||
t->num_packets = 10;
|
||||
}
|
||||
|
||||
int bladerf_config(struct bladerf *dev, const test_t *test) {
|
||||
int status = 0;
|
||||
CHECK_NULL(dev, test);
|
||||
|
||||
CHECK_STATUS(bladerf_set_frequency(dev, test->channel, test->frequency));
|
||||
CHECK_STATUS(bladerf_set_sample_rate(dev, test->channel, test->samplerate, NULL));
|
||||
CHECK_STATUS(bladerf_set_bandwidth(dev, test->channel, test->bandwidth, NULL));
|
||||
CHECK_STATUS(bladerf_sync_config(dev, test->channel, BLADERF_FORMAT_PACKET_META,
|
||||
test->num_buffers, test->buffer_len, 16, 3e6));
|
||||
|
||||
error:
|
||||
return status;
|
||||
}
|
||||
|
||||
int send_packets_variable_len(struct bladerf *dev, const test_t *test) {
|
||||
CHECK_NULL(dev, test);
|
||||
int status = 0;
|
||||
struct bladerf_metadata meta;
|
||||
|
||||
size_t dynamic_packet_len = 0;
|
||||
size_t packet_sizes[4] = {40, 17, 43, dynamic_packet_len};
|
||||
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
meta.flags = BLADERF_META_FLAG_TX_BURST_START | BLADERF_META_FLAG_TX_NOW | BLADERF_META_FLAG_TX_BURST_END;
|
||||
|
||||
CHECK_STATUS(bladerf_enable_module(dev, test->channel, true));
|
||||
|
||||
size_t packet_idx = 0;
|
||||
for (size_t i = 0; i < test->num_packets; i++) {
|
||||
dynamic_packet_len = 20 + (i % 300);
|
||||
packet_sizes[3] = dynamic_packet_len;
|
||||
|
||||
size_t current_packet_len = packet_sizes[packet_idx % 4]; // Select packet size in round-robin fashion
|
||||
size_t packet_size = current_packet_len * sizeof(dword_t);
|
||||
dword_t *packet = malloc(packet_size);
|
||||
CHECK_NULL(packet);
|
||||
|
||||
for (size_t j = 0; j < current_packet_len; j++) {
|
||||
packet[j] = j;
|
||||
}
|
||||
|
||||
CHECK_STATUS(bladerf_sync_tx(dev, packet, bytes_to_dwords(packet_size), &meta, 3e3));
|
||||
|
||||
free(packet);
|
||||
packet_idx++; // Move to the next packet size for the next iteration
|
||||
}
|
||||
|
||||
CHECK_STATUS(bladerf_enable_module(dev, test->channel, false));
|
||||
|
||||
error:
|
||||
return status;
|
||||
}
|
||||
|
||||
int send_packets_static_len(struct bladerf *dev, const test_t *test) {
|
||||
int status = 0;
|
||||
struct bladerf_metadata meta;
|
||||
CHECK_NULL(dev);
|
||||
|
||||
size_t packets_size = test->num_dwords * sizeof(dword_t);
|
||||
dword_t *packet = malloc(packets_size);
|
||||
CHECK_NULL(packet);
|
||||
|
||||
for (size_t i = 0; i < test->num_dwords; i++) {
|
||||
packet[i] = i;
|
||||
}
|
||||
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
meta.flags = BLADERF_META_FLAG_TX_BURST_START | BLADERF_META_FLAG_TX_NOW |
|
||||
BLADERF_META_FLAG_TX_BURST_END;
|
||||
|
||||
CHECK_STATUS(bladerf_enable_module(dev, test->channel, true));
|
||||
|
||||
for (size_t i = 0; i < test->num_packets; i++) {
|
||||
CHECK_STATUS(bladerf_sync_tx(dev, packet, bytes_to_dwords(packets_size), &meta, 3e3));
|
||||
}
|
||||
|
||||
CHECK_STATUS(bladerf_enable_module(dev, test->channel, false));
|
||||
|
||||
error:
|
||||
free(packet);
|
||||
return status;
|
||||
}
|
||||
|
||||
static const struct option long_options[] = {
|
||||
{ "packets", required_argument, NULL, 'n' },
|
||||
{ "size", required_argument, NULL, 's' },
|
||||
{ "device", required_argument, NULL, 'd' },
|
||||
{ "verbosity", required_argument, NULL, 'v' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ NULL, 0, NULL, 0 },
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int status = 0;
|
||||
int opt = 0;
|
||||
int opt_ind = 0;
|
||||
bool ok;
|
||||
struct bladerf *dev;
|
||||
char *devstr = NULL;
|
||||
test_t test;
|
||||
bladerf_log_level log_level;
|
||||
|
||||
test_config_init(&test);
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "n:s:d:v:h", long_options, &opt_ind)) != -1) {
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
test.num_packets = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
test.num_dwords = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
devstr = optarg;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
log_level = str2loglevel(optarg, &ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid log level: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
bladerf_log_set_verbosity(log_level);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
printf("Usage: %s [options]\n", argv[0]);
|
||||
printf("Options:\n");
|
||||
printf(" -n, --packets <n> Number of packets to send.\n");
|
||||
printf(" -s, --size <n> Number of dwords per packet.\n");
|
||||
printf(" -d, --device <str> Specify the device to open. Allows selection of a specific\n");
|
||||
printf(" bladeRF device if multiple are available.\n");
|
||||
printf(" -v, --verbosity <level> Set libbladeRF verbosity level.\n");
|
||||
printf(" -h, --help Show this help message and exit.\n");
|
||||
printf("\n");
|
||||
printf("The program transmits packets using the bladeRF library. If '--size 0' is used, packets\n");
|
||||
printf("will be sent with variable lengths in a round-robin fashion: 40, 17, 43 dwords, and\n");
|
||||
printf("a dynamic packet length of '20 + (packet_count %% 300)'. Otherwise, all packets\n");
|
||||
printf("will have a static length as specified by '--size'.\n");
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Opening device: %s\n", (devstr == NULL) ? "any" : devstr);
|
||||
CHECK_STATUS(bladerf_open(&dev, devstr));
|
||||
CHECK_STATUS(bladerf_config(dev, &test));
|
||||
|
||||
if (test.num_dwords == DYNAMIC_PACKET_LEN) {
|
||||
printf("Sending %zu packets with the following packet length and order:\n", test.num_packets);
|
||||
printf("Packet Lengths: [%i, %i, %i, 20 + (packets_sent %% 300)] dwords\n", 40, 17, 43);
|
||||
|
||||
CHECK_STATUS(send_packets_variable_len(dev, &test));
|
||||
} else {
|
||||
printf("Sending %zu packets: %zu dwords/packet (%zu bytes/packet)\n",
|
||||
test.num_packets, test.num_dwords, test.num_dwords * sizeof(dword_t));
|
||||
|
||||
CHECK_STATUS(send_packets_static_len(dev, &test));
|
||||
}
|
||||
|
||||
error:
|
||||
bladerf_close(dev);
|
||||
return (status == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
@ -337,6 +337,7 @@ INSTANTIATE_TEST_SUITE_P(hdl, verify,
|
|||
|
||||
TEST_HDL_COMPILE(compile)
|
||||
TEST_HDL_COMPILE(fx3_gpif_iq_tb)
|
||||
TEST_HDL_COMPILE(fx3_gpif_iq_packed_tb)
|
||||
TEST_HDL_COMPILE(fx3_gpif_iq_8bit_tb)
|
||||
TEST_HDL_COMPILE(fx3_gpif_meta_8bit_tb)
|
||||
TEST_HDL_COMPILE(fx3_gpif_meta_tb)
|
||||
|
|
@ -351,6 +352,10 @@ TEST_HDL_VERIFY(fx3_gpif_iq_tb, 16b01, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1
|
|||
TEST_HDL_VERIFY(fx3_gpif_iq_tb, 16b10, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='0', 1000);
|
||||
TEST_HDL_VERIFY(fx3_gpif_iq_tb, 16b11, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='1', 1000);
|
||||
|
||||
TEST_HDL_VERIFY(fx3_gpif_iq_packed_tb, 16b01, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1='1', 1000);
|
||||
TEST_HDL_VERIFY(fx3_gpif_iq_packed_tb, 16b10, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='0', 1000);
|
||||
TEST_HDL_VERIFY(fx3_gpif_iq_packed_tb, 16b11, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='1', 1000);
|
||||
|
||||
TEST_HDL_VERIFY(fx3_gpif_packet_tb, 16b00, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1='0', 1000);
|
||||
TEST_HDL_VERIFY(fx3_gpif_packet_tb, 16b01, -gENABLE_CHANNEL_0='0' -gENABLE_CHANNEL_1='1', 1000);
|
||||
TEST_HDL_VERIFY(fx3_gpif_packet_tb, 16b10, -gENABLE_CHANNEL_0='1' -gENABLE_CHANNEL_1='0', 1000);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ int16_t *init(struct bladerf *dev, int16_t num_samples, bladerf_format format,
|
|||
* restricted to multiples of any particular size.
|
||||
*
|
||||
* The value for `num_samples` has no major restrictions here, while the
|
||||
* `buffer_size` below must be a multiple of 1024.
|
||||
* `buffer_size` below must be a multiple of 2048.
|
||||
*/
|
||||
int16_t *samples;
|
||||
|
||||
|
|
|
|||
17
host/libraries/libbladeRF_test/test_streaming/CMakeLists.txt
Normal file
17
host/libraries/libbladeRF_test/test_streaming/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
cmake_minimum_required(VERSION 3.5)
|
||||
project(libbladeRF_test_streaming C)
|
||||
|
||||
set(INCLUDES
|
||||
${libbladeRF_SOURCE_DIR}/include)
|
||||
if(MSVC)
|
||||
set(INCLUDES ${INCLUDES} ${MSVC_C99_INCLUDES})
|
||||
endif()
|
||||
|
||||
set(SRC
|
||||
${BLADERF_HOST_COMMON_SOURCE_DIR}/conversions.c
|
||||
src/main.c)
|
||||
|
||||
include_directories(${INCLUDES} ${CURL_INCLUDE_DIR} include)
|
||||
add_executable(${PROJECT_NAME} ${SRC})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} libbladerf_shared m)
|
||||
329
host/libraries/libbladeRF_test/test_streaming/src/main.c
Normal file
329
host/libraries/libbladeRF_test/test_streaming/src/main.c
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
#include <getopt.h>
|
||||
#include <libbladeRF.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "conversions.h"
|
||||
|
||||
#define INT12_MAX 2047
|
||||
#define BUFFER_SIZE_ALIGNMENT 1024
|
||||
|
||||
#define CHECK_STATUS(fn) \
|
||||
do { \
|
||||
status = (fn); \
|
||||
if (status != 0) { \
|
||||
fprintf(stderr, "Error at %s:%d (%s): %s\n", \
|
||||
__FILE__, __LINE__, __func__, bladerf_strerror(status)); \
|
||||
goto error; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef struct {
|
||||
bool tx;
|
||||
bool rx;
|
||||
bool mimo;
|
||||
size_t num_samples;
|
||||
uint64_t sample_rate;
|
||||
int16_t *tx_samples;
|
||||
int16_t *rx_samples;
|
||||
bladerf_format format;
|
||||
struct bladerf_metadata tx_meta;
|
||||
struct bladerf_metadata rx_meta;
|
||||
size_t num_buffers;
|
||||
size_t buffer_size;
|
||||
size_t num_transfers;
|
||||
size_t timeout_ms;
|
||||
} test_config;
|
||||
|
||||
void print_config(const test_config *config, const char *device_string, const char *fpga_file) {
|
||||
printf("\nConfiguration Summary:\n");
|
||||
printf("---------------------\n");
|
||||
printf("Device: %s\n", device_string ? device_string : "any");
|
||||
printf("FPGA file: %s\n", fpga_file ? fpga_file : "Not specified");
|
||||
printf("TX enabled: %s\n", config->tx ? "Yes" : "No");
|
||||
printf("RX enabled: %s\n", config->rx ? "Yes" : "No");
|
||||
printf("MIMO enabled: %s\n", config->mimo ? "Yes" : "No");
|
||||
printf("Format: %s\n", config->format == BLADERF_FORMAT_SC16_Q11_META ? "SC16 Q11 META" : "SC16 Q11");
|
||||
printf("Sample rate: %.3f MHz\n", config->sample_rate / 1e6);
|
||||
printf("# of samples: %zu\n", config->num_samples);
|
||||
printf("Buffer size: %zu\n", config->buffer_size);
|
||||
printf("# of buffers: %zu\n", config->num_buffers);
|
||||
printf("# of transfers: %zu\n", config->num_transfers);
|
||||
printf("---------------------\n\n");
|
||||
}
|
||||
|
||||
|
||||
// Define suffix table for engineering notation
|
||||
static const struct numeric_suffix freq_suffixes[] = {
|
||||
{ "K", 1000 },
|
||||
{ "k", 1000 },
|
||||
{ "M", 1000000 },
|
||||
{ "m", 1000000 },
|
||||
{ "G", 1000000000 },
|
||||
{ "g", 1000000000 },
|
||||
};
|
||||
|
||||
void print_bladerf_flag_statuses(uint32_t flags) {
|
||||
printf("BladeRF Flag Statuses:\n");
|
||||
printf("%-40s %d\n", "BLADERF_META_STATUS_OVERRUN:", !!(flags & BLADERF_META_STATUS_OVERRUN));
|
||||
printf("%-40s %d\n", "BLADERF_META_STATUS_UNDERRUN:", !!(flags & BLADERF_META_STATUS_UNDERRUN));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_TX_BURST_START:", !!(flags & BLADERF_META_FLAG_TX_BURST_START));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_TX_BURST_END:", !!(flags & BLADERF_META_FLAG_TX_BURST_END));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_TX_NOW:", !!(flags & BLADERF_META_FLAG_TX_NOW));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP:", !!(flags & BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_RX_NOW:", !!(flags & BLADERF_META_FLAG_RX_NOW));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_RX_HW_UNDERFLOW:", !!(flags & BLADERF_META_FLAG_RX_HW_UNDERFLOW));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_RX_HW_MINIEXP1:", !!(flags & BLADERF_META_FLAG_RX_HW_MINIEXP1));
|
||||
printf("%-40s %d\n", "BLADERF_META_FLAG_RX_HW_MINIEXP2:", !!(flags & BLADERF_META_FLAG_RX_HW_MINIEXP2));
|
||||
}
|
||||
|
||||
void print_help() {
|
||||
printf("Usage: test_streaming [options]\n");
|
||||
printf("Options:\n");
|
||||
printf(" -d, --device <device> Specify the device string\n");
|
||||
printf(" -f, --fpga <file> Specify the FPGA file\n");
|
||||
printf(" -v, --verbosity Enable verbose logging\n");
|
||||
printf(" -t, --tx Enable TX test\n");
|
||||
printf(" -r, --rx Enable RX test\n");
|
||||
printf(" -m, --mimo Enable MIMO test\n");
|
||||
printf(" -e, --meta Enable META test\n");
|
||||
printf(" -s, --samplerate <rate> Specify the sample rate\n");
|
||||
printf(" -n, --num-samples <count> Specify the number of samples\n");
|
||||
printf(" -b, --buffer-size <size> Specify the buffer size (multiple of 2048)\n");
|
||||
printf(" -h, --help Display this help message\n");
|
||||
printf("\n");
|
||||
|
||||
printf("Description:\n");
|
||||
printf("The streaming test allows for cross testing between MIMO, SISO, TX, RX, meta,\n");
|
||||
printf("and non-meta configurations.\n");
|
||||
printf("\n");
|
||||
|
||||
printf("Example: TX a CW at 50MSPS and at a frequency of (915MHz+50MHz/16) with meta enabled\n");
|
||||
printf("./output/libbladeRF_test_streaming -te -s 50M\n");
|
||||
printf("\n");
|
||||
printf("Example: TX and RX at 25MSPS and at a frequency of (915MHz+25MHz/16) without meta enabled\n");
|
||||
printf("./output/libbladeRF_test_streaming -tr -s 25M\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int status = 0;
|
||||
struct bladerf *dev = NULL;
|
||||
const char *fpga_file = NULL;
|
||||
const char *device_string = NULL;
|
||||
int c;
|
||||
bool ok;
|
||||
|
||||
test_config config = {
|
||||
.tx = false,
|
||||
.rx = false,
|
||||
.mimo = false,
|
||||
.sample_rate = 61.44e6,
|
||||
.num_samples = 5 * 61.44e6,
|
||||
.tx_samples = NULL,
|
||||
.format = BLADERF_FORMAT_SC16_Q11,
|
||||
.num_buffers = 512,
|
||||
.buffer_size = 4096,
|
||||
.num_transfers = 64,
|
||||
.timeout_ms = 1000,
|
||||
.tx_meta.flags = BLADERF_META_FLAG_TX_BURST_START |
|
||||
BLADERF_META_FLAG_TX_NOW |
|
||||
BLADERF_META_FLAG_TX_BURST_END,
|
||||
.rx_meta.flags = BLADERF_META_FLAG_RX_NOW,
|
||||
};
|
||||
|
||||
bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_INFO);
|
||||
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{"device", required_argument, 0, 'd'},
|
||||
{"fpga", required_argument, 0, 'f'},
|
||||
{"verbosity", no_argument, 0, 'v'},
|
||||
{"tx", no_argument, 0, 't'},
|
||||
{"rx", no_argument, 0, 'r'},
|
||||
{"mimo", no_argument, 0, 'm'},
|
||||
{"meta", no_argument, 0, 'e'},
|
||||
{"samplerate", required_argument, 0, 's'},
|
||||
{"num-samples", required_argument, 0, 'n'},
|
||||
{"buffer-size", required_argument, 0, 'b'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "d:f:vtrmes:n:b:h", long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'd':
|
||||
device_string = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
fpga_file = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_VERBOSE);
|
||||
break;
|
||||
case 't':
|
||||
config.tx = true;
|
||||
break;
|
||||
case 'r':
|
||||
config.rx = true;
|
||||
break;
|
||||
case 'm':
|
||||
config.mimo = true;
|
||||
break;
|
||||
case 'n':
|
||||
config.num_samples = str2uint64_suffix(
|
||||
optarg, 1, UINT64_MAX, freq_suffixes,
|
||||
sizeof(freq_suffixes) / sizeof(freq_suffixes[0]), &ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid number of samples: %s\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
size_t requested_size = strtoull(optarg, NULL, 0);
|
||||
config.buffer_size = ((requested_size + BUFFER_SIZE_ALIGNMENT - 1) / BUFFER_SIZE_ALIGNMENT) * BUFFER_SIZE_ALIGNMENT;
|
||||
if (requested_size % BUFFER_SIZE_ALIGNMENT != 0) {
|
||||
fprintf(stderr, "Requested buffer size rounded up to %zu\n", config.buffer_size);
|
||||
}
|
||||
break;
|
||||
case 'e':
|
||||
config.format = BLADERF_FORMAT_SC16_Q11_META;
|
||||
break;
|
||||
case 's':
|
||||
config.sample_rate = str2uint64_suffix(
|
||||
optarg, 0, UINT64_MAX, freq_suffixes,
|
||||
sizeof(freq_suffixes) / sizeof(freq_suffixes[0]), &ok);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid sample rate: %s\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
print_help();
|
||||
exit(EXIT_FAILURE);
|
||||
default:
|
||||
printf("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.tx && !config.rx) {
|
||||
fprintf(stderr, "[Error] TX or RX must be specified.\n");
|
||||
print_help();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
print_config(&config, device_string, fpga_file);
|
||||
|
||||
// Allocate memory for samples (2* for IQ components and 2* for MIMO)
|
||||
config.tx_samples = malloc(4 * config.num_samples * sizeof(int16_t));
|
||||
config.rx_samples = malloc(4 * config.num_samples * sizeof(int16_t));
|
||||
if (config.tx_samples == NULL || config.rx_samples == NULL) {
|
||||
fprintf(stderr, "Failed to allocate memory for samples\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Opening device: %s\n", (device_string == NULL) ? "any" : device_string);
|
||||
CHECK_STATUS(bladerf_open(&dev, device_string));
|
||||
|
||||
if (fpga_file != NULL) {
|
||||
printf("Loading the FPGA image...\n");
|
||||
CHECK_STATUS(bladerf_load_fpga(dev, fpga_file));
|
||||
}
|
||||
|
||||
printf("Setting sample rate to %0.3f MHz...\n", config.sample_rate / 1e6);
|
||||
CHECK_STATUS(bladerf_set_sample_rate(dev, BLADERF_CHANNEL_RX(0), config.sample_rate, NULL));
|
||||
CHECK_STATUS(bladerf_set_sample_rate(dev, BLADERF_CHANNEL_TX(0), config.sample_rate, NULL));
|
||||
|
||||
printf("Setting frequency to 915 MHz...\n");
|
||||
CHECK_STATUS(bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(0), 915e6));
|
||||
CHECK_STATUS(bladerf_set_frequency(dev, BLADERF_CHANNEL_TX(0), 915e6));
|
||||
|
||||
CHECK_STATUS(bladerf_set_gain(dev, BLADERF_CHANNEL_TX(0), 30));
|
||||
CHECK_STATUS(bladerf_set_gain(dev, BLADERF_CHANNEL_RX(0), 0));
|
||||
|
||||
for (size_t i = 0; i < config.num_samples; i++) {
|
||||
double angle = (2.0 * M_PI * (i % 16)) / 16.0;
|
||||
config.tx_samples[2 * i] = (int16_t)round(INT12_MAX * cos(angle)); // I component
|
||||
config.tx_samples[2 * i + 1] = (int16_t)round(INT12_MAX * sin(angle)); // Q component
|
||||
}
|
||||
|
||||
if (config.mimo) {
|
||||
for (size_t i = 0; i < config.num_samples; i++) {
|
||||
double angle = (2.0 * M_PI * (i % 16)) / 16.0;
|
||||
config.tx_samples[4 * i + 0] = (int16_t)round(INT12_MAX * cos(angle)); // Ch0 I
|
||||
config.tx_samples[4 * i + 1] = (int16_t)round(INT12_MAX * sin(angle)); // Ch0 Q
|
||||
config.tx_samples[4 * i + 2] = (int16_t)round(INT12_MAX * cos(angle)); // Ch1 I
|
||||
config.tx_samples[4 * i + 3] = (int16_t)round(INT12_MAX * sin(angle)); // Ch1 Q
|
||||
}
|
||||
}
|
||||
|
||||
if (config.tx) {
|
||||
printf("Streaming TX...\n");
|
||||
CHECK_STATUS(bladerf_sync_config(
|
||||
dev, (config.mimo == true) ? BLADERF_TX_X2 : BLADERF_TX_X1,
|
||||
config.format, config.num_buffers, config.buffer_size,
|
||||
config.num_transfers, config.timeout_ms));
|
||||
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_TX(0), true));
|
||||
if (config.mimo)
|
||||
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_TX(1), true));
|
||||
CHECK_STATUS(bladerf_sync_tx(dev, config.tx_samples, config.num_samples,
|
||||
&config.tx_meta, 5000));
|
||||
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_TX(0), false));
|
||||
}
|
||||
|
||||
if (config.rx) {
|
||||
printf("Streaming RX...\n");
|
||||
CHECK_STATUS(bladerf_sync_config(
|
||||
dev, (config.mimo == true) ? BLADERF_RX_X2 : BLADERF_RX_X1,
|
||||
config.format, config.num_buffers, config.buffer_size,
|
||||
config.num_transfers, config.timeout_ms));
|
||||
|
||||
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), true));
|
||||
if (config.mimo)
|
||||
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(1), true));
|
||||
|
||||
/* Retrieve the current timestamp */
|
||||
config.rx_meta.flags = 0;
|
||||
status = bladerf_get_timestamp(dev, BLADERF_RX, &config.rx_meta.timestamp);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "Failed to get current RX timestamp: %s\n",
|
||||
bladerf_strerror(status));
|
||||
} else {
|
||||
printf("Current RX timestamp: 0x%016" PRIx64 "\n", config.rx_meta.timestamp);
|
||||
}
|
||||
|
||||
/* Schedule first RX to be 0.1s in the future */
|
||||
config.rx_meta.timestamp += config.sample_rate / 10;
|
||||
printf("Scheduling RX for 0x%016" PRIx64 "\n", config.rx_meta.timestamp);
|
||||
|
||||
status = bladerf_sync_rx(dev, config.rx_samples, config.num_samples,
|
||||
&config.rx_meta, config.timeout_ms);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status));
|
||||
} else if (config.rx_meta.status & BLADERF_META_STATUS_OVERRUN) {
|
||||
fprintf(stderr, "Overrun detected. %u valid samples were read.\n",
|
||||
config.rx_meta.actual_count);
|
||||
print_bladerf_flag_statuses(config.rx_meta.status);
|
||||
} else {
|
||||
printf("RX'd %u samples at t=0x%016" PRIx64 "\n", config.rx_meta.actual_count,
|
||||
config.rx_meta.timestamp);
|
||||
}
|
||||
CHECK_STATUS(bladerf_enable_module(dev, BLADERF_CHANNEL_RX(0), false));
|
||||
}
|
||||
|
||||
error:
|
||||
if (config.tx_samples)
|
||||
free(config.tx_samples);
|
||||
if (config.rx_samples)
|
||||
free(config.rx_samples);
|
||||
if (dev)
|
||||
bladerf_close(dev);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
@ -746,8 +746,8 @@ available parameters.
|
|||
`bitmode` state
|
||||
|
||||
`samples` Number of samples per buffer to use in the
|
||||
asynchronous stream. Must be divisible by 1024 and
|
||||
>= 1024.
|
||||
asynchronous stream. Must be divisible by 2048 and
|
||||
>= 2048.
|
||||
|
||||
`buffers` Number of sample buffers to use in the asynchronous
|
||||
stream. The min value is 4.
|
||||
|
|
@ -935,8 +935,8 @@ available parameters.
|
|||
retransmitting file contents. 0 implies no delay.
|
||||
|
||||
`samples` Number of samples per buffer to use in the
|
||||
asynchronous stream. Must be divisible by 1024 and
|
||||
>= 1024.
|
||||
asynchronous stream. Must be divisible by 2048 and
|
||||
>= 2048.
|
||||
|
||||
`buffers` Number of sample buffers to use in the asynchronous
|
||||
stream. The min value is 4.
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ int cmd_generate(struct cli_state *s, int argc, char **argv)
|
|||
int mag = 2047;
|
||||
int i;
|
||||
|
||||
if (s->bit_mode_8bit) {
|
||||
if (s->sample_format == BLADERF_FORMAT_SC8_Q7) {
|
||||
mag /= 16;
|
||||
}
|
||||
int remaining_argc;
|
||||
|
|
|
|||
|
|
@ -1303,7 +1303,23 @@ out:
|
|||
int print_bitmode(struct cli_state *state, int argc, char **argv)
|
||||
{
|
||||
int rv = CLI_RET_OK;
|
||||
printf(" Bit Mode: %s bit samples\n", state->bit_mode_8bit ? "8" : "16");
|
||||
const char *mode_str;
|
||||
|
||||
switch (state->sample_format) {
|
||||
case BLADERF_FORMAT_SC16_Q11:
|
||||
mode_str = "16 bit";
|
||||
break;
|
||||
case BLADERF_FORMAT_SC16_Q11_PACKED:
|
||||
mode_str = "Packed 16 bit";
|
||||
break;
|
||||
case BLADERF_FORMAT_SC8_Q7:
|
||||
mode_str = "8 bit";
|
||||
break;
|
||||
default:
|
||||
mode_str = "Unknown";
|
||||
}
|
||||
|
||||
printf(" Bit Mode: %s samples\n", mode_str);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
@ -1321,7 +1337,7 @@ int set_bitmode(struct cli_state *state, int argc, char **argv)
|
|||
|
||||
if (argc != 3) {
|
||||
if (argc == 2) {
|
||||
printf(" Usage: %s %s <8|16>\n", argv[0], argv[1]);
|
||||
printf(" Usage: %s %s <8|16|packed>\n", argv[0], argv[1]);
|
||||
rv = CLI_RET_OK;
|
||||
goto out;
|
||||
} else {
|
||||
|
|
@ -1336,21 +1352,21 @@ int set_bitmode(struct cli_state *state, int argc, char **argv)
|
|||
printf(" Error: 16bit mode not permitted when\n"
|
||||
" over sampling is enabled.\n");
|
||||
goto out;
|
||||
} else if(state->bit_mode_8bit) {
|
||||
state->bit_mode_8bit = false;
|
||||
}
|
||||
|
||||
state->sample_format = BLADERF_FORMAT_SC16_Q11;
|
||||
} else if (!strcasecmp("8", argv[2]) || !strcasecmp("8bit", argv[2])) {
|
||||
if (!state->bit_mode_8bit) {
|
||||
if (strcmp(bladerf_get_board_name(state->dev), "bladerf2") != 0) {
|
||||
printf(" Error: BladeRF2 required for 8bit format\n");
|
||||
rv = CLI_RET_UNSUPPORTED;
|
||||
goto out;
|
||||
} else {
|
||||
state->bit_mode_8bit = true;
|
||||
}
|
||||
if (strcmp(bladerf_get_board_name(state->dev), "bladerf2") != 0) {
|
||||
printf(" Error: BladeRF2 required for 8bit format\n");
|
||||
rv = CLI_RET_UNSUPPORTED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
state->sample_format = BLADERF_FORMAT_SC8_Q7;
|
||||
} else if (!strcasecmp("packed", argv[2])) {
|
||||
state->sample_format = BLADERF_FORMAT_SC16_Q11_PACKED;
|
||||
} else {
|
||||
printf(" Usage: %s %s <8|16>\n", argv[0], argv[1]);
|
||||
printf(" Usage: %s %s <8|16|packed>\n", argv[0], argv[1]);
|
||||
rv = CLI_RET_UNSUPPORTED;
|
||||
goto out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ static int rx_write_csv(struct cli_state *s,
|
|||
|
||||
MUTEX_LOCK(&rx->file_mgmt.file_lock);
|
||||
|
||||
if (s->bit_mode_8bit) {
|
||||
if (s->sample_format == BLADERF_FORMAT_SC8_Q7) {
|
||||
samples_sc8q7 = (int8_t*)samples;
|
||||
// Output 2 columns for each enabled channel
|
||||
// (2 cols for BLADERF_RX_X1, 4 cols for BLADERF_RX_X2, etc)
|
||||
|
|
@ -311,7 +311,6 @@ void *rx_task(void *cli_state_arg)
|
|||
struct cli_state *cli_state = (struct cli_state *)cli_state_arg;
|
||||
struct rxtx_data *rx = cli_state->rx;
|
||||
struct rx_params *rx_params = rx->params;
|
||||
bladerf_format sync_fmt;
|
||||
|
||||
task_state = rxtx_get_state(rx);
|
||||
assert(task_state == RXTX_STATE_INIT);
|
||||
|
|
@ -370,12 +369,9 @@ void *rx_task(void *cli_state_arg)
|
|||
if (status == 0) {
|
||||
MUTEX_LOCK(&rx->data_mgmt.lock);
|
||||
|
||||
sync_fmt = cli_state->bit_mode_8bit ?
|
||||
BLADERF_FORMAT_SC8_Q7 : BLADERF_FORMAT_SC16_Q11;
|
||||
|
||||
status = bladerf_sync_config(
|
||||
cli_state->dev, rx->data_mgmt.layout,
|
||||
sync_fmt, rx->data_mgmt.num_buffers,
|
||||
cli_state->sample_format, rx->data_mgmt.num_buffers,
|
||||
rx->data_mgmt.samples_per_buffer,
|
||||
rx->data_mgmt.num_transfers, rx->data_mgmt.timeout_ms);
|
||||
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ enum rxtx_fmt rxtx_str2fmt(const char *str, struct cli_state *s)
|
|||
if (!strcasecmp("csv", str)) {
|
||||
ret = RXTX_FMT_CSV;
|
||||
} else if (!strcasecmp("bin", str)) {
|
||||
ret = (s->bit_mode_8bit) ? RXTX_FMT_BIN_SC8Q7 : RXTX_FMT_BIN_SC16Q11;
|
||||
ret = (s->sample_format == BLADERF_FORMAT_SC8_Q7) ? RXTX_FMT_BIN_SC8Q7 : RXTX_FMT_BIN_SC16Q11;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ static int tx_csv_to_bladerf_format(struct cli_state *s)
|
|||
int max_val = SC16Q11_IQ_MAX;
|
||||
|
||||
// 16 bit samples are 2*int8_t samples wide
|
||||
int sample_size = s->bit_mode_8bit ? 1 : 2;
|
||||
int sample_size = (s->sample_format == BLADERF_FORMAT_SC8_Q7) ? 1 : 2;
|
||||
int status;
|
||||
|
||||
assert(tx->file_mgmt.path != NULL);
|
||||
|
|
@ -268,7 +268,7 @@ static int tx_csv_to_bladerf_format(struct cli_state *s)
|
|||
}
|
||||
|
||||
|
||||
if (s->bit_mode_8bit) {
|
||||
if (s->sample_format == BLADERF_FORMAT_SC8_Q7) {
|
||||
min_val = SC8Q7_IQ_MIN;
|
||||
max_val = SC8Q7_IQ_MAX;
|
||||
}
|
||||
|
|
@ -332,7 +332,7 @@ static int tx_csv_to_bladerf_format(struct cli_state *s)
|
|||
tx->file_mgmt.format = RXTX_FMT_BIN_SC16Q11;
|
||||
|
||||
if (n_clamped != 0) {
|
||||
if (s->bit_mode_8bit) {
|
||||
if (s->sample_format == BLADERF_FORMAT_SC8_Q7) {
|
||||
printf(" Warning: %zu value%s clamped within DAC SC8 Q7 "
|
||||
"range of [%d, %d].\n",
|
||||
n_clamped, 1 == n_clamped ? "" : "s", SC8Q7_IQ_MIN,
|
||||
|
|
@ -375,7 +375,6 @@ void *tx_task(void *cli_state_arg)
|
|||
enum rxtx_state task_state;
|
||||
struct cli_state *cli_state = (struct cli_state *)cli_state_arg;
|
||||
struct rxtx_data *tx = cli_state->tx;
|
||||
bladerf_format sync_fmt;
|
||||
|
||||
/* We expect to be in the IDLE state when this is kicked off. We could
|
||||
* also get into the shutdown state if the program exits before we
|
||||
|
|
@ -408,13 +407,10 @@ void *tx_task(void *cli_state_arg)
|
|||
assert(tx->file_mgmt.file != NULL);
|
||||
MUTEX_UNLOCK(&tx->file_mgmt.file_meta_lock);
|
||||
|
||||
sync_fmt = cli_state->bit_mode_8bit ?
|
||||
BLADERF_FORMAT_SC8_Q7 : BLADERF_FORMAT_SC16_Q11;
|
||||
|
||||
/* Initialize the TX synchronous data configuration */
|
||||
status = bladerf_sync_config(
|
||||
cli_state->dev, tx->data_mgmt.layout,
|
||||
sync_fmt, tx->data_mgmt.num_buffers,
|
||||
cli_state->sample_format, tx->data_mgmt.num_buffers,
|
||||
tx->data_mgmt.samples_per_buffer,
|
||||
tx->data_mgmt.num_transfers, tx->data_mgmt.timeout_ms);
|
||||
|
||||
|
|
@ -487,7 +483,7 @@ static int tx_cmd_start(struct cli_state *s)
|
|||
status = tx_csv_to_bladerf_format(s);
|
||||
|
||||
if (status == 0) {
|
||||
if (s->bit_mode_8bit) {
|
||||
if (s->sample_format == BLADERF_FORMAT_SC8_Q7) {
|
||||
printf(" Converted CSV to SC8 Q7 file and "
|
||||
"switched to converted file.\n\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ struct cli_state *cli_state_create()
|
|||
cli_state->dev = NULL;
|
||||
cli_state->last_lib_error = 0;
|
||||
cli_state->scripts = NULL;
|
||||
cli_state->bit_mode_8bit = false;
|
||||
cli_state->sample_format = BLADERF_FORMAT_SC16_Q11;
|
||||
|
||||
cli_state->dev_info.fpga_size = BLADERF_FPGA_UNKNOWN;
|
||||
cli_state->dev_info.is_bladerf_x40_x115 = false;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ struct cli_state {
|
|||
struct rxtx_data *rx; /**< Data for sample reception */
|
||||
struct rxtx_data *tx; /**< Data for sample transmission */
|
||||
|
||||
bool bit_mode_8bit; /**< Bit mode is set to 16 bits */
|
||||
bladerf_format sample_format; /**< Sample format */
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue