All targets must deal with their own firmware now
[yari.git] / Icarus / testpipe1.v
blobc5bb82a447da871ce770e9ea134197ce7745c574
1 `timescale 1ns/10ps
2 `include "pipeconnect.h"
4 /*
5 Notation:
6 _ low, 0
7 ~ high, 1
8 / posedge
9 \ negedge
10 . unknown,undetermined,unimportant
11 # valid data (held stable)
12 < changing
13 > --
18 Fasttarget presents the request address as the result data after one
19 cycle. Wait is never asserted.
21 WISHBONE - no wait states
23 clock _____/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______
24 addr ........<#### A1 ####><#### A2 ####>.........................
25 read ________/~~~~~~~~~~~~~~~~~~~~~~~~~~\_________________________
26 wait _____________________________________________________________
27 readdata _____________<#### D1 ####><#### D2 ####>____________________
30 PIPECONNECT - no wait states
31 Request noticed by target
32 | Response captured by initiator
33 v v
34 clock _____/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______
35 addr ........<#### A1 ####><#### A2 ####>.........................
36 read ________/~~~~~~~~~~~~~~~~~~~~~~~~~~\_________________________
37 wait _____________________________________________________________
38 readdata ___________________________<#### D1 ####><#### D2 ####>______
41 PIPECONNECT - some wait states
42 Request noticed by target
43 | Response captured by initiator
44 v v
45 clock _____/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______
46 addr ........<#### A1 ##################><#### A2 ####>.........................
47 read ________/~~~~~~~~~~~~~~~~~~~~~~~~~~\_______________________________________
48 wait _____________/~~~~~~~~~~~~\________________________________________________
49 readdata _________________________________________<#### D1 ####><#### D2 ####>______
51 module fasttarget // PIPECONNECT, no wait
52 (input wire clk,
53 input wire rst,
54 input wire `REQ req,
55 output reg `RES res);
57 always @(posedge clk) begin
58 res`WAIT <= 0;
59 res`RD <= ~rst && req`R ? req`A : 0;
60 end
61 endmodule
64 PIPECONNECT - 1 wait state
65 Request noticed by target
66 | Response captured by initiator
67 v v
68 clock _____/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______
69 addr ........<#### A1 ##################><#### A2 ##################>...........
70 read ________/~~~~~~~~~~~~~~~~~~~~~~~~~~\/~~~~~~~~~~~~~~~~~~~~~~~~~~\___________
71 wait _____________/~~~~~~~~~~~~\______________/~~~~~~~~~~~~\____________________
72 readdata _________________________________________<#### D1 ####>______________<#### D2 ####>______
74 _~_~_~_~_~_
76 .AAAABBBB..
77 _~~~~~~~~__
78 _~~__~~____
79 _____aa__bb
82 module slowtarget // PIPECONNECT, 1 wait
83 (input wire clk,
84 input wire rst,
85 input wire `REQ req,
86 output wire `RES res);
88 reg [31:0] readData;
89 reg ready;
91 assign res`RD = readData;
92 assign res`WAIT = req`R & ~ready;
94 always @(posedge clk)
95 if (rst) begin
96 readData <= 0;
97 ready <= 0;
98 //$display("target in reset");
99 end else begin
100 readData <= ready ? req`A : 0;
101 ready <= req`R & ~ready;
102 //$display("target %d %d", ready, res`WAIT);
104 endmodule
107 Simple master waits for a result before issuing new request
109 PIPECONNECT - no wait states
110 Request noticed by target
111 | Response captured by initiator
113 clock /~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______
114 addr ...<#####req 1###>...........................<#####req 2
115 read ___/~~~~~~~~~~~~~\___________________________/~~~~~~~~~~
116 wait ________________________________________________________
117 readdata ______________________<#############>___________________
121 Streaming master keeps one outstanding command
123 PIPECONNECT - no wait states
124 Request noticed by target
125 | Response captured by initiator
127 clock _____/~~~~~~\______/~~~~~~\______/~~~~~~\______/~~~~~~\______
128 addr ........<#####req 1###>.............<#####req 2
129 read ________/~~~~~~~~~~~~~\___________________________/~~~~~~~~~~
130 wait _____________________________________________________________
131 readdata ___________________________<#############>___________________
135 module initiator
136 (input wire clk,
137 input wire rst,
138 output reg `REQ req,
139 input wire `RES res);
141 reg [31:0] counter;
142 reg [31:0] dataExpect;
143 reg dataValid;
145 parameter name = 1;
147 always @(posedge clk)
148 if (rst) begin
149 counter <= 0;
150 req <= 0;
151 dataValid <= 0;
152 dataExpect <= 0;
153 end else begin
154 dataValid <= req`R & ~res`WAIT;
155 if (dataValid) begin
156 if (dataExpect != res`RD)
157 $display("%6d init%d got %x !!! BAD!", $time, name, res`RD);
158 else
159 $display("%6d init%d got %x as expected", $time, name, res`RD);
162 if (~res`WAIT) begin
163 req`R <= 1;
164 req`A <= counter;
165 dataExpect <= req`A;
166 counter <= counter + 1;
168 $display("%6d init%d requests %x", $time, name, counter);
171 endmodule
173 module main();
174 reg rst, clk;
175 wire `REQ req;
176 wire `RES res;
177 wire [31:0] addr = req`A;
178 wire read = req`R;
179 wire wai = res`WAIT;
180 wire [31:0] data = res`RD;
182 initiator initiator1(clk, rst, req1, res1);
183 initiator initiator2(clk, rst, req2, res2);
184 mux2 mux_init(clk, req1, res1, req2, res2, req, res);
185 slowtarget target(clk, rst, req, res);
187 always # 5 clk = ~clk;
188 initial begin
189 $monitor("%d%d %4d %x %d %d %x", rst, clk, $time, addr, read, wai, data);
190 clk = 1;
191 rst = 1;
192 #15 rst = 0;
193 #200 $finish;
195 endmodule