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

Subversion Repositories epc_rfid_transponder

[/] [epc_rfid_transponder/] [trunk/] [flashmemTID.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 TID
8
--
9
--     File name      : flashmemTID.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_TID 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_TID;
51
 
52
--synopsys synthesis_on
53
architecture Behavioural of Flash_MeM_TID 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
 
99
  write_first : process (RC)
100
  begin
101
    if RC'event and RC = '0' then
102
      Addr_int(Addr-1 downto 0) <= A;
103
    end if;
104
  end process write_first;
105
 
106
  write_second : process (RC)
107
  begin
108
    if RC'event and RC = '1' then
109
      Addr_int((2*Addr)-1 downto Addr) <= A;
110
    end if;
111
  end process write_second;
112
 
113
  w_data : process (W)
114
  begin
115
    if W'event and W = '1' then
116
      if program = '1' then
117
        Mem(conv_integer(unsigned(Addr_int))) <= D after 50 ns;
118
        status_register                       <= conv_std_logic_vector(64, Data);  --"01000000"
119
        Data_int                              <= resetVector(Data_int'length);
120
        st                                    <= '0';
121
      elsif erase = '1' then
122
        Mem      <= erase_mem(Mem) after 750000000 ns;
123
        Data_int <= resetVector(Data_int'length);
124
        st       <= '1'            after 750000000 ns;
125
      else
126
        Data_int        <= D;
127
        status_register <= (others => '0');  --"00000000";
128
        st              <= '0';
129
      end if;
130
    end if;
131
  end process w_data;
132
 
133
  read_data : process (G)
134
  begin
135
    if G'event and G = '0' then
136
      if status = '0' then
137
        Q <= Mem(conv_integer(unsigned(Addr_int))) after 50 ns;
138
      else
139
        Q <= status_register after 750000000 ns;
140
      end if;
141
    elsif G'event and G = '1' then
142
      Q <= (others => 'U') after 50 ns;  -- "UUUUUUUU"
143
    end if;
144
  end process read_data;
145
 
146
  decode : process (Data_int)
147
  begin
148
    case conv_integer(Data_int) is
149
      when 64 =>                        -- "01000000"  program
150
        program <= '1';
151
        erase   <= '0';
152
        status  <= '0';
153
      when 32 =>                        -- "00100000"  erase
154
        program <= '0';
155
        erase   <= '1';
156
        status  <= '0';
157
      when 112 =>                       -- "01110000"  read status reg
158
        program <= '0';
159
        erase   <= '0';
160
        status  <= '1';
161
      when others =>
162
        program <= '0';
163
        erase   <= '0';
164
        status  <= '0';
165
    end case;
166
  end process decode;
167
 
168
 
169
--  -- purpose: Load Memory from file  
170
--  load_memory : process(A, D, G, W, RC, InitIsDoneFlag)
171
--    file init_mem_file       : text open read_mode is "meminit.txt";
172
--    variable inline, outline : line;
173
--    variable add             : natural;
174
--    variable c               : character;
175
--    variable Mem_var         : Flash_Type;
176
--  begin  -- process load_memory
177
--    if InitIsDoneFlag = '0' then
178
--      -- Clear Memory
179
--      for i in 0 to Words-1 loop
180
--        Mem_var(i) := (others => '0');
181
--      end loop;  -- i
182
--      -- Load
183
--      while not endfile(init_mem_file) loop
184
--        readline(init_mem_file, inline);
185
--        read(inline, add);
186
--        read(inline, c);
187
--        if c /= ':' then
188
--          write(outline, string'("Syntax Error"));
189
--          writeline(output, outline);
190
--          assert false report "Mem Loader Aborted" severity failure;
191
--        end if;
192
--        for i in (Data-1) downto 0 loop
193
--          read(inline, c);
194
--          if c = '1' then
195
--            Mem_var(add)(i) := '1';
196
--          elsif c = '0' then
197
--            Mem_var(add)(i) := '0';
198
--          else
199
--            write(outline, string'("Invalid Character-Set to '0'"));
200
--            writeline(output, outline);
201
--            Mem_var(add)(i) := '0';
202
--          end if;
203
--        end loop;  -- i
204
--      end loop;
205
--      Mem <= Mem_var;
206
--      InitIsDoneFlag <= '1';
207
--    end if;
208
--  end process load_memory;
209
 
210
--synopsys synthesis_on
211
end Behavioural;
212
--synopsys synthesis_off
213
 
214
 
215
 
216
configuration CFG_Flash_MeM_TID of Flash_MeM_TID is
217
  for Behavioural
218
  end for;
219
end CFG_Flash_MeM_TID;
220
 
221
--synopsys synthesis_on

powered by: WebSVN 2.1.0

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