-
Notifications
You must be signed in to change notification settings - Fork 4
/
hx8kdemo.v
291 lines (255 loc) · 7.67 KB
/
hx8kdemo.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
* PicoSoC - A simple example SoC using PicoRV32
*
* Copyright (C) 2017 Clifford Wolf <clifford@clifford.at>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
module hx8kdemo (
input clk_in,
input reset_n,
output ser_tx,
input ser_rx,
output flash_csb,
output flash_clk,
inout flash_io0,
inout flash_io1,
inout flash_io2,
inout flash_io3,
input key,
output run_led
// output [ 12: 0] zs_addr,
// output [ 1: 0] zs_ba,
// output zs_cas_n,
// output zs_cke,
// output zs_cs_n,
// inout [ 15: 0] zs_dq,
// output [ 1: 0] zs_dqm,
// output zs_ras_n,
// output zs_we_n,
// output sdram_clk
);
wire clk;
wire clk_100m;
wire sdram_clk;
pll pll_logic(
.reset(0),
.refclk(clk_in),
.clk0_out(clk),
.clk1_out(sdram_clk)
);
reg [15:0] reset_cnt = 0;
wire resetn = (reset_cnt >= 1000);
always @(posedge clk) begin
if(!reset_n)
reset_cnt <= 0;
else if(reset_cnt < 1000)
reset_cnt <= reset_cnt + 1;
else
reset_cnt <= reset_cnt;
end
reg [31:0]run_led_r;
always @(posedge clk)
begin
if(!resetn)
run_led_r =0;
else
run_led_r = run_led_r +1'b1;
end
assign run_led = run_led_r[26];
wire flash_io0_oe, flash_io0_do, flash_io0_di;
wire flash_io1_oe, flash_io1_do, flash_io1_di;
wire flash_io2_oe, flash_io2_do, flash_io2_di;
wire flash_io3_oe, flash_io3_do, flash_io3_di;
assign flash_io0 = flash_io0_oe? flash_io0_do : 1'bZ;
assign flash_io1 = flash_io1_oe? flash_io1_do : 1'bZ;
assign flash_io2 = flash_io2_oe? flash_io2_do : 1'bZ;
assign flash_io3 = flash_io3_oe? flash_io3_do : 1'bZ;
assign flash_io0_di =flash_io0 ;
assign flash_io1_di =flash_io1 ;
assign flash_io2_di =flash_io2 ;
assign flash_io3_di =flash_io3 ;
wire iomem_valid;
wire iomem_ready;
wire [3:0] iomem_wstrb;
wire [31:0] iomem_addr;
wire [31:0] iomem_wdata;
wire [31:0] iomem_rdata;
wire init_done;
picosoc32 soc (
.clk (clk ),
.resetn (resetn ),
.ser_tx (ser_tx ),
.ser_rx (ser_rx ),
.ex_irq (0 ),
.flash_csb (flash_csb ),
.flash_clk (flash_clk ),
.flash_io0_oe (flash_io0_oe),
.flash_io1_oe (flash_io1_oe),
.flash_io2_oe (flash_io2_oe),
.flash_io3_oe (flash_io3_oe),
.flash_io0_do (flash_io0_do),
.flash_io1_do (flash_io1_do),
.flash_io2_do (flash_io2_do),
.flash_io3_do (flash_io3_do),
.flash_io0_di (flash_io0_di),
.flash_io1_di (flash_io1_di),
.flash_io2_di (flash_io2_di),
.flash_io3_di (flash_io3_di),
.iomem_valid (iomem_valid ),
.iomem_ready (iomem_ready ),
.iomem_wstrb (iomem_wstrb ),
.iomem_addr (iomem_addr ),
.iomem_wdata (iomem_wdata ),
.iomem_rdata (iomem_rdata )
);
wire [ 10: 0] zs_addr;
wire [ 1: 0] zs_ba;
wire zs_cas_n;
wire zs_cke;
wire zs_cs_n;
wire [ 31: 0] zs_dq;
wire [ 3: 0] zs_dqm;
wire zs_ras_n;
wire zs_we_n;
wire [ 31: 0] za_data;
wire za_valid;
wire za_waitrequest;
wire [ 23: 0] az_addr;
wire [ 3: 0] az_be_n;
wire az_cs;
wire [ 31: 0] az_data;
wire az_rd_n;
wire az_wr_n;
picosoc_sdram bridge (
// cpu port
.clk (clk),
.resetn (resetn),
.valid (iomem_valid ),
.wen (iomem_wstrb),
.addr (iomem_addr[25:2]),
.wdata (iomem_wdata ),
.rdata (iomem_rdata),
.ready (iomem_ready),
// avalone port
.az_addr (az_addr),
.az_be_n (az_be_n),
.az_cs (az_cs),
.az_data (az_data),
.az_rd_n (az_rd_n),
.az_wr_n (az_wr_n),
.za_data (za_data ),
.za_valid (za_valid),
.za_waitrequest (za_waitrequest)
);
sdram_sdram sdram (
.clk (clk),
.reset_n (resetn),
.az_addr (az_addr),
.az_be_n (az_be_n),
.az_cs (az_cs),
.az_data (az_data),
.az_rd_n (az_rd_n),
.az_wr_n (az_wr_n),
.za_data (za_data),
.za_valid (za_valid),
.za_waitrequest (za_waitrequest),
.zs_addr (zs_addr),
.zs_ba (zs_ba),
.zs_cas_n (zs_cas_n),
.zs_cke (zs_cke),
.zs_cs_n (zs_cs_n),
.zs_dq (zs_dq),
.zs_dqm (zs_dqm),
.zs_ras_n (zs_ras_n),
.zs_we_n (zs_we_n),
.init_done (init_done)
);
sdram sdram_dev (
.clk (sdram_clk ),
.ras_n(zs_ras_n ),
.cas_n(zs_cas_n ),
.we_n (zs_we_n ),
.addr (zs_addr ),
.ba (zs_ba ),
.dq (zs_dq ),
.cs_n (0 ),
.dm0 (zs_dqm[0]),
.dm1 (zs_dqm[1]),
.dm2 (zs_dqm[2]),
.dm3 (zs_dqm[3]),
.cke (zs_cke )
);
endmodule
module pico_ram#(
parameter integer WORDS = 4096
)
(
input valid,
input clk,
input [3:0] wen,
input [13:0] addr,
input [31:0] wdata,
output reg ready,
output [31:0] rdata
);
soc_mem mem (
.rsta(0),
.addra(addr[11:0]),
.wea(valid? wen: 4'b0),
.clka(clk),
.dia(wdata),
.doa(rdata)
);
initial begin
ready <= 1'b0;
end
always @(posedge clk) begin
if(valid && !ready )begin
ready <= 1'b1;
end
else begin
ready <= 1'b0;
end
end
endmodule
module pico_rom #(
parameter integer WORDS = 4096
)(
input valid,
input clk,
input [3:0] wen,
input [14:0] addr,
input [31:0] wdata,
output reg ready,
output [31:0] rdata
);
rom picrv_rom (
.rsta(0),
.addra(addr[13:0]),
.clka(clk),
.doa(rdata)
);
initial begin
ready <= 1'b0;
end
always @(posedge clk) begin
if(valid && !ready )begin
ready <= 1'b1;
end
else begin
ready <= 1'b0;
end
end
endmodule