2 `define DSP_CORE_RX_BASE 160
5 input set_stb, input [7:0] set_addr, input [31:0] set_data,
7 input [13:0] adc_a, input adc_ovf_a,
8 input [13:0] adc_b, input adc_ovf_b,
18 wire [15:0] scale_i, scale_q;
19 wire [13:0] adc_a_ofs, adc_b_ofs;
20 reg [13:0] adc_i, adc_q;
21 wire [31:0] phase_inc;
24 wire [35:0] prod_i, prod_q;
25 wire [23:0] i_cordic, q_cordic;
26 wire [23:0] i_cic, q_cic;
27 wire [17:0] i_cic_scaled, q_cic_scaled;
28 wire [17:0] i_hb1, q_hb1;
29 wire [17:0] i_hb2, q_hb2;
30 wire [15:0] i_out, q_out;
32 wire strobe_cic, strobe_hb1, strobe_hb2;
33 wire enable_hb1, enable_hb2;
34 wire [7:0] cic_decim_rate;
36 setting_reg #(.my_addr(`DSP_CORE_RX_BASE+0)) sr_0
37 (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
38 .in(set_data),.out(phase_inc),.changed());
40 setting_reg #(.my_addr(`DSP_CORE_RX_BASE+1)) sr_1
41 (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
42 .in(set_data),.out({scale_i,scale_q}),.changed());
44 setting_reg #(.my_addr(`DSP_CORE_RX_BASE+2)) sr_2
45 (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
46 .in(set_data),.out({enable_hb1, enable_hb2, cic_decim_rate}),.changed());
48 rx_dcoffset #(.WIDTH(14),.ADDR(`DSP_CORE_RX_BASE+6)) rx_dcoffset_a
49 (.clk(clk),.rst(rst),.set_stb(set_stb),.set_addr(set_addr),.set_data(set_data),
50 .adc_in(adc_a),.adc_out(adc_a_ofs));
52 rx_dcoffset #(.WIDTH(14),.ADDR(`DSP_CORE_RX_BASE+7)) rx_dcoffset_b
53 (.clk(clk),.rst(rst),.set_stb(set_stb),.set_addr(set_addr),.set_data(set_data),
54 .adc_in(adc_b),.adc_out(adc_b_ofs));
57 setting_reg #(.my_addr(`DSP_CORE_RX_BASE+8)) sr_8
58 (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
59 .in(set_data),.out(muxctrl),.changed());
62 setting_reg #(.my_addr(`DSP_CORE_RX_BASE+9)) sr_9
63 (.clk(clk),.rst(rst),.strobe(set_stb),.addr(set_addr),
64 .in(set_data),.out(gpio_ena),.changed());
66 // The TVRX connects to what is called adc_b, thus A and B are
67 // swapped throughout the design.
69 // In the interest of expediency and keeping the s/w sane, we just remap them here.
70 // The I & Q fields are mapped the same:
71 // 0 -> "the real A" (as determined by the TVRX)
76 case(muxctrl[1:0]) // The I mapping
77 0: adc_i <= adc_b_ofs; // "the real A"
78 1: adc_i <= adc_a_ofs;
81 endcase // case(muxctrl[1:0])
84 case(muxctrl[3:2]) // The Q mapping
85 0: adc_q <= adc_b_ofs; // "the real A"
86 1: adc_q <= adc_a_ofs;
89 endcase // case(muxctrl[3:2])
97 phase <= phase + phase_inc;
100 (.P(prod_i), // 36-bit multiplier output
101 .A({{4{adc_i[13]}},adc_i} ), // 18-bit multiplier input
102 .B({{2{scale_i[15]}},scale_i}), // 18-bit multiplier input
103 .C(clk), // Clock input
104 .CE(1), // Clock enable input
105 .R(rst) // Synchronous reset input
109 (.P(prod_q), // 36-bit multiplier output
110 .A({{4{adc_q[13]}},adc_q} ), // 18-bit multiplier input
111 .B({{2{scale_q[15]}},scale_q}), // 18-bit multiplier input
112 .C(clk), // Clock input
113 .CE(1), // Clock enable input
114 .R(rst) // Synchronous reset input
118 cordic_z24 #(.bitwidth(24))
119 cordic(.clock(clk), .reset(rst), .enable(run),
120 .xi(prod_i[23:0]),. yi(prod_q[23:0]), .zi(phase[31:8]),
121 .xo(i_cordic),.yo(q_cordic),.zo() );
123 cic_strober cic_strober(.clock(clk),.reset(rst),.enable(run),.rate(cic_decim_rate),
124 .strobe_fast(1),.strobe_slow(strobe_cic) );
127 decim_i (.clock(clk),.reset(rst),.enable(run),
128 .rate(cic_decim_rate),.strobe_in(1'b1),.strobe_out(strobe_cic),
129 .signal_in(i_cordic),.signal_out(i_cic));
132 decim_q (.clock(clk),.reset(rst),.enable(run),
133 .rate(cic_decim_rate),.strobe_in(1'b1),.strobe_out(strobe_cic),
134 .signal_in(q_cordic),.signal_out(q_cic));
136 round_reg #(.bits_in(24),.bits_out(18)) round_icic (.clk(clk),.in(i_cic),.out(i_cic_scaled));
137 round_reg #(.bits_in(24),.bits_out(18)) round_qcic (.clk(clk),.in(q_cic),.out(q_cic_scaled));
139 always @(posedge clk) strobe_cic_d1 <= strobe_cic;
141 small_hb_dec #(.WIDTH(18)) small_hb_i
142 (.clk(clk),.rst(rst),.bypass(~enable_hb1),
143 .stb_in(strobe_cic_d1),.data_in(i_cic_scaled),.stb_out(strobe_hb1),.data_out(i_hb1));
145 small_hb_dec #(.WIDTH(18)) small_hb_q
146 (.clk(clk),.rst(rst),.bypass(~enable_hb1),
147 .stb_in(strobe_cic_d1),.data_in(q_cic_scaled),.stb_out(),.data_out(q_hb1));
149 wire [8:0] cpi_hb = enable_hb1 ? {cic_decim_rate,1'b0} : {1'b0,cic_decim_rate};
150 hb_dec #(.IWIDTH(18), .OWIDTH(18), .CWIDTH(18), .ACCWIDTH(24)) hb_i
151 (.clk(clk),.rst(rst),.bypass(~enable_hb2),.cpi(cpi_hb),
152 .stb_in(strobe_hb1),.data_in(i_hb1),.stb_out(strobe_hb2),.data_out(i_hb2));
154 hb_dec #(.IWIDTH(18), .OWIDTH(18), .CWIDTH(18), .ACCWIDTH(24)) hb_q
155 (.clk(clk),.rst(rst),.bypass(~enable_hb2),.cpi(cpi_hb),
156 .stb_in(strobe_hb1),.data_in(q_hb1),.stb_out(),.data_out(q_hb2));
158 round #(.bits_in(18),.bits_out(16)) round_iout (.in(i_hb2),.out(i_out));
159 round #(.bits_in(18),.bits_out(16)) round_qout (.in(q_hb2),.out(q_out));
163 // io_rx[15] => I channel LSB if gpio_ena[0] high
164 // io_rx[14] => Q channel LSB if gpio_ena[1] high
166 reg [31:0] sample_reg;
167 always @(posedge clk)
169 sample_reg[31:17] <= i_out[15:1];
170 sample_reg[15:1] <= q_out[15:1];
171 sample_reg[16] <= gpio_ena[0] ? io_rx[15] : i_out[0];
172 sample_reg[0] <= gpio_ena[1] ? io_rx[14] : q_out[0];
175 assign sample = sample_reg;
176 assign strobe = strobe_hb2;
177 assign debug = {enable_hb1, enable_hb2, run, strobe, strobe_cic, strobe_cic_d1, strobe_hb1, strobe_hb2};
179 endmodule // dsp_core_rx