chVTSetI infinite loop

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

chVTSetI infinite loop

Post by russian »

I am not yet sure how I got there, but my app gets into an infinite loop inside chVTSetI.

So, I have a piece of code

Code: Select all

   if (offset == 0) {
      xxx;
      return;
   }

   chSysLockFromIsr();
   chVTSetI(&signal->signalTimer, offset, &outCallback, signal);
   chSysUnlockFromIsr();
   }

(actually, there is a parameter check time != TIME_IMMEDIATE anyway)
and sometimes my code was hanging. Debugger showed an infinite loop inside chVTSetI, I have added an asserting an it did fail!

Code: Select all

  while (p->vt_time < time) {
     int isOk = p->vt_time!=0 || p!=p->vt_next;
     chDbgCheck(isOk, "timer constraint");
     if(!isOk)
        break;
    time -= p->vt_time;
    p = p->vt_next;
  }

putput:

Code: Select all

FATAL "timer constraint"()

I use 2.4.3 and I have some DBG checks enabled:
CH_DBG_ENABLE_ASSERTS=1
CH_DBG_ENABLE_CHECKS=1
CH_DBG_SYSTEM_STATE_CHECK=1
CH_DBG_ENABLE_STACK_CHECK=1

Would this be considered a bug in ChibiOS that I can get in such a state? Any hints on how I could have broken the internal constraint?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chVTSetI infinite loop

Post by Giovanni »

Probably you thy to set a timer which is already active, this destroys the list of timers.

You have to do:

Code: Select all

lock
if timer_is armed
  reset_timer
set_timer
unlock


Giovanni
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: chVTSetI infinite loop

Post by russian »

Looks like this has fixed the issue, thank you!

If that's the constraint of this method please consider adding this check into chVTSetI? On the other hand, it's impossible to protect from everything...

PS: another tiny comment in this area - the @brief for chDbgPanic method says 'Prints a panic message on the console' - but does it in fact prints anything? I did not find any references to dbg_panic_msg field, is it simply a variable for use via debugger?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chVTSetI infinite loop

Post by Giovanni »

Hi,

This is scheduled for 3.0, I don't to break the API for the current version.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: chVTSetI infinite loop

Post by steved »

Giovanni wrote:Hi,

This is scheduled for 3.0, I don't to break the API for the current version.

Giovanni

Could it be achieved with a new function retriggerTimer()?

Or, better still, createOrRetriggerTimer()?

(I often have a need for the retriggerTimer() function - mainly for comms timeouts and the like)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chVTSetI infinite loop

Post by Giovanni »

This could be a good idea but I need to finalize 2.6.0, the next step is 3.0.0 anyway.

Giovanni
Post Reply