timer: k_timer_start should accept 0 as duration parameter.
k_timer_start(timer, duration, period) is API used to start a timer. Currently duration parameters accepts only positive number. But a user may require to do some periodic activity ASAP and start timer with 0 value. So this patch allows 0 as minimum value of duration. In this patch, when duration value is set as 0 then timer expiration handler is called instead of submiting this into timeout queue. Jira: ZEP-2497 Signed-off-by: Youvedeep Singh <youvedeep.singh@intel.com>
This commit is contained in:
parent
666d0b672a
commit
d787e3c554
2 changed files with 13 additions and 3 deletions
|
@ -197,7 +197,7 @@ static inline void _add_timeout(struct k_thread *thread,
|
||||||
_wait_q_t *wait_q,
|
_wait_q_t *wait_q,
|
||||||
s32_t timeout_in_ticks)
|
s32_t timeout_in_ticks)
|
||||||
{
|
{
|
||||||
__ASSERT(timeout_in_ticks > 0, "");
|
__ASSERT(timeout_in_ticks >= 0, "");
|
||||||
|
|
||||||
timeout->delta_ticks_from_prev = timeout_in_ticks;
|
timeout->delta_ticks_from_prev = timeout_in_ticks;
|
||||||
timeout->thread = thread;
|
timeout->thread = thread;
|
||||||
|
@ -207,6 +207,16 @@ static inline void _add_timeout(struct k_thread *thread,
|
||||||
_dump_timeout(timeout, 0);
|
_dump_timeout(timeout, 0);
|
||||||
_dump_timeout_q();
|
_dump_timeout_q();
|
||||||
|
|
||||||
|
/* If timer is submitted to expire ASAP with
|
||||||
|
* timeout_in_ticks (duration) as zero value,
|
||||||
|
* then handle timeout immedately without going
|
||||||
|
* through timeout queue.
|
||||||
|
*/
|
||||||
|
if (!timeout_in_ticks) {
|
||||||
|
_handle_one_expired_timeout(timeout);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
s32_t *delta = &timeout->delta_ticks_from_prev;
|
s32_t *delta = &timeout->delta_ticks_from_prev;
|
||||||
struct _timeout *in_q;
|
struct _timeout *in_q;
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ void k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
|
||||||
volatile s32_t period_in_ticks, duration_in_ticks;
|
volatile s32_t period_in_ticks, duration_in_ticks;
|
||||||
|
|
||||||
period_in_ticks = _ms_to_ticks(period);
|
period_in_ticks = _ms_to_ticks(period);
|
||||||
duration_in_ticks = _TICK_ALIGN + _ms_to_ticks(duration);
|
duration_in_ticks = _ms_to_ticks(duration);
|
||||||
|
|
||||||
unsigned int key = irq_lock();
|
unsigned int key = irq_lock();
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ void k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
|
||||||
}
|
}
|
||||||
|
|
||||||
timer->period = period_in_ticks;
|
timer->period = period_in_ticks;
|
||||||
_add_timeout(NULL, &timer->timeout, &timer->wait_q, duration_in_ticks);
|
|
||||||
timer->status = 0;
|
timer->status = 0;
|
||||||
|
_add_timeout(NULL, &timer->timeout, &timer->wait_q, duration_in_ticks);
|
||||||
irq_unlock(key);
|
irq_unlock(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue