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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [allocator.v] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 ghutchis
`timescale 1ns/100ps
2
 
3
module allocator
4
  (
5
   input         clk,    //% System clock
6
   input         reset,  //% Active high reset
7
 
8
   input                crx_abort,  //% asserted at end of packet, indicates packet drop
9
   input                crx_commit, //% asserted at end of packet, indicates packet accept
10
   input [`PFW_SZ-1:0]   crx_data,   //% Incoming data from accumulator
11
   output               crx_drdy,   //% destination flow control
12
   input                crx_srdy,   //% source data available
13
 
14
   // page request i/f
15
   output            par_srdy,
16
   input             par_drdy,
17
 
18
   input             parr_srdy,
19
   output            parr_drdy,
20
   input [`LL_PG_ASZ-1:0]  parr_page,
21
 
22
   // link to next page i/f
23
   output reg        lnp_srdy,
24
   input             lnp_drdy,
25
   output reg [`LL_LNP_SZ-1:0] lnp_pnp,
26
 
27
   // interface to packet buffer
28
   output [`PBR_SZ-1:0] pbra_data,
29
   output               pbra_srdy,
30
   input                pbra_drdy,
31
 
32
   output [`LL_PG_ASZ-1:0] a2f_start,
33
   output [`LL_PG_ASZ-1:0] a2f_end,
34
   output reg              a2f_srdy,
35
   input                   a2f_drdy
36
   );
37
 
38
  wire                     icrx_srdy;
39
 
40
  reg                      icrx_drdy;
41
  wire                     icrx_commit, icrx_abort;
42
  wire [`PFW_SZ-1:0]        icrx_data;
43
 
44
  reg [2:0]                pcount;
45
  reg [1:0]                word_count;
46
  reg [`LL_PG_ASZ-1:0]     start_pg;
47
  reg [`LL_PG_ASZ-1:0]     cur_pg;
48
  reg [`LL_PG_ASZ-1:0]     nxt_start_pg;
49
  reg [`LL_PG_ASZ-1:0]     nxt_cur_pg;
50
 
51
  reg                      obuf_srdy;
52
  wire [`PB_ASZ-1:0]       obuf_addr;
53
  reg [1:0]                cur_line, nxt_cur_line;
54
  wire                     obuf_drdy;
55
 
56
  wire [`PBR_SZ-1:0]       obuf_pbr_word;
57
 
58
  wire                     pp_srdy;
59
  reg                      pp_drdy;
60
  wire [`LL_PG_ASZ-1:0]    pp_page;
61
 
62
  assign obuf_addr = { cur_pg, cur_line };
63
 
64
  //------------------------------------------------------------
65
  // icarus debug
66
 
67
/* -----\/----- EXCLUDED -----\/-----
68
  tape_record #(9+`PFW_SZ+`LL_PG_ASZ) record0
69
    (.clk (clk),
70
    .data ({ reset,
71
             crx_abort,
72
             crx_commit,
73
             crx_srdy,
74
             par_drdy,
75
             parr_srdy,
76
             lnp_drdy,
77
             pbra_drdy,
78
             a2f_drdy, crx_data, parr_page }));
79
 -----/\----- EXCLUDED -----/\----- */
80
 
81
  //------------------------------------------------------------
82
  // page prefetch FIFO and state machine logic
83
  //------------------------------------------------------------
84
 
85
  wire                     pcount_inc = par_srdy & par_drdy;
86
  wire                     pcount_dec = pp_srdy & pp_drdy;
87
  assign par_srdy = (pcount < 4);
88
 
89
  always @(posedge clk)
90
    begin
91
      if (reset)
92
        pcount <= 0;
93
      else
94
        begin
95
          if (pcount_inc & !pcount_dec)
96
            pcount <= pcount + 1;
97
          else if (pcount_dec & !pcount_inc)
98
            pcount <= pcount - 1;
99
        end
100
    end
101
 
102
  sd_fifo_s #(.width(`LL_PG_ASZ), .depth(4)) page_prefetch
103
    (
104
     .c_clk      (clk),
105
     .c_reset    (reset),
106
     .p_clk      (clk),
107
     .p_reset    (reset),
108
 
109
     .c_srdy   (parr_srdy),
110
     .c_drdy   (parr_drdy),
111
     .c_data   (parr_page),
112
 
113
     .p_srdy   (pp_srdy),
114
     .p_drdy   (pp_drdy),
115
     .p_data   (pp_page));
116
 
117
  always @(posedge clk)
118
    begin
119
      if (pp_srdy & pp_drdy)
120
        $display ("%t %m: Storing in page %0d", $time, pp_page);
121
      if (crx_srdy & crx_drdy & crx_commit)
122
        $display ("%t %m: Sent packet (%0d,%0d)", $time, start_pg, cur_pg);
123
    end
124
 
125
  sd_iohalf #(.width(`PFW_SZ+2)) crx_buf
126
    (.clk (clk), .reset (reset),
127
 
128
     .c_srdy (crx_srdy),
129
     .c_drdy (crx_drdy),
130
     .c_data ({crx_commit,crx_abort,crx_data}),
131
 
132
     .p_srdy (icrx_srdy),
133
     .p_drdy (icrx_drdy),
134
     .p_data ({icrx_commit,icrx_abort,icrx_data}));
135
 
136
  //------------------------------------------------------------
137
  // 
138
  //------------------------------------------------------------
139
 
140
  assign a2f_start = start_pg;
141
  assign a2f_end   = cur_pg;
142
 
143
  reg [2:0] state, nxt_state;
144
  localparam s_idle = 0, s_noalloc = 1, s_link = 2, s_commit = 3,
145
    s_abort = 4, s_commit2 = 5;
146
 
147
  always @*
148
    begin
149
      icrx_drdy = 0;
150
      obuf_srdy = 0;
151
      lnp_srdy = 0;
152
      nxt_start_pg = start_pg;
153
      nxt_cur_pg = cur_pg;
154
      nxt_cur_line = cur_line;
155
      lnp_pnp = { cur_pg, 1'b0, pp_page };
156
      a2f_srdy = 0;
157
      pp_drdy = 0;
158
 
159
      case (state)
160
        s_idle :
161
          begin
162
            // if output buffer is ready and a page is allocated,
163
            // preload the address counters to get ready for a packet
164
            if (pp_srdy)
165
              begin
166
                nxt_start_pg = pp_page;
167
                nxt_cur_pg   = pp_page;
168
                nxt_cur_line = 0;
169
                nxt_state = s_noalloc;
170
                pp_drdy = 1;
171
              end
172
          end // case: s_idle
173
 
174
        s_noalloc :
175
          begin
176
            if (icrx_srdy & obuf_drdy)
177
              begin
178
                icrx_drdy = 1;
179
                obuf_srdy = 1;
180
                nxt_cur_line = cur_line + 1;
181
                if (`ANY_EOP(icrx_data[`PRW_PCC]))
182
                  begin
183
                    if (icrx_commit)
184
                      nxt_state = s_commit;
185
                    else
186
                      nxt_state = s_abort;
187
                  end
188
                else if (cur_line == 3)
189
                  begin
190
                    nxt_state = s_link;
191
                  end
192
              end // if (icrx_srdy & obuf_drdy)
193
          end // case: s_noalloc
194
 
195
 
196
        s_link :
197
          begin
198
            if (pp_srdy)
199
              begin
200
                lnp_srdy = 1;
201
                if (lnp_drdy)
202
                  begin
203
                    nxt_cur_pg = pp_page;
204
                    pp_drdy = 1;
205
                    nxt_state = s_noalloc;
206
                  end
207
              end
208
          end // case: s_link
209
 
210
        s_commit :
211
          begin
212
            lnp_pnp = { cur_pg, `LL_ENDPAGE };
213
            lnp_srdy = 1;
214
            if (lnp_drdy)
215
              nxt_state = s_commit2;
216
          end
217
 
218
        s_commit2 :
219
          begin
220
            a2f_srdy = 1;
221
            if (a2f_drdy)
222
              nxt_state = s_idle;
223
          end
224
 
225
        s_abort :
226
          begin
227
            // need to reclaim pages here
228
          end
229
 
230
        default : nxt_state = s_idle;
231
      endcase // case (state)
232
    end
233
 
234
  always @(posedge clk)
235
    begin
236
      if (reset)
237
        begin
238
          state <= s_idle;
239
          /*AUTORESET*/
240
          // Beginning of autoreset for uninitialized flops
241
          cur_line <= 2'h0;
242
          cur_pg <= {(1+(`LL_PG_ASZ-1)){1'b0}};
243
          start_pg <= {(1+(`LL_PG_ASZ-1)){1'b0}};
244
          // End of automatics
245
        end
246
      else
247
        begin
248
          start_pg <= nxt_start_pg;
249
          cur_pg   <= nxt_cur_pg;
250
          cur_line <= nxt_cur_line;
251
          state    <= nxt_state;
252
        end
253
    end
254
 
255
  assign obuf_pbr_word[`PBR_DATA] = icrx_data;
256
  assign obuf_pbr_word[`PBR_ADDR] = obuf_addr;
257
  assign obuf_pbr_word[`PBR_WRITE] = 1'b1;
258
  assign obuf_pbr_word[`PBR_PORT]  = 0;
259
 
260
  sd_iohalf #(.width(`PBR_SZ)) obuf
261
    (.clk (clk), .reset (reset),
262
 
263
     .c_srdy (obuf_srdy),
264
     .c_drdy (obuf_drdy),
265
     .c_data (obuf_pbr_word),
266
 
267
     .p_srdy (pbra_srdy),
268
     .p_drdy (pbra_drdy),
269
     .p_data (pbra_data));
270
 
271
endmodule // allocator
272
 

powered by: WebSVN 2.1.0

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