From 6de8cec1e9ba74d202d976360fd4e17bfafd88e9 Mon Sep 17 00:00:00 2001 From: Daniel Sawka Date: Wed, 16 Oct 2024 19:35:30 +0200 Subject: [PATCH] devices/pipe-rtt: Properly handle timeout in RTT reads This change fixes the problem of plo's `wait` command not waiting while using RTT console. Read operation was completed immediately instead of blocking for at least `timeout`. JIRA: NIL-596 --- devices/pipe-rtt/device.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/devices/pipe-rtt/device.c b/devices/pipe-rtt/device.c index b9f89c90..64c3e30e 100644 --- a/devices/pipe-rtt/device.c +++ b/devices/pipe-rtt/device.c @@ -22,9 +22,20 @@ static ssize_t pipe_read(unsigned int minor, addr_t offs, void *buff, size_t len, time_t timeout) { (void)offs; - (void)timeout; + time_t start = hal_timerGet(); - return rtt_read(minor + 1, buff, len); + while (1 == 1) { + ssize_t ret = rtt_read(minor + 1, buff, len); + + if (ret != 0) { + return ret; + } + if ((hal_timerGet() - start) >= timeout) { + return -ETIME; + } + } + + return 0; }