1*** Variables ***
2${UART}                      sysbus.uart
3${MC3635}                    sysbus.ffe.i2cMaster0.mc3635
4${URI}                       @https://dl.antmicro.com/projects/renode
5
6*** Keywords ***
7Create Machine
8    [Arguments]  ${elf}
9
10    Execute Command          mach create
11    Execute Command          machine LoadPlatformDescription @platforms/boards/eos-s3-quickfeather.repl
12
13    Execute Command          sysbus LoadELF ${URI}/${elf}
14
15Assert Flag
16    [Arguments]              ${register}  ${position}  ${value}
17    ${flag}                  Evaluate    str((${register} >> ${position}) & 0x1)
18    Should Be Equal          ${flag}   ${value}
19
20Feed Test Data
21    [Arguments]              ${peripheral}
22
23    # The test binary sets mode to the continuous sampling on the beggining of configuration,
24    # and some samples are fed before we enter the main loop. Hence we start with a few empty ones.
25    Execute Command          ${peripheral} FeedAccelerationSample 0.0 0.0 0.0 5
26
27    # One sample short from 0.5s worth of data
28    FOR  ${index}  IN RANGE  27
29         ${x}=  Evaluate     -1.0 + ${index} * (2/26)        # Linear sweep from -1 to 1 over 27 samples
30         ${y}=  Evaluate     -2.0 + ${index} * (2/26)        # Linear sweep from -2 to 0 over 27 samples
31         ${z}=  Evaluate     2.0 - ${index} * (2/26)         # Linear sweep from +2 to 0 over 27 samples
32         Execute Command     ${peripheral} FeedAccelerationSample ${x} ${y} ${z}
33    END
34
35*** Test Cases ***
36Should Output Data
37    Create Machine            quick_feather--mc3635_ssi_ai_app.elf-s_947900-114d2e13b2ceffb6144135e61d1b3c2a499e35c3
38    Create Terminal Tester    ${UART}
39    Provides                  Ready Machine
40
41    Start Emulation
42
43    Wait For Line On Uart     X 0,Y 0,Z 0
44
45Should Work With FeedAccelerationSample
46    Requires                  Ready Machine
47
48    Feed Test Data            ${MC3635}
49    Start Emulation
50
51    Wait For Line On Uart     X -8191,Y -16383,Z 16383
52    Wait For Line On Uart     X 0,Y -8191,Z 8191
53    Wait For Line On Uart     X 8191,Y 0,Z 0
54
55Should Be Able To Disable Axis
56    Requires                  Ready Machine
57
58    Execute Command           ${MC3635} DefaultAccelerationX 1.0
59    Execute Command           ${MC3635} DefaultAccelerationY 1.0
60    Execute Command           ${MC3635} DefaultAccelerationZ 1.0
61    Start Emulation
62
63    Wait For Line On Uart     X 8191,Y 8191,Z 8191
64    Execute Command           ${MC3635} RegisterWrite 0x10 0x45 # Mode CWAKE, Z disabled
65    Wait For Line On Uart     X 8191,Y 8191,Z 0
66    Execute Command           ${MC3635} RegisterWrite 0x10 0x25 # Mode CWAKE, Y disabled
67    Wait For Line On Uart     X 8191,Y 0,Z 8191
68    Execute Command           ${MC3635} RegisterWrite 0x10 0x15 # Mode CWAKE, X disabled
69    Wait For Line On Uart     X 0,Y 8191,Z 8191
70
71Should Log Error If Some Of Reserved Bits Have Wrong Value
72    Requires                  Ready Machine
73    Create Log Tester         1
74    Start Emulation
75
76    Execute Command           ${MC3635} RegisterWrite 0x20 0x00
77    Wait For Log Entry        Invalid value written to offset 0x20 reserved bits. Allowed values = 0b0000xx01
78    Execute Command           ${MC3635} RegisterWrite 0x21 0x00
79    Wait For Log Entry        Invalid value written to offset 0x21 reserved bits. Allowed values = 0b1000xx00
80    Execute Command           ${MC3635} RegisterWrite 0x22 0x01
81    Wait For Log Entry        Invalid value written to offset 0x22 reserved bits. Allowed values = 0b0000xx00
82
83Should Log Error On Selecting Unimplemented Modes
84    Requires                  Ready Machine
85    Create Log Tester         1
86    Start Emulation
87
88    Execute Command           ${MC3635} RegisterWrite 0x10 0x02 # Mode SNIFF
89    Wait For Log Entry        Sniff mode unimplemented. Switching to Standby
90    Execute Command           ${MC3635} RegisterWrite 0x10 0x06 # Mode SWAKE
91    Wait For Log Entry        Swake mode unimplemented. Switching to Standby
92
93Should Set Flags
94    # This test relies on the configuration of the emulation and the binary itself.
95    # Any changes require adjusting the `emulation RunFor` arguments
96
97    ${NEW_DATA_REG}=          Evaluate  0x08
98    ${OVR_DATA_REG}=          Evaluate  0x01
99    ${NEW_DATA_POSITION}=     Evaluate  3
100    ${OVR_DATA_POSITION}=     Evaluate  0
101
102    Requires                  Ready Machine
103
104    # Run until the peripheral is set to `continuous sampling` but the configuration is not yet completed and no samples are read
105    Execute Command           emulation RunFor '0.006'
106    ${OVR_DATA}=              Execute Command  ${MC3635} RegisterRead ${OVR_DATA_REG}
107    ${NEW_DATA}=              Execute Command  ${MC3635} RegisterRead ${NEW_DATA_REG}
108
109    # Assert the flags indicate that samples are being overwritten
110    Assert Flag               ${NEW_DATA}  ${NEW_DATA_POSITION}  1
111    Assert Flag               ${OVR_DATA}  ${OVR_DATA_POSITION}  1
112
113    # Read sample and check if flags are adjusted
114    Execute Command           ${MC3635} RegisterRead 0x2
115    ${OVR_DATA}=              Execute Command  ${MC3635} RegisterRead ${OVR_DATA_REG}
116    ${NEW_DATA}=              Execute Command  ${MC3635} RegisterRead ${NEW_DATA_REG}
117    Assert Flag               ${NEW_DATA}  ${NEW_DATA_POSITION}  0
118    Assert Flag               ${OVR_DATA}  ${OVR_DATA_POSITION}  1
119
120    # Wait for the configuration to end, and then for a few more samples. Then assert that samples are not being overwritten
121    Execute Command           emulation RunFor '0.05'
122    ${OVR_DATA}=              Execute Command  ${MC3635} RegisterRead ${OVR_DATA_REG}
123    Assert Flag               ${OVR_DATA}  ${OVR_DATA_POSITION}  0
124