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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [rtl/] [bplib/] [s3board/] [s3_sram_memctl.vhd] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 wfjm
-- $Id: s3_sram_memctl.vhd 649 2015-02-21 21:10:16Z mueller $
2 2 wfjm
--
3 13 wfjm
-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 2 wfjm
--
5
-- This program is free software; you may redistribute and/or modify it under
6
-- the terms of the GNU General Public License as published by the Free
7
-- Software Foundation, either version 2, or at your option any later version.
8
--
9
-- This program is distributed in the hope that it will be useful, but
10
-- WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
-- for complete details.
13
-- 
14
------------------------------------------------------------------------------
15
-- Module Name:    s3_sram_memctl - syn
16
-- Description:    s3board: SRAM driver
17
--
18
-- Dependencies:   vlib/xlib/iob_reg_o
19
--                 vlib/xlib/iob_reg_o_gen
20
--                 vlib/xlib/iob_reg_io_gen
21
-- Test bench:     tb/tb_s3_sram_memctl
22
--                 fw_gen/tst_sram/s3board/tb/tb_tst_sram_s3
23
-- Target Devices: generic
24 29 wfjm
-- Tool versions:  xst 8.2-14.7; ghdl 0.18-0.31
25 2 wfjm
--
26
-- Synthesized (xst):
27
-- Date         Rev  ise         Target      flop lutl lutm slic t peri
28
-- 2010-05-23   293  11.4   L68  xc3s1000-4     7   22    0   14 s  8.5
29
-- 2008-02-16   116  8.2.03 I34  xc3s1000-4     5   30    0   17 s  7.0
30
--
31
-- Revision History: 
32
-- Date         Rev Version  Comment
33 13 wfjm
-- 2011-11-19   427   1.0.6  now numeric_std clean
34 2 wfjm
-- 2010-06-03   299   1.0.5  add "KEEP" for data iob;
35
-- 2010-05-16   291   1.0.4  rename memctl_s3sram -> s3_sram_memctl
36
-- 2008-02-17   117   1.0.3  use req,we rather req_r,req_w interface
37
-- 2008-01-20   113   1.0.2  rename memdrv -> memctl_s3sram
38
-- 2007-12-15   101   1.0.1  use _N for active low; get ce/we clocking right
39
-- 2007-12-08   100   1.0    Initial version 
40
--
41
-- Timing of some signals:
42
--
43
-- single read request:
44
-- 
45
-- state       |_idle  |_read  |_idle  |
46
-- 
47
-- CLK       __|^^^|___|^^^|___|^^^|___|^
48
-- 
49
-- REQ       _______|^^^^^|______________
50
-- WE        ____________________________
51
-- 
52
-- IOB_CE    __________|^^^^^^^|_________
53
-- IOB_OE    __________|^^^^^^^|_________
54
-- 
55
-- DO        oooooooooooooooooo|ddddddd|d
56
-- BUSY      ____________________________
57
-- ACK_R     __________________|^^^^^^^|_
58
-- 
59
-- single write request:
60
-- 
61
-- state       |_idle  |_write1|_write2|_idle  |
62
-- 
63
-- CLK       __|^^^|___|^^^|___|^^^|___|^^^|___|^
64
-- 
65
-- REQ       _______|^^^^^|______________
66
-- WE        _______|^^^^^|______________
67
-- 
68
-- IOB_CE    __________|^^^^^^^^^^^^^^^|_________
69
-- IOB_BE    __________|^^^^^^^^^^^^^^^|_________
70
-- IOB_OE    ____________________________________
71
-- IOB_WE    ______________|^^^^^^^|_____________
72
-- 
73
-- BUSY      __________|^^^^^^^|_________________
74
-- ACK_W     __________________|^^^^^^^|_________
75
-- 
76
------------------------------------------------------------------------------
77
 
78
library ieee;
79
use ieee.std_logic_1164.all;
80 13 wfjm
use ieee.numeric_std.all;
81 2 wfjm
 
82
use work.slvtypes.all;
83
use work.xlib.all;
84
 
85
entity s3_sram_memctl is                -- SRAM driver for S3BOARD
86
  port (
87
    CLK : in slbit;                     -- clock
88
    RESET : in slbit;                   -- reset
89
    REQ   : in slbit;                   -- request
90
    WE    : in slbit;                   -- write enable
91
    BUSY : out slbit;                   -- controller busy
92
    ACK_R : out slbit;                  -- acknowledge read
93
    ACK_W : out slbit;                  -- acknowledge write
94
    ACT_R : out slbit;                  -- signal active read
95
    ACT_W : out slbit;                  -- signal active write
96
    ADDR : in slv18;                    -- address
97
    BE : in slv4;                       -- byte enable
98
    DI : in slv32;                      -- data in  (memory view)
99
    DO : out slv32;                     -- data out (memory view)
100
    O_MEM_CE_N : out slv2;              -- sram: chip enables  (act.low)
101
    O_MEM_BE_N : out slv4;              -- sram: byte enables  (act.low)
102
    O_MEM_WE_N : out slbit;             -- sram: write enable  (act.low)
103
    O_MEM_OE_N : out slbit;             -- sram: output enable (act.low)
104
    O_MEM_ADDR  : out slv18;            -- sram: address lines
105
    IO_MEM_DATA : inout slv32           -- sram: data lines
106
  );
107
end s3_sram_memctl;
108
 
109
 
110
architecture syn of s3_sram_memctl is
111
 
112
  type state_type is (
113
    s_idle,                             -- s_idle: wait for req
114
    s_read,                             -- s_read: read cycle
115
    s_write1,                           -- s_write1: write cycle, 1st half
116
    s_write2,                           -- s_write2: write cycle, 2nd half
117
    s_bta_r2w,                          -- s_bta_r2w: bus turn around: r->w
118
    s_bta_w2r                           -- s_bta_w2r: bus turn around: w->r
119
  );
120
 
121
  type regs_type is record
122
    state : state_type;                 -- state
123
    ackr : slbit;                       -- signal ack_r
124
  end record regs_type;
125
 
126
  constant regs_init : regs_type := (
127 29 wfjm
    s_idle,                             -- state
128 2 wfjm
    '0'                                 -- ackr
129
  );
130
 
131
  signal R_REGS : regs_type := regs_init;  -- state registers
132
  signal N_REGS : regs_type := regs_init;  -- next value state regs
133
 
134
  signal CLK_180  : slbit := '0';
135
  signal MEM_CE_N : slv2 := "00";
136
  signal MEM_BE_N : slv4 := "0000";
137
  signal MEM_WE_N : slbit := '0';
138
  signal MEM_OE_N : slbit := '0';
139
  signal ADDR_CE  : slbit := '0';
140
  signal DATA_CEI : slbit := '0';
141
  signal DATA_CEO : slbit := '0';
142
  signal DATA_OE  : slbit := '0';
143
 
144
begin
145
 
146
  CLK_180 <= not CLK;
147
 
148
  IOB_MEM_CE : iob_reg_o_gen
149
    generic map (
150
      DWIDTH => 2,
151
      INIT   => '1')
152
    port map (
153
      CLK => CLK,
154
      CE  => '1',
155
      DO  => MEM_CE_N,
156
      PAD => O_MEM_CE_N
157
    );
158
 
159
  IOB_MEM_BE : iob_reg_o_gen
160
    generic map (
161
      DWIDTH => 4,
162
      INIT   => '1')
163
    port map (
164
      CLK => CLK,
165
      CE  => ADDR_CE,
166
      DO  => MEM_BE_N,
167
      PAD => O_MEM_BE_N
168
    );
169
 
170
  IOB_MEM_WE : iob_reg_o
171
    generic map (
172
      INIT   => '1')
173
    port map (
174
      CLK => CLK_180,
175
      CE  => '1',
176
      DO  => MEM_WE_N,
177
      PAD => O_MEM_WE_N
178
    );
179
 
180
  IOB_MEM_OE : iob_reg_o
181
    generic map (
182
      INIT   => '1')
183
    port map (
184
      CLK => CLK,
185
      CE  => '1',
186
      DO  => MEM_OE_N,
187
      PAD => O_MEM_OE_N
188
    );
189
 
190
  IOB_MEM_ADDR : iob_reg_o_gen
191
    generic map (
192
      DWIDTH => 18)
193
    port map (
194
      CLK => CLK,
195
      CE  => ADDR_CE,
196
      DO  => ADDR,
197
      PAD => O_MEM_ADDR
198
    );
199
 
200
  IOB_MEM_DATA : iob_reg_io_gen
201
    generic map (
202
      DWIDTH => 32,
203
      PULL   => "KEEP")
204
    port map (
205
      CLK => CLK,
206
      CEI => DATA_CEI,
207
      CEO => DATA_CEO,
208
      OE  => DATA_OE,
209
      DI  => DO,
210
      DO  => DI,
211
      PAD => IO_MEM_DATA
212
    );
213
 
214
  proc_regs: process (CLK)
215
  begin
216
 
217 13 wfjm
    if rising_edge(CLK) then
218 2 wfjm
      if RESET = '1' then
219
        R_REGS <= regs_init;
220
      else
221
        R_REGS <= N_REGS;
222
      end if;
223
    end if;
224
 
225
  end process proc_regs;
226
 
227
  proc_next: process (R_REGS, REQ, WE, BE)
228
 
229
    variable r : regs_type := regs_init;
230
    variable n : regs_type := regs_init;
231
    variable ibusy : slbit := '0';
232
    variable iackw : slbit := '0';
233
    variable iactr : slbit := '0';
234
    variable iactw : slbit := '0';
235
    variable imem_ce : slv2 := "00";
236
    variable imem_be : slv4 := "0000";
237
    variable imem_we : slbit := '0';
238
    variable imem_oe : slbit := '0';
239
    variable iaddr_ce  : slbit := '0';
240
    variable idata_cei : slbit := '0';
241
    variable idata_ceo : slbit := '0';
242
    variable idata_oe  : slbit := '0';
243
 
244
  begin
245
 
246
    r := R_REGS;
247
    n := R_REGS;
248
    n.ackr := '0';
249
 
250
    ibusy := '0';
251
    iackw := '0';
252
    iactr := '0';
253
    iactw := '0';
254
 
255
    imem_ce := "00";
256
    imem_be := "1111";
257
    imem_we := '0';
258
    imem_oe := '0';
259
    iaddr_ce  := '0';
260
    idata_cei := '0';
261
    idata_ceo := '0';
262
    idata_oe  := '0';
263
 
264
    case r.state is
265
      when s_idle =>                    -- s_idle: wait for req
266
        if REQ = '1' then                 -- if IO requested
267
          if WE = '0' then                  -- if READ requested
268
            iaddr_ce := '1';                  -- latch address and be's
269
            imem_ce  := "11";                 -- ce SRAM next cycle
270
            imem_oe  := '1';                  -- oe SRAM next cycle
271
            n.state := s_read;                -- next: read
272
          else                              -- if WRITE requested
273
            iaddr_ce  := '1';                 -- latch address and be's
274
            idata_ceo := '1';                 -- latch output data
275
            idata_oe  := '1';                 -- oe FPGA next cycle
276
            imem_ce   := "11";                -- ce SRAM next cycle
277
            imem_be   := BE;                  -- use request BE's
278
            n.state := s_write1;              -- next: write 1st part
279
          end if;
280
        end if;
281
 
282
      when s_read =>                    -- s_read: read cycle
283
        idata_cei := '1';                 -- latch input data
284
        iactr := '1';                     -- signal mem read
285
        n.ackr := '1';                    -- ACK_R next cycle
286
        if REQ = '1' then                 -- if IO requested
287
          if WE = '0' then                  -- if READ requested
288
            iaddr_ce := '1';                  -- latch address and be's
289
            imem_ce  := "11";                 -- ce SRAM next cycle
290
            imem_oe  := '1';                  -- oe SRAM next cycle
291
            n.state := s_read;                -- next: continue read
292
          else                              -- if WRITE requested
293
            iaddr_ce  := '1';                 -- latch address and be's
294
            idata_ceo := '1';                 -- latch output data
295
            imem_be   := BE;                  -- use request BE's
296
            n.state := s_bta_r2w;             -- next: bus turn around cycle
297
          end if;
298
        else
299
          n.state := s_idle;              -- next: idle if nothing to do
300
        end if;
301
 
302
      when s_write1 =>                  -- s_write1: write cycle, 1st half
303
        ibusy := '1';                     -- signal busy, unable to handle req
304
        iactw := '1';                     -- signal mem write
305
        idata_oe := '1';                  -- oe FPGA next cycle
306
        imem_ce  := "11";                 -- ce SRAM next cycle
307
        imem_we  := '1';                  -- we SRAM next shifted cycle
308
        n.state := s_write2;              -- next: write cycle, 2nd half
309
 
310
      when s_write2 =>                  -- s_write2: write cycle, 2nd half
311
        iactw := '1';                     -- signal mem write
312
        iackw := '1';                     -- signal write acknowledge
313
        idata_cei := '1';                 -- latch input data (from SRAM)
314
        if REQ = '1' then                 -- if IO requested
315
          if WE = '1' then                  -- if WRITE requested
316
            iaddr_ce  := '1';                 -- latch address and be's
317
            idata_ceo := '1';                 -- latch output data
318
            idata_oe  := '1';                 -- oe FPGA next cycle
319
            imem_ce   := "11";                -- ce SRAM next cycle
320
            imem_be   := BE;                  -- use request BE's
321
            n.state := s_write1;              -- next: continue read
322
          else                              -- if READ requested
323
            iaddr_ce := '1';                  -- latch address and be's
324
            n.state := s_bta_w2r;             -- next: bus turn around cycle
325
          end if;
326
        else
327
          n.state := s_idle;              -- next: idle if nothing to do
328
        end if;
329
 
330
      when s_bta_r2w =>                 -- s_bta_r2w: bus turn around: r->w
331
        ibusy := '1';                     -- signal busy, unable to handle req
332
        iactw := '1';                     -- signal mem write
333
        imem_ce  := "11";                 -- ce SRAM next cycle
334
        idata_oe := '1';                  -- oe FPGA next cycle
335
        n.state := s_write1;              -- next: start write
336
 
337
      when s_bta_w2r =>                 -- s_bta_w2r: bus turn around: w->r
338
        ibusy := '1';                     -- signal busy, unable to handle req
339
        iactr := '1';                     -- signal mem read
340
        imem_ce := "11";                  -- ce SRAM next cycle
341
        imem_oe := '1';                   -- oe SRAM next cycle
342
        n.state := s_read;                -- next: start read
343
 
344
      when others => null;
345
    end case;
346
 
347
    N_REGS <= n;
348
 
349
    MEM_CE_N <= not imem_ce;
350
    MEM_WE_N <= not imem_we;
351
    MEM_BE_N <= not imem_be;
352
    MEM_OE_N <= not imem_oe;
353
    ADDR_CE  <= iaddr_ce;
354
    DATA_CEI <= idata_cei;
355
    DATA_CEO <= idata_ceo;
356
    DATA_OE  <= idata_oe;
357
 
358
    BUSY  <= ibusy;
359
    ACK_R <= r.ackr;
360
    ACK_W <= iackw;
361
    ACT_R <= iactr;
362
    ACT_W <= iactw;
363
 
364
  end process proc_next;
365
 
366
end syn;

powered by: WebSVN 2.1.0

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