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

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpSd/] [unitSdWbSlave/] [src/] [SdWbSlave-Rtl-a.vhdl] - 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 119 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 <organization> 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 <COPYRIGHT HOLDER> 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        : SdWbSlave-Rtl-a.vhdl
30
-- Owner       : Rainer Kastl
31
-- Description : Wishbone interface of SDHC-SC-Core
32
-- Links       : 
33
-- 
34 119 rkastl
 
35
architecture Rtl of SdWbSlave is
36
 
37 120 rkastl
        type aWbState is (idle, ClassicWrite, ClassicRead);
38 119 rkastl
        type aSdIntState is (idle, newOperation);
39 126 rkastl
        type aReadBufferState is (invalid, readreq, latchdata, valid);
40 119 rkastl
 
41
        type aRegs is record
42
 
43 126 rkastl
                WbState             : aWbState; -- state of the wb interface
44
                SdIntState          : aSdIntState; -- state of the sd controller interface
45
                OperationBlock      : aOperationBlock; -- Operation for the SdController
46
                ReqOperation        : std_ulogic; -- Register for catching edges on the SdController ReqOperationEdge line
47
                ReadBuffer          : aData;
48
                ReadBufferState     : aReadBufferState;
49
                -- Register outputs
50
                oWbDat              : aSdWbSlaveDataOutput;
51
                oWbCtrl             : aWbSlaveCtrlOutput;
52
                oController         : aSdWbSlaveToSdController;
53
                oWriteFifo          : aoWriteFifo;
54
                oReadFifo                       : aoReadFifo;
55 119 rkastl
 
56
        end record aRegs;
57
 
58
        constant cDefaultRegs : aRegs := (
59 126 rkastl
        WbState                            => idle,
60
        SdIntState                         => idle,
61
        OperationBlock                     => cDefaultOperationBlock,
62
        ReqOperation                       => cInactivated,
63 167 rkastl
        oWbDat                             => (Dat                             => (others => 'X')),
64 126 rkastl
        oWbCtrl                            => cDefaultWbSlaveCtrlOutput,
65
        oController                        => cDefaultSdWbSlaveToSdController,
66
        oWriteFifo                         => cDefaultoWriteFifo,
67
        oReadFifo                                              => cDefaultoReadFifo,
68
        ReadBuffer                         => (others                          => '0'),
69
        ReadBufferState                    => invalid);
70 119 rkastl
 
71
        signal R, NxR : aRegs;
72
 
73
begin
74 120 rkastl
        oWbDat      <= R.oWbDat;
75
        oWbCtrl     <= R.oWbCtrl;
76
        oController <= R.oController;
77 123 rkastl
        oWriteFifo  <= R.oWriteFifo;
78 126 rkastl
        oReadFifo   <= R.oReadFifo;
79 120 rkastl
 
80 119 rkastl
        WbStateReg  : process (iClk, iRstSync)
81
        begin
82
                if (iClk'event and iClk = cActivated) then
83
                        if (iRstSync = cActivated) then -- sync. reset
84
                                R <= cDefaultRegs;
85
                        else
86
                                R <= NxR;
87
                        end if;
88
                end if;
89
        end process WbStateReg ;
90
 
91 126 rkastl
        WbStateAndOutputs : process (iWbCtrl, iWbDat, iController, iWriteFifo, iReadFifo, R)
92 119 rkastl
        begin
93
                -- Default Assignments
94
 
95
                NxR             <= R;
96
                NxR.oWbDat.Dat  <= (others => 'X');
97
                NxR.oWbCtrl     <= cDefaultWbSlaveCtrlOutput;
98 123 rkastl
                NxR.oWriteFifo  <= cDefaultoWriteFifo;
99 119 rkastl
 
100 126 rkastl
                case R.ReadBufferState is
101
                        when invalid =>
102
                                -- is new data available?
103
                                if (iReadFifo.rdempty = cInactivated) then
104
                                        NxR.oReadFifo.rdreq <= cActivated;
105
                                        NxR.ReadBufferState <= readreq;
106
                                end if;
107
 
108
                        when readreq =>
109 171 rkastl
                        -- readreq was sent, data is available next cycle
110 126 rkastl
                                NxR.oReadFifo.rdreq <= cInactivated;
111
                                NxR.ReadBufferState <= latchdata;
112
 
113
                        when latchdata =>
114
                                NxR.ReadBuffer <= iReadFifo.q;
115
                                NxR.ReadBufferState <= valid;
116
 
117
                        when valid =>
118
                        -- do nothing, wishbone statemachine sets the state to invalid when it used it
119
                                null;
120
 
121
                        when others =>
122
                                report "Error: Invalid ReadBufferState" severity error;
123
                end case;
124
 
125
 
126 119 rkastl
                -- Determine next state
127
                case R.WbState is
128
                        when idle =>
129
                                if iWbCtrl.Cyc = cActivated and iWbCtrl.Stb = cActivated then
130 120 rkastl
 
131 119 rkastl
                                        case iWbCtrl.Cti is
132
                                                when cCtiClassicCycle =>
133
                                                        case iWbCtrl.We is
134
                                                                when cInactivated =>
135 120 rkastl
 
136
                                                                        -- perform a ClassicRead
137
                                                                        NxR.oWbCtrl.Ack <= cActivated;
138
                                                                        NxR.WbState     <= ClassicRead;
139
 
140
                                                                        if (iWbDat.Sel = "1") then
141
                                                                                case iWbDat.Adr is
142
                                                                                        when cOperationAddr =>
143
                                                                                                NxR.oWbDat.Dat <= R.OperationBlock.Operation;
144
 
145
                                                                                        when cStartAddrAddr =>
146
                                                                                                NxR.oWbDat.Dat <= R.OperationBlock.StartAddr;
147
 
148
                                                                                        when cEndAddrAddr =>
149
                                                                                                NxR.oWbDat.Dat <= R.OperationBlock.EndAddr;
150
 
151
                                                                                        when cReadDataAddr =>
152 126 rkastl
                                                                                                -- check if data is available
153
                                                                                                case R.ReadBufferState is
154
                                                                                                        when valid =>
155
                                                                                                                -- use buffered data
156
                                                                                                                NxR.oWbDat.Dat <= R.ReadBuffer;
157
                                                                                                                NxR.ReadBufferState <= invalid;
158 120 rkastl
 
159 126 rkastl
                                                                                                        when latchdata =>
160
                                                                                                                -- use input directly
161
                                                                                                                NxR.oWbDat.Dat <= iReadFifo.q;
162
                                                                                                                NxR.ReadBufferState <= invalid;
163
 
164
                                                                                                        when readreq =>
165
                                                                                                        -- no data available, insert a waitstate
166
                                                                                                                NxR.oWbCtrl.Ack <= cInactivated;
167
                                                                                                                NxR.WbState     <= idle;
168
 
169
                                                                                                        when invalid =>
170
                                                                                                        -- no data available, insert a waitstate
171
                                                                                                                NxR.oWbCtrl.Ack <= cInactivated;
172
                                                                                                                NxR.WbState     <= idle;
173
 
174
                                                                                                        when others =>
175
                                                                                                                report "Invalid ReadBufferState" severity error;
176
                                                                                                end case;
177
 
178 120 rkastl
                                                                                        when others =>
179
                                                                                                report "Read to an invalid address" severity warning;
180
                                                                                                NxR.oWbCtrl.Err <= cActivated;
181
                                                                                                NxR.oWbCtrl.Ack <= cInactivated;
182
                                                                                end case;
183
                                                                        end if;
184
 
185 119 rkastl
                                                                when cActivated =>
186 120 rkastl
 
187
                                                                        --perform a ClassicWrite
188
                                                                        NxR.oWbCtrl.Ack <= cActivated;
189
                                                                        NxR.WbState     <= ClassicWrite;
190
 
191 123 rkastl
                                                                        if (iWbDat.Sel = "1") then
192 160 rkastl
                                                                                if (iWbDat.Adr = cOperationAddr or iWbDat.Adr = cStartAddrAddr or iWbDat.Adr = cEndAddrAddr) and
193
                                                                                R.SdIntState = newOperation then
194 120 rkastl
                                                                                -- insert waitstates until we can notify the SdController again
195
 
196 123 rkastl
                                                                                        NxR.oWbCtrl.Ack <= cInactivated;
197
                                                                                        NxR.WbState     <= idle;
198
                                                                                end if;
199 120 rkastl
 
200 123 rkastl
                                                                                if (iWbDat.Adr = cWriteDataAddr and iWriteFifo.wrfull = cActivated) then
201
                                                                                        NxR.oWbCtrl.Ack <= cInactivated;
202
                                                                                        NxR.oWbCtrl.Err <= cActivated;
203
                                                                                        NxR.WbState     <= idle;
204
                                                                                end if;
205
 
206 120 rkastl
                                                                        end if;
207
 
208 119 rkastl
                                                                when others =>
209
                                                                        report "iWbCtrl.We is invalid" severity warning;
210
                                                        end case;
211 120 rkastl
 
212 119 rkastl
                                                when others => null;
213
                                        end case;
214 120 rkastl
 
215 119 rkastl
                                end if;
216
 
217 120 rkastl
                        when ClassicRead =>
218
                                NxR.WbState <= idle;
219 119 rkastl
 
220 120 rkastl
                        when ClassicWrite =>
221 119 rkastl
                                NxR.WbState <= idle;
222
 
223
                                if (iWbDat.Sel = "1") then
224
                                        case iWbDat.Adr is
225
                                                when cOperationAddr =>
226
 
227 120 rkastl
                                                        NxR.OperationBlock.Operation <= iWbDat.Dat;
228
                                                        NxR.SdIntState               <= newOperation;
229 119 rkastl
 
230
                                                when cStartAddrAddr =>
231 120 rkastl
 
232 119 rkastl
                                                        NxR.OperationBlock.StartAddr <= iWbDat.Dat;
233
 
234
                                                when cEndAddrAddr =>
235
 
236
                                                        NxR.OperationBlock.EndAddr <= iWbDat.Dat;
237
 
238
                                                when cWriteDataAddr =>
239
 
240 123 rkastl
                                                        NxR.oWriteFifo.data  <= iWbDat.Dat;
241
                                                        NxR.oWriteFifo.wrreq <= cActivated;
242
 
243 119 rkastl
                                                when others =>
244 120 rkastl
                                                        report "Write to an invalid address" severity warning;
245 167 rkastl
                                                        NxR.oWbCtrl.Err <= cActivated;
246
                                                        NxR.oWbCtrl.Ack <= cInactivated;
247 119 rkastl
                                        end case;
248
                                end if;
249
 
250 120 rkastl
 
251
                        when others =>
252
                                report "Invalid state" severity error;
253 119 rkastl
                end case;
254
 
255
                -- send operations to SdController
256
                case R.SdIntState is
257
                        when idle =>
258
                                -- save edges on the ReqOperationEdge line which would be missed otherwise
259
 
260 122 rkastl
                                if (iController.ReqOperation = cActivated) then
261 119 rkastl
 
262 120 rkastl
                                        NxR.ReqOperation <= cActivated;
263
 
264 119 rkastl
                                end if;
265
 
266
                        when newOperation =>
267
                                -- send a new operation, when the controller requested it
268 122 rkastl
                                if (R.ReqOperation = cActivated or iController.ReqOperation = cActivated) then
269 119 rkastl
 
270 122 rkastl
                                        NxR.oController.OperationBlock <= R.OperationBlock;
271
                                        NxR.oController.AckOperation   <= not R.oController.AckOperation;
272 119 rkastl
 
273
                                        -- go to idle state, the next request will come only after the SdController received this block
274 120 rkastl
 
275 119 rkastl
                                        NxR.ReqOperation <= cInactivated;
276
                                        NxR.SdIntState   <= idle;
277
 
278
                                end if;
279 120 rkastl
 
280 119 rkastl
                        when others =>
281
                                report "Invalid state" severity error;
282
                end case;
283
 
284
        end process WbStateAndOutputs;
285
end architecture Rtl;
286
 

powered by: WebSVN 2.1.0

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