+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// FPGA <-> ARM communication:
+// generate a ssp clock and ssp frame signal for the synchronous transfer from/to the ARM
+reg ssp_clk;
+reg ssp_frame;
+
+always @(negedge adc_clk)
+begin
+ if(mod_type == `SNIFFER)
+ // SNIFFER mode (ssp_clk = adc_clk / 8, ssp_frame clock = adc_clk / 64)):
+ begin
+ if(negedge_cnt[2:0] == 3'd0)
+ ssp_clk <= 1'b1;
+ if(negedge_cnt[2:0] == 3'd4)
+ ssp_clk <= 1'b0;
+
+ if(negedge_cnt[5:0] == 6'd0) // ssp_frame rising edge indicates start of frame
+ ssp_frame <= 1'b1;
+ if(negedge_cnt[5:0] == 6'd8)
+ ssp_frame <= 1'b0;
+ end
+ else
+ // all other modes (ssp_clk = adc_clk / 16, ssp_frame clock = adc_clk / 128):
+ begin
+ if(negedge_cnt[3:0] == 4'd0)
+ ssp_clk <= 1'b1;
+ if(negedge_cnt[3:0] == 4'd8)
+ ssp_clk <= 1'b0;
+
+ if(negedge_cnt[6:0] == 7'd7) // ssp_frame rising edge indicates start of frame
+ ssp_frame <= 1'b1;
+ if(negedge_cnt[6:0] == 7'd23)
+ ssp_frame <= 1'b0;
+ end
+end
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// FPGA -> ARM communication:
+// select the data to be sent to ARM
+reg bit_to_arm;
+reg sendbit;
+
+always @(negedge adc_clk)
+begin
+ if(negedge_cnt[3:0] == 4'd0)
+ begin
+ // What do we communicate to the ARM
+ if(mod_type == `TAGSIM_LISTEN)
+ sendbit = after_hysteresis;
+ else if(mod_type == `TAGSIM_MOD)
+ /* if(fdt_counter > 11'd772) sendbit = mod_sig_coil; // huh?
+ else */
+ sendbit = fdt_indicator;
+ else if (mod_type == `READER_LISTEN)
+ sendbit = curbit;
+ else
+ sendbit = 1'b0;
+ end
+
+
+ if(mod_type == `SNIFFER)
+ // send sampled reader and tag data:
+ bit_to_arm = to_arm[7];
+ else if (mod_type == `TAGSIM_MOD && fdt_elapsed && temp_buffer_reset)
+ // send timing information:
+ bit_to_arm = to_arm[7];
+ else
+ // send data or fdt_indicator
+ bit_to_arm = sendbit;
+end
+
+
+
+
+assign ssp_din = bit_to_arm;