reg [7:0] EMMC_OUT;
reg [ 9:0] data_count;//数据写入计数
reg [367:0] data;
assign emmc_data = read_write?EMMC_OUT:1'dz;
always@(posedge EMMC_CLK)
begin
if(!rst_n)
begin
data<=368'h55;
write_over<=0;
end
else
begin
if(read_write)//可写
begin
if((data_count>0)&&(data_count<2))//发送一次
begin
EMMC_OUT<=8'b0;//发送起始位
end
else if((data_count>=2)&&(data_count<=47))//连续发送46次
begin
EMMC_OUT<=data[7:0];
data<=data>>8;
end
else if((data_count>=48)&&((data_count<=63)))//连续发送16次
begin
EMMC_OUT[0]<=crc16_out[0][63-data_count];
EMMC_OUT[1]<=crc16_out[1][63-data_count];
EMMC_OUT[2]<=crc16_out[2][63-data_count];
EMMC_OUT[3]<=crc16_out[3][63-data_count];
EMMC_OUT[4]<=crc16_out[4][63-data_count];
EMMC_OUT[5]<=crc16_out[5][63-data_count];
EMMC_OUT[6]<=crc16_out[6][63-data_count];
EMMC_OUT[7]<=crc16_out[7][63-data_count];
end
else if(data_count==64)
begin
EMMC_OUT<=8'hff;
write_over<=1;
end
end
else //可读
begin
end
end
end
always@(posedge EMMC_CLK)
begin
if(!rst_n)
data_count <= 10'd0;
else
if(read_write)
data_count <= data_count + 1'd1;
else
data_count <= 10'd0;
end