MQX periodic timer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX periodic timer

1,221 Views
arielablumer
Contributor III

Hi,

I'm using MQX 4.2.0.2 w/ K66 and encounter sporadic problems w/ activation of the callback function of the periodic timer.

Timer activation code looks like:

     timer_id =  _timer_start_periodic_every(timer_cb, NULL, TIMER_ELAPSED_TIME_MODE, 5000);

I haven't tried to debug it but I've seen there were some issues in the past with tasks priorities.

Are there any known issues around the timer callback? Any guidelines for debugging?

Thanks,

Ariela

0 Kudos
5 Replies

654 Views
arielablumer
Contributor III

Hi,

Creation of the timer always succeeds and it works well most of the time. It happens randomly that the device is started and the timer isn't activated at all (I added a print in the callback).

The timer callback is used just for testing some logical conditions and making very simple decisions.

I use the default timer task and this is the only task using the callback.

What is the expected improvement if I use my own task? I believe the timer task is always activated as its priority is the highest in the system.

Thanks,

Ariela

0 Kudos

654 Views
DavidS
NXP Employee
NXP Employee

Hi Ariela,

Trying starting the timer task with following call:

   _timer_create_component(2, 1600);

This will set the timer task priority to 2 and the stack size to 1600 bytes.

By starting the timer task yourself allows you to tweak and tune the priority and stack size.

Regards,

David

0 Kudos

654 Views
arielablumer
Contributor III

Hi David,

This is perfectly clear but what is the advantage of lowering the priority of the timer task? How can the fact that priority is high explain the missing timer events?

Thanks,

Ariela

0 Kudos

654 Views
DavidS
NXP Employee
NXP Employee

Hi Ariela,

Do you check the return value of timer_id to verify it was successful?

What does the timer_cb() function do?

Does it call any blocking MQX function calls?  If yes, you should not call blocking function calls.

Is timer_cb() a short routine or long?  Shorter is better as you want to treat a timer callback like an interrupt routine (i.e. short and non-blocking calls).

Do other tasks use the timer_cb() function?

Do you create the timer task or let MQX do it for you?  If you are letting MQX do it, then you might want to try creating the timer task with your own priority and stack size.  I have seen lowering the priority from default 1 to 2 (or lower as an experiment).  Same thing with the stack size as default is 800 bytes so maybe you need more.

Regards,

David

0 Kudos

654 Views
soledad
NXP Employee
NXP Employee

Hello Ariela,

Please check the below threads and let me know if this information helps.

lwtimer

How to create a cyclic task in MQX

Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos