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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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