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

Subversion Repositories light8080

[/] [light8080/] [trunk/] [verilog/] [rtl/] [l80soc.v] - Blame information for rev 65

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

Line No. Rev Author Line
1 65 motilito
//---------------------------------------------------------------------------------------
2
//      Project:                        light8080 SOC           WiCores Solutions 
3
//
4
//      File name:                      l80soc.v                        (February 04, 2012)
5
//
6
//      Writer:                         Moti Litochevski 
7
//
8
//      Description:
9
//              This file contains the light8080 System On a Chip (SOC). the system includes the 
10
//              CPU, program and data RAM and a UART interface and a general purpose digital IO. 
11
//
12
//      Revision History:
13
//
14
//      Rev <revnumber>                 <Date>                  <owner> 
15
//              <comment>
16
// 
17
//---------------------------------------------------------------------------------------
18
// 
19
//      Copyright (C) 2012 Moti Litochevski 
20
// 
21
//      This source file may be used and distributed without restriction provided that this 
22
//      copyright statement is not removed from the file and that any derivative work 
23
//      contains the original copyright notice and the associated disclaimer.
24
//
25
//      THIS SOURCE FILE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, 
26
//      INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND 
27
//      FITNESS FOR A PARTICULAR PURPOSE. 
28
// 
29
//---------------------------------------------------------------------------------------
30
 
31
module l80soc
32
(
33
        clock, reset,
34
        txd, rxd,
35
        p1dio, p2dio
36
);
37
//---------------------------------------------------------------------------------------
38
// module interfaces 
39
// global signals 
40
input                   clock;          // global clock input 
41
input                   reset;          // global reset input 
42
// uart serial signals 
43
output                  txd;            // serial data output 
44
input                   rxd;            // serial data input 
45
// digital IO ports 
46
inout   [7:0]    p1dio;          // port 1 digital IO 
47
inout   [7:0]    p2dio;          // port 2 digital IO 
48
 
49
//---------------------------------------------------------------------------------------
50
// io space registers addresses 
51
// uart registers 
52
`define UDATA_REG                       8'h80           // used for both transmit and receive 
53
`define UBAUDL_REG                      8'h81           // low byte of baud rate register 
54
`define UBAUDH_REG                      8'h82           // low byte of baud rate register 
55
`define USTAT_REG                       8'h83           // uart status register 
56
// dio port registers 
57
`define P1_DATA_REG                     8'h84           // port 1 data register 
58
`define P1_DIR_REG                      8'h85           // port 1 direction register 
59
`define P2_DATA_REG                     8'h86           // port 2 data register 
60
`define P2_DIR_REG                      8'h87           // port 2 direction register 
61
 
62
//---------------------------------------------------------------------------------------
63
// internal declarations 
64
// registered output 
65
 
66
// internals 
67
wire [15:0] cpu_addr;
68
wire [7:0] cpu_din, cpu_dout, ram_dout;
69
wire cpu_io, cpu_rd, cpu_wr;
70
wire [7:0] txData;
71
wire txValid, txBusy, rxValid, lcd_clk;
72
wire [7:0] rxData;
73
reg [15:0] uartbaud;
74
reg rxfull, scpu_io;
75
reg [7:0] p1reg, p1dir, p2reg, p2dir, io_dout;
76
 
77
//---------------------------------------------------------------------------------------
78
// module implementation 
79
// light8080 CPU instance 
80
light8080 cpu
81
(
82
        .clk(clock),
83
        .reset(reset),
84
        .addr_out(cpu_addr),
85
        .vma(/* nu */),
86
        .io(cpu_io),
87
        .rd(cpu_rd),
88
        .wr(cpu_wr),
89
        .fetch(/* nu */),
90
        .data_in(cpu_din),
91
        .data_out(cpu_dout),
92
        .inta(/* nu */),
93
        .inte(/* nu */),
94
        .halt(/* nu */),
95
        .intr(1'b0)
96
);
97
// cpu data input selection 
98
assign cpu_din = scpu_io ? io_dout : ram_dout;
99
 
100
// program and data Xilinx RAM memory 
101
ram_image ram
102
(
103
        .clk(clock),
104
        .addr(cpu_addr[11:0]),
105
        .we(cpu_wr & ~cpu_io),
106
        .din(cpu_dout),
107
        .dout(ram_dout)
108
);
109
 
110
// io space write registers 
111
always @ (posedge reset or posedge clock)
112
begin
113
        if (reset)
114
        begin
115
                uartbaud <= 16'b0;
116
                rxfull <= 1'b0;
117
                p1reg <= 8'b0;
118
                p1dir <= 8'b0;
119
                p2reg <= 8'b0;
120
                p2dir <= 8'b0;
121
        end
122
        else
123
        begin
124
                // io space registers 
125
                if (cpu_wr && cpu_io)
126
                begin
127
                        if (cpu_addr[7:0] == `UBAUDL_REG)        uartbaud[7:0] <= cpu_dout;
128
                        if (cpu_addr[7:0] == `UBAUDH_REG)        uartbaud[15:8] <= cpu_dout;
129
                        if (cpu_addr[7:0] == `P1_DATA_REG)       p1reg <= cpu_dout;
130
                        if (cpu_addr[7:0] == `P1_DIR_REG)        p1dir <= cpu_dout;
131
                        if (cpu_addr[7:0] == `P2_DATA_REG)       p2reg <= cpu_dout;
132
                        if (cpu_addr[7:0] == `P2_DIR_REG)        p2dir <= cpu_dout;
133
                end
134
 
135
                // receiver full flag 
136
                if (rxValid && !rxfull)
137
                        rxfull <= 1'b1;
138
                else if (cpu_rd && cpu_io && (cpu_addr[7:0] == `UDATA_REG) && rxfull)
139
                        rxfull <= 1'b0;
140
        end
141
end
142
// uart transmit write pulse 
143
assign txValid = cpu_wr & cpu_io & (cpu_addr[7:0] == `UDATA_REG);
144
 
145
// io space read registers 
146
always @ (posedge reset or posedge clock)
147
begin
148
        if (reset)
149
        begin
150
                io_dout <= 8'b0;
151
        end
152
        else
153
        begin
154
                // io space read registers 
155
                if (cpu_io && (cpu_addr[7:0] == `UDATA_REG))
156
                        io_dout <= rxData;
157
                else if (cpu_io && (cpu_addr[7:0] == `USTAT_REG))
158
                        io_dout <= {3'b0, rxfull, 3'b0, txBusy};
159
                else if (cpu_io && (cpu_addr[7:0] == `P1_DATA_REG))
160
                        io_dout <= p1dio;
161
                else if (cpu_io && (cpu_addr[7:0] == `P2_DATA_REG))
162
                        io_dout <= p2dio;
163
 
164
                // sampled io control to select cpu data input 
165
                scpu_io <= cpu_io;
166
        end
167
end
168
 
169
// uart module mapped to the io space 
170
uart uart
171
(
172
        .clock(clock),
173
        .reset(reset),
174
        .serIn(rxd),
175
        .serOut(txd),
176
        .txData(cpu_dout),
177
        .txValid(txValid),
178
        .txBusy(txBusy),
179
        .txDone(/* nu */),
180
        .rxData(rxData),
181
        .rxValid(rxValid),
182
        .baudDiv(uartbaud)
183
);
184
 
185
// digital IO ports 
186
// port 1 
187
assign p1dio[0] = p1dir[0] ? p1reg[0] : 1'bz;
188
assign p1dio[1] = p1dir[1] ? p1reg[1] : 1'bz;
189
assign p1dio[2] = p1dir[2] ? p1reg[2] : 1'bz;
190
assign p1dio[3] = p1dir[3] ? p1reg[3] : 1'bz;
191
assign p1dio[4] = p1dir[4] ? p1reg[4] : 1'bz;
192
assign p1dio[5] = p1dir[5] ? p1reg[5] : 1'bz;
193
assign p1dio[6] = p1dir[6] ? p1reg[6] : 1'bz;
194
assign p1dio[7] = p1dir[7] ? p1reg[7] : 1'bz;
195
// port 2 
196
assign p2dio[0] = p2dir[0] ? p2reg[0] : 1'bz;
197
assign p2dio[1] = p2dir[1] ? p2reg[1] : 1'bz;
198
assign p2dio[2] = p2dir[2] ? p2reg[2] : 1'bz;
199
assign p2dio[3] = p2dir[3] ? p2reg[3] : 1'bz;
200
assign p2dio[4] = p2dir[4] ? p2reg[4] : 1'bz;
201
assign p2dio[5] = p2dir[5] ? p2reg[5] : 1'bz;
202
assign p2dio[6] = p2dir[6] ? p2reg[6] : 1'bz;
203
assign p2dio[7] = p2dir[7] ? p2reg[7] : 1'bz;
204
 
205
endmodule
206
//---------------------------------------------------------------------------------------
207
//                                              Th.. Th.. Th.. Thats all folks !!!
208
//---------------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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