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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [rtl/] [CmodA7/] [SocCS02.sv] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2019-2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
`define DEBUG           1'b1
38
//`define SIM           1'b1
39
 
40
module SocCS02(sysclk, btn,
41
        pio2, pio3,
42
        led, led0_r, led0_g, led0_b,
43
        uart_rxd_out, uart_txd_in,
44
        MemAdr, MemDB, RamOEn, RamWEn, RamCEn);
45
input sysclk;
46
input [1:0] btn;
47
inout tri [6:0] pio2;
48
inout tri [22:0] pio3;
49
output [1:0] led;
50
output reg led0_r;
51
output reg led0_g;
52
output reg led0_b;
53
output uart_rxd_out;
54
input uart_txd_in;
55
output reg [18:0] MemAdr;
56
inout tri [7:0] MemDB;
57
output reg RamOEn;
58
output reg RamWEn;
59
output reg RamCEn;
60
 
61
parameter SYNC = 8'hFF;
62
parameter HIGH = 1'b1;
63
parameter LOW = 1'b0;
64
 
65
 
66
assign pio2 = 7'bz;
67
assign pio3 = 23'bz;
68
 
69
// -----------------------------------------------------------------------------
70
// Signals and registers
71
// -----------------------------------------------------------------------------
72
wire xrst;                                      // external reset (push button)
73
wire rst;                                               // internal reset
74
wire clk120;
75
wire clk80;
76
wire clk40;
77
wire clk;                                               // system clock (50MHz)
78
wire clk14p7;                           // uart clock 14.746 MHz
79
wire clk20;                                     // 20MHz for wall clock time
80
wire cpuclk;
81
wire locked;                            // clock generation is locked
82
wire [1:0] btn_db;      // debounced button output
83
 
84
reg irq;
85
wire vpa;
86
wire cyc;                                               // cpu cycle is active
87
wire stb;                                               // cpu transfer strobe
88
reg ack;                                                // cpu transfer acknowledge
89
wire we;                                                // cpu write cycle
90
wire [23:0] adr;                // cpu address
91
reg [11:0] dat_i;               // cpu data input
92
wire [11:0] dat_o;      // cpu data output
93
reg [11:0] dati;                // memory data input
94
 
95
wire cs_rom0, cs_rom1;
96
wire cs_io;
97
wire cs_mem;
98
wire cs_via;
99
wire cs_sema;
100
wire ack_rom0, ack_rom1;
101
wire ack_mem;
102
wire uart_irq, via_irq;
103
wire ack_uart, ack_via, ack_sema, rnd_ack;
104
wire xal;
105
wire [11:0] rom0_dato;
106
wire [11:0] rom1_dato;
107
wire [11:0] uart_dato;
108
wire [11:0] via_dato;
109
wire [11:0] mem_dato;
110
wire [11:0] sema_dato;
111
wire [11:0] rnd_dato;
112
wire [11:0] pa;
113
wire [11:0] pa_i;
114
wire [11:0] pa_o;
115
wire badram;
116
wire t3_if;
117
 
118
// -----------------------------------------------------------------------------
119
// Clock generation
120
// -----------------------------------------------------------------------------
121
 
122
cs02clkgen ucg1
123
(
124
  // Clock out ports
125
  .clk120(clk120),
126
  .clk80(clk80),
127
  .clk40(clk40),
128
  .clk14p7(clk14p7),
129
  .clk20(clk20),
130
  // Status and control signals
131
  .reset(xrst),
132
  .locked(locked),
133
 // Clock in ports
134
  .clk_in1(sysclk)
135
);
136
 
137
assign rst = !locked;
138
assign irq = uart_irq|via_irq;
139
assign clk = clk40;
140
assign cpuclk = clk40;
141
 
142
// -----------------------------------------------------------------------------
143
// Circuit select logic
144
// -----------------------------------------------------------------------------
145
// Memory map
146
//
147
// 000000       +---------------+
148
//              |               |
149
//              |   Ram 256kB   | (12 bits wide)
150
//                |               |
151
// 040000       +---------------+
152
//                |    unused     |
153
// E00000 +---------------+
154
//                  |     I/O       |
155
// EFFFFF       +---------------+
156
//                              |                unused                 |
157
// FF8000       +---------------+
158
//        |     ROM       |
159
// FFFFFF       +---------------+
160
//
161
// I/O Map
162
//
163
// E3010x       +---------------+
164
//        |    Uart6551   |
165
//        +---------------+
166
//
167
// E3060x       +---------------+
168
//        |     PRNG      |
169
//        +---------------+
170
//
171
// E600xx +---------------+
172
//        |    VIA6522    |
173
//        +---------------+
174
//
175
// EF0xxx       +---------------+
176
//        |  semaphores   |
177
//        +---------------+
178
//
179
// -----------------------------------------------------------------------------
180
 
181
assign cs_rom0 = adr[23:14]==10'h3FF;   // $FFFExxxxx to $FFFFxxxxx
182
assign cs_rom1 = adr[23:14]==10'h3FE;   // $FFFExxxxx to $FFFFxxxxx
183
//assign cs_basrom = cyc && stb && adr[31:16]==16'b1111_1111_1111_1101;      // $FFFCxxxx to $FFFFxxxx
184
assign cs_mem = adr[23:20]==4'h0;
185
assign cs_via = adr[23:8]==16'hE600;
186
assign cs_uart = adr[23:8]==16'hE301;
187
assign cs_sema = adr[23:16]==8'hEF;
188
reg cs_rnd;
189
always_comb cs_rnd = adr[23:8]==16'hE306;               // PRNG random number generator
190
 
191
// -----------------------------------------------------------------------------
192
// Input debouncing
193
// Pressing both buttons at the same time resets the system.
194
// -----------------------------------------------------------------------------
195
 
196
BtnDebounce udbu (sysclk, btn[0], btn_db[0]);
197
BtnDebounce udbd (sysclk, btn[1], btn_db[1]);
198
 
199
`ifdef SIM
200
assign xrst = btn[0];// & btn[1];
201
`else
202
assign xrst = btn_db[0] & btn_db[1];
203
`endif
204
 
205
assign pa_i[8] = btn_db[0];
206
assign pa_i[9] = btn_db[1];
207
 
208
// -----------------------------------------------------------------------------
209
// clock divider
210
// Used to pulse width modulate (PWM) the led signals to reduce the brightness.
211
// -----------------------------------------------------------------------------
212
 
213
reg [31:0] dvd;
214
always @(posedge clk)
215
if (rst)
216
        dvd <= 32'd1;
217
else begin
218
        if (dvd==32'd50000000)
219
                dvd <= 32'd1;
220
        else
221
                dvd <= dvd + 32'd1;
222
end
223
 
224
// -----------------------------------------------------------------------------
225
// LED output
226
// -----------------------------------------------------------------------------
227
 
228
assign led[0] = pa_o[3] & ~dvd[26] & dvd[12];
229
assign led[1] = pa_o[4] & dvd[12];
230
 
231
assign led0_r = ~irq;   // pa[0]
232
assign led0_g = ~cyc;   // pa[1]
233
assign led0_b = ~(pa_o[2] & dvd[12]);     // PWM 50% at about 12kHz.
234
 
235
// -----------------------------------------------------------------------------
236
// Memory interface
237
// -----------------------------------------------------------------------------
238
 
239
wire MemT;
240
wire [7:0] MemDBo;
241
 
242
cs02memInterface umi1
243
(
244
        .rst_i(rst),
245
        .clk_i(clk40),
246
        .cpuclk_i(cpuclk),
247
        .cs_i(cs_mem),
248
        .cyc_i(cyc),
249
        .stb_i(stb),
250
        .ack_o(ack_mem),
251
        .we_i(we),
252
        .adr_i(adr),
253
        .dat_i(dat_o),
254
        .dat_o(mem_dato),
255
        .RamCEn(RamCEn),
256
        .RamWEn(RamWEn),
257
        .RamOEn(RamOEn),
258
        .MemAdr(MemAdr),
259
        .MemDBo(MemDBo),
260
        .MemDBi(MemDB)
261
);
262
assign MemDB = {8{RamWEn}} ? 8'bz : MemDBo;
263
//assign mem_dato = cs_mem ? mem_dato1 : 32'd0;
264
 
265
// -----------------------------------------------------------------------------
266
// -----------------------------------------------------------------------------
267
 
268
random  uprg1
269
(
270
        .rst_i(rst),
271
        .clk_i(cpuclk),
272
        .cs_i(cs_rnd),
273
        .cyc_i(cyc),
274
        .stb_i(stb),
275
        .ack_o(rnd_ack),
276
        .we_i(we),
277
        .adr_i(adr[3:0]),
278
        .dat_i(dat_o),
279
        .dat_o(rnd_dato)
280
);
281
 
282
// -----------------------------------------------------------------------------
283
// -----------------------------------------------------------------------------
284
 
285
semamem usema1
286
(
287
        .rst_i(rst),
288
  .clk_i(cpuclk),
289
  .cs_i(cs_sema),
290
  .cyc_i(cyc),
291
  .stb_i(stb),
292
  .ack_o(ack_sema),
293
  .we_i(we),
294
  .adr_i(adr[12:0]),
295
  .dat_i(dat_o),
296
  .dat_o(sema_dato)
297
);
298
 
299
scratchmem uscr2
300
(
301
  .rst_i(rst),
302
  .clk_i(cpuclk),
303
  .cti_i(3'b000),
304
  .bok_o(),
305
  .cs_i(cs_rom0),
306
  .cyc_i(cyc),
307
  .stb_i(stb),
308
  .ack_o(ack_rom0),
309
  .we_i(we),
310
  .adr_i(adr[13:0]),
311
  .dat_i(dat_o),
312
  .dat_o(rom0_dato)
313
`ifdef SIM
314
  ,.sp(24'h0)
315
`else
316
        ,.sp(24'h0)
317
`endif
318
);
319
demomem uscr2a
320
(
321
  .rst_i(rst),
322
  .clk_i(cpuclk),
323
  .cti_i(3'b000),
324
  .bok_o(),
325
  .cs_i(cs_rom1),
326
  .cyc_i(cyc),
327
  .stb_i(stb),
328
  .ack_o(ack_rom1),
329
  .we_i(we),
330
  .adr_i(adr[13:0]),
331
  .dat_i(dat_o),
332
  .dat_o(rom1_dato)
333
`ifdef SIM
334
  ,.sp(24'h0)
335
`else
336
        ,.sp(24'h0)
337
`endif
338
);
339
 
340
// -----------------------------------------------------------------------------
341
// -----------------------------------------------------------------------------
342
 
343
via6522_x12 uvia1
344
(
345
        .rst_i(rst),
346
        .clk_i(cpuclk),
347
        .wc_clk_i(clk40),
348
        .irq_o(via_irq),
349
        .cs_i(cs_via),
350
        .cyc_i(cyc),
351
        .stb_i(stb),
352
        .ack_o(ack_via),
353
        .we_i(we),
354
        .adr_i(adr[6:0]),
355
        .dat_i(dat_o),
356
        .dat_o(via_dato),
357
        .pa_i(pa_i),
358
        .pa_o(pa_o),
359
        .pa_t(),
360
        .pb_i(),
361
        .pb_o(),
362
        .pb_t(),
363
        .ca1(),
364
        .ca2_i(),
365
        .ca2_o(),
366
        .ca2_t(),
367
        .cb1_i(),
368
        .cb1_o(),
369
        .cb1_t(),
370
        .cb2_i(),
371
        .cb2_o(),
372
        .cb2_t(),
373
        .t1_if(),
374
        .t2_if(),
375
        .t3_if(t3_if)
376
);
377
 
378
// -----------------------------------------------------------------------------
379
// UART
380
// -----------------------------------------------------------------------------
381
 
382
uart6551_x12 #(.CLK_FREQ(40)) uuart1
383
(
384
        .rst_i(rst),
385
        .clk_i(clk40),
386
        .cs_i(cs_uart),
387
        .irq_o(uart_irq),
388
        .cyc_i(cyc),
389
        .stb_i(stb),
390
        .ack_o(ack_uart),
391
        .we_i(we),
392
        .adr_i(adr[3:0]),
393
        .dat_i(dat_o),
394
        .dat_o(uart_dato),
395
        .cts_ni(1'b0),
396
        .rts_no(),
397
        .dsr_ni(1'b0),
398
        .dcd_ni(1'b0),
399
        .dtr_no(),
400
        .ri_ni(1'b1),
401
        .rxd_i(uart_txd_in),
402
        .txd_o(uart_rxd_out),
403
        .data_present(),
404
        .rxDRQ_o(),
405
        .txDRQ_o(),
406
        .xclk_i(clk20),
407
        .RxC_i(1'b0)
408
);
409
 
410
// -----------------------------------------------------------------------------
411
// -----------------------------------------------------------------------------
412
 
413
wire err;
414
 
415
BusError ube1
416
(
417
        .rst_i(rst),
418
        .clk_i(cpuclk),
419
        .cyc_i(cyc),
420
        .ack_i(ack),
421
        .stb_i(stb),
422
        .adr_i(adr),
423
        .err_o(err)
424
);
425
 
426
// -----------------------------------------------------------------------------
427
// CPU
428
// -----------------------------------------------------------------------------
429
 
430
always @(posedge cpuclk)
431
        ack <= ack_rom0|ack_rom1|ack_mem|ack_via|ack_uart|ack_sema|rnd_ack;
432
 
433
always @(posedge cpuclk)
434
        dat_i <= rom0_dato|rom1_dato|mem_dato|via_dato|uart_dato|sema_dato|rnd_dato;
435
 
436
rf6809 ucpu1
437
(
438
        .id(6'h20),
439
        .rst_i(rst),
440
        .clk_i(cpuclk),
441
        .halt_i(1'b0),
442
        .nmi_i(1'b0),
443
        .irq_i(via_irq),
444
        .firq_i(1'b0),
445
        .vec_i(24'h0),
446
        .ba_o(),
447
        .bs_o(),
448
        .lic_o(),
449
        .tsc_i(1'b0),
450
        .rty_i(1'b0),
451
        .bte_o(),
452
        .cti_o(cti),
453
        .bl_o(),
454
        .lock_o(),
455
        .cyc_o(cyc),
456
        .stb_o(stb),
457
        .we_o(we),
458
        .ack_i(ack),
459
        .aack_i(ack),
460
        .atag_i(adr[3:0]),
461
        .adr_o(adr),
462
        .dat_i(dat_i),
463
        .dat_o(dat_o),
464
        .state()
465
);
466
 
467
 
468
CS02_ILA uila1 (
469
        .clk(clk80), // input wire clk
470
 
471
 
472
        .probe0(ucpu1.pc), // input wire [31:0]  probe0
473
        .probe1(ucpu1.dat_i), // input wire [31:0]  probe1
474
        .probe2(ucpu1.cyc_o), // input wire [0:0]  probe2
475
        .probe3(ucpu1.we_o), // input wire [0:0]  probe3
476
        .probe4(ucpu1.adr_o), // input wire [31:0]  probe4
477
        .probe5(MemDB), // input wire [31:0]  probe5
478
        .probe6({umi1.ack_o,RamCEn,RamOEn,RamWEn,umi1.state}),
479
        .probe7(MemAdr)
480
//      .probe6({ucpu1.to_done,ucpu1.state,ucpu1.crs,ucpu1.regset})
481
);
482
 
483
 
484
endmodule

powered by: WebSVN 2.1.0

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