summaryrefslogblamecommitdiffstats
path: root/private/ntos/fw/mips/jztime.c
blob: d57296de65521f48fab6a9e681c3b5150f6b1ed0 (plain) (tree)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415






























































































































































































































































































































































































































                                                                                
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    jztime.c

Abstract:

    This module contains the code to set the Jazz time.

Author:

    David M. Robinson (davidro) 25-Oct-1991

Revision History:

--*/



#include "jzsetup.h"

//
// Static Data
//

PVOID JzEisaControlBase;
PVOID JzRealTimeClockBase;
ULONG LastTime = 0;


UCHAR
JzReadClockRegister (
    UCHAR Register
    )

/*++

Routine Description:

    This routine reads the specified realtime clock register.

Arguments:

    Register - Supplies the number of the register whose value is read.

Return Value:

    The value of the register is returned as the function value.

--*/

{

    UCHAR DataByte;

    //
    // Read the EISA NMI enable register, insert the realtime clock register
    // number, and write the value back to the EISA NMI enable register. This
    // selects the realtime clock register that is read.
    //

    DataByte = READ_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI);
    DataByte = (DataByte & 0x80) | Register;
    WRITE_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI, DataByte);

    //
    // Read the realtime clock register value.
    //

    DataByte = READ_REGISTER_UCHAR((PUCHAR)JzRealTimeClockBase);
    return DataByte;
}

VOID
JzWriteClockRegister (
    UCHAR Register,
    UCHAR Value
    )

/*++

Routine Description:

    This routine writes the specified value to the specified realtime
    clock register.

Arguments:

    Register - Supplies the number of the register whose value is written.

    Value - Supplies the value that is written to the specified register.

Return Value:

    The value of the register is returned as the function value.

--*/

{
    UCHAR DataByte;

    //
    // Read the EISA NMI enable register, insert the realtime clock register
    // number, and write the value back to the EISA NMI enable register. This
    // selects the realtime clock register that is written.
    //

    DataByte = READ_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI);
    DataByte = (DataByte & 0x80) | Register;
    WRITE_REGISTER_UCHAR((PUCHAR)JzEisaControlBase + EISA_NMI, DataByte);

    //
    // Write the realtime clock register value.
    //

    WRITE_REGISTER_UCHAR((PUCHAR)JzRealTimeClockBase, Value);
    return;
}

VOID
JzWriteTime (
    IN PTIME_FIELDS TimeFields
    )

/*++

Routine Description:

    This routine sets the realtime clock.

    N.B. This routine assumes that the caller has provided any required
        synchronization to set the realtime clock information.

Arguments:

    TimeFields - Supplies a pointer to a time structure that specifies the
        realtime clock information.

Return Value:

    If the power to the realtime clock has not failed, then the time
    values are written to the realtime clock and a value of TRUE is
    returned. Otherwise, a value of FALSE is returned.

--*/

{

    UCHAR DataByte;

    //
    // If the realtime clock battery is still functioning, then write
    // the realtime clock values, and return a function value of TRUE.
    // Otherwise, return a function value of FALSE.
    //

    DataByte = JzReadClockRegister(RTC_CONTROL_REGISTERD);
    if (((PRTC_CONTROL_REGISTER_D)(&DataByte))->ValidTime == 1) {

        //
        // Set the realtime clock control to set the time.
        //

        DataByte = 0;
        ((PRTC_CONTROL_REGISTER_B)(&DataByte))->HoursFormat = 1;
        ((PRTC_CONTROL_REGISTER_B)(&DataByte))->DataMode = 1;
        ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 1;
        JzWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);

        //
        // Write the realtime clock values.
        //

        JzWriteClockRegister(RTC_YEAR, (UCHAR)(TimeFields->Year - 1980));
        JzWriteClockRegister(RTC_MONTH, (UCHAR)TimeFields->Month);
        JzWriteClockRegister(RTC_DAY_OF_MONTH, (UCHAR)TimeFields->Day);
        JzWriteClockRegister(RTC_DAY_OF_WEEK, (UCHAR)(TimeFields->Weekday + 1));
        JzWriteClockRegister(RTC_HOUR, (UCHAR)TimeFields->Hour);
        JzWriteClockRegister(RTC_MINUTE, (UCHAR)TimeFields->Minute);
        JzWriteClockRegister(RTC_SECOND, (UCHAR)TimeFields->Second);

        //
        // Set the realtime clock control to update the time.
        //

        ((PRTC_CONTROL_REGISTER_B)(&DataByte))->SetTime = 0;
        JzWriteClockRegister(RTC_CONTROL_REGISTERB, DataByte);
        return;

    } else {
        return;
    }
}


VOID
JzSetTime (
    VOID
    )

/*++

Routine Description:

Arguments:

Return Value:

--*/

{

    UCHAR Character;
    ULONG Count;
    PTIME_FIELDS TimeFields;
    TIME Time;
    CHAR TimeString[80];
    CHAR DateString[80];
    PCHAR StartToken;
    PCHAR EndToken;
    GETSTRING_ACTION Action;

    //
    // Set addresses for RTC access.
    //

    JzEisaControlBase = (PVOID)EISA_IO_VIRTUAL_BASE;
    JzRealTimeClockBase = (PVOID)RTC_VIRTUAL_BASE;

    JzSetPosition( 3, 5);
    JzPrint(JZ_ENTER_DATE_MSG);
    do {
        Action = FwGetString( DateString,
                              sizeof(DateString),
                              NULL,
                              3,
                              5 + strlen(JZ_ENTER_DATE_MSG));
        if (Action == GetStringEscape) {
            return;
        }
    } while ( Action != GetStringSuccess );

    JzSetPosition( 4, 5);
    JzPrint(JZ_ENTER_TIME_MSG);
    do {
        Action = FwGetString( TimeString,
                              sizeof(TimeString),
                              NULL,
                              4,
                              5 + strlen(JZ_ENTER_TIME_MSG));
        if (Action == GetStringEscape) {
            return;
        }
    } while ( Action != GetStringSuccess );

    //
    // Get time
    //

    TimeFields = ArcGetTime();

    StartToken = DateString;
    if (*StartToken != 0) {
        EndToken = strchr(StartToken, '-');
        if (EndToken != NULL) {
            *EndToken = 0;
            TimeFields->Month = atoi(StartToken);
            StartToken = EndToken + 1;
        }

        EndToken = strchr(StartToken, '-');
        if (EndToken != NULL) {
            *EndToken = 0;
            TimeFields->Day = atoi(StartToken);
            StartToken = EndToken + 1;
            TimeFields->Year = atoi(StartToken);
            if (TimeFields->Year < 100) {
                if (TimeFields->Year < 80) {
                    TimeFields->Year += 2000;
                } else {
                    TimeFields->Year += 1900;
                }
            }
        }
    }

    StartToken = TimeString;
    if (*StartToken != 0) {
        EndToken = strchr(StartToken, ':');

        if (EndToken != NULL) {
            *EndToken = 0;
            TimeFields->Hour = atoi(StartToken);
            StartToken = EndToken + 1;
        }

        EndToken = strchr(StartToken, ':');
        if (EndToken != NULL) {
            *EndToken = 0;
            TimeFields->Minute = atoi(StartToken);
            StartToken = EndToken + 1;
            TimeFields->Second = atoi(StartToken);
        } else {
            TimeFields->Minute = atoi(StartToken);
            TimeFields->Second = 0;
        }

    }

    if (!RtlTimeFieldsToTime(TimeFields, &Time)) {
        JzSetPosition( 5, 5);
        JzPrint(JZ_ILLEGAL_TIME_MSG);
        JzPrint(JZ_PRESS_KEY2_MSG);
        ArcRead(ARC_CONSOLE_INPUT, &Character, 1, &Count);
    } else {
        RtlTimeToTimeFields( &Time, TimeFields);
        JzWriteTime(TimeFields);
    }

}

VOID
JzShowTime (
    BOOLEAN First
    )

/*++

Routine Description:

Arguments:

    First - If TRUE then don't check LastTime.

Return Value:

--*/

{

    PTIME_FIELDS TimeFields;
    TIME Time;
    BOOLEAN Pm;
    ULONG ThisTime;

    //
    // Set addresses for RTC access.
    //

    JzEisaControlBase = (PVOID)EISA_IO_VIRTUAL_BASE;
    JzRealTimeClockBase = (PVOID)RTC_VIRTUAL_BASE;

    //
    // See if the time has changed since last time we were called.  This is
    // for when the display is over the serial port, so we don't blast
    // characters out all the time.
    //

    ThisTime = ArcGetRelativeTime();
    if (!First && (ThisTime == LastTime)) {

        //
        // Stall to get rid of the "whistle" on Jazz.
        //

        JzStallExecution(1000);
        return;
    }
    LastTime = ThisTime;

    //
    // Get and display time.
    //

    TimeFields = ArcGetTime();

    JzSetPosition( 0, 44);
    JzPrint("%s, ", Weekday[TimeFields->Weekday]);
    JzPrint("%d-", TimeFields->Month);
    JzPrint("%d-", TimeFields->Day);
    JzPrint("%d   ", TimeFields->Year);

    if (TimeFields->Hour >= 12) {
        Pm = TRUE;
    } else {
        Pm = FALSE;
    }

    if (TimeFields->Hour > 12) {
        TimeFields->Hour -= 12;
    } else if (TimeFields->Hour == 0) {
        TimeFields->Hour = 12;
    }

    JzPrint("%d:", TimeFields->Hour);
    JzPrint("%02d:", TimeFields->Minute);
    JzPrint("%02d ", TimeFields->Second);
    if (Pm) {
        JzPrint(JZ_PM);
    } else {
        JzPrint(JZ_AM);
    }

    //
    // Clear anything to the end of the line.
    //

    JzPrint("%cK", ASCII_CSI);

    return;

}