Kernel: Improve simple timer code. Remove timer.h include where it is not required.
authorWill Sowerbutts <will@sowerbutts.com>
Sat, 27 Dec 2014 01:37:45 +0000 (01:37 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Sat, 27 Dec 2014 11:39:55 +0000 (11:39 +0000)
19 files changed:
Kernel/bankfixed.c
Kernel/filesys.c
Kernel/include/kdata.h
Kernel/include/timer.h
Kernel/inode.c
Kernel/kdata.c
Kernel/lowlevel-z80.s
Kernel/process.c
Kernel/select.c
Kernel/simple.c
Kernel/single.c
Kernel/start.c
Kernel/swap.c
Kernel/syscall_exec.c
Kernel/syscall_fs.c
Kernel/syscall_fs2.c
Kernel/syscall_other.c
Kernel/syscall_proc.c
Kernel/timer.c

index 91bc6c2..e671ffd 100644 (file)
@@ -1,5 +1,4 @@
 #include <kernel.h>
-#include <timer.h>
 #include <kdata.h>
 #include <printf.h>
 
index 00d1c26..56dcb20 100644 (file)
@@ -2,7 +2,6 @@
 #include <kernel.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 /* 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
index e12fe7c..8d39af4 100644 (file)
@@ -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;
index 845dfee..6db1a83 100644 (file)
@@ -2,12 +2,14 @@
 #define __TIMER_DOT_H__
 
 #include <stdbool.h>
+#include <kdata.h>
 #include <kernel.h>
 
 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
index c8a1697..aaf1e96 100644 (file)
@@ -1,7 +1,6 @@
 #include <kernel.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 /* Writei (and readi) need more i/o error handling */
 void readi(inoptr ino, uint8_t flag)
index 1fb1281..39417ec 100644 (file)
@@ -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 */
 
index 2893fe0..5f04ef6 100644 (file)
@@ -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
index ca5efb3..1e11474 100644 (file)
@@ -3,7 +3,6 @@
 #undef DEBUGREALLYHARD         /* turn on getproc dumping */
 
 #include <kernel.h>
-#include <timer.h>
 #include <kdata.h>
 #include <printf.h>
 
index 61216b7..e1ce293 100644 (file)
@@ -2,7 +2,6 @@
 #include <version.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 /*
  *     Logic for select
index 5df4d0d..9b3092d 100644 (file)
@@ -3,7 +3,6 @@
  */
 
 #include <kernel.h>
-#include <timer.h>
 #include <kdata.h>
 #include <printf.h>
 
index 585bb7d..e4bf7a9 100644 (file)
@@ -1,5 +1,4 @@
 #include <kernel.h>
-#include <timer.h>
 #include <kdata.h>
 #include <printf.h>
 
index 331e6ee..85ddafa 100644 (file)
@@ -1,6 +1,5 @@
 #include <kernel.h>
 #include <version.h>
-#include <timer.h>
 #include <kdata.h>
 #include <printf.h>
 #include <tty.h>
index ea39596..ad99282 100644 (file)
@@ -4,7 +4,6 @@
  */
 
 #include <kernel.h>
-#include <timer.h>
 #include <kdata.h>
 #include <printf.h>
 
index c25175a..4d3c2e2 100644 (file)
@@ -2,7 +2,6 @@
 #include <version.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 static void close_on_exec(void)
 {
index b0245fc..139f9cd 100644 (file)
@@ -2,7 +2,6 @@
 #include <version.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 void updoff(void)
 {
index 0a78ce4..d3f87b8 100644 (file)
@@ -2,7 +2,6 @@
 #include <version.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 /*
  *     File system related calls that are not continually used (so
index 3f4c4db..ba1a653 100644 (file)
@@ -2,7 +2,6 @@
 #include <version.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 /*
  *     More obscure syscalls that it might be useful to pull out of the main
index 98555cf..342ea7c 100644 (file)
@@ -1,7 +1,6 @@
 #include <kernel.h>
 #include <kdata.h>
 #include <printf.h>
-#include <timer.h>
 
 #undef DEBUG
 
index 88f0724..9f50e03 100644 (file)
@@ -3,23 +3,23 @@
 #include <timer.h>
 #include <printf.h>
 
-/* 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);
 }
 
 /*-----------------------------------------------------------*/