RP5C15.java
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: package xeij;
36:
37: import java.lang.*;
38: import java.util.*;
39:
40: public class RP5C15 {
41:
42: public static final boolean RTC_DEBUG_TRACE = false;
43: public static final boolean RTC_DEBUG_WRITE = false;
44: public static final boolean RTC_DEBUG_GAP = false;
45:
46:
47:
48:
49:
50:
51: public static final int RTC_0_SECO0 = 0x01;
52: public static final int RTC_0_SECO1 = 0x03;
53:
54:
55: public static final int RTC_0_MINU0 = 0x05;
56: public static final int RTC_0_MINU1 = 0x07;
57:
58:
59:
60:
61:
62: public static final int RTC_0_HOUR0 = 0x09;
63: public static final int RTC_0_HOUR1 = 0x0b;
64:
65:
66:
67:
68:
69:
70:
71:
72: public static final int RTC_0_WDAY = 0x0d;
73:
74:
75:
76:
77:
78:
79:
80:
81: public static final int RTC_0_MDAY0 = 0x0f;
82: public static final int RTC_0_MDAY1 = 0x11;
83:
84:
85: public static final int RTC_0_MONT0 = 0x13;
86: public static final int RTC_0_MONT1 = 0x15;
87:
88:
89:
90:
91:
92:
93: public static final int RTC_0_YEAR0 = 0x17;
94: public static final int RTC_0_YEAR1 = 0x19;
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105: public static final int RTC_1_CLKOUT = 0x01;
106:
107:
108: public static final int RTC_1_ADJUST = 0x03;
109:
110:
111:
112:
113:
114: public static final int RTC_1_MINU0 = 0x05;
115: public static final int RTC_1_MINU1 = 0x07;
116: public static final int RTC_1_HOUR0 = 0x09;
117: public static final int RTC_1_HOUR1 = 0x0b;
118: public static final int RTC_1_WDAY = 0x0d;
119: public static final int RTC_1_MDAY0 = 0x0f;
120: public static final int RTC_1_MDAY1 = 0x11;
121:
122:
123: public static final int RTC_1_RULE = 0x15;
124:
125:
126:
127:
128:
129:
130: public static final int RTC_1_LEAP = 0x17;
131:
132:
133:
134: public static final int RTC_MODE = 0x1b;
135:
136:
137:
138:
139:
140: public static final int RTC_TEST = 0x1d;
141:
142:
143:
144:
145: public static final int RTC_RESET = 0x1f;
146:
147:
148:
149:
150: public static int rtcRule;
151: public static int rtcMove;
152: public static int rtcAlarm;
153: public static int rtcBank;
154: public static final byte[] rtcRegBank0 = new byte[32];
155: public static final byte[] rtcRegBank1 = new byte[32];
156: public static byte[] rtcRegCurrent;
157: public static int rtcTest;
158: public static MemoryMappedDevice rtcFirst;
159: public static long rtcTestStartCmil;
160: public static long rtcTestStartTime;
161:
162:
163:
164:
165:
166:
167:
168: public static int rtcWeekGap;
169:
170:
171:
172:
173:
174:
175:
176:
177:
178: public static long rtcInitialCmilGap;
179: public static long rtcCmilGap;
180: public static long rtcCmil;
181: public static int rtcCday;
182: public static int rtcDsec;
183:
184:
185:
186: public static void rtcInit () {
187: if (RTC_DEBUG_TRACE) {
188: System.out.printf ("rtcInit()\n");
189: }
190: rtcRule = 1;
191: rtcMove = 8;
192: rtcAlarm = 0;
193: rtcBank = 0;
194: rtcRegCurrent = rtcBank == 0 ? rtcRegBank0 : rtcRegBank1;
195: rtcTest = 0;
196: rtcFirst = rtcTest == 0 ? MemoryMappedDevice.MMD_RTC_FIRST : MemoryMappedDevice.MMD_RTC_TEST;
197: rtcTestStartCmil = 0;
198: rtcTestStartTime = 0;
199: if (RTC_DEBUG_TRACE) {
200: System.out.printf (" rtcRule=%d\n", rtcRule);
201: System.out.printf (" rtcMove=%d\n", rtcMove);
202: System.out.printf (" rtcBank=%d\n", rtcBank);
203: System.out.printf (" rtcTest=%d\n", rtcTest);
204: }
205:
206: rtcRegBank0[RTC_0_SECO0] = 0;
207: rtcRegBank0[RTC_0_SECO1] = 0;
208: rtcRegBank0[RTC_0_MINU0] = 0;
209: rtcRegBank0[RTC_0_MINU1] = 0;
210: rtcRegBank0[RTC_0_HOUR0] = 0;
211: rtcRegBank0[RTC_0_HOUR1] = 0;
212:
213: rtcRegBank0[RTC_0_WDAY] = 2;
214: rtcRegBank0[RTC_0_MDAY0] = 1;
215: rtcRegBank0[RTC_0_MDAY1] = 0;
216: rtcRegBank0[RTC_0_MONT0] = 1;
217: rtcRegBank0[RTC_0_MONT1] = 0;
218: rtcRegBank0[RTC_0_YEAR0] = 0;
219: rtcRegBank0[RTC_0_YEAR1] = 0;
220: rtcRegBank1[RTC_1_CLKOUT] = 0;
221: rtcRegBank1[RTC_1_ADJUST] = 0;
222: rtcRegBank1[RTC_1_MINU0] = 16;
223: rtcRegBank1[RTC_1_MINU1] = 16;
224: rtcRegBank1[RTC_1_HOUR0] = 16;
225: rtcRegBank1[RTC_1_HOUR1] = 16;
226: rtcRegBank1[RTC_1_WDAY] = 16;
227: rtcRegBank1[RTC_1_MDAY0] = 16;
228: rtcRegBank1[RTC_1_MDAY1] = 16;
229: rtcRegBank1[RTC_1_RULE] = (byte) rtcRule;
230: rtcRegBank1[RTC_1_LEAP] = 0;
231: rtcRegBank1[RTC_MODE] = (byte) (rtcMove + rtcBank);
232: rtcRegBank1[RTC_TEST] = (byte) rtcTest;
233: rtcRegBank1[RTC_RESET] = 0;
234: rtcWeekGap = 4;
235: rtcInitialCmilGap = TimeZone.getDefault ().getOffset (System.currentTimeMillis ());
236: rtcCmilGap = rtcInitialCmilGap;
237: if (RTC_DEBUG_GAP) {
238: System.out.printf ("rtcInit rtcCmilGap=%d\n", rtcCmilGap);
239: }
240: rtcCmil = 315532800000L;
241: rtcCday = 3652;
242: rtcDsec = 0;
243: if (RTC_DEBUG_TRACE) {
244: System.out.printf (" rtcWeekGap=%d\n", rtcWeekGap);
245: System.out.printf (" rtcCmilGap=%d\n", rtcCmilGap);
246: System.out.printf (" rtcCmil=%d (%s)\n", rtcCmil, DnT.dntSdttmCmil (rtcCmil));
247: System.out.printf (" rtcCday=%d (%s)\n", rtcCday, DnT.dntSdtCday (rtcCday));
248: System.out.printf (" rtcDsec=%d (%s)\n", rtcDsec, DnT.dntStmDsec (rtcDsec));
249: rtcDumpReg ();
250: System.out.printf (" 3652=%d\n", DnT.dntCdayYearMontMday (1980, 1, 1));
251: System.out.printf (" 40176=%d\n", DnT.dntCdayYearMontMday (2079, 12, 31));
252: System.out.printf (" 315532800000=%d\n", DnT.dntCmilYearMontMdayHourMinuSecoMill (1980, 1, 1, 0, 0, 0, 0));
253: System.out.printf (" 3471292799999=%d\n", DnT.dntCmilYearMontMdayHourMinuSecoMill (2079, 12, 31, 23, 59, 59, 999));
254: System.out.printf (" 1980-01-01=%s\n", DnT.dntSdtCday (3652));
255: System.out.printf (" 2079-12-31=%s\n", DnT.dntSdtCday (40176));
256: System.out.printf (" 1980-01-01 00:00:00.999=%s\n", DnT.dntSdttmCmil (315532800000L));
257: System.out.printf (" 2079-12-31 23:59:59.999=%s\n", DnT.dntSdttmCmil (3471292799999L));
258: }
259: }
260:
261:
262: public static void rtcReset () {
263: if (RTC_DEBUG_TRACE) {
264: System.out.printf ("rtcReset()\n");
265: }
266: }
267:
268:
269:
270: public static void rtcSetByHost () {
271: if (RTC_DEBUG_TRACE) {
272: System.out.printf ("rtcSetByHost()\n");
273: }
274: XEiJ.tmrTimer.schedule (new TimerTask () {
275: @Override public void run () {
276: if (rtcTest != 0) {
277:
278: XEiJ.busSuper (MemoryMappedDevice.MMD_RTC_FIRST, 0x00e8a000, 0x00e8c000);
279: rtcTest = 0;
280: rtcFirst = MemoryMappedDevice.MMD_RTC_FIRST;
281: if (RTC_DEBUG_TRACE) {
282: System.out.printf (" rtcTest=%d\n", rtcTest);
283: }
284: }
285: if (rtcMove == 0) {
286:
287: rtcMove = 8;
288: if (RTC_DEBUG_TRACE) {
289: System.out.printf (" rtcMove=%d\n", rtcMove);
290: }
291: }
292: rtcCmilGap = rtcInitialCmilGap;
293: if (RTC_DEBUG_GAP) {
294: System.out.printf ("rtcSetByHost rtcCmilGap=%d\n", rtcCmilGap);
295: }
296: if (RTC_DEBUG_TRACE) {
297: System.out.printf (" rtcCmilGap=%d\n", rtcCmilGap);
298: }
299: rtcUpdate ();
300: }
301: }, 10L);
302: }
303:
304: public static final long[] RTC_TEST_FREQ = {
305:
306: 0L,
307: XEiJ.TMR_FREQ / (16384L * ( 1L)),
308: XEiJ.TMR_FREQ / (16384L * ( 1L )),
309: XEiJ.TMR_FREQ / (16384L * ( 60L + 1L)),
310: XEiJ.TMR_FREQ / (16384L * ( 1L )),
311: XEiJ.TMR_FREQ / (16384L * ( 86400L + 1L)),
312: XEiJ.TMR_FREQ / (16384L * ( 1440L + 1L )),
313: XEiJ.TMR_FREQ / (16384L * ( 86400L + 60L + 1L)),
314: XEiJ.TMR_FREQ / (16384L * ( 1L )),
315: XEiJ.TMR_FREQ / (16384L * (31557600L + 1L)),
316: XEiJ.TMR_FREQ / (16384L * ( 525960L + 1L )),
317: XEiJ.TMR_FREQ / (16384L * (31557600L + 60L + 1L)),
318: XEiJ.TMR_FREQ * 4L / (16384L * ( 1461L + 4L )),
319: XEiJ.TMR_FREQ / (16384L * (31557600L + 86400L + 1L)),
320: XEiJ.TMR_FREQ / (16384L * ( 525960L + 1440L + 1L )),
321: XEiJ.TMR_FREQ / (16384L * (31557600L + 86400L + 60L + 1L)),
322: };
323: public static final long[] RTC_TEST_SCALE = {
324:
325: 0L,
326: ( 1000L),
327: ( 60000L ),
328: ( 1000L),
329: ( 86400000L ),
330: ( 1000L),
331: ( 60000L ),
332: ( 1000L),
333: (31557600000L ),
334: ( 1000L),
335: ( 60000L ),
336: ( 1000L),
337: ( 86400000L ),
338: ( 1000L),
339: ( 60000L ),
340: ( 1000L),
341: };
342:
343:
344:
345: public static void rtcTestUpdate () {
346: if (RTC_DEBUG_TRACE) {
347: System.out.printf ("rtcTestUpdate()\n");
348: }
349: if (rtcMove != 0) {
350: rtcSetCmil (rtcTestStartCmil +
351: ((XEiJ.mpuClockTime - rtcTestStartTime) / RTC_TEST_FREQ[rtcTest]) * RTC_TEST_SCALE[rtcTest]);
352: }
353: }
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364: public static void rtcUpdate () {
365: if (RTC_DEBUG_TRACE) {
366: System.out.printf ("rtcUpdate()\n");
367: XEiJ.prgPrintStackTrace ();
368: }
369: if (rtcMove != 0) {
370: rtcSetCmil (System.currentTimeMillis () + rtcCmilGap);
371: }
372: }
373:
374:
375:
376: public static void rtcSetCmil (long cmil) {
377: if (RTC_DEBUG_TRACE) {
378: System.out.printf ("rtcSetCmil(%d)\n", cmil);
379: }
380:
381:
382:
383:
384: long shift = DnT.dntFdiv (cmil - 315532800000L, 3471292800000L - 315532800000L) * (3471292800000L - 315532800000L);
385: if (shift != 0L) {
386: cmil -= shift;
387: rtcCmilGap -= shift;
388: if (RTC_DEBUG_GAP) {
389: System.out.printf ("rtcSetCmil rtcCmilGap=%d\n", rtcCmilGap);
390: }
391: if (RTC_DEBUG_TRACE) {
392: System.out.printf (" rtcCmilGap=%d\n", rtcCmilGap);
393: }
394: }
395: if (rtcCmil != cmil) {
396: rtcCmil = cmil;
397: if (RTC_DEBUG_TRACE) {
398: System.out.printf (" rtcCmil=%d (%s)\n", rtcCmil, DnT.dntSdttmCmil (rtcCmil));
399: }
400: int cday = DnT.dntCdayCmil (cmil);
401: int dsec = DnT.dntDsecCmil (cmil);
402: if (rtcCday != cday) {
403: rtcCday = cday;
404: if (RTC_DEBUG_TRACE) {
405: System.out.printf (" rtcCday=%d (%s)\n", rtcCday, DnT.dntSdtCday (rtcCday));
406: }
407: int date = DnT.dntDateCday (cday);
408: int t = XEiJ.FMT_BCD4[DnT.dntYearDate (date) - 1980];
409: rtcRegBank0[RTC_0_YEAR1] = (byte) (t >> 4);
410: rtcRegBank0[RTC_0_YEAR0] = (byte) (t & 15);
411: rtcRegBank1[RTC_1_LEAP] = (byte) (t & 3);
412: t = XEiJ.FMT_BCD4[DnT.dntMontDate (date)];
413: rtcRegBank0[RTC_0_MONT1] = (byte) (t >> 4);
414: rtcRegBank0[RTC_0_MONT0] = (byte) (t & 15);
415: t = XEiJ.FMT_BCD4[DnT.dntMdayDate (date)];
416: rtcRegBank0[RTC_0_MDAY1] = (byte) (t >> 4);
417: rtcRegBank0[RTC_0_MDAY0] = (byte) (t & 15);
418: rtcRegBank0[RTC_0_WDAY] = (byte) DnT.dntFrem (cday + rtcWeekGap, 7);
419: if (RTC_DEBUG_TRACE) {
420: rtcDumpReg ();
421: }
422: }
423: if (rtcDsec != dsec) {
424: rtcDsec = dsec;
425: if (RTC_DEBUG_TRACE) {
426: System.out.printf (" rtcDsec=%d (%s)\n", rtcDsec, DnT.dntStmDsec (rtcDsec));
427: }
428: int time = DnT.dntTimeDsec (dsec);
429: int t = DnT.dntHourTime (time);
430: t = XEiJ.FMT_BCD4[rtcRule == 0 && 12 <= t ? t + 8 : t];
431: rtcRegBank0[RTC_0_HOUR1] = (byte) (t >> 4);
432: rtcRegBank0[RTC_0_HOUR0] = (byte) (t & 15);
433: t = XEiJ.FMT_BCD4[DnT.dntMinuTime (time)];
434: rtcRegBank0[RTC_0_MINU1] = (byte) (t >> 4);
435: rtcRegBank0[RTC_0_MINU0] = (byte) (t & 15);
436: t = XEiJ.FMT_BCD4[DnT.dntSecoTime (time)];
437: rtcRegBank0[RTC_0_SECO1] = (byte) (t >> 4);
438: rtcRegBank0[RTC_0_SECO0] = (byte) (t & 15);
439: if (RTC_DEBUG_TRACE) {
440: rtcDumpReg ();
441: }
442: }
443: }
444: }
445:
446:
447: public static void rtcDumpReg () {
448: System.out.printf (" L YY-MM-DD W R HH:MM:SS\n" +
449: " %01X %01X%01X-%01X%01X-%01X%01X %01X %01X %01X%01X:%01X%01X:%01X%01X\n",
450: rtcRegBank1[RTC_1_LEAP],
451: rtcRegBank0[RTC_0_YEAR1], rtcRegBank0[RTC_0_YEAR0],
452: rtcRegBank0[RTC_0_MONT1], rtcRegBank0[RTC_0_MONT0],
453: rtcRegBank0[RTC_0_MDAY1], rtcRegBank0[RTC_0_MDAY0],
454: rtcRegBank0[RTC_0_WDAY],
455: rtcRegBank1[RTC_1_RULE],
456: rtcRegBank0[RTC_0_HOUR1], rtcRegBank0[RTC_0_HOUR0],
457: rtcRegBank0[RTC_0_MINU1], rtcRegBank0[RTC_0_MINU0],
458: rtcRegBank0[RTC_0_SECO1], rtcRegBank0[RTC_0_SECO0]);
459: }
460:
461:
462: public static void rtcAddSeco (int seco) {
463: if (RTC_DEBUG_TRACE) {
464: System.out.printf ("rtcAddSeco(%d)\n", seco);
465: }
466: long mill = (long) seco * 1000L;
467: rtcCmilGap += mill;
468: if (RTC_DEBUG_GAP) {
469: System.out.printf ("rtcAddSeco rtcCmilGap=%d\n", rtcCmilGap);
470: }
471: rtcCmil += mill;
472: rtcCday = DnT.dntCdayCmil (rtcCmil);
473: rtcDsec = DnT.dntDsecCmil (rtcCmil);
474: if (RTC_DEBUG_TRACE) {
475: System.out.printf (" rtcCmilGap=%d\n", rtcCmilGap);
476: System.out.printf (" rtcCmil=%d (%s)\n", rtcCmil, DnT.dntSdttmCmil (rtcCmil));
477: System.out.printf (" rtcCday=%d (%s)\n", rtcCday, DnT.dntSdtCday (rtcCday));
478: System.out.printf (" rtcDsec=%d (%s)\n", rtcDsec, DnT.dntStmDsec (rtcDsec));
479: }
480: if (rtcTest != 0) {
481: rtcTestStartCmil = rtcCmil;
482: rtcTestStartTime = XEiJ.mpuClockTime;
483: if (RTC_DEBUG_TRACE) {
484: System.out.printf (" rtcTestStartCmil=%d (%s)\n", rtcTestStartCmil, DnT.dntSdttmCmil (rtcTestStartCmil));
485: System.out.printf (" rtcTestStartTime=%d\n", rtcTestStartTime);
486: }
487: }
488: }
489:
490:
491: public static void rtcAddMday (int mday) {
492: if (RTC_DEBUG_TRACE) {
493: System.out.printf ("rtcAddMday(%d)\n", mday);
494: }
495: rtcAddSeco (mday * 86400);
496: rtcWeekGap = DnT.dntFrem (rtcWeekGap - mday, 7);
497: if (RTC_DEBUG_TRACE) {
498: System.out.printf (" rtcWeekGap=%d\n", rtcWeekGap);
499: }
500: }
501:
502:
503:
504: public static int rtcPeekByte (int a) {
505: int d = rtcRegCurrent[a & 31] & 15;
506: if (RTC_DEBUG_TRACE) {
507: System.out.printf ("rtcPeekByte(0x%08x)=0x%02x\n", a, d & 255);
508: }
509: return d;
510: }
511:
512:
513:
514: public static int rtcReadByte (int a) {
515: int d = rtcRegCurrent[a & 31] & 15;
516: if (RTC_DEBUG_TRACE) {
517: System.out.printf ("rtcReadByte(0x%08x)=0x%02x\n", a, d & 255);
518: }
519: return d;
520: }
521:
522: public static final String[] RTC_REG_NAME = (
523: "one second," +
524: "ten seconds," +
525: "one minute," +
526: "ten minutes," +
527: "one hour," +
528: "ten hours," +
529: "day of week," +
530: "one day," +
531: "ten days," +
532: "one month," +
533: "ten months," +
534: "one year," +
535: "ten years," +
536: "mode," +
537: "test," +
538: "reset," +
539: "clkout," +
540: "adjust," +
541: "alarm one minute," +
542: "alarm ten minutes," +
543: "alarm one hour," +
544: "alarm ten hours," +
545: "alarm day of week," +
546: "alarm one day," +
547: "alarm ten days," +
548: "," +
549: "twenty four," +
550: "leap year," +
551: "," +
552: "mode," +
553: "test," +
554: "reset"
555: ).split (",");
556:
557:
558:
559: public static void rtcWriteByte (int a, int d) {
560: if (RTC_DEBUG_TRACE ||
561: (RTC_DEBUG_WRITE &&
562: (a & 31) != RTC_MODE && (byte) (d & (8 + 4)) != rtcMove + rtcAlarm)) {
563: System.out.printf ("%08X rtcWriteByte@%d(0x%08x(%s),0x%02x)\n",
564: XEiJ.regPC0, rtcBank, a,
565: (a & 1) == 0 ? "" : RTC_REG_NAME[rtcBank << 4 | ((a & 31) >> 1)],
566: d & 255);
567: }
568: switch (rtcBank << 5 | a & 31) {
569:
570: case 0 << 5 | RTC_0_SECO0:
571: d &= 15;
572: rtcAddSeco (d - rtcRegBank0[RTC_0_SECO0]);
573: rtcRegBank0[RTC_0_SECO0] = (byte) d;
574: if (RTC_DEBUG_TRACE) {
575: rtcDumpReg ();
576: }
577: return;
578: case 0 << 5 | RTC_0_SECO1:
579: d &= 7;
580: rtcAddSeco ((d - rtcRegBank0[RTC_0_SECO1]) * 10);
581: rtcRegBank0[RTC_0_SECO1] = (byte) d;
582: if (RTC_DEBUG_TRACE) {
583: rtcDumpReg ();
584: }
585: return;
586: case 0 << 5 | RTC_0_MINU0:
587: d &= 15;
588: rtcAddSeco ((d - rtcRegBank0[RTC_0_MINU0]) * 60);
589: rtcRegBank0[RTC_0_MINU0] = (byte) d;
590: if (RTC_DEBUG_TRACE) {
591: rtcDumpReg ();
592: }
593: return;
594: case 0 << 5 | RTC_0_MINU1:
595: d &= 7;
596: rtcAddSeco ((d - rtcRegBank0[RTC_0_MINU1]) * 600);
597: rtcRegBank0[RTC_0_MINU1] = (byte) d;
598: if (RTC_DEBUG_TRACE) {
599: rtcDumpReg ();
600: }
601: return;
602: case 0 << 5 | RTC_0_HOUR0:
603: d &= 15;
604: rtcAddSeco ((d - rtcRegBank0[RTC_0_HOUR0]) * 3600);
605: rtcRegBank0[RTC_0_HOUR0] = (byte) d;
606: if (RTC_DEBUG_TRACE) {
607: rtcDumpReg ();
608: }
609: return;
610: case 0 << 5 | RTC_0_HOUR1:
611: d &= 3;
612: rtcAddSeco (((d >> 1) - (rtcRegBank0[RTC_0_HOUR1] >> 1)) * (rtcRule == 0 ? 43200 : 72000) +
613: ((d & 1) - (rtcRegBank0[RTC_0_HOUR1] & 1)) * 36000);
614: rtcRegBank0[RTC_0_HOUR1] = (byte) d;
615: if (RTC_DEBUG_TRACE) {
616: rtcDumpReg ();
617: }
618: return;
619: case 0 << 5 | RTC_0_WDAY:
620: d &= 7;
621: {
622: int t = rtcWeekGap + d - rtcRegBank0[RTC_0_WDAY] + 7;
623:
624:
625: rtcWeekGap = t - (t * 19 >>> 7) * 7;
626: rtcRegBank0[RTC_0_WDAY] = (byte) d;
627: if (RTC_DEBUG_TRACE) {
628: System.out.printf (" rtcWeekGap=%d\n", rtcWeekGap);
629: rtcDumpReg ();
630: }
631: }
632: return;
633: case 0 << 5 | RTC_0_MDAY0:
634: d &= 15;
635: rtcAddMday (d - rtcRegBank0[RTC_0_MDAY0]);
636: rtcRegBank0[RTC_0_MDAY0] = (byte) d;
637: if (RTC_DEBUG_TRACE) {
638: rtcDumpReg ();
639: }
640: return;
641: case 0 << 5 | RTC_0_MDAY1:
642: d &= 3;
643: rtcAddMday ((d - rtcRegBank0[RTC_0_MDAY1]) * 10);
644: rtcRegBank0[RTC_0_MDAY1] = (byte) d;
645: if (RTC_DEBUG_TRACE) {
646: rtcDumpReg ();
647: }
648: return;
649: case 0 << 5 | RTC_0_MONT0:
650: d &= 15;
651: rtcAddMday (DnT.dntCdayYearMontMday (1980 + rtcRegBank0[RTC_0_YEAR1] * 10 + rtcRegBank0[RTC_0_YEAR0],
652: rtcRegBank0[RTC_0_MONT1] * 10 + d,
653: rtcRegBank0[RTC_0_MDAY1] * 10 + rtcRegBank0[RTC_0_MDAY0]) - rtcCday);
654: rtcRegBank0[RTC_0_MONT0] = (byte) d;
655: if (RTC_DEBUG_TRACE) {
656: rtcDumpReg ();
657: }
658: return;
659: case 0 << 5 | RTC_0_MONT1:
660: d &= 1;
661: rtcAddMday (DnT.dntCdayYearMontMday (1980 + rtcRegBank0[RTC_0_YEAR1] * 10 + rtcRegBank0[RTC_0_YEAR0],
662: d * 10 + rtcRegBank0[RTC_0_MONT0],
663: rtcRegBank0[RTC_0_MDAY1] * 10 + rtcRegBank0[RTC_0_MDAY0]) - rtcCday);
664: rtcRegBank0[RTC_0_MONT1] = (byte) d;
665: if (RTC_DEBUG_TRACE) {
666: rtcDumpReg ();
667: }
668: return;
669: case 0 << 5 | RTC_0_YEAR0:
670: d &= 15;
671: rtcAddMday (DnT.dntCdayYearMontMday (1980 + rtcRegBank0[RTC_0_YEAR1] * 10 + d,
672: rtcRegBank0[RTC_0_MONT1] * 10 + rtcRegBank0[RTC_0_MONT0],
673: rtcRegBank0[RTC_0_MDAY1] * 10 + rtcRegBank0[RTC_0_MDAY0]) - rtcCday);
674: rtcRegBank0[RTC_0_YEAR0] = (byte) d;
675: rtcRegBank1[RTC_1_LEAP] = (byte) (rtcRegBank0[RTC_0_YEAR1] * 10 + d & 3);
676: if (RTC_DEBUG_TRACE) {
677: rtcDumpReg ();
678: }
679: return;
680: case 0 << 5 | RTC_0_YEAR1:
681: d &= 15;
682: rtcAddMday (DnT.dntCdayYearMontMday (1980 + d * 10 + rtcRegBank0[RTC_0_YEAR0],
683: rtcRegBank0[RTC_0_MONT1] * 10 + rtcRegBank0[RTC_0_MONT0],
684: rtcRegBank0[RTC_0_MDAY1] * 10 + rtcRegBank0[RTC_0_MDAY0]) - rtcCday);
685: rtcRegBank0[RTC_0_YEAR1] = (byte) d;
686: rtcRegBank1[RTC_1_LEAP] = (byte) (d * 10 + rtcRegBank0[RTC_0_YEAR0] & 3);
687: if (RTC_DEBUG_TRACE) {
688: rtcDumpReg ();
689: }
690: return;
691:
692: case 1 << 5 | RTC_1_CLKOUT:
693:
694: return;
695: case 1 << 5 | RTC_1_ADJUST:
696:
697: return;
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712: case 1 << 5 | RTC_1_RULE:
713: d &= 1;
714: if (rtcRule != d) {
715:
716: rtcAddSeco ((rtcRegBank0[RTC_0_HOUR1] >> 1) *
717: ((d == 0 ? 43200 : 72000) - (rtcRule == 0 ? 43200 : 72000)));
718: rtcRegBank1[RTC_1_RULE] = (byte) d;
719: rtcRule = d;
720: if (RTC_DEBUG_TRACE) {
721: System.out.printf (" rtcRule=%d\n", rtcRule);
722: rtcDumpReg ();
723: }
724: }
725: return;
726: case 1 << 5 | RTC_1_LEAP:
727:
728: return;
729:
730: case 0 << 5 | RTC_MODE:
731: case 1 << 5 | RTC_MODE:
732: d &= 8 + 4 + 1;
733: rtcBank = d & 1;
734: if (RTC_DEBUG_TRACE) {
735: System.out.printf (" rtcBank=%d\n", rtcBank);
736: }
737: rtcRegCurrent = rtcBank == 0 ? rtcRegBank0 : rtcRegBank1;
738: if (rtcMove < (d & 8)) {
739: if (rtcTest == 0) {
740: rtcCmilGap = rtcCmil - System.currentTimeMillis ();
741: rtcCmilGap = rtcCmilGap < 0L ? -(((-rtcCmilGap + 500L) / 1000L) * 1000L) : ((rtcCmilGap + 500L) / 1000L) * 1000L;
742: if (RTC_DEBUG_GAP) {
743: System.out.printf ("rtcWriteByte rtcCmilGap=%d\n", rtcCmilGap);
744: }
745: if (RTC_DEBUG_TRACE) {
746: System.out.printf (" rtcCmilGap=%d\n", rtcCmilGap);
747: }
748: } else {
749: rtcTestStartCmil = rtcCmil;
750: rtcTestStartTime = XEiJ.mpuClockTime;
751: if (RTC_DEBUG_TRACE) {
752: System.out.printf (" rtcTestStartCmil=%d (%s)\n", rtcTestStartCmil, DnT.dntSdttmCmil (rtcTestStartCmil));
753: System.out.printf (" rtcTestStartTime=%d\n", rtcTestStartTime);
754: }
755: }
756: }
757: rtcAlarm = d & 4;
758: rtcMove = d & 8;
759: if (RTC_DEBUG_TRACE) {
760: System.out.printf (" rtcMove=%d\n", rtcMove);
761: }
762: rtcRegBank0[RTC_MODE] = rtcRegBank1[RTC_MODE] = (byte) d;
763: return;
764: case 0 << 5 | RTC_TEST:
765: case 1 << 5 | RTC_TEST:
766: d &= 15;
767: if (rtcTest != d) {
768: if (d == 0) {
769: XEiJ.busSuper (MemoryMappedDevice.MMD_RTC_FIRST, 0x00e8a000, 0x00e8c000);
770: if (rtcMove != 0) {
771: rtcCmilGap = rtcCmil - System.currentTimeMillis ();
772: rtcCmilGap = rtcCmilGap < 0L ? -(((-rtcCmilGap + 500L) / 1000L) * 1000L) : ((rtcCmilGap + 500L) / 1000L) * 1000L;
773: if (RTC_DEBUG_GAP) {
774: System.out.printf ("rtcWriteByte rtcCmilGap=%d\n", rtcCmilGap);
775: }
776: if (RTC_DEBUG_TRACE) {
777: System.out.printf (" rtcCmilGap=%d\n", rtcCmilGap);
778: }
779: }
780: } else if (rtcTest == 0) {
781: XEiJ.busSuper (MemoryMappedDevice.MMD_RTC_TEST, 0x00e8a000, 0x00e8c000);
782: if (rtcMove != 0) {
783: rtcTestStartCmil = rtcCmil;
784: rtcTestStartTime = XEiJ.mpuClockTime;
785: if (RTC_DEBUG_TRACE) {
786: System.out.printf (" rtcTestStartCmil=%d (%s)\n", rtcTestStartCmil, DnT.dntSdttmCmil (rtcTestStartCmil));
787: System.out.printf (" rtcTestStartTime=%d\n", rtcTestStartTime);
788: }
789: }
790: } else {
791: if (rtcMove != 0) {
792: rtcTestStartCmil = rtcCmil;
793: rtcTestStartTime = XEiJ.mpuClockTime;
794: if (RTC_DEBUG_TRACE) {
795: System.out.printf (" rtcTestStartCmil=%d (%s)\n", rtcTestStartCmil, DnT.dntSdttmCmil (rtcTestStartCmil));
796: System.out.printf (" rtcTestStartTime=%d\n", rtcTestStartTime);
797: }
798: }
799: }
800: rtcTest = d;
801: rtcFirst = rtcTest == 0 ? MemoryMappedDevice.MMD_RTC_FIRST : MemoryMappedDevice.MMD_RTC_TEST;
802: if (RTC_DEBUG_TRACE) {
803: System.out.printf (" rtcTest=%d\n", rtcTest);
804: }
805: rtcRegBank0[RTC_TEST] = rtcRegBank1[RTC_TEST] = (byte) d;
806: }
807: return;
808:
809:
810:
811: }
812: }
813:
814: }
815:
816:
817: