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 52 to Rev 53
- ↔ Reverse comparison
Rev 52 → Rev 53
/sdhc-sc-core/trunk/src/grpSd/unitSdCardModel/src/SdCardModel.sv
37,7 → 37,6
aCrc crc7; |
logic endbit; |
|
|
function void display(); |
$display("Startbit: %b", startbit); |
$display("Transbit: %b", transbit); |
59,23 → 58,24
endfunction |
|
function void checkCrc(); |
assert(crc7 == calcCrc()); |
assert(crc7 == calcCrcOfToken()); |
endfunction |
|
function automatic aCrc calcCrc(); |
function automatic aCrc calcCrcOfToken(); |
logic[39:0] temp; |
aCrc crc = 0; |
logic[39:0] temp; |
|
temp[39] = startbit; |
temp[38] = transbit; |
temp[37:32] = id; |
temp[31:0] = arg; |
|
|
for(int i = 39; i >= 0; i--) begin |
if (((crc[6] & 1)) != temp[i]) |
crc = (crc << 1) ^ 'b10001001; |
else |
crc <<= 1; |
end |
crc = (crc << 1) ^ 'b10001001; |
else |
crc <<= 1; |
end |
return crc; |
endfunction |
|
89,21 → 89,87
endclass |
|
class SDCommandResponse; |
protected logic startbit; |
protected logic transbit; |
protected logic[5:0] id; |
protected SDCommandArg arg; |
protected aCrc crc; |
protected logic endbit; |
|
function automatic void calcCrc(); |
logic[39:0] temp; |
|
temp[39] = startbit; |
temp[38] = transbit; |
temp[37:32] = id; |
temp[31:0] = arg; |
|
for(int i = 39; i >= 0; i--) begin |
if (((crc[6] & 1)) != temp[i]) |
crc = (crc << 1) ^ 'b10001001; |
else |
crc <<= 1; |
end |
endfunction |
|
|
task automatic send(virtual ISdCmd.Card ICmd); |
calcCrc(); |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= startbit; |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= transbit; |
|
for(int i = 5; i >= 0; i--) begin |
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= id[i]; |
end |
|
for (int i = 31; i>= 0; i--) begin |
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= arg[i]; |
end |
|
for (int i = 5; i >= 0; i--) begin |
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= crc[i]; |
end |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= endbit; |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= 'z; |
endtask |
endclass |
|
class SDCommandR7 extends SDCommandResponse; |
|
function new(SDCommandArg arg); |
startbit = 0; |
transbit = 0; |
id = cSdCmdSendIfCond; |
this.arg = arg; |
endbit = 1; |
endfunction |
|
endclass |
|
class SDCard; |
virtual ISdCmd.Card ICmd; |
local virtual ISdCmd.Card ICmd; |
|
SDCardState state; |
SDCommandToken recvcmd; |
local SDCardState state; |
local SDCommandToken recvcmd; |
|
event CmdReceived; |
local event CmdReceived, InitDone; |
|
function new(virtual ISdCmd CmdInterface, event CmdReceived); |
ICmd = CmdInterface; |
function new(virtual ISdCmd CmdInterface, event CmdReceived, event InitDone); |
ICmd = CmdInterface; |
state = idle; |
this.CmdReceived = CmdReceived; |
this.InitDone = InitDone; |
endfunction |
|
task reset(); |
110,11 → 176,12
state = idle; |
endtask |
|
// Receive a command token and handle it |
task recv(); |
recvcmd = new(); |
ICmd.cbCard.Cmd <= 'z; |
|
@(ICmd.cbCard.Cmd == 0); |
wait(ICmd.cbCard.Cmd == 0); |
// Startbit |
recvcmd.startbit = ICmd.cbCard.Cmd; |
|
144,9 → 211,32
@ICmd.cbCard; |
recvcmd.endbit = ICmd.cbCard.Cmd; |
|
recvcmd.checkFromHost(); |
-> CmdReceived; |
endtask |
|
task automatic init(); |
SDCommandR7 voltageresponse; |
SDCommandResponse response; |
|
// expect CMD0 so that state is clear |
recv(); |
assert(recvcmd.id == cSdCmdGoIdleState); |
|
// expect CMD8: voltage and SD 2.00 compatible |
recv(); |
assert(recvcmd.id == cSdCmdSendIfCond); |
assert(recvcmd.arg[12:8] == 'b0001); // Standard voltage |
|
// respond with R7: we are SD 2.00 compatible and compatible to the |
// voltage |
voltageresponse = new(recvcmd.arg); |
response = voltageresponse; |
response.send(ICmd); |
|
-> InitDone; |
|
endtask |
|
function automatic SDCommandToken getCmd(); |
return recvcmd; |
/sdhc-sc-core/trunk/src/grpSd/unitSdVerificationTestbench/src/SdVerificationTestbench.sv
10,9 → 10,11
|
`define cCmdCount 1000 |
|
const logic[3:0] cSdStandardVoltage = 'b0001; // 2.7-3.6V |
|
program Test(ISdCmd ICmd); |
initial begin |
SDCard card = new(ICmd, $root.Testbed.CmdReceived); |
SDCard card = new(ICmd, $root.Testbed.CmdReceived, $root.Testbed.InitDone); |
SDCommandToken recvCmd, sendCmd; |
bit done = 0; |
int c = 0; |
27,8 → 29,27
|
fork |
begin // generator |
// init |
sendCmd = new(); |
|
@ICmd.cb; |
sendCmd.id = cSdCmdGoIdleState; |
sendCmd.arg = 0; |
-> $root.Testbed.ApplyCommand; |
@$root.Testbed.CmdReceived; |
|
sendCmd.id = cSdCmdSendIfCond; |
sendCmd.arg[31:12] = 0; // Reserved |
sendCmd.arg[11:8] = cSdStandardVoltage; // 2.7 - 3.6V |
sendCmd.arg[7:0] = 'b10101010; // Check pattern, recommended value |
-> $root.Testbed.ApplyCommand; |
@$root.Testbed.CmdReceived; |
|
ICmd.Valid <= 0; |
@$root.Testbed.InitDone; |
|
for (int i = 0; i < `cCmdCount; i++) begin |
@ICmd.cb; |
$display("generator: %0d", i); |
sendCmd = new(); |
sendCmd.randomize(); |
-> $root.Testbed.ApplyCommand; |
40,8 → 61,10
end |
|
begin // driver for SdCmd |
for (int i = 0; i < `cCmdCount; i++) begin |
for (int i = 0; i < `cCmdCount + 2; i++) begin |
@$root.Testbed.ApplyCommand; |
|
$display("driver: %0d", i); |
ICmd.CmdId <= sendCmd.id; |
ICmd.Arg <= sendCmd.arg; |
ICmd.Valid <= 1; |
50,15 → 73,22
end |
|
begin // driver for SdCardModel |
card.init(); |
|
for (int i = 0; i < `cCmdCount; i++) begin |
@$root.Testbed.CardRecv; |
|
$display("driver2: %0d", i); |
card.recv(); |
end |
end |
|
begin // checker |
@$root.Testbed.InitDone; |
|
for (int i = 0; i < `cCmdCount; i++) begin |
@$root.Testbed.CmdReceived; |
$display("checker: %0d", i); |
recvCmd = card.getCmd(); |
//recvCmd.display(); |
//sendCmd.display(); |
85,6 → 115,6
|
Test tb(CmdInterface); |
|
event ApplyCommand, CardRecv, CmdReceived, GenCmd; |
event ApplyCommand, CardRecv, CmdReceived, GenCmd, InitDone; |
|
endmodule |