Warp-SE/cpld/CNT.v

125 lines
3.3 KiB
Coq
Raw Normal View History

2021-10-29 10:04:59 +00:00
module CNT(
2023-03-20 04:53:10 +00:00
/* C8M clock input */
input C8M,
2022-09-04 01:32:05 +00:00
/* FSB clock and bus active signal */
2023-03-20 04:53:10 +00:00
input FCLK, input LBACT,
2021-10-29 10:04:59 +00:00
/* Refresh request */
2022-09-04 01:32:05 +00:00
output reg RefReq, output RefUrgent,
2023-03-20 04:53:10 +00:00
/* BERR output */
output reg BERRTimeout,
2022-09-04 01:32:05 +00:00
/* Reset, switch, button */
input [3:1] SW, input nRESin, output reg nRESout, input nIPL2,
2023-03-20 04:53:10 +00:00
/* Mac PDS bus master control outputs */
output reg AoutOE, output nAoutOE, output nBR_IOB,
2022-09-04 01:32:05 +00:00
/* Configuration outputs */
2023-03-20 04:53:10 +00:00
output reg WarpEnable, output reg FastROMEN, output C20MEN, output C25MEN);
2022-09-04 01:32:05 +00:00
2023-03-20 04:53:10 +00:00
/* Timer counts from 0 to 1100000 (96) -- 97 states == 12.382 us */
reg [6:0] Timer = 0;
wire TimerTC = Timer[6:5]==2'b11;
always @(posedge C8M) Timer <= TimerTC ? 0 : Timer+1;
2022-09-04 01:32:05 +00:00
2023-03-20 04:53:10 +00:00
/* Refresh timer sequence
* | Timer | RefReq | RefUrgent |
* |----------------------------|
* | 0 | 0 | 0 |
* | 1 | 0 | 0 |
* | 2 | 0 | 0 |
* | 3 | 0 | 0 |
* | 4 | 0 | 0 |
* | 5 | 0 | 0 |
* | 6 | 0 | 0 |
* | 7 | 0 | 0 |
* | 8 | 0 | 0 |
* | 9 | 1 | 0 |
* | 10 | 1 | 0 |
* | 11 | 1 | 0 |
* | ... | 1 | 0 |
* | 62 | 1 | 0 |
* | 63 | 1 | 0 |
* | 64 | 1 | 1 |
* | 65 | 1 | 1 |
* | 66 | 1 | 1 |
* | ... | 1 | 1 |
* | 93 | 1 | 1 |
* | 94 | 1 | 1 |
* | 95 | 1 | 1 |
* | 96 | 1 | 1 |
* back to timer==0
2022-09-04 01:32:05 +00:00
*/
2023-03-20 04:53:10 +00:00
assign RefUrgent = Timer[6];
always @(posedge C8M) begin
2023-03-20 05:13:11 +00:00
if (Timer[3]) RefReq <= 1;
else if (TimerTC) RefReq <= 0;
2021-10-29 10:04:59 +00:00
end
2023-03-20 04:53:10 +00:00
/* LBACTr - LBACT synchronized to C16M clock domain */
reg LBACTr;
always @(posedge C8M) LBACTr <= LBACT;
2022-09-04 01:32:05 +00:00
2023-03-20 04:53:10 +00:00
/* BERR generation in C8M clock domain */
2022-09-04 01:32:05 +00:00
reg BERRArm = 0;
2023-03-20 04:53:10 +00:00
always @(posedge C8M) begin
if (LBACTr && TimerTC) begin
2022-09-18 09:57:45 +00:00
BERRArm <= 1;
2022-09-04 01:32:05 +00:00
if (BERRArm) BERRTimeout <= 1;
2023-03-20 04:53:10 +00:00
end else if (!LBACTr) begin
2022-09-04 01:32:05 +00:00
BERRArm <= 0;
BERRTimeout <= 0;
2021-10-29 10:04:59 +00:00
end
end
2023-03-20 04:53:10 +00:00
/* Long timer counts from 0 to 16384 -- 16385 states == 202.888 ms */
reg [14:0] LTimer; // Long timer
2023-03-20 05:13:11 +00:00
wire LTimerTC = LTimer[14];
2023-03-20 04:53:10 +00:00
always @(posedge C8M) begin
if (LTimerTC) LTimer <= 0;
else LTimer <= LTimer+1;
2022-09-18 09:57:45 +00:00
end
2023-03-20 05:13:11 +00:00
/* IPL2 synchronizer */
reg IPL2r;
always @(posedge C8M) IPL2r <= !nIPL2;
2022-09-04 01:32:05 +00:00
/* Startup sequence control */
2022-09-18 09:57:45 +00:00
reg [1:0] PORS = 0;
2023-03-20 04:53:10 +00:00
reg Disable = 0;
2023-03-20 05:13:11 +00:00
reg BR_IOB = 0; assign nBR_IOB = !BR_IOB;
assign nAoutOE = !AoutOE;
2023-03-20 04:53:10 +00:00
always @(posedge C8M) begin
2022-09-18 09:57:45 +00:00
case (PORS)
2022-09-11 21:15:53 +00:00
0: begin
2023-03-20 04:53:10 +00:00
AoutOE <= 0; // Tristate PDS address and control
nRESout <= 0; // Hold reset low
Disable <= 0;
if (LTimerTC) PORS <= 1;
2022-09-11 21:15:53 +00:00
end 1: begin
2023-03-20 04:53:10 +00:00
AoutOE <= 0; // Tristate PDS address and control
nRESout <= 0; // Hold reset low
2023-03-20 05:13:11 +00:00
Disable <= Disable | IPL2r;
2023-03-20 04:53:10 +00:00
if (!IPL2r && LTimerTC) begin
BR_IOB <= !Disable;
PORS <= 2;
end
2022-09-11 21:15:53 +00:00
end 2: begin
2023-03-20 04:53:10 +00:00
AoutOE <= 0; // Tristate PDS address and control
nRESout <= 0; // Hold reset low
if (LTimerTC) PORS <= 3;
2022-09-11 21:15:53 +00:00
end 3: begin
2023-03-20 04:53:10 +00:00
AoutOE <= BR_IOB;
// Wait until LTimerTC to release reset
if (LTimerTC) nRESout <= 1;
else nRESout = 0;
PORS <= 3;
2022-09-04 01:32:05 +00:00
end
2022-09-11 21:15:53 +00:00
endcase
end
2022-09-04 01:32:05 +00:00
// Enable both oscillators... only mount one
2022-09-05 08:37:18 +00:00
assign C20MEN = 1;
assign C25MEN = 1;
2023-03-20 04:53:10 +00:00
// Enable fast ROM
assign FastROMEN = 1;
2022-09-04 01:32:05 +00:00
2021-10-29 10:04:59 +00:00
endmodule