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

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [host/] [basic_nexys3/] [basic_nexys3_fpga.v] - Blame information for rev 8

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) 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_100,
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
    inout wire [7:0] GPIO_0,    // Test points
31
    output wire [7:0] GPIO_1,
32
    output wire [7:0] GPIO_2,
33
    inout wire [7:0] GPIO_3
34
);
35
`default_nettype none
36
 
37
// Export selected pins to the extension connector
38
assign GPIO_0[7:0] = A[7:0];
39
assign GPIO_1[7:0] = A[15:8];
40
assign GPIO_2[7:0] = D[7:0];
41
assign GPIO_3 = {reset, uart_tx, nM1, nMREQ, nRFSH, nHALT, nBUSACK};
42
 
43
// Basic wires and the reset logic
44
wire uart_tx;
45
wire reset;
46
wire locked;
47
 
48
assign reset = locked & ~KEY0;
49
assign UART_TXD = uart_tx;
50
 
51
// ----------------- CPU PINS -----------------
52
wire nM1;
53
wire nMREQ;
54
wire nIORQ;
55
wire nRD;
56
wire nWR;
57
wire nRFSH;
58
wire nHALT;
59
wire nBUSACK;
60
 
61
wire nWAIT = 1;
62
wire nBUSRQ = 1;
63
wire nINT = ~KEY1;
64
wire nNMI = ~KEY2;
65
 
66
wire [15:0] A;
67
reg [7:0] D /* synthesis keep */;
68
 
69
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
// Instantiate PLL
71
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
wire pll_clk;
73
wire clk_uart; // 50MHz clock for UART
74
 
75
clock pll ( .CLK_IN1(CLOCK_100), .CLK_OUT1(pll_clk), .CLK_OUT2(clk_uart), .LOCKED(locked) );
76
 
77
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78
// Clocks
79
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
wire clk_cpu = pll_clk; // CPU clock == PLL1 clock
81
 
82
// Test code: Divide pll clock with a power of 2 to reduce effective CPU clock
83
// reg [0:0] counter = 0;
84
// always @(posedge pll_clk)
85
// begin
86
//     if (counter==1'b0)
87
//         clk_cpu <= ~clk_cpu;
88
//     counter <= counter - 1'b1;
89
// end
90
 
91
// ----------------- INTERNAL WIRES -----------------
92
wire [7:0] RamData; // Data writer from the RAM module
93
wire [7:0] CpuData;
94
assign CpuData = nRD==0 ? D[7:0] : {nIORQ,nRD,nWR}==3'b011 ? 8'h80 : {8{1'bz}};
95
 
96
wire RamWE;
97
assign RamWE = nIORQ==1 && nRD==1 && nWR==0;
98
 
99
wire uart_busy;
100
wire UartWE;
101
assign UartWE = nIORQ==0 && nRD==1 && nWR==0;
102
 
103
// Memory map:
104
//   0000 - 3FFF  16Kb RAM
105
always @(*) // always_comb
106
begin
107
    case ({nIORQ,nRD,nWR})
108
        // -------------------------------- Memory read --------------------------------
109
        3'b101: D[7:0] = RamData;
110
        // -------------------------------- Memory write -------------------------------
111
        3'b110: D[7:0] = CpuData;
112
        // ---------------------------------- IO write ---------------------------------
113
        3'b010: D[7:0] = CpuData;
114
        // ---------------------------------- IO read ----------------------------------
115
        3'b001: D[7:0] = {7'b0000000, uart_busy};
116
        // IO read *** Interrupts test ***
117
        // This value will be pushed on the data bus on an IORQ access which
118
        // means that:
119
        // In IM0: this is the opcode of an instruction to execute, set it to 0xFF
120
        // In IM2: this is a vector, set it to 0x80 (to correspond to a test program Hello World)
121
        3'b011: D[7:0] = 8'h80;
122
    default:
123
        D[7:0] = {8{1'bz}};
124
    endcase
125
end
126
 
127
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128
// Instantiate A-Z80 CPU module
129
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
z80_top_direct_n z80_(
131
    .nM1 (nM1),
132
    .nMREQ (nMREQ),
133
    .nIORQ (nIORQ),
134
    .nRD (nRD),
135
    .nWR (nWR),
136
    .nRFSH (nRFSH),
137
    .nHALT (nHALT),
138
    .nBUSACK (nBUSACK),
139
 
140
    .nWAIT (nWAIT),
141
    .nINT (nINT),
142
    .nNMI (nNMI),
143
    .nRESET (reset),
144
    .nBUSRQ (nBUSRQ),
145
 
146
    .CLK (clk_cpu),
147
    .A (A),
148
    .D (CpuData)
149
);
150
 
151
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152
// Instantiate 16K of RAM memory
153
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154
ram #( .n(14)) ram_(
155
    .addr(A[13:0]),
156
    .clk(clk_cpu),
157
    .data_in(D),
158
    .we(RamWE),
159
    .data_out(RamData)
160
);
161
 
162
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163
// Instantiate UART module
164
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165
uart #( .BAUD(115200), .IN_CLOCK(50000000) ) uart_(
166
   // Outputs
167
   .busy(uart_busy),
168
   .uart_tx(uart_tx),
169
   // Inputs
170
   .wr(UartWE),
171
   .data(D),
172
   .clk(clk_uart),
173
   .reset(!reset)
174
);
175
 
176
endmodule

powered by: WebSVN 2.1.0

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