eliminate use of bram14 in Memory.ship
[fleet.git] / ships / Debug.ship
1 ship: Debug
2
3 == Ports ===========================================================
4 data  in:   in
5
6 percolate up:   root_in_r   1
7 percolate down: root_in_a   1
8 percolate up:   root_in_d   8
9 percolate down: uart_in     1
10 percolate up:   uart_out    1
11 percolate up:   uart_rts    1
12 percolate down: uart_cts    1
13 percolate up:   rst_out     1
14 percolate down: rst_in      1
15
16 == Constants ========================================================
17
18 == TeX ==============================================================
19
20 This ship is used for debugging.  It has only one port, {\tt in}.
21 Programmers should send debug report values to this port.  How such
22 values are reported back to the programmer doing the debugging is left
23 unspecified.
24
25 \subsection*{To Do}
26
27 Provide an {\tt inOp} port and use opcode ports \cite{am25} to
28 effectively allow multiple independent ``debug streams''
29
30 Provide a way to programmatically read back the output of the debug
31 ship.
32
33 == Fleeterpreter ====================================================
34 public void service() {
35   if (box_in.dataReadyForShip())
36     ((Interpreter)getFleet()).debug(box_in.removeDataForShip());
37 }
38
39 == FleetSim ==============================================================
40
41 == FPGA ==============================================================
42
43   wire break_i;
44   reg break_last;
45   reg send_k;                initial send_k = 0;
46
47   wire       data_to_host_full;
48   wire       data_to_host_write_enable;
49   wire [7:0] data_to_host;
50
51   wire       data_to_fleet_empty;
52   wire       data_to_fleet_read_enable;
53   wire [7:0] data_to_fleet;
54
55   reg we;
56   reg re;
57   reg [7:0] data_to_host_r;
58   assign data_to_host = data_to_host_r;
59
60   wire ser_rst;
61   reg ser_rst_r;
62   initial ser_rst_r = 0;
63   assign ser_rst = (rst_in & ser_rst_r);
64
65   wire sio_ce;
66   wire sio_ce_x4;
67
68   wire break;
69   assign rst_out = rst_in && !break;
70
71   sasc_brg sasc_brg(clk, ser_rst, 3, 65, sio_ce, sio_ce_x4);
72   sasc_top sasc_top(clk, ser_rst,
73                     uart_in,
74                     uart_out,
75                     uart_cts,
76                     uart_rts, 
77                     sio_ce,
78                     sio_ce_x4,
79                     data_to_host,
80                     data_to_fleet,
81                     data_to_fleet_read_enable,
82                     data_to_host_write_enable,
83                     data_to_host_full,
84                     data_to_fleet_empty,
85                     break,
86                     break_i);
87
88    // break and break are _active high_
89    always @(posedge clk) break_last <= break;
90    assign break_i    =  break && !break_last;
91    assign break_done = !break &&  break_last;
92
93    reg data_to_host_write_enable_reg;
94    reg data_to_fleet_read_enable_reg;
95
96    reg [`WORDWIDTH-1:0] root_out_d;
97    reg root_out_r; initial root_out_r = 0;
98    wire root_out_a;
99
100    reg root_out_a_reg;
101    reg root_in_r_reg;
102    reg [7:0] root_in_d_reg;
103    initial root_in_r_reg = 0;
104    initial root_in_d_reg = 0;
105    initial root_out_a_reg = 0;
106    initial data_to_fleet_read_enable_reg = 0;
107    initial data_to_host_write_enable_reg = 0;
108
109    assign root_out_a                = root_out_a_reg;                
110    assign root_in_r                 = root_in_r_reg;
111    assign data_to_fleet_read_enable = data_to_fleet_read_enable_reg;
112    assign data_to_host_write_enable = data_to_host_write_enable_reg;
113    assign root_in_d                 = root_in_d_reg;
114
115    // fpga -> host
116    always @(posedge clk)
117    begin
118      if (break_i) begin
119        root_out_a_reg = 0;
120        data_to_host_write_enable_reg <= 0;
121
122      end else if (break_done) begin
123        data_to_host_write_enable_reg <= 1;
124        data_to_host_r <= 111;
125        send_k <= 1;
126      end else if (send_k) begin
127        data_to_host_write_enable_reg <= 1;
128        data_to_host_r <= 107;
129        send_k <= 0;
130
131
132      end else if (root_out_r && !root_out_a_reg && !data_to_host_full) begin
133        data_to_host_write_enable_reg <= 1;
134        data_to_host_r <= root_out_d[7:0];
135        root_out_a_reg = 1;
136      end else if (root_out_a_reg && !root_out_r) begin
137        data_to_host_write_enable_reg <= 0;
138        root_out_a_reg = 0;
139      end else begin
140        data_to_host_write_enable_reg <= 0;
141      end
142    end
143
144    // host -> fpga
145    always @(posedge clk)
146    begin
147      ser_rst_r <= 1;
148      if (break_i) begin
149        root_in_r_reg <= 0;
150        root_in_d_reg <= 0;
151        data_to_fleet_read_enable_reg <= 0;
152      end else
153   
154      if (!data_to_fleet_empty && !root_in_r_reg && !root_in_a) begin
155         root_in_r_reg <= 1;
156         root_in_d_reg <= data_to_fleet;
157         data_to_fleet_read_enable_reg <= 1;
158      end else begin
159        data_to_fleet_read_enable_reg <= 0;
160         if (root_in_a) begin
161           root_in_r_reg <= 0;
162         end
163      end
164    end
165
166   reg [7:0] count;
167   initial count = 0;
168
169   always @(posedge clk) begin
170     if (!rst) begin
171       `reset
172     end else begin
173       `flush
174       `cleanup
175       if (root_out_r && root_out_a) root_out_r <= 0;
176       if (`in_full && !root_out_r && !root_out_a && count==0) begin
177         `drain_in
178         root_out_d <= in_d;
179         root_out_r <= 1;
180         count <= 5;
181       end
182       if (count!=0 && !root_out_r && !root_out_a) begin
183         count <= count-1;
184         root_out_r <= 1;
185         root_out_d <= (root_out_d >> 8);
186       end
187     end
188   end
189
190 == Test ================================================================
191 #expect 25
192
193 #ship debug : Debug
194
195 debug.in:
196   set word= 25;
197   deliver;
198
199 == Contributors =========================================================
200 Adam Megacz <megacz@cs.berkeley.edu>