Page 1 of 1

Problems using chVTSetI()

Posted: Wed Mar 19, 2014 8:20 pm
by Stomper85
Hi,

I encountered some problems with using the chVTSetI() Method.

Here is my code:

Code: Select all

/* EVENT TIMER STRUCT */
static VirtualTimer vt;
.
.
.
 /*
   * Normal main() thread activity, check the time here and set relais if necessary
   */
  while (TRUE)
  {

    /* Query Time */
    rtcGetTimeTm(&RTCD1, &thetime);

    /* Query all alarms if one fits the actual time */
    for (i=0; i<8; i++)
    {
      if (alarmlist[i].hour == thetime.tm_hour &&
          alarmlist[i].minute == thetime.tm_min &&
          thetime.tm_sec <= 1)
      {
        /* check if duration of alarm not 0 */
        if (alarmlist[i].durationSec != 0)
        {
          /* Set the Water ON */
          SetWaterON();

          /* Schedule to switch off after duration time of alarm  - later use: S2ST(alarmlist[i].durationSec) */
          chVTSetI(&vt, 5000, SetWaterOFF, 0);
         
          /* exit for, cause there should be only one alarm at one time in the list */
          break;
        }
      }
    }

    chThdSleepMilliseconds(1000);
  }
.
.
.
void SetWaterOFF(void *arg)
{
  valve1 = 0;
  valve2 = 0;
  pump = 0;
}


When using this Code, the MCU got stuck in the unhandled exeption loop.

I am doing something wrong?

Best regards
Stomper

Re: Problems using chVTSetI()

Posted: Wed Mar 19, 2014 8:42 pm
by jscott
It looks like you are using this function in your main() function....

If that is the case, then you need to use chVTSet() not chVTSetI()...

The "I" on the end indicates that it is to be called in one of the system lock states...

Do a search for "i" class functions for more information.

-John Scott

Re: Problems using chVTSetI()

Posted: Wed Mar 19, 2014 9:00 pm
by Stomper85
You are right, but unfortunatelly this doesn´t solve my problem :-(

Still the same with the chVTSet() method, it hangs up shortly after processing that line.

Re: Problems using chVTSetI()

Posted: Wed Mar 19, 2014 10:46 pm
by jscott
Are you using a debugger?

Do you have all the debugging options turned on in the config files?

What are you seeing? Inquiring minds want to know! :D :D

http://chibios.org/dokuwiki/doku.php?id=chibios:guides:debug_guide In case you have not seen it.

-John Scott

Re: Problems using chVTSetI()

Posted: Thu Mar 20, 2014 9:01 am
by Giovanni
Hi,

You need to put it in lock/unlocks like jscott explained, you also need to check if the timer is *already running*, in that case you need to reset it then set it again.

Code: Select all

  if (chVTIsArmedI(&vt))
    chVTResetI(&vt);
  chVTSetI(&vt, ...);


Giovanni

Re: Problems using chVTSetI()

Posted: Sat Mar 22, 2014 7:20 pm
by Stomper85
Great, now it works!

Thanks!