Esempio n. 1
0
            /// <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;
            }
Esempio n. 2
0
            /// <summary>
            ///  Gets the date. Only used on Cerb based boards.
            /// </summary>
            public static void RTC_GetDate()
            {
                SafeToProceed(DeviceID.FEZ_CERB);

                Register RTC_DR = new Register(RTC_BASE + 0x04);
                UInt32 tmpreg = (UInt32)(RTC_DR.Read() & RTC_DR_RESERVED_MASK);
                /* Fill the structure fields with the read parameters */
                RTC_Year = (byte)((tmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
                RTC_Month = (byte)((tmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
                RTC_Date = (byte)(tmpreg & (RTC_DR_DT | RTC_DR_DU));
                RTC_WeekDay = (byte)((tmpreg & (RTC_DR_WDU)) >> 13);
                /* Convert the structure parameters to Binary format */
                RTC_Year = (byte)RTC_Bcd2ToByte(RTC_Year);
                RTC_Month = (byte)RTC_Bcd2ToByte(RTC_Month);
                RTC_Date = (byte)RTC_Bcd2ToByte(RTC_Date);
                //RTC_WeekDay = (byte)(RTC_DateStruct->RTC_WeekDay);

            }
Esempio n. 3
0
            /// <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;
            }
Esempio n. 4
0
            /// <summary>
            /// Gets the time. Only used on Cerb based boards.
            /// </summary>
            public static void RTC_GetTime()
            {
                SafeToProceed(DeviceID.FEZ_CERB);

                Register RTC_TR = new Register(RTC_BASE + 0x00);
                UInt32 tmpreg;
                tmpreg = (UInt32)(RTC_TR.Read() & RTC_TR_RESERVED_MASK);
                RTC_Hours = (byte)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
                RTC_Minutes = (byte)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> 8);
                RTC_Seconds = (byte)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
                RTC_H12 = (byte)((tmpreg & (RTC_TR_PM)) >> 22);
                /* Convert the structure parameters to Binary format */
                RTC_Hours = (byte)RTC_Bcd2ToByte(RTC_Hours);
                RTC_Minutes = (byte)RTC_Bcd2ToByte(RTC_Minutes);
                RTC_Seconds = (byte)RTC_Bcd2ToByte(RTC_Seconds);


            }