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

Subversion Repositories t6507lp

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

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 203 creep
module t6532(clk, reset_n, io_lines, enable, mem_rw, 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 203 creep
        input mem_rw; // read == 0, write == 1
59 197 creep
        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 203 creep
        assign data = (mem_rw || !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 204 creep
                        port_b <= 8'b00001000; // D3=1, color!
86 201 creep
                        ddra <= 8'h00;
87 194 creep
                end
88 201 creep
                else begin
89 204 creep
                        if (io_lines[0]) begin // these are switches
90
                                port_b[0] <= !port_b[0];
91
                        end
92
                        if (io_lines[1]) begin
93
                                port_b[1] <= !port_b[1];
94
                        end
95
                        if (io_lines[3]) begin
96 201 creep
                                port_b[3] <= !port_b[3];
97
                        end
98
                        if (io_lines[6]) begin
99
                                port_b[6] <= !port_b[6];
100
                        end
101
                        if (io_lines[7]) begin
102
                                port_b[7] <= !port_b[7];
103
                        end
104 197 creep
 
105 201 creep
                        port_a[0] <= (ddra[0] == 1'b0) ? io_lines[8] : port_a[0];
106
                        port_a[1] <= (ddra[1] == 1'b0) ? io_lines[9] : port_a[1];
107
                        port_a[2] <= (ddra[2] == 1'b0) ? io_lines[10] : port_a[2];
108
                        port_a[3] <= (ddra[3] == 1'b0) ? io_lines[11] : port_a[3];
109
                        port_a[4] <= (ddra[4] == 1'b0) ? io_lines[12] : port_a[4];
110
                        port_a[5] <= (ddra[5] == 1'b0) ? io_lines[13] : port_a[5];
111
                        port_a[6] <= (ddra[6] == 1'b0) ? io_lines[14] : port_a[6];
112
                        port_a[7] <= (ddra[7] == 1'b0) ? io_lines[15] : port_a[7];
113
                end
114 197 creep
        end
115 194 creep
 
116 201 creep
        always @(posedge clk  or negedge reset_n) begin // R/W register/memory handling
117
                if (reset_n == 1'b0) begin
118
                        data_drv <= 8'h00;
119
                        c1_timer <= 1'b0;
120
                        c8_timer <= 1'b0;
121
                        c64_timer <= 1'b0;
122
                        c1024_timer <= 1'b0;
123
                        timer <= 8'h00;
124
                        flipped <= 1'b0;
125
                        counter <= 11'd0;
126 197 creep
                end
127 201 creep
                else begin
128
                        if (reading) begin // reading! 
129
                                case (address)
130
                                        10'h280: data_drv <= port_a;
131
                                        10'h281: data_drv <= ddra;
132
                                        10'h282: data_drv <= port_b;
133
                                        10'h283: data_drv <= 8'h00; // portb ddr is always input
134
                                        10'h284: data_drv <= timer;
135 204 creep
                                        default: data_drv <= ram[address];
136 201 creep
                                endcase
137
                        end
138
                        else if (writing) begin // writing! 
139 204 creep
                                case (address)
140
                                        10'h281: begin
141
                                                ddra <= data;
142
                                        end
143 201 creep
                                        10'h294: begin
144
                                                c1_timer <= 1'b1;
145
                                                c8_timer <= 1'b0;
146
                                                c64_timer <= 1'b0;
147
                                                c1024_timer <= 1'b0;
148
                                                timer <= data;
149
                                                flipped <= 1'b0;
150
                                                counter <= 11'd1;
151
                                        end
152
                                        10'h295: begin
153
                                                c1_timer <= 1'b0;
154
                                                c8_timer <= 1'b1;
155
                                                c64_timer <= 1'b0;
156
                                                c1024_timer <= 1'b0;
157
                                                timer <= data;
158
                                                flipped <= 1'b0;
159 204 creep
                                                counter <= 11'd7;
160 201 creep
                                        end
161
                                        10'h296: begin
162
                                                c1_timer <= 1'b0;
163
                                                c8_timer <= 1'b0;
164
                                                c64_timer <= 1'b1;
165
                                                c1024_timer <= 1'b0;
166
                                                timer <= data;
167
                                                flipped <= 1'b0;
168 204 creep
                                                counter <= 11'd63;
169 201 creep
                                        end
170
                                        10'h297: begin
171
                                                c1_timer <= 1'b0;
172
                                                c8_timer <= 1'b0;
173
                                                c64_timer <= 1'b0;
174
                                                c1024_timer <= 1'b1;
175
                                                timer <= data;
176
                                                flipped <= 1'b0;
177 204 creep
                                                counter <= 11'd1023;
178 201 creep
                                        end
179
                                        default: begin
180 204 creep
                                                ram[address] <= data;
181 201 creep
                                        end
182
                                endcase
183
                        end
184
 
185
                        if (!writing_at_timer) begin
186 204 creep
                                if (flipped || timer == 8'd0) begin // finished counting
187
                                        counter <= 11'd0;
188 201 creep
                                        timer <= timer - 8'd1;
189 204 creep
                                        flipped <= 1'b1;
190
                                end
191
                                else begin
192
                                        if (counter == 11'd0) begin
193
                                                timer <= timer - 8'd1;
194 201 creep
 
195 204 creep
                                                if (c1_timer) begin
196
                                                        counter <= 11'd0;
197
                                                end
198
                                                if (c8_timer) begin
199
                                                        counter <= 11'd7;
200
                                                end
201
                                                if (c64_timer) begin
202
                                                        counter <= 11'd63;
203
                                                end
204
                                                if (c1024_timer) begin
205
                                                        counter <= 11'd1023;
206
                                                end
207 201 creep
                                        end
208 204 creep
                                        else begin
209
                                                counter <= counter - 11'd1;
210 201 creep
                                        end
211 197 creep
                                end
212
                        end
213
                end
214
        end
215 201 creep
 
216
        always @(*) begin // logic for easier controlling
217 197 creep
                reading = 1'b0;
218
                writing = 1'b0;
219
                writing_at_timer = 1'b0;
220
 
221 201 creep
                if (enable && reset_n) begin
222 203 creep
                        if (mem_rw == 1'b0) begin
223 201 creep
                                reading = 1'b1;
224
                        end
225
                        else begin
226
                                writing = 1'b1;
227 197 creep
 
228 201 creep
                                if ( (address == 10'h294) || (address == 10'h295) || (address == 10'h296) || (address == 10'h297) ) begin
229
                                        writing_at_timer = 1'b1;
230
                                end
231 197 creep
                        end
232
                end
233
        end
234 192 creep
 
235
endmodule

powered by: WebSVN 2.1.0

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