1*** Variables ***
2${UART}                           sysbus.lpuart2
3${CAN}                            sysbus.can0
4${CAN_HUB}                        canHub
5${URI}                            https://dl.antmicro.com/projects/renode/
6
7${CAN_COUNTER_ELF}                @${URI}/mr_canhubk3--zephyr-can-counter.elf-s_1959844-b2284bfd7adff900c7d6ac7fa06bb5ba3291b0e4
8${CAN_COUNTER_NO_LOOPBACK_ELF}    @${URI}/mr_canhubk3--zephyr-can-counter--no-loopback.elf-s_1959384-b17eb95f04cb75ef5a7781cdaad708db8a7f7449
9
10*** Keywords ***
11Create CAN Hub
12    Execute Command               emulation CreateCANHub "${CAN_HUB}" False
13
14Create MR CANHUBK3 Machine
15    [Arguments]                   ${binary}    ${name}=machine-0
16    Execute Command               $name="${name}"
17    Execute Command               $bin=${binary}
18    Execute Command               include @tests/peripherals/mr_canhubk3.resc
19    Execute Command               connector Connect ${CAN} ${CAN_HUB}
20
21*** Test Cases ***
22Should Receive CAN Frames On Loopback
23    Create CAN Hub
24    Create MR CANHUBK3 Machine    ${CAN_COUNTER_ELF}
25    Create Terminal Tester        ${UART}
26
27    # Wait for several successful transmissions
28    ${cnt}=                   Set Variable  40
29    FOR  ${i}  IN RANGE  0  ${cnt}
30        Wait For Line On Uart     Counter received: ${i}
31    END
32
33Should Exchange CAN Frames Between Machines
34    Create CAN Hub
35    Create MR CANHUBK3 Machine    ${CAN_COUNTER_NO_LOOPBACK_ELF}   name=machine-0
36    ${tester-0}=                  Create Terminal Tester  ${UART}  machine=machine-0
37
38    Create MR CANHUBK3 Machine    ${CAN_COUNTER_NO_LOOPBACK_ELF}   name=machine-1
39    ${tester-1}=                  Create Terminal Tester  ${UART}  machine=machine-1
40
41    # Lower quantum to keep synchronization between machines
42    Execute Command               emulation SetGlobalQuantum "0.000025"
43    Execute Command               emulation SetGlobalSerialExecution True
44
45    # Wait for several successful transmissions
46    ${cnt}=                       Set Variable  40
47    FOR  ${i}  IN RANGE  0  ${cnt}
48        Wait For Line On Uart     Counter received: ${i}  testerId=${tester-0}
49        Wait For Line On Uart     Counter received: ${i}  testerId=${tester-1}
50    END
51