1*** Variables ***
2${UART}                             sysbus.uart
3${BIN}                              @https://dl.antmicro.com/projects/renode/clic/clic_level_prio-01.elf-s_14364-35778c43e2c9ce51414fc232d1fd5c2a518d1847
4${INT_ENABLE_ADDR}                  0x80002000
5${PLATFORM}                         SEPARATOR=
6...                                 """  ${\n}
7...                                 using "tests/peripherals/CLIC/CLIC-test-platform.repl"  ${\n}
8...                                 clic:  ${\n}
9...                                 ${SPACE*4}machineLevelBits: 4  ${\n}
10...                                 """
11
12*** Keywords ***
13Create Machine
14    Execute Command                 using sysbus
15    Execute Command                 mach create
16    Execute Command                 machine LoadPlatformDescriptionFromString ${PLATFORM}
17    Execute Command                 sysbus LoadELF ${BIN}
18
19*** Test Cases ***
20Should Pass CLIC-level-prio-01
21    Create Machine
22    Create Terminal Tester          ${UART}
23    Execute Command                 showAnalyzer uart Antmicro.Renode.Analyzers.LoggingUartAnalyzer
24
25    Wait For Line On Uart           Init complete
26
27    # Trigger interrupts 17 and 18; they have the same level, but 17 has a higher priority so it should be taken first.
28    Execute Command                 clic OnGPIO 18 True
29    Execute Command                 clic OnGPIO 17 True
30
31    # Interrupts are disabled until a non-zero value is written to INT_ENABLE_ADDR.
32    # This forces CLIC to prioritize the interrupts.
33    Execute Command                 sysbus WriteByte ${INT_ENABLE_ADDR} 1
34
35    # Interrupt with the highest priority should be handled first.
36    Wait For Line On Uart           Interrupt 17, level 1, priority 15
37    Wait For Line On Uart           Interrupt 18, level 1, priority 14
38
39    # At this point we're spinning in interrupt 18 - preempt it with interrupt 16, that has a higher level.
40    Execute Command                 clic OnGPIO 16 True
41    Wait For Line On Uart           Interrupt 16, level 2, priority 12
42
43    # At this point we're spinning in interrupt 16 - try to preempt it with interrupt of a lower level, but higher priority; this should not work.
44    Execute Command                 clic OnGPIO 17 False
45    Execute Command                 clic OnGPIO 17 True
46    Should Not Be On Uart           Interrupt 17, level 1, priority 15
47