Commit 65244784 authored by Kevin Bracey's avatar Kevin Bracey
Browse files

Modified gettimeofday() to return microsecond accuracy, as long as it's...

Modified gettimeofday() to return microsecond accuracy, as long as it's running on an IOC or IOMD system.

Version 5.27. Tagged as 'TCPIPLibs-5_27'
parent 1fa7dd3c
/* (5.26)
/* (5.27)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 5.26
#define Module_MajorVersion_CMHG 5.27
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 15 Jul 1999
#define Module_Date_CMHG 19 Jul 1999
#define Module_MajorVersion "5.26"
#define Module_Version 526
#define Module_MajorVersion "5.27"
#define Module_Version 527
#define Module_MinorVersion ""
#define Module_Date "15 Jul 1999"
#define Module_Date "19 Jul 1999"
#define Module_FullVersion "5.26"
#define Module_FullVersion "5.27"
......@@ -45,7 +45,11 @@ INCLUDES= TCPIPLibs:,C:
CFLAGS= -depend !Depend -Wp -zps0 -I${INCLUDES} -fah -Fn -DINET -DCOMPAT_INET4
CFLAGSZM= -depend !Depend -Wp -zps1 -I${INCLUDES} -ffah -DINET -DCOMPAT_INET4 -zM
AFLAGS= -depend !Depend
AFLAGSZM= -depend !Depend -PD "module SETL {TRUE}"
CCZM= ${CC} ${CFLAGSZM}
ASZM= ${AS} ${AFLAGSZM}
CFILES= access.c chdir.c chmod.c close.c filestat.c flushinput.c \
fstat.c getdtabsiz.c getegid.c geteuid.c getgroups.c \
......@@ -55,7 +59,7 @@ CFILES= access.c chdir.c chmod.c close.c filestat.c flushinput.c \
memops.c osreadc.c read.c readdir.c readv.c strcasecmp.c \
stubs.c write.c writev.c xgets.c xperror.c xputchar.c \
getopt.c strsep.c kvm.c err.c errlst.c xstrerror.c \
strdup.c sleep.c ffs.c
strdup.c sleep.c ffs.c asm.s
OFILES= access.o chdir.o chmod.o close.o filestat.o flushinput.o \
fstat.o getdtabsiz.o getegid.o geteuid.o getgroups.o \
......@@ -65,7 +69,7 @@ OFILES= access.o chdir.o chmod.o close.o filestat.o flushinput.o \
memops.o osreadc.o read.o readdir.o readv.o strcasecmp.o \
stubs.o write.o writev.o xgets.o xperror.o xputchar.o \
getopt.o strsep.o kvm.o err.o errlst.o xstrerror.o \
strdup.o sleep.o ffs.o
strdup.o sleep.o ffs.o asm.o
ZFILES= z.access z.chdir z.chmod z.close z.filestat z.flushinput \
z.fstat z.getdtabsiz z.getegid z.geteuid z.getgroups \
......@@ -75,12 +79,14 @@ ZFILES= z.access z.chdir z.chmod z.close z.filestat z.flushinput \
z.memops z.osreadc z.read z.readdir z.readv z.strcasecmp \
z.stubs z.write z.writev z.xgets z.xperror z.xputchar \
z.getopt z.strsep z.kvm z.err z.errlst z.xstrerror \
z.strdup z.sleep z.ffs
z.strdup z.sleep z.ffs z.asm
.SUFFIXES: .z .o .c .s
.c.z:; ${CCZM} -c -o $@ $<
.c.o:; ${CC} ${CFLAGS} -c -o $@ $<
.s.z:; ${ASZM} -o $@ $<
.s.o:; ${AS} ${AFLAGS} -o $@ $<
COMPONENT = unixlib
LIBDIR = <Lib$Dir>
......
......@@ -24,23 +24,14 @@
* Initial revision
*
*/
#include <time.h>
#include "kernel.h"
/*
* YUCK YUCK YUCK
*
* time_t and clock_t are defined in <time.h>, stop their
* re-definition in "sys/types.h"
*/
#define __time_t
#define __clock_t
#include "sys/time.h"
#include "sys/types.h"
#include <sys/time.h>
#include <sys/types.h>
#include <swis.h>
#include "unixlib.h"
#include "asm.h"
#define secs0070 (((unsigned)86400) * (365 * 70 + 17)) /* less than 2^32 */
......@@ -48,30 +39,19 @@ typedef struct {unsigned int l,h;} machinetime;
/**********************************************************************/
static long realtime(long *csecs)
static long machinetime_to_realtime(machinetime *t, long *csecs)
{
/*
* this is time(), recoded here to avoid the absurd 6ms delay
* in the RISC OS 3 Shared C Library (penalty is timezone())
*/
machinetime bt, w, w2;
/*
* read timer as 5 byte integer
* centiseconds since 1/1/1900
*/
bt.l = 3; /* presumably 'request time' arg */
_kernel_osword(14, (int *)&bt);
/* to two 3-byte things - for divide */
w.h = ((bt.h & 255) << 8) | (bt.l >> 24);
w.l = bt.l & 0xffffff;
w.h = ((t->h & 255) << 8) | (t->l >> 24);
w.l = t->l & 0xffffff;
/* turn csecs to secs */
w2.h = w.h / 100;
w2.l = ((w.h % 100 << 24) | w.l) / 100;
if (csecs)
*csecs = ((w.h % 100 << 24) | w.l) % 100;
*csecs = ((w.h % 100L << 24) | w.l) % 100;
/* back to 8 byte binary */
bt.h = w2.h >> 8;
......@@ -90,16 +70,70 @@ static long realtime(long *csecs)
/**********************************************************************/
/*
* Return 1 if IOC/IOMD is present (OS_ReadSysInfo 2 reports I/O control
* chip = 0 or 1 - IOC or IOMD).
*/
static int iomd_present()
{
unsigned int hardware;
if (_swix(OS_ReadSysInfo, _IN(0)|_OUT(0), 2, &hardware))
return 2;
return (hardware & 0xFF00) <= 0x0100 ? 1 : 2;
}
/**********************************************************************/
/*
* This function is actully reasonably fast - it's between 7 and 8us
* on a 200MHz StrongARM.
*/
int gettimeofday(struct timeval *tv, struct timezone *tzp)
{
struct tm *t_gmt;
struct tm *t_local;
static int iomd_check; /* 0 = not checked, 1 = present, 2 = not present */
machinetime t1, t2;
unsigned long timer_count;
/* Only poke the hardware if we're sure it's there :) */
if (!iomd_check)
iomd_check = iomd_present();
tv->tv_sec = realtime(&tv->tv_usec);
t1.l = 3;
t2.l = 3;
if (iomd_check == 1)
{
/* Check initial time */
_kernel_osword(14, (int *) &t1);
/* Read the Timer 0 value - it counts down from 19999 to 0,
* the clock tick occurring as it changes from 0 to 19999.
*/
timer_count = _get_t0_count();
}
/* Check new time */
_kernel_osword(14, (int *) &t2);
tv->tv_sec = machinetime_to_realtime(&t2, &tv->tv_usec);
tv->tv_usec *= 10000;
if (iomd_check == 1 && t1.l == t2.l)
{
/* Clock didn't tick - add in timer count */
tv->tv_usec += (19999 - timer_count) / 2;
}
else
{
/* Clock ticked - let it rest at the 10000us boundary */
}
if ( tzp )
{
struct tm *t_gmt;
struct tm *t_local;
t_gmt = gmtime( (time_t *)&tv->tv_sec );
t_local = localtime( (time_t *)&tv->tv_sec );
tzp->tz_minuteswest = (int)difftime(mktime(t_gmt),
......
/* Copyright 1999 Pace Micro Technology plc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern unsigned int _get_t0_count(void);
; Copyright 1999 Pace Micro Technology plc
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
GET Hdr:ListOpts
GET Hdr:Macros
GET Hdr:System
EXPORT _get_t0_count
AREA |Asm$$Code|, CODE, READONLY
_get_t0_count
MOV r12,lr
SWI XOS_EnterOS
MOV r3,#IOC
STRB r3,[r3,#Timer0LR]
LDRB r1,[r3,#Timer0CL]
LDRB r0,[r3,#Timer0CH]
ORR r0,r1,r0,LSL #8
MOVS pc,r12
END
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment