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

Subversion Repositories sdhc-sc-core

[/] [sdhc-sc-core/] [trunk/] [grpSd/] [unitTestWbMaster/] [src/] [TestWbMaster-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 150 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        : TestWbMaster-Rtl-a.vhdl
30
-- Owner       : Rainer Kastl
31
-- Description : Wishbone master for testing SDHC-SC-Core on the SbX
32
-- Links       : 
33
-- 
34 150 rkastl
 
35
architecture Rtl of TestWbMaster is
36
 
37
        type aState is (startAddr, writeBuffer, write, readbuffer, read, done);
38
        subtype aCounter is unsigned(7 downto 0); -- 128 * 32 bit = 512 byte
39
 
40
        type aWbState is (idle, write, read);
41
 
42
        type aReg is record
43
 
44
                State : aState;
45
                Counter : aCounter;
46
                WbState : aWbState;
47
                Err : std_ulogic;
48 167 rkastl
                ReadData : unsigned(31 downto 0);
49
                StartAddr: unsigned(31 downto 0);
50 150 rkastl
 
51
        end record aReg;
52
 
53
        signal R, NxR : aReg;
54
 
55
begin
56
 
57 167 rkastl
        LEDBANK_O(7) <= R.Err;
58
        LEDBANK_O(2 downto 0) <= std_ulogic_vector(R.StartAddr(2 downto 0));
59
 
60 150 rkastl
        Regs : process (CLK_I)
61
        begin
62
                if (rising_edge(CLK_I)) then
63
 
64
                        if (RST_I = '1') then
65
                                -- sync. reset
66
                                R.State   <= startAddr;
67
                                R.Counter <= (others => '0');
68
                                R.WbState <= write;
69
                                R.Err     <= '0';
70 167 rkastl
                                R.ReadData <= (others => '0');
71
                                R.StartAddr <= X"00000000";
72 150 rkastl
 
73
                        else
74
                                R <= NxR;
75
 
76
                        end if;
77
 
78
                end if;
79
        end process Regs;
80
 
81
        StateMachine : process (R, ERR_I, RTY_I, ACK_I, DAT_I)
82
        begin
83
 
84
                -- default assignment
85
                NxR <= R;
86
                CTI_O <= "000";
87
                CYC_O <= '0';
88
                WE_O  <= '0';
89
                SEL_O <= "0";
90
                STB_O <= '0';
91
                ADR_O <= "000";
92
                DAT_O <= (others => '0');
93
                BTE_O <= "00";
94 167 rkastl
                LEDBANK_O(6 downto 3) <= (others => '0');
95 150 rkastl
 
96
                -- we donĀ“t care for errors or retrys
97
                if (ERR_I = '1' or RTY_I = '1') then
98
                        NxR.Err <= '1';
99
                end if;
100
 
101
                case R.WbState is
102
                        when idle =>
103
                                null;
104
 
105
                        when write =>
106
                                -- write data 
107
                                CTI_O <= "000";
108
                                CYC_O <= '1';
109
                                WE_O  <= '1';
110
                                SEL_O <= "1";
111
                                STB_O <= '1';
112
 
113
                                if (ACK_I = '1') then
114
                                        if (R.Counter = 128) then
115
                                                NxR.Counter <= (others => '0');
116
                                        else
117
                                                NxR.Counter <= R.Counter + 1;
118
                                        end if;
119
                                end if;
120
 
121
                        when read =>
122
                                -- read data
123
                                CTI_O <= "000";
124
                                CYC_O <= '1';
125
                                WE_O  <= '0';
126
                                SEL_O <= "1";
127
                                STB_O <= '1';
128
 
129
                        when others =>
130
                                report "Invalid wbState" severity error;
131
                end case;
132
 
133
                case R.State is
134
                        when startAddr =>
135
                                ADR_O <= "001";
136 167 rkastl
                                DAT_O <= std_ulogic_vector(R.startAddr);
137 150 rkastl
 
138
                                if (ACK_I = '1') then
139 167 rkastl
                                        NxR.State <= read;
140 150 rkastl
                                        NxR.Counter <= (others => '0');
141
                                        NxR.WbState <= write;
142
                                end if;
143
 
144
                        when writeBuffer =>
145
                                ADR_O <= "100"; -- write data
146 167 rkastl
                                DAT_O <= std_ulogic_vector(R.ReadData + 1);
147 150 rkastl
 
148 167 rkastl
                                if (ACK_I = '1') then
149
                                        if (R.Counter = 128) then
150
                                                NxR.State   <= write;
151
                                                NxR.Counter <= to_unsigned(128, aCounter'length);
152
                                                NxR.WbState <= write;
153
                                        else
154
                                                NxR.State <= readBuffer;
155
                                                NxR.WbState <= read;
156
                                        end if;
157 150 rkastl
                                end if;
158
 
159
                        when write =>
160 167 rkastl
                                LEDBANK_O(3) <= '1';
161 150 rkastl
                                ADR_O <= "000";
162
                                DAT_O <= X"00000010"; -- start write operation
163
 
164
                                if (ACK_I = '1') then
165 167 rkastl
                                        NxR.State   <= startAddr;
166
                                        NxR.WbState <= write;
167
                                        NxR.startAddr <= R.startAddr + 1;
168
                                end if;
169
 
170 183 rkastl
                                if (R.StartAddr = 22) then
171 167 rkastl
                                        NxR.State <= done;
172 150 rkastl
                                        NxR.WbState <= idle;
173
                                end if;
174
 
175
                        when read =>
176 167 rkastl
                                LEDBANK_O(4) <= '1';
177 150 rkastl
                                ADR_O <= "000";
178
                                DAT_O <= X"00000001"; -- start read operation
179
 
180
                                if (ACK_I = '1') then
181
                                        NxR.State <= readBuffer;
182
                                        NxR.WbState <= read;
183
                                end if;
184
 
185
                        when readBuffer =>
186 167 rkastl
                                LEDBANK_O(5) <= '1';
187 150 rkastl
                                ADR_O <= "011"; -- read data
188
 
189 167 rkastl
                                if (ACK_I = '1') then
190
                                        NxR.ReadData <= unsigned(DAT_I);
191
                                        NxR.State <= writeBuffer;
192
                                        NxR.WbState <= write;
193 150 rkastl
                                end if;
194
 
195
                        when done =>
196 167 rkastl
                                LEDBANK_O(6) <= '1';
197
                                report "End of Simulation" severity failure;
198 150 rkastl
 
199
                        when others =>
200
                                report "Invalid state" severity error;
201
                end case;
202
 
203
        end process StateMachine;
204
 
205
 
206
end architecture Rtl;

powered by: WebSVN 2.1.0

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