OpenCores
URL https://opencores.org/ocsvn/spi_boot/spi_boot/trunk

Subversion Repositories spi_boot

[/] [spi_boot/] [trunk/] [rtl/] [vhdl/] [sample/] [ram_loader.vhd] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 arniml
-------------------------------------------------------------------------------
2
--
3
-- SD/MMC Bootloader
4
-- Sample client for loading an image to asynchronous SRAM
5
--
6
-- $Id: ram_loader.vhd,v 1.1 2005-02-18 20:49:00 arniml Exp $
7
--
8
-- Copyright (c) 2005, Arnim Laeuger (arniml@opencores.org)
9
--
10
-- All rights reserved, see COPYING.
11
--
12
-- Redistribution and use in source and synthezised forms, with or without
13
-- modification, are permitted provided that the following conditions are met:
14
--
15
-- Redistributions of source code must retain the above copyright notice,
16
-- this list of conditions and the following disclaimer.
17
--
18
-- Redistributions in synthesized form must reproduce the above copyright
19
-- notice, this list of conditions and the following disclaimer in the
20
-- documentation and/or other materials provided with the distribution.
21
--
22
-- Neither the name of the author nor the names of other contributors may
23
-- be used to endorse or promote products derived from this software without
24
-- specific prior written permission.
25
--
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
-- POSSIBILITY OF SUCH DAMAGE.
37
--
38
-- Please report bugs to the author, but before you do so, please
39
-- make sure that this is not a derivative work and that
40
-- you have the latest version of this file.
41
--
42
-- The latest version of this file can be found at:
43
--      http://www.opencores.org/projects.cgi/web/spi_boot/overview
44
--
45
-------------------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
 
50
 
51
entity ram_loader is
52
 
53
  port (
54
    -- Global Interface -------------------------------------------------------
55
    clk_i      : in    std_logic;
56
    reset_i    : in    std_logic;
57
    lamp_o     : out   std_logic;
58
    -- Config Interface -------------------------------------------------------
59
    cfg_clk_i  : in    std_logic;
60
    cfg_data_i : in    std_logic;
61
    start_o    : out   std_logic;
62
    mode_o     : out   std_logic;
63
    done_o     : out   std_logic;
64
    -- Asynchronous RAM Interface ---------------------------------------------
65
    ram_addr_o : out   std_logic_vector(15 downto 0);
66
    ram_data_b : out   std_logic_vector( 7 downto 0);
67
    ram_ce_no  : out   std_logic_vector( 3 downto 0);
68
    ram_oe_no  : out   std_logic;
69
    ram_we_no  : out   std_logic
70
  );
71
 
72
end ram_loader;
73
 
74
 
75
library ieee;
76
use ieee.numeric_std.all;
77
 
78
architecture rtl of ram_loader is
79
 
80
  signal addr_q     : unsigned(17 downto 0);
81
  signal inc_addr_s : boolean;
82
 
83
  signal shift_dat_q : std_logic_vector(7 downto 0);
84
  signal ser_dat_q   : std_logic_vector(7 downto 0);
85
  signal bit_q       : unsigned(2 downto 0);
86
  signal bit_ovfl_q  : boolean;
87
 
88
  type fsm_t is (IDLE,
89
                 WE_ON,
90
                 WE_OFF,
91
                 INC_ADDR1, INC_ADDR2,
92
                 FINISHED);
93
  signal fsm_s,
94
         fsm_q  : fsm_t;
95
 
96
  signal ram_we_n_q,
97
         ram_we_n_s  : std_logic;
98
  signal ram_ce_n_q,
99
         ram_ce_n_s  : std_logic_vector(3 downto 0);
100
 
101
  signal start_q         : std_logic;
102
  signal trigger_start_s,
103
         trigger_start_q : boolean;
104
  signal seen_trigger_q  : boolean;
105
  signal start_cnt_q     : unsigned(7 downto 0);
106
  signal done_q          : std_logic;
107
  signal done_s          : boolean;
108
  signal mode_q,
109
         mode_s          : std_logic;
110
  signal enable_q        : boolean;
111
 
112
begin
113
 
114
  seq: process (cfg_clk_i, reset_i)
115
  begin
116
    if reset_i = '0' then
117
      addr_q      <= (others => '0');
118
      shift_dat_q <= (others => '0');
119
      ser_dat_q   <= (others => '0');
120
      bit_q       <= (others => '0');
121
      bit_ovfl_q  <= false;
122
      fsm_q       <= IDLE;
123
      ram_we_n_q  <= '1';
124
      ram_ce_n_q  <= (others => '1');
125
      done_q      <= '0';
126
      trigger_start_q <= false;
127
 
128
    elsif cfg_clk_i'event and cfg_clk_i = '1' then
129
      if inc_addr_s then
130
        addr_q <= addr_q + 1;
131
      end if;
132
 
133
      if enable_q then
134
        bit_q      <= bit_q + 1;
135
        bit_ovfl_q <= bit_q = 7;
136
 
137
        shift_dat_q(0) <= cfg_data_i;
138
        shift_dat_q(7 downto 1) <= shift_dat_q(6 downto 0);
139
      end if;
140
 
141
      -- update register when 8 serial bits have been shifted in
142
      if bit_ovfl_q then
143
        ser_dat_q <= shift_dat_q;
144
      end if;
145
 
146
      fsm_q <= fsm_s;
147
 
148
      ram_we_n_q <= ram_we_n_s;
149
      ram_ce_n_q <= ram_ce_n_s;
150
 
151
      if done_s then
152
        done_q <= '1';
153
      end if;
154
 
155
      trigger_start_q <= trigger_start_s;
156
 
157
    end if;
158
  end process seq;
159
 
160
 
161
  start: process (clk_i, reset_i)
162
    variable trigger_start_v : boolean;
163
  begin
164
    if reset_i = '0' then
165
      start_cnt_q   <= (others => '0');
166
      start_q       <= '0';
167
      mode_q        <= '0';
168
      enable_q      <= false;
169
      seen_trigger_q <= false;
170
 
171
    elsif clk_i'event and clk_i = '1' then
172
      trigger_start_v := not seen_trigger_q and trigger_start_q;
173
 
174
      if trigger_start_q then
175
        seen_trigger_q <= true;
176
      end if;
177
 
178
      if trigger_start_v then
179
        start_cnt_q <= (others => '0');
180
      elsif start_q = '0' then
181
        start_cnt_q <= start_cnt_q + 1;
182
      end if;
183
 
184
      if trigger_start_v then
185
        start_q     <= '0';
186
      elsif start_cnt_q = "11111111" then
187
        start_q     <= '1';
188
        enable_q    <= true;
189
        if start_q = '0' then
190
          mode_q    <= mode_s;
191
        end if;
192
      end if;
193
 
194
    end if;
195
  end process start;
196
 
197
 
198
  fsm: process (fsm_q,
199
                bit_ovfl_q,
200
                start_q,
201
                addr_q)
202
  begin
203
    -- default assignments
204
    inc_addr_s      <= false;
205
    ram_we_n_s      <= '1';
206
    trigger_start_s <= false;
207
    done_s          <= false;
208
    fsm_s           <= IDLE;
209
    lamp_o          <= '1';
210
    mode_s          <= '0';
211
 
212
    case fsm_q is
213
      when IDLE =>
214
        lamp_o <= '0';
215
        if start_q = '1' then
216
          if bit_ovfl_q then
217
            fsm_s <= WE_ON;
218
          end if;
219
        end if;
220
 
221
      when WE_ON =>
222
        ram_we_n_s <= '0';
223
        fsm_s      <= WE_OFF;
224
 
225
      when WE_OFF =>
226
        fsm_s <= INC_ADDR1;
227
 
228
      when INC_ADDR1 =>
229
        fsm_s      <= INC_ADDR2;
230
 
231
      when INC_ADDR2 =>
232
        if addr_q = "001111111111111111" then  -- load only 64k
233
          fsm_s <= FINISHED;
234
          trigger_start_s <= true;
235
          done_s <= true;
236
        else
237
          inc_addr_s <= true;
238
          fsm_s      <= IDLE;
239
        end if;
240
 
241
      when FINISHED =>
242
        fsm_s  <= FINISHED;
243
        lamp_o <= '1';
244
        mode_s <= '1';
245
 
246
      when others =>
247
    end case;
248
 
249
  end process fsm;
250
 
251
  ce_gen: process (addr_q)
252
  begin
253
    ram_ce_n_s <= (others => '1');
254
    ram_ce_n_s(to_integer(addr_q(17 downto 16))) <= '0';
255
  end process ce_gen;
256
 
257
  -----------------------------------------------------------------------------
258
  -- Output Mapping
259
  -----------------------------------------------------------------------------
260
  start_o    <= start_q;
261
  mode_o     <= mode_q;
262
  done_o     <=   done_q
263
                when start_q = '1' else
264
                  '1';
265
  ram_addr_o <= std_logic_vector(addr_q(15 downto 0));
266
  ram_data_b <= ser_dat_q;
267
  ram_oe_no  <= '1';
268
  ram_ce_no  <= ram_ce_n_q;
269
  ram_we_no  <= ram_we_n_q;
270
 
271
end rtl;

powered by: WebSVN 2.1.0

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