1*** Variables ***
2${PROMPT}                      H2U
3
4*** Keywords ***
5Create Platform
6    Execute Command            using sysbus
7    Execute Command            mach create
8    Execute Command            machine LoadPlatformDescription @platforms/boards/arty_litex_vexriscv.repl
9    Execute Command            sysbus LoadELF @https://dl.antmicro.com/projects/renode/arty_litex_vexriscv--firmware.elf-s_438376-e20651f6e9625812f6588ce2b79c978f2c4d7eab
10
11*** Test Cases ***
12Should Boot
13    Create Platform
14    Create Terminal Tester     sysbus.uart
15    Execute Command            showAnalyzer sysbus.uart
16
17    Start Emulation
18
19    Wait For Prompt On Uart    ${PROMPT}
20
21    Provides                   booted-image
22
23Should Control LEDs
24    Requires                   booted-image
25
26    ${led0_tester}=            Create LED Tester  sysbus.cas.led0
27    ${led1_tester}=            Create LED Tester  sysbus.cas.led1
28    ${led2_tester}=            Create LED Tester  sysbus.cas.led2
29    ${led3_tester}=            Create LED Tester  sysbus.cas.led3
30
31    Assert LED State           false  testerId=${led0_tester}
32    Assert LED State           false  testerId=${led1_tester}
33    Assert LED State           false  testerId=${led2_tester}
34    Assert LED State           false  testerId=${led3_tester}
35
36    Write Line To Uart         debug cas leds 1
37    Wait For Prompt On Uart    ${PROMPT}
38    Assert LED State           true   testerId=${led0_tester}
39    Assert LED State           false  testerId=${led1_tester}
40    Assert LED State           false  testerId=${led2_tester}
41    Assert LED State           false  testerId=${led3_tester}
42
43    Write Line To Uart         debug cas leds 3
44    Wait For Prompt On Uart    ${PROMPT}
45    Assert LED State           true  testerId=${led0_tester}
46    Assert LED State           true  testerId=${led1_tester}
47    Assert LED State           false  testerId=${led2_tester}
48    Assert LED State           false  testerId=${led3_tester}
49
50    Write Line To Uart         debug cas leds 7
51    Wait For Prompt On Uart    ${PROMPT}
52    Assert LED State           true  testerId=${led0_tester}
53    Assert LED State           true  testerId=${led1_tester}
54    Assert LED State           true  testerId=${led2_tester}
55    Assert LED State           false  testerId=${led3_tester}
56
57    Write Line To Uart         debug cas leds 15
58    Wait For Prompt On Uart    ${PROMPT}
59    Assert LED State           true  testerId=${led0_tester}
60    Assert LED State           true  testerId=${led1_tester}
61    Assert LED State           true  testerId=${led2_tester}
62    Assert LED State           true  testerId=${led3_tester}
63
64    Write Line To Uart         debug cas leds 0
65    Wait For Prompt On Uart    ${PROMPT}
66    Assert LED State           false  testerId=${led0_tester}
67    Assert LED State           false  testerId=${led1_tester}
68    Assert LED State           false  testerId=${led2_tester}
69    Assert LED State           false  testerId=${led3_tester}
70
71Should Read Switches
72    Requires                   booted-image
73
74    Write Line To Uart         debug cas switches
75    Wait For Line On Uart      0
76
77    Execute Command            cas.switch0 Toggle
78    Write Line To Uart         debug cas switches
79    Wait For Line On Uart      1
80
81    Execute Command            cas.switch1 Toggle
82    Write Line To Uart         debug cas switches
83    Wait For Line On Uart      3
84
85    Execute Command            cas.switch2 Toggle
86    Write Line To Uart         debug cas switches
87    Wait For Line On Uart      7
88
89    Execute Command            cas.switch3 Toggle
90    Write Line To Uart         debug cas switches
91    Wait For Line On Uart      F
92
93    Execute Command            cas.switch0 Toggle
94    Execute Command            cas.switch1 Toggle
95    Execute Command            cas.switch2 Toggle
96    Execute Command            cas.switch3 Toggle
97    Write Line To Uart         debug cas switches
98    Wait For Line On Uart      0
99
100Should Read Buttons
101    Requires                   booted-image
102
103    Write Line To Uart         debug cas buttons read
104    Wait For Line On Uart      0 0
105
106    Execute Command            cas.button0 Toggle
107    Write Line To Uart         debug cas buttons read
108    Wait For Line On Uart      1 1
109
110    Execute Command            cas.button1 Toggle
111    Write Line To Uart         debug cas buttons read
112    Wait For Line On Uart      3 3
113
114    Execute Command            cas.button2 Toggle
115    Write Line To Uart         debug cas buttons read
116    Wait For Line On Uart      7 7
117
118    Execute Command            cas.button3 Toggle
119    Write Line To Uart         debug cas buttons read
120    Wait For Line On Uart      F F
121
122    Execute Command            cas.button0 Toggle
123    Execute Command            cas.button1 Toggle
124    Execute Command            cas.button2 Toggle
125    Execute Command            cas.button3 Toggle
126    Write Line To Uart         debug cas buttons read
127    Wait For Line On Uart      0 F
128
129    Write Line To Uart         debug cas buttons clear
130    Write Line To Uart         debug cas buttons read
131    Wait For Line On Uart      0 0
132
133Should Read Ethernet PHY Status
134    [Documentation]         Reads the status of LiteX Ethernet PHY.
135    Create Platform
136    Create Terminal Tester  sysbus.uart
137
138    # MDIO status: 10Mbps + link down
139    Execute Command         eth.phy VendorSpecific1 0x0
140    Start Emulation
141
142    Wait For Line On Uart   MDIO mode: 10Mbps / link: down
143
144    # MDIO status: 100Mbps + link up
145    Execute Command         eth.phy VendorSpecific1 0x4400
146    Write Line To Uart      mdio_status
147    Wait For Line On Uart   MDIO mode: 100Mbps / link: up
148