Problems using chVTSetI()

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

Problems using chVTSetI()

Post 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
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

Re: Problems using chVTSetI()

Post 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
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

Re: Problems using chVTSetI()

Post 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.
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

Re: Problems using chVTSetI()

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Problems using chVTSetI()

Post 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
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

Re: Problems using chVTSetI()

Post by Stomper85 »

Great, now it works!

Thanks!
Post Reply