📄 epcs_controller.v
字号:
else
begin
if (write_shift_reg)
delayCounter <= 2833;
if (transmitting & slowclock & (delayCounter != 0))
delayCounter <= delayCounter - 1;
end
end
// 'state' counts from 0 to 17.
always @(posedge clk or negedge reset_n)
begin
if (reset_n == 0)
state <= 0;
else if (transmitting & slowclock & (delayCounter == 0))
if (state == 17)
state <= 0;
else
state <= state + 1;
end
assign enableSS = transmitting & (delayCounter != 2833);
assign MOSI = shift_reg[7];
assign SS_n = (enableSS | SSO_reg) ? ~epcs_slave_select_reg : {1 {1'b1} };
assign SCLK = SCLK_reg;
// As long as there's an empty spot somewhere,
//it's safe to write data.
assign TRDY = ~(transmitting & tx_holding_primed);
// Enable write to tx_holding_register.
assign write_tx_holding = data_wr_strobe & TRDY;
// Enable write to shift register.
assign write_shift_reg = tx_holding_primed & ~transmitting;
always @(posedge clk or negedge reset_n)
begin
if (reset_n == 0)
begin
shift_reg <= 0;
rx_holding_reg <= 0;
EOP <= 0;
RRDY <= 0;
ROE <= 0;
TOE <= 0;
tx_holding_reg <= 0;
tx_holding_primed <= 0;
transmitting <= 0;
SCLK_reg <= 0;
MISO_reg <= 0;
end
else
begin
if (write_tx_holding)
begin
tx_holding_reg <= data_from_cpu;
tx_holding_primed <= 1;
end
if (data_wr_strobe & ~TRDY)
// You wrote when I wasn't ready.
TOE <= 1;
// EOP must be updated by the last (2nd) cycle of access.
if ((p1_data_rd_strobe && (rx_holding_reg == endofpacketvalue_reg)) || (p1_data_wr_strobe && (data_from_cpu[7 : 0] == endofpacketvalue_reg)))
EOP <= 1;
if (write_shift_reg)
begin
shift_reg <= tx_holding_reg;
transmitting <= 1;
end
if (write_shift_reg & ~write_tx_holding)
// Clear tx_holding_primed
tx_holding_primed <= 0;
if (data_rd_strobe)
// On data read, clear the RRDY bit.
RRDY <= 0;
if (status_wr_strobe)
begin
// On status write, clear all status bits (ignore the data).
EOP <= 0;
RRDY <= 0;
ROE <= 0;
TOE <= 0;
end
if (slowclock && (delayCounter == 0))
begin
if (state == 17)
begin
transmitting <= 0;
RRDY <= 1;
rx_holding_reg <= shift_reg;
SCLK_reg <= 0;
if (RRDY)
ROE <= 1;
end
else if (state != 0)
if (transmitting)
SCLK_reg <= ~SCLK_reg;
if (SCLK_reg ^ 0 ^ 0)
begin
if (1)
shift_reg <= {shift_reg[6 : 0], MISO_reg};
end
else
MISO_reg <= MISO;
end
end
end
endmodule
module tornado_epcs_controller_atom (
// inputs:
dclkin,
oe,
scein,
sdoin,
// outputs:
data0out
);
output data0out;
input dclkin;
input oe;
input scein;
input sdoin;
wire data0out;
//synthesis translate_off
//////////////// SIMULATION-ONLY CONTENTS
assign data0out = sdoin | scein | dclkin | oe;
//////////////// END SIMULATION-ONLY CONTENTS
//synthesis translate_on
//synthesis read_comments_as_HDL on
// tornado_spiblock the_tornado_spiblock
// (
// .data0out (data0out),
// .dclkin (dclkin),
// .oe (oe),
// .scein (scein),
// .sdoin (sdoin)
// );
//
//
//synthesis read_comments_as_HDL off
endmodule
module epcs_controller (
// inputs:
address,
chipselect,
clk,
read_n,
reset_n,
write_n,
writedata,
// outputs:
dataavailable,
endofpacket,
irq,
readdata,
readyfordata
);
output dataavailable;
output endofpacket;
output irq;
output [ 31: 0] readdata;
output readyfordata;
input [ 8: 0] address;
input chipselect;
input clk;
input read_n;
input reset_n;
input write_n;
input [ 31: 0] writedata;
wire MISO;
wire MOSI;
wire SCLK;
wire SS_n;
wire [ 15: 0] data_from_cpu;
wire [ 15: 0] data_to_cpu;
wire dataavailable;
wire endofpacket;
wire epcs_select;
wire irq;
wire [ 2: 0] mem_addr;
wire [ 31: 0] readdata;
wire readyfordata;
wire [ 31: 0] rom_readdata;
epcs_controller_sub the_epcs_controller_sub
(
.MISO (MISO),
.MOSI (MOSI),
.SCLK (SCLK),
.SS_n (SS_n),
.clk (clk),
.data_from_cpu (data_from_cpu),
.data_to_cpu (data_to_cpu),
.dataavailable (dataavailable),
.endofpacket (endofpacket),
.epcs_select (epcs_select),
.irq (irq),
.mem_addr (mem_addr),
.read_n (read_n),
.readyfordata (readyfordata),
.reset_n (reset_n),
.write_n (write_n)
);
//epcs_control_port, which is an e_avalon_slave
tornado_epcs_controller_atom the_tornado_epcs_controller_atom
(
.data0out (MISO),
.dclkin (SCLK),
.oe (1'b0),
.scein (SS_n),
.sdoin (MOSI)
);
assign epcs_select = chipselect && (address[7] );
assign mem_addr = address;
assign data_from_cpu = writedata;
assign readdata = epcs_select ? data_to_cpu : rom_readdata;
//synthesis translate_off
//////////////// SIMULATION-ONLY CONTENTS
altsyncram the_boot_copier_rom
(
.address_a (address[6 : 0]),
.clock0 (clk),
.q_a (rom_readdata)
);
defparam the_boot_copier_rom.byte_size = 8,
the_boot_copier_rom.init_file =
`ifdef NO_PLI
"epcs_controller_boot_rom.dat"
`else
"epcs_controller_boot_rom.hex"
`endif
,
the_boot_copier_rom.lpm_type = "altsyncram",
the_boot_copier_rom.numwords_a = 128,
the_boot_copier_rom.operation_mode = "ROM",
the_boot_copier_rom.outdata_reg_a = "UNREGISTERED",
the_boot_copier_rom.read_during_write_mode_mixed_ports = "DONT_CARE",
the_boot_copier_rom.width_a = 32,
the_boot_copier_rom.widthad_a = 7;
//////////////// END SIMULATION-ONLY CONTENTS
//synthesis translate_on
//synthesis read_comments_as_HDL on
// altsyncram the_boot_copier_rom
// (
// .address_a (address[6 : 0]),
// .clock0 (clk),
// .q_a (rom_readdata)
// );
//
// defparam the_boot_copier_rom.byte_size = 8,
// the_boot_copier_rom.init_file = "epcs_controller_boot_rom.hex",
// the_boot_copier_rom.lpm_type = "altsyncram",
// the_boot_copier_rom.numwords_a = 128,
// the_boot_copier_rom.operation_mode = "ROM",
// the_boot_copier_rom.outdata_reg_a = "UNREGISTERED",
// the_boot_copier_rom.read_during_write_mode_mixed_ports = "DONT_CARE",
// the_boot_copier_rom.width_a = 32,
// the_boot_copier_rom.widthad_a = 7;
//
//synthesis read_comments_as_HDL off
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -