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

Subversion Repositories epc_rfid_transponder

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

powered by: WebSVN 2.1.0

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