Added some time related functions.

svn path=/trunk/; revision=732
This commit is contained in:
Eric Kohl 1999-10-24 17:52:17 +00:00
parent ad5e850736
commit 2bd986927c
5 changed files with 161 additions and 10 deletions

View file

@ -45,7 +45,9 @@ NtSetSystemTime (
IN PLARGE_INTEGER NewSystemTime OPTIONAL
)
{
UNIMPLEMENTED;
HalSetRealTimeClock ((PTIME)SystemTime);
// UNIMPLEMENTED;
return STATUS_SUCCESS;
}

View file

@ -22,19 +22,43 @@
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
/* MACROS and CONSTANTS ******************************************************/
/* macro BCD_INT : convert bcd to int */
#define BCD_INT(bcd) ( ((bcd &0xf0)>>4)*10+(bcd &0x0f) )
#define BCD_INT(bcd) ( ((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f) )
void HalQueryRealTimeClock(PTIME_FIELDS pTime)
/* macro INT_BCD : convert int to bcd */
#define INT_BCD(int) ( ((int / 10) << 4) + (int % 10) )
#define RTC_REGISTER_A 0x0A
#define RTC_REG_A_UIP 0x80 /* Update In Progress bit */
/* FUNCTIONS *****************************************************************/
VOID
HalQueryRealTimeClock(PTIME_FIELDS pTime)
{
//FIXME : wait RTC ok?
UCHAR uip; // Update In Progress
#if 0
do
{
outb(0x70,0);
pTime->Second=BCD_INT(inb(0x71));
} while(pTime->Second>60);
#endif
do
{
outb(0x70, RTC_REGISTER_A);
uip = inb(0x71) & RTC_REG_A_UIP;
} while(uip);
outb(0x70,0);
pTime->Second=BCD_INT(inb(0x71));
outb(0x70,2);
pTime->Minute=BCD_INT(inb(0x71));
outb(0x70,4);
@ -49,10 +73,54 @@ void HalQueryRealTimeClock(PTIME_FIELDS pTime)
pTime->Year=BCD_INT(inb_p(0x71));
if(pTime->Year>80) pTime->Year +=1900;
else pTime->Year +=2000;
#if 0
/* Century */
outb_p(0x70,0x32);
pTime->Year += BCD_INT(inb_p(0x71)) * 100;
#endif
pTime->Milliseconds=0;
}
void HalSetRealTimeClock(PTIME_FIELDS pTime)
VOID
HalSetRealTimeClock(PTIME_FIELDS pTime)
{
UCHAR uip; // Update In Progress
do
{
outb(0x70,0xA);
uip = inb(0x71) & RTC_REG_A_UIP;
} while(uip);
outb(0x70,0);
outb(0x71, INT_BCD(pTime->Second));
outb(0x70,2);
outb(0x71, INT_BCD(pTime->Minute));
outb(0x70,4);
outb(0x71, INT_BCD(pTime->Hour));
outb(0x70,6);
outb(0x71, INT_BCD(pTime->Weekday));
outb(0x70,7);
outb(0x71, INT_BCD(pTime->Day));
outb(0x70,8);
outb(0x71, INT_BCD(pTime->Month));
outb_p(0x70,9);
outb(0x71, INT_BCD(pTime->Year % 100));
/* Century */
#if 0
outb_p(0x70,0x32);
outb(0x71, INT_BCD(pTime->Year / 100));
#endif
}

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.def,v 1.19 1999/10/21 11:10:26 ekohl Exp $
; $Id: ntoskrnl.def,v 1.20 1999/10/24 17:52:17 ekohl Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -154,6 +154,7 @@ NtQueryInformationProcess@20
NtQueryInformationToken@20
;NtQueryOleDirectoryFile@ <--- ?
NtQuerySecurityObject@20
NtQuerySystemTime@4
NtQueryVolumeInformationFile@20
NtReadFile@36
;NtRequestPort@8
@ -165,6 +166,7 @@ NtSetInformationFile@20
NtSetInformationProcess@16
NtSetInformationThread@16
NtSetSecurityObject@12
NtSetSystemTime@8
NtUnlockFile@20
;NtVdmControl@8 <--- ?
NtWaitForSingleObject@12
@ -183,7 +185,11 @@ RtlLargeIntegerAdd
RtlLargeIntegerGreaterThan
RtlLargeIntegerShiftRight
RtlMoveMemory
RtlSecondsSince1970ToTime
RtlSecondsSince1980ToTime
RtlTimeFieldsToTime
RtlTimeToSecondsSince1970
RtlTimeToSecondsSince1980
RtlTimeToTimeFields
RtlZeroMemory
ZwAccessCheckAndAuditAlarm@44
@ -239,6 +245,7 @@ ZwQuerySection@20
ZwQuerySecurityObject@20
ZwQuerySymbolicLinkObject@12
ZwQuerySystemInformation@16
ZwQuerySystemTime@4
ZwQueryValueKey@24
ZwQueryVolumeInformationFile@20
ZwReadFile@36
@ -389,7 +396,7 @@ HalSetBusDataByOffset
HalSetDisplayParameters
;HalSetEnvironmentVariable
;HalSetProfileInterval
;HalSetRealTimeClock
HalSetRealTimeClock
;HalSetTimeIncrement
;HalStartNextProcessor
;HalStartProfileInterrupt

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.edf,v 1.7 1999/10/21 11:10:26 ekohl Exp $
; $Id: ntoskrnl.edf,v 1.8 1999/10/24 17:52:17 ekohl Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -154,6 +154,7 @@ NtQueryInformationProcess=NtQueryInformationProcess@20
NtQueryInformationToken=NtQueryInformationToken@20
;NtQueryOleDirectoryFile@ <--- ?
NtQuerySecurityObject=NtQuerySecurityObject@20
NtQuerySystemTime=NtQuerySystemTime@4
NtQueryVolumeInformationFile=NtQueryVolumeInformationFile@20
NtReadFile=NtReadFile@36
;NtRequestPort@8
@ -165,6 +166,7 @@ NtSetInformationFile=NtSetInformationFile@20
NtSetInformationProcess=NtSetInformationProcess@16
NtSetInformationThread=NtSetInformationThread@16
NtSetSecurityObject=NtSetSecurityObject@12
NtSetSystemTime=NtSetSystemTime@8
NtUnlockFile=NtUnlockFile@20
;NtVdmControl@8 <--- ?
NtWaitForSingleObject=NtWaitForSingleObject@12
@ -183,7 +185,11 @@ RtlLargeIntegerAdd
RtlLargeIntegerGreaterThan
RtlLargeIntegerShiftRight
RtlMoveMemory
RtlSecondsSince1970ToTime
RtlSecondsSince1980ToTime
RtlTimeFieldsToTime
RtlTimeToSecondsSince1970
RtlTimeToSecondsSince1980
RtlTimeToTimeFields
RtlZeroMemory
ZwAccessCheckAndAuditAlarm=ZwAccessCheckAndAuditAlarm@44
@ -239,6 +245,7 @@ ZwQuerySection=ZwQuerySection@20
ZwQuerySecurityObject=ZwQuerySecurityObject@20
ZwQuerySymbolicLinkObject=ZwQuerySymbolicLinkObject@12
ZwQuerySystemInformation=ZwQuerySystemInformation@16
ZwQuerySystemTime=ZwQuerySystemTime@4
ZwQueryValueKey=ZwQueryValueKey@24
ZwQueryVolumeInformationFile=ZwQueryVolumeInformationFile@20
ZwReadFile=ZwReadFile@36
@ -389,7 +396,7 @@ HalSetBusDataByOffset
HalSetDisplayParameters
;HalSetEnvironmentVariable
;HalSetProfileInterval
;HalSetRealTimeClock
HalSetRealTimeClock
;HalSetTimeIncrement
;HalStartNextProcessor
;HalStartProfileInterrupt

View file

@ -1,4 +1,5 @@
/*
/* $Id: time.c,v 1.8 1999/10/24 17:51:54 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: kernel/rtl/time.c
@ -31,6 +32,10 @@
#define DAYSPERLEAPYEAR 366
#define MONSPERYEAR 12
#define TICKSTO1970 0x019db1ded53e8000
#define TICKSTO1980 0x01a8e79fe1d58000
static const int YearLengths[2] = {DAYSPERNORMALYEAR, DAYSPERLEAPYEAR};
static const int MonthLengths[2][MONSPERYEAR] =
{
@ -189,3 +194,65 @@ BOOLEAN RtlTimeFieldsToTime(PTIME_FIELDS tfTimeFields,
return TRUE;
}
VOID
RtlSecondsSince1970ToTime (ULONG SecondsSince1970,
PLARGE_INTEGER Time)
{
LONGLONG llTime;
llTime = (SecondsSince1970 * TICKSPERSEC) + TICKSTO1970;
*Time = *(LARGE_INTEGER *)&llTime;
}
VOID
RtlSecondsSince1980ToTime (ULONG SecondsSince1980,
PLARGE_INTEGER Time)
{
LONGLONG llTime;
llTime = (SecondsSince1980 * TICKSPERSEC) + TICKSTO1980;
*Time = *(LARGE_INTEGER *)&llTime;
}
BOOLEAN
RtlTimeToSecondsSince1970 (PLARGE_INTEGER Time,
PULONG SecondsSince1970)
{
LARGE_INTEGER liTime;
liTime.QuadPart = Time->QuadPart - TICKSTO1970;
liTime.QuadPart = liTime.QuadPart / TICKSPERSEC;
if (liTime.u.HighPart != 0)
return FALSE;
*SecondsSince1970 = liTime.u.LowPart;
return TRUE;
}
BOOLEAN
RtlTimeToSecondsSince1980 (PLARGE_INTEGER Time,
PULONG SecondsSince1980)
{
LARGE_INTEGER liTime;
liTime.QuadPart = Time->QuadPart - TICKSTO1980;
liTime.QuadPart = liTime.QuadPart / TICKSPERSEC;
if (liTime.u.HighPart != 0)
return FALSE;
*SecondsSince1980 = liTime.u.LowPart;
return TRUE;
}
/* EOF */