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

Subversion Repositories usb_dongle_fpga

[/] [usb_dongle_fpga/] [trunk/] [src/] [flash/] [flsh_if.vhd] - Blame information for rev 53

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 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
    --flash Bus
35
    fl_addr   : out std_logic_vector(23 downto 0);
36
    fl_ce_n      : out std_logic;       --chip select   (timing is very chip dependent)
37
    fl_oe_n      : out std_logic;       --output enable for flash (timing is very chip dependent)
38
    fl_we_n      : out std_logic;       --write enable (timing is very chip dependent)
39
    fl_data      : inout std_logic_vector(15 downto 0);
40
    fl_rp_n      : out std_logic;       --reset signal
41
    fl_byte_n      : out std_logic;       --hold in byte mode
42
    fl_sts       : in std_logic;        --status signal
43
    -- mem Bus
44
    mem_addr  : in std_logic_vector(23 downto 0);
45
    mem_do    : out std_logic_vector(15 downto 0);
46
    mem_di    : in  std_logic_vector(15 downto 0);
47
 
48
    mem_wr    : in  std_logic;  --write not read signal
49
    mem_val   : in  std_logic;
50
    mem_ack   : out std_logic
51
    );
52
end flash_if;
53
 
54
 
55
architecture RTL of flash_if is
56
 type state_type is (RESETs,FLREADs,FLWRITEs,WAITs);
57
  signal CS : state_type;
58
  signal fl_cnt : std_logic_vector(3 downto 0);
59
  signal  fl_oe_nd      : std_logic;       --output enable for flash
60
begin
61
 
62
fl_rp_n <= reset_n;                     --make flash reset
63
fl_addr <= mem_addr(23 downto 0);
64
fl_byte_n <= '0';                       --all byte accesses
65
 
66
 
67
fl_oe_n<=fl_oe_nd;
68
fl_data <= mem_di when fl_oe_nd ='1' else
69
          (others =>'Z');
70
 
71
 
72
 
73
RD: process (clk, reset_n)
74
begin  -- process READ
75
  if reset_n='0' then
76
     fl_oe_nd <='1';
77
         CS <= RESETs;
78
         fl_cnt <= (others=>'0');
79
         mem_do <= (others=>'0');
80
         mem_ack <='0';
81
   elsif clk'event and clk = '1' then    -- rising clock edge
82
                case CS is
83
                        when RESETs =>
84
                                 mem_ack <='0';
85
                                 fl_ce_n <= (not mem_val);                 --chipselect 4 flash
86
                                 fl_we_n <= (not (mem_val and mem_wr));  --write enable 4 flash
87
                                 if mem_val='1' and mem_wr = '0' then --READ
88
                                        fl_oe_nd <='0';
89
                                        fl_cnt <= (others=>'0');
90
                                        CS <= FLREADs;
91
                                 elsif mem_val='1' and mem_wr = '1' then --WRITE
92
                                        fl_oe_nd <='1';
93
                                        fl_cnt <= (others=>'0');
94
                                        CS <= FLWRITEs;
95
                                 end if;   --elsif mem_cmd
96
                        when FLREADs =>
97
                                fl_cnt <= fl_cnt + 1;
98
                                if fl_cnt=x"3" then --3 cycles later
99
                                        mem_ack <='1';
100
                                        mem_do <= fl_data;      --registered is nicer
101
                                elsif fl_cnt=x"4" then --4 cycles later
102
                                        mem_ack <='0';
103
                                        fl_oe_nd <='1';
104
                                        CS <= WAITs;
105
                                end if;
106
                        when FLWRITEs =>
107
                                fl_cnt <= fl_cnt + 1;
108
                                if fl_cnt=x"3" then --3 cycles later
109
                                        mem_ack <='1';
110
                                elsif fl_cnt=x"4" then --4 cycles later
111
                                        mem_ack <='0';
112
                                        CS <= WAITs;
113
                                end if;
114
                        when WAITs =>
115
                                if      mem_val='0' then -- wait untill val is removed
116
                                        CS <= RESETs;
117
                                end if;
118
                end case;
119
 
120
  end if;                               --system
121
end process RD;
122
 
123
 
124
 
125
 
126
end RTL;
127
 

powered by: WebSVN 2.1.0

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