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

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpSdVerification/] [unitSdCardModel/] [src/] [SdCardModel.sv] - Diff between revs 56 and 57

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 56 Rev 57
Line 20... Line 20...
         cSdCmdSelCard = 7, // [31:16] RCA
         cSdCmdSelCard = 7, // [31:16] RCA
         cSdCmdSendIfCond = 8, // [31:12] reserved, [11:8] supply voltage, [7:0] check pattern
         cSdCmdSendIfCond = 8, // [31:12] reserved, [11:8] supply voltage, [7:0] check pattern
         cSdCmdSendCSD = 9, // [31:16] RCA
         cSdCmdSendCSD = 9, // [31:16] RCA
         cSdCmdSendCID = 10, // [31:16] RCA
         cSdCmdSendCID = 10, // [31:16] RCA
         cSdCmdStopTrans = 12,
         cSdCmdStopTrans = 12,
         cSdCmdSendStatus = 13 // [31:16] RCA
         cSdCmdSendStatus = 13, // [31:16] RCA
 
         cSdCmdNextIsACMD = 55 // [31:16] RCA
} SDCommandId;
} SDCommandId;
 
 
typedef enum {
typedef enum {
        idle
        cSdCmdACMD41 = 41
} SDCardState;
} SDAppCommandId;
 
 
 
const SDCommandArg cSdArgACMD41HCS = 'b01000000111111111000000000000000;
 
 
 
typedef enum {
 
        idle = 0, ready = 1, ident = 2, stby = 3, trans = 4,
 
        data = 5, rcv = 6, prg = 7, dis = 8
 
} SDCardStates;
 
 
 
class SDCardState;
 
        local logic OutOfRange;
 
        local logic AddressError;
 
        local logic BlockLenError;
 
 
 
        local logic[3:0] state;
 
 
 
        local logic AppCmd;
 
 
 
        function new();
 
                OutOfRange = 0;
 
                AddressError = 0;
 
                BlockLenError = 0;
 
                state = idle;
 
                AppCmd = 0;
 
        endfunction
 
 
 
        function void recvCMD55();
 
                AppCmd = 1;
 
        endfunction
 
 
 
        function automatic SDCommandArg get();
 
                SDCommandArg temp = 0;
 
                temp[31] = OutOfRange;
 
                temp[30] = AddressError;
 
                temp[29] = BlockLenError;
 
                temp[12:9] = state;
 
                temp[5] = AppCmd;
 
                return temp;
 
        endfunction
 
 
 
endclass
 
 
class SDCommandToken;
class SDCommandToken;
        logic startbit;
        logic startbit;
        logic transbit;
        logic transbit;
        rand logic[5:0] id;
        rand logic[5:0] id;
Line 156... Line 197...
                endbit = 1;
                endbit = 1;
        endfunction
        endfunction
 
 
endclass
endclass
 
 
 
class SDCommandR1 extends SDCommandResponse;
 
 
 
        function new(SDCommandId id, SDCardState state);
 
                startbit = 0;
 
                transbit = 0;
 
                this.id = id;
 
                this.arg = state.get();
 
                endbit = 1;
 
        endfunction
 
 
 
endclass
 
 
class SDCard;
class SDCard;
        local virtual ISdCmd.Card ICmd;
        local virtual ISdCmd.Card ICmd;
 
 
        local SDCardState state;
        local SDCardState state;
        local SDCommandToken recvcmd;
        local SDCommandToken recvcmd;
 
 
        local event CmdReceived, InitDone;
        local event CmdReceived, InitDone;
 
 
        function new(virtual ISdCmd CmdInterface, event CmdReceived, event InitDone);
        function new(virtual ISdCmd CmdInterface, event CmdReceived, event InitDone);
                ICmd = CmdInterface;
                ICmd = CmdInterface;
                state = idle;
                state = new();
                this.CmdReceived = CmdReceived;
                this.CmdReceived = CmdReceived;
                this.InitDone = InitDone;
                this.InitDone = InitDone;
        endfunction
        endfunction
 
 
        task reset();
        task reset();
                state = idle;
 
        endtask
        endtask
 
 
        // Receive a command token and handle it
        // Receive a command token and handle it
        task recv();
        task recv();
                recvcmd = new();
                recvcmd = new();
Line 216... Line 268...
                -> CmdReceived;
                -> CmdReceived;
        endtask
        endtask
 
 
        task automatic init();
        task automatic init();
                SDCommandR7 voltageresponse;
                SDCommandR7 voltageresponse;
                SDCommandResponse response;
                SDCommandR1 response;
 
 
                // expect CMD0 so that state is clear
                // expect CMD0 so that state is clear
                recv();
                recv();
                assert(recvcmd.id == cSdCmdGoIdleState);
                assert(recvcmd.id == cSdCmdGoIdleState);
 
 
Line 230... Line 282...
                assert(recvcmd.arg[12:8] == 'b0001); // Standard voltage
                assert(recvcmd.arg[12:8] == 'b0001); // Standard voltage
 
 
                // respond with R7: we are SD 2.00 compatible and compatible to the
                // respond with R7: we are SD 2.00 compatible and compatible to the
                // voltage
                // voltage
                voltageresponse = new(recvcmd.arg);
                voltageresponse = new(recvcmd.arg);
                response = voltageresponse;
                voltageresponse.send(ICmd);
 
 
 
                // expect CMD55 with default RCA
 
                recv();
 
                assert(recvcmd.id == cSdCmdNextIsACMD);
 
                assert(recvcmd.arg == 0);
 
                state.recvCMD55();
 
 
 
                // respond with R1
 
                response = new(cSdCmdNextIsACMD, state);
                response.send(ICmd);
                response.send(ICmd);
 
 
 
                // expect ACMD41 with HCS = 1
 
                recv();
 
                assert(recvcmd.id == cSdCmdACMD41);
 
                assert(recvcmd.arg == cSdArgACMD41HCS);
 
 
                -> InitDone;
                -> InitDone;
 
 
        endtask
        endtask
 
 
        function automatic SDCommandToken getCmd();
        function automatic SDCommandToken getCmd();

powered by: WebSVN 2.1.0

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