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

Subversion Repositories artec_dongle_ii_fpga

[/] [artec_dongle_ii_fpga/] [trunk/] [src/] [flash/] [flsh_if.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 nuubik
------------------------------------------------------------------
2
-- Universal dongle board source code
3
-- 
4
-- Copyright (C) 2006 Artec Design <jyrit@artecdesign.ee>
5
-- 
6
-- This source code is free hardware; you can redistribute it and/or
7
-- modify it under the terms of the GNU Lesser General Public
8
-- License as published by the Free Software Foundation; either
9
-- version 2.1 of the License, or (at your option) any later version.
10
-- 
11
-- This source code 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 GNU
14
-- Lesser General Public License for more details.
15
-- 
16
-- You should have received a copy of the GNU Lesser General Public
17
-- License along with this library; if not, write to the Free Software
18
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
-- 
20
-- 
21
-- The complete text of the GNU Lesser General Public License can be found in 
22
-- the file 'lesser.txt'.
23
 
24
 
25
library IEEE;
26
use IEEE.std_logic_1164.all;
27
use IEEE.std_logic_unsigned.all;
28
use IEEE.std_logic_arith.all;
29
 
30
entity flash_if is
31
  port (
32
    clk       : in  std_logic;
33
    reset_n   : in  std_logic;
34
    mode      : in    std_logic_vector(2 downto 0);  --sel upper addr bits
35
    --flash Bus
36
    fl_addr   : out std_logic_vector(23 downto 0);
37
    fl_ce_n      : out std_logic;       --chip select   (timing is very chip dependent)
38
    fl_oe_n      : out std_logic;       --output enable for flash (timing is very chip dependent)
39
    fl_we_n      : out std_logic;       --write enable (timing is very chip dependent)
40
    fl_data      : inout std_logic_vector(15 downto 0);
41
    fl_rp_n      : out std_logic;       --reset signal
42
    fl_byte_n      : out std_logic;       --hold in byte mode
43
    fl_sts       : in std_logic;        --status signal
44
    -- mem Bus
45
    mem_addr  : in std_logic_vector(23 downto 0);
46
    mem_do    : out std_logic_vector(15 downto 0);
47
    mem_di    : in  std_logic_vector(15 downto 0);
48
 
49
    mem_wr    : in  std_logic;  --write not read signal
50
    mem_val   : in  std_logic;
51
    mem_ack   : out std_logic
52
    );
53
end flash_if;
54
 
55
 
56
architecture RTL of flash_if is
57
 type state_type is (RESETs,FLREADs,FLWRITEs,WAITs);
58
  signal CS : state_type;
59
  signal fl_cnt : std_logic_vector(3 downto 0);
60
  signal  fl_oe_nd      : std_logic;       --output enable for flash
61
  signal mode_d    :  std_logic_vector(2 downto 0);  --sel upper addr bits
62
begin
63
 
64
fl_rp_n <= reset_n;                     --make flash reset
65
fl_addr <= mem_addr(23 downto 0);
66
fl_byte_n <= '0';                       --all byte accesses
67
 
68
 
69
fl_oe_n<=fl_oe_nd;
70
fl_data <= mem_di when fl_oe_nd ='1' else
71
          (others =>'Z');
72
 
73
 
74
 
75
RD: process (clk, reset_n)
76
begin  -- process READ
77
  if reset_n='0' then
78
         fl_we_n <='1';
79
         fl_ce_n <='1';
80
     fl_oe_nd <='1';
81
         CS <= RESETs;
82
         fl_cnt <= (others=>'0');
83
         mem_do <= (others=>'0');
84
         mem_ack <='0';
85
   elsif clk'event and clk = '1' then    -- rising clock edge
86
                mode_d <= mode;
87
                case CS is
88
                        when RESETs =>
89
                                 mem_ack <='0';
90
                                 fl_ce_n <= (not mem_val);                 --chipselect 4 flash
91
                                 fl_we_n <= (not (mem_val and mem_wr));  --write enable 4 flash
92
                                 if mem_val='1' and mem_wr = '0' then --READ
93
                                        fl_oe_nd <='0';
94
                                        CS <= FLREADs;
95
                                 elsif mem_val='1' and mem_wr = '1' then --WRITE
96
                                        fl_oe_nd <='1';
97
                                        CS <= FLWRITEs;
98
                                 end if;   --elsif mem_cmd
99
                                 --Lets set the cnt for flash and PSRAM separately
100
                                 if (mode_d(2)='0')then
101
                                        fl_cnt <= (others=>'0');
102
                                 else
103
                                        fl_cnt <= x"2";  --PSRAM cycle is 80 ns with 25MHz clock
104
                                 end if;
105
                        when FLREADs =>
106
                                fl_cnt <= fl_cnt + 1;
107
                                if fl_cnt=x"3" then --3 cycles later
108
                                        mem_ack <='1';
109
                                        mem_do <= fl_data;      --registered is nicer
110
                                elsif fl_cnt=x"4" then --4 cycles later
111
                                        mem_ack <='0';
112
                                        fl_oe_nd <='1';
113
                                        CS <= WAITs;
114
                                end if;
115
                        when FLWRITEs =>
116
                                fl_cnt <= fl_cnt + 1;
117
                                if fl_cnt=x"3" then --3 cycles later
118
                                        mem_ack <='1';
119
                                elsif fl_cnt=x"4" then --4 cycles later
120
                                        mem_ack <='0';
121
                                        CS <= WAITs;
122
                                end if;
123
                        when WAITs =>
124
                                if      mem_val='0' then -- wait untill val is removed
125
                                        CS <= RESETs;
126
                                end if;
127
                end case;
128
 
129
  end if;                               --system
130
end process RD;
131
 
132
 
133
 
134
 
135
end RTL;
136
 

powered by: WebSVN 2.1.0

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