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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [port_ring_tap_fsm.v] - Blame information for rev 12

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

Line No. Rev Author Line
1 5 ghutchis
module port_ring_tap_fsm
2
  #(parameter rdp_sz = 64,
3 8 ghutchis
    parameter pdp_sz = 64,
4 5 ghutchis
    parameter portnum = 0)
5
  (
6
   input               clk,
7
   input               reset,
8
 
9
   output reg               lfli_drdy,
10
   output reg               lprx_drdy,
11 8 ghutchis
   output reg[pdp_sz-1:0]    lptx_data,
12 5 ghutchis
   output reg               lptx_srdy,
13
   output reg               lri_drdy,
14
   output reg[rdp_sz-1:0]    lro_data,
15
   output reg               lro_srdy,
16
 
17 8 ghutchis
   input [`NUM_PORTS-1:0]   lfli_data,
18 5 ghutchis
   input               lfli_srdy,
19 8 ghutchis
   input [pdp_sz-1:0]   lprx_data,
20 5 ghutchis
   input               lprx_srdy,
21
   input               lptx_drdy,
22
   input [rdp_sz-1:0]   lri_data,
23
   input               lri_srdy,
24 12 ghutchis
   input               lro_drdy,
25
 
26
   output              rarb_req,
27
   input               rarb_ack
28 5 ghutchis
   );
29
 
30 8 ghutchis
  reg [4:0]            state, nxt_state;
31 5 ghutchis
 
32
  wire [`NUM_PORTS-1:0] port_mask;
33 11 ghutchis
  //reg [`NUM_PORTS-1:0]  pe_vec, nxt_pe_vec;
34
  wire [`NUM_PORTS-1:0] nxt_pe_vec = lri_data[`PRW_DATA] & ~port_mask;
35 5 ghutchis
 
36
  assign port_mask = 1 << portnum;
37
 
38 8 ghutchis
  localparam s_idle = 0,
39
             s_rfwd = 1,
40
             s_rcopy = 2,
41
             s_rsink = 3,
42
             s_tdata = 4;
43
  localparam ns_idle = 1,
44
             ns_rfwd = 2,
45
             ns_rcopy = 4,
46
             ns_rsink = 8,
47
             ns_tdata = 16;
48 12 ghutchis
 
49
  assign rarb_req = lfli_srdy & lprx_srdy | state[s_tdata];
50 5 ghutchis
 
51
  always @*
52
    begin
53
      lro_data = lri_data;
54 8 ghutchis
      lptx_data = lri_data;
55
      lfli_drdy = 0;
56
      lprx_drdy = 0;
57
      lptx_srdy = 0;
58
      lri_drdy  = 0;
59
      lro_srdy  = 0;
60 12 ghutchis
      nxt_state = state;
61 5 ghutchis
 
62
      case (1'b1)
63
        state[s_idle] :
64
          begin
65 12 ghutchis
            if (lfli_srdy & lprx_srdy & rarb_ack)
66 5 ghutchis
              begin
67 8 ghutchis
                if (lfli_data != 0)
68
                  begin
69
                    lro_data = 0;
70
                    lro_data[`PRW_PVEC] = 1;
71
                    lro_data[`PRW_DATA] = lfli_data;
72
                    if (lro_drdy)
73
                      begin
74
                        lfli_drdy = 1;
75
                        lro_srdy = 1;
76
                        nxt_state = ns_tdata;
77
                      end
78
                  end
79
                else
80
                  lfli_drdy = 1;
81 5 ghutchis
              end
82
            else if (lri_srdy)
83
              begin
84
                if (lri_data[`PRW_DATA] & port_mask)
85
                  begin
86
                    // packet is for our port
87 11 ghutchis
                    //nxt_pe_vec = lri_data[`PRW_DATA] & ~port_mask;
88 5 ghutchis
 
89
                    // if enable vector is not empty, send the
90
                    // vector to the next port
91
                    if ((nxt_pe_vec != 0) & lro_drdy)
92
                      begin
93
                        lro_data[`PRW_DATA] = nxt_pe_vec;
94
                        lro_data[`PRW_PVEC] = 1;
95
                        lro_srdy = 1;
96
                        lri_drdy = 1;
97
                        nxt_state = ns_rcopy;
98
                      end
99 11 ghutchis
                    else if (nxt_pe_vec == 0)
100 5 ghutchis
                      begin
101
                        lri_drdy = 1;
102
                        nxt_state = ns_rsink;
103
                      end // else: !if((nxt_pe_vec != 0) & lro_drdy)
104
                  end // if (lri_data[`PRW_DATA] & port_mask)
105
                else
106
                  // packet is not for our port, forward it on the
107
                  // ring
108
                  begin
109
                    if (lro_drdy)
110
                      begin
111
                        lri_drdy = 1;
112
                        lro_srdy = 1;
113
                        nxt_state = ns_rfwd;
114
                      end
115
                  end // else: !if(lri_data[`PRW_DATA] & port_mask)
116
              end // if (lri_srdy)
117
          end // case: state[s_idle]
118
 
119 8 ghutchis
        // transmit data from port on to the ring
120
        state[s_tdata] :
121
          begin
122
            lro_data = lprx_data;
123
            lro_data[`PRW_PVEC] = 0;
124
            if (lro_drdy & lprx_srdy)
125
              begin
126
                lprx_drdy = 1;
127
                lro_srdy  = 1;
128
                if ((lprx_data[`PRW_PCC] == `PCC_EOP) |
129
                    (lprx_data[`PRW_PCC] == `PCC_BADEOP))
130
                  nxt_state = ns_idle;
131
              end
132
          end // case: state[s_tdata]
133
 
134
        // data on ring is for our port as well as further ports
135
        // copy ring data to our TX buffer as well as on the ring
136
        state[s_rcopy] :
137
          begin
138
            lro_data = lri_data;
139
            lptx_data = lri_data[`PFW_SZ-1:0];
140
            if (lri_srdy & lro_drdy & lptx_drdy)
141
              begin
142
                lri_drdy = 1;
143
                lro_srdy = 1;
144
                lptx_srdy = 1;
145
                if ((lri_data[`PRW_PCC] == `PCC_EOP) |
146
                    (lri_data[`PRW_PCC] == `PCC_BADEOP))
147
                  nxt_state = ns_idle;
148
              end
149
          end
150
 
151
        // data on ring is not for our port, copy from ring in to ring out
152
        state[s_rfwd] :
153
          begin
154
            lro_data = lri_data;
155
            if (lri_srdy & lro_drdy)
156
              begin
157
                lri_drdy = 1;
158
                lro_srdy = 1;
159
                if ((lri_data[`PRW_PCC] == `PCC_EOP) |
160
                    (lri_data[`PRW_PCC] == `PCC_BADEOP))
161
                  nxt_state = ns_idle;
162
              end
163
          end
164
 
165
        // data on ring is for our port and we are the last port
166
        // copy ring data to our TX buffer but do not copy to ring
167 11 ghutchis
        state[s_rsink] :
168 8 ghutchis
          begin
169
            lptx_data = lri_data[`PFW_SZ-1:0];
170
            if (lri_srdy & lptx_drdy)
171
              begin
172
                lri_drdy = 1;
173
                lptx_srdy = 1;
174
                if ((lri_data[`PRW_PCC] == `PCC_EOP) |
175
                    (lri_data[`PRW_PCC] == `PCC_BADEOP))
176
                  nxt_state = ns_idle;
177
              end
178
          end
179
 
180 5 ghutchis
        default : nxt_state = ns_idle;
181
      endcase // case (1'b1)
182
    end // always @ *
183 8 ghutchis
 
184
  always @(posedge clk)
185
    begin
186
      if (reset)
187
        begin
188
          state <= #1 1;
189
          /*AUTORESET*/
190
        end
191
      else
192
        begin
193
          state <= #1 nxt_state;
194
        end
195
    end // always @ (posedge clk)
196
 
197 5 ghutchis
 
198
 
199
endmodule // port_ring_tap_fsm

powered by: WebSVN 2.1.0

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