Avalon-MM____SD_CARD IP Design
0赞(1)verilog代码
/********************************************************************
* Module Name : Crazy_SDCARD
* Author : Crazy Bingo
* Device : EP2C8Q208C8
* Version : Quartus II 10.1
* Date : 2011-3-3
* Description :
*********************************************************************/
/********************************************************************
* Module Name : Crazy_KEY_LED
* Author : Crazy Bingo
* Device : EP2C8Q208C8
* Version : Quartus II 10.1
* Date : 2011-3-2
* Description :
*********************************************************************/
module Crazy_SDCARD
(
//Avalon Clock
input csi_clk,
input csi_rst_n,
//Avalon-MM
input avs_chipselect,
input [1:0] avs_address, //multiple of 4
// input [1:0] avs_byteenable_n, //1,2,4,8,16,54,128
input avs_write,
input [31:0] avs_writedata, //32bit cpu
input avs_read,
output [31:0] avs_readdata, //32bit cpu
//Avalon Conduit
output reg coe_sd_cs,
output reg coe_sd_clk,
input coe_sd_miso,
output reg coe_sd_mosi // 2 bis led
);
//write
reg [1:0] coe_led_data_r;
always @(posedge csi_clk or negedge csi_rst_n)
begin
if(!csi_rst_n)
begin
coe_sd_cs <= 0;
coe_sd_clk <= 0;
coe_sd_mosi <= 0;
end
else if (avs_chipselect && avs_write)
begin
case(avs_address)
0: coe_sd_cs <= avs_writedata[0];
2: coe_sd_clk <= avs_writedata[0];
3: coe_sd_mosi <= avs_writedata[0];
default: ;//4
endcase
end
end
//read
reg avs_readdata_r;
always @(posedge csi_clk or negedge csi_rst_n)
begin
if(!csi_rst_n)
avs_readdata_r <= 0;
else if (avs_chipselect && avs_read && (avs_address == 4)) //for steady state
avs_readdata_r <= coe_sd_miso;
end
assign avs_readdata = avs_readdata_r;
endmodule