Behavior of sdReadTimeout

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
chrismerck
Posts: 21
Joined: Fri Mar 14, 2014 12:35 am
Been thanked: 4 times

Behavior of sdReadTimeout

Post 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. (?)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Behavior of sdReadTimeout

Post 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
Post Reply