From ad92c2be0623ff2a6bdbd254d1c5a444959998ec Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 27 Dec 2014 21:38:56 +0000 Subject: [PATCH] timer: Move structures about All the clock bits are now in the cpu struct together. This also lets us flip the 6809 clock/mini union the right way up for big endian --- Kernel/cpu-6502/cpu.h | 11 +++++++++++ Kernel/cpu-6809/cpu.h | 13 ++++++++++++- Kernel/cpu-z80/cpu.h | 11 +++++++++++ Kernel/include/kernel.h | 3 --- Kernel/timer.c | 20 ++++++++++++-------- 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Kernel/cpu-6502/cpu.h b/Kernel/cpu-6502/cpu.h index eb39e672..ffce123a 100644 --- a/Kernel/cpu-6502/cpu.h +++ b/Kernel/cpu-6502/cpu.h @@ -24,11 +24,22 @@ extern size_t strlen(const char *); #define staticfast static +/* User's structure for times() system call */ +typedef unsigned long clock_t; + typedef struct { uint32_t low; uint32_t high; } time_t; +typedef union { /* this structure is endian dependent */ + clock_t full; /* 32-bit count of ticks since boot */ + union { + uint16_t low; /* 16-bit count of ticks since boot */ + uint16_t high; + } h; +} ticks_t; + /* We don't yet have bank attributes and banking for Z80 */ #define CODE1 #define CODE2 diff --git a/Kernel/cpu-6809/cpu.h b/Kernel/cpu-6809/cpu.h index 4d676aca..74705505 100644 --- a/Kernel/cpu-6809/cpu.h +++ b/Kernel/cpu-6809/cpu.h @@ -27,12 +27,23 @@ extern uint16_t swab(uint16_t); non-reentrant functions static */ #define staticfast auto -/* FIXME: should be 64bits - need to add helpers and struct variants */ +/* User's structure for times() system call */ +typedef unsigned long clock_t; + typedef struct { uint32_t low; uint32_t high; } time_t; +typedef union { /* this structure is endian dependent */ + clock_t full; /* 32-bit count of ticks since boot */ + union { + uint16_t high; + uint16_t low; /* 16-bit count of ticks since boot */ + } h; +} ticks_t; + + #define cpu_to_le16(x) swab(x) #define le16_to_cpu(x) swab(x) diff --git a/Kernel/cpu-z80/cpu.h b/Kernel/cpu-z80/cpu.h index a669a4a6..183376a1 100644 --- a/Kernel/cpu-z80/cpu.h +++ b/Kernel/cpu-z80/cpu.h @@ -31,12 +31,23 @@ extern int16_t strlen(const char *p); #define staticfast static +/* User's structure for times() system call */ +typedef unsigned long clock_t; + /* Must match native ordering of long long */ typedef struct { uint32_t low; uint32_t high; } time_t; +typedef union { /* this structure is endian dependent */ + clock_t full; /* 32-bit count of ticks since boot */ + union { + uint16_t low; /* 16-bit count of ticks since boot */ + uint16_t high; + } h; +} ticks_t; + /* We don't yet have bank attributes and banking for Z80 */ #define CODE1 #define CODE2 diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index c0be3662..ba689119 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -70,9 +70,6 @@ typedef struct s_queue { int q_wakeup; /* Threshold for waking up processes waiting on queue */ } queue_t; -/* User's structure for times() system call */ -typedef unsigned long clock_t; - struct tms { clock_t tms_utime; clock_t tms_stime; diff --git a/Kernel/timer.c b/Kernel/timer.c index f80708c1..e9b8a3c3 100644 --- a/Kernel/timer.c +++ b/Kernel/timer.c @@ -3,23 +3,27 @@ #include #include -/* WRS: simple timer functions */ +/* WRS: simple timer functions + + These use a 16bit "miniticks" to keep the generated code nice +*/ + timer_t set_timer_duration(uint16_t duration) { - timer_t a; + timer_t a; if (duration & 0x8000) { kprintf("bad timer duration 0x%x\n", duration); } - /* obvious code is return (miniticks+duration), however we have to do */ - /* it this longwinded way or sdcc doesn't load miniticks atomically */ - a = ticks.mini; - a += duration; - return a; + /* obvious code is return (miniticks+duration), however we have to do */ + /* it this longwinded way or sdcc doesn't load miniticks atomically */ + a = ticks.h.low; + a += duration; + return a; } bool timer_expired(timer_t timer_val) { - return ((timer_val - ticks.mini) & 0x8000); + return ((timer_val - ticks.h.low) & 0x8000); } /*-----------------------------------------------------------*/ -- 2.34.1