Warp-SE/cpld/CNT.v

89 lines
2.5 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, input E, input Er,
2021-10-29 10:04:59 +00:00
/* Refresh request */
output reg RefReq, output RefUrgent,
2022-09-04 01:32:05 +00:00
/* Reset, switch, button */
2023-03-22 01:11:58 +00:00
input [3:1] SW, output reg nRESout, input nIPL2,
2023-03-20 04:53:10 +00:00
/* Mac PDS bus master control outputs */
2023-03-25 04:59:14 +00:00
output reg AoutOE, output reg nBR_IOB,
2022-09-04 01:32:05 +00:00
/* Configuration outputs */
2023-03-22 01:11:58 +00:00
output C20MEN, output C25MEN, output FastROMEN);
2022-09-04 01:32:05 +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
* | Timer | RefReq | RefUrgent |
* |------------------------------|
* | 0 0000 | 0 | 0 |
* | 1 0001 | 0 | 0 |
* | 2 0010 | 0 | 0 |
* | 3 0011 | 1 | 0 |
* | 4 0100 | 1 | 0 |
* | 5 0101 | 1 | 0 |
* | 6 0110 | 1 | 0 |
* | 7 0111 | 1 | 0 |
2023-03-22 01:11:58 +00:00
* | 8 1000 | 1 | 1 |
* | 9 1001 | 1 | 1 |
* | 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;
reg TimerTC;
assign RefUrgent = Timer[3];
always @(negedge C8M) begin
if (Er && !E) begin
TimerTC <= Timer[3:0]==4'h8;
if (TimerTC) Timer <= 0;
else Timer <= Timer+1;
RefReq <= Timer[3:0]==4'h2 ||
Timer[3:0]==4'h3 || Timer[3:0]==4'h4 || Timer[3:0]==4'h5 ||
Timer[3:0]==4'h6 || Timer[3:0]==4'h7 || Timer[3:0]==4'h8;
end
2021-10-29 10:04:59 +00:00
end
2023-03-22 01:11:58 +00:00
/* Long timer counts from 0 to 8192 -- 8193 states == 115.046 ms */
2023-03-22 01:11:58 +00:00
reg [13:0] LTimer;
wire LTimerTC = LTimer[13];
always @(negedge C8M) begin
if (Er && !E) && TimerTC begin
2023-03-22 01:11:58 +00:00
if (LTimerTC) LTimer <= 0;
else LTimer <= LTimer+1;
2021-10-29 10:04:59 +00:00
end
end
2023-03-20 05:13:11 +00:00
2022-09-04 01:32:05 +00:00
/* Startup sequence control */
reg [1:0] INITS = 0;
assign nAoutOE = !AoutOE;
2023-03-22 01:11:58 +00:00
always @(negedge C8M) begin
case (INITS)
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
2023-03-22 01:11:58 +00:00
nBR_IOB <= 0; // Default to request bus
if (LTimerTC) INITS <= 1;
else INITS <= 0;
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
nBR_IOB <= nBR_IOB | !nIPL2; // Disable bus request if NMI pressed
if (LTimerTC && !IPL2r) INITS <= 2;
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) INITS <= 3;
2022-09-11 21:15:53 +00:00
end 3: begin
AoutOE <= !nBR_IOB; // Get on PDS bus if bus was requested
nRESout <= 1; // Release reset
INITS <= 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