Skip to content

Commit

Permalink
tests/ports/psoc6: Final test setup for hil.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <[email protected]>
  • Loading branch information
NikhitaR-IFX committed Nov 26, 2024
1 parent bb203a0 commit 4ff7723
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 109 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ports_psoc6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ jobs:
source tools/ci.sh && ci_psoc6_flash_multiple_devices ${{ matrix.board }} firmware.hex tools/psoc6/${{ runner.name }}-devs.yml
- name: Run psoc6 tests
timeout-minutes: 12
run: |
./tests/ports/psoc6/run_psoc6_tests.sh --test-suite ci-tests --board ${{ matrix.board }} --hil ${{ runner.name }}
run: |
./tests/ports/psoc6/run_psoc6_tests.sh --test-suite pdm_pcm --board ${{ matrix.board }} --hil ${{ runner.name }}
#./tests/ports/psoc6/run_psoc6_tests.sh --test-suite ci-tests --board ${{ matrix.board }} --hil ${{ runner.name }}
- name: Container teardown
if: failure() || success()
run: |
Expand Down
67 changes: 0 additions & 67 deletions tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py

This file was deleted.

18 changes: 0 additions & 18 deletions tests/ports/psoc6/board_ext_hw/multi/pdm_pcm.py.exp

This file was deleted.

22 changes: 0 additions & 22 deletions tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_gen.py

This file was deleted.

122 changes: 122 additions & 0 deletions tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import os
from machine import PDM_PCM, Pin
import machine
import time

# Allocate pin based on board
board = os.uname().machine
if "CY8CPROTO-062-4343W" in board:
clk_pin = "P10_4"
data_pin = "P10_5"
send_signal_to_tx_pin = "P10_3"

elif "CY8CPROTO-063-BLE" in board:
print("SKIP")
raise SystemExit
elif "CY8CKIT-062S2-AI" in board:
clk_pin = "P10_4"
data_pin = "P10_5"


def generate_exp_seq(data):
exp_seq = bytearray(data * 64)
return exp_seq


send_signal = Pin(send_signal_to_tx_pin, mode=Pin.OUT, pull=Pin.PULL_DOWN, value=False)
send_signal.value(0)

print("1. blocking read implementation ")

_sampling_rate = [8000, 16000, 32000, 48000, 22050, 44100]
_mode = [PDM_PCM.MONO_LEFT, PDM_PCM.MONO_RIGHT, PDM_PCM.STEREO]
_bits = 16
exp_data = [[0x00], [0xFF]]
iterations = 100
rounds = 2

for m in range(rounds):
exp_seq = generate_exp_seq(exp_data[m])
if m == 0:
print("*** Test for data high ***")
else:
print("*** Test for data low ***")

for i in range(len(_sampling_rate)): # Check for all sampling rates
set_sampling_rate = _sampling_rate[i]
if _sampling_rate[i] == 22050 or _sampling_rate[i] == 44100:
machine.freq(machine.AUDIO_PDM_22_579_000_HZ)
else:
machine.freq(machine.AUDIO_PDM_24_576_000_HZ)
for j in range(len(_mode)): # Check for all modes
set_mode = _mode[j]
if set_mode == PDM_PCM.STEREO:
iterations = 200
pdm_pcm = PDM_PCM(
0,
sck=clk_pin,
data=data_pin,
sample_rate=set_sampling_rate,
decimation_rate=64,
bits=PDM_PCM.BITS_16,
format=set_mode,
left_gain=0,
right_gain=0,
)
pdm_pcm.init() # Start

for k in range(iterations):
rx_buf = bytearray([1] * 64)
num_read = pdm_pcm.readinto(rx_buf)
# print("buf :", ''.join(f'{x:02x} ' for x in rx_buf))
if rx_buf[:3] == bytearray([exp_data[m][0], exp_data[m][0], exp_data[m][0]]):
is_seq_received = rx_buf == exp_seq
if is_seq_received:
print(
f"data received for mode = {set_mode}, bits = PDM_PCM.BITS_16, rate = {set_sampling_rate} : {is_seq_received}"
)
break
pdm_pcm.deinit()
send_signal.high()
time.sleep(1) # Wait to sync

send_signal.deinit()

###############################################################################
print("\n2. irq non-blocking read implementation ")

rx_done = False


def rx_complete_irq(obj):
global rx_done
rx_done = True


machine.freq(machine.AUDIO_PDM_24_576_000_HZ)
pdm_pcm = PDM_PCM(
0,
sck=clk_pin,
data=data_pin,
sample_rate=set_sampling_rate,
decimation_rate=64,
bits=PDM_PCM.BITS_16,
format=set_mode,
left_gain=0,
right_gain=0,
)

pdm_pcm.init() # Start

rx_buf = bytearray([0] * 64)
pdm_pcm.irq(rx_complete_irq)
num_read = pdm_pcm.readinto(rx_buf)

while not rx_done:
pass

# if we get pass this rx_done flag has been
# modified by the interrupt

print("rx blocking done")
pdm_pcm.deinit()
42 changes: 42 additions & 0 deletions tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_rx.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
1. blocking read implementation
*** Test for data high ***
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 8000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 8000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 8000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 16000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 16000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 16000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 32000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 32000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 32000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 48000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 48000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 48000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 22050 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 22050 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 22050 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 44100 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 44100 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 44100 : True
*** Test for data low ***
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 8000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 8000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 8000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 16000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 16000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 16000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 32000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 32000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 32000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 48000 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 48000 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 48000 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 22050 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 22050 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 22050 : True
data received for mode = 0, bits = PDM_PCM.BITS_16, rate = 44100 : True
data received for mode = 1, bits = PDM_PCM.BITS_16, rate = 44100 : True
data received for mode = 2, bits = PDM_PCM.BITS_16, rate = 44100 : True

2. irq non-blocking read implementation
rx blocking done
50 changes: 50 additions & 0 deletions tests/ports/psoc6/board_ext_hw/multi/pdm_pcm_tx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
from machine import Pin
import time

# Allocate pin based on board
board = os.uname().machine
if "CY8CPROTO-062-4343W" in board:
clk_in_pin = "P10_1"
data_out_pin = "P10_5"
sync_in_pin = "P10_0"
elif "CY8CPROTO-063-BLE" in board:
print("SKIP")
raise SystemExit
elif "CY8CKIT-062S2-AI" in board:
print("SKIP")
raise SystemExit

start_time = time.time()

sig_val = 1
test_done = False


def signal_irq(event):
global sig_val
sig_val = 0


def blocking_delay_ms(delay_ms):
start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < delay_ms:
pass


data_out = Pin(data_out_pin, mode=Pin.OUT, pull=Pin.PULL_DOWN, value=False)
clk_in = Pin(clk_in_pin, Pin.IN, Pin.PULL_DOWN)
sync_data = Pin(sync_in_pin, Pin.IN, Pin.PULL_DOWN)
sync_data.irq(handler=signal_irq, trigger=Pin.IRQ_RISING)

data_out.value(1)
while test_done == False:
while sig_val:
pass
data_out.value(0)
blocking_delay_ms(200000)
test_done = True

data_out.deinit()
clk_in.deinit()
sync_data.deinit()
20 changes: 20 additions & 0 deletions tests/ports/psoc6/run_psoc6_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ usage() {
echo " uart run uart tests"
echo " spi run spi tests"
echo " i2s run i2s tests"
echo " pdm_pcm run pdm_pcm tests"
echo " bitstream run bitstream tests"
echo " watchdog run watchdog tests"
echo " multi-instance run multiple board instances tests"
Expand Down Expand Up @@ -236,6 +237,11 @@ i2s_tests() {
"" "i2s_tx" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/i2s_tx.py"
}

pdm_pcm_tests() {
run_tests "pdm_pcm" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/multi/pdm_pcm_rx.py" \
"" "pdm_pcm_tx" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/pdm_pcm_tx.py"
}

wdt_tests() {
run_tests "wdt" ${dev_test} "${tests_psoc6_dir}/board_only_hw/single/wdt.py"
sleep 2
Expand Down Expand Up @@ -341,6 +347,17 @@ run_ci_tests() {
fi
fi
i2s_tests

if [ "${board}" == "CY8CPROTO-062-4343W" ] || [ "${board}" == "CY8CPROTO-063-BLE" ]; then
dev_test=${devs_b[0]}
dev_stub=${devs_a[0]}
else
if [ "${board}" == "CY8CKIT-062S2-AI" ]; then
dev_test=${devs_c[0]}
dev_stub=${devs_b[0]}
fi
fi
pdm_pcm_tests

if [ "${board}" == "CY8CPROTO-062-4343W" ] || [ "${board}" == "CY8CPROTO-063-BLE" ]; then
dev_test=${devs_a[0]}
Expand Down Expand Up @@ -399,6 +416,9 @@ case ${test_suite} in
"i2s")
i2s_tests
;;
"pdm_pcm")
pdm_pcm_tests
;;
"uart")
uart_tests
;;
Expand Down

0 comments on commit 4ff7723

Please sign in to comment.