ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cmos.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS HAL
00003  * LICENSE:         GPL - See COPYING in the top level directory
00004  * FILE:            hal/halx86/generic/cmos.c
00005  * PURPOSE:         CMOS Access Routines (Real Time Clock and LastKnownGood)
00006  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
00007  *                  Eric Kohl
00008  */
00009 
00010 /* INCLUDES ******************************************************************/
00011 
00012 #include <hal.h>
00013 #define NDEBUG
00014 #include <debug.h>
00015 
00016 /* GLOBALS *******************************************************************/
00017 
00018 KSPIN_LOCK HalpSystemHardwareLock;
00019 
00020 /* PRIVATE FUNCTIONS *********************************************************/
00021 
00022 UCHAR
00023 FORCEINLINE
00024 HalpReadCmos(IN UCHAR Reg)
00025 {
00026     /* Select the register */
00027     WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, Reg);
00028 
00029     /* Query the value */
00030     return READ_PORT_UCHAR(CMOS_DATA_PORT);
00031 }
00032 
00033 VOID
00034 FORCEINLINE
00035 HalpWriteCmos(IN UCHAR Reg,
00036               IN UCHAR Value)
00037 {
00038     /* Select the register */
00039     WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, Reg);
00040 
00041     /* Write the value */
00042     WRITE_PORT_UCHAR(CMOS_DATA_PORT, Value);
00043 }
00044 
00045 ULONG
00046 NTAPI
00047 HalpGetCmosData(IN ULONG BusNumber,
00048                 IN ULONG SlotNumber,
00049                 IN PVOID Buffer,
00050                 IN ULONG Length)
00051 {
00052     PUCHAR Ptr = (PUCHAR)Buffer;
00053     ULONG Address = SlotNumber;
00054     ULONG Len = Length;
00055 
00056     /* FIXME: Acquire CMOS Lock */
00057 
00058     /* Do nothing if we don't have a length */
00059     if (!Length) return 0;
00060 
00061     /* Check if this is simple CMOS */
00062     if (!BusNumber)
00063     {
00064         /* Loop the buffer up to 0xFF */
00065         while ((Len > 0) && (Address < 0x100))
00066         {
00067             /* Read the data */
00068             *Ptr = HalpReadCmos((UCHAR)Address);
00069 
00070             /* Update position and length */
00071             Ptr++;
00072             Address++;
00073             Len--;
00074         }
00075     }
00076     else if (BusNumber == 1)
00077     {
00078         /* Loop the buffer up to 0xFFFF */
00079         while ((Len > 0) && (Address < 0x10000))
00080         {
00081             /* Write the data */
00082             *Ptr = HalpReadCmos((UCHAR)Address);
00083 
00084             /* Update position and length */
00085             Ptr++;
00086             Address++;
00087             Len--;
00088         }
00089     }
00090 
00091     /* FIXME: Release the CMOS Lock */
00092 
00093     /* Return length read */
00094     return Length - Len;
00095 }
00096 
00097 ULONG
00098 NTAPI
00099 HalpSetCmosData(IN ULONG BusNumber,
00100                 IN ULONG SlotNumber,
00101                 IN PVOID Buffer,
00102                 IN ULONG Length)
00103 {
00104     PUCHAR Ptr = (PUCHAR)Buffer;
00105     ULONG Address = SlotNumber;
00106     ULONG Len = Length;
00107 
00108     /* FIXME: Acquire CMOS Lock */
00109 
00110     /* Do nothing if we don't have a length */
00111     if (!Length) return 0;
00112 
00113     /* Check if this is simple CMOS */
00114     if (!BusNumber)
00115     {
00116         /* Loop the buffer up to 0xFF */
00117         while ((Len > 0) && (Address < 0x100))
00118         {
00119             /* Write the data */
00120             HalpWriteCmos((UCHAR)Address, *Ptr);
00121 
00122             /* Update position and length */
00123             Ptr++;
00124             Address++;
00125             Len--;
00126         }
00127     }
00128     else if (BusNumber == 1)
00129     {
00130         /* Loop the buffer up to 0xFFFF */
00131         while ((Len > 0) && (Address < 0x10000))
00132         {
00133             /* Write the data */
00134             HalpWriteCmos((UCHAR)Address, *Ptr);
00135 
00136             /* Update position and length */
00137             Ptr++;
00138             Address++;
00139             Len--;
00140         }
00141     }
00142 
00143     /* FIXME: Release the CMOS Lock */
00144 
00145     /* Return length read */
00146     return Length - Len;
00147 }
00148 
00149 /* PUBLIC FUNCTIONS **********************************************************/
00150 
00151 /*
00152  * @implemented
00153  */
00154 ARC_STATUS
00155 NTAPI
00156 HalGetEnvironmentVariable(IN PCH Name,
00157                           IN USHORT ValueLength,
00158                           IN PCH Value)
00159 {
00160     UCHAR Val;
00161 
00162     /* Only variable supported on x86 */
00163     if (_stricmp(Name, "LastKnownGood")) return ENOENT;
00164 
00165     /* FIXME: Acquire CMOS Lock */
00166 
00167     /* Query the current value */
00168     Val = HalpReadCmos(RTC_REGISTER_B) & 0x01;
00169 
00170     /* FIXME: Release CMOS lock */
00171 
00172     /* Check the flag */
00173     if (Val)
00174     {
00175         /* Return false */
00176         strncpy(Value, "FALSE", ValueLength);
00177     }
00178     else
00179     {
00180         /* Return true */
00181         strncpy(Value, "TRUE", ValueLength);
00182     }
00183 
00184     /* Return success */
00185     return ESUCCESS;
00186 }
00187 
00188 /*
00189  * @implemented
00190  */
00191 ARC_STATUS
00192 NTAPI
00193 HalSetEnvironmentVariable(IN PCH Name,
00194                           IN PCH Value)
00195 {
00196     UCHAR Val;
00197 
00198     /* Only variable supported on x86 */
00199     if (_stricmp(Name, "LastKnownGood")) return ENOMEM;
00200 
00201     /* Check if this is true or false */
00202     if (!_stricmp(Value, "TRUE"))
00203     {
00204         /* It's true, acquire CMOS lock (FIXME) */
00205 
00206         /* Read the current value and add the flag */
00207         Val = HalpReadCmos(RTC_REGISTER_B) | 1;
00208     }
00209     else if (!_stricmp(Value, "FALSE"))
00210     {
00211         /* It's false, acquire CMOS lock (FIXME) */
00212 
00213         /* Read the current value and mask out  the flag */
00214         Val = HalpReadCmos(RTC_REGISTER_B) & ~1;
00215     }
00216     else
00217     {
00218         /* Fail */
00219         return ENOMEM;
00220     }
00221 
00222     /* Write new value */
00223     HalpWriteCmos(RTC_REGISTER_B, Val);
00224 
00225     /* Release the lock and return success */
00226     return ESUCCESS;
00227 }
00228 
00229 /*
00230  * @implemented
00231  */
00232 BOOLEAN
00233 NTAPI
00234 HalQueryRealTimeClock(OUT PTIME_FIELDS Time)
00235 {
00236     /* FIXME: Acquire CMOS Lock */
00237 
00238     /* Loop while update is in progress */
00239     while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP);
00240 
00241     /* Set the time data */
00242     Time->Second = BCD_INT(HalpReadCmos(0));
00243     Time->Minute = BCD_INT(HalpReadCmos(2));
00244     Time->Hour = BCD_INT(HalpReadCmos(4));
00245     Time->Weekday = BCD_INT(HalpReadCmos(6));
00246     Time->Day = BCD_INT(HalpReadCmos(7));
00247     Time->Month = BCD_INT(HalpReadCmos(8));
00248     Time->Year = BCD_INT(HalpReadCmos(9));
00249     Time->Milliseconds = 0;
00250 
00251     /* FIXME: Check century byte */
00252 
00253     /* Compensate for the century field */
00254     Time->Year += (Time->Year > 80) ? 1900: 2000;
00255 
00256     /* FIXME: Release CMOS Lock */
00257 
00258     /* Always return TRUE */
00259     return TRUE;
00260 }
00261 
00262 /*
00263  * @implemented
00264  */
00265 BOOLEAN
00266 NTAPI
00267 HalSetRealTimeClock(IN PTIME_FIELDS Time)
00268 {
00269     /* FIXME: Acquire CMOS Lock */
00270 
00271     /* Loop while update is in progress */
00272     while ((HalpReadCmos(RTC_REGISTER_A)) & RTC_REG_A_UIP);
00273 
00274     /* Write time fields to CMOS RTC */
00275     HalpWriteCmos(0, INT_BCD(Time->Second));
00276     HalpWriteCmos(2, INT_BCD(Time->Minute));
00277     HalpWriteCmos(4, INT_BCD(Time->Hour));
00278     HalpWriteCmos(6, INT_BCD(Time->Weekday));
00279     HalpWriteCmos(7, INT_BCD(Time->Day));
00280     HalpWriteCmos(8, INT_BCD(Time->Month));
00281     HalpWriteCmos(9, INT_BCD(Time->Year % 100));
00282 
00283     /* FIXME: Set the century byte */
00284 
00285     /* FIXME: Release the CMOS Lock */
00286 
00287     /* Always return TRUE */
00288     return TRUE;
00289 }
00290 
00291 /* EOF */

Generated on Sun May 27 2012 04:28:41 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.