Line 94... |
Line 94... |
|
|
//
|
//
|
// Some WB simplifications:
|
// Some WB simplifications:
|
//
|
//
|
reg r_cmd_busy;
|
reg r_cmd_busy;
|
|
|
|
wire wb_stb, write_stb, cmd_stb, new_data, new_cmd;
|
|
wire [1:0] wb_addr;
|
|
wire [31:0] wb_data;
|
|
`ifdef WB_CLOCK
|
wire wb_stb, write_stb, cmd_stb; // read_stb
|
wire wb_stb, write_stb, cmd_stb; // read_stb
|
assign wb_stb = ((i_wb_cyc)&&(i_wb_stb)&&(~o_wb_stall));
|
assign wb_stb = ((i_wb_stb)&&(~o_wb_stall));
|
assign write_stb = ((wb_stb)&&( i_wb_we));
|
assign write_stb = ((wb_stb)&&( i_wb_we));
|
// assign read_stb = ((wb_stb)&&(~i_wb_we));
|
// assign read_stb = ((wb_stb)&&(~i_wb_we));
|
assign cmd_stb = (~r_cmd_busy)&&(write_stb)
|
assign cmd_stb = (~r_cmd_busy)&&(write_stb)
|
&&(i_wb_addr==`SDSPI_CMD_ADDRESS);
|
&&(i_wb_addr==`SDSPI_CMD_ADDRESS);
|
|
assign wb_addr = i_wb_addr;
|
|
assign wb_data = i_wb_data;
|
|
assign new_cmd = cmd_stb;
|
|
assign new_data = (i_wb_stb)&&(~o_wb_stall)&&(i_wb_we)
|
|
&&(i_wb_addr == `SDSPI_DAT_ADDRESS);
|
|
`else
|
|
reg r_wb_stb, r_write_stb, r_cmd_stb, r_new_data;
|
|
reg [1:0] r_wb_addr;
|
|
reg [31:0] r_wb_data;
|
|
always @(posedge i_clk)
|
|
r_wb_stb <= ((i_wb_stb)&&(~o_wb_stall));
|
|
always @(posedge i_clk)
|
|
r_write_stb <= ((i_wb_stb)&&(~o_wb_stall)&&(i_wb_we));
|
|
always @(posedge i_clk)
|
|
r_cmd_stb <= (~r_cmd_busy)&&(i_wb_stb)&&(~o_wb_stall)&&(i_wb_we)
|
|
&&(i_wb_addr == `SDSPI_CMD_ADDRESS);
|
|
always @(posedge i_clk)
|
|
r_new_data <= (i_wb_stb)&&(~o_wb_stall)&&(i_wb_we)
|
|
&&(i_wb_addr == `SDSPI_DAT_ADDRESS);
|
|
always @(posedge i_clk)
|
|
r_wb_addr <= i_wb_addr;
|
|
always @(posedge i_clk)
|
|
r_wb_data <= i_wb_data;
|
|
|
|
assign wb_stb = r_wb_stb;
|
|
assign write_stb= r_write_stb;
|
|
assign cmd_stb = r_cmd_stb;
|
|
assign new_cmd = r_cmd_stb;
|
|
assign new_data = r_new_data;
|
|
assign wb_addr = r_wb_addr;
|
|
assign wb_data = r_wb_data;
|
|
`endif
|
|
|
|
|
//
|
//
|
// Access to our lower-level SDSPI driver, the one that actually
|
// Access to our lower-level SDSPI driver, the one that actually
|
// uses/sets the SPI ports
|
// uses/sets the SPI ports
|
Line 181... |
Line 218... |
reg [25:0] r_watchdog;
|
reg [25:0] r_watchdog;
|
reg r_watchdog_err;
|
reg r_watchdog_err;
|
reg pre_cmd_state;
|
reg pre_cmd_state;
|
|
|
// Relieve some stress from the WB bus timing
|
// Relieve some stress from the WB bus timing
|
reg new_data, new_cmd;
|
|
reg [31:0] r_wb_data;
|
|
always @(posedge i_clk)
|
|
new_data <= (write_stb)&&(i_wb_addr == `SDSPI_DAT_ADDRESS);
|
|
always @(posedge i_clk)
|
|
new_cmd <= (~r_cmd_busy)&&(write_stb)
|
|
&&(i_wb_addr==`SDSPI_CMD_ADDRESS);
|
|
always @(posedge i_clk)
|
|
r_wb_data <= i_wb_data;
|
|
|
|
|
|
initial r_cmd_busy = 1'b0;
|
initial r_cmd_busy = 1'b0;
|
initial r_data_reg = 32'h00;
|
initial r_data_reg = 32'h00;
|
initial r_last_r_one = 8'hff;
|
initial r_last_r_one = 8'hff;
|
initial ll_cmd_stb = 1'b0;
|
initial ll_cmd_stb = 1'b0;
|
Line 357... |
Line 384... |
end else if (new_cmd)
|
end else if (new_cmd)
|
begin // Command write
|
begin // Command write
|
// Clear the error on any write, whether a commanding
|
// Clear the error on any write, whether a commanding
|
// one or not. -- provided the user requests clearing
|
// one or not. -- provided the user requests clearing
|
// it (by setting the bit high)
|
// it (by setting the bit high)
|
r_cmd_err <= (r_cmd_err)&&(~r_wb_data[15]);
|
r_cmd_err <= (r_cmd_err)&&(~wb_data[15]);
|
// In a similar fashion, we can switch fifos even if
|
// In a similar fashion, we can switch fifos even if
|
// not in the middle of a command
|
// not in the middle of a command
|
r_fifo_id <= r_wb_data[12];
|
r_fifo_id <= wb_data[12];
|
//
|
//
|
// Doesn't matter what this is set to as long as we
|
// Doesn't matter what this is set to as long as we
|
// aren't busy, so we can set it irrelevantly here.
|
// aren't busy, so we can set it irrelevantly here.
|
ll_cmd_dat <= r_wb_data[7:0];
|
ll_cmd_dat <= wb_data[7:0];
|
//
|
//
|
// Note that we only issue a write upon receiving a
|
// Note that we only issue a write upon receiving a
|
// valid command. Such a command is 8 bits, and must
|
// valid command. Such a command is 8 bits, and must
|
// start with its high order bits set to zero and one.
|
// start with its high order bits set to zero and one.
|
// Hence ... we test for that here.
|
// Hence ... we test for that here.
|
if (r_wb_data[7:6] == 2'b01)
|
if (wb_data[7:6] == 2'b01)
|
begin // Issue a command
|
begin // Issue a command
|
//
|
//
|
r_cmd_busy <= 1'b1;
|
r_cmd_busy <= 1'b1;
|
//
|
//
|
ll_cmd_stb <= 1'b1;
|
ll_cmd_stb <= 1'b1;
|
r_cmd_resp <= r_wb_data[9:8];
|
r_cmd_resp <= wb_data[9:8];
|
//
|
//
|
r_cmd_crc_stb <= 1'b1;
|
r_cmd_crc_stb <= 1'b1;
|
//
|
//
|
r_fifo_wr <= r_wb_data[10];
|
r_fifo_wr <= wb_data[10];
|
r_use_fifo <= r_wb_data[11];
|
r_use_fifo <= wb_data[11];
|
//
|
//
|
end else if (r_wb_data[7])
|
end else if (wb_data[7])
|
// If, on the other hand, the command was invalid,
|
// If, on the other hand, the command was invalid,
|
// then it must have been an attempt to read our
|
// then it must have been an attempt to read our
|
// internal configuration. So we'll place that on
|
// internal configuration. So we'll place that on
|
// our data register.
|
// our data register.
|
r_data_reg <= { 8'h00,
|
r_data_reg <= { 8'h00,
|
4'h0, max_lgblklen,
|
4'h0, max_lgblklen,
|
4'h0, r_lgblklen, 1'b0, r_sdspi_clk };
|
4'h0, r_lgblklen, 1'b0, r_sdspi_clk };
|
end else if (new_data) // Data write
|
end else if (new_data) // Data write
|
r_data_reg <= r_wb_data;
|
r_data_reg <= wb_data;
|
end
|
end
|
|
|
|
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
pre_cmd_state <= (ll_cmd_stb)&&(ll_idle);
|
pre_cmd_state <= (ll_cmd_stb)&&(ll_idle);
|
Line 477... |
Line 504... |
begin
|
begin
|
// Update our internal configuration parameters, unconnected
|
// Update our internal configuration parameters, unconnected
|
// with the card. These include the speed of the interface,
|
// with the card. These include the speed of the interface,
|
// and the size of the block length to expect as part of a FIFO
|
// and the size of the block length to expect as part of a FIFO
|
// command.
|
// command.
|
if ((new_cmd)&&(r_wb_data[7:6]==2'b11)&&(~r_data_reg[7])
|
if ((new_cmd)&&(wb_data[7:6]==2'b11)&&(~r_data_reg[7])
|
&&(r_data_reg[15:12]==4'h00))
|
&&(r_data_reg[15:12]==4'h00))
|
begin
|
begin
|
if (|r_data_reg[6:0])
|
if (|r_data_reg[6:0])
|
r_sdspi_clk <= r_data_reg[6:0];
|
r_sdspi_clk <= r_data_reg[6:0];
|
if (|r_data_reg[11:8])
|
if (|r_data_reg[11:8])
|
Line 490... |
Line 517... |
r_lgblklen <= max_lgblklen;
|
r_lgblklen <= max_lgblklen;
|
end
|
end
|
|
|
assign need_reset = 1'b0;
|
assign need_reset = 1'b0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
case(i_wb_addr)
|
case(wb_addr)
|
`SDSPI_CMD_ADDRESS:
|
`SDSPI_CMD_ADDRESS:
|
o_wb_data <= { need_reset, 11'h00,
|
o_wb_data <= { need_reset, 11'h00,
|
3'h0, fifo_crc_err,
|
3'h0, fifo_crc_err,
|
r_cmd_err, r_cmd_busy, 1'b0, r_fifo_id,
|
r_cmd_err, r_cmd_busy, 1'b0, r_fifo_id,
|
r_use_fifo, r_fifo_wr, r_cmd_resp,
|
r_use_fifo, r_fifo_wr, r_cmd_resp,
|
Line 522... |
Line 549... |
// Let's work with our FIFO memory here ...
|
// Let's work with our FIFO memory here ...
|
//
|
//
|
//
|
//
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
begin
|
begin
|
if ((write_stb)&&(i_wb_addr == `SDSPI_CMD_ADDRESS))
|
if ((write_stb)&&(wb_addr == `SDSPI_CMD_ADDRESS))
|
begin // Command write
|
begin // Command write
|
// Clear the read/write address
|
// Clear the read/write address
|
fifo_wb_addr <= {(LGFIFOLN){1'b0}};
|
fifo_wb_addr <= {(LGFIFOLN){1'b0}};
|
end else if ((wb_stb)&&(i_wb_addr[1]))
|
end else if ((wb_stb)&&(wb_addr[1]))
|
begin // On read or write, of either FIFO,
|
begin // On read or write, of either FIFO,
|
// we increase our pointer
|
// we increase our pointer
|
fifo_wb_addr <= fifo_wb_addr + 1;
|
fifo_wb_addr <= fifo_wb_addr + 1;
|
// And let ourselves know we need to update ourselves
|
// And let ourselves know we need to update ourselves
|
// on the next clock
|
// on the next clock
|
Line 562... |
Line 589... |
pre_fifo_addr_inc_wr <= ((ll_fifo_wr)&&(ll_out_stb)&&(r_have_start_token));
|
pre_fifo_addr_inc_wr <= ((ll_fifo_wr)&&(ll_out_stb)&&(r_have_start_token));
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
pre_fifo_addr_inc_rd <= ((ll_fifo_rd)&&(ll_cmd_stb)&&(ll_idle));//&&(ll_fifo_pkt_state[2:0]!=3'b000));
|
pre_fifo_addr_inc_rd <= ((ll_fifo_rd)&&(ll_cmd_stb)&&(ll_idle));//&&(ll_fifo_pkt_state[2:0]!=3'b000));
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
begin
|
begin
|
// if ((write_stb)&&(i_wb_addr == `SDSPI_CMD_ADDRESS)&&(i_wb_data[11]))
|
|
// ll_fifo_addr <= {(LGFIFOLN+2){1'b0}};
|
|
if (~r_cmd_busy)
|
if (~r_cmd_busy)
|
ll_fifo_addr <= {(LGFIFOLN+2){1'b0}};
|
ll_fifo_addr <= {(LGFIFOLN+2){1'b0}};
|
else if ((pre_fifo_addr_inc_wr)||(pre_fifo_addr_inc_rd))
|
else if ((pre_fifo_addr_inc_wr)||(pre_fifo_addr_inc_rd))
|
ll_fifo_addr <= ll_fifo_addr + 1;
|
ll_fifo_addr <= ll_fifo_addr + 1;
|
end
|
end
|
Line 602... |
Line 627... |
pre_fifo_a_wr <= (ll_fifo_wr)&&(ll_out_stb)&&(~r_fifo_id)&&(ll_fifo_wr_state == 2'b00);
|
pre_fifo_a_wr <= (ll_fifo_wr)&&(ll_out_stb)&&(~r_fifo_id)&&(ll_fifo_wr_state == 2'b00);
|
pre_fifo_b_wr <= (ll_fifo_wr)&&(ll_out_stb)&&( r_fifo_id)&&(ll_fifo_wr_state == 2'b00);
|
pre_fifo_b_wr <= (ll_fifo_wr)&&(ll_out_stb)&&( r_fifo_id)&&(ll_fifo_wr_state == 2'b00);
|
fifo_wr_crc_stb <= (ll_fifo_wr)&&(ll_out_stb)&&(ll_fifo_wr_state == 2'b00)&&(r_have_start_token);
|
fifo_wr_crc_stb <= (ll_fifo_wr)&&(ll_out_stb)&&(ll_fifo_wr_state == 2'b00)&&(r_have_start_token);
|
pre_fifo_crc_a<= (ll_fifo_wr)&&(ll_out_stb)&&(ll_fifo_wr_state == 2'b01);
|
pre_fifo_crc_a<= (ll_fifo_wr)&&(ll_out_stb)&&(ll_fifo_wr_state == 2'b01);
|
pre_fifo_crc_b<= (ll_fifo_wr)&&(ll_out_stb)&&(ll_fifo_wr_state == 2'b10);
|
pre_fifo_crc_b<= (ll_fifo_wr)&&(ll_out_stb)&&(ll_fifo_wr_state == 2'b10);
|
clear_fifo_crc <= (new_cmd)&&(r_wb_data[15]);
|
clear_fifo_crc <= (new_cmd)&&(wb_data[15]);
|
end
|
end
|
|
|
reg fifo_a_wr, fifo_b_wr;
|
reg fifo_a_wr, fifo_b_wr;
|
reg [3:0] fifo_a_wr_mask, fifo_b_wr_mask;
|
reg [3:0] fifo_a_wr_mask, fifo_b_wr_mask;
|
reg [(LGFIFOLN-1):0] fifo_a_wr_addr, fifo_b_wr_addr;
|
reg [(LGFIFOLN-1):0] fifo_a_wr_addr, fifo_b_wr_addr;
|
Line 615... |
Line 640... |
initial fifo_crc_err = 1'b0;
|
initial fifo_crc_err = 1'b0;
|
always @(posedge i_clk)
|
always @(posedge i_clk)
|
begin // One and only memory write allowed
|
begin // One and only memory write allowed
|
fifo_a_wr <= 1'b0;
|
fifo_a_wr <= 1'b0;
|
fifo_a_wr_data <= { ll_out_dat, ll_out_dat, ll_out_dat, ll_out_dat };
|
fifo_a_wr_data <= { ll_out_dat, ll_out_dat, ll_out_dat, ll_out_dat };
|
if ((write_stb)&&(i_wb_addr[1:0]==2'b10))
|
if ((write_stb)&&(wb_addr[1:0]==2'b10))
|
begin
|
begin
|
fifo_a_wr <= 1'b1;
|
fifo_a_wr <= 1'b1;
|
fifo_a_wr_mask <= 4'b1111;
|
fifo_a_wr_mask <= 4'b1111;
|
fifo_a_wr_addr <= fifo_wb_addr;
|
fifo_a_wr_addr <= fifo_wb_addr;
|
fifo_a_wr_data <= i_wb_data;
|
fifo_a_wr_data <= wb_data;
|
end else if (pre_fifo_a_wr)
|
end else if (pre_fifo_a_wr)
|
begin
|
begin
|
fifo_a_wr <= 1'b1;
|
fifo_a_wr <= 1'b1;
|
fifo_a_wr_addr <= ll_fifo_addr[(LGFIFOLN+1):2];
|
fifo_a_wr_addr <= ll_fifo_addr[(LGFIFOLN+1):2];
|
case(ll_fifo_addr[1:0])
|
case(ll_fifo_addr[1:0])
|
Line 644... |
Line 669... |
if ((fifo_a_wr)&&(fifo_a_wr_mask[3]))
|
if ((fifo_a_wr)&&(fifo_a_wr_mask[3]))
|
fifo_a_mem_3[fifo_a_wr_addr] <= fifo_a_wr_data[31:24];
|
fifo_a_mem_3[fifo_a_wr_addr] <= fifo_a_wr_data[31:24];
|
|
|
fifo_b_wr <= 1'b0;
|
fifo_b_wr <= 1'b0;
|
fifo_b_wr_data <= { ll_out_dat, ll_out_dat, ll_out_dat, ll_out_dat };
|
fifo_b_wr_data <= { ll_out_dat, ll_out_dat, ll_out_dat, ll_out_dat };
|
if ((write_stb)&&(i_wb_addr[1:0]==2'b11))
|
if ((write_stb)&&(wb_addr[1:0]==2'b11))
|
begin
|
begin
|
fifo_b_wr <= 1'b1;
|
fifo_b_wr <= 1'b1;
|
fifo_b_wr_mask <= 4'b1111;
|
fifo_b_wr_mask <= 4'b1111;
|
fifo_b_wr_addr <= fifo_wb_addr;
|
fifo_b_wr_addr <= fifo_wb_addr;
|
fifo_b_wr_data <= i_wb_data;
|
fifo_b_wr_data <= wb_data;
|
end else if (pre_fifo_b_wr)
|
end else if (pre_fifo_b_wr)
|
begin
|
begin
|
fifo_b_wr <= 1'b1;
|
fifo_b_wr <= 1'b1;
|
fifo_b_wr_addr <= ll_fifo_addr[(LGFIFOLN+1):2];
|
fifo_b_wr_addr <= ll_fifo_addr[(LGFIFOLN+1):2];
|
case(ll_fifo_addr[1:0])
|
case(ll_fifo_addr[1:0])
|
Line 771... |
Line 796... |
begin
|
begin
|
// Idle the channel
|
// Idle the channel
|
ll_fifo_rd_complete <= 1'b1;
|
ll_fifo_rd_complete <= 1'b1;
|
fifo_byte <= 8'hff;
|
fifo_byte <= 8'hff;
|
end
|
end
|
end else if ((write_stb)&&(i_wb_addr == `SDSPI_CMD_ADDRESS))
|
end else if ((write_stb)&&(wb_addr == `SDSPI_CMD_ADDRESS))
|
begin
|
begin
|
ll_fifo_pkt_state <= 3'h0;
|
ll_fifo_pkt_state <= 3'h0;
|
ll_fifo_rd_complete <= 1'b0;
|
ll_fifo_rd_complete <= 1'b0;
|
fifo_byte <= (i_wb_data[12]) ? fifo_b_byte : fifo_a_byte;
|
fifo_byte <= (wb_data[12]) ? fifo_b_byte : fifo_a_byte;
|
fifo_rd_crc_stb <= 1'b1;
|
fifo_rd_crc_stb <= 1'b1;
|
end else begin // Packet state is IDLE (clear the CRC registers)
|
end else begin // Packet state is IDLE (clear the CRC registers)
|
ll_fifo_pkt_state <= 3'b111;
|
ll_fifo_pkt_state <= 3'b111;
|
ll_fifo_rd_complete <= 1'b1;
|
ll_fifo_rd_complete <= 1'b1;
|
end
|
end
|