Source
...
Target
Commits (1)
  • Ben Avison's avatar
    HALised microtime() · bad60796
    Ben Avison authored
    Detail:
      microtime(), which reads the current time into a struct timeval (seconds
      and microseconds) looked for an IOMD, and if not then dropped back to
      centisecond accuracy. This hadn't been noticed before, but upon trying the
      module on a 32-bit IOMD build, its attempt to access IOMD at its 26-bit
      address aborted. Now changed to use the HAL if possible, so all HAL machines
      now have a nice accurate microtime().
    Admin:
      Tested to the extent that it doesn't abort any more - precise checking of
      microtime() values has not been done, nor any analysis of the effect of
      the increased accuracy.
    
    Version 5.52. Tagged as 'Internet-5_52'
    bad60796
/* (5.51) /* (5.52)
* *
* This file is automatically maintained by srccommit, do not edit manually. * This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.2. * Last processed by srccommit version: 1.1.
* *
*/ */
#define Module_MajorVersion_CMHG 5.51 #define Module_MajorVersion_CMHG 5.52
#define Module_MinorVersion_CMHG #define Module_MinorVersion_CMHG
#define Module_Date_CMHG 24 Feb 2007 #define Module_Date_CMHG 22 Dec 2008
#define Module_MajorVersion "5.51" #define Module_MajorVersion "5.52"
#define Module_Version 551 #define Module_Version 552
#define Module_MinorVersion "" #define Module_MinorVersion ""
#define Module_Date "24 Feb 2007" #define Module_Date "22 Dec 2008"
#define Module_ApplicationDate "24-Feb-07" #define Module_ApplicationDate "22-Dec-08"
#define Module_ComponentName "Internet" #define Module_ComponentName "Internet"
#define Module_ComponentPath "RiscOS/Sources/Networking/AUN/Internet" #define Module_ComponentPath "mixed/RiscOS/Sources/Networking/AUN/Internet"
#define Module_FullVersion "5.51" #define Module_FullVersion "5.52"
#define Module_HelpVersion "5.51 (24 Feb 2007)" #define Module_HelpVersion "5.52 (22 Dec 2008)"
#define Module_LibraryVersionInfo "5:51" #define Module_LibraryVersionInfo "5:52"
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#include "module.h" #include "module.h"
#include "swiveneers.h" #include "swiveneers.h"
#include "Global/HALEntries.h"
#define TickerV 28 #define TickerV 28
#define NCALLOUT 20 #define NCALLOUT 20
...@@ -821,23 +823,43 @@ static int iomd_present() ...@@ -821,23 +823,43 @@ static int iomd_present()
*/ */
void microtime(struct timeval *tv) void microtime(struct timeval *tv)
{ {
static int iomd_check; /* 0 = not checked, 1 = present, 2 = not present */ static int iomd_check; /* 0 = not checked, 1 = present, 2 = no counter present, 3 = use HAL */
static unsigned long timer_divider; /* ticks per microsecond */
machinetime t1, t2; machinetime t1, t2;
unsigned long timer_count; unsigned long timer_count;
unsigned long timer_period = 19999; /* default for non-HAL case */
/* Only poke the hardware if we're sure it's there :) */ /* Only poke the hardware if we're sure it's there :) */
if (!iomd_check) if (!iomd_check)
{
if (_swix(OS_Hardware, _INR(8,9)|_OUT(0), 0, EntryNo_HAL_CounterRate, &timer_divider) != NULL)
{
iomd_check = iomd_present(); iomd_check = iomd_present();
timer_divider = 2;
}
else
{
iomd_check = 3;
timer_divider /= 1000000;
if (timer_divider == 0) timer_divider = 1; /* avoid division by 0 */
}
}
if (iomd_check == 1) if (iomd_check != 2)
{ {
if (iomd_check == 3)
_swix(OS_Hardware, _INR(8,9)|_OUT(0), 0, EntryNo_HAL_CounterPeriod, &timer_period);
/* Check initial time */ /* Check initial time */
osword_read_realtime(&t1); osword_read_realtime(&t1);
/* Read the Timer 0 value - it counts down from 19999 to 0, /* Read the Timer 0 value - it counts down from 19999 to 0,
* the clock tick occurring as it changes from 0 to 19999. * the clock tick occurring as it changes from 0 to 19999.
*/ */
if (iomd_check == 1)
timer_count = get_t0_count(); timer_count = get_t0_count();
else
_swix(OS_Hardware, _INR(8,9)|_OUT(0), 0, EntryNo_HAL_CounterRead, &timer_count);
} }
/* Check new time */ /* Check new time */
...@@ -846,10 +868,10 @@ void microtime(struct timeval *tv) ...@@ -846,10 +868,10 @@ void microtime(struct timeval *tv)
tv->tv_sec = machinetime_to_realtime(&t2, &tv->tv_usec); tv->tv_sec = machinetime_to_realtime(&t2, &tv->tv_usec);
tv->tv_usec *= 10000; tv->tv_usec *= 10000;
if (iomd_check == 1 && t1.l == t2.l) if (iomd_check != 2 && t1.l == t2.l)
{ {
/* Clock didn't tick - add in timer count */ /* Clock didn't tick - add in timer count */
tv->tv_usec += (19999 - timer_count) / 2; tv->tv_usec += (timer_period - timer_count) / timer_divider;
} }
else else
{ {
......