split Debug.ship into two versions, one for ml509 and one for bee2
[fleet.git] / ships / Debug.ship.bee2
1 ship: Debug
2
3 == Ports ===========================================================
4 data  in:     in
5 dockless out: out
6
7 percolate down:  Clkin_p          1
8 percolate down:  Clkin_m          1
9 percolate up:    clk_out          1
10 percolate inout: D                8
11 percolate down:  RDWR_B           1
12 percolate down:  CS_B             1
13 percolate up:    CCLK             1
14 percolate up:    INIT_B           1
15
16 percolate up:    rst_out          1
17 percolate down:  rst_in           1
18
19 == Constants ========================================================
20
21 == TeX ==============================================================
22
23 percolate up:   uart_rts    1
24 percolate down: uart_cts    1
25
26 This ship is used for debugging.  It has only one port, {\tt in}.
27 Programmers should send debug report values to this port.  How such
28 values are reported back to the programmer doing the debugging is left
29 unspecified.
30
31 \subsection*{To Do}
32
33 Provide an {\tt inOp} port and use opcode ports \cite{am25} to
34 effectively allow multiple independent ``debug streams''
35
36 Provide a way to programmatically read back the output of the debug
37 ship.
38
39 == Fleeterpreter ====================================================
40 public void service() {
41   if (box_in.dataReadyForShip())
42     ((Interpreter)getFleet()).debug(new BitVector(37).set(box_in.removeDataForShip()));
43 }
44
45 == FleetSim ==============================================================
46
47 == FPGA ==============================================================
48
49    wire                        CCLK_int;
50    
51    wire [0:7]                  D_I;
52    wire [0:7]                  D_O;
53    wire [0:7]                  D_T;
54
55    wire                        User_Rst;
56
57    wire [7:0] write_data;
58    wire       write_enable;
59    wire       write_full;
60
61    wire [7:0] read_data;
62    wire       read_empty;
63    wire       read_enable;
64
65    // IO buffers
66    OBUF obuf_cclk( .I( CCLK_int ),     .O( CCLK )         );
67    IOBUF iobuf_d0( .I( D_O[0] ),    .IO( D[0] ),     .O( D_I[0] ),    .T( D_T[0] )    );
68    IOBUF iobuf_d1( .I( D_O[1] ),    .IO( D[1] ),     .O( D_I[1] ),    .T( D_T[1] )    );
69    IOBUF iobuf_d2( .I( D_O[2] ),    .IO( D[2] ),     .O( D_I[2] ),    .T( D_T[2] )    );
70    IOBUF iobuf_d3( .I( D_O[3] ),    .IO( D[3] ),     .O( D_I[3] ),    .T( D_T[3] )    );
71    IOBUF iobuf_d4( .I( D_O[4] ),    .IO( D[4] ),     .O( D_I[4] ),    .T( D_T[4] )    );
72    IOBUF iobuf_d5( .I( D_O[5] ),    .IO( D[5] ),     .O( D_I[5] ),    .T( D_T[5] )    );
73    IOBUF iobuf_d6( .I( D_O[6] ),    .IO( D[6] ),     .O( D_I[6] ),    .T( D_T[6] )    );
74    IOBUF iobuf_d7( .I( D_O[7] ),    .IO( D[7] ),     .O( D_I[7] ),    .T( D_T[7] )    );
75
76    // Clock buffer and reset
77    wire clk_fast;
78    wire clk_half;
79    wire clk_fb;
80    IBUFGDS_LVDS_25 diff_usrclk_buf( .I( Clkin_p ),   .IB( Clkin_m ),  .O( clk_fast )  );
81
82    wire clkdiv0_unbuffered;
83    wire clk0_unbuffered;
84    wire clk0_fb;
85 //   BUFG bufg1 (.I(clkdiv0_unbuffered),  .O(clk_out));
86 //   BUFG bufg1 (.I(clk_fast),  .O(clk_out));
87 //   BUFG bufg1 (.I(clk0_unbuffered),  .O(clk_out));
88    BUFG bufg2 (.I(clk0_unbuffered),     .O(clk0_fb));
89
90
91 reg foo;
92 reg foo2;
93    BUFG bufg1 (.I(foo2),  .O(clk_out));
94
95 always @(posedge clk_fast) begin
96   if (foo)
97     foo2 <= ~foo2;
98   foo <= ~foo;
99 end
100
101    DCM
102     #(
103       .CLKIN_PERIOD          (10.0),
104       .DUTY_CYCLE_CORRECTION ("TRUE"),
105       .DLL_FREQUENCY_MODE    ("LOW"),
106       .STARTUP_WAIT          ("FALSE")
107      ) ddr2_dcm (
108       .CLKIN     (clk_fast),
109       .CLKFB     (clk0_fb),
110       .CLK0      (clk0_unbuffered),
111       .RST       (User_Rst)
112      );
113
114 //   BUFG GBUF_FOR_MUX_CLOCK (.I(clk_half), .O(clk_out));
115 //   BUFG GBUF_FOR_MUX_CLOCK (.I(clk_fast), .O(clk_out));
116
117
118    wire [0:3] rstr;
119    FD rstr0( .D( 1'b0 ),         .Q( rstr[0] ),      .C( clk )   );   defparam rstr0.INIT = 1'b1;
120    FD rstr1( .D( rstr[0] ),      .Q( rstr[1] ),      .C( clk )   );   defparam rstr1.INIT = 1'b1;
121    FD rstr2( .D( rstr[1] ),      .Q( rstr[2] ),      .C( clk )   );   defparam rstr2.INIT = 1'b1;
122    FD rstr3( .D( rstr[2] ),      .Q( rstr[3] ),      .C( clk )   );   defparam rstr3.INIT = 1'b1;
123    assign   User_Rst = |rstr;
124
125    user_fifo test_fifo( 
126                         .WrFifo_Din( write_data ),
127                         .WrFifo_WrEn( write_enable ),
128                         .WrFifo_Full( write_full ),
129                         .WrFifo_WrCnt(  ),
130                         .RdFifo_Dout( read_data ),
131                         .RdFifo_RdEn( read_enable ),
132                         .RdFifo_Empty( read_empty ),
133                         .RdFifo_RdCnt(  ),
134                         .User_Rst( User_Rst ),
135                         .User_Clk( clk ),
136                         .Sys_Rst( User_Rst ),
137                         .Sys_Clk( clk_fast ),
138                         .D_I( D_I ),
139                         .D_O( D_O ),
140                         .D_T( D_T ),                         
141                         .RDWR_B( RDWR_B ),
142                         .CS_B( CS_B ),
143                         .INIT_B( INIT_B ),
144                         .CCLK( CCLK_int )
145                         );
146
147    wire       data_to_host_full;
148    reg  [7:0] data_to_host;
149    wire       data_to_fleet_empty;
150    wire [7:0] data_to_fleet;
151    reg        data_to_host_write_enable;
152    reg        data_to_fleet_read_enable;
153
154    assign data_to_fleet = read_data;
155    assign read_enable = data_to_fleet_read_enable;
156    assign write_enable = data_to_host_write_enable;
157    assign write_data = data_to_host;
158    assign data_to_fleet_empty = read_empty;
159    assign data_to_host_full = write_full;
160
161    initial data_to_fleet_read_enable = 1;
162    initial data_to_host_write_enable = 0;
163
164    reg  [7:0] force_reset;
165    assign rst_out = User_Rst || (force_reset!=0);
166
167    /// Common //////////////////////////////////////////////////////////////////////////////
168
169    reg send_k;
170    initial send_k = 0;
171
172    reg [`WORDWIDTH-1:0] data_to_host_full_word;
173    reg [7:0] count_in;
174    reg [7:0] count_out;
175    reg [49:0] out_d;
176    assign out_d_ = out_d;
177
178    reg [16:0] credits;
179
180    // fpga -> host
181    always @(posedge clk) begin
182      if (/*rst_in*/User_Rst) begin
183        count_in    <= 0;
184        count_out   <= 0;
185        force_reset <= 0;
186        credits      = 0;
187        `reset
188      end else begin
189
190        `cleanup
191
192        // fpga -> host
193        data_to_host_write_enable <= 0;
194        if (force_reset == 1) begin
195          force_reset <= 0;
196          data_to_host_write_enable <= 1;
197          credits = 0;
198          count_in  <= 0;
199          count_out <= 0;
200          `reset
201        end else if (force_reset != 0) begin
202          force_reset <= force_reset-1;
203        end else if (count_out==0 && `in_full) begin
204          `drain_in
205          data_to_host_full_word <= in_d;
206          count_out <= 8;
207        end else if (count_out!=0 && !data_to_host_full && !data_to_host_write_enable && credits!=0) begin
208          data_to_host <= { 2'b0, data_to_host_full_word[5:0] };
209          data_to_host_full_word <= (data_to_host_full_word >> 6);
210          data_to_host_write_enable <= 1;
211          count_out <= count_out-1;
212          credits = credits - 1;
213        end
214
215        // host -> fpga
216        data_to_fleet_read_enable <= 0;
217        if (!data_to_fleet_empty && !data_to_fleet_read_enable) begin
218
219          // Note: if the switch fabric refuses to accept a new item,
220          // we can get deadlocked in a state where sending a reset
221          // code (2'b11) won't have any effect.  Probably need to go
222          // back to using the break signal.
223
224            // command 0: data
225          if (data_to_fleet[7:6] == 2'b00 && `out_empty) begin
226            data_to_fleet_read_enable <= 1;
227            out_d <= { out_d[43:0], data_to_fleet[5:0] };
228            if (count_in==9) begin
229              count_in <= 0;
230              `fill_out
231            end else begin
232              count_in <= count_in+1;
233            end
234
235            // command 1: flow control credit
236          end else if (data_to_fleet[7:6] == 2'b01) begin
237            data_to_fleet_read_enable <= 1;
238            credits = credits + data_to_fleet[5:0];
239
240            // command 3: reset (and echo back reset code)
241          end else if (data_to_fleet[7:6] == 2'b11) begin
242            data_to_fleet_read_enable <= 1;
243            data_to_host <= data_to_fleet;
244            force_reset <= 255;
245
246          end 
247
248        end
249
250     end
251   end
252
253
254 == UCF =================================================================
255
256 ######################################
257 ## System clock pins
258 ######################################
259
260 NET Clkin_p             LOC = AP21 | IOSTANDARD = LVDS_25;
261 NET Clkin_m             LOC = AN21 | IOSTANDARD = LVDS_25;
262
263 NET rst_in              LOC = H4   | IOSTANDARD = LVCMOS18;
264
265 NET clk_out             PERIOD=50MHz;
266 //NET clk_out             PERIOD=100MHz;
267 //NET clk_fast            PERIOD=100MHz;
268 NET Clkin_p             PERIOD=100MHz;
269 NET Clkin_m             PERIOD=100MHz;
270
271 ######################################
272 ## SelectMAP interface pins
273 ######################################
274
275 NET D<0>                LOC = AU9  | IOSTANDARD = LVCMOS25;
276 NET D<1>                LOC = AV9  | IOSTANDARD = LVCMOS25;
277 NET D<2>                LOC = AY9  | IOSTANDARD = LVCMOS25;
278 NET D<3>                LOC = AW9  | IOSTANDARD = LVCMOS25;
279 NET D<4>                LOC = AW34 | IOSTANDARD = LVCMOS25;
280 NET D<5>                LOC = AY34 | IOSTANDARD = LVCMOS25;
281 NET D<6>                LOC = AV34 | IOSTANDARD = LVCMOS25;
282 NET D<7>                LOC = AU34 | IOSTANDARD = LVCMOS25;
283
284 NET RDWR_B              LOC = AR34 | IOSTANDARD = LVCMOS25;
285 NET CS_B                LOC = AT34 | IOSTANDARD = LVCMOS25;
286 NET INIT_B              LOC = AR9  | IOSTANDARD = LVCMOS25;
287 NET CCLK                LOC = C14  | IOSTANDARD = LVCMOS25;
288
289 #Net rst_pin LOC=E9;
290 #Net rst_pin PULLUP;
291 #Net rst_pin TIG;
292
293
294 == Test ================================================================
295 #expect 25
296
297 #ship debug : Debug
298
299 debug.in:
300   set word= 25;
301   deliver;
302
303 == Contributors =========================================================
304 Adam Megacz <megacz@cs.berkeley.edu>