mirror of https://github.com/Desuuuu/klipper.git
sched: Change sched_from_ms() to sched_from_us()
Some code may require micro-second precision so update sched_from_ms() to use micro-seconds. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
d68cb264c4
commit
ed103822f5
|
@ -8,18 +8,18 @@
|
|||
#include "command.h" // shutdown
|
||||
#include "irq.h" // irq_save
|
||||
#include "sched.h" // sched_timer_kick
|
||||
#include "timer.h" // timer_from_ms
|
||||
#include "timer.h" // timer_from_us
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* Low level timer code
|
||||
****************************************************************/
|
||||
|
||||
// Return the number of clock ticks for a given number of milliseconds
|
||||
// Return the number of clock ticks for a given number of microseconds
|
||||
uint32_t
|
||||
timer_from_ms(uint32_t ms)
|
||||
timer_from_us(uint32_t us)
|
||||
{
|
||||
return ms * (F_CPU / 1000);
|
||||
return us * (F_CPU / 1000000);
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
|
@ -156,7 +156,7 @@ timer_try_set_next(uint32_t target)
|
|||
// Too many repeat timers from a single interrupt - force a pause
|
||||
timer_repeat = TIMER_MAX_NEXT_REPEAT;
|
||||
next = now + TIMER_DEFER_REPEAT_TICKS;
|
||||
if (diff < (int16_t)(-timer_from_ms(1)))
|
||||
if (diff < (int16_t)(-timer_from_us(1000)))
|
||||
goto fail;
|
||||
|
||||
done:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t timer_from_ms(uint32_t ms);
|
||||
uint32_t timer_from_us(uint32_t us);
|
||||
void timer_periodic(void);
|
||||
uint32_t timer_read_time(void);
|
||||
uint8_t timer_set_next(uint32_t next);
|
||||
|
|
|
@ -205,7 +205,7 @@ stats_task(void)
|
|||
sumsq = nextsumsq;
|
||||
|
||||
static uint32_t prev;
|
||||
if (sched_is_before(cur, prev + sched_from_ms(5000)))
|
||||
if (sched_is_before(cur, prev + sched_from_us(5000000)))
|
||||
return;
|
||||
sendf("stats count=%u sum=%u sumsq=%u", count, cur - prev, sumsq);
|
||||
prev = cur;
|
||||
|
|
12
src/sched.c
12
src/sched.c
|
@ -9,9 +9,9 @@
|
|||
#include <stddef.h> // NULL
|
||||
#include "autoconf.h" // CONFIG_*
|
||||
#include "board/irq.h" // irq_save
|
||||
#include "board/timer.h" // timer_from_ms
|
||||
#include "board/timer.h" // timer_from_us
|
||||
#include "command.h" // shutdown
|
||||
#include "sched.h" // sched_from_ms
|
||||
#include "sched.h" // sched_from_us
|
||||
#include "stepper.h" // stepper_event
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ ms_event(struct timer *t)
|
|||
{
|
||||
millis++;
|
||||
timer_periodic();
|
||||
t->waketime += sched_from_ms(1);
|
||||
t->waketime += sched_from_us(1000);
|
||||
return SF_RESCHEDULE;
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,11 @@ sched_check_periodic(uint16_t time, uint16_t *pnext)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Return the number of clock ticks for a given number of milliseconds
|
||||
// Return the number of clock ticks for a given number of microseconds
|
||||
uint32_t
|
||||
sched_from_ms(uint32_t ms)
|
||||
sched_from_us(uint32_t us)
|
||||
{
|
||||
return timer_from_ms(ms);
|
||||
return timer_from_us(us);
|
||||
}
|
||||
|
||||
// Return the current time (in clock ticks)
|
||||
|
|
|
@ -23,7 +23,7 @@ enum { SF_DONE=0, SF_RESCHEDULE=1 };
|
|||
|
||||
// sched.c
|
||||
uint8_t sched_check_periodic(uint16_t time, uint16_t *pnext);
|
||||
uint32_t sched_from_ms(uint32_t ms);
|
||||
uint32_t sched_from_us(uint32_t us);
|
||||
uint32_t sched_read_time(void);
|
||||
uint8_t sched_is_before(uint32_t time1, uint32_t time2);
|
||||
void sched_timer(struct timer*);
|
||||
|
|
|
@ -17,7 +17,7 @@ uint8_t Interrupt_off;
|
|||
****************************************************************/
|
||||
|
||||
uint32_t
|
||||
timer_from_ms(uint32_t ms)
|
||||
timer_from_us(uint32_t us)
|
||||
{
|
||||
return 0; // XXX
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t timer_from_ms(uint32_t ms);
|
||||
uint32_t timer_from_us(uint32_t us);
|
||||
void timer_periodic(void);
|
||||
uint32_t timer_read_time(void);
|
||||
uint8_t timer_set_next(uint32_t next);
|
||||
|
|
Loading…
Reference in New Issue