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

Subversion Repositories t6507lp

[/] [t6507lp/] [trunk/] [rtl/] [verilog/] [t6532.v] - Blame information for rev 201

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

Line No. Rev Author Line
1 192 creep
////////////////////////////////////////////////////////////////////////////
2
////                                                                    ////
3
//// t6532 IP Core                                                      ////
4
////                                                                    ////
5
//// This file is part of the t2600 project                             ////
6
//// http://www.opencores.org/cores/t2600/                              ////
7
////                                                                    ////
8
//// Description                                                        ////
9
//// 6532 top level                                                     ////
10
////                                                                    ////
11
//// TODO:                                                              ////
12
//// - Add the timer, ram and i/o                                       ////
13
////                                                                    ////
14
//// Author(s):                                                         ////
15
//// - Gabriel Oshiro Zardo, gabrieloshiro@gmail.com                    ////
16
//// - Samuel Nascimento Pagliarini (creep), snpagliarini@gmail.com     ////
17
////                                                                    ////
18
////////////////////////////////////////////////////////////////////////////
19
////                                                                    ////
20
//// Copyright (C) 2001 Authors and OPENCORES.ORG                       ////
21
////                                                                    ////
22
//// This source file may be used and distributed without               ////
23
//// restriction provided that this copyright statement is not          ////
24
//// removed from the file and that any derivative work contains        ////
25
//// the original copyright notice and the associated disclaimer.       ////
26
////                                                                    ////
27
//// This source file is free software; you can redistribute it         ////
28
//// and/or modify it under the terms of the GNU Lesser General         ////
29
//// Public License as published by the Free Software Foundation;       ////
30
//// either version 2.1 of the License, or (at your option) any         ////
31
//// later version.                                                     ////
32
////                                                                    ////
33
//// This source is distributed in the hope that it will be             ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied         ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR            ////
36
//// PURPOSE. See the GNU Lesser General Public License for more        ////
37
//// details.                                                           ////
38
////                                                                    ////
39
//// You should have received a copy of the GNU Lesser General          ////
40
//// Public License along with this source; if not, download it         ////
41
//// from http://www.opencores.org/lgpl.shtml                           ////
42
////                                                                    ////
43
////////////////////////////////////////////////////////////////////////////
44
 
45
`include "timescale.v"
46
 
47 201 creep
module t6532(clk, reset_n, io_lines, enable, rw_mem, address, data);
48 192 creep
        parameter [3:0] DATA_SIZE = 4'd8;
49 201 creep
        parameter [3:0] ADDR_SIZE = 4'd10; // this is the *local* addr_size
50 192 creep
 
51
        localparam [3:0] DATA_SIZE_ = DATA_SIZE - 4'd1;
52
        localparam [3:0] ADDR_SIZE_ = ADDR_SIZE - 4'd1;
53
 
54 197 creep
        input clk; // master clock signal, 1.19mhz
55 201 creep
        input reset_n;
56 197 creep
        input [15:0] io_lines; // inputs from the keyboard controller
57
        input enable; // since the address bus is shared an enable signal is used
58
        input rw_mem; // read == 0, write == 1
59
        input [ADDR_SIZE_:0] address; // system address bus
60
        inout [DATA_SIZE_:0] data; // controler <=> riot data bus
61 193 creep
 
62 201 creep
        reg [DATA_SIZE_:0] ram [8'hFF:8'h80]; // the ram itself. TODO: test the memory compiler
63 194 creep
        reg [DATA_SIZE_:0] port_a;
64
        reg [DATA_SIZE_:0] port_b;
65
        reg [DATA_SIZE_:0] ddra;
66 197 creep
        reg [DATA_SIZE_:0] timer; // the timer
67
        reg c1_timer; // 1 clock cycle counter enable
68
        reg c8_timer; // 8 clock cycles counter enable
69
        reg c64_timer; // 64 clock cycles counter enable
70
        reg c1024_timer; // 1024 clock cycles counter enable
71
        reg [10:0] counter; // also called the prescaler
72
        reg flipped; // a flag to remember if the timer already flipped
73
 
74
        reg reading; // combinational logic for easing the control over timers
75
        reg writing;
76
        reg writing_at_timer;
77 196 creep
 
78 197 creep
        reg [DATA_SIZE_:0] data_drv; // wrapper for the data bus
79 193 creep
 
80 201 creep
        assign data = (rw_mem || !reset_n) ? 8'bZ : data_drv; // if under writing the bus receives the data from cpu, else local data.  
81 193 creep
 
82 201 creep
        always @(posedge clk or negedge reset_n) begin // I/O handling
83
                if (reset_n == 1'b0) begin
84
                        port_a <= 8'h00;
85
                        port_b <= 8'h00;
86
                        ddra <= 8'h00;
87 194 creep
                end
88 201 creep
                else begin
89
                        port_b[0] <= ~io_lines[0]; // these two are not actually switches
90
                        port_b[1] <= ~io_lines[1];
91
 
92
                        if (io_lines[3]) begin // these are.
93
                                port_b[3] <= !port_b[3];
94
                        end
95
                        if (io_lines[6]) begin
96
                                port_b[6] <= !port_b[6];
97
                        end
98
                        if (io_lines[7]) begin
99
                                port_b[7] <= !port_b[7];
100
                        end
101 197 creep
 
102 201 creep
                        port_a[0] <= (ddra[0] == 1'b0) ? io_lines[8] : port_a[0];
103
                        port_a[1] <= (ddra[1] == 1'b0) ? io_lines[9] : port_a[1];
104
                        port_a[2] <= (ddra[2] == 1'b0) ? io_lines[10] : port_a[2];
105
                        port_a[3] <= (ddra[3] == 1'b0) ? io_lines[11] : port_a[3];
106
                        port_a[4] <= (ddra[4] == 1'b0) ? io_lines[12] : port_a[4];
107
                        port_a[5] <= (ddra[5] == 1'b0) ? io_lines[13] : port_a[5];
108
                        port_a[6] <= (ddra[6] == 1'b0) ? io_lines[14] : port_a[6];
109
                        port_a[7] <= (ddra[7] == 1'b0) ? io_lines[15] : port_a[7];
110
                end
111 197 creep
        end
112 194 creep
 
113 201 creep
        always @(posedge clk  or negedge reset_n) begin // R/W register/memory handling
114
                if (reset_n == 1'b0) begin
115
                        data_drv <= 8'h00;
116
                        c1_timer <= 1'b0;
117
                        c8_timer <= 1'b0;
118
                        c64_timer <= 1'b0;
119
                        c1024_timer <= 1'b0;
120
                        timer <= 8'h00;
121
                        flipped <= 1'b0;
122
                        counter <= 11'd0;
123 197 creep
                end
124 201 creep
                else begin
125
                        if (reading) begin // reading! 
126
                                case (address)
127
                                        10'h280: data_drv <= port_a;
128
                                        10'h281: data_drv <= ddra;
129
                                        10'h282: data_drv <= port_b;
130
                                        10'h283: data_drv <= 8'h00; // portb ddr is always input
131
                                        10'h284: data_drv <= timer;
132
                                        default: data_drv <= ram[address[6:0]];
133
                                endcase
134
                        end
135
                        else if (writing) begin // writing! 
136
                                case (address)
137
                                        10'h294: begin
138
                                                c1_timer <= 1'b1;
139
                                                c8_timer <= 1'b0;
140
                                                c64_timer <= 1'b0;
141
                                                c1024_timer <= 1'b0;
142
                                                timer <= data;
143
                                                flipped <= 1'b0;
144
                                                counter <= 11'd1;
145
                                        end
146
                                        10'h295: begin
147
                                                c1_timer <= 1'b0;
148
                                                c8_timer <= 1'b1;
149
                                                c64_timer <= 1'b0;
150
                                                c1024_timer <= 1'b0;
151
                                                timer <= data;
152
                                                flipped <= 1'b0;
153
                                                counter <= 11'd8;
154
                                        end
155
                                        10'h296: begin
156
                                                c1_timer <= 1'b0;
157
                                                c8_timer <= 1'b0;
158
                                                c64_timer <= 1'b1;
159
                                                c1024_timer <= 1'b0;
160
                                                timer <= data;
161
                                                flipped <= 1'b0;
162
                                                counter <= 11'd64;
163
                                        end
164
                                        10'h297: begin
165
                                                c1_timer <= 1'b0;
166
                                                c8_timer <= 1'b0;
167
                                                c64_timer <= 1'b0;
168
                                                c1024_timer <= 1'b1;
169
                                                timer <= data;
170
                                                flipped <= 1'b0;
171
                                                counter <= 11'd1024;
172
                                        end
173
                                        default: begin
174
                                                ram[address[6:0]] <= data;
175
                                        end
176
                                endcase
177
                        end
178
 
179
                        if (!writing_at_timer) begin
180
                                if (counter == 11'd0) begin
181
                                        timer <= timer - 8'd1;
182
 
183
                                        if (timer == 8'd0) begin
184
                                                flipped <= 1'b1;
185
                                        end
186
 
187
                                        if (c1_timer || flipped) begin
188
                                                counter <= 11'd1;
189
                                        end
190
                                        if (c8_timer) begin
191
                                                counter <= 11'd8;
192
                                        end
193
                                        if (c64_timer) begin
194
                                                counter <= 11'd64;
195
                                        end
196
                                        if (c1024_timer) begin
197
                                                counter <= 11'd1024;
198
                                        end
199 197 creep
                                end
200 201 creep
                                else begin
201
                                        counter <= counter - 11'd1;
202 197 creep
                                end
203
                        end
204
                end
205
        end
206 201 creep
 
207
        always @(*) begin // logic for easier controlling
208 197 creep
                reading = 1'b0;
209
                writing = 1'b0;
210
                writing_at_timer = 1'b0;
211
 
212 201 creep
                if (enable && reset_n) begin
213
                        if (rw_mem == 1'b0) begin
214
                                reading = 1'b1;
215
                        end
216
                        else begin
217
                                writing = 1'b1;
218 197 creep
 
219 201 creep
                                if ( (address == 10'h294) || (address == 10'h295) || (address == 10'h296) || (address == 10'h297) ) begin
220
                                        writing_at_timer = 1'b1;
221
                                end
222 197 creep
                        end
223
                end
224
        end
225 192 creep
 
226
endmodule

powered by: WebSVN 2.1.0

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