1 |
2 |
wd5gnr |
/*
|
2 |
|
|
This file is part of Blue8.
|
3 |
|
|
|
4 |
|
|
Foobar is free software: you can redistribute it and/or modify
|
5 |
|
|
it under the terms of the GNU Lesser General Public License as published by
|
6 |
|
|
the Free Software Foundation, either version 3 of the License, or
|
7 |
|
|
(at your option) any later version.
|
8 |
|
|
|
9 |
|
|
Foobar is distributed in the hope that it will be useful,
|
10 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
GNU Lesser General Public License for more details.
|
13 |
|
|
|
14 |
|
|
You should have received a copy of the GNU Lesser General Public License
|
15 |
|
|
along with Blue8. If not, see <http://www.gnu.org/licenses/>.
|
16 |
|
|
|
17 |
|
|
Blue8 by Al Williams alw@al-williams.com
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
`default_nettype none
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
module controlclk(input wire extstart, input wire extstop, input wire extexam,
|
29 |
|
|
input wire extdeposit, input wire ihlt, input wire aluov, output wire [8:1] cp,
|
30 |
|
|
output wire [8:1] cpw, input wire extreset, output wire reset,
|
31 |
|
|
output reg sw2bus, output reg loadpc1, input wire extloadpc, output wire exout, output wire depout,
|
32 |
|
|
output wire running, input wire clk, input wire wclk, input wire abortcycle);
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
//reg [2:0] counter;
|
37 |
|
|
wire xrun, xexam, xdep, pstop, cycle, start, stop, exam, deposit,lpc, treset;
|
38 |
|
|
//initial counter=0;
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
// sync switches so that each positive edge just gives a clk pulse
|
43 |
|
|
// this might be redundant with the front panel debouncers?
|
44 |
|
|
// Note that the frontpanel reset switch is not debounced, so you still need
|
45 |
|
|
// swreset at least
|
46 |
|
|
switchsync swstart(clk,extstart,start);
|
47 |
|
|
switchsync swstop(clk,extstop,stop);
|
48 |
|
|
switchsync swexam(clk,extexam,exam);
|
49 |
|
|
switchsync swdeposit(clk,extdeposit,deposit);
|
50 |
|
|
switchsync swreset(clk,extreset,treset);
|
51 |
|
|
switchsync swlpc(clk,extloadpc,lpc);
|
52 |
|
|
|
53 |
|
|
assign reset=treset&&~xrun;
|
54 |
|
|
|
55 |
|
|
// handle "load PC"
|
56 |
|
|
/* this doesn't work with sync reset, but 2 flops below don't work either?
|
57 |
|
|
always @(posedge clk) begin
|
58 |
|
|
if (reset) begin sw2bus<=1'b0; loadpc1<=1'b0; end
|
59 |
|
|
if (lpc && ~sw2bus) begin
|
60 |
|
|
sw2bus<=1'b1;
|
61 |
|
|
end
|
62 |
|
|
if (sw2bus) begin
|
63 |
|
|
if (loadpc1==1'b0) loadpc1<=1'b1;
|
64 |
|
|
else begin
|
65 |
|
|
sw2bus<=1'b0;
|
66 |
|
|
loadpc1<=1'b0;
|
67 |
|
|
end
|
68 |
|
|
end
|
69 |
|
|
end
|
70 |
|
|
*/
|
71 |
|
|
always @(posedge clk or posedge reset) begin
|
72 |
|
|
if (reset) sw2bus<=1'b0;
|
73 |
|
|
else begin
|
74 |
|
|
if (lpc && ~sw2bus) sw2bus<=1'b1;
|
75 |
|
|
if (sw2bus && loadpc1!=1'b0) sw2bus<=1'b0;
|
76 |
|
|
end
|
77 |
|
|
end
|
78 |
|
|
|
79 |
|
|
always @(posedge clk or posedge reset) begin
|
80 |
|
|
if (reset) loadpc1<=1'b0;
|
81 |
|
|
else begin
|
82 |
|
|
if (sw2bus)
|
83 |
|
|
if (loadpc1==1'b0) loadpc1<=1'b1; else loadpc1<=1'b0;
|
84 |
|
|
end
|
85 |
|
|
end
|
86 |
|
|
//
|
87 |
|
|
|
88 |
|
|
// Handle deposit -- Fetch cycle is OK until the end (need to pass out xdep and xexam)
|
89 |
|
|
assign depout=xdep;
|
90 |
|
|
// Handle examine -- Examine cycle is OK until the end
|
91 |
|
|
assign exout=xexam;
|
92 |
|
|
assign running=xrun;
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
// this flop is set when a stop is pending
|
96 |
|
|
jkff pendstop(clk,stop|ihlt|aluov|xexam|xdep,cpw[8],pstop,treset);
|
97 |
|
|
// this flop is set when running -- the clear of this doesn't do right on single step when executing E inst.
|
98 |
|
|
// somehow step stops for the E cycle. However, changing !pende to !(pende|estate) doesn't do better
|
99 |
|
|
jkff RUN(clk,start, pstop &cpw[8] , xrun,treset);
|
100 |
|
|
// this flop sets when we are running at least one cycle
|
101 |
|
|
jkff CYCLE(clk, xrun | xexam | xdep, ((pstop)||xexam||xdep)&cpw[8],cycle,treset);
|
102 |
|
|
// examine state
|
103 |
|
|
jkff EXAM(clk,exam,cycle && cpw[8],xexam,treset);
|
104 |
|
|
// deposit state
|
105 |
|
|
jkff DEP(clk,deposit,cycle && cpw[8],xdep,treset);
|
106 |
|
|
|
107 |
|
|
// I'm trying not to use cp[n] in the cpw expressions to reduce logic levels
|
108 |
|
|
// I wonder if I'd have been better off coding this as a one hot?
|
109 |
|
|
/*
|
110 |
|
|
assign cp[1]=((counter==0)&&(xrun|xdep|xexam))?1'b1:1'b0;
|
111 |
|
|
assign cp[2]=(counter==1)?1'b1:1'b0;
|
112 |
|
|
assign cp[3]=(counter==2)?1'b1:1'b0;
|
113 |
|
|
assign cp[4]=(counter==3)?1'b1:1'b0;
|
114 |
|
|
assign cp[5]=(counter==4)?1'b1:1'b0;
|
115 |
|
|
assign cp[6]=(counter==5)?1'b1:1'b0;
|
116 |
|
|
assign cp[7]=(counter==6)?1'b1:1'b0;
|
117 |
|
|
assign cp[8]=((counter==7)&&cycle)?1'b1:1'b0;
|
118 |
|
|
assign cpw[1]=(((counter==0)&&(xrun|xdep|xexam))?1'b1:1'b0)&wclk;
|
119 |
|
|
assign cpw[2]=((counter==1)?1'b1:1'b0)&wclk;
|
120 |
|
|
assign cpw[3]=((counter==2)?1'b1:1'b0)&wclk;
|
121 |
|
|
assign cpw[4]=((counter==3)?1'b1:1'b0)&wclk;
|
122 |
|
|
assign cpw[5]=((counter==4)?1'b1:1'b0)&wclk;
|
123 |
|
|
assign cpw[6]=((counter==5)?1'b1:1'b0)&wclk;
|
124 |
|
|
assign cpw[7]=((counter==6)?1'b1:1'b0)&wclk;
|
125 |
|
|
assign cpw[8]=((counter==7)?1'b1:1'b0)&wclk;
|
126 |
|
|
|
127 |
|
|
// prime counter if starting -- note start/exam/deposit must be pulsed
|
128 |
|
|
always @(posedge clk or posedge reset) begin
|
129 |
|
|
if (reset) begin counter<=0; end
|
130 |
|
|
else begin
|
131 |
|
|
if (start||exam||deposit||abortcycle) counter<=7; else
|
132 |
|
|
if (xrun || xexam || xdep ) begin
|
133 |
|
|
counter<=counter+1;
|
134 |
|
|
end
|
135 |
|
|
end
|
136 |
|
|
end
|
137 |
|
|
*/
|
138 |
|
|
reg [7:0] onehot;
|
139 |
|
|
reg wclks;
|
140 |
|
|
assign cp[1]=onehot[0] && (xrun|xdep|xexam);
|
141 |
|
|
assign cp[2]=onehot[1];
|
142 |
|
|
assign cp[3]=onehot[2];
|
143 |
|
|
assign cp[4]=onehot[3];
|
144 |
|
|
assign cp[5]=onehot[4];
|
145 |
|
|
assign cp[6]=onehot[5];
|
146 |
|
|
assign cp[7]=onehot[6];
|
147 |
|
|
assign cp[8]=onehot[7] && cycle;
|
148 |
|
|
assign cpw[1]=wclks && onehot[0] && (xrun|xdep|xexam);
|
149 |
|
|
assign cpw[2]=wclks&onehot[1];
|
150 |
|
|
assign cpw[3]=wclks&onehot[2];
|
151 |
|
|
assign cpw[4]=wclks&onehot[3];
|
152 |
|
|
assign cpw[5]=wclks&onehot[4];
|
153 |
|
|
assign cpw[6]=wclks&onehot[5];
|
154 |
|
|
assign cpw[7]=wclks&onehot[6];
|
155 |
|
|
assign cpw[8]=wclks&&onehot[7] && cycle;
|
156 |
|
|
|
157 |
|
|
always @(posedge wclk or posedge clk) begin
|
158 |
|
|
if (wclk) wclks<=1'b1; else wclks<=1'b0;
|
159 |
|
|
end
|
160 |
|
|
|
161 |
|
|
always @(posedge clk or posedge reset) begin
|
162 |
|
|
if (reset) onehot<=8'b1;
|
163 |
|
|
else begin
|
164 |
|
|
if (start || exam || deposit || abortcycle) onehot<=8'b10000000;
|
165 |
|
|
else if (xrun||xexam || xdep) onehot<={onehot[6:0], onehot[7]};
|
166 |
|
|
end
|
167 |
|
|
end
|
168 |
|
|
|
169 |
|
|
endmodule
|
170 |
|
|
|