From 6d607d97a62be9dd13d536fa7e60aef45697cee1 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 2 Jan 2015 20:00:03 +0000 Subject: [PATCH] timer: Make the ticks timer run at 10hz not at a platform rate We now get a sensible time between rollovers and more importantly we can do much better in the C library with division by 10 than random per platform numbers. --- Kernel/include/timer.h | 4 ++-- Kernel/platform-socz80/devsd.c | 6 +++--- Kernel/process.c | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Kernel/include/timer.h b/Kernel/include/timer.h index 6db1a838..8766c031 100644 --- a/Kernel/include/timer.h +++ b/Kernel/include/timer.h @@ -7,8 +7,8 @@ typedef uint16_t timer_t; -#define set_timer_ms(msec) (set_timer_duration(((msec * TICKSPERSEC) / 1000U) == 0 ? 1 : ((msec * TICKSPERSEC) / 1000U))) -#define set_timer_sec(sec) (set_timer_duration(sec * TICKSPERSEC)) +#define set_timer_ms(msec) (set_timer_duration(msec < 100U ? 1 : ((msec) / 100U)) +#define set_timer_sec(sec) (set_timer_duration((sec) * 10)) timer_t set_timer_duration(uint16_t duration); /* good for up to 32K ticks */ bool timer_expired(timer_t timer_val); diff --git a/Kernel/platform-socz80/devsd.c b/Kernel/platform-socz80/devsd.c index cec8f912..7bd9e620 100644 --- a/Kernel/platform-socz80/devsd.c +++ b/Kernel/platform-socz80/devsd.c @@ -201,7 +201,7 @@ int sd_spi_init(void) /* Enter Idle state */ if (sd_send_command(CMD0, 0) == 1) { /* initialisation timeout 1 second */ - timer = set_timer_duration(TICKSPERSEC); + timer = set_timer_sec(1); if (sd_send_command(CMD8, (uint32_t)0x1AA) == 1) { /* SDHC */ /* Get trailing return value of R7 resp */ for (n = 0; n < 4; n++) ocr[n] = sd_spi_receive_byte(); @@ -256,7 +256,7 @@ int sd_spi_wait_ready(void) unsigned char res; timer_t timer; - timer = set_timer_duration(TICKSPERSEC/10); /* 100ms */ + timer = set_timer_ms(100); /* 100ms */ sd_spi_receive_byte(); do{ res = sd_spi_receive_byte(); @@ -287,7 +287,7 @@ int sd_spi_receive_block(void *ptr, int length) unsigned int timer; unsigned char b; - timer = set_timer_duration(TICKSPERSEC/5); /* 200ms */ + timer = set_timer_ms(200); /* 200ms */ do{ b = sd_spi_receive_byte(); diff --git a/Kernel/process.c b/Kernel/process.c index 7ced59cb..f26b1d3f 100644 --- a/Kernel/process.c +++ b/Kernel/process.c @@ -328,8 +328,6 @@ void timer_interrupt(void) udata.u_utime++; } - ticks.full++; - /* Do once-per-decisecond things - this doesn't work out well on boxes with 64 ticks/second.. need a better approach */ if (++ticks_this_dsecond == TICKSPERSEC / 10) { @@ -337,6 +335,7 @@ void timer_interrupt(void) /* Update global time counters */ ticks_this_dsecond = 0; + ticks.full++; /* Update process alarm clocks and timeouts */ for (p = ptab; p < ptab + maxproc; ++p) { -- 2.34.1