timer: Allow board code to define its own timer_is_before implementation

Move sched_is_before() from sched.c to timer_is_before() in the board
specific timer code.  This allows the board code to provide its own
definition.

Also, remove the sched_from_us() and sched_read_time() wrapper
functions and change the callers to directly invoke timer_from_us() /
timer_read_time().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2017-03-24 23:01:08 -04:00
parent 14340ac4df
commit 60e488eb17
9 changed files with 48 additions and 47 deletions

View File

@@ -7,6 +7,7 @@
#include "basecmd.h" // oid_alloc
#include "board/gpio.h" // struct gpio_out
#include "board/irq.h" // irq_disable
#include "board/misc.h" // timer_is_before
#include "command.h" // DECL_COMMAND
#include "sched.h" // sched_add_timer
@@ -117,7 +118,7 @@ soft_pwm_toggle_event(struct timer *timer)
waketime += s->on_duration;
else
waketime += s->off_duration;
if (s->flags & SPF_CHECK_END && !sched_is_before(waketime, s->end_time)) {
if (s->flags & SPF_CHECK_END && !timer_is_before(waketime, s->end_time)) {
// End of normal pulsing - next event loads new pwm settings
s->timer.func = soft_pwm_load_event;
waketime = s->end_time;
@@ -189,13 +190,13 @@ command_schedule_soft_pwm_out(uint32_t *args)
next_flags |= SPF_NEXT_CHECK_END;
}
irq_disable();
if (s->flags & SPF_CHECK_END && sched_is_before(s->end_time, time))
if (s->flags & SPF_CHECK_END && timer_is_before(s->end_time, time))
shutdown("next soft pwm extends existing pwm");
s->end_time = time;
s->next_on_duration = next_on_duration;
s->next_off_duration = next_off_duration;
s->flags |= next_flags;
if (s->flags & SPF_TOGGLING && sched_is_before(s->timer.waketime, time)) {
if (s->flags & SPF_TOGGLING && timer_is_before(s->timer.waketime, time)) {
// soft_pwm_toggle_event() will schedule a load event when ready
} else {
// Schedule the loading of the pwm parameters at the requested time