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 3

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

powered by: WebSVN 2.1.0

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