Skip to content

Commit

Permalink
make channel_estimator output blk_exp together with IQ data (#21)
Browse files Browse the repository at this point in the history
IQ constellation diagram of test_receiver.py looks good now
  • Loading branch information
catkira committed May 25, 2023
1 parent aef8483 commit 8376632
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
37 changes: 19 additions & 18 deletions hdl/channel_estimator.sv
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module channel_estimator #(
parameter IN_DW = 32, // input data width
parameter BLK_EXP_LEN = 8,
localparam OUT_DW = IN_DW,
localparam NFFT = 8,
localparam FFT_LEN = 2 ** NFFT,
Expand All @@ -12,13 +13,13 @@ module channel_estimator #(
input clk_i,
input reset_ni,
input wire [IN_DW - 1 : 0] s_axis_in_tdata,
input wire s_axis_in_tuser, // 1 bit, 1 -> PBCH message, 0 -> other
input wire [BLK_EXP_LEN + 1 - 1 : 0] s_axis_in_tuser, // bit 0: 1 -> PBCH message, 0 -> other
input s_axis_in_tvalid,
input wire [$clog2(MAX_CELL_ID) - 1: 0] N_id_i,
input N_id_valid_i,

output reg [OUT_DW - 1 : 0] m_axis_out_tdata,
output reg [1 : 0] m_axis_out_tuser, // 2 bits, 1 -> PBCH message, 0 -> other
output reg [BLK_EXP_LEN + 2 - 1 : 0] m_axis_out_tuser, // bit 0-1: symbol type, bit 2: BLK_EXP
output reg m_axis_out_tlast,
output reg m_axis_out_tvalid,

Expand Down Expand Up @@ -229,7 +230,7 @@ always @(posedge clk_i) begin
case (state_det_ibar)
0: begin
debug_ibar_SSB_valid_o <= 0;
if (s_axis_in_tuser && PBCH_DMRS_ready) begin
if (s_axis_in_tuser[0] && PBCH_DMRS_ready) begin
pilots_ready <= '0;
state_det_ibar <= 1;
PBCH_sym_idx <= '0;
Expand Down Expand Up @@ -298,13 +299,13 @@ end
reg [IN_DW - 1 : 0] in_fifo_data;
reg in_fifo_valid;
// wire in_fifo_ready;
reg in_fifo_user;
reg [BLK_EXP_LEN + 1 - 1 : 0] in_fifo_user;
localparam EXTRA_LEN = FFT_LEN; // for the atan2 latency, FIFO_LEN has to be power of 2, therefore increase by FFT_LEN !
reg [$clog2(FFT_LEN + EXTRA_LEN) - 1 : 0] in_fifo_level;
AXIS_FIFO #(
.DATA_WIDTH(IN_DW),
.FIFO_LEN(FFT_LEN + EXTRA_LEN),
.USER_WIDTH(1),
.USER_WIDTH(BLK_EXP_LEN + 1),
.ASYNC(0)
)
data_FIFO_i(
Expand Down Expand Up @@ -405,7 +406,7 @@ localparam SYMS_PER_PBCH = 3;
localparam SYMS_PER_OTHER = 3;
reg [IN_DW - 1 : 0] corr_data_fifo_in_data;
reg corr_data_fifo_in_valid;
reg [1 : 0] corr_data_fifo_in_tuser;
reg [BLK_EXP_LEN + 1 : 0] corr_data_fifo_in_tuser;
reg corr_data_fifo_in_last;

wire in_fifo_ready = angle_FIFO_valid && in_fifo_valid && (SC_cnt != FFT_LEN - ZERO_CARRIERS) && (state_corrector != WAIT_FOR_INPUTS);
Expand Down Expand Up @@ -447,13 +448,13 @@ always @(posedge clk_i) begin
end else if (in_fifo_valid && PBCH_DMRS_ready) begin
// in_fifo_user signals start of a new burst if its != 0
// the symbol type depends on the position of the set bit
if ((in_fifo_user == 1) && pilots_ready) begin // pilots become ready withing 256 clks, so we can wait here, FIFOs are large enough
if ((in_fifo_user[0] == 1) && pilots_ready) begin // pilots become ready withing 256 clks, so we can wait here, FIFOs are large enough
$display("calculate_phase: PBCH symbol");
remaining_syms <= SYMS_PER_PBCH - 1;
symbol_type <= SYMBOL_TYPE_PBCH;
state_corrector <= CALC_CORRECTION;
ibar_SSB_buf <= ibar_SSB_detected;
end else if (in_fifo_user == 0) begin
end else if (in_fifo_user[0] == 0) begin
// $display("calculate_phase: data symbol");
remaining_syms <= SYMS_PER_OTHER - 1;
symbol_type <= SYMBOL_TYPE_OTHER;
Expand Down Expand Up @@ -524,7 +525,7 @@ always @(posedge clk_i) begin
end
end else begin
corr_data_fifo_in_last <= '0;
corr_data_fifo_in_tuser <= symbol_type;
corr_data_fifo_in_tuser <= {in_fifo_user[BLK_EXP_LEN : 1], symbol_type};
SC_cnt <= SC_cnt + 1;
end
end else begin
Expand Down Expand Up @@ -561,7 +562,7 @@ always @(posedge clk_i) begin
state_corrector <= WAIT_FOR_INPUTS;
end else begin
corr_data_fifo_in_last <= '0;
corr_data_fifo_in_tuser <= symbol_type;
corr_data_fifo_in_tuser <= {in_fifo_user[BLK_EXP_LEN : 1], symbol_type};
SC_cnt <= SC_cnt + 1;
end
end
Expand Down Expand Up @@ -631,11 +632,11 @@ reg corr_data_fifo_out_empty;
wire corr_data_fifo_out_ready;
reg corr_data_fifo_out_last;
reg [$clog2(FFT_LEN) - 1 : 0] corr_data_fifo_out_level;
reg [1 : 0] corr_data_fifo_out_symbol_type;
reg [BLK_EXP_LEN + 1 : 0] corr_data_fifo_out_user;
AXIS_FIFO #(
.DATA_WIDTH(IN_DW),
.FIFO_LEN(FFT_LEN),
.USER_WIDTH(2),
.USER_WIDTH(BLK_EXP_LEN + 2),
.ASYNC(0)
)
corr_data_fifo_i(
Expand All @@ -651,7 +652,7 @@ corr_data_fifo_i(
.m_axis_out_tdata(corr_data_fifo_out_data),
.m_axis_out_tvalid(corr_data_fifo_out_valid),
.m_axis_out_tempty(corr_data_fifo_out_empty),
.m_axis_out_tuser(corr_data_fifo_out_symbol_type),
.m_axis_out_tuser(corr_data_fifo_out_user),
.m_axis_out_tlast(corr_data_fifo_out_last),
.m_axis_out_tlevel(corr_data_fifo_out_level)
);
Expand All @@ -661,21 +662,21 @@ corr_data_fifo_i(
localparam COMPLEX_MULT_DELAY = 6;
localparam CORR_DATA_DELAY = 4 - 1;
localparam CORR_DELAY = CORR_DATA_DELAY + COMPLEX_MULT_DELAY;
reg [1 : 0] symbol_type_delayed [0 : CORR_DELAY - 1];
reg [BLK_EXP_LEN + 1 : 0] user_delayed [0 : CORR_DELAY - 1];
reg tlast_delayed [0 : CORR_DELAY - 1];
assign m_axis_out_tuser = symbol_type_delayed[CORR_DELAY - 1];
assign m_axis_out_tuser = user_delayed[CORR_DELAY - 1];
assign m_axis_out_tlast = tlast_delayed[CORR_DELAY - 1];
always @(posedge clk_i) begin
if (!reset_ni) begin
for (integer i = 0; i < CORR_DELAY; i = i + 1) begin
symbol_type_delayed[i] <= '0;
user_delayed[i] <= '0;
tlast_delayed[i] <= '0;
end
end else begin
symbol_type_delayed[0] <= corr_data_fifo_out_symbol_type;
user_delayed[0] <= corr_data_fifo_out_user;
tlast_delayed[0] <= corr_data_fifo_out_last;
for (integer i = 0; i < CORR_DELAY - 1; i = i + 1) begin
symbol_type_delayed[i + 1] <= symbol_type_delayed[i];
user_delayed[i + 1] <= user_delayed[i];
tlast_delayed[i + 1] <= tlast_delayed[i];
end
end
Expand Down
9 changes: 5 additions & 4 deletions hdl/receiver.sv
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module receiver
output SSS_valid_o,

output [FFT_OUT_DW - 1 : 0] m_axis_cest_out_tdata,
output [1 : 0] m_axis_cest_out_tuser,
output [BLK_EXP_LEN + 1 : 0] m_axis_cest_out_tuser,
output m_axis_cest_out_tlast,
output m_axis_cest_out_tvalid,

Expand Down Expand Up @@ -664,15 +664,16 @@ assign N_id_o = N_id;
assign N_id_valid_o = N_id_valid;

channel_estimator #(
.IN_DW(FFT_OUT_DW)
.IN_DW(FFT_OUT_DW),
.BLK_EXP_LEN(BLK_EXP_LEN)
)
channel_estimator_i(
.clk_i(clk_i),
.reset_ni(reset_fft_demod_n),
.N_id_i(N_id),
.N_id_valid_i(N_id_valid),
.s_axis_in_tdata(fft_demod_out_tdata),
.s_axis_in_tuser(fft_demod_out_tuser[0]),
.s_axis_in_tuser(fft_demod_out_tuser[BLK_EXP_LEN + 1 - 1: 0]),
.s_axis_in_tvalid(fft_demod_out_tvalid),

.m_axis_out_tdata(m_axis_cest_out_tdata),
Expand All @@ -699,7 +700,7 @@ demap_i(
.reset_ni(reset_fft_demod_n),

.s_axis_in_tdata(m_axis_cest_out_tdata),
.s_axis_in_tuser(m_axis_cest_out_tuser),
.s_axis_in_tuser(m_axis_cest_out_tuser[1 : 0]),
.s_axis_in_tlast(m_axis_cest_out_tlast),
.s_axis_in_tvalid(m_axis_cest_out_tvalid),

Expand Down
13 changes: 7 additions & 6 deletions tests/test_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,27 @@ async def simple_test(dut):
if dut.m_axis_llr_out_tvalid.value == 1 and dut.m_axis_llr_out_tuser.value == 1:
received_PBCH_LLR.append(_twos_comp(dut.m_axis_llr_out_tdata.value.integer & (2 ** (tb.LLR_DW) - 1), tb.LLR_DW))

if dut.m_axis_cest_out_tvalid.value == 1 and dut.m_axis_cest_out_tuser.value == 1:
corrected_PBCH.append(_twos_comp(dut.m_axis_cest_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
+ 1j * _twos_comp((dut.m_axis_cest_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2))
if dut.m_axis_cest_out_tvalid.value == 1 and ((dut.m_axis_cest_out_tuser.value & 0x03) == 1):
blk_exp = dut.m_axis_cest_out_tuser.value.integer >> 2
corrected_PBCH.append((_twos_comp(dut.m_axis_cest_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
+ 1j * _twos_comp((dut.m_axis_cest_out_tdata.value.integer >> (FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)) / (2 ** blk_exp))

if dut.PBCH_valid_o.value.integer == 1:
# print(f"rx PBCH[{len(received_PBCH):3d}] re = {dut.m_axis_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1):4x} " \
# "im = {(dut.m_axis_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1):4x}")
received_PBCH.append(_twos_comp(dut.m_axis_demod_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
+ 1j * _twos_comp((dut.m_axis_demod_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2))
+ 1j * _twos_comp((dut.m_axis_demod_out_tdata.value.integer >> (FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2))

if dut.SSS_valid_o.value.integer == 1:
received_SSS.append(_twos_comp(dut.m_axis_demod_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
+ 1j * _twos_comp((dut.m_axis_demod_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2))
+ 1j * _twos_comp((dut.m_axis_demod_out_tdata.value.integer >> (FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2))

if dut.m_axis_out_tvalid.value.integer:
if rgs_sc_idx < 1 + NUM_TIMESTAMP_SAMPLES:
received_rgs[num_rgs_symbols, rgs_sc_idx] = dut.m_axis_out_tdata.value.integer
else:
received_rgs[num_rgs_symbols, rgs_sc_idx] = _twos_comp(dut.m_axis_out_tdata.value.integer & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2) \
+ 1j * _twos_comp((dut.m_axis_out_tdata.value.integer>>(FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
+ 1j * _twos_comp((dut.m_axis_out_tdata.value.integer >> (FFT_OUT_DW//2)) & (2**(FFT_OUT_DW//2) - 1), FFT_OUT_DW//2)
if dut.m_axis_out_tlast.value.integer:
num_rgs_symbols += 1
assert rgs_sc_idx == RGS_TRANSFER_LEN - 1, print('Error: received from number of bytes from ressource_grid_subscriber!')
Expand Down

0 comments on commit 8376632

Please sign in to comment.