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

powered by: WebSVN 2.1.0

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