1 //-----------------------------------------------------------------------------
3 // Jonathan Westhues, April 2006
4 //-----------------------------------------------------------------------------
6 module hi_read_rx_xcorr(
7 pck0, ck_1356meg, ck_1356megb,
8 pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4,
10 ssp_frame, ssp_din, ssp_dout, ssp_clk,
15 input pck0, ck_1356meg, ck_1356megb;
16 output pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4;
20 output ssp_frame, ssp_din, ssp_clk;
21 input cross_hi, cross_lo;
23 input xcorr_is_848, snoop;
25 // Carrier is steady on through this, unless we're snooping.
26 assign pwr_hi = ck_1356megb & (~snoop);
27 assign pwr_oe1 = 1'b0;
28 assign pwr_oe2 = 1'b0;
29 assign pwr_oe3 = 1'b0;
30 assign pwr_oe4 = 1'b0;
36 always @(posedge ck_1356meg)
41 always @(xcorr_is_848 or fc_div_2 or ck_1356meg)
43 // The subcarrier frequency is fc/16; we will sample at fc, so that
44 // means the subcarrier is 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 ...
45 adc_clk <= ck_1356meg;
47 // The subcarrier frequency is fc/32; we will sample at fc/2, and
48 // the subcarrier will look identical.
51 // When we're a reader, we just need to do the BPSK demod; but when we're an
52 // eavesdropper, we also need to pick out the commands sent by the reader,
53 // using AM. Do this the same way that we do it for the simulated tag.
54 reg after_hysteresis, after_hysteresis_prev;
55 reg [11:0] has_been_low_for;
56 always @(negedge adc_clk)
58 if(& adc_d[7:0]) after_hysteresis <= 1'b1;
59 else if(~(| adc_d[7:0])) after_hysteresis <= 1'b0;
63 has_been_low_for <= 7'b0;
67 if(has_been_low_for == 12'd4095)
69 has_been_low_for <= 12'd0;
70 after_hysteresis <= 1'b1;
73 has_been_low_for <= has_been_low_for + 1;
77 // Let us report a correlation every 4 subcarrier cycles, or 4*16 samples,
78 // so we need a 6-bit counter.
81 // And a couple of registers in which to accumulate the correlations.
82 reg signed [15:0] corr_i_accum;
83 reg signed [15:0] corr_q_accum;
84 reg signed [7:0] corr_i_out;
85 reg signed [7:0] corr_q_out;
87 // ADC data appears on the rising edge, so sample it on the falling edge
88 always @(negedge adc_clk)
90 // These are the correlators: we correlate against in-phase and quadrature
91 // versions of our reference signal, and keep the (signed) result to
92 // send out later over the SSP.
93 if(corr_i_cnt == 7'd63)
97 corr_i_out <= {corr_i_accum[12:6], after_hysteresis_prev};
98 corr_q_out <= {corr_q_accum[12:6], after_hysteresis};
102 // Only correlations need to be delivered.
103 corr_i_out <= corr_i_accum[13:6];
104 corr_q_out <= corr_q_accum[13:6];
107 corr_i_accum <= adc_d;
108 corr_q_accum <= adc_d;
115 corr_i_accum <= corr_i_accum - adc_d;
117 corr_i_accum <= corr_i_accum + adc_d;
120 corr_q_accum <= corr_q_accum - adc_d;
122 corr_q_accum <= corr_q_accum + adc_d;
124 corr_i_cnt <= corr_i_cnt + 1;
125 corr_q_cnt <= corr_q_cnt + 1;
128 // The logic in hi_simulate.v reports 4 samples per bit. We report two
129 // (I, Q) pairs per bit, so we should do 2 samples per pair.
130 if(corr_i_cnt == 6'd31)
131 after_hysteresis_prev <= after_hysteresis;
133 // Then the result from last time is serialized and send out to the ARM.
134 // We get one report each cycle, and each report is 16 bits, so the
135 // ssp_clk should be the adc_clk divided by 64/16 = 4.
137 if(corr_i_cnt[1:0] == 2'b10)
140 if(corr_i_cnt[1:0] == 2'b00)
143 // Don't shift if we just loaded new data, obviously.
144 if(corr_i_cnt != 7'd0)
146 corr_i_out[7:0] <= {corr_i_out[6:0], corr_q_out[7]};
147 corr_q_out[7:1] <= corr_q_out[6:0];
151 if(corr_i_cnt[5:2] == 4'b000 || corr_i_cnt[5:2] == 4'b1000)
158 assign ssp_din = corr_i_out[7];
160 assign dbg = corr_i_cnt[3];
163 assign pwr_lo = 1'b0;