Warp-SE/cpld/CNT.v

83 lines
2.1 KiB
Coq
Raw Normal View History

2021-10-29 10:04:59 +00:00
module CNT(
2023-03-26 08:33:59 +00:00
/* FSB clock and E clock inputs */
input CLK, input E,
2021-10-29 10:04:59 +00:00
/* Refresh request */
2023-04-08 08:08:53 +00:00
output reg RefReq, output reg RefUrg,
2023-03-26 08:33:59 +00:00
/* Reset, button */
output reg nRESout, input nIPL2,
2023-03-20 04:53:10 +00:00
/* Mac PDS bus master control outputs */
2023-03-26 08:33:59 +00:00
output reg AoutOE, output reg nBR_IOB);
/* E clock synchronization */
reg [1:0] Er;
wire EFall = Er[1] && !Er[0];
always @(posedge CLK) Er[1:0] <= { Er[0], E };
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
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 |
* | 7 0111 | 1 | 0 |
2023-04-08 08:08:53 +00:00
* | 8 1000 | 1 | 0 |
* | 9 1001 | 1 | 0 |
* | 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;
2023-04-08 08:08:53 +00:00
wire TimerTC = RefUrg;
2023-03-26 08:33:59 +00:00
always @(posedge CLK) begin
if (EFall) begin
if (TimerTC) Timer <= 0;
else Timer <= Timer+1;
2023-04-08 08:08:53 +00:00
RefUrg <= Timer==9;
RefReq <= !(Timer==10);
end
2021-10-29 10:04:59 +00:00
end
2023-03-22 01:11:58 +00:00
2023-03-26 08:33:59 +00:00
/* Long timer counts from 0 to 8191 -- 8192 states == 115.033 ms */
reg [12:0] LTimer;
reg LTimerTC;
always @(posedge CLK) begin
if (EFall && TimerTC) begin
LTimer <= LTimer+1;
LTimerTC <= LTimer[12:0]==13'h1FFE;
2021-10-29 10:04:59 +00:00
end
end
2023-03-20 05:13:11 +00:00
2023-03-26 08:33:59 +00:00
reg nIPL2r; always @(posedge CLK) nIPL2r <= nIPL2;
2022-09-04 01:32:05 +00:00
/* Startup sequence control */
reg [1:0] INITS = 0;
2023-03-26 08:33:59 +00:00
wire INITSTC = EFall && TimerTC && LTimerTC;
always @(posedge CLK) begin
case (INITS[1:0])
2'h0: 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-26 08:33:59 +00:00
if (INITSTC) INITS <= 1;
end 2'h1: begin
AoutOE <= 0;
nRESout <= 0;
nBR_IOB <= !(!nBR_IOB && nIPL2r); // Disable bus request if NMI pressed
if (INITSTC && nIPL2r) INITS <= 2;
end 2'h2: begin
AoutOE <= !nBR_IOB;
nRESout <= 0;
if (INITSTC) INITS <= 3;
end 2'h3: begin
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
2021-10-29 10:04:59 +00:00
endmodule