/* * @implemented */ BOOLEAN NTAPI HalQueryRealTimeClock(OUT PTIME_FIELDS Time) { /* FIXME: Acquire CMOS Lock */ /* Loop while update is in progress */ while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP); /* Set the time data */ Time->Second = BCD_INT(HalpReadCmos(0)); Time->Minute = BCD_INT(HalpReadCmos(2)); Time->Hour = BCD_INT(HalpReadCmos(4)); Time->Weekday = BCD_INT(HalpReadCmos(6)); Time->Day = BCD_INT(HalpReadCmos(7)); Time->Month = BCD_INT(HalpReadCmos(8)); Time->Year = BCD_INT(HalpReadCmos(9)); Time->Milliseconds = 0; /* FIXME: Check century byte */ /* Compensate for the century field */ Time->Year += (Time->Year > 80) ? 1900: 2000; /* FIXME: Release CMOS Lock */ /* Always return TRUE */ return TRUE; }
ULONG LlbHwRtcRead(VOID) { /* Issue the GET_TIME request on the RTC control register */ LlbHwOmap3TwlWrite1(0x4B, 0x29, 0x41); /* Read the BCD registers and convert them */ LlbTime.Second = BCD_INT(LlbHwOmap3TwlRead1(0x4B, 0x1C)); LlbTime.Minute = BCD_INT(LlbHwOmap3TwlRead1(0x4B, 0x1D)); LlbTime.Hour = BCD_INT(LlbHwOmap3TwlRead1(0x4B, 0x1E)); LlbTime.Day = BCD_INT(LlbHwOmap3TwlRead1(0x4B, 0x1F)); LlbTime.Month = BCD_INT(LlbHwOmap3TwlRead1(0x4B, 0x20)); LlbTime.Year = BCD_INT(LlbHwOmap3TwlRead1(0x4B, 0x21)); LlbTime.Year += (LlbTime.Year > 80) ? 1900 : 2000; return 0; }
//================== // Initialize RTC //================== void Init_RTC(uint32_t do_adj, uint8_t year, uint8_t month, uint8_t day, uint8_t week, uint8_t hour, uint8_t minute, uint8_t second) { // Initialize I2C if (I2CInit((uint32_t) I2CMASTER) == FALSE ) { while (1); // Error Trap } // Initialize RTC if (do_adj) { Wait_N_Ticks(100); // wait 1000ms // RTC_Write_Reg(RTC_CONTROL1, 0x20); // STOP RTC_Write_Reg(RTC_CONTROL2, 0x00); // RTC_Write_Reg(RTC_HOURS, BCD_INT(hour)); RTC_Write_Reg(RTC_MINUTES, BCD_INT(minute)); RTC_Write_Reg(RTC_SECONDS, BCD_INT(second)); // RTC_Write_Reg(RTC_YEARS, BCD_INT(year)); RTC_Write_Reg(RTC_C_MONTHS, BCD_INT(month)); RTC_Write_Reg(RTC_DAYS, BCD_INT(day)); RTC_Write_Reg(RTC_WEEKDAYS, BCD_INT(week)); // RTC_Write_Reg(RTC_MINUTE_ALARM, 0x00); RTC_Write_Reg(RTC_HOUR_ALARM, 0x00); RTC_Write_Reg(RTC_DAY_ALARM, 0x00); RTC_Write_Reg(RTC_WEEKDAY_ALARM, 0x00); // RTC_Write_Reg(RTC_CLKOUT_FREQ, 0x00); RTC_Write_Reg(RTC_TIMER_CONTROL,0x00); RTC_Write_Reg(RTC_TIMER, 0x00); // RTC_Write_Reg(RTC_CONTROL1, 0x00); // START } }