timer

Navigation:  Programming language SQC > Built-in functions > Time >

timer

Previous pageReturn to chapter overviewNext page

The timer() starts a timer instance, when the timer elapses the associated interrupt is raised and the interrupt function is called.

The timer function returns 0 if successful, else -1.

 

There are two types of timer instances:

 

- SINGLE_SHOT_TIMER                just for one shot.

- INTERVAL_TIMER                this type will be start automatically after the timer elapse

 

int timer( int timernumber, int timeout)

 

Example:

 

int cnt = 0;

 

#interrupt IV_TIMER

void foo1(int port, int no, char* data, int datalen)

{

   switch(port)

   {

      case TIMER_1:

         printf("timer 1\n");

          timer(TIMER_1,200,SINGLE_SHOT_TIMER);

      break;

      

      case TIMER_2:

         printf("timer 2\n");

      break;

      

      case TIMER_3:

         printf("timer 3\n");

      break;

   }

   

   cnt++;

}

 

void main() {

   

   int *ptr = 0;

   int t = *ptr++;

 

 setprio(IV_TIMER, TIMER_1, 1);

 setprio(IV_TIMER, TIMER_2, 2);

 setprio(IV_TIMER, TIMER_3, 3);

 

 timer(TIMER_2,200,INTERVAL_TIMER);

 timer(TIMER_3,200,INTERVAL_TIMER);

 timer(TIMER_1,200,SINGLE_SHOT_TIMER);

  

 while( cnt < 10 ){}

 

 printf("finish\n");

 

}

 

Output:

 

timer 1

timer 2

timer 3

timer 1

timer 2

timer 3

timer 1

timer 2

timer 3

timer 1

timer 2

timer 3

finish