how to user KTimer?


Li, Jun R
 

Hi there,

 

I’m trying to use the “k_timer” in my project, and get confused by the parameters in the function “k_timer_start(struct k_timer *timer, int32_t duration, int32_t period)”. How are the parameters “duration” and “period” defined for this one? How can I use them? Thank you!

 

Regards,

Jun

 

 


Benjamin Walsh <benjamin.walsh@...>
 

Hi Jun,

I’m trying to use the “k_timer” in my project, and get confused by the
parameters in the function “k_timer_start(struct k_timer *timer,
int32_t duration, int32_t period)”. How are the parameters “duration”
and “period” defined for this one? How can I use them? Thank you!
<duration> is the time before the first timer expiry, and <period> is
the period at which it will expiry subsenquently. If you specify a
<period> of 0, the timer only fire once.

e.g.

If the current uptime is 1000ms, and you specify duration = 100 and
period = 50, the timer will expire at uptime = 1100 and then at every
subsequent multiple of 50 (1150, 1200, 1250, etc) until cancelled.

HTH,
Ben

--
Benjamin Walsh, SMTS
WR VxWorks Virtualization Profile
www.windriver.com
Zephyr kernel maintainer
www.zephyrproject.org


Li, Jun R
 

Ben,
Thanks for the explanation! It is very clear now.

Regards,
Jun

On Mar 14, 2017, at 06:30, Benjamin Walsh <benjamin.walsh@windriver.com> wrote:

Hi Jun,

I’m trying to use the “k_timer” in my project, and get confused by the
parameters in the function “k_timer_start(struct k_timer *timer,
int32_t duration, int32_t period)”. How are the parameters “duration”
and “period” defined for this one? How can I use them? Thank you!
<duration> is the time before the first timer expiry, and <period> is
the period at which it will expiry subsenquently. If you specify a
<period> of 0, the timer only fire once.

e.g.

If the current uptime is 1000ms, and you specify duration = 100 and
period = 50, the timer will expire at uptime = 1100 and then at every
subsequent multiple of 50 (1150, 1200, 1250, etc) until cancelled.

HTH,
Ben

--
Benjamin Walsh, SMTS
WR VxWorks Virtualization Profile
www.windriver.com
Zephyr kernel maintainer
www.zephyrproject.org