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

Subversion Repositories pcie_sg_dma

[/] [pcie_sg_dma/] [trunk/] [rtl/] [Interrupts.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 weng_ziti
----------------------------------------------------------------------------------
2
-- Company:  ziti, Uni. HD
3
-- Engineer:  wgao
4
-- 
5
-- Design Name: 
6
-- Module Name:    Interrupts - Behavioral 
7
-- Project Name: 
8
-- Target Devices: 
9
-- Tool versions: 
10
-- Description: 
11
--
12
-- Dependencies: 
13
--
14
-- Revision 1.00 - first release.  14.05.2007
15
-- 
16
-- Additional Comments: 
17
--
18
----------------------------------------------------------------------------------
19
library IEEE;
20
use IEEE.STD_LOGIC_1164.ALL;
21
use IEEE.STD_LOGIC_ARITH.ALL;
22
use IEEE.STD_LOGIC_UNSIGNED.ALL;
23
 
24
library work;
25
use work.abb64Package.all;
26
 
27
---- Uncomment the following library declaration if instantiating
28
---- any Xilinx primitives in this code.
29
--library UNISIM;
30
--use UNISIM.VComponents.all;
31
 
32
entity Interrupts is
33
    port (
34
      -- System Interrupt register from Registers module
35
      Sys_IRQ                     : IN  std_logic_vector(C_DBUS_WIDTH-1   downto 0);
36
 
37
      -- Interrupt generator signals
38
      IG_Reset                    : IN  std_logic;
39
      IG_Host_Clear               : IN  std_logic;
40
      IG_Latency                  : IN  std_logic_vector(C_DBUS_WIDTH-1   downto 0);
41
      IG_Num_Assert               : OUT std_logic_vector(C_DBUS_WIDTH-1   downto 0);
42
      IG_Num_Deassert             : OUT std_logic_vector(C_DBUS_WIDTH-1   downto 0);
43
      IG_Asserting                : OUT std_logic;
44
 
45
 
46
      -- Interrupt Interface 
47
      cfg_interrupt_n             : OUT std_logic;
48
      cfg_interrupt_rdy_n         : IN  std_logic;
49
      cfg_interrupt_mmenable      : IN  std_logic_VECTOR(2 downto 0);
50
      cfg_interrupt_msienable     : IN  std_logic;
51
      cfg_interrupt_di            : OUT std_logic_VECTOR(7 downto 0);
52
      cfg_interrupt_do            : IN  std_logic_VECTOR(7 downto 0);
53
      cfg_interrupt_assert_n      : OUT std_logic;
54
 
55
      -- Irpt Channel
56
      Irpt_Req                    : OUT std_logic;
57
      Irpt_RE                     : IN  std_logic;
58
      Irpt_Qout                   : OUT std_logic_vector(C_CHANNEL_BUF_WIDTH-1 downto 0);
59
 
60
      -- Clock and reset
61
      trn_clk                     : IN  std_logic;
62
      trn_reset_n                 : IN  std_logic
63
 
64
    );
65
end Interrupts;
66
 
67
 
68
architecture Behavioral of Interrupts is
69
 
70
  -- State machine: Interrupt control
71
  type IrptStates is              ( IntST_RST
72
                                  , IntST_Idle
73
                                  , IntST_Asserting
74
                                  , IntST_Asserted
75
                                  , IntST_Deasserting
76
                                  );
77
 
78
  signal edge_Intrpt_State        : IrptStates;
79
  signal level_Intrpt_State       : IrptStates;
80
 
81
  signal cfg_interrupt_n_i        : std_logic;
82
  signal cfg_interrupt_rdy_n_i    : std_logic;
83
  signal cfg_interrupt_di_i       : std_logic_vector(7 downto 0);
84
  signal cfg_interrupt_assert_n_i : std_logic;
85
 
86
  signal edge_Irpt_Req_i          : std_logic;
87
  signal level_Irpt_Req_i         : std_logic;
88
 
89
  signal Irpt_RE_i                : std_logic;
90
  signal Irpt_Qout_i              : std_logic_vector(C_CHANNEL_BUF_WIDTH-1 downto 0)
91
                                  := (OTHERS=>'0');
92
 
93
  signal Msg_Tag_Lo               : std_logic_vector( 3 downto 0);
94
  signal Msg_Code                 : std_logic_vector( 7 downto 0);
95
 
96
  signal edge_MsgCode_is_ASSERT   : std_logic;
97
  signal level_MsgCode_is_ASSERT  : std_logic;
98
 
99
  signal Interrupts_ORed          : std_logic;
100
 
101
  -- Interrupt Generator 
102
  signal IG_Trigger_i             : std_logic;
103
 
104
  -- Interrupt Generator Counter
105
  signal IG_Counter               : std_logic_vector(C_CNT_GINT_WIDTH-1 downto 0);
106
  signal IG_Run                   : std_logic;
107
 
108
  -- Interrupt Generator Statistic: Assert number
109
  signal IG_Num_Assert_i          : std_logic_vector(C_DBUS_WIDTH-1   downto 0);
110
 
111
  -- Interrupt Generator Statistic: Deassert number
112
  signal IG_Num_Deassert_i        : std_logic_vector(C_DBUS_WIDTH-1   downto 0);
113
 
114
  -- Interrupt Generator indicator
115
  signal IG_Asserting_i           : std_logic;
116
 
117
 
118
begin
119
 
120
  -- Interrupt interface
121
  -- cfg_interrupt_n should be explicitly clarified!
122
  cfg_interrupt_assert_n          <= cfg_interrupt_assert_n_i;
123
  cfg_interrupt_rdy_n_i           <= cfg_interrupt_rdy_n;
124
  -- Only Legacy IntA for the moment ...
125
  cfg_interrupt_di                <= cfg_interrupt_di_i;
126
  cfg_interrupt_di_i              <= (Others=>'0');
127
 
128
  -- Channel mode interface.
129
  Irpt_RE_i       <= Irpt_RE;
130
  Irpt_Qout       <= Irpt_Qout_i;
131
 
132
 
133
--  ---------------------------------------------------
134
--  emulates a channel buffer output
135
--     Note: Type not shows in this buffer
136
--
137
--  127 ~  97 : reserved
138
--         96 : reserved
139
--         95 : reserved
140
--         94 : Valid
141
--   93 ~  35 : reserved
142
--   34 ~  27 : Msg code
143
--   26 ~  19 : Tag
144
--
145
--   18 ~  17 : Format
146
--   16 ~  14 : TC
147
--         13 : TD
148
--         12 : EP
149
--   11 ~  10 : Attribute
150
--    9 ~   0 : Length
151
-- 
152
  Irpt_Qout_i(C_CHBUF_QVALID_BIT)                                       <= '1';
153
  Irpt_Qout_i(C_CHBUF_TAG_BIT_TOP downto C_CHBUF_TAG_BIT_BOT)           <= C_MSG_TAG_HI & Msg_Tag_Lo;
154
  Irpt_Qout_i(C_CHBUF_MSG_CODE_BIT_TOP downto C_CHBUF_MSG_CODE_BIT_BOT) <= Msg_Code;
155
  Irpt_Qout_i(C_CHBUF_FMT_BIT_TOP downto C_CHBUF_FMT_BIT_BOT)           <= C_FMT4_NO_DATA;
156
  Irpt_Qout_i(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT)         <= C_ALL_ZEROS(C_CHBUF_LENG_BIT_TOP downto C_CHBUF_LENG_BIT_BOT);
157
 
158
 
159
 
160
-- ---------------------------------------------------------------
161
-- All Interrups are OR'ed
162
--
163
   Syn_Interrupts_ORed:
164
   process ( trn_clk )
165
   begin
166
      if trn_clk'event and trn_clk = '1' then
167
         if Sys_IRQ(C_NUM_OF_INTERRUPTS-1 downto 0)
168
              = C_ALL_ZEROS(C_NUM_OF_INTERRUPTS-1 downto 0)
169
            then
170
            Interrupts_ORed      <= '0';
171
         else
172
            Interrupts_ORed      <= '1';
173
         end if;
174
      end if;
175
   end process;
176
 
177
 
178
 
179
-------------------------------------------
180
---- Cfg Interface mode
181
-------------------------------------------
182
 Gen_Cfg_Irpt: if USE_CFG_INTERRUPT generate
183
 
184
   cfg_interrupt_n      <= cfg_interrupt_n_i;
185
   Irpt_Req             <= '0';               -- Cfg interface mode, channel disabled.
186
   Msg_Code             <= (Others=>'0');
187
 
188
   States_Machine_Irpt:
189
   process ( trn_clk, trn_reset_n)
190
   begin
191
      if trn_reset_n = '0' then
192
         edge_Intrpt_State      <= IntST_RST;
193
         cfg_interrupt_n_i <= '1';
194
         cfg_interrupt_assert_n_i  <= '1';
195
 
196
      elsif trn_clk'event and trn_clk = '1' then
197
 
198
        case edge_Intrpt_State is
199
 
200
          when IntST_RST =>
201
              edge_Intrpt_State      <= IntST_Idle;
202
              cfg_interrupt_n_i <= '1';
203
              cfg_interrupt_assert_n_i  <= '1';
204
 
205
          when IntST_Idle =>
206
            if Interrupts_ORed='1' then
207
              edge_Intrpt_State      <= IntST_Asserting;
208
              cfg_interrupt_n_i <= '0';
209
              cfg_interrupt_assert_n_i  <= '0';
210
            else
211
              edge_Intrpt_State      <= IntST_Idle;
212
              cfg_interrupt_n_i <= '1';
213
              cfg_interrupt_assert_n_i  <= '1';
214
            end if;
215
 
216
          when IntST_Asserting =>
217
            if cfg_interrupt_rdy_n='1' then
218
              edge_Intrpt_State      <= IntST_Asserting;
219
              cfg_interrupt_n_i <= '0';
220
              cfg_interrupt_assert_n_i  <= '0';
221
            else
222
              edge_Intrpt_State      <= IntST_Asserted;
223
              cfg_interrupt_n_i <= '1';
224
              cfg_interrupt_assert_n_i  <= '0';
225
            end if;
226
 
227
 
228
          when IntST_Asserted =>
229
            if Interrupts_ORed='0' then
230
              edge_Intrpt_State      <= IntST_Deasserting;
231
              cfg_interrupt_n_i <= '0';
232
              cfg_interrupt_assert_n_i  <= '1';
233
            else
234
              edge_Intrpt_State      <= IntST_Asserted;
235
              cfg_interrupt_n_i <= '1';
236
              cfg_interrupt_assert_n_i  <= '0';
237
            end if;
238
 
239
 
240
          when IntST_Deasserting =>
241
            if Irpt_RE_i='0' then
242
              edge_Intrpt_State      <= IntST_Deasserting;
243
              cfg_interrupt_n_i <= '0';
244
              cfg_interrupt_assert_n_i  <= '1';
245
            else
246
              edge_Intrpt_State      <= IntST_Idle;
247
              cfg_interrupt_n_i <= '1';
248
              cfg_interrupt_assert_n_i  <= '1';
249
            end if;
250
 
251
 
252
          when OTHERS  =>
253
              edge_Intrpt_State      <= IntST_Idle;
254
              cfg_interrupt_n_i <= '1';
255
              cfg_interrupt_assert_n_i  <= '1';
256
 
257
        end case;
258
 
259
      end if;
260
   end process;
261
 
262
 end generate;
263
 
264
 
265
----------------------------------------------
266
--  Channel mode
267
----------------------------------------------
268
 Gen_Chan_MSI: if not USE_CFG_INTERRUPT generate
269
 
270
   cfg_interrupt_n      <= '1';          -- Channel mode, cfg interface disabled.
271
   cfg_interrupt_assert_n_i  <= '1';
272
 
273
   Irpt_Req             <= edge_Irpt_Req_i;
274
   Msg_Code             <= C_MSGCODE_INTA when edge_MsgCode_is_ASSERT='1'
275
                           else C_MSGCODE_INTA_N;
276
 
277
   -- State Machine for edge interrupts
278
   State_Machine_edge_Irpt:
279
   process ( trn_clk, trn_reset_n)
280
   begin
281
      if trn_reset_n = '0' then
282
         edge_Intrpt_State      <= IntST_RST;
283
         edge_Irpt_Req_i        <= '0';
284
         edge_MsgCode_is_ASSERT <= '0';
285
 
286
      elsif trn_clk'event and trn_clk = '1' then
287
 
288
        case edge_Intrpt_State is
289
 
290
          when IntST_RST =>
291
              edge_Intrpt_State      <= IntST_Idle;
292
              edge_Irpt_Req_i        <= '0';
293
                        edge_MsgCode_is_ASSERT <= '0';
294
 
295
          when IntST_Idle =>
296
            if Interrupts_ORed='1' then
297
              edge_Intrpt_State      <= IntST_Asserting;
298
              edge_Irpt_Req_i        <= '1';
299
                        edge_MsgCode_is_ASSERT <= edge_MsgCode_is_ASSERT;  -- '1';
300
            else
301
              edge_Intrpt_State      <= IntST_Idle;
302
              edge_Irpt_Req_i        <= '0';
303
                        edge_MsgCode_is_ASSERT <= edge_MsgCode_is_ASSERT;
304
            end if;
305
 
306
          when IntST_Asserting =>
307
            if Irpt_RE_i='0' then
308
              edge_Intrpt_State      <= IntST_Asserting;
309
              edge_Irpt_Req_i        <= '1';
310
                        edge_MsgCode_is_ASSERT <= edge_MsgCode_is_ASSERT; -- '1';
311
            else
312
              edge_Intrpt_State      <= IntST_Asserted;
313
              edge_Irpt_Req_i        <= '0';
314
                        edge_MsgCode_is_ASSERT <= '1';
315
            end if;
316
 
317
          when IntST_Asserted =>
318
            if Interrupts_ORed='0' then
319
              edge_Intrpt_State      <= IntST_Deasserting;
320
              edge_Irpt_Req_i        <= '1';
321
                        edge_MsgCode_is_ASSERT <= edge_MsgCode_is_ASSERT;  -- !!
322
            else
323
              edge_Intrpt_State      <= IntST_Asserted;
324
              edge_Irpt_Req_i        <= '0';
325
                        edge_MsgCode_is_ASSERT <= edge_MsgCode_is_ASSERT;  -- '1';
326
            end if;
327
 
328
          when IntST_Deasserting =>
329
            if Irpt_RE_i='0' then
330
              edge_Intrpt_State      <= IntST_Deasserting;
331
              edge_Irpt_Req_i        <= '1';
332
                        edge_MsgCode_is_ASSERT <= edge_MsgCode_is_ASSERT; -- '0';
333
            else
334
              edge_Intrpt_State      <= IntST_Idle;
335
              edge_Irpt_Req_i        <= '0';
336
                        edge_MsgCode_is_ASSERT <= '0';
337
            end if;
338
 
339
          when OTHERS  =>
340
              edge_Intrpt_State      <= IntST_Idle;
341
              edge_Irpt_Req_i        <= '0';
342
                        edge_MsgCode_is_ASSERT <= '0';
343
 
344
        end case;
345
 
346
      end if;
347
   end process;
348
 
349
 
350
 
351
 
352
   --  Tag of Msg TLP increments
353
   Sync_Msg_Tag_Increment:
354
   process ( trn_clk, trn_reset_n)
355
   begin
356
      if trn_reset_n = '0' then
357
         Msg_Tag_Lo        <= (Others=>'0');
358
 
359
      elsif trn_clk'event and trn_clk = '1' then
360
         if Irpt_RE_i = '1' then
361
            Msg_Tag_Lo  <=  Msg_Tag_Lo + '1';
362
         else
363
            Msg_Tag_Lo  <=  Msg_Tag_Lo;
364
         end if;
365
 
366
      end if;
367
   end process;
368
 
369
 
370
 end generate;   -- Gen_Chan_MSI: if not USE_CFG_INTERRUPT
371
 
372
 
373
 -- 
374
 --------------      Generate Interrupt Generator       ------------------
375
 --
376
 Gen_IG:  if IMP_INT_GENERATOR generate
377
 
378
   IG_Num_Assert   <= IG_Num_Assert_i;
379
   IG_Num_Deassert <= IG_Num_Deassert_i;
380
   IG_Asserting    <= IG_Asserting_i;
381
 
382
-- -------------------------------------------------------
383
-- FSM: generating interrupts
384
   FSM_Generate_Interrupts:
385
   process ( trn_clk, trn_reset_n)
386
   begin
387
      if trn_reset_n = '0' then
388
         IG_Counter    <= (Others=>'0');
389
 
390
      elsif trn_clk'event and trn_clk = '1' then
391
 
392
        if IG_Reset = '1' then
393
           IG_Counter    <= (Others=>'0');
394
        elsif IG_Counter /= C_ALL_ZEROS(C_CNT_GINT_WIDTH-1 downto 0) then
395
           IG_Counter    <= IG_Counter - '1';
396
        elsif IG_Run = '0' then
397
           IG_Counter    <= (Others=>'0');
398
        else
399
           IG_Counter    <= IG_Latency(C_CNT_GINT_WIDTH-1 downto 0);
400
        end if;
401
 
402
      end if;
403
   end process;
404
 
405
 
406
-- -------------------------------------------------------
407
-- Issuing: Interrupt trigger
408
   Synch_Interrupt_Trigger:
409
   process ( trn_clk, trn_reset_n)
410
   begin
411
      if trn_reset_n = '0' then
412
         IG_Trigger_i  <= '0';
413
 
414
      elsif trn_clk'event and trn_clk = '1' then
415
 
416
        if IG_Reset = '1' then
417
           IG_Trigger_i  <= '0';
418
        elsif IG_Counter = CONV_STD_LOGIC_VECTOR(1, C_CNT_GINT_WIDTH) then
419
           IG_Trigger_i  <= '1';
420
        else
421
           IG_Trigger_i  <= '0';
422
        end if;
423
 
424
      end if;
425
   end process;
426
 
427
 
428
-- -------------------------------------------------------
429
-- register: IG_Run
430
   Synch_IG_Run:
431
   process ( trn_clk, trn_reset_n)
432
   begin
433
      if trn_reset_n = '0' then
434
         IG_Run   <= '0';
435
 
436
      elsif trn_clk'event and trn_clk = '1' then
437
 
438
        if IG_Reset = '1' then
439
           IG_Run   <= '0';
440
        elsif IG_Latency(C_DBUS_WIDTH-1 downto 2)=C_ALL_ZEROS(C_DBUS_WIDTH-1 downto 2) then
441
           IG_Run   <= '0';
442
        else
443
           IG_Run   <= '1';
444
        end if;
445
 
446
      end if;
447
   end process;
448
 
449
 
450
-- -----------------------------------------------
451
-- Synchronous Register: IG_Num_Assert_i
452
   SysReg_IntGen_Number_of_Assert:
453
   process ( trn_clk, trn_reset_n)
454
   begin
455
      if trn_reset_n = '0' then
456
         IG_Num_Assert_i       <= (OTHERS => '0');
457
 
458
      elsif trn_clk'event and trn_clk = '1' then
459
 
460
        if IG_Reset='1' then
461
            IG_Num_Assert_i    <=  (OTHERS => '0');
462
        elsif IG_Trigger_i = '1'  then
463
            IG_Num_Assert_i    <=  IG_Num_Assert_i + '1';
464
        else
465
            IG_Num_Assert_i    <=  IG_Num_Assert_i;
466
        end if;
467
 
468
      end if;
469
   end process;
470
 
471
 
472
-- -----------------------------------------------
473
-- Synchronous Register: IG_Num_Deassert_i
474
   SysReg_IntGen_Number_of_Deassert:
475
   process ( trn_clk, trn_reset_n)
476
   begin
477
      if trn_reset_n = '0' then
478
         IG_Num_Deassert_i       <= (OTHERS => '0');
479
 
480
      elsif trn_clk'event and trn_clk = '1' then
481
 
482
        if IG_Reset='1' then
483
            IG_Num_Deassert_i    <=  (OTHERS => '0');
484
        elsif IG_Host_Clear='1' and IG_Asserting_i='1' then
485
            IG_Num_Deassert_i    <=  IG_Num_Deassert_i + '1';
486
        else
487
            IG_Num_Deassert_i    <=  IG_Num_Deassert_i;
488
        end if;
489
 
490
      end if;
491
   end process;
492
 
493
 
494
-- -----------------------------------------------
495
-- Synchronous Register: IG_Asserting_i
496
   SysReg_IntGen_IG_Asserting_i:
497
   process ( trn_clk, trn_reset_n)
498
   begin
499
      if trn_reset_n = '0' then
500
         IG_Asserting_i       <= '0';
501
 
502
      elsif trn_clk'event and trn_clk = '1' then
503
 
504
        if IG_Reset='1' then
505
            IG_Asserting_i    <=  '0';
506
        elsif IG_Asserting_i='0' and IG_Trigger_i='1' then
507
            IG_Asserting_i    <=  '1';
508
        elsif IG_Asserting_i='0' and IG_Trigger_i='0' then
509
            IG_Asserting_i    <=  '0';
510
        elsif IG_Asserting_i='1' and IG_Host_Clear='0' then
511
            IG_Asserting_i    <=  '1';
512
        elsif IG_Asserting_i='1' and IG_Host_Clear='1' then
513
            IG_Asserting_i    <=  '0';
514
        else
515
            IG_Asserting_i    <=  IG_Asserting_i;
516
        end if;
517
 
518
      end if;
519
   end process;
520
 
521
 end generate;
522
 
523
 
524
 -- 
525
 --------------    No Generation of Interrupt Generator     ----------------
526
 --
527
 
528
 NotGen_IG:  if not IMP_INT_GENERATOR generate
529
 
530
   IG_Num_Assert   <= (OTHERS=>'0');
531
   IG_Num_Deassert <= (OTHERS=>'0');
532
   IG_Asserting    <= '0';
533
 
534
 end generate;
535
 
536
end Behavioral;

powered by: WebSVN 2.1.0

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