OpenCores
URL https://opencores.org/ocsvn/cheap_ethernet/cheap_ethernet/trunk

Subversion Repositories cheap_ethernet

[/] [cheap_ethernet/] [trunk/] [Ethernet_test/] [TENBASET_RxD.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 graver
`timescale 1ns / 1ps
2
// 10BASE-T receiving interface (based on fpga4fun.com version)
3
module TENBASET_RxD(clk48,
4
        manchester_data_in,
5
        RcvData, RcvStart, RcvStop, new_bit_available, new_byte_available, end_of_Ethernet_frame,       sync2);
6
 
7
input clk48;
8
input manchester_data_in;
9
output [7:0] RcvData;
10
output RcvStart;
11
output RcvStop;
12
output new_bit_available;
13
output new_byte_available;
14
output end_of_Ethernet_frame;
15
output [9:0] sync2;
16
 
17
reg [7:0] RcvData = 0;
18
reg RcvStart = 0;
19
reg RcvStop = 0;
20
reg new_bit_available = 0;
21
reg end_of_Ethernet_frame = 0;
22
 
23
reg [2:0] in_data = 0;
24
reg [1:0] cnt = 0;
25
reg [2:0] transition_timeout = 0;
26
reg [4:0] sync1 = 0;
27
reg [9:0] sync2 = 0;
28
 
29
wire new_byte_available = ((new_bit_available) && (sync2[2:0] == 3'h0) && (sync2[9:3] != 0));
30
 
31
always @(posedge clk48) begin
32
        in_data <= {in_data[1:0], manchester_data_in};
33
        new_bit_available <= (cnt == 3);
34
        if (|cnt || (in_data[2] ^ in_data[1]))
35
                cnt <= cnt + 1;
36
        if (cnt == 3)
37
                RcvData <= {in_data[1], RcvData[7:1]};
38
end
39
 
40
/////////////////////////////////////////////////
41
always @(posedge clk48) begin
42
        if (end_of_Ethernet_frame)
43
                sync1 <= 0;
44
        else if (new_bit_available)
45
                begin
46
                if (!(RcvData == 8'h55 || RcvData == 8'hAA)) // not preamble?
47
                        sync1 <= 0;
48
                else if (~&sync1) // if all bits of this "sync1" counter are one, we decide that enough of the preamble
49
                                                         // has been received, so stop counting and wait for "sync2" to detect the SFD
50
                        sync1 <= sync1 + 1; // otherwise keep counting
51
                end
52
end
53
 
54
always @(posedge clk48) begin
55
        RcvStart <= 0;
56
        if (end_of_Ethernet_frame)
57
                sync2 <= 0;
58
        else if (new_bit_available)
59
                begin
60
                if  (|sync2) // if the SFD has already been detected (Ethernet data is coming in)
61
                        begin
62
                        sync2 <= sync2 + 1; // then count the bits coming in
63
                        if (&sync2)
64
                                sync2 <= 8;
65
                        end
66
                else if (&sync1 && RcvData == 8'hD5) // otherwise, let's wait for the SFD (0xD5)
67
                        begin
68
                        RcvStart <= 1;
69
                        sync2 <= 1;
70
                        end
71
                end
72
end
73
 
74
/////////////////////////////////////////////////
75
// if no clock transistion is detected for some time, that's the end of the Ethernet frame
76
 
77
always @(posedge clk48) begin
78
        if (in_data[2] ^ in_data[1])
79
                transition_timeout <= 0;
80
        else if (~&cnt)
81
                transition_timeout <= transition_timeout + 1;
82
end
83
 
84
always @(posedge clk48) begin
85
        RcvStop <= 0;
86
        end_of_Ethernet_frame <= &transition_timeout;
87
        if (!end_of_Ethernet_frame && &transition_timeout && |sync2)
88
                RcvStop <= 1;
89
end
90
 
91
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.