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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [sd_rx_gigmac.v] - Blame information for rev 29

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ghutchis
// mock-up of RX portion of gigabit ethernet MAC
2
// performs packet reception and creates internal
3
// packet codes, as well as checking CRC on incoming
4
// packets.
5
 
6
// incoming data is synchronous to "clk", which should
7
// be the GMII RX clock.  Output data is also synchronous
8
// to this clock, so needs to go through a sync FIFO.
9
 
10
// If output is not ready while receiving data,
11
// truncates the packet and makes it an error packet.
12
 
13
module sd_rx_gigmac
14
  (
15
   input        clk,
16
   input        reset,
17
   input        gmii_rx_dv,
18
   input [7:0]  gmii_rxd,
19
 
20
   output       rxg_srdy,
21
   input        rxg_drdy,
22
   output [1:0] rxg_code,
23
   output [7:0] rxg_data
24
   );
25
 
26
  reg           rxdv1, rxdv2;
27
  reg [7:0]      rxd1, rxd2;
28 24 ghutchis
  reg [31:0]    pkt_crc;
29 9 ghutchis
  reg [3:0]      valid_bits, nxt_valid_bits;
30 24 ghutchis
  reg [31:0]    nxt_pkt_crc;
31 9 ghutchis
 
32 24 ghutchis
  reg [6:0]      state, nxt_state;
33 9 ghutchis
  reg           ic_srdy;
34
  wire          ic_drdy;
35
  reg [1:0]      ic_code;
36
  reg [7:0]      ic_data;
37 24 ghutchis
  wire [31:0]   crc;
38 9 ghutchis
 
39 24 ghutchis
  reg           crc_valid;
40
  reg           crc_clear;
41
 
42
  mac_crc32 crc_chk
43
    (
44
     .clear                             (crc_clear),
45
     .data                              (rxd2),
46
     .valid                             (crc_valid),
47 9 ghutchis
 
48 24 ghutchis
     /*AUTOINST*/
49
     // Outputs
50
     .crc                               (crc[31:0]),
51
     // Inputs
52
     .clk                               (clk));
53 9 ghutchis
 
54
  always @(posedge clk)
55
    begin
56
      if (reset)
57
        begin
58
          rxd1  <= #1 0;
59
          rxdv1 <= #1 0;
60
          rxd2  <= #1 0;
61
          rxdv2 <= #1 0;
62 24 ghutchis
          pkt_crc <= #1 0;
63 9 ghutchis
        end
64
      else
65
        begin
66
          rxd1  <= #1 gmii_rxd;
67
          rxdv1 <= #1 gmii_rx_dv;
68
          rxd2  <= #1 rxd1;
69
          rxdv2 <= #1 rxdv1;
70 24 ghutchis
          pkt_crc <= #1 nxt_pkt_crc;
71 9 ghutchis
        end
72
    end // always @ (posedge clk)
73
 
74 24 ghutchis
  localparam s_idle = 0, s_preamble = 1, s_sop = 2, s_payload = 3, s_trunc = 4, s_sink = 5, s_eop = 6;
75 9 ghutchis
  localparam ns_idle = 1, ns_preamble = 2, ns_sop = 4, ns_payload = 8, ns_trunc = 16, ns_sink = 32;
76
 
77
  always @*
78
    begin
79
      ic_srdy = 0;
80
      ic_code = `PCC_DATA;
81
      ic_data = 0;
82
      nxt_valid_bits = valid_bits;
83 24 ghutchis
      nxt_pkt_crc = pkt_crc;
84
      crc_valid = 0;
85
      crc_clear = 0;
86 9 ghutchis
 
87
      case (1'b1)
88
        state[s_idle] :
89
          begin
90 24 ghutchis
            crc_clear = 1;
91 9 ghutchis
            nxt_pkt_crc  = 0;
92
            nxt_valid_bits = 0;
93
            if (rxdv2 & (rxd2 == `GMII_SFD))
94
              begin
95
                nxt_state = ns_sop;
96
              end
97
            else if (rxdv2)
98
              begin
99
                nxt_state = ns_preamble;
100
              end
101
          end // case: state[s_idle]
102
 
103
        state[s_preamble]:
104
          begin
105
            if (!rxdv2)
106
              nxt_state = ns_idle;
107
            else if (rxd2 == `GMII_SFD)
108
              nxt_state = ns_sop;
109
          end
110
 
111
        state[s_sop] :
112
          begin
113
            if (!rxdv2)
114
              begin
115
                nxt_state = ns_idle;
116
              end
117
            else if (!ic_drdy)
118
              nxt_state = ns_sink;
119
            else
120
              begin
121
                ic_srdy = 1;
122
                ic_code = `PCC_SOP;
123
                ic_data = rxd2;
124 24 ghutchis
                crc_valid = 1;
125
                nxt_pkt_crc = { rxd2, pkt_crc[31:8] };
126 9 ghutchis
                nxt_state = ns_payload;
127
              end
128
          end // case: state[ns_payload]
129
 
130
        state[s_payload] :
131
          begin
132
            if (!ic_drdy)
133
              nxt_state = ns_trunc;
134
            else if (!rxdv1)
135
              begin
136 24 ghutchis
                //nxt_state = ns_idle;
137
                ic_srdy = 0;
138 9 ghutchis
                ic_data = rxd2;
139 24 ghutchis
                crc_valid = 1;
140
                nxt_pkt_crc = { rxd2, pkt_crc[31:8] };
141
                nxt_state = 1 << s_eop;
142 9 ghutchis
              end
143
            else
144
              begin
145
                ic_srdy = 1;
146
                ic_code = `PCC_DATA;
147
                ic_data = rxd2;
148 24 ghutchis
                crc_valid = 1;
149
                nxt_pkt_crc = { rxd2, pkt_crc[31:8] };
150 9 ghutchis
              end // else: !if(!rxdv1)
151
          end // case: state[ns_payload]
152
 
153 24 ghutchis
 
154
        state[s_eop] :
155
          begin
156
            ic_srdy =1;
157
            ic_data = pkt_crc[31:24];
158
            if (pkt_crc == crc)
159
              begin
160
                ic_code = `PCC_EOP;
161
              end
162
            else
163
              ic_code = `PCC_BADEOP;
164
 
165
            if (ic_drdy)
166
              nxt_state = 1 << s_idle;
167
          end
168
 
169 9 ghutchis
        state[s_trunc] :
170
          begin
171
            ic_srdy = 1;
172
            ic_code = `PCC_BADEOP;
173
            ic_data = 0;
174
            if (ic_drdy)
175
              nxt_state = ns_sink;
176
          end
177
 
178
        state[s_sink] :
179
          begin
180
            if (!rxdv2)
181
              nxt_state = ns_idle;
182
          end
183
 
184
        default : nxt_state = ns_idle;
185
      endcase // case (1'b1)    
186
    end // always @ *
187
 
188
  always @(posedge clk)
189
    begin
190
      if (reset)
191
        begin
192
          state <= #1 1;
193
          /*AUTORESET*/
194 24 ghutchis
          // Beginning of autoreset for uninitialized flops
195
          pkt_crc <= 32'h0;
196
          valid_bits <= 4'h0;
197
          // End of automatics
198 9 ghutchis
        end
199
      else
200
        begin
201
          pkt_crc  <= #1 nxt_pkt_crc;
202
          state    <= #1 nxt_state;
203
          valid_bits <= #1 nxt_valid_bits;
204
        end // else: !if(reset)
205
    end // always @ (posedge clk)
206
 
207
  sd_output #(8+2) out_hold
208
    (.clk (clk), .reset (reset),
209
     .ic_srdy (ic_srdy),
210
     .ic_drdy (ic_drdy),
211
     .ic_data ({ic_code,ic_data}),
212
     .p_srdy  (rxg_srdy),
213
     .p_drdy  (rxg_drdy),
214
     .p_data  ({rxg_code, rxg_data}));
215
 
216
endmodule // sd_rx_gigmac

powered by: WebSVN 2.1.0

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