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

Subversion Repositories epc_rfid_transponder

[/] [epc_rfid_transponder/] [trunk/] [flashmemUSR.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 erwing
-------------------------------------------------------------------------------
2
--     Politecnico di Torino                                              
3
--     Dipartimento di Automatica e Informatica             
4
-------------------------------------------------------------------------------
5
-------------------------------------------------------------------------------     
6
--
7
--     Title          : Flash Memory USR
8
--
9
--     File name      : flashmemUSR.vhd 
10
--
11
--     Description    : Flash memory model.  
12
--
13
--     Author         : Paolo Bernardi <paolo.bernardi@polito.it>
14
--
15
--     Rev. History   : Erwing Sanchez  -- 17/07/06
16
--                              - Ready/busy input removed because not used
17
--                              - "Bits" generic removed
18
--                              - RP input removed
19
--                              - Command codes changed to work with Data = 16
20
--                      E.R. Sanchez   -- 13/10/06     
21
--                              - Include Parameters & Initialization
22
-------------------------------------------------------------------------------            
23
-------------------------------------------------------------------------------
24
 
25
library IEEE;
26
use IEEE.STD_LOGIC_1164.all;
27
use IEEE.STD_LOGIC_ARITH.all;
28
use IEEE.STD_LOGIC_UNSIGNED.all;
29
use IEEE.std_logic_textio.all;
30
use STD.TEXTIO.all;
31
 
32
 
33
entity Flash_MeM_USR is
34
  generic (
35
    Words : integer := 256;           -- number of addresses
36
    Addr  : integer := 5;  -- number of pins reserved for addresses
37
    Data  : integer := 16
38
    );
39
  port (
40
    A  : in  std_logic_vector(Addr-1 downto 0);  -- Address inputs
41
    D  : in  std_logic_vector(Data-1 downto 0);  -- Data input
42
    Q  : out std_logic_vector(Data-1 downto 0);  -- Data output
43
    G  : in  std_logic;                 -- Output enable
44
    W  : in  std_logic;                 -- Write  enable
45
    RC : in  std_logic;                 -- Row/Column address select
46
    st : out std_logic                  -- Interface reset
47
    );
48
 
49
end Flash_MeM_USR;
50
 
51
--synopsys synthesis_on
52
architecture Behavioural of Flash_MeM_USR is
53
--synopsys synthesis_off
54
 
55
  type   Flash_Type is array (0 to Words-1) of std_logic_vector(Data-1 downto 0);
56
  signal Mem : Flash_Type := (others => (others => '1'));
57
 
58
 
59
  signal Addr_int : std_logic_vector((2*Addr)-1 downto 0);
60
  signal Data_int : std_logic_vector(Data-1 downto 0);
61
 
62
  signal program         : std_logic := '0';
63
  signal erase           : std_logic := '0';
64
  signal i               : natural range Words-1 downto 0;
65
  signal status_register : std_logic_vector(Data-1 downto 0);
66
  signal status          : std_logic;
67
  signal InitIsDoneFlag  : std_logic := '0';
68
 
69
  function resetVector (dim : natural) return std_logic_vector is
70
 
71
    variable vectorOut : std_logic_vector(dim -1 downto 0);
72
    variable i         : natural range dim downto 0;
73
 
74
  begin
75
    for i in 0 to dim-1 loop
76
      vectorOut(i) := '0';
77
    end loop;
78
    return vectorOut;
79
 
80
  end resetVector;
81
 
82
  function erase_mem (mem : Flash_Type) return Flash_Type is
83
 
84
    variable mem_out : Flash_Type;
85
    variable i       : natural range Words-1 downto 0;
86
 
87
  begin
88
    for i in 0 to Words-1 loop
89
      Mem_out(i) := (others => '1');    --"11111111";
90
    end loop;
91
    return mem_out;
92
 
93
  end erase_mem;
94
  --synopsys synthesis_on
95
begin  --BEHAVIOURAL
96
  --synopsys synthesis_off
97
  write_first : process (RC)
98
  begin
99
    if RC'event and RC = '0' then
100
      Addr_int(Addr-1 downto 0) <= A;
101
    end if;
102
  end process write_first;
103
 
104
  write_second : process (RC)
105
  begin
106
    if RC'event and RC = '1' then
107
      Addr_int((2*Addr)-1 downto Addr) <= A;
108
    end if;
109
  end process write_second;
110
 
111
  w_data : process (W)
112
  begin
113
    if W'event and W = '1' then
114
      if program = '1' then
115
        Mem(conv_integer(unsigned(Addr_int))) <= D after 50 ns;
116
        status_register                       <= conv_std_logic_vector(64, Data);  --"01000000"
117
        Data_int                              <= resetVector(Data_int'length);
118
        st                                    <= '0';
119
      elsif erase = '1' then
120
        Mem      <= erase_mem(Mem) after 750000000 ns;
121
        Data_int <= resetVector(Data_int'length);
122
        st       <= '1'            after 750000000 ns;
123
      else
124
        Data_int        <= D;
125
        status_register <= (others => '0');  --"00000000";
126
        st              <= '0';
127
      end if;
128
    end if;
129
  end process w_data;
130
 
131
  read_data : process (G)
132
  begin
133
    if G'event and G = '0' then
134
      if status = '0' then
135
        Q <= Mem(conv_integer(unsigned(Addr_int))) after 50 ns;
136
      else
137
        Q <= status_register after 750000000 ns;
138
      end if;
139
    elsif G'event and G = '1' then
140
      Q <= (others => 'U') after 50 ns;  -- "UUUUUUUU"
141
    end if;
142
  end process read_data;
143
 
144
  decode : process (Data_int)
145
  begin
146
    case conv_integer(Data_int) is
147
      when 64 =>                        -- "01000000"  program
148
        program <= '1';
149
        erase   <= '0';
150
        status  <= '0';
151
      when 32 =>                        -- "00100000"  erase
152
        program <= '0';
153
        erase   <= '1';
154
        status  <= '0';
155
      when 112 =>                       -- "01110000"  read status reg
156
        program <= '0';
157
        erase   <= '0';
158
        status  <= '1';
159
      when others =>
160
        program <= '0';
161
        erase   <= '0';
162
        status  <= '0';
163
    end case;
164
  end process decode;
165
 
166
 
167
--  -- purpose: Load Memory from file  
168
--  load_memory : process(A, D, G, W, RC, InitIsDoneFlag)
169
--    file init_mem_file       : text open read_mode is "meminit.txt";
170
--    variable inline, outline : line;
171
--    variable add             : natural;
172
--    variable c               : character;
173
--    variable Mem_var         : Flash_Type;
174
--  begin  -- process load_memory
175
--    if InitIsDoneFlag = '0' then
176
--      -- Clear Memory
177
--      for i in 0 to Words-1 loop
178
--        Mem_var(i) := (others => '0');
179
--      end loop;  -- i
180
--      -- Load
181
--      while not endfile(init_mem_file) loop
182
--        readline(init_mem_file, inline);
183
--        read(inline, add);
184
--        read(inline, c);
185
--        if c /= ':' then
186
--          write(outline, string'("Syntax Error"));
187
--          writeline(output, outline);
188
--          assert false report "Mem Loader Aborted" severity failure;
189
--        end if;
190
--        for i in (Data-1) downto 0 loop
191
--          read(inline, c);
192
--          if c = '1' then
193
--            Mem_var(add)(i) := '1';
194
--          elsif c = '0' then
195
--            Mem_var(add)(i) := '0';
196
--          else
197
--            write(outline, string'("Invalid Character-Set to '0'"));
198
--            writeline(output, outline);
199
--            Mem_var(add)(i) := '0';
200
--          end if;
201
--        end loop;  -- i
202
--      end loop;
203
--      Mem <= Mem_var;
204
--      InitIsDoneFlag <= '1';
205
--    end if;
206
--  end process load_memory;
207
 
208
--synopsys synthesis_on
209
end Behavioural;
210
--synopsys synthesis_off
211
 
212
 
213
configuration CFG_Flash_MeM_USR of Flash_MeM_USR is
214
  for Behavioural
215
  end for;
216
end CFG_Flash_MeM_USR;
217
 
218
--synopsys synthesis_on

powered by: WebSVN 2.1.0

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