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

Subversion Repositories layer2

[/] [layer2/] [trunk/] [vhdl/] [flash/] [rtl/] [flash.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
--------------------------------------------------------------------------------
2
-- Numonyx™ 128 Mbit EMBEDDED FLASH MEMORY J3 Version D                       --
3
--------------------------------------------------------------------------------
4
-- Copyright (C)2011  Mathias Hörtnagl <mathias.hoertnagl@gmail.comt>         --
5
--                                                                            --
6
-- This program is free software: you can redistribute it and/or modify       --
7
-- it under the terms of the GNU General Public License as published by       --
8
-- the Free Software Foundation, either version 3 of the License, or          --
9
-- (at your option) any later version.                                        --
10
--                                                                            --
11
-- This program is distributed in the hope that it will be useful,            --
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              --
14
-- GNU General Public License for more details.                               --
15
--                                                                            --
16
-- You should have received a copy of the GNU General Public License          --
17
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.      --
18
--------------------------------------------------------------------------------
19
library ieee;
20
use ieee.std_logic_1164.all;
21
use ieee.numeric_std.all;
22
 
23
library work;
24
use work.iwb.all;
25
 
26
entity flash is
27
   port (
28
      si           : in    slave_in_t;
29
      so           : out   slave_out_t;
30
   -- Non Wishbone Signals
31
      SF_OE        : out   std_logic;
32
      SF_CE        : out   std_logic;
33
      SF_WE        : out   std_logic;
34
      SF_BYTE      : out   std_logic;
35
      --SF_STS       : in    std_logic;
36
      SF_A         : out   std_logic_vector(23 downto 0);
37
      SF_D         : inout std_logic_vector(7 downto 0);
38
      PF_OE        : out   std_logic;
39
      LCD_RW       : out   std_logic;
40
      LCD_E        : out   std_logic;
41
      SPI_ROM_CS   : out   std_logic;
42
      SPI_ADC_CONV : out   std_logic;
43
      SPI_DAC_CS   : out   std_logic
44
   );
45
end flash;
46
 
47
architecture rtl of flash is
48
 
49
   type state_t is (Init, Idle, SetupRead, DataRead, WaitRead, DataWrite,
50
                    Finish);
51
 
52
   type reg_t is record
53
      s : state_t;                           -- State.
54
      n : natural range 0 to 49;             -- Period counter.
55
      a : natural range 0 to 3;              -- Address incrementer for read.
56
      d : std_logic_vector(31 downto 0);     -- Latched data for read.
57
      --w : std_logic_vector(7 downto 0);      -- Latched data for write.
58
   end record;
59
 
60
   signal r, rin : reg_t;
61
begin
62
 
63
   -- Disable shared components.
64
   PF_OE        <= '0';
65
   LCD_RW       <= '0';
66
   LCD_E        <= '0';
67
   SPI_ROM_CS   <= '1';
68
   SPI_ADC_CONV <= '0';
69
   SPI_DAC_CS   <= '1';
70
 
71
   -----------------------------------------------------------------------------
72
   -- Read/Write Control                                                      --
73
   -----------------------------------------------------------------------------
74
   SF_A <= si.adr(23 downto 2) & std_logic_vector( to_unsigned(r.a, 2) );
75
 
76
   nsl : process(si, r, SF_D)
77
   begin
78
 
79
      rin <= r;
80
 
81
      SF_OE   <= '1';
82
      SF_CE   <= '1';
83
      SF_WE   <= '1';
84
      SF_BYTE <= '0';
85
      SF_D    <= (others => 'Z');
86
 
87
      so.ack <= '0';
88
 
89
      case r.s is
90
 
91
         -- Wait 1µs for the device to be ready at startup.
92
         -- [Datasheet timing: R12, R13]
93
         when Init =>
94
            if r.n = 49 then -- 1µs
95
               rin.n <= 0;
96
               rin.s <= Idle;
97
            else
98
               rin.n <= r.n + 1;
99
            end if;
100
 
101
         -- Wait for incomming read or write commands.
102
         when Idle =>
103
            if wb_read(si) then
104
               rin.a <= 0;
105
               rin.s <= SetupRead;
106
            elsif wb_write(si) then
107
               rin.a <= to_integer( unsigned(si.adr(1 downto 0)) );
108
               -- case si.sel is
109
                  -- when "0001" => rin.w <= si.dat(7 downto 0);
110
                  -- when "0010" => rin.w <= si.dat(15 downto 8);
111
                  -- when "0100" => rin.w <= si.dat(23 downto 16);
112
                  -- when "1000" => rin.w <= si.dat(31 downto 24);
113
                  -- when others => rin.w <= si.dat(7 downto 0);
114
               -- end case;
115
               rin.s <= DataWrite;
116
            end if;
117
 
118
         -- Set CE and OE low while waiting 80ns (75ns) for the first data byte
119
         -- ready to latch. [Datasheet timing: R2, R3]
120
         when SetupRead =>
121
            SF_CE <= '0';
122
            SF_OE <= '0';
123
            if r.n = 3 then -- 80ns
124
               rin.n <= 0;
125
               rin.s <= DataRead;
126
            else
127
               rin.n <= r.n + 1;
128
            end if;
129
 
130
         -- Latch data word four times and increment SF_A[1:0]. After every
131
         -- read, jump to WaitRead and wait for the next data byte. On the
132
         -- last read go to FinishRead.
133
         when DataRead =>
134
            SF_CE <= '0';
135
            SF_OE <= '0';
136
            rin.d <= r.d(23 downto 0) & SF_D;
137
            if r.a = 3 then
138
               rin.a <= 0;
139
               rin.s <= Finish;
140
            else
141
               rin.a <= r.a + 1;
142
               rin.s <= WaitRead;
143
            end if;
144
 
145
         -- Wait for 40ns (25ns) until the next data byte is ready.
146
         -- [Datasheet timing: R15]
147
         when WaitRead =>
148
            SF_CE <= '0';
149
            SF_OE <= '0';
150
            if r.n = 1 then -- 40ns
151
               rin.n <= 0;
152
               rin.s <= DataRead;
153
            else
154
               rin.n <= r.n + 1;
155
            end if;
156
 
157
         -- Pull down CE and WE. Wait for 60ns (60ns).
158
         when DataWrite =>
159
            SF_CE <= '0';
160
            SF_WE <= '0';
161
            --SF_D  <= r.w;
162
            case si.sel is
163
               when "0001" => SF_D <= si.dat(7 downto 0);
164
               when "0010" => SF_D <= si.dat(15 downto 8);
165
               when "0100" => SF_D <= si.dat(23 downto 16);
166
               when "1000" => SF_D <= si.dat(31 downto 24);
167
               when others => SF_D <= si.dat(7 downto 0);
168
            end case;
169
            if r.n = 2 then -- 60ns
170
               rin.n <= 0;
171
               rin.s <= Finish;
172
            else
173
               rin.n <= r.n + 1;
174
            end if;
175
 
176
         -- Set CE and OE high and wait 20ns (25ns). After that the next command
177
         -- can be processed. The remaining 5ns are compensated by the Idle
178
         -- state which takes another 20ns. Wait for si.stb to be low again as
179
         -- well. [Datasheet timing: R8]
180
         -- Write recovery before read is 40ns (35ns). Wait at least 20ns and
181
         -- then go to Idle state which waits for another 20ns.
182
         -- [Datasheet timing: W12]
183
         when Finish =>
184
            so.ack <= '1';
185
            if si.stb = '0' then
186
               rin.s <= Idle;
187
            end if;
188
 
189
      end case;
190
   end process;
191
 
192
   so.dat <= r.d;
193
 
194
   -----------------------------------------------------------------------------
195
   -- Registers                                                               --
196
   -----------------------------------------------------------------------------
197
   reg : process(si.clk)
198
   begin
199
      if rising_edge(si.clk) then
200
         r <= rin;
201
 
202
         if si.rst = '1' then
203
            r.s <= Init;
204
         end if;
205
      end if;
206
   end process;
207
end rtl;
208
 

powered by: WebSVN 2.1.0

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