]> Joshua Wise's Git repositories - poslink.git/blame_incremental - POSLink.v
ucf and makefile fixes
[poslink.git] / POSLink.v
... / ...
CommitLineData
1module POSLink(
2 input xtal,
3 input [3:0] tos_inputs_e2,
4 input serial_e2,
5 input [1:0] buttons,
6 output tos_output,
7 output reg data_output,
8 output reg [3:0] anode,
9 output reg [7:0] cathode);
10
11 reg [3:0] tos_inputs_e;
12 reg [3:0] tos_inputs;
13 reg serial_e;
14 reg serial;
15
16 wire [3:0] tos_good;
17
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;
23 serial <= serial_e;
24 end
25
26 wire [11:0] data;
27 wire data_good;
28
29 reg [1:0] seg;
30
31 always @(*)
32 case (seg)
33 2'b00: anode = 4'b0111;
34 2'b01: anode = 4'b1011;
35 2'b10: anode = 4'b1101;
36 2'b11: anode = 4'b1110;
37 endcase
38
39 reg [1:0] tos_select;
40
41wire [4:0] edge_counter;
42 wire [3:0] current_bit;
43
44 assign tos_output = tos_inputs_e2[tos_select];
45
46 always @(*) begin
47 cathode = data[7:0];
48 seg = data[9:8];
49 tos_select = data[11:10];
50 end
51
52 wire [7:0] output_stuff = { 2'b0, buttons, tos_good };
53
54 always @(*)
55 data_output = output_stuff[current_bit[2:0]];
56
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));
59endmodule
60
61
62module POS_Serial(
63 input xtal,
64 input serial,
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);
69
70 reg serial_1a;
71
72 always @(posedge xtal)
73 serial_1a <= serial;
74
75 wire edge_detect = serial ^ serial_1a;
76
77
78 always @(posedge xtal) begin
79 data_good <= 0;
80
81 if (edge_detect) begin
82 if (edge_counter == 31) begin
83 current_bit <= 0;
84// data_reg <= 0;
85 end else 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
90 current_bit <= 0;
91 end else
92 current_bit <= current_bit + 1;
93 end
94
95 edge_counter <= 0;
96 end else begin
97 if (edge_counter != 31)
98 edge_counter <= edge_counter + 1;
99 end
100 end
101endmodule
102
103
104/* xtal: 25MHz (==40ns)
105 * Minimum: 100ns
106 * 2 cycles (80 ns)
107 * Maximum: 1000ns
108 * 25 cycles (we'll allow 30 = 1200ns for good measure)
109 */
110module TOS_Detect(
111 input xtal,
112 input tos_input,
113 output reg tos_good = 0);
114
115 reg tos_input_1a = 0;
116 always @(posedge xtal)
117 tos_input_1a <= tos_input;
118 wire transition = tos_input ^ tos_input_1a;
119
120 reg [3:0] lasttx = 0;
121 always @(posedge xtal) begin
122 if (transition) begin
123 if (lasttx < 2) /* Too soon! */
124 tos_good <= 0;
125 else if (lasttx > 30) /* Too late! */
126 tos_good <= 0;
127 else /* OK by me. */
128 tos_good <= 1;
129 lasttx <= 0;
130 end else begin
131 if (lasttx != 31)
132 lasttx <= lasttx + 1;
133 else
134 tos_good <= 0;
135 end
136 end
137endmodule
138
This page took 0.018446 seconds and 4 git commands to generate.