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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [sd_tx_gigmac.v] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 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
// If output is not ready while receiving data,
7
// truncates the packet and makes it an error packet.
8
 
9
module sd_tx_gigmac
10
  (
11
   input        clk,
12
   input        reset,
13 11 ghutchis
   output reg        gmii_tx_en,
14 8 ghutchis
   output reg [7:0]  gmii_txd,
15
 
16
   input       txg_srdy,
17
   output      txg_drdy,
18
   input [1:0] txg_code,
19
   input [7:0] txg_data
20
   );
21
 
22
  wire         ip_srdy;
23
  reg          ip_drdy;
24
  wire [1:0]   ip_code;
25
  wire [7:0]   ip_data;
26
  reg [3:0]    count, nxt_count;
27
 
28
  reg [7:0]    nxt_gmii_txd;
29 11 ghutchis
  reg          nxt_gmii_tx_en;
30 24 ghutchis
  reg [5:0]    state, nxt_state;
31 8 ghutchis
 
32 24 ghutchis
  wire [31:0]  crc;
33
  reg          clear;
34
  reg          crc_valid;
35
 
36
  localparam s_idle = 0, s_preamble = 1, s_payload = 2, s_ipg = 3, s_badcrc = 4, s_goodcrc = 5;
37 8 ghutchis
  localparam ns_idle = 1, ns_preamble = 2, ns_payload = 4, ns_ipg = 8;
38
 
39
  sd_input #(8+2) in_hold
40
    (
41
     // Outputs
42
     .c_drdy                            (txg_drdy),
43
     .ip_srdy                           (ip_srdy),
44
     .ip_data                           ({ip_code,ip_data}),
45
     // Inputs
46
     .clk                               (clk),
47
     .reset                             (reset),
48
     .c_srdy                            (txg_srdy),
49
     .c_data                            ({txg_code,txg_data}),
50
     .ip_drdy                           (ip_drdy));
51
 
52 24 ghutchis
  mac_crc32 crcgen
53
    (
54
     .data                              (ip_data[7:0]),
55
     .valid                             (crc_valid),
56
     /*AUTOINST*/
57
     // Outputs
58
     .crc                               (crc[31:0]),
59
     // Inputs
60
     .clk                               (clk),
61
     .clear                             (clear));
62
 
63 8 ghutchis
  always @*
64
    begin
65
      ip_drdy = 0;
66
      nxt_count = count;
67 11 ghutchis
      nxt_gmii_tx_en = 0;
68 8 ghutchis
      nxt_gmii_txd = gmii_txd;
69 24 ghutchis
      clear = 0;
70
      crc_valid = 0;
71 8 ghutchis
 
72
      case (1'b1)
73
        state[s_idle] :
74
          begin
75
            if (ip_srdy & (ip_code == `PCC_SOP))
76
              begin
77 11 ghutchis
                nxt_gmii_tx_en = 1;
78 8 ghutchis
                nxt_gmii_txd = `GMII_PRE;
79
                nxt_count = 1;
80
                nxt_state = ns_preamble;
81 24 ghutchis
                clear = 1;
82 8 ghutchis
              end
83
            else
84
              begin
85
                ip_drdy = 1;
86
              end // else: !if(ip_srdy & (ip_code == `PCC_SOP))
87
          end // case: state[s_idle]
88
 
89
        state[s_preamble] :
90
          begin
91
            nxt_count = count + 1;
92 11 ghutchis
            nxt_gmii_tx_en = 1;
93 8 ghutchis
            if (count == 6)
94 11 ghutchis
              begin
95
                nxt_gmii_txd = `GMII_SFD;
96
                nxt_state = ns_payload;
97
              end
98 8 ghutchis
            else
99
              nxt_gmii_txd = `GMII_PRE;
100
          end // case: state[s_preamble]
101
 
102
        state[s_payload] :
103
          begin
104
            ip_drdy = 1;
105 11 ghutchis
            nxt_gmii_tx_en = 1;
106
            nxt_gmii_txd = ip_data;
107 24 ghutchis
            crc_valid = 1;
108 11 ghutchis
 
109 8 ghutchis
            if (!ip_srdy | ((ip_code == `PCC_EOP) | (ip_code == `PCC_BADEOP)))
110
              begin
111
                nxt_count = 0;
112 24 ghutchis
                if (ip_code == `PCC_EOP)
113
                  nxt_state = 1 << s_goodcrc;
114
                else
115
                  nxt_state = 1 << s_badcrc;
116 8 ghutchis
              end
117
          end // case: state[s_payload]
118
 
119 24 ghutchis
        state[s_goodcrc] :
120
          begin
121
            nxt_count = count + 1;
122
            nxt_gmii_tx_en = 1;
123
            case (count)
124
 
125
              1 : nxt_gmii_txd = crc[15:8];
126
              2 : nxt_gmii_txd = crc[23:16];
127
              3 : nxt_gmii_txd = crc[31:24];
128
            endcase // case (count)
129
 
130
            if (count == 3)
131
              begin
132
                nxt_state = 1 << s_ipg;
133
              end
134
          end
135
 
136
        state[s_badcrc] :
137
          begin
138
           nxt_count = count + 1;
139
            nxt_gmii_tx_en = 1;
140
            nxt_gmii_txd   = 8'h0;
141
 
142
            if (count == 3)
143
              begin
144
                nxt_state = 1 << s_ipg;
145
              end
146
          end
147
 
148 8 ghutchis
        state[s_ipg] :
149
          begin
150 11 ghutchis
            nxt_gmii_tx_en = 0;
151 8 ghutchis
            ip_drdy = 0;
152
            nxt_count = count + 1;
153
            if (count == 11)
154
              nxt_state = ns_idle;
155
          end
156
 
157
        default : nxt_state = ns_idle;
158
      endcase // case (1'b1)
159
    end // always @ *
160
 
161
  always @(posedge clk)
162
    begin
163
      if (reset)
164
        begin
165
          state <= #1 1;
166
          /*AUTORESET*/
167 11 ghutchis
          // Beginning of autoreset for uninitialized flops
168
          count <= 4'h0;
169
          gmii_tx_en <= 1'h0;
170
          gmii_txd <= 8'h0;
171
          // End of automatics
172 8 ghutchis
        end
173
      else
174
        begin
175
          state <= #1 nxt_state;
176
          count <= #1 nxt_count;
177 11 ghutchis
          gmii_tx_en <= #1 nxt_gmii_tx_en;
178 8 ghutchis
          gmii_txd   <= #1 nxt_gmii_txd;
179
        end // else: !if(reset)
180
    end // always @ (posedge clk)
181
 
182
endmodule // sd_rx_gigmac
183
// Local Variables:
184
// verilog-library-directories:("." "../../../rtl/verilog/closure" "../../../rtl/verilog/memory" "../../../rtl/verilog/forks")
185
// End:  

powered by: WebSVN 2.1.0

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