From 7eb6c4e5e5add3ea1ab72ebff146c0ce789bea8c Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Sat, 27 Dec 2014 01:37:45 +0000 Subject: [PATCH] Kernel: Improve simple timer code. Remove timer.h include where it is not required. --- Kernel/bankfixed.c | 1 - Kernel/filesys.c | 1 - Kernel/include/kdata.h | 3 ++- Kernel/include/timer.h | 6 ++++-- Kernel/inode.c | 1 - Kernel/kdata.c | 4 ++-- Kernel/lowlevel-z80.s | 5 ----- Kernel/process.c | 1 - Kernel/select.c | 1 - Kernel/simple.c | 1 - Kernel/single.c | 1 - Kernel/start.c | 1 - Kernel/swap.c | 1 - Kernel/syscall_exec.c | 1 - Kernel/syscall_fs.c | 1 - Kernel/syscall_fs2.c | 1 - Kernel/syscall_other.c | 1 - Kernel/syscall_proc.c | 1 - Kernel/timer.c | 16 ++++++++-------- 19 files changed, 16 insertions(+), 32 deletions(-) diff --git a/Kernel/bankfixed.c b/Kernel/bankfixed.c index 91bc6c25..e671ffd0 100644 --- a/Kernel/bankfixed.c +++ b/Kernel/bankfixed.c @@ -1,5 +1,4 @@ #include -#include #include #include diff --git a/Kernel/filesys.c b/Kernel/filesys.c index 00d1c260..56dcb20e 100644 --- a/Kernel/filesys.c +++ b/Kernel/filesys.c @@ -2,7 +2,6 @@ #include #include #include -#include /* N_open is given a string containing a path name in user space, * and returns an inode table pointer. If it returns NULL, the file diff --git a/Kernel/include/kdata.h b/Kernel/include/kdata.h index e12fe7c0..8d39af4f 100644 --- a/Kernel/include/kdata.h +++ b/Kernel/include/kdata.h @@ -31,7 +31,8 @@ extern uint8_t ticks_this_dsecond; /* Tick counter for counting off one de extern uint16_t runticks; /* Number of ticks current process has been swapped in */ extern time_t tod; /* Time of day */ -extern clock_t ticks; /* Cumulative tick counter, in minutes and ticks */ +extern clock_t ticks; /* 32-bit count of ticks since boot */ +extern uint16_t miniticks; /* 16-bit count of ticks since boot */ extern uint8_t *swapbase; /* Used by device driver for swapping */ extern unsigned swapcnt; diff --git a/Kernel/include/timer.h b/Kernel/include/timer.h index 845dfee3..6db1a838 100644 --- a/Kernel/include/timer.h +++ b/Kernel/include/timer.h @@ -2,12 +2,14 @@ #define __TIMER_DOT_H__ #include +#include #include typedef uint16_t timer_t; -extern timer_t system_timer; /* counts up at TICKSPERSEC, wraps to zero */ -timer_t set_timer_duration(uint16_t duration); /* good for up to approx 0x8000 ticks */ +#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)) +timer_t set_timer_duration(uint16_t duration); /* good for up to 32K ticks */ bool timer_expired(timer_t timer_val); #endif diff --git a/Kernel/inode.c b/Kernel/inode.c index c8a1697b..aaf1e961 100644 --- a/Kernel/inode.c +++ b/Kernel/inode.c @@ -1,7 +1,6 @@ #include #include #include -#include /* Writei (and readi) need more i/o error handling */ void readi(inoptr ino, uint8_t flag) diff --git a/Kernel/kdata.c b/Kernel/kdata.c index 1fb12811..39417ec6 100644 --- a/Kernel/kdata.c +++ b/Kernel/kdata.c @@ -7,14 +7,14 @@ char *cmdline = (char *) CMDLINE; char bootline[2]; uint16_t ramsize, procmem, maxproc, nproc, nready; uint16_t runticks; -uint16_t system_tick_counter; bool inint; uint8_t root_dev = DEFAULT_ROOT; uint8_t ticks_this_dsecond; inoptr root; uint16_t waitno; time_t tod; // time of day -clock_t ticks; // system tick counter +clock_t ticks; // 32-bit system tick counter +uint16_t miniticks; // 16-bit system tick counter int16_t acct_fh = -1; /* Accounting file handle */ diff --git a/Kernel/lowlevel-z80.s b/Kernel/lowlevel-z80.s index 2893fe0f..5f04ef6e 100644 --- a/Kernel/lowlevel-z80.s +++ b/Kernel/lowlevel-z80.s @@ -35,7 +35,6 @@ .globl unix_syscall_entry .globl _chksigs .globl null_handler - .globl _system_tick_counter .globl unix_syscall_entry .globl dispatch_process_signal .globl _doexec @@ -270,10 +269,6 @@ interrupt_handler: push ix push iy - ld hl, (_system_tick_counter) - inc hl - ld (_system_tick_counter), hl - ; Some platforms (MSX for example) have devices we *must* ; service irrespective of kernel state in order to shut them ; up. This code must be in common and use small amounts of stack diff --git a/Kernel/process.c b/Kernel/process.c index ca5efb37..1e114747 100644 --- a/Kernel/process.c +++ b/Kernel/process.c @@ -3,7 +3,6 @@ #undef DEBUGREALLYHARD /* turn on getproc dumping */ #include -#include #include #include diff --git a/Kernel/select.c b/Kernel/select.c index 61216b72..e1ce293a 100644 --- a/Kernel/select.c +++ b/Kernel/select.c @@ -2,7 +2,6 @@ #include #include #include -#include /* * Logic for select diff --git a/Kernel/simple.c b/Kernel/simple.c index 5df4d0da..9b3092d6 100644 --- a/Kernel/simple.c +++ b/Kernel/simple.c @@ -3,7 +3,6 @@ */ #include -#include #include #include diff --git a/Kernel/single.c b/Kernel/single.c index 585bb7de..e4bf7a96 100644 --- a/Kernel/single.c +++ b/Kernel/single.c @@ -1,5 +1,4 @@ #include -#include #include #include diff --git a/Kernel/start.c b/Kernel/start.c index 331e6eea..85ddafa6 100644 --- a/Kernel/start.c +++ b/Kernel/start.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include diff --git a/Kernel/swap.c b/Kernel/swap.c index ea395969..ad99282b 100644 --- a/Kernel/swap.c +++ b/Kernel/swap.c @@ -4,7 +4,6 @@ */ #include -#include #include #include diff --git a/Kernel/syscall_exec.c b/Kernel/syscall_exec.c index c25175a2..4d3c2e21 100644 --- a/Kernel/syscall_exec.c +++ b/Kernel/syscall_exec.c @@ -2,7 +2,6 @@ #include #include #include -#include static void close_on_exec(void) { diff --git a/Kernel/syscall_fs.c b/Kernel/syscall_fs.c index b0245fcb..139f9cdf 100644 --- a/Kernel/syscall_fs.c +++ b/Kernel/syscall_fs.c @@ -2,7 +2,6 @@ #include #include #include -#include void updoff(void) { diff --git a/Kernel/syscall_fs2.c b/Kernel/syscall_fs2.c index 0a78ce4e..d3f87b8c 100644 --- a/Kernel/syscall_fs2.c +++ b/Kernel/syscall_fs2.c @@ -2,7 +2,6 @@ #include #include #include -#include /* * File system related calls that are not continually used (so diff --git a/Kernel/syscall_other.c b/Kernel/syscall_other.c index 3f4c4db0..ba1a6536 100644 --- a/Kernel/syscall_other.c +++ b/Kernel/syscall_other.c @@ -2,7 +2,6 @@ #include #include #include -#include /* * More obscure syscalls that it might be useful to pull out of the main diff --git a/Kernel/syscall_proc.c b/Kernel/syscall_proc.c index 98555cf5..342ea7c2 100644 --- a/Kernel/syscall_proc.c +++ b/Kernel/syscall_proc.c @@ -1,7 +1,6 @@ #include #include #include -#include #undef DEBUG diff --git a/Kernel/timer.c b/Kernel/timer.c index 88f07242..9f50e034 100644 --- a/Kernel/timer.c +++ b/Kernel/timer.c @@ -3,23 +3,23 @@ #include #include -/* the interrupt handler increments this after every timer interrupt */ -uint16_t system_timer; - -/* WRS: timer functions */ +/* WRS: simple timer functions */ timer_t set_timer_duration(uint16_t duration) { + timer_t a; if (duration & 0x8000) { kprintf("bad timer duration 0x%x\n", duration); } - return (system_timer + duration); + /* obvious code is return (miniticks+duration), however we have to do */ + /* it this longwinded way or sdcc doesn't load miniticks atomically */ + a = miniticks; + a += duration; + return a; } bool timer_expired(timer_t timer_val) { - if ((timer_val - system_timer) > 0x7fff) - return true; - return false; + return ((timer_val - miniticks) & 0x8000); } /*-----------------------------------------------------------*/ -- 2.34.1