Skip to content

Commit 81df67e

Browse files
committed
freerun gateware now validates all addresses from the m68k to check proper function
1 parent 79a75bf commit 81df67e

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

hdl/mojo/ise/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# HDL
2+
3+
## freerun
4+
5+
Puts the m68k into a "freerun". The data bus is wired to 0x0000, which is the opcode for "ORI.B #0, D0". The processor's address bus should could 0, 2, 4, then 6 for the first 4 cycles. This sets both the program counter and the stack pointer to 0x0000. The processor will then jump back to 0 and start counting through all addresses until it wraps back around to 0x0000. At 12.5 MHz, this takes about 2.68 seconds.
6+
7+
This example will validate that the addresses count as expected to validate the correct operation of the address bus, address strobe, reset, and clock signals. If an error is encountered, a single 'E' is output to the UART and the m68k will be reset.
8+
9+
## bus-to-uart
10+
11+
Communicates every bus state over the uart so that a host side program can issue commands directly to it and watch what happens. Should validate all bus signals.
12+
13+
## mojo-base-project
14+
15+
Submodule pointing to the base ISE project for the mojo board from Embedded Micro (now Alchitry). This provides the avr interface module.

hdl/mojo/ise/freerun/m68k_tester.v

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ module m68k_tester(
4343
wire rst_out_n;
4444
wire clk_sys;
4545
wire clk_m68k;
46+
wire clk_m68k_sample;
4647
clk_wiz_v3_6 pll (
4748
.clk_50_in(clk_50),
4849
.clk_50_out(clk_sys),
50+
.clk_25_out(clk_m68k_sample),
4951
.clk_12_5_out(clk_m68k),
5052
.rst_in(~rst_n),
5153
.rst_out_n(rst_out_n)
@@ -85,10 +87,6 @@ wire avr_data_out_ready;
8587
wire avr_data_out_busy;
8688
wire avr_data_in_ready;
8789

88-
// note: data is sent if "ready" is 1 and "busy" is 0 on any given clock cycle
89-
assign avr_data_out = 8'h00;
90-
assign avr_data_ready = 1'd0;
91-
9290
avr_interface #(.CLK_RATE(50000000)) avr (
9391
.clk(clk_sys),
9492
.rst(rst),
@@ -121,36 +119,88 @@ assign m68k_BERR_n = 1'd1;
121119
// ---- Freerun Test ----
122120

123121
// delay startup by 2^24 sysclk cycles (about 300 milliseconds)
122+
wire error;
124123
reg m68k_RESET_in_n_q;
125124
reg [23:0] startup_delay;
126125
always @(posedge clk_sys) begin
127-
if (rst) begin
126+
if (rst | error) begin
128127
startup_delay <= 24'd0;
129128
m68k_RESET_in_n_q <= 1'd0;
130129
end else if (~m68k_RESET_in_n_q) begin
131130
{m68k_RESET_in_n_q, startup_delay} <= startup_delay + 1;
132131
end
133132
end
134133

134+
// synchronize the m68k bus signals with the FPGA
135+
reg [23:0] a_sample;
136+
reg as_sample;
137+
138+
always @(posedge clk_m68k_sample) begin
139+
if (~m68k_RESET_out_n) begin
140+
a_sample <= 24'd0;
141+
as_sample <= 1'd0;
142+
end else begin
143+
a_sample <= m68k_A;
144+
as_sample <= ~m68k_AS_n;
145+
end
146+
end
147+
148+
// system logic reading synchronized m68k bus signals
149+
150+
// Address Strobe edges
151+
reg as_edge;
152+
always @(posedge clk_sys) begin
153+
if (rst) begin
154+
as_edge <= 1'd0;
155+
end else begin
156+
as_edge <= as_sample;
157+
end
158+
end
159+
160+
wire as_asserted;
161+
wire as_deasserted;
162+
assign as_asserted = ~as_edge & as_sample;
163+
assign as_deasserted = as_edge & ~as_sample;
164+
165+
// assign leds on the start of the bus cycle
135166
reg [7:0] leds_q;
136-
reg as_previous;
137-
// wait for falling edge of AS
167+
assign led = leds_q;
138168
always @(posedge clk_sys) begin
139169
if (rst) begin
140170
leds_q <= 8'd0;
141-
as_previous <= 1'd1;
142-
end else begin
143-
if (as_previous & ~m68k_AS_n) begin
144-
leds_q <= m68k_A[23:16];
145-
end
146-
as_previous <= m68k_AS_n;
171+
end else if (as_asserted) begin
172+
leds_q <= m68k_A[23:16];
147173
end
148174
end
149175

150176
// DTACK_n grounded
151177
assign m68k_DTACK_n = 1'd0;
152178
assign m68k_RESET_in = ~m68k_RESET_in_n_q;
153179
assign m68k_D_out = 16'd0;
154-
assign led = leds_q;
180+
181+
// validate received address
182+
reg [23:0] expected_address;
183+
reg has_started;
184+
always @(posedge clk_sys) begin
185+
// increment expected address after cycle ends
186+
if (~m68k_RESET_out_n) begin
187+
expected_address <= 24'd0;
188+
has_started <= 1'd0;
189+
end else if (as_deasserted) begin
190+
if (~has_started & expected_address == 24'd6) begin
191+
// account for the first 4 reads, reset to zero
192+
expected_address <= 24'd0;
193+
has_started <= 1'd1;
194+
end else
195+
expected_address <= expected_address + 2;
196+
end
197+
end
198+
199+
// error if there is an address mismatch
200+
assign error = as_asserted & (expected_address != a_sample);
201+
202+
// send 'E' on error
203+
assign avr_data_out = 8'h45;
204+
assign avr_data_out_ready = error;
155205

156206
endmodule

0 commit comments

Comments
 (0)