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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [gaisler/] [misc/] [wild2ahb.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
------------------------------------------------------------------------------
2
--  This file is a part of the GRLIB VHDL IP LIBRARY
3
--  Copyright (C) 2003, Gaisler Research
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  This program is distributed in the hope that it will be useful,
11
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--  GNU General Public License for more details.
14
--
15
--  You should have received a copy of the GNU General Public License
16
--  along with this program; if not, write to the Free Software
17
--  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
18
--============================================================================--
19
-- Design unit  : WildCard CardBus to AMBA interface (entity and architecture)
20
--
21
-- File name    : wild2ahb.vhd
22
--
23
-- Purpose      : WildCard CardBus to AMBA interface
24
--
25
-- Library      : gaisler
26
--
27
-- Authors      : Mr Sandi Alexander Habinc
28
--                Gaisler Research
29
--
30
-- Contact      : mailto:support@gaisler.com
31
--                http://www.gaisler.com
32
--
33
-- Disclaimer   : All information is provided "as is", there is no warranty that
34
--                the information is correct or suitable for any purpose,
35
--                neither implicit nor explicit.
36
--============================================================================--
37
 
38
library  IEEE;
39
use      IEEE.Std_Logic_1164.all;
40
 
41
library  grlib;
42
use      grlib.amba.all;
43
 
44
library  gaisler;
45
use      gaisler.wild.all;
46
 
47
entity Wild2AHB is
48
   generic (
49
      hindex:        in    Integer := 0;
50
      burst:         in    Integer := 0;
51
      syncrst:       in    Integer := 0);
52
   port (
53
      rstkn:         in    Std_ULogic;
54
      clkk:          in    Std_ULogic;
55
 
56
      rstfn:         in    Std_ULogic;
57
      clkf:          in    Std_ULogic;
58
 
59
      ahbmi:         in    AHB_Mst_In_Type;
60
      ahbmo:         out   AHB_Mst_Out_Type;
61
 
62
      ladi:          in    LAD_In_Type;
63
      lado:          out   LAD_Out_Type);
64
end entity Wild2AHB; --=======================================================--
65
 
66
library  IEEE;
67
use      IEEE.Std_Logic_1164.all;
68
 
69
library  grlib;
70
use      grlib.amba.all;
71
use      grlib.stdlib.all;
72
use      grlib.stdlib.all;
73
use      grlib.devices.all;
74
use      grlib.dma2ahb_package.all;
75
 
76
architecture RTL of Wild2AHB is
77
   -----------------------------------------------------------------------------
78
   -- configuration constants
79
   -----------------------------------------------------------------------------
80
   constant REVISION:         Integer := 0;
81
 
82
   -----------------------------------------------------------------------------
83
   -- WildCard revision constants
84
   -----------------------------------------------------------------------------
85
   constant PE_CORE_MAJOR_VERSION:  Std_Logic_Vector(7 downto 0) := x"01";
86
   constant PE_CORE_MINOR_VERSION:  Std_Logic_Vector(7 downto 0) := x"03";
87
 
88
   constant PE_CORE_VERSION:        Std_Logic_Vector(31 downto 0) :=
89
               x"0000" & PE_CORE_MAJOR_VERSION & PE_CORE_MINOR_VERSION;
90
 
91
   -----------------------------------------------------------------------------
92
   -- general
93
   -----------------------------------------------------------------------------
94
   signal   vcc, gnd:         Std_Logic_Vector(7 downto 0);
95
 
96
   -----------------------------------------------------------------------------
97
   -- memory buffer type
98
   -----------------------------------------------------------------------------
99
   constant bits:             Integer := burst;
100
   constant depth:            Integer := 2**bits;
101
   subtype  memory_type is    Std_Logic_Vector(31 downto 0);
102
   type     memory_array is   array (0 to depth-1) of memory_type;
103
 
104
   -----------------------------------------------------------------------------
105
   -- registers - Main clock domain, X MHz, Clk_F
106
   -----------------------------------------------------------------------------
107
   type register_type is record
108
      -- ahb/dma handling
109
      dmai:             dma_in_type;
110
 
111
      -- ctrl
112
      error:            Std_ULogic;
113
      ready:            Std_ULogic;
114
      ongoing:          Std_ULogic;
115
 
116
      cntr:             Integer range 0 to depth;
117
      index:            Integer range 0 to depth-1;
118
      rarray:           memory_array;
119
 
120
      -- sync
121
      active_1st:       Std_ULogic;
122
      active_2nd:       Std_ULogic;
123
      active:           Std_ULogic;
124
   end record;
125
 
126
   signal   r, rin:     register_type;
127
 
128
   -----------------------------------------------------------------------------
129
   -- data types - PCI clock domain, 33 MHz, Clk_K
130
   -----------------------------------------------------------------------------
131
   type ctrl_type is record
132
      warray:           memory_array;
133
      wsize:            Integer range 0 to depth;
134
 
135
      wdata:            Std_Logic_Vector(31 downto 0);
136
      waddr:            Std_Logic_Vector(31 downto 0);
137
      store:            Std_ULogic;
138
 
139
      addr:             Std_Logic_Vector(16 downto 0);
140
      active:           Std_ULogic;
141
      fetch:            Std_ULogic;
142
 
143
      error:            Std_ULogic;
144
      error_1st:        Std_ULogic;
145
      error_2nd:        Std_ULogic;
146
 
147
      ready:            Std_ULogic;
148
      ready_1st:        Std_ULogic;
149
      ready_2nd:        Std_ULogic;
150
   end record;
151
 
152
   -----------------------------------------------------------------------------
153
   -- registers - PCI clock domain, 33 MHz, Clk_K
154
   -----------------------------------------------------------------------------
155
   type register_lad_type is record
156
      -- input
157
      ladi:             LAD_In_Type;
158
 
159
      -- lad access control
160
      ctrl:             ctrl_type;
161
   end record;
162
 
163
   signal   rk, rkin:   register_lad_type;
164
 
165
   -----------------------------------------------------------------------------
166
   -- local unregistered signals
167
   -----------------------------------------------------------------------------
168
   signal   dmao:       dma_out_type;                    -- dma output
169
   signal   dmai:       dma_in_type;                     -- dma input
170
 
171
   -----------------------------------------------------------------------------
172
   -- Reserved space    : 0x00008000 - 0x0000FFFC
173
   -- User space        : 0x00010000 - 0x0001FFFC
174
   -- Version register  : 0x00008000 - (decode bits 15 and 14 only)
175
   -----------------------------------------------------------------------------
176
   constant cUser:      Std_Logic_Vector(16 downto 15) := "10";
177
   constant cVersion:   Std_Logic_Vector(16 downto 14) := "010";
178
   constant cReserved:  Std_Logic_Vector(16 downto 14) := "011";
179
 
180
   -----------------------------------------------------------------------------
181
   -- Register addresses:
182
   -----------------------------------------------------------------------------
183
   constant cStat:      Std_Logic_Vector(7 downto 0) := X"00";
184
   constant cCtrl:      Std_Logic_Vector(7 downto 0) := X"04";
185
   constant cSize:      Std_Logic_Vector(7 downto 0) := X"08";
186
   constant cVer:       Std_Logic_Vector(7 downto 0) := X"0C";
187
   constant cRAddr:     Std_Logic_Vector(7 downto 0) := X"10";
188
   constant cWAddr:     Std_Logic_Vector(7 downto 0) := X"20";
189
   constant cRData:     Std_Logic_Vector(9 downto 0) := "10" & X"00";
190
   constant cWData:     Std_Logic_Vector(9 downto 0) := "11" & X"00";
191
 
192
   -- 00 0000 00--
193
   -- 00 0000 01--
194
   -- 00 0000 10--
195
   -- 00 0000 11--
196
   -- 00 0001 ----
197
   -- 00 0010 ----
198
   -- 10 ---- ----
199
   -- 11 ---- ----
200
 
201
   -- Read(Addr, Ptr)
202
   --    -> transfer read address (command) - cRAddr
203
   --    -> loop
204
   --    ->    check status - cStat
205
   --    -> retreive read data - cRData
206
   --
207
   -- WriteAddr(Addr, Ptr)
208
   --    -> transfer write data - cWData
209
   --    -> transfer write address (command) - cWAddr
210
   --    -> loop
211
   --    ->    check status - cStat
212
 
213
   -----------------------------------------------------------------------------
214
   -- Status register:
215
   -----------------------------------------------------------------------------
216
   -- Bit:     Name:       Mode:    Remark:
217
   -----------------------------------------------------------------------------
218
   -- 2        Error       r/w      AMBA error
219
   -- 1        Active      r        Access on-going
220
   -- 0        Ready       r/w      Access completed
221
   -----------------------------------------------------------------------------
222
 
223
   -----------------------------------------------------------------------------
224
   -- Data output
225
   -----------------------------------------------------------------------------
226
   signal      Addr_Data, iAddr_Data:           Std_Logic_Vector(31 downto 0);
227
   signal      Addr_Data_OE_n, iAddr_Data_OE_n: Std_Logic_Vector(31 downto 0);
228
   signal      Addr_Data_In:                    Std_Logic_Vector(31 downto 0);
229
 
230
   attribute   syn_preserve : Boolean;
231
   attribute   syn_preserve of Addr_Data :      signal is True;
232
   attribute   syn_preserve of Addr_Data_OE_n : signal is True;
233
   attribute   syn_preserve of Addr_Data_In :   signal is True;
234
 
235
begin
236
 
237
   -----------------------------------------------------------------------------
238
   -- combinatorial logic
239
   -----------------------------------------------------------------------------
240
   comb: process(rstfn, rstkn, r, rk, ladi, dmao, Addr_Data_In)
241
      variable v:             register_type;
242
      variable vk:            register_lad_type;
243
   begin
244
      --------------------------------------------------------------------------
245
      -- local variable copy of register signal
246
      v                    := r;
247
      vk                   := rk;
248
 
249
      --------------------------------------------------------------------------
250
      -- synchronization of external inputs
251
      vk.ladi              := ladi;
252
 
253
      --------------------------------------------------------------------------
254
      -- synchronization internally
255
      v.active_1st         := rk.ctrl.active;
256
      v.active_2nd         := r.active_1st;
257
      if r.active_1st='1' and r.active_2nd='0' then
258
         v.active          := '1';
259
      end if;
260
      if r.active_1st='0' and r.active_2nd='0' then
261
         v.active          := '0';
262
      end if;
263
 
264
      vk.ctrl.error_1st    := r.error;
265
      vk.ctrl.error_2nd    := rk.ctrl.error_1st;
266
      if rk.ctrl.error_1st='1' and rk.ctrl.error_2nd='0' then
267
         vk.ctrl.error     := '1';
268
      end if;
269
 
270
      vk.ctrl.ready_1st    := r.ready;
271
      vk.ctrl.ready_2nd    := rk.ctrl.ready_1st;
272
      if rk.ctrl.ready_1st='1' and not rk.ctrl.ready_2nd='0' then
273
         vk.ctrl.ready     := '1';
274
      end if;
275
 
276
      --------------------------------------------------------------------------
277
      -- lad interface
278
      --------------------------------------------------------------------------
279
      -- address phase
280
      if rk.ladi.AS_N='0' and rk.ladi.CS_N='0' then
281
         if rk.ladi.Reg_N='0' then
282
            -- register space
283
            if rk.ladi.WR_N='0' then
284
               -- write access
285
               vk.ctrl.store  := '1';
286
            else
287
               -- read access
288
               vk.ctrl.store  := '0';
289
            end if;
290
         else
291
            -- no access
292
            vk.ctrl.store     := '0';
293
         end if;
294
         vk.ctrl.addr         := Addr_Data_In(16 downto 0);
295
      end if;
296
 
297
      -- data phase - write access
298
      if rk.ladi.DS_N='0' and rk.ladi.CS_N='0' then
299
         if rk.ctrl.store='1' then
300
            if    rk.ctrl.addr(9 downto 8)=cWData(9 downto 8) and (burst = 0) then
301
               vk.ctrl.wdata     := Addr_Data_In;
302
            elsif rk.ctrl.addr(9 downto 8)=cWData(9 downto 8) and (burst /= 0) then
303
               vk.ctrl.warray(Conv_Integer(rk.ctrl.addr(bits+1 downto 2))):= Addr_Data_In;
304
            elsif rk.ctrl.addr(7 downto 0)=cStat then
305
               vk.ctrl.error     := '0';
306
               vk.ctrl.ready     := '0';
307
            elsif rk.ctrl.addr(7 downto 0)=cRAddr then
308
               vk.ctrl.waddr     := Addr_Data_In;
309
               vk.ctrl.active    := '1';
310
               vk.ctrl.fetch     := '1';
311
            elsif rk.ctrl.addr(7 downto 0)=cWAddr then
312
               vk.ctrl.waddr     := Addr_Data_In;
313
               vk.ctrl.active    := '1';
314
               vk.ctrl.fetch     := '0';
315
            elsif rk.ctrl.addr(7 downto 0)=cSize and (burst /= 0) then
316
               vk.ctrl.wsize     := Conv_Integer(Addr_Data_In);
317
            end if;
318
         end if;
319
      end if;
320
 
321
      if rk.ladi.DS_N='0' and rk.ladi.CS_N='0' and (burst /= 0) then
322
         if rk.ladi.Reg_N='0' then
323
            -- register space
324
            -- address increment
325
            vk.ctrl.addr(bits+1 downto 2) := rk.ctrl.addr(bits+1 downto 2) + 1;
326
         end if;
327
      end if;
328
 
329
      -- data phase - read access
330
      iAddr_Data           <= (others => '0');
331
      if    rk.ctrl.addr(16 downto 14)=cVersion then
332
         iAddr_Data        <= PE_CORE_VERSION;
333
      elsif rk.ctrl.addr(9 downto 8)=cRData(9 downto 8) and (burst = 0) then
334
         iAddr_Data        <= dmao.Data;
335
      elsif rk.ctrl.addr(9 downto 8)=cRData(9 downto 8) and (burst /= 0) then
336
         iAddr_Data        <= r.rarray(Conv_Integer(vk.ctrl.addr(bits+1 downto 2)));
337
      elsif rk.ctrl.addr(7 downto 0)=cStat then
338
         iAddr_Data(2)     <= rk.ctrl.error;
339
         iAddr_Data(1)     <= rk.ctrl.active;
340
         iAddr_Data(0)     <= rk.ctrl.ready;
341
      elsif rk.ctrl.addr(7 downto 0)=cVer then
342
         iAddr_Data(11 downto 0) <= Conv_Std_Logic_Vector(depth, 8) & Conv_Std_Logic_Vector(REVISION, 4);
343
      end if;
344
 
345
      if rk.ctrl.ready_1st='1' and not rk.ctrl.ready_2nd='0' then
346
         vk.ctrl.active       := '0';
347
      end if;
348
 
349
      -- combinatorial output enable control
350
      if rk.ladi.CS_N='0' and rk.ladi.WR_N='1' then
351
         iAddr_Data_OE_n <= (others => '0');
352
      else
353
         iAddr_Data_OE_n <= (others => '1');
354
      end if;
355
 
356
      --------------------------------------------------------------------------
357
      -- dma interface
358
      --------------------------------------------------------------------------
359
      if r.active='1' and r.ongoing='0' and r.ready='0' then
360
         v.ongoing            := '1';
361
         if (burst /= 0) then
362
            if rk.ctrl.fetch='1' then
363
               v.index        := 0;
364
            else
365
               v.index        := 1;
366
            end if;
367
            if (rk.ctrl.wsize > 0) then
368
               v.cntr         := rk.ctrl.wsize-1;
369
            end if;
370
            v.dmai.Data       := rk.ctrl.warray(0);
371
         end if;
372
         if (burst /= 0) and (rk.ctrl.wsize > 1) then
373
            v.dmai.Burst      := '1';
374
         else
375
            v.dmai.Burst      := '0';
376
         end if;
377
         if rk.ctrl.fetch='1' then
378
            v.dmai.Store      := '0';
379
         else
380
            v.dmai.Store      := '1';
381
         end if;
382
         v.dmai.Request       := '1';
383
 
384
      elsif r.ongoing='1' then
385
         if dmao.Grant = '1' then
386
            if (burst /= 0) and r.cntr > 0 then
387
               v.cntr      := r.cntr - 1;
388
            else
389
               v.dmai.Request := '0';
390
               v.dmai.Burst   := '0';
391
            end if;
392
         end if;
393
 
394
         if rk.ctrl.fetch='1' then
395
            if dmao.Ready='1' then
396
               if (burst /= 0) then
397
                  v.rarray(r.index) := dmao.Data;
398
               end if;
399
               if (burst /= 0) and (r.index < rk.ctrl.wsize-1) and (rk.ctrl.wsize > 0) then
400
                  v.index     := r.index + 1;
401
               else
402
                  v.ready     := '1';
403
                  v.ongoing   := '0';
404
               end if;
405
            end if;
406
         else
407
            if dmao.OKAY='1' then
408
               if (burst /= 0) then
409
                  v.dmai.Data := rk.ctrl.warray(r.index);
410
               end if;
411
               if (burst /= 0) and (r.index < rk.ctrl.wsize-1) and (rk.ctrl.wsize > 0) then
412
                  v.index     := r.index + 1;
413
               else
414
                  v.ready     := '1';
415
                  v.ongoing   := '0';
416
                  v.dmai.Store:= '0';
417
               end if;
418
            end if;
419
         end if;
420
         if dmao.Fault='1' then
421
            v.error           := '1';
422
            v.ready           := '1';
423
            v.ongoing         := '0';
424
            v.dmai.Burst      := '0';
425
            v.dmai.Store      := '0';
426
            v.dmai.Request    := '0';
427
         end if;
428
 
429
      elsif r.active='0' and r.ongoing='0' and (r.ready='1') then
430
         v.ready              := '0';
431
      else
432
         v.dmai.Burst         := '0';
433
         v.dmai.Request       := '0';
434
         v.dmai.Store         := '0';
435
      end if;
436
 
437
 
438
      --======================================================================--
439
      -- Synchronous reset operation
440
      --------------------------------------------------------------------------
441
      if rstfn = '0' then
442
         v.dmai.Request          := '0';
443
         v.dmai.Store            := '0';
444
 
445
         v.error                 := '0';
446
         v.ready                 := '0';
447
         v.ongoing               := '0';
448
         if (burst /= 0) then
449
            v.cntr               := 0;
450
            v.index              := 0;
451
            v.dmai.Burst         := '0';
452
         end if;
453
 
454
         v.active_1st            := '0';
455
         v.active_2nd            := '0';
456
         v.active                := '0';
457
      end if;
458
 
459
      if rstkn = '0' then
460
         vk.ladi.WR_n            := '1';
461
         vk.ladi.CS_n            := '1';
462
         vk.ladi.AS_n            := '1';
463
         vk.ladi.Reg_n           := '1';
464
 
465
         vk.ctrl.addr            := (others => '0');
466
         vk.ctrl.store           := '0';
467
         vk.ctrl.active          := '0';
468
         vk.ctrl.fetch           := '0';
469
         if (burst /= 0) then
470
            vk.ctrl.wsize        := 0;
471
         end if;
472
 
473
         vk.ctrl.error           := '0';
474
         vk.ctrl.error_1st       := '0';
475
         vk.ctrl.error_2nd       := '0';
476
         vk.ctrl.ready           := '0';
477
         vk.ctrl.ready_1st       := '0';
478
         vk.ctrl.ready_2nd       := '0';
479
 
480
         vk.ctrl.waddr           := (others => '0');
481
         vk.ctrl.wdata           := (others => '0');
482
      end if;
483
 
484
      --------------------------------------------------------------------------
485
      -- variable to signal assigment
486
      rin               <= v;
487
      rkin              <= vk;
488
   end process comb;
489
 
490
   -----------------------------------------------------------------------------
491
   -- general
492
   -----------------------------------------------------------------------------
493
   vcc <= (others => '1');
494
   gnd <= (others => '0');
495
 
496
   -----------------------------------------------------------------------------
497
   -- output ports - non-registered signals
498
   -----------------------------------------------------------------------------
499
   lado.Addr_Data          <= Addr_Data;
500
   lado.Addr_Data_OE_n     <= Addr_Data_OE_n;
501
 
502
   -----------------------------------------------------------------------------
503
   -- output ports  - fixed signals
504
   -----------------------------------------------------------------------------
505
   lado.Ack_n              <= vcc(0);
506
   lado.Int_Req_n          <= vcc(0);
507
   lado.DMA_0_Data_OK_n    <= vcc(0);
508
   lado.DMA_0_Burst_OK     <= gnd(0);
509
   lado.DMA_1_Data_OK_n    <= vcc(0);
510
   lado.DMA_1_Burst_OK     <= gnd(0);
511
   lado.Reg_Data_OK_n      <= gnd(0);
512
   lado.Reg_Burst_OK       <= vcc(0);
513
   lado.Force_K_Clk_n      <= gnd(0);
514
   lado.Reserved           <= gnd(0);
515
 
516
   -----------------------------------------------------------------------------
517
   -- registered signals
518
   -----------------------------------------------------------------------------
519
   dmai.Reset              <= '0';
520
   dmai.Request            <= r.dmai.Request;
521
   dmai.Burst              <= r.dmai.Burst when (burst /= 0) else '0';
522
   dmai.Beat               <= HINCR;
523
   dmai.Store              <= r.dmai.Store;
524
   dmai.Data               <= r.dmai.Data when (burst /= 0) else rk.ctrl.wdata;
525
   dmai.Address            <= rk.ctrl.waddr;
526
   dmai.Size               <= HSIZE32;
527
 
528
   -----------------------------------------------------------------------------
529
   -- registers, Main clock domain, X MHz, Clk_F
530
   -----------------------------------------------------------------------------
531
   regs: process(clkf, rstfn)
532
   begin
533
      if Rising_Edge(clkf) then
534
         r              <= rin;
535
      end if;
536
   end process regs;
537
 
538
   -----------------------------------------------------------------------------
539
   -- registers, PCI clock domain, 33 MHz, Clk_K
540
   -----------------------------------------------------------------------------
541
   regs_falling: process(clkk, rstkn)
542
   begin
543
      if Falling_Edge(clkk) then
544
         rk             <= rkin;
545
      end if;
546
   end process regs_falling;
547
 
548
   -- explicit flip-flops for LAD data-address signals for placement in IOB
549
   regs_explicit: process(clkk, rstkn)
550
   begin
551
      if rstkn='0' then
552
         Addr_Data      <= (others => '1');
553
         Addr_Data_OE_N <= (others => '1');
554
         Addr_Data_In   <= (others => '1');
555
      elsif Falling_Edge(clkk) then
556
         Addr_Data      <= iAddr_Data;
557
         Addr_Data_OE_N <= iAddr_Data_OE_N;
558
         Addr_Data_In   <= ladi.Addr_Data;
559
      end if;
560
   end process regs_explicit;
561
 
562
   ---------------------------------------------------------------------------
563
   -- amba ahb master with dma
564
   ---------------------------------------------------------------------------
565
   dma2ahb_unit: dma2ahb
566
      generic map(
567
         hindex            => hindex,
568
         vendorid          => vendor_gaisler,
569
         deviceid          => gaisler_wild2ahb,
570
         version           => REVISION,
571
         syncrst           => syncrst)
572
      port map(
573
         hclk              => clkf,
574
         hresetn           => rstfn,
575
         dmain             => dmai,
576
         dmaout            => dmao,
577
         ahbin             => ahbmi,
578
         ahbout            => ahbmo);
579
 
580
end architecture RTL; --======================================================--

powered by: WebSVN 2.1.0

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