Line 1... |
Line 1... |
//
|
//
|
// rom.v -- parallel flash ROM interface
|
// rom.v -- parallel flash ROM interface
|
|
// 512K x 32 bit = 2 MB
|
//
|
//
|
|
|
|
|
module rom(clk, reset,
|
`timescale 1ns/10ps
|
en, wr, size, addr,
|
`default_nettype none
|
data_out, wt,
|
|
|
|
|
module rom(clk, rst,
|
|
stb, we, addr,
|
|
data_out, ack,
|
ce_n, oe_n, we_n, rst_n, byte_n, a, d);
|
ce_n, oe_n, we_n, rst_n, byte_n, a, d);
|
// internal interface signals
|
// internal interface signals
|
input clk;
|
input clk;
|
input reset;
|
input rst;
|
input en;
|
input stb;
|
input wr;
|
input we;
|
input [1:0] size;
|
input [20:2] addr;
|
input [20:0] addr;
|
|
output reg [31:0] data_out;
|
output reg [31:0] data_out;
|
output reg wt;
|
output reg ack;
|
// flash ROM interface signals
|
// flash ROM interface signals
|
output ce_n;
|
output ce_n;
|
output oe_n;
|
output oe_n;
|
output we_n;
|
output we_n;
|
output rst_n;
|
output rst_n;
|
Line 36... |
Line 40... |
assign rst_n = 1;
|
assign rst_n = 1;
|
assign byte_n = 1;
|
assign byte_n = 1;
|
|
|
// the flash ROM is organized in 16-bit halfwords
|
// the flash ROM is organized in 16-bit halfwords
|
// address line a[0] is controlled by the state machine
|
// address line a[0] is controlled by the state machine
|
// (this is necessary for word accesses)
|
// ("upper half" means "at higher address in ROM")
|
assign a[19:1] = addr[20:2];
|
assign a[19:1] = addr[20:2];
|
assign a[0] = upper_half;
|
assign a[0] = upper_half;
|
|
|
// the state machine
|
// the state machine
|
always @(posedge clk) begin
|
always @(posedge clk) begin
|
if (reset == 1) begin
|
if (rst) begin
|
state <= 0;
|
state <= 0;
|
wt <= 1;
|
ack <= 0;
|
end else begin
|
end else begin
|
if (state == 0) begin
|
if (state == 0) begin
|
// wait for start of access
|
// wait for start of access
|
if (en == 1 && wr == 0) begin
|
if (stb & ~we) begin
|
state <= 1;
|
state <= 1;
|
if (size[1] == 1) begin
|
|
// word access
|
|
upper_half <= 0;
|
upper_half <= 0;
|
end else begin
|
|
// halfword or byte access
|
|
upper_half <= addr[1];
|
|
end
|
|
end
|
end
|
end else
|
end else
|
if (state == 6) begin
|
if (state == 6) begin
|
if (size[1] == 1) begin
|
|
// word access
|
|
// latch upper halfword
|
// latch upper halfword
|
data_out[31:24] <= d[7:0];
|
data_out[31:24] <= d[7:0];
|
data_out[23:16] <= d[15:8];
|
data_out[23:16] <= d[15:8];
|
state <= 7;
|
state <= 7;
|
upper_half <= 1;
|
upper_half <= 1;
|
end else begin
|
|
// halfword or byte access
|
|
data_out[31:16] <= 16'h0000;
|
|
if (size[0] == 1) begin
|
|
// halfword access
|
|
data_out[15:8] <= d[7:0];
|
|
data_out[7:0] <= d[15:8];
|
|
end else begin
|
|
// byte access
|
|
data_out[15:8] <= 8'h00;
|
|
if (addr[0] == 0) begin
|
|
// even address
|
|
data_out[7:0] <= d[7:0];
|
|
end else begin
|
|
// odd address
|
|
data_out[7:0] <= d[15:8];
|
|
end
|
|
end
|
|
state <= 13;
|
|
wt <= 0;
|
|
end
|
|
end else
|
end else
|
if (state == 12) begin
|
if (state == 12) begin
|
// word access (state is only reached in this case)
|
|
// latch lower halfword
|
// latch lower halfword
|
data_out[15:8] <= d[7:0];
|
data_out[15:8] <= d[7:0];
|
data_out[7:0] <= d[15:8];
|
data_out[7:0] <= d[15:8];
|
state <= 13;
|
state <= 13;
|
wt <= 0;
|
ack <= 1;
|
end else
|
end else
|
if (state == 13) begin
|
if (state == 13) begin
|
// end of access
|
// end of access
|
wt <= 1;
|
ack <= 0;
|
state <= 0;
|
state <= 0;
|
end else begin
|
end else begin
|
// wait for flash ROM access time to pass
|
// wait for flash ROM access time to pass
|
state <= state + 1;
|
state <= state + 1;
|
end
|
end
|