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

Subversion Repositories epc_rfid_transponder

[/] [epc_rfid_transponder/] [trunk/] [memctrl.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          : Memory Controller
8
--
9
--     File name      : MemCtrl.vhd 
10
--
11
--     Description    : Flash memory controller.  
12
--
13
--     Authors        : Erwing Sanchez <erwing.sanchezsanchez@polito.it>
14
--
15
--     Rev. History   : Erwing Sanchez  -- 17/07/06
16
--                             
17
-------------------------------------------------------------------------------            
18
-------------------------------------------------------------------------------
19
--      EPC Memory Map
20
--
21
--               _______________________  
22
--              |                       | RESERVED MEMORY (Bank 00)
23
--              |                       |
24
--              |_______________________|
25
--              |                       | EPC MEMORY (Bank 01)
26
--              |                       |
27
--              |_______________________|
28
--              |                       | TID MEMORY (Bank 10)
29
--              |                       |
30
--              |_______________________|
31
--              |                       | USER MEMORY (Bank 11)
32
--              |                       |
33
--              |_______________________|
34
--
35
 
36
 
37
library IEEE;
38
use IEEE.STD_LOGIC_1164.all;
39
use IEEE.STD_LOGIC_ARITH.all;
40
 
41
 
42
entity Mem_ctrl is
43
  generic (
44
    WordsRSV :     integer := 8;
45
    WordsEPC :     integer := 16;
46
    WordsTID :     integer := 8;
47
    WordsUSR :     integer := 256;
48
    --Address are loaded in two steps, so only half of address pins are needed.
49
    AddrRSV  :     integer := 2;        -- 1/2address pins 
50
    AddrEPC  :     integer := 3;        -- 1/2address pins
51
    AddrTID  :     integer := 2;        -- 1/2address pins
52
    AddrUSR  :     integer := 5;        -- 1/2address pins    
53
    Data     :     integer := 16);
54
  port (
55
    clk      : in  std_logic;
56
    rst_n    : in  std_logic;
57
    BANK     : in  std_logic_vector(1 downto 0);
58
    WR       : in  std_logic;           -- Write signal
59
    RD       : in  std_logic;           -- Read signal
60
    ADR      : in  std_logic_vector((2*AddrUSR)-1 downto 0);
61
    DTI      : in  std_logic_vector(Data-1 downto 0);
62
    DTO      : out std_logic_vector(Data-1 downto 0);
63
    RB       : out std_logic            -- Ready/nBusy signal(unbuffered!)
64
    );
65
end Mem_ctrl;
66
 
67
 
68
architecture Mem_Ctrl_arch of Mem_ctrl is
69
 
70
 
71
  component Flash_MeM_EPC
72
    generic (
73
      Words : integer;
74
      Addr  : integer;
75
      Data  : integer);
76
    port (
77
      A  : in  std_logic_vector(Addr-1 downto 0);
78
      D  : in  std_logic_vector(Data-1 downto 0);
79
      Q  : out std_logic_vector(Data-1 downto 0);
80
      G  : in  std_logic;
81
      W  : in  std_logic;
82
      RC : in  std_logic;
83
      st : out std_logic);
84
  end component;
85
 
86
  component Flash_MeM_TID
87
    generic (
88
      Words : integer;
89
      Addr  : integer;
90
      Data  : integer);
91
    port (
92
      A  : in  std_logic_vector(Addr-1 downto 0);
93
      D  : in  std_logic_vector(Data-1 downto 0);
94
      Q  : out std_logic_vector(Data-1 downto 0);
95
      G  : in  std_logic;
96
      W  : in  std_logic;
97
      RC : in  std_logic;
98
      st : out std_logic);
99
  end component;
100
 
101
  component Flash_MeM_USR
102
    generic (
103
      Words : integer;
104
      Addr  : integer;
105
      Data  : integer);
106
    port (
107
      A  : in  std_logic_vector(Addr-1 downto 0);
108
      D  : in  std_logic_vector(Data-1 downto 0);
109
      Q  : out std_logic_vector(Data-1 downto 0);
110
      G  : in  std_logic;
111
      W  : in  std_logic;
112
      RC : in  std_logic;
113
      st : out std_logic);
114
  end component;
115
 
116
  component Flash_MeM_RSV
117
    generic (
118
      Words : integer;
119
      Addr  : integer;
120
      Data  : integer);
121
    port (
122
      A  : in  std_logic_vector(Addr-1 downto 0);
123
      D  : in  std_logic_vector(Data-1 downto 0);
124
      Q  : out std_logic_vector(Data-1 downto 0);
125
      G  : in  std_logic;
126
      W  : in  std_logic;
127
      RC : in  std_logic;
128
      st : out std_logic);
129
  end component;
130
 
131
 
132
  -- Contants
133
  constant WriteCommand                   : std_logic_vector(Data-1 downto 0) := conv_std_logic_vector(64, Data);  --"01000000" Flash Write Code
134
  -- FSM
135
  type MemCtrl_t is (st_idle, st_read_LoadAddr1, st_read_LoadAddr2, st_read_LoadOutput, st_read_read, st_write_LoadAddr1, st_write_LoadAddr2, st_write_write);
136
  signal   StMCtrl, NextStMCtrl           : MemCtrl_t;
137
  -- Memory signals
138
  signal   A_RSV                          : std_logic_vector(AddrRSV-1 downto 0);
139
  signal   A_EPC                          : std_logic_vector(AddrEPC-1 downto 0);
140
  signal   A_TID                          : std_logic_vector(AddrTID-1 downto 0);
141
  signal   A_USR                          : std_logic_vector(AddrUSR-1 downto 0);
142
  signal   D                              : std_logic_vector(Data-1 downto 0);
143
  signal   Q                              : std_logic_vector(Data-1 downto 0);
144
  signal   G, G_i                         : std_logic;
145
  signal   W, W_i                         : std_logic;
146
  signal   RC, RC_i                       : std_logic;
147
  signal   st                             : std_logic;
148
  signal   W_RSV, W_EPC, W_TID, W_USR     : std_logic;
149
  signal   G_RSV, G_EPC, G_TID, G_USR     : std_logic;
150
  signal   Q_RSV, Q_EPC, Q_TID, Q_USR     : std_logic_vector(Data-1 downto 0);
151
  signal   RC_RSV, RC_EPC, RC_TID, RC_USR : std_logic;
152
  -- Internal regs
153
  signal   DTI_r                          : std_logic_vector(Data-1 downto 0);
154
  signal   DTO_r                          : std_logic_vector(Data-1 downto 0);
155
  signal   ADR_r                          : std_logic_vector((2*AddrUSR)-1 downto 0);
156
  signal   BNK_r                          : std_logic_vector(1 downto 0);
157
  signal   ADR_ce, DTI_ce, DTO_ce, BNK_ce : std_logic;
158
  -- Internal Flags & other signals
159
  signal   AddrMux                        : std_logic;
160
  signal   WRCmdFlag, WRCmdFlag_i         : std_logic;
161
 
162
begin  -- Mem_Ctrl_arch
163
 
164
 
165
  SYNC_MEMCTRL : process (clk, rst_n)
166
  begin  -- process SYNC
167
    if rst_n = '0' then                 -- asynchronous reset (active low)
168
      StMCtrl <= st_idle;
169
      RC      <= '1';                   -- 1 -> 0 : Load LSB address
170
      G       <= '1';                   -- 0: enable
171
      W       <= '0';
172
      WRCmdFlag <= '0';
173
    elsif clk'event and clk = '1' then  -- rising clock edge
174
      StMCtrl <= NextStMCtrl;
175
      RC      <= RC_i;
176
      G       <= G_i;
177
      W       <= W_i;
178
      WRCmdFlag <= WRCmdFlag_i;
179
    end if;
180
  end process SYNC_MEMCTRL;
181
 
182
  NEXTST_MEMCTRL : process (StMCtrl, WR, RD, ADR, DTI)
183
  begin  -- process NEXTST
184
 
185
    NextStMCtrl <= StMCtrl;
186
 
187
    case StMCtrl is
188
      when st_idle            =>
189
        if WR = '1' then
190
          NextStMCtrl <= st_write_LoadAddr1;
191
        elsif RD = '1' then
192
          NextStMCtrl <= st_read_LoadAddr1;
193
        end if;
194
      when st_read_LoadAddr1  =>
195
        NextStMCtrl   <= st_read_LoadAddr2;
196
      when st_read_LoadAddr2  =>
197
        NextStMCtrl   <= st_read_read;
198
      when st_read_read       =>
199
        NextStMCtrl   <= st_read_LoadOutput;
200
      when st_read_LoadOutput =>
201
        NextStMCtrl   <= st_idle;
202
 
203
      when st_write_LoadAddr1 =>
204
        NextStMCtrl <= st_write_LoadAddr2;
205
      when st_write_LoadAddr2 =>
206
        NextStMCtrl <= st_write_write;
207
      when st_write_write     =>
208
        NextStMCtrl <= st_idle;
209
 
210
      when others => null;
211
    end case;
212
 
213
  end process NEXTST_MEMCTRL;
214
 
215
 
216
  OUTPUT_MEMCTRL : process (StMCtrl, WR, RD)
217
  begin  -- process OUTPUT_MEMCTRL
218
 
219
    RB        <= '0';
220
    ADR_ce    <= '0';
221
    DTI_ce    <= '0';
222
    DTO_ce    <= '0';
223
    BNK_ce    <= '0';
224
    AddrMux   <= '0';
225
    WRCmdFlag_i <= '0';
226
    -- Memory signals
227
    RC_i      <= '1';
228
    G_i       <= '1';
229
    W_i       <= '0';
230
 
231
    case StMCtrl is
232
      when st_idle =>
233
        RB       <= '1';
234
        if WR = '1' then
235
          ADR_ce <= '1';                -- load address
236
          DTI_ce <= '1';                -- load data
237
          BNK_ce <= '1';                -- load Bank
238
          RB     <= '0';
239
        elsif RD = '1' then
240
          ADR_ce <= '1';                -- load address
241
          BNK_ce <= '1';                -- load Bank
242
          RB     <= '0';
243
        end if;
244
 
245
      when st_read_LoadAddr1 =>
246
        RC_i <= '0';                    -- Load Address LSB
247
 
248
      when st_read_LoadAddr2 =>
249
        AddrMux <= '1';                 -- Load Address MSB
250
 
251
      when st_read_read =>
252
        G_i <= '0';                     -- Read Command
253
 
254
      when st_read_LoadOutput =>
255
        DTO_ce <= '1';                  -- Load output register
256
 
257
      when st_write_LoadAddr1 =>
258
        RC_i      <= '0';               -- Load Address LSB
259
        WRCmdFlag_i <= '1';               -- Load Write Command code
260
        W_i       <= '1';
261
 
262
      when st_write_LoadAddr2 =>
263
        AddrMux <= '1';                 -- Load Address MSB
264
 
265
      when st_write_write =>
266
        W_i <= '1';                     -- Write Data
267
 
268
      when others => null;
269
    end case;
270
  end process OUTPUT_MEMCTRL;
271
 
272
 
273
 
274
  INTREGS : process (clk, rst_n)
275
  begin  -- process INTREGS
276
    if rst_n = '0' then                 -- asynchronous reset (active low)
277
      ADR_r   <= (others => '0');
278
      DTI_r   <= (others => '0');
279
      DTO_r   <= (others => '0');
280
      BNK_r   <= (others => '0');
281
    elsif clk'event and clk = '1' then  -- rising clock edge
282
      if ADR_ce = '1' then
283
        ADR_r <= ADR;
284
      end if;
285
      if DTI_ce = '1' then
286
        DTI_r <= DTI;
287
      end if;
288
      if DTO_ce = '1' then
289
        DTO_r <= Q;
290
      end if;
291
      if BNK_ce = '1' then
292
        BNK_r <= BANK;
293
      end if;
294
    end if;
295
  end process INTREGS;
296
 
297
 
298
  DTO <= DTO_r;
299
 
300
 
301
-------------------------------------------------------------------------------
302
-- ADDRESS MUX
303
-------------------------------------------------------------------------------
304
 
305
  A_RSV <= ADR_r(AddrRSV-1 downto 0) when AddrMux = '0' else
306
           ADR_r((2*AddrRSV)-1 downto AddrRSV);
307
 
308
  A_EPC <= ADR_r(AddrEPC-1 downto 0) when AddrMux = '0' else
309
           ADR_r((2*AddrEPC)-1 downto AddrEPC);
310
 
311
  A_TID <= ADR_r(AddrTID-1 downto 0) when AddrMux = '0' else
312
           ADR_r((2*AddrTID)-1 downto AddrTID);
313
 
314
  A_USR <= ADR_r(AddrUSR-1 downto 0) when AddrMux = '0' else
315
           ADR_r((2*AddrUSR)-1 downto AddrUSR);
316
 
317
 
318
-------------------------------------------------------------------------------
319
-- DATA IN MUX
320
-------------------------------------------------------------------------------
321
 
322
  D <= WriteCommand when WRCmdFlag = '1' else
323
       DTI_r;
324
 
325
-------------------------------------------------------------------------------
326
-- CONTROL SIGNALS MUXs
327
-------------------------------------------------------------------------------
328
 
329
  W_RSV <= W when BNK_r = "00" else
330
           '0';
331
  W_EPC <= W when BNK_r = "01" else
332
           '0';
333
  W_TID <= W when BNK_r = "10" else
334
           '0';
335
  W_USR <= W when BNK_r = "11" else
336
           '0';
337
 
338
 
339
  G_RSV <= G when BNK_r = "00" else
340
           '1';
341
  G_EPC <= G when BNK_r = "01" else
342
           '1';
343
  G_TID <= G when BNK_r = "10" else
344
           '1';
345
  G_USR <= G when BNK_r = "11" else
346
           '1';
347
 
348
  RC_RSV <= RC when BNK_r = "00" else
349
            '1';
350
  RC_EPC <= RC when BNK_r = "01" else
351
            '1';
352
  RC_TID <= RC when BNK_r = "10" else
353
            '1';
354
  RC_USR <= RC when BNK_r = "11" else
355
            '1';
356
 
357
  Q <= Q_RSV when BNK_r = "00" else
358
       Q_EPC when BNK_r = "01" else
359
       Q_TID when BNK_r = "10" else
360
       Q_USR;
361
 
362
-------------------------------------------------------------------------------
363
-- MEMORIES
364
-------------------------------------------------------------------------------
365
 
366
  Flash_MeM_RSV_i : Flash_MeM_RSV
367
    generic map (
368
      Words => WordsRSV,
369
      Addr  => AddrRSV,
370
      Data  => Data)
371
    port map (
372
      A     => A_RSV,
373
      D     => D,
374
      Q     => Q_RSV,
375
      G     => G_RSV,
376
      W     => W_RSV,
377
      RC    => RC_RSV,
378
      st    => st);
379
 
380
  Flash_MeM_EPC_i : Flash_MeM_EPC
381
    generic map (
382
      Words => WordsEPC,
383
      Addr  => AddrEPC,
384
      Data  => Data)
385
    port map (
386
      A     => A_EPC,
387
      D     => D,
388
      Q     => Q_EPC,
389
      G     => G_EPC,
390
      W     => W_EPC,
391
      RC    => RC_EPC,
392
      st    => st);
393
 
394
  Flash_MeM_TID_i : Flash_MeM_TID
395
    generic map (
396
      Words => WordsTID,
397
      Addr  => AddrTID,
398
      Data  => Data)
399
    port map (
400
      A     => A_TID,
401
      D     => D,
402
      Q     => Q_TID,
403
      G     => G_TID,
404
      W     => W_TID,
405
      RC    => RC_TID,
406
      st    => st);
407
 
408
  Flash_MeM_USR_i : Flash_MeM_USR
409
    generic map (
410
      Words => WordsUSR,
411
      Addr  => AddrUSR,
412
      Data  => Data)
413
    port map (
414
      A     => A_USR,
415
      D     => D,
416
      Q     => Q_USR,
417
      G     => G_USR,
418
      W     => W_USR,
419
      RC    => RC_USR,
420
      st    => st);
421
 
422
end Mem_Ctrl_arch;

powered by: WebSVN 2.1.0

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