/// <summary> /// Sets the time. Only used on Cerb based boards. /// </summary> /// <param name="hours">Hours</param> /// <param name="minutes">Minutes</param> /// <param name="seconds">Seconds</param> /// <returns></returns> public static int RTC_SetTime(byte hours, byte minutes, byte seconds) { SafeToProceed(DeviceID.FEZ_CERB); UInt32 tmpreg; RTC_H12 = 0; RTC_Hours = hours; RTC_Minutes = minutes; RTC_Seconds = seconds; tmpreg = (UInt32)(((UInt32)RTC_ByteToBcd2(RTC_Hours) << 16) | ((UInt32)RTC_ByteToBcd2(RTC_Minutes) << 8) | ((UInt32)RTC_ByteToBcd2(RTC_Seconds)) | (((UInt32)RTC_H12) << 22)); RTC_WPR.Write(0xCA); RTC_WPR.Write(0x53); int status = ERROR; if (RTC_EnterInitMode() == ERROR) { status = ERROR; } else { /* Set the RTC_TR register */ Register RTC_TR = new Register(RTC_BASE + 0x00); RTC_TR.Write(tmpreg & RTC_TR_RESERVED_MASK); /* Exit Initialization mode */ RTC_ExitInitMode(); if (RTC_WaitForSynchro() == ERROR) { status = ERROR; } else { status = SUCCESS; } } /* Enable the write protection for RTC registers */ RTC_WPR.Write(0xFF); return status; }
/// <summary> /// Sets the time. Only used on Cerb based boards. /// </summary> /// <param name="year">Year</param> /// <param name="month">Month</param> /// <param name="dayofweek">Day of Week</param> /// <param name="date">Date</param> /// <returns></returns> public static int RTC_SetDate(int year, byte month, byte dayofweek, byte date) { SafeToProceed(DeviceID.FEZ_CERB); int status = ERROR; UInt32 tmp = 0x10; UInt32 tmpreg = 0x00; RTC_Year = (byte)(year - 1980); RTC_Month = month; RTC_WeekDay = dayofweek; RTC_Date = date; if ((RTC_Month & 0x10) == 0x10) { RTC_Month = (byte)((RTC_Month & (UInt32)~(tmp)) + 0x0A); } tmpreg = (((UInt32)RTC_ByteToBcd2(RTC_Year) << 16) | ((UInt32)RTC_ByteToBcd2(RTC_Month) << 8) | ((UInt32)RTC_ByteToBcd2(RTC_Date)) | ((UInt32)RTC_WeekDay << 13)); RTC_WPR.Write(0xCA); RTC_WPR.Write(0x53); if (RTC_EnterInitMode() == ERROR) { status = ERROR; } else { /* Set the RTC_DR register */ Register RTC_DR = new Register(RTC_BASE + 0x04); RTC_DR.Write(tmpreg & RTC_DR_RESERVED_MASK); /* Exit Initialization mode */ RTC_ExitInitMode(); if (RTC_WaitForSynchro() == ERROR) { status = ERROR; } else { status = SUCCESS; } } /* Enable the write protection for RTC registers */ RTC_WPR.Write(0xFF); return status; }