Skip to content

Commit bc2eea6

Browse files
committed
tb: improve interrupt trigger mode test
1 parent 022082c commit bc2eea6

File tree

3 files changed

+88
-21
lines changed

3 files changed

+88
-21
lines changed
Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,91 @@
11
/*
2-
* This test verifies level-sensitive interrupt handling
2+
* This test verifies various interrupt trigger modes
33
*/
44

55
lc r100, 0x10000000 // test result output pointer
66
lc r101, halt
77
lc r102, failure
88
lc r103, 0x40000000 // timer: number of pulses (0xFFFFFFFF - infinite)
99
lc r104, 0x40000004 // timer: delay between pulses (in cycles)
10-
lc r105, 0x40000008 // timer: clear interrupt
11-
12-
lc iv3, timer_handler
13-
lc cr, 0x08080008 // enable intertups 3, mark as level-sensitive and inverted
10+
lc r105, 0x40000008 // timer: trigger mode
11+
lc r106, 0x4000000C // timer: clear interrupt
12+
13+
// Rising edge trigger
14+
mov cr, 0
15+
lc iv3, timer_handler_edge
16+
sw r105, 0
17+
lc cr, 0x00000008 // enable interrupt
1418
1519
lc r32, 1000 // cycle counter
16-
lc r33, cnt_loop
20+
lc r33, cnt_loop1
1721
mov r34, 0 // interrupt call counter
1822
1923
sw r104, 100
20-
sw r103, 5
24+
sw r103, 3
2125
22-
cnt_loop:
26+
cnt_loop1:
2327
sub r32, r32, 1
2428
cjmpug r33, r32, 0 // cnt_loop
2529
30+
cjmpne r102, r34, 3 // failure
31+
32+
// Falling edge trigger
33+
mov cr, 0
34+
lc iv3, timer_handler_edge
35+
sw r105, 2
36+
lc cr, 0x08000008 // enable interrupt
37+
38+
lc r32, 1000 // cycle counter
39+
lc r33, cnt_loop2
40+
mov r34, 0 // interrupt call counter
41+
42+
sw r104, 100
43+
sw r103, 4
44+
45+
cnt_loop2:
46+
sub r32, r32, 1
47+
cjmpug r33, r32, 0 // cnt_loop
48+
49+
cjmpne r102, r34, 4 // failure
50+
51+
// High level trigger
52+
mov cr, 0
53+
lc iv3, timer_handler_level
54+
sw r105, 1
55+
lc cr, 0x00080008 // enable interrupt
56+
57+
lc r32, 1000 // cycle counter
58+
lc r33, cnt_loop3
59+
mov r34, 0 // interrupt call counter
60+
61+
sw r104, 100
62+
sw r103, 5
63+
64+
cnt_loop3:
65+
sub r32, r32, 1
66+
cjmpug r33, r32, 0 // cnt_loop
67+
2668
cjmpne r102, r34, 5 // failure
69+
70+
// Low level trigger
71+
mov cr, 0
72+
lc iv3, timer_handler_level
73+
sw r105, 3
74+
lc cr, 0x08080008 // enable interrupt
75+
76+
lc r32, 1000 // cycle counter
77+
lc r33, cnt_loop4
78+
mov r34, 0 // interrupt call counter
79+
80+
sw r104, 100
81+
sw r103, 6
82+
83+
cnt_loop4:
84+
sub r32, r32, 1
85+
cjmpug r33, r32, 0 // cnt_loop
86+
87+
cjmpne r102, r34, 6 // failure
88+
2789
2890
sw r100, 1
2991
jmp r101 // halt
@@ -35,9 +97,15 @@ halt:
3597
hlt
3698
jmp r101 // halt
3799
38-
timer_handler:
100+
timer_handler_edge:
39101
add r34, r34, 1
40-
sw r105, 1
102+
lc r0, 0x10000004
103+
sw r0, r34
104+
iret
105+
106+
timer_handler_level:
107+
add r34, r34, 1
108+
sw r106, 1
41109
lc r0, 0x10000004
42110
sw r0, r34
43111
iret

verify/lxp32/src/platform/platform.vhd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,6 @@ timer_inst: entity work.timer(rtl)
349349
-- Timer with a level-sensitive IRQ
350350

351351
timer2_inst: entity work.timer(rtl)
352-
generic map(
353-
IRQ_LEVEL_TRIGGERED=>true,
354-
IRQ_INVERT=>true
355-
)
356352
port map(
357353
clk_i=>clk_i,
358354
rst_i=>rst_i,

verify/lxp32/src/platform/timer.vhd

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ use ieee.std_logic_1164.all;
1616
use ieee.numeric_std.all;
1717

1818
entity timer is
19-
generic(
20-
IRQ_LEVEL_TRIGGERED: boolean:=false;
21-
IRQ_INVERT: boolean:=false
22-
);
2319
port(
2420
clk_i: in std_logic;
2521
rst_i: in std_logic;
@@ -39,6 +35,9 @@ end entity;
3935

4036
architecture rtl of timer is
4137

38+
signal irq_level_triggered: std_logic:='0';
39+
signal irq_invert: std_logic:='0';
40+
4241
signal pulses: unsigned(31 downto 0):=(others=>'0');
4342
signal interval: unsigned(31 downto 0):=(others=>'0');
4443
signal cnt: unsigned(31 downto 0):=(others=>'0');
@@ -55,7 +54,7 @@ begin
5554
cnt<=(others=>'0');
5655
elapsed<='0';
5756
else
58-
if not IRQ_LEVEL_TRIGGERED then
57+
if irq_level_triggered='0' then
5958
elapsed<='0';
6059
end if;
6160
if pulses/=X"00000000" or cnt/=X"00000000" then
@@ -87,7 +86,11 @@ begin
8786
unsigned(wbs_dat_i(i*8+7 downto i*8));
8887
cnt<=(others=>'0');
8988
end if;
90-
if wbs_adr_i="00"&X"000002" and wbs_dat_i(0)='1' and i=0 then
89+
if wbs_adr_i="00"&X"000002" and i=0 then
90+
irq_level_triggered<=wbs_dat_i(0);
91+
irq_invert<=wbs_dat_i(1);
92+
end if;
93+
if wbs_adr_i="00"&X"000003" and wbs_dat_i(0)='1' and i=0 then
9194
elapsed<='0';
9295
end if;
9396
end if;
@@ -102,6 +105,6 @@ wbs_dat_o<=std_logic_vector(pulses) when wbs_adr_i="00"&X"000000" else
102105
std_logic_vector(interval) when wbs_adr_i="00"&X"000001" else
103106
(others=>'-');
104107

105-
elapsed_o<=elapsed when not IRQ_INVERT else not elapsed;
108+
elapsed_o<=elapsed xor irq_invert;
106109

107110
end architecture;

0 commit comments

Comments
 (0)