Skip to content

Commit 617f42e

Browse files
committed
Merge branch '21-etr01sv-30-add-gpo-support' into 'master'
Resolve "[ETR01SV-30] Add GPO support" Closes #21 See merge request internal/development-environment/ts-tvl!15
2 parents 175cabc + ce2d397 commit 617f42e

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

tvl/host/low_level_communication.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,80 @@ def ll_receive(
141141
return response
142142

143143

144+
def ll_receive_check_irq(
145+
target: TropicProtocol,
146+
logger: logging.Logger,
147+
max_polling: int = 10,
148+
wait: int = 0,
149+
retry_wait: int = 0,
150+
) -> bytes:
151+
if wait > 0:
152+
logger.info("Waiting before polling.")
153+
logger.debug(f"Wait time: {wait} us.")
154+
target.wait(wait)
155+
156+
# poll for status
157+
logger.info("Polling for STATUS byte.")
158+
159+
for i in range(start := 1, max_polling + start):
160+
# wait a bit until next try except at the beginning of the loop
161+
if i != start and retry_wait > 0:
162+
logger.info("Waiting before next try.")
163+
logger.debug(f"Retry wait time: {retry_wait} us.")
164+
target.wait(retry_wait)
165+
166+
logger.debug(f"- attempt no. {i}.")
167+
168+
# check a new l2 response is ready
169+
if target.irq_state():
170+
break
171+
172+
else:
173+
raise TargetTimeoutError(f"Target not ready after {max_polling} attempts.")
174+
175+
# start communication
176+
logger.info("Driving Chip Select to LOW.")
177+
target.spi_drive_csn_low()
178+
179+
# send GET_RESP and a few padding bytes
180+
recvd = target.spi_send(bytes([L2IdFieldEnum.GET_RESP]) + bytes(MIN_L2_FRAME_LEN))
181+
182+
# CHIP_STATUS field - one byte
183+
chip_status = recvd[0]
184+
try:
185+
chip_status = L1ChipStatusFlag(chip_status)
186+
logger.debug(f"CHIP_STATUS: {chip_status!s}.")
187+
except ValueError:
188+
logger.debug(f"Unknown CHIP_STATUS: {chip_status:#04x}.")
189+
190+
# STATUS field - one byte
191+
status = recvd[1]
192+
try:
193+
status = L2StatusEnum(status)
194+
logger.debug(f"STATUS: {status!s}.")
195+
except ValueError:
196+
logger.debug(f"Unknown STATUS: {status:#04x}.")
197+
198+
# start accumulating bytes
199+
response = recvd[1:]
200+
201+
# LEN field - one byte
202+
rsp_len = response[1]
203+
logger.debug(f"RSP_LEN: {rsp_len:#04x}.")
204+
205+
# fetching remaining bytes
206+
if rsp_len > 0:
207+
logger.debug(f"Fetching {rsp_len} remaining bytes.")
208+
response += target.spi_send(bytes(rsp_len))
209+
210+
# end communication
211+
logger.info("Driving Chip Select to HIGH.")
212+
target.spi_drive_csn_high()
213+
214+
logger.debug(f"Received {response}.")
215+
return response
216+
217+
144218
def ll_send_l2_request(
145219
data: bytes,
146220
target: TropicProtocol,

tvl/protocols.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ def power_off(self) -> None:
3333
def wait(self, usecs: int) -> None:
3434
"""Wait `usecs` microseconds in the chip time reference."""
3535
...
36+
37+
def irq_state(self) -> bool:
38+
"""
39+
Get state of the IRQ pin.
40+
Returns `True` if a new L2 response is ready, `False` otherwise.
41+
"""
42+
...

0 commit comments

Comments
 (0)