//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
// Project: light8080 SOC WiCores Solutions
|
// Project: light8080 SOC WiCores Solutions
|
//
|
//
|
// File name: l80soc.v (February 04, 2012)
|
// File name: l80soc.v (February 04, 2012)
|
//
|
//
|
// Writer: Moti Litochevski
|
// Writer: Moti Litochevski
|
//
|
//
|
// Description:
|
// Description:
|
// This file contains the light8080 System On a Chip (SOC). the system includes the
|
// This file contains the light8080 System On a Chip (SOC). the system includes the
|
// CPU, program and data RAM and a UART interface and a general purpose digital IO.
|
// CPU, program and data RAM and a UART interface and a general purpose digital IO.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
//
|
//
|
// Rev <revnumber> <Date> <owner>
|
// Rev <revnumber> <Date> <owner>
|
// <comment>
|
// <comment>
|
//
|
//
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
//
|
//
|
// Copyright (C) 2012 Moti Litochevski
|
// Copyright (C) 2012 Moti Litochevski
|
//
|
//
|
// This source file may be used and distributed without restriction provided that this
|
// This source file may be used and distributed without restriction provided that this
|
// copyright statement is not removed from the file and that any derivative work
|
// copyright statement is not removed from the file and that any derivative work
|
// contains the original copyright notice and the associated disclaimer.
|
// contains the original copyright notice and the associated disclaimer.
|
//
|
//
|
// THIS SOURCE FILE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
|
// THIS SOURCE FILE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
|
// INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
|
// INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
//
|
//
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
|
|
module l80soc
|
module l80soc
|
(
|
(
|
clock, reset,
|
clock, reset,
|
txd, rxd,
|
txd, rxd,
|
p1dio, p2dio
|
p1dio, p2dio,
|
|
extint
|
);
|
);
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
// module interfaces
|
// module interfaces
|
// global signals
|
// global signals
|
input clock; // global clock input
|
input clock; // global clock input
|
input reset; // global reset input
|
input reset; // global reset input
|
// uart serial signals
|
// uart serial signals
|
output txd; // serial data output
|
output txd; // serial data output
|
input rxd; // serial data input
|
input rxd; // serial data input
|
// digital IO ports
|
// digital IO ports
|
inout [7:0] p1dio; // port 1 digital IO
|
inout [7:0] p1dio; // port 1 digital IO
|
inout [7:0] p2dio; // port 2 digital IO
|
inout [7:0] p2dio; // port 2 digital IO
|
|
// external interrupt sources
|
|
input [3:0] extint; // external interrupt sources
|
|
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
// io space registers addresses
|
// io space registers addresses
|
// uart registers
|
// uart registers
|
`define UDATA_REG 8'h80 // used for both transmit and receive
|
`define UDATA_REG 8'h80 // used for both transmit and receive
|
`define UBAUDL_REG 8'h81 // low byte of baud rate register
|
`define UBAUDL_REG 8'h81 // low byte of baud rate register
|
`define UBAUDH_REG 8'h82 // low byte of baud rate register
|
`define UBAUDH_REG 8'h82 // low byte of baud rate register
|
`define USTAT_REG 8'h83 // uart status register
|
`define USTAT_REG 8'h83 // uart status register
|
// dio port registers
|
// dio port registers
|
`define P1_DATA_REG 8'h84 // port 1 data register
|
`define P1_DATA_REG 8'h84 // port 1 data register
|
`define P1_DIR_REG 8'h85 // port 1 direction register
|
`define P1_DIR_REG 8'h85 // port 1 direction register
|
`define P2_DATA_REG 8'h86 // port 2 data register
|
`define P2_DATA_REG 8'h86 // port 2 data register
|
`define P2_DIR_REG 8'h87 // port 2 direction register
|
`define P2_DIR_REG 8'h87 // port 2 direction register
|
|
// interrupt controller register
|
|
`define INTR_EN_REG 8'h88 // interrupts enable register
|
|
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
// internal declarations
|
// internal declarations
|
// registered output
|
// registered output
|
|
|
// internals
|
// internals
|
wire [15:0] cpu_addr;
|
wire [15:0] cpu_addr;
|
wire [7:0] cpu_din, cpu_dout, ram_dout;
|
wire [7:0] cpu_din, cpu_dout, ram_dout, intr_dout;
|
wire cpu_io, cpu_rd, cpu_wr;
|
wire cpu_io, cpu_rd, cpu_wr, cpu_inta, cpu_inte, cpu_intr;
|
wire [7:0] txData;
|
wire [7:0] txData, rxData;
|
wire txValid, txBusy, rxValid, lcd_clk;
|
wire txValid, txBusy, rxValid;
|
wire [7:0] rxData;
|
|
reg [15:0] uartbaud;
|
reg [15:0] uartbaud;
|
reg rxfull, scpu_io;
|
reg rxfull, scpu_io;
|
reg [7:0] p1reg, p1dir, p2reg, p2dir, io_dout;
|
reg [7:0] p1reg, p1dir, p2reg, p2dir, io_dout;
|
|
reg [3:0] intr_ena;
|
|
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
// module implementation
|
// module implementation
|
// light8080 CPU instance
|
// light8080 CPU instance
|
light8080 cpu
|
light8080 cpu
|
(
|
(
|
.clk(clock),
|
.clk(clock),
|
.reset(reset),
|
.reset(reset),
|
.addr_out(cpu_addr),
|
.addr_out(cpu_addr),
|
.vma(/* nu */),
|
.vma(/* nu */),
|
.io(cpu_io),
|
.io(cpu_io),
|
.rd(cpu_rd),
|
.rd(cpu_rd),
|
.wr(cpu_wr),
|
.wr(cpu_wr),
|
.fetch(/* nu */),
|
.fetch(/* nu */),
|
.data_in(cpu_din),
|
.data_in(cpu_din),
|
.data_out(cpu_dout),
|
.data_out(cpu_dout),
|
.inta(/* nu */),
|
.inta(cpu_inta),
|
.inte(/* nu */),
|
.inte(cpu_inte),
|
.halt(/* nu */),
|
.halt(/* nu */),
|
.intr(1'b0)
|
.intr(cpu_intr)
|
);
|
);
|
// cpu data input selection
|
// cpu data input selection
|
assign cpu_din = scpu_io ? io_dout : ram_dout;
|
assign cpu_din = (cpu_inta) ? intr_dout : (scpu_io) ? io_dout : ram_dout;
|
|
|
// program and data Xilinx RAM memory
|
// program and data Xilinx RAM memory
|
ram_image ram
|
ram_image ram
|
(
|
(
|
.clk(clock),
|
.clk(clock),
|
.addr(cpu_addr[11:0]),
|
.addr(cpu_addr[11:0]),
|
.we(cpu_wr & ~cpu_io),
|
.we(cpu_wr & ~cpu_io),
|
.din(cpu_dout),
|
.din(cpu_dout),
|
.dout(ram_dout)
|
.dout(ram_dout)
|
);
|
);
|
|
|
// io space write registers
|
// io space write registers
|
always @ (posedge reset or posedge clock)
|
always @ (posedge reset or posedge clock)
|
begin
|
begin
|
if (reset)
|
if (reset)
|
begin
|
begin
|
uartbaud <= 16'b0;
|
uartbaud <= 16'b0;
|
rxfull <= 1'b0;
|
rxfull <= 1'b0;
|
p1reg <= 8'b0;
|
p1reg <= 8'b0;
|
p1dir <= 8'b0;
|
p1dir <= 8'b0;
|
p2reg <= 8'b0;
|
p2reg <= 8'b0;
|
p2dir <= 8'b0;
|
p2dir <= 8'b0;
|
|
intr_ena <= 4'b0;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
// io space registers
|
// io space registers
|
if (cpu_wr && cpu_io)
|
if (cpu_wr && cpu_io)
|
begin
|
begin
|
if (cpu_addr[7:0] == `UBAUDL_REG) uartbaud[7:0] <= cpu_dout;
|
if (cpu_addr[7:0] == `UBAUDL_REG) uartbaud[7:0] <= cpu_dout;
|
if (cpu_addr[7:0] == `UBAUDH_REG) uartbaud[15:8] <= cpu_dout;
|
if (cpu_addr[7:0] == `UBAUDH_REG) uartbaud[15:8] <= cpu_dout;
|
if (cpu_addr[7:0] == `P1_DATA_REG) p1reg <= cpu_dout;
|
if (cpu_addr[7:0] == `P1_DATA_REG) p1reg <= cpu_dout;
|
if (cpu_addr[7:0] == `P1_DIR_REG) p1dir <= cpu_dout;
|
if (cpu_addr[7:0] == `P1_DIR_REG) p1dir <= cpu_dout;
|
if (cpu_addr[7:0] == `P2_DATA_REG) p2reg <= cpu_dout;
|
if (cpu_addr[7:0] == `P2_DATA_REG) p2reg <= cpu_dout;
|
if (cpu_addr[7:0] == `P2_DIR_REG) p2dir <= cpu_dout;
|
if (cpu_addr[7:0] == `P2_DIR_REG) p2dir <= cpu_dout;
|
|
if (cpu_addr[7:0] == `INTR_EN_REG) intr_ena <= cpu_dout[3:0];
|
end
|
end
|
|
|
// receiver full flag
|
// receiver full flag
|
if (rxValid && !rxfull)
|
if (rxValid && !rxfull)
|
rxfull <= 1'b1;
|
rxfull <= 1'b1;
|
else if (cpu_rd && cpu_io && (cpu_addr[7:0] == `UDATA_REG) && rxfull)
|
else if (cpu_rd && cpu_io && (cpu_addr[7:0] == `UDATA_REG) && rxfull)
|
rxfull <= 1'b0;
|
rxfull <= 1'b0;
|
end
|
end
|
end
|
end
|
// uart transmit write pulse
|
// uart transmit write pulse
|
assign txValid = cpu_wr & cpu_io & (cpu_addr[7:0] == `UDATA_REG);
|
assign txValid = cpu_wr & cpu_io & (cpu_addr[7:0] == `UDATA_REG);
|
|
|
// io space read registers
|
// io space read registers
|
always @ (posedge reset or posedge clock)
|
always @ (posedge reset or posedge clock)
|
begin
|
begin
|
if (reset)
|
if (reset)
|
begin
|
begin
|
io_dout <= 8'b0;
|
io_dout <= 8'b0;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
// io space read registers
|
// io space read registers
|
if (cpu_io && (cpu_addr[7:0] == `UDATA_REG))
|
if (cpu_io && (cpu_addr[7:0] == `UDATA_REG))
|
io_dout <= rxData;
|
io_dout <= rxData;
|
else if (cpu_io && (cpu_addr[7:0] == `USTAT_REG))
|
else if (cpu_io && (cpu_addr[7:0] == `USTAT_REG))
|
io_dout <= {3'b0, rxfull, 3'b0, txBusy};
|
io_dout <= {3'b0, rxfull, 3'b0, txBusy};
|
else if (cpu_io && (cpu_addr[7:0] == `P1_DATA_REG))
|
else if (cpu_io && (cpu_addr[7:0] == `P1_DATA_REG))
|
io_dout <= p1dio;
|
io_dout <= p1dio;
|
else if (cpu_io && (cpu_addr[7:0] == `P2_DATA_REG))
|
else if (cpu_io && (cpu_addr[7:0] == `P2_DATA_REG))
|
io_dout <= p2dio;
|
io_dout <= p2dio;
|
|
|
// sampled io control to select cpu data input
|
// sampled io control to select cpu data input
|
scpu_io <= cpu_io;
|
scpu_io <= cpu_io;
|
end
|
end
|
end
|
end
|
|
|
|
// interrupt controller
|
|
intr_ctrl intrc
|
|
(
|
|
.clock(clock),
|
|
.reset(reset),
|
|
.ext_intr(extint),
|
|
.cpu_intr(cpu_intr),
|
|
.cpu_inte(cpu_inte),
|
|
.cpu_inta(cpu_inta),
|
|
.cpu_rd(cpu_rd),
|
|
.cpu_inst(intr_dout),
|
|
.intr_ena(intr_ena)
|
|
);
|
|
|
// uart module mapped to the io space
|
// uart module mapped to the io space
|
uart uart
|
uart uart
|
(
|
(
|
.clock(clock),
|
.clock(clock),
|
.reset(reset),
|
.reset(reset),
|
.serIn(rxd),
|
.serIn(rxd),
|
.serOut(txd),
|
.serOut(txd),
|
.txData(cpu_dout),
|
.txData(cpu_dout),
|
.txValid(txValid),
|
.txValid(txValid),
|
.txBusy(txBusy),
|
.txBusy(txBusy),
|
.txDone(/* nu */),
|
.txDone(/* nu */),
|
.rxData(rxData),
|
.rxData(rxData),
|
.rxValid(rxValid),
|
.rxValid(rxValid),
|
.baudDiv(uartbaud)
|
.baudDiv(uartbaud)
|
);
|
);
|
|
|
// digital IO ports
|
// digital IO ports
|
// port 1
|
// port 1
|
assign p1dio[0] = p1dir[0] ? p1reg[0] : 1'bz;
|
assign p1dio[0] = p1dir[0] ? p1reg[0] : 1'bz;
|
assign p1dio[1] = p1dir[1] ? p1reg[1] : 1'bz;
|
assign p1dio[1] = p1dir[1] ? p1reg[1] : 1'bz;
|
assign p1dio[2] = p1dir[2] ? p1reg[2] : 1'bz;
|
assign p1dio[2] = p1dir[2] ? p1reg[2] : 1'bz;
|
assign p1dio[3] = p1dir[3] ? p1reg[3] : 1'bz;
|
assign p1dio[3] = p1dir[3] ? p1reg[3] : 1'bz;
|
assign p1dio[4] = p1dir[4] ? p1reg[4] : 1'bz;
|
assign p1dio[4] = p1dir[4] ? p1reg[4] : 1'bz;
|
assign p1dio[5] = p1dir[5] ? p1reg[5] : 1'bz;
|
assign p1dio[5] = p1dir[5] ? p1reg[5] : 1'bz;
|
assign p1dio[6] = p1dir[6] ? p1reg[6] : 1'bz;
|
assign p1dio[6] = p1dir[6] ? p1reg[6] : 1'bz;
|
assign p1dio[7] = p1dir[7] ? p1reg[7] : 1'bz;
|
assign p1dio[7] = p1dir[7] ? p1reg[7] : 1'bz;
|
// port 2
|
// port 2
|
assign p2dio[0] = p2dir[0] ? p2reg[0] : 1'bz;
|
assign p2dio[0] = p2dir[0] ? p2reg[0] : 1'bz;
|
assign p2dio[1] = p2dir[1] ? p2reg[1] : 1'bz;
|
assign p2dio[1] = p2dir[1] ? p2reg[1] : 1'bz;
|
assign p2dio[2] = p2dir[2] ? p2reg[2] : 1'bz;
|
assign p2dio[2] = p2dir[2] ? p2reg[2] : 1'bz;
|
assign p2dio[3] = p2dir[3] ? p2reg[3] : 1'bz;
|
assign p2dio[3] = p2dir[3] ? p2reg[3] : 1'bz;
|
assign p2dio[4] = p2dir[4] ? p2reg[4] : 1'bz;
|
assign p2dio[4] = p2dir[4] ? p2reg[4] : 1'bz;
|
assign p2dio[5] = p2dir[5] ? p2reg[5] : 1'bz;
|
assign p2dio[5] = p2dir[5] ? p2reg[5] : 1'bz;
|
assign p2dio[6] = p2dir[6] ? p2reg[6] : 1'bz;
|
assign p2dio[6] = p2dir[6] ? p2reg[6] : 1'bz;
|
assign p2dio[7] = p2dir[7] ? p2reg[7] : 1'bz;
|
assign p2dio[7] = p2dir[7] ? p2reg[7] : 1'bz;
|
|
|
endmodule
|
endmodule
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
// Th.. Th.. Th.. Thats all folks !!!
|
// Th.. Th.. Th.. Thats all folks !!!
|
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
|
|