Skip to content

Commit 9b9130d

Browse files
committed
tests/ports/psoc6: Stabilize time_pulse_us tests.
Signed-off-by: NikhitaR-IFX <nikhita.rajasekhar@infineon.com>
1 parent 0529b19 commit 9b9130d

6 files changed

Lines changed: 124 additions & 48 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from machine import Pin
2+
import os
3+
import time
4+
5+
# Allocate pin based on board
6+
board = os.uname().machine
7+
if "CY8CPROTO-062-4343W" in board:
8+
pulse_out_pin = "P9_7"
9+
ack_in_pin = "P9_6"
10+
elif "CY8CPROTO-063-BLE" in board:
11+
pulse_out_pin = "P9_4"
12+
ack_in_pin = "P9_6"
13+
elif "CY8CKIT-062S2-AI" in board:
14+
pulse_out_pin = "P9_7"
15+
ack_in_pin = "P9_6"
16+
17+
ack_recvd = False
18+
19+
20+
def cback(pin):
21+
global ack_recvd
22+
ack_recvd = True
23+
24+
25+
def blocking_delay_ms(delay_ms):
26+
start = time.ticks_ms()
27+
while time.ticks_diff(time.ticks_ms(), start) < delay_ms:
28+
pass
29+
30+
31+
pulse_out = Pin(pulse_out_pin, Pin.OUT, value=False)
32+
ack_in = Pin(ack_in_pin, Pin.IN)
33+
ack_in.irq(trigger=Pin.IRQ_RISING, handler=cback)
34+
35+
# Starting condition always low pulse
36+
pulse_out.low()
37+
blocking_delay_ms(500)
38+
39+
while not ack_recvd:
40+
pass # Wait for the Begin ACK signal
41+
42+
ack_recvd = False
43+
44+
# Generate high pulse
45+
pulse_out.high()
46+
while not ack_recvd:
47+
pass # Wait for high received ACK signal
48+
49+
# Wait for 1sec to time the pulse
50+
blocking_delay_ms(1000)
51+
52+
pulse_out.low()
53+
54+
pulse_out.deinit() # Deinitialize the pulse output pin
55+
ack_in.deinit()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from machine import Pin, time_pulse_us
2+
import os
3+
import time
4+
5+
# Allocate pin based on board
6+
board = os.uname().machine
7+
if "CY8CPROTO-062-4343W" in board:
8+
pulse_in_pin = "P9_7"
9+
ack_out_pin = "P9_6"
10+
elif "CY8CPROTO-063-BLE" in board:
11+
pulse_in_pin = "P9_4"
12+
ack_out_pin = "P9_6"
13+
elif "CY8CKIT-062S2-AI" in board:
14+
pulse_in_pin = "P9_7"
15+
ack_out_pin = "P9_6"
16+
17+
pin_high_received = False
18+
19+
20+
def cback(pin):
21+
global pin_high_received
22+
pin_high_received = True
23+
24+
25+
def blocking_delay_ms(delay_ms):
26+
start = time.ticks_ms()
27+
while time.ticks_diff(time.ticks_ms(), start) < delay_ms:
28+
pass
29+
30+
31+
pulse_in = Pin(pulse_in_pin, Pin.IN, Pin.PULL_DOWN)
32+
ack_out = Pin(ack_out_pin, Pin.OUT)
33+
ack_out.low()
34+
35+
width = 0
36+
37+
pulse_in.irq(trigger=Pin.IRQ_RISING, handler=cback)
38+
39+
# Send begin ack to start generating pulse
40+
ack_out.high()
41+
blocking_delay_ms(1000)
42+
ack_out.low()
43+
44+
# Wait to receive pulse high signal
45+
while not pin_high_received:
46+
pass
47+
48+
# Send pulse high recvd ack
49+
ack_out.high()
50+
51+
# Measure the pulse width
52+
width = time_pulse_us(pulse_in, 1, 10000000)
53+
54+
print(
55+
f"Pulse timing verified: {True if (0.98 < (width / 1000000) < 1.2) else 'False, width=' + str(width / 1000000)}"
56+
)
57+
58+
pulse_in.deinit()
59+
ack_out.deinit()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pulse timing verified: True

tests/ports/psoc6/board_ext_hw/single/time_pulse_us.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/ports/psoc6/board_ext_hw/single/time_pulse_us.py.exp

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/ports/psoc6/run_psoc6_tests.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ pwm_tests() {
207207
run_tests "pwm" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/single/pwm.py"
208208
}
209209

210-
time_pulse_tests() {
211-
run_tests "time_pulse" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/single/time_pulse_us.py"
212-
}
210+
#time_pulse_tests() {
211+
# run_tests "time_pulse" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/single/time_pulse_us.py"
212+
#}
213213

214214
pin_tests() {
215215
run_tests "pin" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/single/pin.py"
@@ -223,6 +223,7 @@ i2c_tests() {
223223
run_tests "i2c" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/single/i2c.py"
224224
}
225225

226+
226227
uart_tests() {
227228
run_tests "uart" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/single/uart.py"
228229
}
@@ -242,6 +243,11 @@ i2s_tests() {
242243
"" "i2s_tx" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/i2s_tx.py"
243244
}
244245

246+
time_pulse_tests() {
247+
run_tests "time_pulse" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/multi/time_pulse_us.py" \
248+
"" "time_pulse_sig_gen" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/time_pulse_sig_gen.py"
249+
}
250+
245251
pdm_pcm_tests() {
246252
run_tests "pdm_pcm" ${dev_test} "${tests_psoc6_dir}/board_ext_hw/multi/pdm_pcm_rx.py" \
247253
"" "pdm_pcm_tx" ${dev_stub} "${tests_psoc6_dir}/board_ext_hw/multi/pdm_pcm_tx.py"

0 commit comments

Comments
 (0)