chTimeIsInRangeX always false? Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chTimeIsInRangeX always false?

Post by Giovanni »

Thanks, let me check.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chTimeIsInRangeX always false?

Post by Giovanni »

Hi,

If prev==next then the window is the whole time range so the thread goes to sleep for a long time but not forever, I think the behavior is correct but also consider that calling chThdSleepUntilWindowed() with prev==next makes no sense because you want the thread to sleep while the system time is within the specified window.

Previously prev==next meant a zero size window, now it is a "whole" size window, both make no sense IMO or I am just missing the use case.

Giovanni
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: chTimeIsInRangeX always false?

Post by alex31 »

Hello,

I agree with you that calling chThdSleepUntilWindowed with prev == next is no sense.

The problem arose when next is the result of a calculation of type next = now + something,

° before patch #1060 there was no need to protect the call to chThdSleepUntilWindowed is something was 0 (and then prev == next)

° now with the patch, there is a behaviour change and one must verify that prev != next before calling chThdSleepUntilWindowed.

I say that because i had a program that suddenly stopped to work after commiting chibios 19 stable to the last version, and it tooks me some time to understand why and to protect the call to chThdSleepUntilWindowed.

So the sense of my post is this question : should the test be outside chThdSleepUntilWindowed as it need to be now, or inside, to avoid a behavior change that can conduct existing program to behave differently ?


Alexandre
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chTimeIsInRangeX always false?

Post by Giovanni »

Good point, let me think about this.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chTimeIsInRangeX always false?

Post by Giovanni »

I decided to restore the original behavior and document it correctly.

Undone bug #1060.

Giovanni
User avatar
wurstnase
Posts: 121
Joined: Tue Oct 17, 2017 2:24 pm
Has thanked: 43 times
Been thanked: 30 times

Re: chTimeIsInRangeX always false?

Post by wurstnase »

The I2C fallback needs now some rework again.

Something like this:

Code: Select all

diff --git a/os/hal/lib/fallback/I2C/hal_i2c_lld.c b/os/hal/lib/fallback/I2C/hal_i2c_lld.c
index f324333dc..e3e3ec86f 100644
--- a/os/hal/lib/fallback/I2C/hal_i2c_lld.c
+++ b/os/hal/lib/fallback/I2C/hal_i2c_lld.c
@@ -94,6 +94,9 @@ static inline msg_t i2c_check_arbitration(I2CDriver *i2cp) {
 
 static inline msg_t i2c_check_timeout(I2CDriver *i2cp) {
 
+  if (i2cp->start == i2cp->end)
+      return MSG_OK;
+
   if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), i2cp->start, i2cp->end)) {
     i2c_write_stop(i2cp);
     return MSG_TIMEOUT;
@@ -105,6 +108,7 @@ static inline msg_t i2c_check_timeout(I2CDriver *i2cp) {
 static msg_t i2c_wait_clock(I2CDriver *i2cp) {
 
   while (palReadLine(i2cp->config->scl) == PAL_LOW) {
+    if (i2cp->start != i2cp->end)
     if (!osalTimeIsInRangeX(osalOsGetSystemTimeX(), i2cp->start, i2cp->end)) {
       return MSG_TIMEOUT;
     }
Post Reply