3 input [3:0] tos_inputs_e2,
7 output reg data_output,
8 output reg [3:0] anode,
9 output reg [7:0] cathode);
11 reg [3:0] tos_inputs_e;
18 /* Synchronize inputs */
19 always @(posedge xtal) begin
20 tos_inputs_e <= tos_inputs_e2;
21 tos_inputs <= tos_inputs_e;
22 serial_e <= serial_e2;
33 2'b00: anode = 4'b0111;
34 2'b01: anode = 4'b1011;
35 2'b10: anode = 4'b1101;
36 2'b11: anode = 4'b1110;
41 wire [4:0] edge_counter;
42 wire [3:0] current_bit;
44 assign tos_output = tos_inputs_e2[tos_select];
49 tos_select = data[11:10];
52 wire [5:0] output_stuff = { buttons, tos_good };
55 data_output = output_stuff[current_bit[2:0]];
57 TOS_Detect detect[3:0](.xtal(xtal), .tos_input(tos_inputs), .tos_good(tos_good));
58 POS_Serial serinput(.xtal(xtal), .serial(serial), .data_reg(data), .current_bit(current_bit), .data_good(data_good), .edge_counter(edge_counter));
65 output reg [11:0] data_reg = 0,
66 output reg [3:0] current_bit = 0,
67 output reg [4:0] edge_counter = 0,
68 output reg data_good = 0);
72 always @(posedge xtal)
75 wire edge_detect = serial ^ serial_1a;
78 always @(posedge xtal) begin
81 if (edge_detect) begin
82 if (edge_counter == 31) begin
86 // data_reg[11:1] = data_reg[10:0];
87 // data_reg[0] = (edge_counter > 20);
88 data_reg[current_bit] <= ((edge_counter > 20) ? 1'b1 : 1'b0);
89 if (current_bit == 11) begin
92 current_bit <= current_bit + 1;
97 if (edge_counter != 31)
98 edge_counter <= edge_counter + 1;
104 /* xtal: 25MHz (==40ns)
108 * 25 cycles (we'll allow 30 = 1200ns for good measure)
113 output reg tos_good = 0);
115 reg tos_input_1a = 0;
116 always @(posedge xtal)
117 tos_input_1a <= tos_input;
118 wire transition = tos_input ^ tos_input_1a;
120 reg [3:0] lasttx = 0;
121 always @(posedge xtal) begin
122 if (transition) begin
123 if (lasttx < 2) /* Too soon! */
125 else if (lasttx > 30) /* Too late! */
132 lasttx <= lasttx + 1;