OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [host/] [basic_de1/] [basic_de1_fpga.sv] - Blame information for rev 21

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 gdevic
//============================================================================
2
// Host design containing A-Z80 and a few peripherials
3
//
4
// This module defines a host board to be run on an FPGA.
5
//
6
//  Copyright (C) 2014-2016  Goran Devic
7
//
8
//  This program is free software; you can redistribute it and/or modify it
9
//  under the terms of the GNU General Public License as published by the Free
10
//  Software Foundation; either version 2 of the License, or (at your option)
11
//  any later version.
12
//
13
//  This program is distributed in the hope that it will be useful, but WITHOUT
14
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
16
//  more details.
17
//
18
//  You should have received a copy of the GNU General Public License along
19
//  with this program; if not, write to the Free Software Foundation, Inc.,
20
//  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
//============================================================================
22
module host
23
(
24
    input wire CLOCK_50,
25
    input wire KEY0,            // KEY0 is reset
26
    input wire KEY1,            // KEY1 generates a maskable interrupt (INT)
27
    input wire KEY2,            // KEY2 generates a non-maskable interrupt (NMI)
28
    output wire UART_TXD,
29
 
30
    output wire [5:0] GPIO_0    // Test points
31
);
32
`default_nettype none
33
 
34
// Export selected pins to the extension connector
35
assign GPIO_0[0] = reset;
36
assign GPIO_0[1] = locked;
37
assign GPIO_0[2] = nM1;
38
assign GPIO_0[3] = nMREQ;
39
assign GPIO_0[4] = nRD;
40
assign GPIO_0[5] = nWR;
41
 
42
// Basic wires and the reset logic
43
wire uart_tx;
44
wire uart_busy;
45
wire UartWE;
46
wire reset;
47
wire locked;
48
 
49
assign reset = locked & KEY0;
50
assign UART_TXD = uart_tx;
51
 
52
// ----------------- CPU PINS -----------------
53
wire nM1;
54
wire nMREQ;
55
wire nIORQ;
56
wire nRD;
57
wire nWR;
58
wire nRFSH;
59
wire nHALT;
60
wire nBUSACK;
61
 
62 13 gdevic
wire nWAIT;
63 8 gdevic
wire nBUSRQ = 1;
64
wire nINT = KEY1;
65
wire nNMI = KEY2;
66
 
67
wire [15:0] A;
68
wire [7:0] D;
69
 
70 13 gdevic
// This is an optional, test feature: add M1/Memory Wait states as described in the Zilog manual
71
reg nWAIT_M1_sig;
72
reg nWAIT_Mem_sig;
73
 
74
// *** Uncomment one of the following 3 choices ***:
75
//assign nWAIT = nWAIT_M1_sig;  // Add one wait state to an M1 cycle
76
//assign nWAIT = nWAIT_Mem_sig; // Add one wait state to any memory cycle (M1 + memory read/write)
77
assign nWAIT = 1;               // Do not add wait cycles
78
 
79 8 gdevic
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
// Instantiate PLL
81
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
wire pll_clk;
83
pll pll_( .locked(locked), .inclk0(CLOCK_50), .c0(pll_clk) );
84
 
85
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86
// Generate the CPU clock by dividing input clock by a factor of a power of 2
87
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88
reg clk_cpu = 0;                        // Final CPU clock
89
// Note: In order to test at 3.5 MHz, the PLL needs to be set to generate 14 MHz
90
// and then this divider-by-4 brings the effective clock down to 3.5 MHz
91
reg [0:0] counter = 0;                  // Clock divider counter
92
 
93
always @(posedge pll_clk)
94
begin
95
    if (counter=='0)
96
        clk_cpu <= ~clk_cpu;
97
    counter <= counter - 1'b1;
98
end
99
 
100
// ----------------- INTERNAL WIRES -----------------
101
wire [7:0] RamData; // Data writer from the RAM module
102
wire RamWE;
103
assign RamWE = nIORQ==1 && nRD==1 && nWR==0;
104
assign UartWE = nIORQ==0 && nRD==1 && nWR==0;
105
 
106
// Memory map:
107
//   0000 - 3FFF  16K RAM
108
always_comb
109
begin
110
    case ({nIORQ,nRD,nWR})
111
        3'b101: begin   // Memory read
112
                casez (A[15:14])
113
                    2'b00:  D[7:0] = RamData;
114
                default:
115
                    D[7:0] = 8'h76; // HALT
116
                endcase
117
                end
118
        3'b001: D[7:0] = {7'h0,uart_busy};
119
        // IO read *** Interrupts test ***
120
        // This value will be pushed on the data bus on an IORQ access which
121
        // means that:
122
        // In IM0: this is the opcode of an instruction to execute, set it to 0xFF
123
        // In IM2: this is a vector, set it to 0x80 (to correspond to a test program Hello World)
124
        3'b011: D[7:0] = 8'h80;
125
    default:
126
        D[7:0] = {8{1'bz}};
127
    endcase
128
end
129
 
130
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131
// Instantiate A-Z80 CPU module
132
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133
z80_top_direct_n z80_( .*, .nRESET(reset), .CLK(clk_cpu) );
134
 
135
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
136 13 gdevic
// Instantiate gates to add Wait states to M1 and Memory cycles (for testing)
137
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138
wait_state wait_state_inst
139
(
140
    .CLK(clk_cpu),
141
    .nM1(nM1),
142
    .nMREQ(nMREQ),
143
    .nWAIT_M1(nWAIT_M1_sig),
144
    .nWAIT_Mem(nWAIT_Mem_sig)
145
);
146
 
147
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148 8 gdevic
// Instantiate 16Kb of RAM memory
149
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
ram ram_( .address(A[13:0]), .clock(pll_clk), .data(D[7:0]), .wren(RamWE), .q(RamData[7:0]) );
151
 
152
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153
// Instantiate UART module
154
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155
uart #( .BAUD(115200), .IN_CLOCK(50000000) ) uart_(
156
   // Outputs
157
   .busy(uart_busy),
158
   .uart_tx(uart_tx),
159
   // Inputs
160
   .wr(UartWE),
161
   .data(D[7:0]),
162
   .clk(CLOCK_50),
163
   .reset(!reset)
164
);
165
 
166
endmodule

powered by: WebSVN 2.1.0

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