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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [designs/] [leon3-altera-ep1c20/] [smc_mctrl.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
 
2
 
3
 
4
 
5
----------------------------------------------------------------------------
6
--  This file is a part of the LEON VHDL model
7
--  Copyright (C) 1999  European Space Agency (ESA)
8
--
9
--  This library is free software; you can redistribute it and/or
10
--  modify it under the terms of the GNU Lesser General Public
11
--  License as published by the Free Software Foundation; either
12
--  version 2 of the License, or (at your option) any later version.
13
--
14
--  See the file COPYING.LGPL for the full details of the license.
15
 
16
 
17
-----------------------------------------------------------------------------
18
-- Entity:      mctrl
19
-- File:        mctrl.vhd
20
-- Author:      Jiri Gaisler - ESA/ESTEC
21
-- Description: External memory controller.
22
------------------------------------------------------------------------------
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26
library grlib;
27
use grlib.amba.all;
28
use grlib.devices.all;
29
use grlib.stdlib.all;
30
library gaisler;
31
use gaisler.memctrl.all;
32
library esa;
33
use esa.memoryctrl.all;
34
 
35
entity smc_mctrl is
36
  generic (
37
    hindex    : integer := 0;
38
    pindex    : integer := 0;
39
    romaddr   : integer := 16#000#;
40
    rommask   : integer := 16#E00#;
41
    ioaddr    : integer := 16#200#;
42
    iomask    : integer := 16#E00#;
43
    ramaddr   : integer := 16#400#;
44
    rammask   : integer := 16#C00#;
45
    paddr     : integer := 0;
46
    pmask     : integer := 16#fff#;
47
    wprot     : integer := 0;
48
    invclk    : integer := 0;
49
    fast      : integer := 0;
50
    romasel   : integer := 28;
51
    sdrasel   : integer := 29;
52
    srbanks   : integer := 4;
53
    ram8      : integer := 0;
54
    ram16     : integer := 0;
55
    sden      : integer := 0;
56
    sepbus    : integer := 0;
57
    sdbits    : integer := 32;
58
    sdlsb     : integer := 2;          -- set to 12 for the GE-HPE board
59
    oepol     : integer := 0;
60
    syncrst   : integer := 0
61
  );
62
  port (
63
    rst       : in  std_ulogic;
64
    clk       : in  std_ulogic;
65
    memi      : in  memory_in_type;
66
    memo      : out memory_out_type;
67
    ahbsi     : in  ahb_slv_in_type;
68
    ahbso     : out ahb_slv_out_type;
69
    apbi      : in  apb_slv_in_type;
70
    apbo      : out apb_slv_out_type;
71
    wpo       : in  wprot_out_type;
72
    sdo       : out sdram_out_type;
73
    eth_aen   : out std_logic; -- for smsc eth
74
    eth_readn : out std_logic; -- for smsc eth
75
    eth_writen: out std_logic;  -- for smsc eth
76
    eth_nbe   : out std_logic_vector(3 downto 0) -- for smsc eth
77
  );
78
end;
79
 
80
architecture rtl of smc_mctrl is
81
 
82
constant REVISION  : integer := 0;
83
 
84
constant prom : integer := 1;
85
constant memory : integer := 0;
86
 
87
constant hconfig : ahb_config_type := (
88
 
89
  4 => ahb_membar(romaddr, '1', '1', rommask),
90
  5 => ahb_membar(ioaddr,  '0', '0', iomask),
91
  6 => ahb_membar(ramaddr, '1', '1', rammask),
92
  others => zero32);
93
 
94
constant pconfig : apb_config_type := (
95
 
96
  1 => apb_iobar(paddr, pmask));
97
 
98
constant RAMSEL5 : boolean := srbanks = 5;
99
constant SDRAMEN : boolean := (sden /= 0);
100
constant BUS16EN : boolean := (ram16 /= 0);
101
constant BUS8EN  : boolean := (ram8 /= 0);
102
constant WPROTEN : boolean := (wprot /= 0);
103
constant WENDFB  : boolean := false;
104
constant SDSEPBUS: boolean := (sepbus /= 0);
105
constant BUS64   : boolean := (sdbits = 64);
106
 
107
constant rom : integer := 0;
108
constant io  : integer := 1;
109
constant ram : integer := 2;
110
type memcycletype is (idle, berr, bread, bwrite, bread8, bwrite8, bread16, bwrite16);
111
 
112
-- memory configuration register 1 type
113
 
114
type mcfg1type is record
115
  romrws           : std_logic_vector(3 downto 0);
116
  romwws           : std_logic_vector(3 downto 0);
117
  romwidth         : std_logic_vector(1 downto 0);
118
  romwrite         : std_logic;
119
 
120
  ioen             : std_logic;
121
  iows             : std_logic_vector(3 downto 0);
122
  bexcen           : std_logic;
123
  brdyen           : std_logic;
124
  iowidth          : std_logic_vector(1 downto 0);
125
end record;
126
 
127
-- memory configuration register 2 type
128
 
129
type mcfg2type is record
130
  ramrws           : std_logic_vector(1 downto 0);
131
  ramwws           : std_logic_vector(1 downto 0);
132
  ramwidth         : std_logic_vector(1 downto 0);
133
  rambanksz        : std_logic_vector(3 downto 0);
134
  rmw              : std_logic;
135
  brdyen           : std_logic;
136
  srdis            : std_logic;
137
  sdren            : std_logic;
138
end record;
139
 
140
-- memory status register type
141
 
142
-- local registers
143
 
144
type reg_type is record
145
  address          : std_logic_vector(31 downto 0);  -- memory address
146
  data             : std_logic_vector(31 downto 0);  -- latched memory data
147
  writedata        : std_logic_vector(31 downto 0);
148
  writedata8       : std_logic_vector(15 downto 0);  -- lsb write data buffer
149
  sdwritedata      : std_logic_vector(63 downto 0);
150
  readdata         : std_logic_vector(31 downto 0);
151
  brdyn            : std_logic;
152
  ready            : std_logic;
153
  ready8           : std_logic;
154
  bdrive           : std_logic_vector(3 downto 0);
155
  nbdrive          : std_logic_vector(3 downto 0);
156
  ws               : std_logic_vector(3 downto 0);
157
  romsn            : std_logic_vector(1 downto 0);
158
  ramsn            : std_logic_vector(4 downto 0);
159
  ramoen           : std_logic_vector(4 downto 0);
160
  size             : std_logic_vector(1 downto 0);
161
  busw             : std_logic_vector(1 downto 0);
162
  oen              : std_logic;
163
  iosn             : std_logic_vector(1 downto 0);
164
  read             : std_logic;
165
  wrn              : std_logic_vector(3 downto 0);
166
  writen           : std_logic;
167
  bstate           : memcycletype;
168
  area             : std_logic_vector(0 to 2);
169
  mcfg1            : mcfg1type;
170
  mcfg2            : mcfg2type;
171
  bexcn            : std_logic;         -- latched external bexcn
172
  echeck           : std_logic;
173
  brmw             : std_logic;
174
  haddr            : std_logic_vector(31 downto 0);
175
  hsel             : std_logic;
176
  srhsel           : std_logic;
177
  hwrite           : std_logic;
178
  hburst           : std_logic_vector(2 downto 0);
179
  htrans           : std_logic_vector(1 downto 0);
180
  hresp            : std_logic_vector(1 downto 0);
181
  sa               : std_logic_vector(14 downto 0);
182
  sd               : std_logic_vector(63 downto 0);
183
  mben             : std_logic_vector(3 downto 0);
184
 
185
  eth_aen    : std_logic; -- for smsc eth
186
  eth_readn  : std_logic; -- for smsc eth
187
  eth_writen : std_logic; -- for smsc eth
188
  eth_nbe    : std_logic_vector(3 downto 0);-- for smsc eth
189
end record;
190
 
191
signal r, ri : reg_type;
192
signal wrnout : std_logic_vector(3 downto 0);
193
signal sdmo : sdram_mctrl_out_type;
194
signal sdi  : sdram_in_type;
195
 
196
-- vectored output enable to data pads 
197
signal rbdrive, ribdrive : std_logic_vector(31 downto 0);
198
signal rsbdrive, risbdrive : std_logic_vector(63 downto 0);
199
attribute syn_preserve : boolean;
200
attribute syn_preserve of rbdrive : signal is true;
201
attribute syn_preserve of rsbdrive : signal is true;
202
 
203
-- **** tame: added signal to invert polarity
204
-- signal bprom_cs : std_ulogic;
205
 
206
begin
207
 
208
  ctrl : process(rst, ahbsi, apbi, memi, r, wpo, sdmo, rbdrive, rsbdrive)
209
  variable v : reg_type;                -- local variables for registers
210
  variable start : std_logic;
211
  variable dataout : std_logic_vector(31 downto 0); -- data from memory
212
  variable regsd : std_logic_vector(31 downto 0);   -- data from registers
213
  variable memdata : std_logic_vector(31 downto 0);   -- data to memory
214
  variable rws : std_logic_vector(3 downto 0);           -- read waitstates
215
  variable wws : std_logic_vector(3 downto 0);           -- write waitstates
216
  variable wsnew : std_logic_vector(3 downto 0);         -- write waitstates
217
  variable adec : std_logic_vector(1 downto 0);
218
  variable rams : std_logic_vector(4 downto 0);
219
  variable bready, leadin : std_logic;
220
  variable csen : std_logic;                    -- Generate chip selects
221
  variable aprot   : std_logic_vector(14 downto 0); --
222
  variable wrn   : std_logic_vector(3 downto 0); --
223
  variable bexc, addrerr : std_logic;
224
  variable ready : std_logic;
225
  variable writedata : std_logic_vector(31 downto 0);
226
  variable bwdata : std_logic_vector(31 downto 0);
227
  variable merrtype  : std_logic_vector(2 downto 0); -- memory error type
228
  variable noerror : std_logic;
229
  variable area  : std_logic_vector(0 to 2);
230
  variable bdrive : std_logic_vector(3 downto 0);
231
  variable ramsn : std_logic_vector(4 downto 0);
232
  variable romsn, busw : std_logic_vector(1 downto 0);
233
  variable iosn : std_logic;
234
  variable lock : std_logic;
235
  variable wprothitx : std_logic;
236
  variable brmw : std_logic;
237
  variable bidle: std_logic;
238
  variable haddr   : std_logic_vector(31 downto 0);
239
  variable hsize   : std_logic_vector(1 downto 0);
240
  variable hwrite  : std_logic;
241
  variable hburst  : std_logic_vector(2 downto 0);
242
  variable htrans  : std_logic_vector(1 downto 0);
243
  variable sdhsel, srhsel, hready  : std_logic;
244
  variable vbdrive : std_logic_vector(31 downto 0);
245
  variable vsbdrive : std_logic_vector(63 downto 0);
246
  variable bdrive_sel : std_logic_vector(3 downto 0);
247
  begin
248
 
249
-- Variable default settings to avoid latches
250
 
251
    v := r; wprothitx := '0'; v.ready8 := '0'; v.iosn(0) := r.iosn(1);
252
 
253
    ready := '0'; addrerr := '0'; regsd := (others => '0'); csen := '0';
254
 
255
    v.ready := '0'; v.echeck := '0';
256
    merrtype := "---"; bready := '1';
257
 
258
    vbdrive := rbdrive; vsbdrive := rsbdrive;
259
 
260
    v.data := memi.data; v.bexcn := memi.bexcn; v.brdyn := memi.brdyn;
261
    if (((r.brdyn and r.mcfg1.brdyen) = '1') and (r.area(io) = '1')) or
262
       (((r.brdyn and r.mcfg2.brdyen) = '1') and (r.area(ram) = '1') and
263
         (r.ramsn(4) = '0') and RAMSEL5)
264
    then
265
      bready := '0';
266
    else bready := '1'; end if;
267
 
268
    v.hresp := HRESP_OKAY;
269
 
270
    if SDRAMEN and (r.hsel = '1') and (ahbsi.hready = '0') then
271
      haddr := r.haddr;  hsize := r.size; hburst := r.hburst;
272
      htrans := r.htrans; hwrite := r.hwrite;
273
      area := r.area;
274
    else
275
      haddr := ahbsi.haddr;  hsize := ahbsi.hsize(1 downto 0);
276
      hburst := ahbsi.hburst; htrans := ahbsi.htrans; hwrite := ahbsi.hwrite;
277
      area := ahbsi.hmbsel(0 to 2);
278
    end if;
279
 
280
    if SDRAMEN then
281
      if fast = 1 then
282
        sdhsel := ahbsi.hsel(hindex) and ahbsi.haddr(sdrasel) and
283
           ahbsi.htrans(1) and ahbsi.hmbsel(2);
284
      else
285
        sdhsel := ahbsi.hsel(hindex) and ahbsi.htrans(1) and
286
          r.mcfg2.sdren and ahbsi.hmbsel(2) and (ahbsi.haddr(sdrasel) or r.mcfg2.srdis);
287
      end if;
288
      srhsel := ahbsi.hsel(hindex) and not sdhsel;
289
    else  sdhsel := '0'; srhsel := ahbsi.hsel(hindex); end if;
290
 
291
-- decode memory area parameters
292
 
293
    leadin := '0'; rws := "----"; wws := "----"; adec := "--";
294
    busw := (others => '-'); brmw := '0';
295
    if area(rom) = '1' then
296
      busw := r.mcfg1.romwidth;
297
    end if;
298
    if area(ram) = '1' then
299
      adec := genmux(r.mcfg2.rambanksz, haddr(sdrasel downto 14)) &
300
              genmux(r.mcfg2.rambanksz, haddr(sdrasel-1 downto 13));
301
 
302
      if sdhsel = '1' then busw := "10";
303
 
304
      else
305
        busw := r.mcfg2.ramwidth;
306
        if ((r.mcfg2.rmw and hwrite) = '1') and
307
         ((BUS16EN and (busw = "01") and (hsize = "00")) or
308
          ((busw(1) = '1') and (hsize(1) = '0'))
309
 
310
        )
311
        then brmw := '1'; end if;        -- do a read-modify-write cycle
312
      end if;
313
    end if;
314
    if area(io) = '1' then
315
      leadin := '1';
316
      busw := r.mcfg1.iowidth;
317
    end if;
318
 
319
-- decode waitstates, illegal access and cacheability
320
 
321
    if r.area(rom) = '1' then
322
      rws := r.mcfg1.romrws; wws := r.mcfg1.romwws;
323
      if (r.mcfg1.romwrite or r.read) = '0' then addrerr := '1'; end if;
324
    end if;
325
    if r.area(ram) = '1' then
326
      rws := "00" & r.mcfg2.ramrws; wws := "00" & r.mcfg2.ramwws;
327
    end if;
328
    if r.area(io) = '1' then
329
      rws := r.mcfg1.iows; wws := r.mcfg1.iows;
330
      if r.mcfg1.ioen = '0' then addrerr := '1'; end if;
331
    end if;
332
 
333
-- generate data buffer enables
334
 
335
    bdrive := (others => '1');
336
    case r.busw is
337
    when "00" => if BUS8EN then bdrive := "0001"; end if;
338
    when "01" => if BUS16EN then bdrive := "0011"; end if;
339
    when others =>
340
    end case;
341
 
342
-- generate chip select and output enable
343
 
344
    rams := '0' & decode(adec);
345
    case srbanks is
346
    when 0 => rams := "00000";
347
    when 1 => rams := "00001";
348
    when 2 => rams := "000" & (rams(3 downto 2) or rams(1 downto 0));
349
    when others =>
350
      if RAMSEL5 and (haddr(sdrasel) = '1') then rams := "10000"; end if;
351
    end case;
352
 
353
    iosn := '1'; ramsn := (others => '1'); romsn := (others => '1');
354
    if area(rom) = '1' then
355
      romsn := (not haddr(romasel)) & haddr(romasel);
356
    end if;
357
    if area(ram) = '1' then ramsn := not rams; end if;
358
    if area(io) = '1' then iosn := '0'; end if;
359
 
360
-- generate write strobe
361
 
362
    wrn := "0000";
363
    case r.busw is
364
    when "00" =>
365
      if BUS8EN then wrn := "1110"; end if;
366
    when "01" =>
367
      if BUS16EN then
368
        if (r.size = "00") and (r.brmw = '0') then
369
          wrn := "11" & (not r.address(0)) & r.address(0);
370
        else wrn := "1100"; end if;
371
      end if;
372
    when "10" | "11" =>
373
      case r.size is
374
      when "00" =>
375
        case r.address(1 downto 0) is
376
        when "00" => wrn := "1110";
377
        when "01" => wrn := "1101";
378
        when "10" => wrn := "1011";
379
        when others => wrn := "0111";
380
        end case;
381
      when "01" =>
382
        wrn := not r.address(1) & not r.address(1) & r.address(1) & r.address(1);
383
      when others => null;
384
      end case;
385
    when others => null;
386
    end case;
387
 
388
    if (r.mcfg2.rmw = '1') and (r.area(ram) = '1') then wrn := not bdrive; end if;
389
 
390
    if (((ahbsi.hready and ahbsi.hsel(hindex) and ahbsi.htrans(1)) = '1') or (((sdmo.aload and r.hsel) = '1') and SDRAMEN))
391
    then
392
      v.area := area;
393
      v.address  := haddr;
394
      if (busw = "00") and (hwrite = '0') and (area(io) = '0') and BUS8EN
395
      then v.address(1 downto 0) := "00"; end if;
396
      if (busw = "01") and (hwrite = '0') and (area(io) = '0') and BUS16EN
397
      then v.address(1 downto 0) := "00"; end if;
398
      if (brmw = '1') then
399
        v.read := '1';
400
 
401
      else v.read := not hwrite; end if;
402
      v.busw := busw; v.brmw := brmw;
403
 
404
    end if;
405
 
406
-- Select read data depending on bus width
407
 
408
    if BUS8EN and (r.busw = "00") then
409
      memdata := r.readdata(23 downto 0) & r.data(31 downto 24);
410
    elsif BUS16EN and (r.busw = "01") then
411
      memdata := r.readdata(15 downto 0) & r.data(31 downto 16);
412
    else
413
      memdata := r.data;
414
    end if;
415
 
416
    bwdata := memdata;
417
 
418
-- Merge data during byte write
419
 
420
    writedata := ahbsi.hwdata;
421
    if ((r.brmw and r.busw(1)) = '1')
422
 
423
    then
424
      case r.address(1 downto 0) is
425
 
426
      when "00" =>
427
        writedata(15 downto 0) := bwdata(15 downto 0);
428
        if r.size = "00" then
429
          writedata(23 downto 16) := bwdata(23 downto 16);
430
        end if;
431
      when "01" =>
432
        writedata(31 downto 24) := bwdata(31 downto 24);
433
        writedata(15 downto 0) := bwdata(15 downto 0);
434
      when "10" =>
435
        writedata(31 downto 16) := bwdata(31 downto 16);
436
        if r.size = "00" then
437
          writedata(7 downto 0) := bwdata(7 downto 0);
438
        end if;
439
      when  others =>
440
        writedata(31 downto 8) := bwdata(31 downto 8);
441
      end case;
442
    end if;
443
    if (r.brmw = '1') and (r.busw = "01") and BUS16EN then
444
      if (r.address(0) = '0') then
445
        writedata(23 downto 16) :=  r.data(23 downto 16);
446
      else
447
        writedata(31 downto 24) :=  r.data(31 downto 24);
448
      end if;
449
    end if;
450
 
451
-- save read data during 8/16 bit reads
452
 
453
    if BUS8EN and (r.ready8 = '1') and (r.busw = "00") then
454
      v.readdata := v.readdata(23 downto 0) & r.data(31 downto 24);
455
    elsif BUS16EN and (r.ready8 = '1') and (r.busw = "01") then
456
      v.readdata := v.readdata(15 downto 0) & r.data(31 downto 16);
457
    end if;
458
 
459
-- Ram, rom, IO access FSM
460
 
461
    if r.read = '1' then wsnew := rws; else wsnew := wws; end if;
462
 
463
    case r.bstate is
464
    when idle =>
465
      v.ws := wsnew;
466
 
467
      if r.bdrive(0) = '1' then
468
 
469
        if r.busw(1) = '1' then v.writedata := writedata;
470
        else
471
          v.writedata(31 downto 16) := writedata(31 downto 16);
472
          v.writedata8 := writedata(15 downto 0);
473
        end if;
474
 
475
      end if;
476
      if (r.srhsel = '1') and ((sdmo.busy = '0') or not SDRAMEN)
477
 
478
      then
479
        if WPROTEN then wprothitx := wpo.wprothit; end if;
480
        if (wprothitx or addrerr) = '1' then
481
          v.hresp := HRESP_ERROR; v.bstate := berr; v.bdrive := (others => '1');
482
        elsif r.read = '0' then
483
          if (r.busw = "00") and (r.area(io) = '0') and BUS8EN then
484
            v.bstate := bwrite8;
485
          elsif (r.busw = "01") and (r.area(io) = '0') and BUS16EN then
486
            v.bstate := bwrite16;
487
          else v.bstate := bwrite; end if;
488
          v.wrn := wrn; v.writen := '0'; v.bdrive := not bdrive;
489
        else
490
          if r.oen = '1' then v.ramoen := r.ramsn; v.oen := '0';
491
          else
492
            if (r.busw = "00") and (r.area(io) = '0') and BUS8EN then v.bstate := bread8;
493
            elsif (r.busw = "01") and (r.area(io) = '0') and BUS16EN then v.bstate := bread16;
494
            else v.bstate := bread; end if;
495
          end if;
496
        end if;
497
      end if;
498
    when berr =>
499
      v.bstate := idle; ready := '1';
500
      v.hresp := HRESP_ERROR;
501
      v.ramsn := (others => '1'); v.romsn := (others => '1');
502
      v.ramoen := (others => '1'); v.oen := '1'; v.iosn := "11"; v.bdrive := (others => '1');
503
    when bread =>
504
      if ((r.ws = "0000") and (r.ready = '0') and (bready = '1'))
505
      then
506
        if r.brmw = '0' then
507
          ready := '1'; v.address := ahbsi.haddr; v.echeck := '1';
508
        end if;
509
        if (((ahbsi.hsel(hindex) = '0') or (ahbsi.htrans /= HTRANS_SEQ)) or (r.hburst = HBURST_SINGLE))
510
        then
511
          v.ramoen := (others => '1'); v.oen := '1'; v.iosn := "11";
512
          v.bstate := idle; v.read := not r.hwrite;
513
          if r.brmw = '0' then
514
            v.ramsn := (others => '1'); v.romsn := (others => '1');
515
          else
516
            v.echeck := '1';
517
          end if;
518
        end if;
519
      end if;
520
      if r.ready = '1' then
521
        v.ws := rws;
522
      else
523
        if r.ws /= "0000" then v.ws := r.ws - 1; end if;
524
      end if;
525
    when bwrite =>
526
      if (r.ws = "0000") and (bready = '1') then
527
        ready := '1'; v.wrn := (others => '1'); v.writen := '1'; v.echeck := '1';
528
        v.ramsn := (others => '1'); v.romsn := (others => '1'); v.iosn := "11";
529
        v.bdrive := (others => '1'); v.bstate := idle;
530
      end if;
531
      if r.ws /= "0000" then v.ws := r.ws - 1; end if;
532
    when bread8 =>
533
      if BUS8EN then
534
        if (r.ws = "0000") and (r.ready8 = '0') and (bready = '1') then
535
          v.ready8 := '1'; v.ws := rws;
536
          v.address(1 downto 0) := r.address(1 downto 0) + 1;
537
 
538
          if (r.address(1 downto 0) = "11") then
539
            ready := '1'; v.address := ahbsi.haddr; v.echeck := '1';
540
 
541
            if (((ahbsi.hsel(hindex) = '0') or (ahbsi.htrans /= HTRANS_SEQ)) or
542
                (r.hburst = HBURST_SINGLE))
543
            then
544
              v.ramoen := (others => '1'); v.oen := '1'; v.iosn := "11";
545
              v.bstate := idle;
546
 
547
              v.ramsn := (others => '1'); v.romsn := (others => '1');
548
 
549
            end if;
550
          end if;
551
        end if;
552
        if (r.ready8 = '1') then v.ws := rws;
553
        elsif r.ws /= "0000" then v.ws := r.ws - 1; end if;
554
      else
555
        v.bstate := idle;
556
      end if;
557
    when bwrite8 =>
558
      if BUS8EN then
559
        if (r.ws = "0000") and (r.ready8 = '0') and (bready = '1') then
560
          v.ready8 := '1'; v.wrn := (others => '1'); v.writen := '1';
561
        end if;
562
 
563
        if (r.ws = "0000") and (bready = '1') and
564
           ((r.address(1 downto 0) = "11") or
565
            ((r.address(1 downto 0) = "01") and (r.size = "01")) or
566
            (r.size = "00"))
567
 
568
        then
569
          ready := '1'; v.wrn := (others => '1'); v.writen := '1'; v.echeck := '1';
570
          v.ramsn := (others => '1'); v.romsn := (others => '1'); v.iosn := "11";
571
          v.bdrive := (others => '1'); v.bstate := idle;
572
 
573
        end if;
574
        if (r.ready8 = '1') then
575
          v.address(1 downto 0) := r.address(1 downto 0) + 1; v.ws := rws;
576
          v.writedata(31 downto 16) := r.writedata(23 downto 16) & r.writedata8(15 downto 8);
577
          v.writedata8(15 downto 8) := r.writedata8(7 downto 0);
578
          v.bstate := idle;
579
 
580
        end if;
581
        if r.ws /= "0000" then v.ws := r.ws - 1; end if;
582
      else
583
        v.bstate := idle;
584
      end if;
585
    when bread16 =>
586
      if BUS16EN then
587
        if (r.ws = "0000") and (bready = '1') and ((r.address(1) or r.brmw) = '1') and
588
           (r.ready8 = '0')
589
        then
590
          if r.brmw = '0' then
591
            ready := '1'; v.address := ahbsi.haddr; v.echeck := '1';
592
          end if;
593
          if (((ahbsi.hsel(hindex) = '0') or (ahbsi.htrans /= HTRANS_SEQ)) or
594
              (r.hburst = HBURST_SINGLE))
595
          then
596
            if r.brmw = '0' then
597
              v.ramsn := (others => '1'); v.romsn := (others => '1');
598
            end if;
599
            v.ramoen := (others => '1'); v.oen := '1'; v.iosn := "11";
600
            v.bstate := idle; v.read := not r.hwrite;
601
          end if;
602
        end if;
603
        if (r.ws = "0000") and (bready = '1') and (r.ready8 = '0') then
604
          v.ready8 := '1'; v.ws := rws;
605
          if r.brmw = '0' then v.address(1) := not r.address(1); end if;
606
        end if;
607
        if r.ws /= "0000" then v.ws := r.ws - 1; end if;
608
      else
609
        v.bstate := idle;
610
      end if;
611
    when bwrite16 =>
612
      if BUS16EN then
613
        if (r.ws = "0000") and (bready = '1') and
614
           ((r.address(1 downto 0) = "10") or (r.size(1) = '0'))
615
        then
616
          ready := '1'; v.wrn := (others => '1'); v.writen := '1'; v.echeck := '1';
617
          v.ramsn := (others => '1'); v.romsn := (others => '1'); v.iosn := "11";
618
          v.bdrive := (others => '1'); v.bstate := idle;
619
        end if;
620
        if (r.ws = "0000") and (bready = '1') and (r.ready8 = '0') then
621
          v.ready8 := '1'; v.wrn := (others => '1'); v.writen := '1';
622
        end if;
623
        if (r.ready8 = '1') then
624
          v.address(1) := not r.address(1); v.ws := rws;
625
          v.writedata(31 downto 16) := r.writedata8(15 downto 0);
626
          v.bstate := idle;
627
        end if;
628
        if r.ws /= "0000" then v.ws := r.ws - 1; end if;
629
      else
630
        v.bstate := idle;
631
      end if;
632
    when others =>
633
    end case;
634
 
635
-- if BUSY or IDLE cycle seen, or if de-selected, return to idle state
636
    if (ahbsi.hready = '1') then
637
      if ((ahbsi.hsel(hindex) = '0') or (ahbsi.htrans = HTRANS_BUSY) or
638
        (ahbsi.htrans = HTRANS_IDLE))
639
      then
640
        v.bstate := idle;
641
        v.ramsn := (others => '1'); v.romsn := (others => '1');
642
        v.ramoen := (others => '1'); v.oen := '1'; v.iosn := "11";
643
        v.bdrive := (others => '1'); v.wrn := (others => '1');
644
        v.writen := '1'; v.hsel := '0'; ready := ahbsi.hsel(hindex); v.srhsel := '0';
645
      elsif srhsel = '1' then
646
        v.romsn := romsn; v.ramsn(4 downto 0) := ramsn(4 downto 0); v.iosn := iosn & '1';
647
        if v.read = '1' then v.ramoen(4 downto 0) := ramsn(4 downto 0); v.oen := leadin; end if;
648
      end if;
649
    end if;
650
 
651
-- error checking and reporting
652
 
653
    noerror := '1';
654
    if ((r.echeck and r.mcfg1.bexcen and not r.bexcn) = '1') then
655
      noerror := '0'; v.bstate := berr; v.hresp := HRESP_ERROR; v.bdrive := (others => '1');
656
    end if;
657
 
658
-- APB register access
659
 
660
    case apbi.paddr(3 downto 2) is
661
    when "00" =>
662
      regsd(28 downto 0) := r.mcfg1.iowidth &
663
        r.mcfg1.brdyen & r.mcfg1.bexcen & "0" & r.mcfg1.iows & r.mcfg1.ioen &
664
        '0' &
665
 
666
        "000000" & r.mcfg1.romwrite &
667
 
668
        '0' & r.mcfg1.romwidth & r.mcfg1.romwws & r.mcfg1.romrws;
669
    when "01" =>
670
      if SDRAMEN then
671
        regsd(31 downto 19) := sdmo.prdata(31 downto 19);
672
        if BUS64 then regsd(18) := '1'; end if;
673
        regsd(14 downto 13) := r.mcfg2.sdren & r.mcfg2.srdis;
674
      end if;
675
      regsd(12 downto 9) := r.mcfg2.rambanksz;
676
      if RAMSEL5 then regsd(7) := r.mcfg2.brdyen; end if;
677
      regsd(6 downto 0) := r.mcfg2.rmw & r.mcfg2.ramwidth &
678
        r.mcfg2.ramwws & r.mcfg2.ramrws;
679
    when "10" =>
680
 
681
      if SDRAMEN then
682
        regsd(26 downto 12) := sdmo.prdata(26 downto 12);
683
      end if;
684
    when others => regsd := (others => '0');
685
    end case;
686
 
687
    apbo.prdata <= regsd;
688
 
689
    if (apbi.psel(pindex) and apbi.penable and apbi.pwrite) = '1' then
690
      case apbi.paddr(5 downto 2) is
691
      when "0000" =>
692
        v.mcfg1.romrws      :=  apbi.pwdata(3 downto 0);
693
        v.mcfg1.romwws      :=  apbi.pwdata(7 downto 4);
694
        v.mcfg1.romwidth    :=  apbi.pwdata(9 downto 8);
695
        v.mcfg1.romwrite    :=  apbi.pwdata(11);
696
 
697
        v.mcfg1.ioen        :=  apbi.pwdata(19);
698
        v.mcfg1.iows        :=  apbi.pwdata(23 downto 20);
699
        v.mcfg1.bexcen      :=  apbi.pwdata(25);
700
        v.mcfg1.brdyen      :=  apbi.pwdata(26);
701
        v.mcfg1.iowidth     :=  apbi.pwdata(28 downto 27);
702
      when "0001" =>
703
        v.mcfg2.ramrws      := apbi.pwdata(1 downto 0);
704
        v.mcfg2.ramwws      := apbi.pwdata(3 downto 2);
705
        v.mcfg2.ramwidth    := apbi.pwdata(5 downto 4);
706
        v.mcfg2.rmw         := apbi.pwdata(6);
707
        v.mcfg2.brdyen      := apbi.pwdata(7);
708
        v.mcfg2.rambanksz   := apbi.pwdata(12 downto 9);
709
        if SDRAMEN then
710
          v.mcfg2.srdis     := apbi.pwdata(13);
711
          v.mcfg2.sdren     := apbi.pwdata(14);
712
        end if;
713
 
714
      when others => null;
715
      end case;
716
    end if;
717
 
718
-- select appropriate data during reads
719
 
720
    if (r.area(rom) or r.area(ram)) = '1' then dataout := memdata;
721
    else
722
      if BUS8EN and (r.busw = "00") then
723
        dataout := r.data(31 downto 24) & r.data(31 downto 24)
724
                 & r.data(31 downto 24) & r.data(31 downto 24);
725
      elsif BUS16EN and (r.busw = "01") then
726
        dataout := r.data(31 downto 16) & r.data(31 downto 16);
727
      else dataout := r.data; end if;
728
    end if;
729
 
730
    v.ready := ready;
731
    v.srhsel := r.srhsel and not ready;
732
    if ahbsi.hready = '1' then v.hsel := ahbsi.hsel(hindex); end if;
733
 
734
    if ((ahbsi.hready and ahbsi.hsel(hindex)) = '1') then
735
      v.size := ahbsi.hsize(1 downto 0); v.hwrite := ahbsi.hwrite;
736
      v.hburst := ahbsi.hburst; v.htrans := ahbsi.htrans;
737
      if ahbsi.htrans(1) = '1' then v.hsel := '1'; v.srhsel := srhsel; end if;
738
      if SDRAMEN then
739
        v.haddr := ahbsi.haddr;
740
      end if;
741
    end if;
742
 
743
-- sdram synchronisation
744
 
745
    if SDRAMEN then
746
      v.sa := sdmo.address; v.sd := memi.sd;
747
      if (r.bstate /= idle) then bidle := '0';
748
      else
749
        bidle := '1';
750
        if (sdmo.busy and not sdmo.aload) = '1' then
751
          if not SDSEPBUS then
752
            v.address(sdlsb + 14 downto sdlsb) := sdmo.address;
753
          end if;
754
          v.romsn := (others => '1'); v.ramsn(4 downto 0) := (others => '1');
755
          v.iosn := (others =>'1'); v.ramoen(4 downto 0) := (others => '1');
756
          v.oen := '1';
757
          v.bdrive := not (sdmo.bdrive & sdmo.bdrive & sdmo.bdrive & sdmo.bdrive);
758
          v.hresp := sdmo.hresp;
759
        end if;
760
      end if;
761
      if (sdmo.aload and r.srhsel) = '1' then
762
        v.romsn := romsn; v.ramsn(4 downto 0) := ramsn(4 downto 0); v.iosn := iosn & '1';
763
        if v.read = '1' then v.ramoen(4 downto 0) := ramsn(4 downto 0); v.oen := leadin; end if;
764
      end if;
765
      if sdmo.hsel = '1' then
766
        v.writedata := writedata;
767
        v.sdwritedata(31 downto 0) := writedata;
768
        if BUS64 and sdmo.bsel = '1' then
769
          v.sdwritedata(63 downto 32) := writedata;
770
        end if;
771
        hready := sdmo.hready and noerror and not r.brmw;
772
        if SDSEPBUS then
773
          if BUS64 and sdmo.bsel = '1' then dataout := r.sd(63 downto 32);
774
          else dataout := r.sd(31 downto 0); end if;
775
        end if;
776
      else hready := r.ready and noerror; end if;
777
    else
778
      hready := r.ready and noerror;
779
    end if;
780
 
781
    if v.read = '1' then v.mben := "0000"; else v.mben := v.wrn; end if;
782
 
783
    v.nbdrive := not v.bdrive;
784
 
785
    if oepol = 0 then
786
      bdrive_sel := r.bdrive;
787
      vbdrive(31 downto 24) := (others => v.bdrive(0));
788
      vbdrive(23 downto 16) := (others => v.bdrive(1));
789
      vbdrive(15 downto 8) := (others => v.bdrive(2));
790
      vbdrive(7 downto 0) := (others => v.bdrive(3));
791
 
792
      vsbdrive(31 downto 24) := (others => v.bdrive(0));
793
      vsbdrive(23 downto 16) := (others => v.bdrive(1));
794
      vsbdrive(15 downto 8) := (others => v.bdrive(2));
795
      vsbdrive(7 downto 0) := (others => v.bdrive(3));
796
 
797
      vsbdrive(63 downto 56) := (others => v.bdrive(0));
798
      vsbdrive(55 downto 48) := (others => v.bdrive(1));
799
      vsbdrive(47 downto 40) := (others => v.bdrive(2));
800
      vsbdrive(39 downto 32) := (others => v.bdrive(3));
801
    else
802
      bdrive_sel := r.nbdrive;
803
      vbdrive(31 downto 24) := (others => v.nbdrive(0));
804
      vbdrive(23 downto 16) := (others => v.nbdrive(1));
805
      vbdrive(15 downto 8) := (others => v.nbdrive(2));
806
      vbdrive(7 downto 0) := (others => v.nbdrive(3));
807
 
808
      vsbdrive(31 downto 24) := (others => v.nbdrive(0));
809
      vsbdrive(23 downto 16) := (others => v.nbdrive(1));
810
      vsbdrive(15 downto 8) := (others => v.nbdrive(2));
811
      vsbdrive(7 downto 0) := (others => v.nbdrive(3));
812
 
813
      vsbdrive(63 downto 56) := (others => v.nbdrive(0));
814
      vsbdrive(55 downto 48) := (others => v.nbdrive(1));
815
      vsbdrive(47 downto 40) := (others => v.nbdrive(2));
816
      vsbdrive(39 downto 32) := (others => v.nbdrive(3));
817
    end if;
818
 
819
-- for smc lan chip ********************************************
820
    if (r.iosn(0) = '1' and v.iosn(0) = '0') then
821
       v.eth_aen := '0';
822
       v.eth_nbe := v.wrn and not (r.read&r.read&r.read&r.read);
823
    elsif (r.iosn(0) = '1' and r.eth_aen = '0') then
824
       v.eth_aen := '1';
825
       v.eth_nbe := v.wrn;
826
    end if;
827
 
828
    if (r.eth_aen = '0' and v.iosn(0) = '0' and r.read = '1') then
829
       v.eth_readn := '0';
830
    else
831
       v.eth_readn := '1';
832
    end if;
833
 
834
    if (r.eth_aen = '0' and v.iosn(0) = '0' and r.writen = '0') then
835
       v.eth_writen := '0';
836
    else
837
       v.eth_writen := '1';
838
    end if;
839
-- *************************************************************
840
 
841
-- reset
842
 
843
    if rst = '0' then
844
 
845
      v.bstate           := idle;
846
      v.read             := '1';
847
      v.wrn              := "1111";
848
      v.writen           := '1';
849
      v.mcfg1.romwrite   := '0';
850
      v.mcfg1.ioen       := '0';
851
      v.mcfg1.brdyen     := '0';
852
      v.mcfg1.bexcen     := '0';
853
      v.hsel             := '0';
854
      v.srhsel           := '0';
855
      v.ready            := '1';
856
      v.mcfg1.iows       := "0000";
857
      v.mcfg2.ramrws     := "00";
858
      v.mcfg2.ramwws     := "00";
859
      v.mcfg1.romrws     := "1111";
860
      v.mcfg1.romwws     := "1111";
861
      v.mcfg1.romwidth   := memi.bwidth;
862
      v.mcfg2.srdis      := '0';
863
      v.mcfg2.sdren      := '0';
864
 
865
      v.eth_aen      := '1'; -- for smsc eth
866
      v.eth_readn    := '1'; -- for smsc eth
867
      v.eth_writen   := '1'; -- for smsc eth
868
      v.eth_nbe      := (others => '1'); -- for smsc eth
869
 
870
      if syncrst = 1 then
871
        v.ramsn := (others => '1'); v.romsn := (others => '1');
872
        v.oen := '1'; v.iosn := "11"; v.ramoen := (others => '1');
873
        v.bdrive := (others => '1'); v.nbdrive := (others => '0');
874
        if oepol = 0 then vbdrive := (others => '1'); vsbdrive := (others => '1');
875
        else vbdrive := (others => '0'); vsbdrive := (others => '0'); end if;
876
      end if;
877
    end if;
878
 
879
-- optional feeb-back from write stobe to data bus drivers
880
 
881
    if WENDFB then bdrive := r.bdrive and memi.wrn;
882
    else bdrive := r.bdrive; end if;
883
 
884
-- pragma translate_off
885
    for i in dataout'range loop --'
886
      if is_x(dataout(i)) then dataout(i) := '1'; end if;
887
    end loop;
888
-- pragma translate_on
889
 
890
 
891
-- drive various register inputs and external outputs
892
 
893
    ri <= v;
894
 
895
    ribdrive <= vbdrive;
896
    risbdrive <= vsbdrive;
897
 
898
    ahbso.hcache <= not r.area(io);
899
    memo.address <= r.address;
900
    memo.sa <= r.sa;
901
    memo.ramsn          <= "111" & r.ramsn;
902
    memo.ramoen         <= "111" & r.ramoen;
903
    memo.romsn          <= "111111" & r.romsn;
904
    memo.oen            <= r.oen;
905
    memo.iosn           <= r.iosn(0);
906
    memo.read           <= r.read;
907
    memo.wrn            <= r.wrn;
908
    memo.writen         <= r.writen;
909
    memo.bdrive         <= bdrive;
910
    memo.data           <= r.writedata;
911
    memo.sddata(31 downto 0)  <= r.sdwritedata(31 downto 0);
912
    memo.sddata(63 downto 32) <= r.sdwritedata(63 downto 32);
913
    memo.mben           <= r.mben;
914
    memo.vbdrive        <= rbdrive;
915
    memo.svbdrive       <= rsbdrive;
916
    sdi.idle            <= bidle;
917
    sdi.haddr           <= haddr;
918
    sdi.rhaddr          <= r.haddr;
919
    sdi.nhtrans         <= htrans;
920
    sdi.rhtrans         <= r.htrans;
921
    sdi.htrans          <= ahbsi.htrans;
922
    sdi.hready          <= ahbsi.hready;
923
    sdi.hsize           <= r.size;
924
    sdi.hwrite          <= r.hwrite;
925
    sdi.hsel            <= sdhsel;
926
    sdi.enable          <= r.mcfg2.sdren;
927
    sdi.srdis           <= r.mcfg2.srdis;
928
 
929
    ahbso.hrdata <= dataout;
930
    ahbso.hready <= hready;
931
    ahbso.hresp  <= r.hresp;
932
 
933
    -- for smsc eth
934
    eth_aen    <= r.eth_aen;
935
    eth_readn  <= r.eth_readn;
936
    eth_writen <= r.eth_writen;
937
    eth_nbe    <= r.eth_nbe;
938
 
939
  end process;
940
 
941
  stdregs : process(clk,rst)
942
  begin
943
    if rising_edge(clk) then
944
      r <= ri; rbdrive <= ribdrive; rsbdrive <= risbdrive;
945
      if rst = '0' then r.ws <= (others => '0'); end if;
946
    end if;
947
    if (syncrst = 0) and (rst = '0') then
948
      r.ramsn <= (others => '1'); r.romsn <= (others => '1');
949
      r.oen <= '1'; r.iosn <= "11"; r.ramoen <= (others => '1');
950
      r.bdrive <= (others => '1'); r.nbdrive <= (others => '0');
951
      if oepol = 0 then rbdrive <= (others => '1'); rsbdrive <= (others => '1');
952
      else rbdrive <= (others => '0'); rsbdrive <= (others => '0'); end if;
953
    end if;
954
  end process;
955
 
956
  ahbso.hsplit <= (others => '0');
957
  ahbso.hconfig <= hconfig;
958
  ahbso.hirq    <= (others => '0');
959
  ahbso.hindex <= hindex;
960
  apbo.pconfig  <= pconfig;
961
  apbo.pirq     <= (others => '0');
962
  apbo.pindex   <= pindex;
963
 
964
-- optional sdram controller
965
 
966
  sd0 : if SDRAMEN generate
967
    sdctrl : sdmctrl generic map (pindex, invclk, fast, wprot, sdbits)
968
        port map ( rst => rst, clk => clk, sdi => sdi,
969
        sdo => sdo, apbi => apbi, wpo => wpo, sdmo => sdmo);
970
  end generate;
971
  sd1 : if not SDRAMEN generate
972
        sdo <= ("00", "11", '1', '1', '1', "11111111");
973
        sdmo.address <= (others => '0'); sdmo.busy <= '0';
974
        sdmo.aload <= '0'; sdmo.bdrive <= '0'; sdmo.hready <= '1';
975
        sdmo.hresp <= "11"; sdmo.prdata <= (others => '0');
976
 
977
  end generate;
978
 
979
end;
980
 

powered by: WebSVN 2.1.0

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