Page 1 of 1

Behavior of sdReadTimeout

Posted: Thu Apr 10, 2014 7:15 pm
by chrismerck
I have a serial device that sends a byte once every 100ms at 115200 baud.

When I call sdReadTimeout, I expect it to timeout after the specified time, regardless of the incoming traffic pattern. So, given the following code, we would expect to return after at most 1sec:

Code: Select all

uint8_t buf[512];
sdReadTimeout(&SD1,buf,sizeof(buf),MS2ST(1000));


However, what I see is sdReadTimeout takes ~1min to timeout.

This seems to be because internally, qwait is called with the same 'time' value each time some data is received, without decrementing 'time' accordingly.

Code: Select all

// from chIQReadTimeout in chqueues.c
...
      if (qwait((GenericQueue *)iqp, time) != Q_OK) {
...


Of course, there are workarounds, but I'm just wondering if this behavior is intentional. (?)

Re: Behavior of sdReadTimeout

Posted: Thu Apr 10, 2014 8:00 pm
by Giovanni
The timeout is measured from the last received character not from function entry. Like you wrote there are other ways to achieve an absolute timeout.

Decrementing "time" is not sufficient because the time spent in qwait() is not known, a check using system time should be performed and that would make a simple function like that much heavier.

Giovanni