Warp-SE/cpld/IOBM.v

121 lines
3.0 KiB
Coq
Raw Normal View History

2021-10-29 10:04:59 +00:00
module IOBM(
/* PDS interface */
2023-03-26 08:33:59 +00:00
input C16M, input C8M, input E,
2024-10-03 09:51:10 +00:00
output reg nASout, output reg nLDS, output reg nUDS, output reg nVMA,
2023-03-25 07:49:44 +00:00
input nDTACK, input nVPA, input nBERR, input nRES,
2021-10-29 10:04:59 +00:00
/* PDS address and data latch control */
2023-03-20 04:53:10 +00:00
input AoutOE, output nDoutOE, output reg ALE0, output reg nDinLE,
2021-10-29 10:04:59 +00:00
/* IO bus slave port interface */
2024-10-03 09:51:10 +00:00
input IORDREQ, input IOWRREQ, input IOLDS, input IOUDS,
output reg IOACT, output reg IODONE, output reg IOBERR);
2021-10-29 10:04:59 +00:00
/* C8M clock registration */
reg C8Mr; always @(posedge C16M) C8Mr <= C8M;
/* I/O request input synchronization */
2024-10-03 09:51:10 +00:00
reg IORDREQr; always @(posedge C16M) IORDREQr <= IORDREQ;
reg IOWRREQr; always @(posedge C16M) IOWRREQr <= IOWRREQ;
wire IOREQr = IORDREQr || IOWRREQr;
/* VPA synchronization */
reg VPAr; always @(negedge C8M) VPAr <= !nVPA;
2023-04-01 08:46:47 +00:00
2023-03-26 08:33:59 +00:00
/* E clock synchronization */
reg Er; always @(negedge C8M) begin Er <= E; end
2023-03-26 08:33:59 +00:00
2021-10-29 10:04:59 +00:00
/* E clock state */
reg [3:0] ES;
always @(negedge C8M) begin
if (!E && Er) ES <= 1;
else if (ES==0 || ES==9) ES <= 0;
2021-10-29 10:04:59 +00:00
else ES <= ES+1;
end
/* ETACK and VMA generation */
wire ETACK = (ES==8) && !nVMA;
always @(posedge C8M) begin
if ((ES==5) && IOACT && VPAr) nVMA <= 0;
else if(ES==0) nVMA <= 1;
end
/* DTACK and BERR synchronization */
2024-10-03 09:51:10 +00:00
always @(negedge C8M, posedge nASout) begin
if (nASout) begin
IODONE <= 0;
IOBERR <= 0;
end else begin
IODONE <= (!nDTACK || ETACK || !nRES);
IOBERR <= !nBERR;
end
2021-10-29 10:04:59 +00:00
end
/* I/O bus state */
reg [2:0] IOS = 0;
reg IOS0;
2024-10-03 09:51:10 +00:00
always @(posedge C16M) begin
if (IOS==0) begin
if (IOREQr && !C8Mr && AoutOE) begin // "IOS1"
IOS <= 2;
IOS0 <= 0;
end else begin // "regular" IOS0
IOS <= 0;
IOS0 <= 1;
end
2024-10-03 09:51:10 +00:00
IOACT <= IOREQr && AoutOE;
ALE0 <= IOREQr && AoutOE;
end else if (IOS==2) begin
2021-10-29 10:04:59 +00:00
IOS <= 3;
IOS0 <= 0;
2021-10-29 10:04:59 +00:00
IOACT <= 1;
ALE0 <= 1;
2024-10-03 09:51:10 +00:00
end else if (IOS==3) begin
2021-10-29 10:04:59 +00:00
IOS <= 4;
IOS0 <= 0;
2021-10-29 10:04:59 +00:00
IOACT <= 1;
ALE0 <= 1;
2024-10-03 09:51:10 +00:00
end else if (IOS==4) begin
2021-10-29 10:04:59 +00:00
IOS <= 5;
IOS0 <= 0;
IOACT <= 1;
2021-10-29 10:04:59 +00:00
ALE0 <= 1;
2024-10-03 09:51:10 +00:00
end else if (IOS==5) begin
if (!C8Mr && (IODONE || IOBERR)) begin
2021-10-29 10:04:59 +00:00
IOS <= 6;
IOACT <= 0;
end else begin
IOS <= 5;
IOACT <= 1;
end
IOS0 <= 0;
2021-10-29 10:04:59 +00:00
ALE0 <= 1;
2024-10-03 09:51:10 +00:00
end else if (IOS==6) begin
2021-10-29 10:04:59 +00:00
IOS <= 7;
IOS0 <= 0;
2021-10-29 10:04:59 +00:00
IOACT <= 0;
ALE0 <= 0;
2024-10-03 09:51:10 +00:00
end else if (IOS==7) begin
2021-10-29 10:04:59 +00:00
IOS <= 0;
IOS0 <= 1;
2021-10-29 10:04:59 +00:00
IOACT <= 0;
ALE0 <= 0;
end
2024-10-03 09:51:10 +00:00
end
2021-10-29 10:04:59 +00:00
/* PDS address and data latch control */
2023-03-20 05:13:11 +00:00
always @(negedge C16M) begin nDinLE = IOS==4 || IOS==5; end
reg DoutOE = 0;
2021-10-29 10:04:59 +00:00
always @(posedge C16M) begin
2024-10-03 09:51:10 +00:00
DoutOE <= (IOS==0 && IOWRREQr && !C8Mr) ||
(DoutOE && (IOS==2 || IOS==3 || IOS==4 || IOS==5));
2021-10-29 10:04:59 +00:00
end
assign nDoutOE = !(AoutOE && (DoutOE || (IOS0 && !IOREQr)));
2021-10-29 10:04:59 +00:00
2024-10-03 09:51:10 +00:00
/* AS, DS control */
2021-10-29 10:04:59 +00:00
always @(negedge C16M) begin
2024-10-03 09:51:10 +00:00
nASout <= !((IOS==0 && IOREQr && !C8Mr) || IOS==2 || IOS==3 || IOS==4 || IOS==5);
nLDS <= !(IOLDS && ((IOS==0 && IORDREQr && !C8Mr) || (IOS==2 && !nLDS) || IOS==3 || IOS==4 || IOS==5));
nUDS <= !(IOUDS && ((IOS==0 && IORDREQr && !C8Mr) || (IOS==2 && !nUDS) || IOS==3 || IOS==4 || IOS==5));
2021-10-29 10:04:59 +00:00
end
endmodule