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

powered by: WebSVN 2.1.0

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