Problems using chVTSetI()

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

Moderators: barthess, RoccoMarco

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

Problems using chVTSetI()

Postby Stomper85 » Wed Mar 19, 2014 8:20 pm

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
Location: Middle Georgia, USA
Contact:

Re: Problems using chVTSetI()

Postby jscott » Wed Mar 19, 2014 8:42 pm

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()

Postby Stomper85 » Wed Mar 19, 2014 9:00 pm

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
Location: Middle Georgia, USA
Contact:

Re: Problems using chVTSetI()

Postby jscott » Wed Mar 19, 2014 10:46 pm

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: 13012
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 745 times
Been thanked: 621 times
Contact:

Re: Problems using chVTSetI()

Postby Giovanni » Thu Mar 20, 2014 9:01 am

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()

Postby Stomper85 » Sat Mar 22, 2014 7:20 pm

Great, now it works!

Thanks!


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 5 guests