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

Subversion Repositories epc_rfid_transponder

[/] [epc_rfid_transponder/] [trunk/] [flashmemRSV.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 RSV
8
--
9
--     File name      : flashmemRSV.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_RSV is
35
  generic (
36
    Words : integer := 8;           -- number of addresses
37
    Addr  : integer := 2;  -- 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_RSV;
51
 
52
 
53
architecture Behavioural of Flash_MeM_RSV 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 := ("0100000000000000",
58
                              "0000000000011000",
59
                              "0000000000000000",
60
                              "0000000000000000",
61
                              "0000000000000000",
62
                              "0000000000000000",
63
                              "0000000000000000",
64
                              "0000000000000000");
65
 
66
 
67
 
68
  signal Addr_int : std_logic_vector((2*Addr)-1 downto 0);
69
  signal Data_int : std_logic_vector(Data-1 downto 0);
70
 
71
  signal program         : std_logic := '0';
72
  signal erase           : std_logic := '0';
73
  signal i               : natural range Words-1 downto 0;
74
  signal status_register : std_logic_vector(Data-1 downto 0);
75
  signal status          : std_logic;
76
  signal InitIsDoneFlag  : std_logic := '0';
77
 
78
  function resetVector (dim : natural) return std_logic_vector is
79
 
80
    variable vectorOut : std_logic_vector(dim -1 downto 0);
81
    variable i         : natural range dim downto 0;
82
 
83
  begin
84
    for i in 0 to dim-1 loop
85
      vectorOut(i) := '0';
86
    end loop;
87
    return vectorOut;
88
 
89
  end resetVector;
90
 
91
  function erase_mem (mem : Flash_Type) return Flash_Type is
92
 
93
    variable mem_out : Flash_Type;
94
    variable i       : natural range Words-1 downto 0;
95
 
96
  begin
97
    for i in 0 to Words-1 loop
98
      Mem_out(i) := (others => '1');    --"11111111";
99
    end loop;
100
    return mem_out;
101
 
102
  end erase_mem;
103
  --synopsys synthesis_on
104
begin  --BEHAVIOURAL
105
  --synopsys synthesis_off
106
  write_first : process (RC)
107
  begin
108
    if RC'event and RC = '0' then
109
      Addr_int(Addr-1 downto 0) <= A;
110
    end if;
111
  end process write_first;
112
 
113
  write_second : process (RC)
114
  begin
115
    if RC'event and RC = '1' then
116
      Addr_int((2*Addr)-1 downto Addr) <= A;
117
    end if;
118
  end process write_second;
119
 
120
  w_data : process (W)
121
  begin
122
    if W'event and W = '1' then
123
      if program = '1' then
124
        Mem(conv_integer(unsigned(Addr_int))) <= D after 50 ns;
125
        status_register                       <= conv_std_logic_vector(64, Data);  --"01000000"
126
        Data_int                              <= resetVector(Data_int'length);
127
        st                                    <= '0';
128
      elsif erase = '1' then
129
        Mem      <= erase_mem(Mem) after 750000000 ns;
130
        Data_int <= resetVector(Data_int'length);
131
        st       <= '1'            after 750000000 ns;
132
      else
133
        Data_int        <= D;
134
        status_register <= (others => '0');  --"00000000";
135
        st              <= '0';
136
      end if;
137
    end if;
138
  end process w_data;
139
 
140
  read_data : process (G)
141
  begin
142
    if G'event and G = '0' then
143
      if status = '0' then
144
        Q <= Mem(conv_integer(unsigned(Addr_int))) after 50 ns;
145
      else
146
        Q <= status_register after 750000000 ns;
147
      end if;
148
    elsif G'event and G = '1' then
149
      Q <= (others => 'U') after 50 ns;  -- "UUUUUUUU"
150
    end if;
151
  end process read_data;
152
 
153
  decode : process (Data_int)
154
  begin
155
    case conv_integer(Data_int) is
156
      when 64 =>                        -- "01000000"  program
157
        program <= '1';
158
        erase   <= '0';
159
        status  <= '0';
160
      when 32 =>                        -- "00100000"  erase
161
        program <= '0';
162
        erase   <= '1';
163
        status  <= '0';
164
      when 112 =>                       -- "01110000"  read status reg
165
        program <= '0';
166
        erase   <= '0';
167
        status  <= '1';
168
      when others =>
169
        program <= '0';
170
        erase   <= '0';
171
        status  <= '0';
172
    end case;
173
  end process decode;
174
 
175
 
176
--  -- purpose: Load Memory from file  
177
--  load_memory : process(A, D, G, W, RC, InitIsDoneFlag)
178
--    file init_mem_file       : text open read_mode is "meminit.txt";
179
--    variable inline, outline : line;
180
--    variable add             : natural;
181
--    variable c               : character;
182
--    variable Mem_var         : Flash_Type;
183
--  begin  -- process load_memory
184
--    if InitIsDoneFlag = '0' then
185
--      -- Clear Memory
186
--      for i in 0 to Words-1 loop
187
--        Mem_var(i) := (others => '0');
188
--      end loop;  -- i
189
--      -- Load
190
--      while not endfile(init_mem_file) loop
191
--        readline(init_mem_file, inline);
192
--        read(inline, add);
193
--        read(inline, c);
194
--        if c /= ':' then
195
--          write(outline, string'("Syntax Error"));
196
--          writeline(output, outline);
197
--          assert false report "Mem Loader Aborted" severity failure;
198
--        end if;
199
--        for i in (Data-1) downto 0 loop
200
--          read(inline, c);
201
--          if c = '1' then
202
--            Mem_var(add)(i) := '1';
203
--          elsif c = '0' then
204
--            Mem_var(add)(i) := '0';
205
--          else
206
--            write(outline, string'("Invalid Character-Set to '0'"));
207
--            writeline(output, outline);
208
--            Mem_var(add)(i) := '0';
209
--          end if;
210
--        end loop;  -- i
211
--      end loop;
212
--      Mem <= Mem_var;
213
--      InitIsDoneFlag <= '1';
214
--    end if;
215
--  end process load_memory;
216
 
217
--synopsys synthesis_on
218
end Behavioural;
219
 
220
--synopsys synthesis_off
221
 
222
configuration CFG_Flash_MeM_RSV of Flash_MeM_RSV is
223
  for Behavioural
224
  end for;
225
end CFG_Flash_MeM_RSV;
226
 
227
--synopsys synthesis_on

powered by: WebSVN 2.1.0

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