| 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 |
66 |
motilito |
p1dio, p2dio,
|
| 36 |
|
|
extint
|
| 37 |
65 |
motilito |
);
|
| 38 |
|
|
//---------------------------------------------------------------------------------------
|
| 39 |
|
|
// module interfaces
|
| 40 |
|
|
// global signals
|
| 41 |
|
|
input clock; // global clock input
|
| 42 |
|
|
input reset; // global reset input
|
| 43 |
|
|
// uart serial signals
|
| 44 |
|
|
output txd; // serial data output
|
| 45 |
|
|
input rxd; // serial data input
|
| 46 |
|
|
// digital IO ports
|
| 47 |
|
|
inout [7:0] p1dio; // port 1 digital IO
|
| 48 |
|
|
inout [7:0] p2dio; // port 2 digital IO
|
| 49 |
66 |
motilito |
// external interrupt sources
|
| 50 |
|
|
input [3:0] extint; // external interrupt sources
|
| 51 |
65 |
motilito |
|
| 52 |
|
|
//---------------------------------------------------------------------------------------
|
| 53 |
|
|
// io space registers addresses
|
| 54 |
|
|
// uart registers
|
| 55 |
|
|
`define UDATA_REG 8'h80 // used for both transmit and receive
|
| 56 |
|
|
`define UBAUDL_REG 8'h81 // low byte of baud rate register
|
| 57 |
|
|
`define UBAUDH_REG 8'h82 // low byte of baud rate register
|
| 58 |
|
|
`define USTAT_REG 8'h83 // uart status register
|
| 59 |
|
|
// dio port registers
|
| 60 |
|
|
`define P1_DATA_REG 8'h84 // port 1 data register
|
| 61 |
|
|
`define P1_DIR_REG 8'h85 // port 1 direction register
|
| 62 |
|
|
`define P2_DATA_REG 8'h86 // port 2 data register
|
| 63 |
|
|
`define P2_DIR_REG 8'h87 // port 2 direction register
|
| 64 |
66 |
motilito |
// interrupt controller register
|
| 65 |
|
|
`define INTR_EN_REG 8'h88 // interrupts enable register
|
| 66 |
65 |
motilito |
|
| 67 |
|
|
//---------------------------------------------------------------------------------------
|
| 68 |
|
|
// internal declarations
|
| 69 |
|
|
// registered output
|
| 70 |
|
|
|
| 71 |
|
|
// internals
|
| 72 |
|
|
wire [15:0] cpu_addr;
|
| 73 |
66 |
motilito |
wire [7:0] cpu_din, cpu_dout, ram_dout, intr_dout;
|
| 74 |
|
|
wire cpu_io, cpu_rd, cpu_wr, cpu_inta, cpu_inte, cpu_intr;
|
| 75 |
|
|
wire [7:0] txData, rxData;
|
| 76 |
|
|
wire txValid, txBusy, rxValid;
|
| 77 |
65 |
motilito |
reg [15:0] uartbaud;
|
| 78 |
|
|
reg rxfull, scpu_io;
|
| 79 |
|
|
reg [7:0] p1reg, p1dir, p2reg, p2dir, io_dout;
|
| 80 |
66 |
motilito |
reg [3:0] intr_ena;
|
| 81 |
65 |
motilito |
|
| 82 |
|
|
//---------------------------------------------------------------------------------------
|
| 83 |
|
|
// module implementation
|
| 84 |
|
|
// light8080 CPU instance
|
| 85 |
|
|
light8080 cpu
|
| 86 |
|
|
(
|
| 87 |
|
|
.clk(clock),
|
| 88 |
|
|
.reset(reset),
|
| 89 |
|
|
.addr_out(cpu_addr),
|
| 90 |
|
|
.vma(/* nu */),
|
| 91 |
|
|
.io(cpu_io),
|
| 92 |
|
|
.rd(cpu_rd),
|
| 93 |
|
|
.wr(cpu_wr),
|
| 94 |
|
|
.fetch(/* nu */),
|
| 95 |
|
|
.data_in(cpu_din),
|
| 96 |
|
|
.data_out(cpu_dout),
|
| 97 |
66 |
motilito |
.inta(cpu_inta),
|
| 98 |
|
|
.inte(cpu_inte),
|
| 99 |
65 |
motilito |
.halt(/* nu */),
|
| 100 |
66 |
motilito |
.intr(cpu_intr)
|
| 101 |
65 |
motilito |
);
|
| 102 |
|
|
// cpu data input selection
|
| 103 |
66 |
motilito |
assign cpu_din = (cpu_inta) ? intr_dout : (scpu_io) ? io_dout : ram_dout;
|
| 104 |
65 |
motilito |
|
| 105 |
|
|
// program and data Xilinx RAM memory
|
| 106 |
|
|
ram_image ram
|
| 107 |
|
|
(
|
| 108 |
|
|
.clk(clock),
|
| 109 |
|
|
.addr(cpu_addr[11:0]),
|
| 110 |
|
|
.we(cpu_wr & ~cpu_io),
|
| 111 |
|
|
.din(cpu_dout),
|
| 112 |
|
|
.dout(ram_dout)
|
| 113 |
|
|
);
|
| 114 |
|
|
|
| 115 |
|
|
// io space write registers
|
| 116 |
|
|
always @ (posedge reset or posedge clock)
|
| 117 |
|
|
begin
|
| 118 |
|
|
if (reset)
|
| 119 |
|
|
begin
|
| 120 |
|
|
uartbaud <= 16'b0;
|
| 121 |
|
|
rxfull <= 1'b0;
|
| 122 |
|
|
p1reg <= 8'b0;
|
| 123 |
|
|
p1dir <= 8'b0;
|
| 124 |
|
|
p2reg <= 8'b0;
|
| 125 |
|
|
p2dir <= 8'b0;
|
| 126 |
66 |
motilito |
intr_ena <= 4'b0;
|
| 127 |
65 |
motilito |
end
|
| 128 |
|
|
else
|
| 129 |
|
|
begin
|
| 130 |
|
|
// io space registers
|
| 131 |
|
|
if (cpu_wr && cpu_io)
|
| 132 |
|
|
begin
|
| 133 |
|
|
if (cpu_addr[7:0] == `UBAUDL_REG) uartbaud[7:0] <= cpu_dout;
|
| 134 |
|
|
if (cpu_addr[7:0] == `UBAUDH_REG) uartbaud[15:8] <= cpu_dout;
|
| 135 |
|
|
if (cpu_addr[7:0] == `P1_DATA_REG) p1reg <= cpu_dout;
|
| 136 |
|
|
if (cpu_addr[7:0] == `P1_DIR_REG) p1dir <= cpu_dout;
|
| 137 |
|
|
if (cpu_addr[7:0] == `P2_DATA_REG) p2reg <= cpu_dout;
|
| 138 |
|
|
if (cpu_addr[7:0] == `P2_DIR_REG) p2dir <= cpu_dout;
|
| 139 |
66 |
motilito |
if (cpu_addr[7:0] == `INTR_EN_REG) intr_ena <= cpu_dout[3:0];
|
| 140 |
65 |
motilito |
end
|
| 141 |
|
|
|
| 142 |
|
|
// receiver full flag
|
| 143 |
|
|
if (rxValid && !rxfull)
|
| 144 |
|
|
rxfull <= 1'b1;
|
| 145 |
|
|
else if (cpu_rd && cpu_io && (cpu_addr[7:0] == `UDATA_REG) && rxfull)
|
| 146 |
|
|
rxfull <= 1'b0;
|
| 147 |
|
|
end
|
| 148 |
|
|
end
|
| 149 |
|
|
// uart transmit write pulse
|
| 150 |
|
|
assign txValid = cpu_wr & cpu_io & (cpu_addr[7:0] == `UDATA_REG);
|
| 151 |
|
|
|
| 152 |
|
|
// io space read registers
|
| 153 |
|
|
always @ (posedge reset or posedge clock)
|
| 154 |
|
|
begin
|
| 155 |
|
|
if (reset)
|
| 156 |
|
|
begin
|
| 157 |
|
|
io_dout <= 8'b0;
|
| 158 |
|
|
end
|
| 159 |
|
|
else
|
| 160 |
|
|
begin
|
| 161 |
|
|
// io space read registers
|
| 162 |
|
|
if (cpu_io && (cpu_addr[7:0] == `UDATA_REG))
|
| 163 |
|
|
io_dout <= rxData;
|
| 164 |
|
|
else if (cpu_io && (cpu_addr[7:0] == `USTAT_REG))
|
| 165 |
|
|
io_dout <= {3'b0, rxfull, 3'b0, txBusy};
|
| 166 |
|
|
else if (cpu_io && (cpu_addr[7:0] == `P1_DATA_REG))
|
| 167 |
|
|
io_dout <= p1dio;
|
| 168 |
|
|
else if (cpu_io && (cpu_addr[7:0] == `P2_DATA_REG))
|
| 169 |
|
|
io_dout <= p2dio;
|
| 170 |
|
|
|
| 171 |
|
|
// sampled io control to select cpu data input
|
| 172 |
|
|
scpu_io <= cpu_io;
|
| 173 |
|
|
end
|
| 174 |
|
|
end
|
| 175 |
|
|
|
| 176 |
66 |
motilito |
// interrupt controller
|
| 177 |
|
|
intr_ctrl intrc
|
| 178 |
|
|
(
|
| 179 |
|
|
.clock(clock),
|
| 180 |
|
|
.reset(reset),
|
| 181 |
|
|
.ext_intr(extint),
|
| 182 |
|
|
.cpu_intr(cpu_intr),
|
| 183 |
|
|
.cpu_inte(cpu_inte),
|
| 184 |
|
|
.cpu_inta(cpu_inta),
|
| 185 |
|
|
.cpu_rd(cpu_rd),
|
| 186 |
|
|
.cpu_inst(intr_dout),
|
| 187 |
|
|
.intr_ena(intr_ena)
|
| 188 |
|
|
);
|
| 189 |
|
|
|
| 190 |
65 |
motilito |
// uart module mapped to the io space
|
| 191 |
|
|
uart uart
|
| 192 |
|
|
(
|
| 193 |
|
|
.clock(clock),
|
| 194 |
|
|
.reset(reset),
|
| 195 |
|
|
.serIn(rxd),
|
| 196 |
|
|
.serOut(txd),
|
| 197 |
|
|
.txData(cpu_dout),
|
| 198 |
|
|
.txValid(txValid),
|
| 199 |
|
|
.txBusy(txBusy),
|
| 200 |
|
|
.txDone(/* nu */),
|
| 201 |
|
|
.rxData(rxData),
|
| 202 |
|
|
.rxValid(rxValid),
|
| 203 |
|
|
.baudDiv(uartbaud)
|
| 204 |
|
|
);
|
| 205 |
|
|
|
| 206 |
|
|
// digital IO ports
|
| 207 |
|
|
// port 1
|
| 208 |
|
|
assign p1dio[0] = p1dir[0] ? p1reg[0] : 1'bz;
|
| 209 |
|
|
assign p1dio[1] = p1dir[1] ? p1reg[1] : 1'bz;
|
| 210 |
|
|
assign p1dio[2] = p1dir[2] ? p1reg[2] : 1'bz;
|
| 211 |
|
|
assign p1dio[3] = p1dir[3] ? p1reg[3] : 1'bz;
|
| 212 |
|
|
assign p1dio[4] = p1dir[4] ? p1reg[4] : 1'bz;
|
| 213 |
|
|
assign p1dio[5] = p1dir[5] ? p1reg[5] : 1'bz;
|
| 214 |
|
|
assign p1dio[6] = p1dir[6] ? p1reg[6] : 1'bz;
|
| 215 |
|
|
assign p1dio[7] = p1dir[7] ? p1reg[7] : 1'bz;
|
| 216 |
|
|
// port 2
|
| 217 |
|
|
assign p2dio[0] = p2dir[0] ? p2reg[0] : 1'bz;
|
| 218 |
|
|
assign p2dio[1] = p2dir[1] ? p2reg[1] : 1'bz;
|
| 219 |
|
|
assign p2dio[2] = p2dir[2] ? p2reg[2] : 1'bz;
|
| 220 |
|
|
assign p2dio[3] = p2dir[3] ? p2reg[3] : 1'bz;
|
| 221 |
|
|
assign p2dio[4] = p2dir[4] ? p2reg[4] : 1'bz;
|
| 222 |
|
|
assign p2dio[5] = p2dir[5] ? p2reg[5] : 1'bz;
|
| 223 |
|
|
assign p2dio[6] = p2dir[6] ? p2reg[6] : 1'bz;
|
| 224 |
|
|
assign p2dio[7] = p2dir[7] ? p2reg[7] : 1'bz;
|
| 225 |
|
|
|
| 226 |
|
|
endmodule
|
| 227 |
|
|
//---------------------------------------------------------------------------------------
|
| 228 |
|
|
// Th.. Th.. Th.. Thats all folks !!!
|
| 229 |
|
|
//---------------------------------------------------------------------------------------
|