]> git.zerfleddert.de Git - proxmark3-svn/blame - fpga/lo_simulate.v
marcan's patch until he gets commit access. Remove C library's includes from the...
[proxmark3-svn] / fpga / lo_simulate.v
CommitLineData
6658905f 1//-----------------------------------------------------------------------------\r
2// The way that we connect things in low-frequency simulation mode. In this\r
3// case just pass everything through to the ARM, which can bit-bang this\r
4// (because it is so slow).\r
5//\r
6// Jonathan Westhues, April 2006\r
7//-----------------------------------------------------------------------------\r
8\r
9module lo_simulate(\r
10 pck0, ck_1356meg, ck_1356megb,\r
11 pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4,\r
12 adc_d, adc_clk,\r
13 ssp_frame, ssp_din, ssp_dout, ssp_clk,\r
14 cross_hi, cross_lo,\r
802a3616 15 dbg,
16 divisor\r
6658905f 17);\r
18 input pck0, ck_1356meg, ck_1356megb;\r
19 output pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4;\r
20 input [7:0] adc_d;\r
21 output adc_clk;\r
22 input ssp_dout;\r
23 output ssp_frame, ssp_din, ssp_clk;\r
24 input cross_hi, cross_lo;\r
802a3616 25 output dbg;
26 input [7:0] divisor;\r
6658905f 27\r
28// No logic, straight through.\r
29assign pwr_oe3 = 1'b0;\r
30assign pwr_oe1 = ssp_dout;\r
31assign pwr_oe2 = ssp_dout;\r
32assign pwr_oe4 = ssp_dout;\r
33assign ssp_clk = cross_lo;\r
34assign pwr_lo = 1'b0;\r
6658905f 35assign pwr_hi = 1'b0;\r
802a3616 36assign dbg = ssp_frame;\r
37
38// Divide the clock to be used for the ADC
39reg [7:0] pck_divider;
40reg clk_state;
41\r
42always @(posedge pck0)\r
43begin\r
44 if(pck_divider == divisor[7:0])\r
45 begin\r
46 pck_divider <= 8'd0;
47 clk_state = !clk_state;\r
48 end\r
49 else\r
50 begin\r
51 pck_divider <= pck_divider + 1;\r
52 end\r
53end\r
54
55assign adc_clk = ~clk_state;
56
57// Toggle the output with hysteresis
58// Set to high if the ADC value is above 200
59// Set to low if the ADC value is below 64
60reg is_high;
61reg is_low;
62reg output_state;
63
64always @(posedge pck0)\r
65begin\r
66 if((pck_divider == 8'd7) && !clk_state) begin
67 is_high = (adc_d >= 8'd200);
68 is_low = (adc_d <= 8'd64);
69 end
70end
71
72always @(posedge is_high or posedge is_low)
73begin
74 if(is_high)
75 output_state <= 1'd1;
76 else if(is_low)
77 output_state <= 1'd0;
78end
79
80assign ssp_frame = output_state;
6658905f 81\r
82endmodule\r
Impressum, Datenschutz