Warp-SE/cpld/CNT.v

88 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 */
2023-03-22 01:11:58 +00:00
input C8M, input E,
2021-10-29 10:04:59 +00:00
/* Refresh request */
2023-03-22 01:11:58 +00:00
output reg RefReq, output reg 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-22 01:11:58 +00:00
output reg AoutOE, output nAoutOE, 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
2023-03-22 01:11:58 +00:00
/* Timer counts from 0 to 1001 (9) -- 10 states == 12.766 us
* 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 | 1 |
* | 8 1000 | 1 | 1 |
* | 9 1001 | 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;
always @(posedge 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;
RefUrgent <= Timer[3:0]==4'h6 || Timer[3:0]==4'h7 || Timer[3:0]==4'h8;
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 == 104.588 ms */
reg [13:0] LTimer;
wire LTimerTC = LTimer[13];
always @(negedge C8M) begin
if (TimerTC) begin
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
/* IPL2 synchronizer */
2023-03-22 01:11:58 +00:00
reg IPL2r; always @(negedge C8M) IPL2r <= !nIPL2;
2023-03-20 05:13:11 +00:00
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 05:13:11 +00:00
assign nAoutOE = !AoutOE;
2023-03-22 01:11:58 +00:00
always @(negedge 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
2023-03-22 01:11:58 +00:00
nBR_IOB <= 0; // Default to request bus
2023-03-20 04:53:10 +00:00
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-22 01:11:58 +00:00
nBR_IOB <= nBR_IOB | IPL2r; // Disable bus request if NMI pressed
if (LTimerTC && !IPL2r) PORS <= 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) PORS <= 3;
2022-09-11 21:15:53 +00:00
end 3: begin
2023-03-22 01:11:58 +00:00
AoutOE <= !nBR_IOB;
if (LTimerTC) nRESout <= 1; // Wait until LTimerTC to release reset
2023-03-20 04:53:10 +00:00
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