2021-10-29 10:04:59 +00:00
|
|
|
module CNT(
|
2023-07-16 03:21:44 +00:00
|
|
|
/* FSB clock and E clock inputs */
|
2024-10-03 11:59:29 +00:00
|
|
|
input CLK, input C8M, input E,
|
2024-10-11 21:28:08 +00:00
|
|
|
/* Power-on reset */
|
|
|
|
output reg nPOR,
|
2021-10-29 10:04:59 +00:00
|
|
|
/* Refresh request */
|
2024-10-03 23:13:23 +00:00
|
|
|
output reg RefReq, output reg RefUrg,
|
2023-03-26 08:33:59 +00:00
|
|
|
/* Reset, button */
|
2024-09-22 12:13:18 +00:00
|
|
|
output reg nRESout, input nRESin, input nIPL2,
|
2023-03-20 04:53:10 +00:00
|
|
|
/* Mac PDS bus master control outputs */
|
2023-04-08 09:46:13 +00:00
|
|
|
output reg AoutOE, output reg nBR_IOB,
|
2024-10-03 11:59:29 +00:00
|
|
|
/* QoS select inputs */
|
2024-10-09 12:00:35 +00:00
|
|
|
input nAS,
|
|
|
|
input ASrf,
|
2024-09-06 10:05:06 +00:00
|
|
|
input BACT,
|
2024-10-16 02:12:25 +00:00
|
|
|
input BACTr,
|
2024-10-15 07:29:31 +00:00
|
|
|
input IACK0CS,
|
|
|
|
input IACK1CS,
|
2024-10-11 20:41:31 +00:00
|
|
|
input VIACS,
|
|
|
|
input IWMCS,
|
|
|
|
input SCCCS,
|
|
|
|
input SCSICS,
|
|
|
|
input SndCSWR,
|
|
|
|
/* QoS settings inputs */
|
2024-10-15 07:29:31 +00:00
|
|
|
/*input SlowIACK,
|
2024-10-11 20:41:31 +00:00
|
|
|
input SlowVIA,
|
|
|
|
input SlowIWM,
|
|
|
|
input SlowSCC,
|
|
|
|
input SlowSCSI,
|
|
|
|
input SlowSnd,
|
|
|
|
input SlowClockGate,
|
2024-10-15 07:29:31 +00:00
|
|
|
input [3:0] SlowInterval, */
|
2024-10-03 11:59:29 +00:00
|
|
|
/* QoS outputs */
|
|
|
|
output reg QoSEN,
|
2024-10-09 12:00:35 +00:00
|
|
|
output reg MCKE);
|
2023-03-26 08:33:59 +00:00
|
|
|
|
|
|
|
/* E clock synchronization */
|
2023-07-16 06:25:27 +00:00
|
|
|
reg [1:0] Er; always @(posedge CLK) Er[1:0] <= { Er[0], E };
|
2023-03-26 08:33:59 +00:00
|
|
|
wire EFall = Er[1] && !Er[0];
|
2023-07-16 06:25:27 +00:00
|
|
|
|
2024-10-03 11:59:29 +00:00
|
|
|
/* C8M clock synchronization */
|
|
|
|
reg [3:0] C8Mr; always @(posedge CLK) C8Mr[3:0] <= { C8Mr[2:0], C8M };
|
2024-10-09 12:00:35 +00:00
|
|
|
wire C8MFall = C8Mr[1] && !C8Mr[0]; // C8M falling edge detect
|
2024-10-03 11:59:29 +00:00
|
|
|
|
2023-03-25 07:50:31 +00:00
|
|
|
/* Timer counts from 0 to 1010 (10) -- 11 states == 14.042 us
|
2023-03-22 01:11:58 +00:00
|
|
|
* Refresh timer sequence
|
2023-04-08 08:08:53 +00:00
|
|
|
* | Timer | RefReq | RefUrg |
|
|
|
|
* |---------|--------|-----------|
|
2023-03-22 01:11:58 +00:00
|
|
|
* | 0 0000 | 0 | 0 |
|
2023-04-08 08:08:53 +00:00
|
|
|
* | 1 0001 | 1 | 0 |
|
2023-03-26 08:33:59 +00:00
|
|
|
* | 2 0010 | 1 | 0 |
|
2023-03-22 01:11:58 +00:00
|
|
|
* | 3 0011 | 1 | 0 |
|
|
|
|
* | 4 0100 | 1 | 0 |
|
|
|
|
* | 5 0101 | 1 | 0 |
|
|
|
|
* | 6 0110 | 1 | 0 |
|
2023-03-25 07:50:31 +00:00
|
|
|
* | 7 0111 | 1 | 0 |
|
2024-10-03 23:13:23 +00:00
|
|
|
* | 8 1000 | 1 | 0 |
|
2023-04-10 08:08:23 +00:00
|
|
|
* | 9 1001 | 1 | 1 |
|
2023-03-25 07:50:31 +00:00
|
|
|
* | 10 1010 | 1 | 1 |
|
2023-03-20 04:53:10 +00:00
|
|
|
* back to timer==0
|
2022-09-04 01:32:05 +00:00
|
|
|
*/
|
2023-03-22 01:11:58 +00:00
|
|
|
reg [3:0] Timer = 0;
|
2024-10-03 11:59:29 +00:00
|
|
|
wire TimerTC = Timer==10;
|
|
|
|
reg TimerTick;
|
2023-03-26 08:33:59 +00:00
|
|
|
always @(posedge CLK) begin
|
|
|
|
if (EFall) begin
|
2023-03-25 07:50:31 +00:00
|
|
|
if (TimerTC) Timer <= 0;
|
|
|
|
else Timer <= Timer+1;
|
2023-07-16 03:21:44 +00:00
|
|
|
RefReq <= Timer!=10;
|
2024-10-03 23:13:23 +00:00
|
|
|
RefUrg <= Timer==8 || Timer==9;
|
2024-10-03 09:51:10 +00:00
|
|
|
end
|
2023-07-16 03:21:43 +00:00
|
|
|
end
|
2024-10-03 11:59:29 +00:00
|
|
|
always @(posedge CLK) TimerTick <= EFall && TimerTC;
|
2024-09-22 12:13:18 +00:00
|
|
|
|
2024-10-16 02:12:25 +00:00
|
|
|
/* QoS select latch */
|
|
|
|
reg SndCSWRr; always @(posedge CLK) SndCSWRr <= BACT && SndCSWR;
|
|
|
|
reg nRESr; always @(posedge CLK) nRESr <= nRESin;
|
2024-10-15 07:43:52 +00:00
|
|
|
|
|
|
|
reg [3:0] QS;
|
|
|
|
always @(posedge CLK) begin
|
2024-10-16 02:12:25 +00:00
|
|
|
if (!nRESr) QS <= 3;
|
|
|
|
else if (BACT && BACTr) begin
|
|
|
|
if (SndCSWRr) QS <= 15;
|
|
|
|
else if (IACK0CS) QS <= 15;
|
|
|
|
else if (VIACS) QS[1] <= 1;
|
|
|
|
else if (IWMCS) QS[1] <= 1;
|
|
|
|
end else if (QS!=0 && TimerTick) QS <= QS-1;
|
2024-10-15 07:43:52 +00:00
|
|
|
end
|
2024-10-14 04:53:32 +00:00
|
|
|
|
2024-10-16 02:12:25 +00:00
|
|
|
reg [1:0] QFS;
|
2024-10-15 07:43:52 +00:00
|
|
|
always @(posedge CLK) begin
|
|
|
|
if (!nRESr) QFS <= 0;
|
2024-10-16 02:12:25 +00:00
|
|
|
else if (BACT && BACTr) begin
|
|
|
|
if (SndCSWRr) QFS <= 0;
|
|
|
|
else if (IACK1CS) QFS <= 2;
|
|
|
|
else if (IACK0CS) QFS <= 0;
|
|
|
|
else if (VIACS) QFS <= 0;
|
|
|
|
else if (IWMCS) QFS <= 0;
|
|
|
|
else if (SCCCS) QFS <= 2;
|
|
|
|
end else if (QFS!=0 && TimerTick) QFS <= QFS-1;
|
|
|
|
end
|
2024-10-15 07:43:52 +00:00
|
|
|
|
|
|
|
reg ClockGateEN;
|
|
|
|
always @(posedge CLK) begin
|
2024-10-16 02:12:25 +00:00
|
|
|
if (!nRESr) ClockGateEN <= 0;
|
|
|
|
else if (BACT && BACTr) begin
|
|
|
|
if (SndCSWRr) ClockGateEN <= 1;
|
|
|
|
else if (IACK1CS) ClockGateEN <= 0;
|
|
|
|
else if (IACK0CS) ClockGateEN <= 0;
|
|
|
|
else if (VIACS) ClockGateEN <= 0;
|
|
|
|
else if (IWMCS) ClockGateEN <= 0;
|
|
|
|
else if (SCCCS) ClockGateEN <= 0;
|
|
|
|
else if (SCSICS) ClockGateEN <= 0;
|
|
|
|
end
|
2024-10-15 07:43:52 +00:00
|
|
|
end
|
2024-09-22 12:13:18 +00:00
|
|
|
|
2024-10-03 09:51:10 +00:00
|
|
|
/* QoS enable control */
|
2024-10-16 02:12:25 +00:00
|
|
|
always @(posedge CLK) if (!BACT) QoSEN <= QS!=0 && QFS==0;
|
2024-10-13 21:55:19 +00:00
|
|
|
|
2024-10-09 12:00:35 +00:00
|
|
|
/* MC68k clock gating during QoS */
|
|
|
|
always @(negedge CLK, negedge nAS) begin
|
2024-10-15 07:41:01 +00:00
|
|
|
if (!nAS) MCKE <= 1;
|
|
|
|
else MCKE <= !(QoSEN && !ASrf && !C8MFall && ClockGateEN);
|
2024-10-09 12:00:35 +00:00
|
|
|
end
|
|
|
|
|
2024-10-03 11:59:29 +00:00
|
|
|
/* Long timer counts from 0 to 4095.
|
|
|
|
* 4096 states == 57.516 ms */
|
|
|
|
reg [11:0] LTimer;
|
|
|
|
wire LTimerTC = LTimer[11:0]==12'hFFF;
|
|
|
|
reg LTimerTick;
|
|
|
|
always @(posedge CLK) if (TimerTick) LTimer <= LTimer+1;
|
|
|
|
always @(posedge CLK) LTimerTick <= TimerTick && LTimerTC;
|
|
|
|
|
|
|
|
/* C8M duty cycle check and power-on reset */
|
|
|
|
always @(posedge CLK) begin
|
|
|
|
if (C8Mr[3:0]==4'b0000 || C8Mr[3:0]==4'b1111) nPOR <= 0;
|
|
|
|
else if (C8Mr[1:0]==2'b01) nPOR <= 1;
|
|
|
|
end
|
2024-09-29 07:29:49 +00:00
|
|
|
|
2023-04-08 09:49:29 +00:00
|
|
|
/* Startup sequence state control */
|
2024-10-03 11:59:29 +00:00
|
|
|
reg [1:0] IS = 0;
|
|
|
|
always @(posedge CLK) begin
|
2024-10-03 22:45:13 +00:00
|
|
|
if (!nPOR) IS <= 0;
|
2024-10-03 11:59:29 +00:00
|
|
|
else case (IS[1:0])
|
|
|
|
0: if (LTimerTick) IS <= 1;
|
|
|
|
1: if (LTimerTick) IS <= 2;
|
2024-10-03 22:45:35 +00:00
|
|
|
2: if (LTimerTick && nIPL2) IS[0] <= 1;
|
2024-10-03 11:59:29 +00:00
|
|
|
3: IS <= 3;
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
/* Startup sequence */
|
2023-03-26 08:33:59 +00:00
|
|
|
always @(posedge CLK) begin
|
2023-04-08 09:46:13 +00:00
|
|
|
case (IS[1:0])
|
2024-10-03 11:59:29 +00:00
|
|
|
0, 1: begin
|
2023-03-20 04:53:10 +00:00
|
|
|
AoutOE <= 0; // Tristate PDS address and control
|
|
|
|
nRESout <= 0; // Hold reset low
|
2023-03-22 01:11:58 +00:00
|
|
|
nBR_IOB <= 0; // Default to request bus
|
2023-04-10 02:47:27 +00:00
|
|
|
end 2: begin
|
2024-10-03 11:59:29 +00:00
|
|
|
AoutOE <= 0;
|
2023-03-26 08:33:59 +00:00
|
|
|
nRESout <= 0;
|
2024-10-03 22:45:35 +00:00
|
|
|
if (!nIPL2) nBR_IOB <= 1; // Disable bus request if NMI pressed
|
2023-04-10 02:47:27 +00:00
|
|
|
end 3: begin
|
2024-10-03 11:59:29 +00:00
|
|
|
AoutOE <= !nBR_IOB;
|
|
|
|
if (LTimerTick) nRESout <= 1; // Release reset after a while
|
2022-09-04 01:32:05 +00:00
|
|
|
end
|
2022-09-11 21:15:53 +00:00
|
|
|
endcase
|
|
|
|
end
|
2024-10-03 09:51:10 +00:00
|
|
|
|
2021-10-29 10:04:59 +00:00
|
|
|
endmodule
|