This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to create multiple user tmers and call back function?

It seems that we have to use the second para "info" in os_tmr_create (xx, info)to distinct which usr timer callback funtion is called.


#define Timer1CallBackFn1 1
#define Timer2CallBackFn2 2

#define TimerInterval1    10
#define TimerInterval2    15

  tmr1 = os_tmr_create (TimerInterval1, Timer1CallBackFn1 );
  if (tmr1 == NULL) {
    printf ("Failed to create user timer1.\n");
  }
  tmr2 = os_tmr_create (TimerInterval2, Timer2CallBackFn2 );
  if (tmr2 == NULL) {
    printf ("Failed to create user timer2.\n");
  }


Then, we have to modify rtx_confg.c as following:


void os_tmr_call (U16 info) {
  /* This function is called when the user timer has expired. Parameter  */
  /* 'info' holds the value, defined when the timer was created.         */

  /* HERE: include optional user code to be executed on timeout. */
        switch(info)
        {
                case Timer1CallBackFn1 :
                        //add code here
                        printf("Timer1 expired!\n");

                        break;
                case Timer1CallBackFn1 :
                        //add code here
                        printf("Timer2 expired!\n");
                        break;
                default:

                        break;



        }

}

So,We can create different Usr timer and its callback funtions, is it ok?

In fact, it is best to do this:

os_tmr_create (TimerInterval, TimerCallBackFn );


Where
TimerCallBackFn is a usr function address.