Hardware/LPC/IT87XX.cs
changeset 78 52c16b1d5536
parent 63 1a7c13ac7348
child 84 05bf128434c6
     1.1 --- a/Hardware/LPC/IT87XX.cs	Mon Mar 08 20:05:51 2010 +0000
     1.2 +++ b/Hardware/LPC/IT87XX.cs	Tue Mar 09 20:35:19 2010 +0000
     1.3 @@ -46,6 +46,9 @@
     1.4      private bool available = false;
     1.5      private ushort address;
     1.6  
     1.7 +    private readonly ushort addressReg;
     1.8 +    private readonly ushort dataReg;
     1.9 +
    1.10      private Sensor[] temperatures;
    1.11      private Sensor[] fans;
    1.12      private Sensor[] voltages;
    1.13 @@ -67,25 +70,31 @@
    1.14        new byte[] { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
    1.15      private byte[] FAN_TACHOMETER_EXT_REG =
    1.16        new byte[] { 0x18, 0x19, 0x1a, 0x81, 0x83 };
    1.17 -    private const byte VOLTAGE_BASE_REG = 0x20;  
    1.18 -    
    1.19 -    private byte ReadByte(byte register) {
    1.20 -      WinRing0.WriteIoPortByte(
    1.21 -        (ushort)(address + ADDRESS_REGISTER_OFFSET), register);
    1.22 -      return WinRing0.ReadIoPortByte((ushort)(address + DATA_REGISTER_OFFSET));
    1.23 -    } 
    1.24 +    private const byte VOLTAGE_BASE_REG = 0x20;
    1.25 +
    1.26 +    private byte ReadByte(byte register, out bool valid) {
    1.27 +      WinRing0.WriteIoPortByte(addressReg, register);
    1.28 +      byte value = WinRing0.ReadIoPortByte(dataReg);
    1.29 +      valid = register == WinRing0.ReadIoPortByte(addressReg);
    1.30 +      return value;
    1.31 +    }
    1.32  
    1.33      public IT87XX(Chip chip, ushort address) : base (chip) {
    1.34        
    1.35        this.address = address;
    1.36 +      this.addressReg = (ushort)(address + ADDRESS_REGISTER_OFFSET);
    1.37 +      this.dataReg = (ushort)(address + DATA_REGISTER_OFFSET);
    1.38        
    1.39        // Check vendor id
    1.40 -      byte vendorId = ReadByte(VENDOR_ID_REGISTER);      
    1.41 -      if (vendorId != ITE_VENDOR_ID)
    1.42 +      bool valid;
    1.43 +      byte vendorId = ReadByte(VENDOR_ID_REGISTER, out valid);       
    1.44 +      if (!valid || vendorId != ITE_VENDOR_ID)
    1.45          return;
    1.46  
    1.47        // Bit 0x10 of the configuration register should always be 1
    1.48 -      if ((ReadByte(CONFIGURATION_REGISTER) & 0x10) == 0)
    1.49 +      if ((ReadByte(CONFIGURATION_REGISTER, out valid) & 0x10) == 0)
    1.50 +        return;
    1.51 +      if (!valid)
    1.52          return;
    1.53  
    1.54        temperatures = new Sensor[3];
    1.55 @@ -131,7 +140,12 @@
    1.56          r.Append(" "); r.Append((i << 4).ToString("X2")); r.Append("  ");
    1.57          for (int j = 0; j <= 0xF; j++) {
    1.58            r.Append(" ");
    1.59 -          r.Append(ReadByte((byte)((i << 4) | j)).ToString("X2"));
    1.60 +          bool valid;
    1.61 +          byte value = ReadByte((byte)((i << 4) | j), out valid);
    1.62 +          if (valid)
    1.63 +            r.Append(value.ToString("X2"));
    1.64 +          else
    1.65 +            r.Append("??");
    1.66          }
    1.67          r.AppendLine();
    1.68        }
    1.69 @@ -143,7 +157,12 @@
    1.70      public void Update() {
    1.71  
    1.72        foreach (Sensor sensor in voltages) {
    1.73 -        int value = ReadByte((byte)(VOLTAGE_BASE_REG + sensor.Index));
    1.74 +        bool valid;
    1.75 +        int value = ReadByte(
    1.76 +          (byte)(VOLTAGE_BASE_REG + sensor.Index), out valid);
    1.77 +        if (!valid)
    1.78 +          continue;
    1.79 +
    1.80          sensor.Value = voltageGains[sensor.Index] * 0.001f * (value << 4);
    1.81          if (sensor.Value > 0)
    1.82            ActivateSensor(sensor);
    1.83 @@ -152,8 +171,12 @@
    1.84        }
    1.85  
    1.86        foreach (Sensor sensor in temperatures) {
    1.87 -        sbyte value = 
    1.88 -          (sbyte)ReadByte((byte)(TEMPERATURE_BASE_REG + sensor.Index));
    1.89 +        bool valid;
    1.90 +        sbyte value = (sbyte)ReadByte(
    1.91 +          (byte)(TEMPERATURE_BASE_REG + sensor.Index), out valid);
    1.92 +        if (!valid)
    1.93 +          continue;
    1.94 +
    1.95          sensor.Value = value + sensor.Parameters[0].Value;
    1.96          if (value < sbyte.MaxValue && value > 0)
    1.97            ActivateSensor(sensor);
    1.98 @@ -162,8 +185,13 @@
    1.99        }
   1.100  
   1.101        foreach (Sensor sensor in fans) {
   1.102 -        int value = ReadByte(FAN_TACHOMETER_REG[sensor.Index]);
   1.103 -        value |= ReadByte(FAN_TACHOMETER_EXT_REG[sensor.Index]) << 8;
   1.104 +        bool valid;
   1.105 +        int value = ReadByte(FAN_TACHOMETER_REG[sensor.Index], out valid);
   1.106 +        if (!valid) 
   1.107 +          continue;
   1.108 +        value |= ReadByte(FAN_TACHOMETER_EXT_REG[sensor.Index], out valid) << 8;
   1.109 +        if (!valid)
   1.110 +          continue;
   1.111  
   1.112          if (value > 0x3f) {
   1.113            sensor.Value = (value < 0xffff) ? 1.35e6f / ((value) * 2) : 0;