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

Subversion Repositories Aquarius

[/] [Aquarius/] [trunk/] [verilog/] [top.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 thorn_aitc
//======================================================
2
// Aquarius Project
3
//    SuperH-2 ISA Compatible RISC CPU
4
//------------------------------------------------------
5
// Module      : Top Layer (A Simple MCU)
6
//------------------------------------------------------
7
// File        : top.v
8
// Library     : none
9
// Description : Top Layer for Aquarius.
10
//               It is a simple MCU Chip.
11
// Simulator   : Icarus Verilog (Cygwin)
12
// Synthesizer : Xilinx XST (Windows XP)
13
// Author      : Thorn Aitch
14
//------------------------------------------------------
15
// Revision Number : 1
16
// Date of Change  : 15th April 2002
17
// Creator         : Thorn Aitch
18
// Description     : Initial Design                               
19
//------------------------------------------------------
20
// Revision Number : 2
21
// Date of Change  : 30th April 2003
22
// Modifier        : Thorn Aitch
23
// Description     : Release Version 1.0
24
//======================================================
25
// Copyright (C) 2002-2003, Thorn Aitch
26
//
27
// Designs can be altered while keeping list of
28
// modifications "the same as in GNU" No money can
29
// be earned by selling the designs themselves, but
30
// anyone can get money by selling the implementation
31
// of the design, such as ICs based on some cores, 
32
// boards based on some schematics or Layouts, and
33
// even GUI interfaces to text mode drivers.
34
// "The same as GPL SW" Any update to the design
35
// should be documented and returned to the design. 
36
// Any derivative work based on the IP should be free
37
// under OpenIP License. Derivative work means any
38
// update, change or improvement on the design. 
39
// Any work based on the design can be either made
40
// free under OpenIP license or protected by any other
41
// license. Work based on the design means any work uses
42
// the OpenIP Licensed core as a building black without
43
// changing anything on it with any other blocks to
44
// produce larger design.  There is NO WARRANTY on the
45
// functionality or performance of the design on the
46
// real hardware implementation.
47
// On the other hand, the SuperH-2 ISA (Instruction Set
48
// Architecture) executed by Aquarius is rigidly
49
// the property of Renesas Corp. Then you have all 
50
// responsibility to judge if there are not any 
51
// infringements to Renesas's rights regarding your 
52
// Aquarius adoption into your design. 
53
// By adopting Aquarius, the user assumes all 
54
// responsibility for its use.
55
// This project may cause any damages around you, for 
56
// example, loss of properties, data, money, profits,
57
// life, or business etc. By adopting this source, 
58
// the user assumes all responsibility for its use.
59
//======================================================
60
 
61
`include "timescale.v"
62
`include "defines.v"
63
 
64
//******************************
65
// Top Module
66
//******************************
67
module top(
68
      CLK_SRC, RST_n,
69
      LCDRS, LCDRW, LCDE,
70
          LCDDBO, LCDDBI,
71
          KEYYO, KEYXI,
72
      RXD, TXD, CTS, RTS
73
    );
74
 
75
    input  CLK_SRC; // non stop clock
76
    input  RST_n;
77
    output LCDRS;
78
    output LCDRW;
79
    output LCDE;
80
    output [7:0] LCDDBO;
81
    input  [7:0] LCDDBI;
82
    output [4:0] KEYYO;
83
    input  [4:0] KEYXI;
84
    input  RXD;
85
    output TXD;
86
    input  CTS;
87
    output RTS;
88
 
89
//------------------
90
// Internal Signals
91
//------------------
92
    wire   CLK;           // internal system clock, which stops during sleep
93
    reg    RST;           // 2nd sync reset
94
    reg    RST1;          // 1st sync reset 
95
    wire   CYC;           // external bus cycle to be kept
96
    wire   STB;           // external bus strobe
97
    reg    ACK;           // external device acknowledge
98
    wire   [31:0] ADR;    // external address
99
    reg    [31:0] DATI;   // external data read bus
100
    wire   [31:0] DATO;   // external data write bus
101
    wire   WE;            // external write/read
102
    wire   [3:0] SEL;     // external data valid position
103
    reg    IF_WIDTH;      // IF_WIDTH : external fetch space width
104
 
105
    reg    CEMEM, CEPIO, CEUART, CESYS;  // chip enable of each device
106
    wire   [31:0] DATMEM;  // direct memory output
107
    wire   [31:0] DATPIO;  // direct pio output
108
    wire   [31:0] DATUART; // direct uart output 
109
    wire   [31:0] DATSYS ; // direct sys output
110
    wire   [31:0] PI;  // port input
111
    wire   [31:0] PO;  // port output
112
 
113
    wire   RXD, TXD, CTS, RTS; //uart signals
114
 
115
    wire   [2:0] EVENT_REQ;   // Hardware Exception Event Request
116
    wire   EVENT_ACK;         // Hardware Exception Event Acknowledge
117
    wire   [11:0] EVENT_INFO; // Hardware Exception Event Information
118
 
119
    wire   SLP;       // SLEEP output
120
 
121
    assign LCDRS     = PO[8];
122
    assign LCDRW     = PO[9];
123
    assign LCDE      = PO[10];
124
    assign LCDDBO    = PO[7:0];
125
    assign PI[ 7: 0] = LCDDBI;
126
    assign KEYYO     = PO[20:16];
127
    assign PI[20:16] = KEYXI;
128
    assign PI[31:21] = 11'b00000000000;
129
    assign PI[15: 8] =  8'b00000000;
130
 
131
//********
132
// Modules
133
//********
134
    cpu CPU(
135
        // system signal
136
        .CLK(CLK), .RST(RST),
137
        // WISHBONE external bus signal
138
        .CYC_O(CYC), .STB_O(STB), .ACK_I(ACK),
139
        .ADR_O(ADR), .DAT_I(DATI), .DAT_O(DATO),
140
        .WE_O(WE), .SEL_O(SEL),
141
        .TAG0_I(IF_WIDTH),
142
        // Exception
143
        .EVENT_REQ_I(EVENT_REQ),
144
        .EVENT_ACK_O(EVENT_ACK),
145
        .EVENT_INFO_I(EVENT_INFO),
146
        //SLEEP
147
        .SLP_O(SLP)
148
    );
149
 
150
    memory MEMORY(
151
        .CLK(CLK), .CE(CEMEM), .WE(WE), .SEL(SEL),
152
        .ADR(ADR[13:0]), .DATI(DATO), .DATO(DATMEM)
153
    );
154
 
155
    pio PIO(
156
        .CLK(CLK), .RST(RST),
157
        .CE(CEPIO), .WE(WE), .SEL(SEL),
158
        .DATI(DATO), .DATO(DATPIO),
159
        .PI(PI), .PO(PO)
160
    );
161
 
162
    uart UART(
163
        .CLK(CLK), .RST(RST),
164
        .CE(CEUART), .WE(WE), .SEL(SEL),
165
        .DATI(DATO), .DATO(DATUART),
166
        .RXD(RXD), .TXD(TXD), .CTS(CTS), .RTS(RTS)
167
    );
168
 
169
    sys SYS(
170
        .CLK_SRC(CLK_SRC), .CLK(CLK), .SLP(SLP), .WAKEUP(~KEYXI[4]), .RST(RST),
171
        .CE(CESYS), .WE(WE), .SEL(SEL), .ACK(ACK),
172
        .DATI(DATO), .DATO(DATSYS),
173
        .EVENT_REQ(EVENT_REQ),
174
        .EVENT_ACK(EVENT_ACK),
175
        .EVENT_INFO(EVENT_INFO),
176
        .STB(STB), .ADR(ADR)
177
    );
178
 
179
//************
180
// Address MAP
181
//************
182
// address           size wait width device
183
// 00000000-0000FFFF 64K  0    32    MEMORY (shadow every 16KB)
184
// 00010000-0001FFFF 64K  3    32    MEMORY (shadow every 16KB)
185
// 00020000-0002FFFF 64K  0    16    MEMORY (shadow every 16KB)
186
// 00030000-0003FFFF 64K  3    16    MEMORY (shadow every 16KB)
187
// 00040000-ABCCFFFF ................(shadow MEMORY)
188
// ABCD0000-ABCD00FF 256  3    32    PIO (shadow every 4B)
189
// ABCD0100-ABCD01FF 256  3    32    UART(shadow every 4B)
190
// ABCD0200-ABCD02FF 256  3    32    SYS (shadow every 8B)
191
// ABCD0300-FFFBFFFF ................(shadow MEMORY)
192
// FFFC0000-FFFCFFFF 64K  0    32    MEMORY (shadow every 16KB)
193
// FFFD0000-FFFDFFFF 64K  3    32    MEMORY (shadow every 16KB)
194
// FFFE0000-FFFEFFFF 64K  0    16    MEMORY (shadow every 16KB)
195
// FFFF0000-FFFFFFFF 64K  3    16    MEMORY (shadow every 16KB)
196
//
197
// <MEMORY>
198
// ****0000-****1FFF  8K  ROM
199
// ****2000-****3FFF  8K  RAM
200
// ****4000-****5FFF  8K  ROM (shadow)
201
// ****6000-****7FFF  8K  RAM (shadow)
202
// ****8000-****9FFF  8K  ROM (shadow)
203
// ****A000-****BFFF  8K  RAM (shadow)
204
// ****C000-****DFFF  8K  ROM (shadow)
205
// ****E000-****FFFF  8K  RAM (shadow)
206
 
207
    always @(posedge CLK)
208
    begin
209
        RST1 <= ~RST_n;
210
        RST  <= RST1;
211
    end
212
 
213
    always @(DATMEM or DATPIO or DATUART or DATSYS) begin
214
       DATI <= DATMEM | DATPIO | DATUART | DATSYS; // read data gathering 
215
    end
216
 
217
    always @(STB or ADR)
218
    begin
219
        if (STB == 1'b0)
220
            {CEMEM,CEPIO,CEUART,CESYS} <= 4'b0000;
221
        else if (ADR[31:8] == 24'hABCD00)
222
            {CEMEM,CEPIO,CEUART,CESYS} <= 4'b0100;
223
        else if (ADR[31:8] == 24'hABCD01)
224
            {CEMEM,CEPIO,CEUART,CESYS} <= 4'b0010;
225
        else if (ADR[31:8] == 24'hABCD02)
226
            {CEMEM,CEPIO,CEUART,CESYS} <= 4'b0001;
227
        else
228
            {CEMEM,CEPIO,CEUART,CESYS} <= 4'b1000;
229
    end
230
 
231
//---------------------
232
// Control Access Cycle
233
//---------------------
234
    reg ACK0; // 0 wait device
235
    reg ACK3; // 3 wait device
236
 
237
    always @(ACK0 or ACK3) begin
238
        ACK <= ACK0 | ACK3;
239
    end
240
 
241
    always @(STB or ADR) begin
242
        if ((STB == 1'b1) && (ADR[16] == 1'b0))
243
            ACK0 <= 1'b1;
244
        else
245
            ACK0 <= 1'b0;
246
    end
247
 
248
    // S0: ACK3=0
249
    // S1: ACK3=0
250
    // S2: ACK3=0
251
    // S3: ACK3=1
252
    //
253
    // S0 -> S0
254
    // S0 -> S1 if ADR = **8 ~ **F, then wait
255
    // S2 -> S3
256
    // S3 -> S0
257
 
258
    reg [1:0] ACK3_STATE;
259
    reg [1:0] ACK3_NEXT_STATE;
260
    always @(posedge CLK or posedge RST) begin
261
        if (RST == 1'b1)
262
            begin
263
                ACK3_STATE <= 2'b00;
264
            end
265
        else
266
            begin
267
                ACK3_STATE <= ACK3_NEXT_STATE;
268
            end
269
    end
270
    always @(ACK3_STATE or STB or ADR) begin
271
        case (ACK3_STATE)
272
           2'b00 : if ((STB & ADR[16])  == 1'b1)
273
                       ACK3_NEXT_STATE <= 2'b01;
274
                   else
275
                       ACK3_NEXT_STATE <= 2'b00;
276
           2'b01 : ACK3_NEXT_STATE <= 2'b10;
277
           2'b10 : ACK3_NEXT_STATE <= 2'b11;
278
           2'b11 : ACK3_NEXT_STATE <= 2'b00;
279
           default : ACK3_NEXT_STATE <= 2'bxx;
280
        endcase
281
    end
282
    always @(ACK3_STATE)
283
        ACK3 <= ACK3_STATE[1] & ACK3_STATE[0];
284
 
285
//-------------------
286
// Control Data Width
287
//-------------------
288
    always @(ADR) begin
289
        if (ADR[17] == 1'b0)
290
            IF_WIDTH <= 1'b1;
291
        else
292
            IF_WIDTH <= 1'b0;
293
    end
294
 
295
//======================================================
296
  endmodule
297
//======================================================

powered by: WebSVN 2.1.0

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