timer: micro/nano abstraction for announcing tick

The gain is two-fold:

- Removes the need of preprocessor conditionals in the timer drivers'
  ISRs.
- Allows removing the duplication of the 'tick announce' code across
  all timer drivers.

Change-Id: I6078a0b00a833c1d1ca76474987c3214a0c05f7b
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
This commit is contained in:
Benjamin Walsh 2015-05-01 16:53:30 -04:00 committed by Anas Nashif
parent 0c798772cc
commit 153503d766
2 changed files with 40 additions and 0 deletions

View file

@ -64,6 +64,16 @@ extern void _timer_idle_enter(int32_t ticks);
extern void _timer_idle_exit(void);
#endif /* TIMER_SUPPORTS_TICKLESS */
#ifdef CONFIG_MICROKERNEL
#define _sys_clock_tick_announce() \
nano_isr_stack_push(&_k_command_stack, TICK_EVENT)
#else
extern void _do_sys_clock_tick_announce(uint32_t ticks);
extern uint32_t _sys_idle_elapsed_ticks;
#define _sys_clock_tick_announce() \
_do_sys_clock_tick_announce(_sys_idle_elapsed_ticks)
#endif
#endif /* _ASMLANGUAGE */
#endif /* _TIMER__H_ */

View file

@ -50,6 +50,9 @@ int sys_clock_hw_cycles_per_tick;
int64_t _nano_ticks = 0;
struct nano_timer *_nano_timer_list = NULL;
/* updated by timer driver for tickless, stays at 1 for non-tickless */
uint32_t _sys_idle_elapsed_ticks = 1;
/*******************************************************************************
*
* nano_time_init - constructor that initializes nanokernel time tracking system
@ -190,4 +193,31 @@ uint32_t nano_tick_delta_32(int64_t *reftime)
return (uint32_t)_nano_tick_delta(reftime);
}
/*******************************************************************************
*
* _do_sys_clock_tick_announce - announce a tick to the nanokernel
*
* This function is only to be called by the system clock timer driver when a
* tick is to be announced to the nanokernel. It takes care of dequeuing the
* timers that have expired and wake up the fibers pending on them.
*
* RETURNS: N/A
*/
void _do_sys_clock_tick_announce(uint32_t ticks)
{
_nano_ticks += ticks;
if (_nano_timer_list) {
_nano_timer_list->ticks -= ticks;
while (_nano_timer_list && (!_nano_timer_list->ticks)) {
struct nano_timer *expired = _nano_timer_list;
struct nano_lifo *lifo = &expired->lifo;
_nano_timer_list = expired->link;
nano_isr_lifo_put(lifo, expired->userData);
}
}
}
#endif /* CONFIG_NANOKERNEL */