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/] [SdCommand.sv] - Blame information for rev 185

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 164 rkastl
// SDHC-SC-Core
2
// Secure Digital High Capacity Self Configuring Core
3 58 rkastl
//
4 170 rkastl
// (C) Copyright 2010, Rainer Kastl
5
// All rights reserved.
6 164 rkastl
//
7 170 rkastl
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are met:
9
//     * Redistributions of source code must retain the above copyright
10
//       notice, this list of conditions and the following disclaimer.
11
//     * Redistributions in binary form must reproduce the above copyright
12
//       notice, this list of conditions and the following disclaimer in the
13
//       documentation and/or other materials provided with the distribution.
14
//     * Neither the name of the  nor the
15
//       names of its contributors may be used to endorse or promote products
16
//       derived from this software without specific prior written permission.
17 164 rkastl
//
18 170 rkastl
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  "AS IS" AND
19
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
// DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANY
22
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 164 rkastl
//
29
// File        : SdCommand.sv
30
// Owner       : Rainer Kastl
31
// Description : Classes and types describing the commands of the SD spec
32
// Links       :
33
//
34 135 rkastl
 
35
`ifndef SDCOMMAND
36
`define SDCOMMAND
37
 
38
`include "SDCommandArg.sv";
39
`include "SdCardState.sv";
40
`include "SDCID.sv";
41
`include "SDOCR.sv";
42 145 rkastl
`include "SdBFM.sv";
43 135 rkastl
 
44 63 rkastl
typedef logic[15:0] RCA_t;
45 58 rkastl
 
46
typedef enum {
47
         cSdCmdGoIdleState = 0,
48
         cSdCmdAllSendCID = 2,
49
         cSdCmdSendRelAdr = 3,
50
         cSdCmdSetDSR = 4, // [31:16] DSR
51 103 rkastl
         cSdCmdSwitchFuntion = 6,
52 58 rkastl
         cSdCmdSelCard = 7, // [31:16] RCA
53
         cSdCmdSendIfCond = 8, // [31:12] reserved, [11:8] supply voltage, [7:0] check pattern
54
         cSdCmdSendCSD = 9, // [31:16] RCA
55
         cSdCmdSendCID = 10, // [31:16] RCA
56
         cSdCmdStopTrans = 12,
57
         cSdCmdSendStatus = 13, // [31:16] RCA
58 113 rkastl
         cSdCmdReadSingleBlock = 17,
59 123 rkastl
         cSdCmdWriteSingleBlock = 24,
60 58 rkastl
         cSdCmdNextIsACMD = 55 // [31:16] RCA
61
} SDCommandId;
62
 
63
typedef enum {
64 99 rkastl
        cSdCmdACMD41 = 41,
65 102 rkastl
        cSdCmdSendSCR = 51,
66
        cSdCmdSetBusWidth = 6
67 58 rkastl
} SDAppCommandId;
68
 
69
const SDCommandArg cSdArgACMD41HCS = 'b01000000111111111000000000000000;
70
 
71 145 rkastl
typedef logic[5:0] SdCommandId;
72
const logic cSdTransbitToHost = 0;
73 58 rkastl
 
74 145 rkastl
class DefaultSdResponse extends SdBusTransToken;
75 58 rkastl
 
76 145 rkastl
        function new(SdCommandId id, SDCommandArg arg);
77
                this.transbit = cSdTransbitToHost;
78
                this.id = id;
79
                this.arg = arg;
80
                this.crc = calcCrcOfToken();
81 58 rkastl
        endfunction
82
 
83
endclass
84
 
85 145 rkastl
class SDCommandR7 extends DefaultSdResponse;
86 58 rkastl
 
87
        function new(SDCommandArg arg);
88 145 rkastl
                super.new(cSdCmdSendIfCond, arg);
89 58 rkastl
        endfunction
90
 
91
endclass
92
 
93 145 rkastl
class SDCommandR1 extends DefaultSdResponse;
94 58 rkastl
 
95 151 rkastl
        function new(int id, SdCardModelState state);
96 145 rkastl
                super.new(id, state.get());
97 58 rkastl
        endfunction
98 99 rkastl
 
99 58 rkastl
endclass
100
 
101 145 rkastl
class SDCommandR3 extends DefaultSdResponse;
102 59 rkastl
 
103
        function new(SDOCR ocr);
104 145 rkastl
                super.new('b111111, ocr.get());
105
                this.crc = 'b111111;
106 59 rkastl
        endfunction
107 89 rkastl
 
108 59 rkastl
endclass
109
 
110 145 rkastl
class SDCommandR2 extends SdBusTrans;
111 62 rkastl
        local SDCID cid;
112
 
113
        function new();
114
                this.cid = new();
115 153 rkastl
                assert(this.cid.randomize());
116 62 rkastl
        endfunction
117
 
118 145 rkastl
        virtual function SdBusTransData packToData();
119
                SdBusTransData data;
120
                SdCommandId id = 'b111111;
121
                cidreg_t creg = cid.get();
122 62 rkastl
 
123 145 rkastl
                data = { >> {cSdTransbitToHost, id, creg}};
124
                return data;
125
        endfunction
126 62 rkastl
 
127 145 rkastl
        virtual function void unpackFromData(ref SdBusTransData data);
128
                Logger log = new();
129
                log.error("SDCommandR2::unpackFromData not implemented");
130
        endfunction
131 62 rkastl
 
132
endclass
133
 
134 151 rkastl
function SDCommandArg getArgFromRcaAndState(RCA_t rca, SdCardModelState state);
135 145 rkastl
        SDCommandArg arg;
136
        arg[31:16] = rca;
137
        arg[15] = state.ComCrcError;
138
        arg[14] = state.IllegalCommand;
139
        arg[13] = state.Error;
140
        arg[12:9] = state.state;
141
        arg[8] = state.ReadyForData;
142
        arg[7:6] = 0;
143
        arg[5] = state.AppCmd;
144
        arg[4] = 0;
145
        arg[3] = state.AkeSeqError;
146
        arg[2:0] = 0;
147
        return arg;
148
endfunction
149 63 rkastl
 
150 145 rkastl
class SDCommandR6 extends DefaultSdResponse;
151
 
152 151 rkastl
        function new(RCA_t rca, SdCardModelState state);
153 145 rkastl
                super.new(cSdCmdSendRelAdr, getArgFromRcaAndState(rca, state));
154 63 rkastl
        endfunction
155
 
156
endclass
157
 
158 135 rkastl
`endif

powered by: WebSVN 2.1.0

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