1*** Variables ***
2${echo_i2c_peripheral}              ${CURDIR}/echo-i2c-peripheral.py
3@{HUMIDITY_SAMPLES}                 10  20  30  40  50  60  70  80  90  100
4@{TEMPERATURE_SAMPLES}              15  17  19  21  23  25  27  29  31  33
5${URL}                              https://dl.antmicro.com/projects/renode
6${HELLO_WORLD_ELF}                  ${URL}/renesas-da1459x-uart_hello_world.elf-s_1302844-67f230aeae16f04f9e6e9e1ac1ab1ceb133dc2a1
7${HELLO_WORLD_BIN}                  ${URL}/renesas-da1459x-uart_hello_world.bin-s_42820-89e34783fa568d03c826357dceaa80c3637c14e1
8${WATCHDOG_ELF}                     ${URL}/renesas-da1459x-watchdog_sample.elf-s_1303312-8bc26c376a46712a15126400d9ededc496fd2037
9${WATCHDOG_BIN}                     ${URL}/renesas-da1459x-watchdog_sample.bin-s_41400-a4756b01832abd9bd41143bd7c27db7b39db6031
10${ADC_ELF}                          ${URL}/renesas-da1459x-adc_sample.elf-s_1412432-54c1b6468094ec1439f16264fe4a9447b4d69567
11${ADC_BIN}                          ${URL}/renesas-da1459x-adc_sample.bin-s_42412-84790dc8f65a890e952e59353e80f4708ca4325f
12${ADC_RESD}                         ${URL}/renesas_da14_gpadc.resd-s_49-d7ebebfafe5c44561381ab5c3ffe65266f0a8ad3
13${GPIO_ELF}                         ${URL}/renesas-da1459x-gpio_sample.elf-s_1309028-7708a94edad0e9f9d64725c562dd18e2aebb0d96
14${GPIO_BIN}                         ${URL}/renesas-da1459x-gpio_sample.bin-s_45084-d1c4c9a304a8b3176b3dc6feb89237ae3d48351a
15${GPT_ELF}                          ${URL}/renesas-da1459x-gpt_sample.elf-s_1305560-b68c731499af957e243d1abdd346d8bf7c59c30f
16${GPT_BIN}                          ${URL}/renesas-da1459x-gpt_sample.bin-s_44196-90bb5fd7a2da259e36db86eccfb9b6b4f6177b87
17${DMA_BIN}                          ${URL}/renesas-da1459x-dma_mem_to_mem.bin-s_45332-cb73b4ea7fc562627ba10e9d64d2128527917273
18${DMA_ELF}                          ${URL}/renesas-da1459x-dma_mem_to_mem.elf-s_1301508-5370b27c1b1a252e07446758579c5fefaff168a9
19${FREERTOS_RETARGET_ELF}            ${URL}/renesas-da1459x-freertos_retarget.elf-s_1379120-5728b9a9cca03e23e66c32db302e356532fcfc52
20${FREERTOS_RETARGET_BIN}            ${URL}/renesas-da1459x-freertos_retarget.bin-s_63072-e28ce2134937840990ae4be78a3da330595f48e8
21${SPI_BIN}                          ${URL}/renesas-da1459x-spi_sample.bin-s_43188-944034990fb62e11fe2738530f1420b6e232819a
22${SPI_ELF}                          ${URL}/renesas-da1459x-spi_sample.elf-s_1490188-9f030ab673cc588fb2c19ed3da3fde7d973259e7
23${I2C_BIN}                          ${URL}/renesas-da1459x-i2c_sample.bin-s_36032-0cb6f278b3467dfbbf80f14b8504db7f2552c113
24${I2C_ELF}                          ${URL}/renesas-da1459x-i2c_sample.elf-s_1500812-4323681e8ecb9c7ca31db357a86e0348477c6894
25${I2C_DMA_BIN}                      ${URL}/renesas-da14592--sdk-i2c_example.bin-s_68956-a27edc575b95fc553d5d626afe5e7c5581be1977
26${I2C_DMA_ELF}                      ${URL}/renesas-da14592--sdk-i2c_example.elf-s_1483872-07e845601c2acfcd439249f3ba3e5d19cdc37445
27
28*** Keywords ***
29Create Machine
30    [Arguments]                     ${bin}  ${symbolsElf}
31    Execute Command                 set bin @${bin}
32    Execute Command                 set symbolsElf @${symbolsElf}
33    Execute Command                 include @scripts/single-node/renesas-da14592.resc
34
35Check Acceleration Values
36    [Arguments]                     ${x}  ${y}  ${z}
37    Execute Command                 sysbus.spi.adxl372 AccelerationX ${x}
38    Execute Command                 sysbus.spi.adxl372 AccelerationY ${y}
39    Execute Command                 sysbus.spi.adxl372 AccelerationZ ${z}
40
41    Wait For Line On Uart           X = ${x}, Y = ${y}, Z = ${z}
42
43Create Echo Peripheral
44    Execute Command                 machine LoadPlatformDescriptionFromString "dummy: Mocks.DummyI2CSlave @ i2c 0x75"
45    Execute Command                 include "${echo_i2c_peripheral}"
46    Execute Command                 setup_echo_i2c_peripheral "sysbus.i2c.dummy"
47
48*** Test Cases ***
49UART Should Work
50    Create Machine                  ${HELLO_WORLD_BIN}    ${HELLO_WORLD_ELF}
51    Create Terminal Tester          sysbus.uart1
52
53    Wait For Line On Uart           Hello, world!    pauseEmulation=true
54    Provides                        machine-after-hello-world
55
56Watchdog Should Reset Machine Continuously If Not Frozen
57    Requires                        machine-after-hello-world
58    Create Log Tester               5
59
60    # Let's check this sample without GeneralPurposeRegisters containing Watchdog freeze register.
61    # It should reset over and over again without the ability to freeze it.
62    Execute Command                 sysbus Unregister sysbus.gp_regs
63
64    # Failed attempt to freeze watchdog.
65    Wait For Log Entry              WriteDoubleWord to non existing peripheral at 0x50050300, value 0x8
66
67    # And resets all over the place.
68    Wait For Log Entry              sys_wdog: Reseting machine
69    Wait For Log Entry              sys_wdog: Reseting machine
70    Wait For Log Entry              sys_wdog: Reseting machine
71
72Freezing Watchdog Should Work
73    Requires                        machine-after-hello-world
74    Create Log Tester               5
75    Execute Command                 logLevel -1 sysbus.sys_wdog
76    Execute Command                 sysbus LogPeripheralAccess sysbus.gp_regs
77
78    # Sample freezes Watchdog after reaching limit which prevents resetting machine.
79    Wait For Log Entry              sys_wdog: Limit reached
80    Wait For Log Entry              WriteUInt32 to 0x0 (SetFreeze), value 0x8
81    Wait For Log Entry              sys_wdog: Freeze set
82
83    Should Not Be In Log            sys_wdog: Resetting machine
84
85Test Watchdog
86    Create Machine          ${WATCHDOG_BIN}  ${WATCHDOG_ELF}
87
88    Create Log Tester       5    defaultPauseEmulation=true
89    Execute Command         logLevel -1 sysbus.sys_wdog
90
91    Wait For Log Entry      sys_wdog: Ticker value set to: 0x1FFF
92
93    # The application initializes the sys_wdog and then loops to refresh the watchdog 100 times.
94    FOR  ${i}  IN RANGE  100
95        Wait For Log Entry      sys_wdog: Ticker value set to: 0x1FFF
96    END
97
98    # After NMI exception, binary falls into while(true) loop while waiting for the watchdog to reset the machine.
99    # We set the quantum and advance immediately to speed up the test.
100    Execute Command         emulation SetGlobalQuantum "0.001"
101    Execute Command         emulation SetAdvanceImmediately true
102
103    # The application loops waiting for the watchdog to reset the machine.
104    Wait For Log Entry      sys_wdog: Limit reached     timeout=85
105    Wait For Log Entry      sys_wdog: Triggering IRQ
106
107    # hw_watchdog_handle_int freezes watchdog so let's unfreeze it afterwards and wait for reset.
108    Execute Command         sysbus LogPeripheralAccess sysbus.gp_regs
109    Wait For Log Entry      WriteUInt32 to 0x0 (SetFreeze), value 0x8
110    Execute Command         sys_wdog Frozen false
111
112    # It should take about 160ms of virtual time after NMI to reset the machine.
113    Wait For Log Entry      sys_wdog: Limit reached    timeout=0.17
114    Wait For Log Entry      sys_wdog: Reseting machine
115
116Test GPADC
117    Create Machine                  ${ADC_BIN}   ${ADC_ELF}
118    Create Terminal Tester          sysbus.uart1
119    Execute Command                 sysbus.gpadc FeedSamplesFromRESD @${ADC_RESD} 6 6
120
121    Wait For Line On Uart           ADC read completed
122    Wait For Line On Uart           Number of samples: 21, ADC result value: 19026
123
124GPIO Should Work
125    Create Machine                  ${GPIO_BIN}    ${GPIO_ELF}
126    Create Terminal Tester          sysbus.uart1
127
128    FOR  ${i}  IN RANGE  2
129        FOR  ${j}  IN RANGE  2
130            Wait For Line On Uart           Initial GPIO port: ${i} pin: ${j} val: 0
131            Wait For Line On Uart           Updated GPIO port: ${i} pin: ${j} val: 1
132        END
133    END
134
135Timer Should Work
136    Create Machine                  ${GPT_BIN}     ${GPT_ELF}
137    Create Terminal Tester          sysbus.uart1  defaultPauseEmulation=true
138
139    Wait For Line On Uart           Hello, world!
140
141    # Let's freeze watchdog cause it isn't done by software.
142    Execute Command                 sysbus.sys_wdog Frozen true
143
144    # Timer is configured to fire approx. once per second
145    Wait For Line On Uart           Timer tick!  timeout=1.1
146    Wait For Line On Uart           Timer tick!  timeout=1.1
147    Wait For Line On Uart           Timer tick!  timeout=1.1
148
149DMA Should Work
150    Create Machine                  ${DMA_BIN}    ${DMA_ELF}
151    Create Terminal Tester          sysbus.uart1
152
153    # Let's freeze watchdog cause it isn't done by software.
154    Execute Command                 sysbus.sys_wdog Frozen true
155
156    Wait For Line On Uart           SRC: { 0 1 2 3 4 5 6 7 8 9 }
157    Wait For Line On Uart           DEST: { 0 0 0 0 0 0 0 0 0 0 }
158    Wait For Line On Uart           Transfer completed
159    Wait For Line On Uart           DEST: { 0 1 2 3 4 5 6 7 8 9 }
160
161freertos_retarget Should work
162    Create Machine                  ${FREERTOS_RETARGET_BIN}     ${FREERTOS_RETARGET_ELF}
163
164    Create Terminal Tester          sysbus.uart1
165    Create Log Tester               10
166
167    # Wait for the bootrom to finish
168    # At the end, it remaps the eflash to 0x0 and restarts the machine
169    Wait For Log Entry              Successfully remapped eflash to address 0x0, restarting machine
170    Wait For Log Entry              cpu_m33: PC set to 0x200, SP set to 0x20005EF8
171
172    Wait For Prompt On Uart           \#
173
174Should Read Samples From ADXL372 Over SPI
175    Create Machine                  ${SPI_BIN}  ${SPI_ELF}
176    Execute Command                 machine LoadPlatformDescriptionFromString "adxl372: Sensors.ADXL372 @ spi 1"
177
178    Create Terminal Tester          sysbus.uart1  defaultPauseEmulation=true
179
180    Wait For Line On Uart           Starting SPI app test
181    Wait For Line On Uart           Device ID: 0xAD
182    Wait For Line On Uart           Part ID: 0xFA
183
184    Check Acceleration Values       0  0  0
185    Check Acceleration Values       1  0  0
186    Check Acceleration Values       5  3  7
187    Check Acceleration Values       3  56  12
188
189Should Pass Communication Test With Sample Echo Slave
190    Create Machine                  ${I2C_BIN}  ${I2C_ELF}
191
192    Create Echo Peripheral
193    Create Log Tester               1
194
195    Wait For Log Entry              i2c.dummy: Test suite passed  level=Info
196
197I2C Should Work With DMA Triggers
198    Create Machine                  ${I2C_DMA_BIN}    ${I2C_DMA_ELF}
199    Execute Command                 machine LoadPlatformDescriptionFromString "hs3001: Sensors.HS3001 @ i2c 0x44"
200
201    Create Terminal Tester          sysbus.uart1  defaultPauseEmulation=true
202
203    Wait For Line On Uart           I2C init
204
205    FOR    ${index}    ${element}    IN ENUMERATE    @{HUMIDITY_SAMPLES}
206        Execute Command            sysbus.i2c.hs3001 Temperature ${TEMPERATURE_SAMPLES}[${index}]
207        Execute Command            sysbus.i2c.hs3001 Humidity ${HUMIDITY_SAMPLES}[${index}]
208
209        Wait For Line On Uart      Successfully read I2C
210        Wait For Line On Uart      Hum: ${HUMIDITY_SAMPLES}[${index}] Temp: ${TEMPERATURE_SAMPLES}[${index}]
211    END
212