Skip to content

Commit

Permalink
ports/psoc6: Bitstream Tests.
Browse files Browse the repository at this point in the history
Signed-off-by: IFX-Anusha <Anusha.TR@infineon.com>
  • Loading branch information
IFX-Anusha committed Mar 20, 2024
1 parent af80dec commit ba939cf
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tests/psoc6/bitstream_listen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import time
from machine import Pin
from machine import bitstream

# Allocate pin based on board
machine = os.uname().machine
if "CY8CPROTO-062-4343W" in machine:
pin_in = 'P12_0'
pin_out = 'P13_7'

elif "CY8CPROTO-063-BLE" in machine:
pin_in = 'P5_3'
pin_out = 'P12_6'

expected_values = [8000, 5000, 8000, 5000, 8000, 50000, 8000, 5000, 3000, 1000, 3000, 10000, 3000, 1000, 3000, 1000]
tolerance = 100

print("bitstream capture")
input_pin = Pin(pin_in, Pin.IN)
periods = []
last_value = 0
p0 = Pin(pin_out, Pin.OUT, value=0)
start_time = time.ticks_us()
current_value =0
for i in range(17):
while (current_value == last_value):
current_value=input_pin.value()
current_time = time.ticks_us()
time_period = time.ticks_diff(current_time, start_time)
last_value=current_value
start_time=current_time
periods.append(time_period)

for i in range(len(periods)-1):
if abs((periods[i+1] - expected_values[i]) <= tolerance):
print("true")
else:
print("false")
17 changes: 17 additions & 0 deletions tests/psoc6/bitstream_listen.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bitstream capture
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
28 changes: 27 additions & 1 deletion tests/psoc6/run_psoc6_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ usage() {
echo " -n run not yet implemented tests only"
echo " -w run wifi tests => needs secrets.py key file>"
echo " -v run virtual filesystem related tests. If followed by -x, runs advance tests too."
echo " -b run bitsream script."
echo " --dev0 device to be used"
echo " --dev1 second device to be used (for multi test)"
echo " --psoc6 run only psoc6 port related tests"
Expand All @@ -39,11 +40,14 @@ for arg in "$@"; do
esac
done

while getopts "acd:e:fhimnptwvx" o; do
while getopts "abcd:e:fhimnptwvx" o; do
case "${o}" in
a)
all=1
;;
b)
bitstream=1
;;
c)
cleanResultsDirectoryFirst=1
;;
Expand Down Expand Up @@ -135,6 +139,10 @@ if [ -z "${afs}" ]; then
afs=0
fi

if [ -z "${bitstream}" ]; then
bitstream=0
fi

if [ -z "${psoc6OnlyMulti}" ]; then
psoc6OnlyMulti=0
fi
Expand Down Expand Up @@ -431,6 +439,24 @@ if [ ${hwext} -eq 1 ]; then
fi


if [ ${bitstream} -eq 1 ]; then

echo " running bitstream tests ... "
echo

chmod 777 ./psoc6/test_scripts/bit.py

python3 ./psoc6/test_scripts/bit.py ${device0} 0

echo " running bitstream listen.."

./run-tests.py --target psoc6 --device ${device1} \
\
psoc6/bitstream_listen.py \
|tee -a ${resultsFile}

fi

### not yet enabled/implemented, therefore failing
if [ ${notYetImplemented} -eq 1 ]; then

Expand Down
27 changes: 27 additions & 0 deletions tests/psoc6/test_inputs/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
import time
import os
from machine import Pin
from machine import bitstream


# Allocate pin based on board
machine = os.uname().machine
if "CY8CPROTO-062-4343W" in machine:
gpio_pin = 'P12_1'
input_pin = 'P13_6'
elif "CY8CPROTO-063-BLE" in machine:
gpio_pin = 'P5_2'
input_pin = 'P12_7'

print("bitstream execution")
timing = [3000000, 1000000, 8000000, 5000000]
buf = bytearray([0xF0])
p0 = Pin(gpio_pin, Pin.OUT, value=0)
input_pin = Pin(input_pin, Pin.IN)
while(input_pin.value()==1):
pass
for i in range(2):
bitstream(p0, 0, timing, buf)


36 changes: 36 additions & 0 deletions tests/psoc6/test_scripts/bit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
import time
import os
import subprocess

device = sys.argv[1]
file_location = "./psoc6/test_inputs/main.py"
remote_directory_path = "/"
mpr_connect = f"../tools/mpremote/mpremote.py connect {device}"
mpr_file_cp = f"{mpr_connect} cp {file_location} :{remote_directory_path}"
mpr_ls = f"{mpr_connect} fs ls /"
mpr_rm = f"{mpr_connect} fs rm "
mpr_reset =f"../tools/mpremote/mpremote.py reset"

def exec(cmd, op_file_path="null"):
if cmd == mpr_rm:
# Check if file is present already
output = subprocess.run(f"{mpr_ls} | grep {op_file_path}", shell=True, capture_output=True)
# If the file is present, remove it
if output.returncode == 0:
subprocess.run(f"{cmd} {op_file_path}", shell=True, capture_output=False)
else:
with open(op_file_path, "a") as file:
subprocess.check_call(cmd, shell=True, stdout=file)

#bistream generation

print("copying file to remote device")
exec(mpr_rm, "main.py")
exec(mpr_file_cp)
print("Resest board")
subprocess.run(mpr_reset, shell=True)




0 comments on commit ba939cf

Please sign in to comment.