經過昨天的介紹,目前應該都對Hardware Monitor有初步的瞭解,今天要來介紹與讀取CPU風扇轉速相關的實作。
主要函式宣告如下:
SioSdk.h
SIO_API unsigned int GetCpuFanSpeed();
SioSdk.c
unsigned int GetHwmBase();
unsigned char ReadHwm(unsigned int Base, unsigned int Bank, unsigned int Register);
bool WriteHwm(unsigned int Base, unsigned int Bank, unsigned int Register, unsigned int Data);
GetCpuFanSpeed
為讀取CPU風扇轉速的主體函式。GetHwmBase
用來讀取Hardware Monitor的I/O位址。ReadHwm
和WriteHwm
就類似於Day13的ReadSio
和WriteSio
,但這裡只針對Hardware Monitor的暫存器作讀寫。主要函式實作如下:
SioSdk.c
GetHwmBase
unsigned int GetHwmBase()
{
unsigned int BaseLow, BaseHigh;
printf("GetHwmBase\n");
WriteSio(LDN_SEL, LDN_HWM);
BaseLow = (unsigned int)ReadSio(BASE1_LO) & 0xFF;
BaseHigh = (unsigned int)ReadSio(BASE1_HI) & 0xFF;
return (BaseHigh << 8) + BaseLow;
}
unsigned int
。ReadHwm
unsigned char ReadHwm(unsigned int Base, unsigned int Bank, unsigned int Register)
{
unsigned char Temp;
unsigned char Output;
printf("ReadHwm\n");
WriteIoPort(Base + 0x05, HWM_BANK_NO);
Temp = ReadIoPort(Base + 0x06);
Temp &= 0xF0;
WriteIoPort(Base + 0x06, Temp | Bank);
WriteIoPort(Base + 0x05, Register);
Output = ReadIoPort(Base + 0x06);
return Output;
}
Base
為Hardware Monitor I/O位址,Base + 0x05
為Index埠,Base + 0x06
為Data埠。Register
為想要讀取的暫存器位址。ReadHwm
bool WriteHwm(unsigned int Base, unsigned int Bank, unsigned int Register, unsigned int Data)
{
unsigned char Temp;
bool Result = FALSE;
printf("WriteHwm\n");
WriteIoPort(Base + 0x05, HWM_BANK_NO);
Temp = ReadIoPort(Base + 0x06);
Temp &= 0xF0;
WriteIoPort(Base + 0x06, Temp | Bank);
Result = WriteIoPort(Base + 0x05, Register);
Result = WriteIoPort(Base + 0x06, Data);
return Result;
}
Register
為想要寫入的暫存器位址。Data
為想要寫入的暫存器的值。GetCpuFanSpeed
unsigned int GetCpuFanSpeed()
{
unsigned int Base;
unsigned int RpmLow, RpmHigh;
printf("GetCpuFanSpeed\n");
OpenSioConfig();
Base = GetHwmBase();
CloseSioConfig();
RpmHigh = ReadHwm(Base, 0x04, 0xC2);
RpmLow = ReadHwm(Base, 0x04, 0xC3);
return (RpmHigh << 8) + RpmLow;
}
以上就是讀取CPU風扇轉速相關的實作,完整的專案可以到參考內容中的SioSdk閱讀。