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 "command.h" // shutdown
|
||||||
#include "irq.h" // irq_save
|
#include "irq.h" // irq_save
|
||||||
#include "sched.h" // sched_timer_kick
|
#include "sched.h" // sched_timer_kick
|
||||||
#include "timer.h" // timer_from_ms
|
#include "timer.h" // timer_from_us
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Low level timer code
|
* 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
|
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
|
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
|
// Too many repeat timers from a single interrupt - force a pause
|
||||||
timer_repeat = TIMER_MAX_NEXT_REPEAT;
|
timer_repeat = TIMER_MAX_NEXT_REPEAT;
|
||||||
next = now + TIMER_DEFER_REPEAT_TICKS;
|
next = now + TIMER_DEFER_REPEAT_TICKS;
|
||||||
if (diff < (int16_t)(-timer_from_ms(1)))
|
if (diff < (int16_t)(-timer_from_us(1000)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint32_t timer_from_ms(uint32_t ms);
|
uint32_t timer_from_us(uint32_t us);
|
||||||
void timer_periodic(void);
|
void timer_periodic(void);
|
||||||
uint32_t timer_read_time(void);
|
uint32_t timer_read_time(void);
|
||||||
uint8_t timer_set_next(uint32_t next);
|
uint8_t timer_set_next(uint32_t next);
|
||||||
|
|
|
@ -205,7 +205,7 @@ stats_task(void)
|
||||||
sumsq = nextsumsq;
|
sumsq = nextsumsq;
|
||||||
|
|
||||||
static uint32_t prev;
|
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;
|
return;
|
||||||
sendf("stats count=%u sum=%u sumsq=%u", count, cur - prev, sumsq);
|
sendf("stats count=%u sum=%u sumsq=%u", count, cur - prev, sumsq);
|
||||||
prev = cur;
|
prev = cur;
|
||||||
|
|
12
src/sched.c
12
src/sched.c
|
@ -9,9 +9,9 @@
|
||||||
#include <stddef.h> // NULL
|
#include <stddef.h> // NULL
|
||||||
#include "autoconf.h" // CONFIG_*
|
#include "autoconf.h" // CONFIG_*
|
||||||
#include "board/irq.h" // irq_save
|
#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 "command.h" // shutdown
|
||||||
#include "sched.h" // sched_from_ms
|
#include "sched.h" // sched_from_us
|
||||||
#include "stepper.h" // stepper_event
|
#include "stepper.h" // stepper_event
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ ms_event(struct timer *t)
|
||||||
{
|
{
|
||||||
millis++;
|
millis++;
|
||||||
timer_periodic();
|
timer_periodic();
|
||||||
t->waketime += sched_from_ms(1);
|
t->waketime += sched_from_us(1000);
|
||||||
return SF_RESCHEDULE;
|
return SF_RESCHEDULE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +52,11 @@ sched_check_periodic(uint16_t time, uint16_t *pnext)
|
||||||
return 1;
|
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
|
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)
|
// Return the current time (in clock ticks)
|
||||||
|
|
|
@ -23,7 +23,7 @@ enum { SF_DONE=0, SF_RESCHEDULE=1 };
|
||||||
|
|
||||||
// sched.c
|
// sched.c
|
||||||
uint8_t sched_check_periodic(uint16_t time, uint16_t *pnext);
|
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);
|
uint32_t sched_read_time(void);
|
||||||
uint8_t sched_is_before(uint32_t time1, uint32_t time2);
|
uint8_t sched_is_before(uint32_t time1, uint32_t time2);
|
||||||
void sched_timer(struct timer*);
|
void sched_timer(struct timer*);
|
||||||
|
|
|
@ -17,7 +17,7 @@ uint8_t Interrupt_off;
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
timer_from_ms(uint32_t ms)
|
timer_from_us(uint32_t us)
|
||||||
{
|
{
|
||||||
return 0; // XXX
|
return 0; // XXX
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint32_t timer_from_ms(uint32_t ms);
|
uint32_t timer_from_us(uint32_t us);
|
||||||
void timer_periodic(void);
|
void timer_periodic(void);
|
||||||
uint32_t timer_read_time(void);
|
uint32_t timer_read_time(void);
|
||||||
uint8_t timer_set_next(uint32_t next);
|
uint8_t timer_set_next(uint32_t next);
|
||||||
|
|
Loading…
Reference in New Issue