This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
I see the systime_t type is unsigned then the condition if((time -= chTimeNow()) > 0) is always true and the time value is very long time(in case time < chTimeNow()) . I think it may be fixed like this
The implementation assumes that all the specifiable instants are in the future, does it make sense to wait until some instant in the past?
If you need a "sleep until" that is tolerant of deadline violations then this is something different, probably I could add that code to version 3.0 after finding a proper name for it.
Something like chThdWaitUntilButExitIfTheTimeIsInTheRecentPast()
You are not bothering me, you same opinion has already been expressed several other times, there are at least 2 tickets on the tracker about this and I think the idea is basically good.
I think that an alternate API should be introduced and I am really looking for a meaningful name
A serious name could be chThdWaitAtLeastUntil() and your implementation would fit that.
And don't forget that the time point value specified to a chThdWaitAtLeastUntil(systime_t time_point) function must deal with wraparound of the time values. For instance if systime_t is a uint32_t, and it is implemented as milliseconds, then it will wrap around from 0xFFFF FFFF to zero approximately every 50 days. So you can't just do a greater-than comparison to determine if the specified time_point is in the past or not. You might have to add the requirement that time_point is within half the range of systime_t of the current time, so that you can divide the possible systime_t values into two domains of past and present values. Time wraparound is a tricky issue.
systime_t prev = chVTGetSystemTime(); while (1) { /* Do Something.*/ prev = chThdSleepUntilWindowed(prev, prev + MS2ST(500)); }
Note that if "Do Something*/ exceeds the time slot then timings become unreliable, the function is just executed as fast as possible, the functionality becomes non deterministic.