summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/mips/fwtime.c
blob: 3720e2bcf1d08f82633916dc00f98ffaa01e85cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    fwtime.c

Abstract:

    This module implements the ARC firmware time operations.

Author:

    David M. Robinson (davidro) 19-Aug-1991


Revision History:


--*/

#include "fwp.h"
#include "jxhalp.h"

//
// Static data.
//

TIME_FIELDS FwTime;
ULONG Seconds;
ULONG FwDays;

//
// Define global data used to locate the EISA control space and the realtime
// clock registers.
//

PVOID HalpEisaControlBase;
PVOID HalpRealTimeClockBase;


ARC_STATUS
FwTimeInitialize (
    VOID
    )

/*++

Routine Description:

    This routine initializes the time routine addresses.

Arguments:

    None.

Return Value:

    ESUCCESS is returned.

--*/
{

    //
    // Initialize the time routine addresses in the system
    // parameter block.
    //

    (PARC_GET_TIME_ROUTINE)SYSTEM_BLOCK->FirmwareVector[GetTimeRoutine] =
                                                            FwGetTime;
    (PARC_GET_RELATIVE_TIME_ROUTINE)SYSTEM_BLOCK->FirmwareVector[GetRelativeTimeRoutine] =
                                                            FwGetRelativeTime;

    //
    // Initialize pointers that the HAL routines use to access the RTC.  Note
    // that these routines are linked with the firmware and so this does not
    // affect the actual HAL.
    //

    HalpEisaControlBase = (PVOID)EISA_IO_VIRTUAL_BASE;
    HalpRealTimeClockBase = (PVOID)RTC_VIRTUAL_BASE;

    //
    // Initialize static data.
    //

    Seconds = 0;
    FwDays = 0;

    return ESUCCESS;
}

PTIME_FIELDS
FwGetTime (
    VOID
    )

/*++

Routine Description:

    This routine returns a time structure filled in with the current
    time read from the RTC.

Arguments:

    None.

Return Value:

    Returns a pointer to a time structure.  If the time information is
    valid, valid data is returned, otherwise all fields are returned as zero.

--*/

{
    if (!HalQueryRealTimeClock(&FwTime)) {
        FwTime.Year = 0;
        FwTime.Month = 0;
        FwTime.Day = 0;
        FwTime.Hour = 0;
        FwTime.Minute = 0;
        FwTime.Second = 0;
        FwTime.Milliseconds = 0;
        FwTime.Weekday = 0;
    }
    return &FwTime;
}


ULONG
FwGetRelativeTime (
    VOID
    )

/*++

Routine Description:

    This routine returns a ULONG which increases at a rate of one per second.
    This routine must be called at least once per day for the number to maintain
    an accurate count.

Arguments:

    None.

Return Value:

    Returns a pointer to a ULONG.  If the time information is valid, valid
    data is returned, otherwise a zero is returned.

--*/

{
    TIME_FIELDS Time;
    ULONG TempTime;

    TempTime = Seconds;
    if (HalQueryRealTimeClock(&Time)) {
        Seconds = ((FwDays * 24 + Time.Hour) * 60 + Time.Minute) * 60 + Time.Second;
        if (Seconds < TempTime) {
            FwDays++;
            Seconds += 24 * 60 * 60;
        }
    } else {
        Seconds = 0;
    }
    return Seconds;
}