OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 102 to Rev 103
    Reverse comparison

Rev 102 → Rev 103

/sdhc-sc-core/trunk/src/grpSd/unitSdData/src/SdData-Rtl-a.vhdl
125,7 → 125,7
if (iSdDataFromController.DataMode = widewidth) then
if (iSdDataFromController.ExpectBits = ScrBits) then
NextR.ByteCounter <= to_unsigned(63, aByteCounter'length);
else
elsif (iSdDataFromController.ExpectBits = SwitchFunctionBits) then
NextR.ByteCounter <= to_unsigned(511, aByteCounter'length);
end if;
end if;
/sdhc-sc-core/trunk/src/grpSd/unitSdCardModel/src/SdData.sv
24,25 → 24,62
this.datamode = datamode;
endfunction
 
task automatic send(virtual ISdCmd.Card ICmd, logic data[$]);
aCrc16 crc = 0;
data.push_front(0); // startbit
function void CrcOnContainer(inout logic data[$]);
aCrc16 crc = 0;
crc = calcCrc16(data);
 
for (int i = 15; i >= 0; i--)
data.push_back(crc[i]);
endfunction
 
data.push_back(1); // endbit
foreach(data[i]) begin
task automatic send(virtual ISdCmd.Card ICmd, logic data[$]);
aCrc16 crc = 0;
 
if (mode == standard) begin
data.push_front(0); // startbit
CrcOnContainer(data);
data.push_back(1); // endbit
foreach(data[i]) begin
@ICmd.cb;
ICmd.cb.Data[0] <= data[i];
end
 
data = {};
@ICmd.cb;
ICmd.cb.Data[0] <= data[i];
ICmd.cb.Data <= 'z;
end
else begin
logic dat0[$];
logic dat1[$];
logic dat2[$];
logic dat3[$];
 
data = {};
@ICmd.cb;
ICmd.cb.Data <= 'z;
for (int i = 0; i < data.size(); i+=4) begin
dat3.push_back(data[i]);
dat2.push_back(data[i+1]);
dat1.push_back(data[i+2]);
dat0.push_back(data[i+3]);
end
CrcOnContainer(dat0);
CrcOnContainer(dat1);
CrcOnContainer(dat2);
CrcOnContainer(dat3);
 
@ICmd.cb;
ICmd.cb.Data = 0;
 
for(int i = 0; i < dat0.size(); i++) begin
@ICmd.cb;
ICmd.cb.Data <= (dat3[i]<<3) + (dat2[i] <<2) + (dat1[i] <<1) + dat0[i];
end
@ICmd.cb;
ICmd.cb.Data = 0;
 
@ICmd.cb;
ICmd.cb.Data <= 'z;
end
endtask
 
endclass
/sdhc-sc-core/trunk/src/grpSd/unitSdCardModel/src/SdCardModel.sv
185,6 → 185,25
response = new(cSdCmdSetBusWidth, state);
response.send(ICmd);
 
sddata.mode = wide;
 
// expect CMD6
recv();
assert(recvcmd.id == cSdCmdSwitchFuntion);
assert(recvcmd.arg == 'h00FFFFF1);
response.send(ICmd);
 
// send status data structure
data = {};
for (int i = 0; i < 512; i++)
data.push_back(0);
 
data[511-400] = 1;
data[511-376] = 1;
sddata.send(ICmd, data);
 
-> InitDone;
 
endtask
/sdhc-sc-core/trunk/src/grpSd/unitSdCardModel/src/SdCommand.sv
13,6 → 13,7
cSdCmdAllSendCID = 2,
cSdCmdSendRelAdr = 3,
cSdCmdSetDSR = 4, // [31:16] DSR
cSdCmdSwitchFuntion = 6,
cSdCmdSelCard = 7, // [31:16] RCA
cSdCmdSendIfCond = 8, // [31:12] reserved, [11:8] supply voltage, [7:0] check pattern
cSdCmdSendCSD = 9, // [31:16] RCA
/sdhc-sc-core/trunk/src/grpSd/pkgSd/src/Sd-p.vhdl
112,7 → 112,7
 
type aSdDataBusMode is (standard, wide);
type aSdDataMode is (usual, widewidth);
type aSdDataBits is (ScrBits);
type aSdDataBits is (ScrBits, SwitchFunctionBits);
 
-- Types for entities
-- between SdController and SdCmd
241,6 → 241,18
constant cSdWideBusWidth : std_ulogic_vector(1 downto 0) := "10";
constant cSdStandardBusWidth : std_ulogic_vector(1 downto 0) := "00";
 
constant cSdCmdSwitchFunction : aSdCmdId := std_ulogic_vector(to_unsigned(6, cSdCmdIdHigh));
-- 31: mode
constant cSdCmdCheckMode : std_ulogic := '0';
constant cSdCmdSwitchMode : std_ulogic := '1';
-- 30:24 reserved
-- 23:8 function group 6 - 3
-- 7:4 group 2 for command system
-- 3:0 group 1 for access mode
constant cSdCmdCheckSpeedSupport : aSdCmdArg := X"00FFFFF1";
constant cSdHighSpeedFunctionSupportBit : natural := 400;
constant cSdHighSpeedFunctionGroupLow : natural := 376;
 
end package Sd;
 
package body Sd is
/sdhc-sc-core/trunk/src/grpSd/unitSdController/src/SdController-Rtl-a.vhdl
11,7 → 11,7
architecture Rtl of SdController is
 
type aSdControllerState is (startup, init, config, idle, invalidCard);
type aCmdRegion is (CMD0, CMD8, ACMD41, CMD2, CMD3, SelectCard, CheckBusWidth, SetBusWidth, CheckSpeed);
type aCmdRegion is (CMD0, CMD8, ACMD41, CMD2, CMD3, SelectCard, CheckBusWidth, SetBusWidth, CheckSpeed, ChangeSpeed);
type aRegion is (idle, send, response, waitstate, senddata, receivedata, checkbusy, waitstatedata);
constant cDefaultToSdCmd : aSdCmdFromController := (
255,11 → 255,11
NextRegion := send;
 
when others =>
report "SdController: Unhandled state" severity error;
report "SdController: Unhandled region" severity error;
end case;
 
when others =>
report "SdController: Unhandled state" severity error;
report "SdController: Unhandled CmdRegion" severity error;
end case;
 
when config =>
330,16 → 330,8
end if;
 
when receivedata =>
if (iSdData.Err = cActivated) then
NextR.State <= init;
null;
 
elsif (iSdData.Valid = cActivated) then
NextR.Region <= waitstatedata;
 
elsif (Timeout = cActivated) then
NextR.State <= invalidCard;
end if;
 
when waitstatedata =>
NextRegion := send;
360,8 → 352,6
end if;
 
when SetBusWidth =>
oLedBank(4) <= cActivated;
 
if (R.SendCMD55 = cInactivated) then
case R.Region is
when send =>
393,8 → 383,54
end if;
 
when CheckSpeed =>
NextR.State <= idle;
oLedBank(4) <= cActivated;
NextR.ToSdData.DataMode <= widewidth;
NextR.ToSdData.ExpectBits <= SwitchFunctionBits;
 
case R.Region is
when send =>
NextR.ToSdCmd.Content.id <= cSdCmdSwitchFunction;
NextR.ToSdCmd.Content.arg <= cSdCmdCheckSpeedSupport;
NextRegion := response;
 
when response =>
if (iSdCmd.Valid = cActivated) then
if (iSdCmd.Content.id = cSdCmdSwitchFunction) then
NextR.CardStatus <= iSdCmd.Content.arg;
NextR.Region <= receivedata;
else
NextR.State <= invalidCard;
end if;
elsif (Timeout = cActivated) then
NextR.State <= invalidCard;
end if;
 
when receivedata =>
null;
when waitstatedata =>
NextRegion := send;
 
if (NextCmdTimeout = cActivated) then
if (iSdData.DataBlock(cSdHighSpeedFunctionSupportBit) = cActivated and
iSdData.DataBlock(cSdHighSpeedFunctionGroupLow+3 downto cSdHighSpeedFunctionGroupLow) = X"1") then
NextCmdRegion := ChangeSpeed;
NextRegion := idle;
 
else
NextState := idle;
end if;
end if;
 
 
when others =>
report "Unhandled region";
end case;
 
when ChangeSpeed =>
oLedBank(1) <= cActivated;
 
when others =>
report "Unhandled CmdRegion" severity error;
end case;
470,6 → 506,17
when receivedata =>
TimeoutEnable <= cActivated;
 
if (iSdData.Err = cActivated) then
NextR.State <= init;
 
elsif (iSdData.Valid = cActivated) then
NextR.Region <= waitstatedata;
 
elsif (Timeout = cActivated) then
NextR.State <= invalidCard;
end if;
 
 
when waitstatedata =>
NextCmdTimeoutEnable <= cActivated;
488,7 → 535,7
TimeoutGenerator_inst: entity work.TimeoutGenerator
generic map (
gClkFrequency => 25E6,
gTimeoutTime => 100 ms
gTimeoutTime => 10 ms
)
port map (
iClk => iClk,

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.