📄 portio.cpp
字号:
Else
{
::Sleep(10)
Subtract(Local0, 10, Local0)
}*/
if(Timeout < 10)
{
status = 0x18;
break;
}
else
{
::Sleep(10);
Timeout = Timeout-10;
}
}
}
//Return(Local2)
return status;
} // Method(SWTC)
//-------------------------------------------------------------------------
// Read a byte to the embedded controller (EC) SMBUS via port io
//-------------------------------------------------------------------------
int
FANCONTROL::ECSMBusRead(char SMBusBaseOffsetInERAM, char Protocol, char SlaveAddress, char Command, char* ReturnLen, char* ReturnData)
//
// _SBR (SMBus Read):
// ------------------
//
// Parameters:
// Arg0 = Protocol (Integer)
// Arg1 = Slave Address (Integer)
// Arg2 = Command (Integer)
//
// Return Value (Package):
// (0) = Status (Integer)
// (1) = Data Length (Integer)
// (2) = Data (Integer | Buffer)
//
// Method(_SBR, 3)
{
//
// Local0 is the return package. The status code is defaulted
// to 'unknown failure' (0x07).
//
// Store(Package(3){0x07,0x00,0x00}, Local0)
int status = 0x07;
char buffer,i=0;
//
// Make sure the protocol is valid, if not return the
// 'invalid protocol' status code. Note that this segment
// does not support packet error checking.
//
/* If(LNotEqual(Arg0, 0x03)) // Read Quick
{
If(LNotEqual(Arg0, 0x05)) // Receive Byte
{
If(LNotEqual(Arg0, 0x07)) // Read Byte
{
If(LNotEqual(Arg0, 0x09)) // Read Word
{
If(LNotEqual(Arg0, 0x0B)) // Read Block
{
Store(0x19, Index(Local0, 0))
Return(Local0)
}
}
}
}
}*/
if(Protocol != 0x03 && Protocol != 0x05 && Protocol != 0x07 && Protocol != 0x09
&& Protocol != 0x0B )
return 0x19;
//
// Acquire the SMBus mutex to ensure transactional synchronization.
//
// If(LEqual(Acquire(SBX0, 0xFFFF), 0))
{
//
// Make sure the SMBus is ready for this transaction. If not,
// return a 'bus busy' error code. Note that 'we' should be
// the only consumer...
//
// If(LNotEqual(PRTC, 0))
status = ReadByteFromEC(SMBusBaseOffsetInERAM + EC_SMPR, &buffer) ;
if(status != TRUE) return 0x07;
if( buffer != 0 )
{
// Store(0x1A, Index(Local0, 0)) // ERROR: Bus is busy.
return 0x1A;
}
//Else
else
{
//
// Initiate the transaction by writing the slave address,
// command, and protocol registers. Note that the command
// code is always written, even if the protocol (e.g. 'read
// quick') doesn't require it (it will be ignored). Note also
// that the “Read Block" always return 32-byte buffer regardless
// of the actual block length. This is not a requirement but
// is implementation specific to this sample ASL.
//
//Store(ShiftLeft(Arg1, 1), ADDR)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMAD, SlaveAddress<<1);
//Store(Arg2, CMD)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMCM, Command);
//Store(Arg0, PRTC)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMPR, Protocol);
//
// Wait for completion. Save the status code, data size,
// and data into the return package (if required by the protocol).
//
//Store(SWTC(1000), Index(Local0, 0))
if( ECSMBusWaitComplete(SMBusBaseOffsetInERAM,1000) !=0) return 0x07;
/*If(LEqual(Arg0, 0x05)) // Receive Byte
{
Store(1, Index(Local0, 1))
Store(DAT0, Index(Local0, 2))
}
If(LEqual(Arg0, 0x07)) // Read Byte
{
Store(1, Index(Local0, 1))
Store(DAT0, Index(Local0, 2))
}*/
if( Protocol == 0x05 || Protocol == 0x07 )
{
*ReturnLen = 1;
status = ReadByteFromEC(this->ECSMBusBaseOffsetInERAM + EC_SMD0, ReturnData) ;
if(status != TRUE) return 0x07;
}
/*If(LEqual(Arg0, 0x09)) // Read Word
{
Store(2, Index(Local0, 1))
Store(DAT1, Local1)
ShiftLeft(Local1, 8, Local1)
Add(Local1, DAT0, Local1)
Store(Local1, Index(Local0, 2))
}*/
if( Protocol == 0x09 )
{
*ReturnLen = 2;
status = ReadByteFromEC(this->ECSMBusBaseOffsetInERAM + EC_SMD0, ReturnData) ;
if(status != TRUE) return 0x07;
status = ReadByteFromEC( this->ECSMBusBaseOffsetInERAM +EC_SMD0 +1, ReturnData+1) ;
if(status != TRUE) return 0x07;
}
/*If(LEqual(Arg0, 0x0B)) // Read Block
{
Store(BCNT, Index(Local0, 1))
Store(DATA, Index(Local0, 2))
}*/
if( Protocol == 0x0B )
{
status = ReadByteFromEC(this->ECSMBusBaseOffsetInERAM + EC_BCNT, ReturnLen) ;
if(status != TRUE) return 0x07;
if(*ReturnLen > 32) return 0x07;
for (i=0; i< *ReturnLen; i++ )
{
status = ReadByteFromEC(this->ECSMBusBaseOffsetInERAM + EC_SMD0 +i, ReturnData+i) ;
if(status != TRUE) return 0x07;
}
}
}
// Release(SBX0)
}
//Return(Local0)
return 0;
} // _SBR()
//-------------------------------------------------------------------------
// Write a byte to the embedded controller (EC) SMBUS via port io
//-------------------------------------------------------------------------
int
FANCONTROL::ECSMBusWrite(char SMBusBaseOffsetInERAM, char Protocol, char SlaveAddress, char Command, char WriteLen, char* WriteData)
//
// _SBW (SMBus Write):
// ------------------
//
// Parameters:
// Arg0 = Protocol Value (Integer)
// Arg1 = Slave Address (Integer)
// Arg2 = Command Code (Integer)
// Arg3 = Data Length (Integer)
// Arg4 = Data (Integer | Buffer)
//
// Return Value (Package):
// (0) = Status (Integer)
//
// Method(_SBW, 5)
{
//
// Local0 is the return package. The status code is defaulted
// to 'unknown failure' (0x07).
//
//Store(Package(1){0x07}, Local0)
int status = 0x07, i=0;
char buffer;
//
// Make sure the protocol is valid, if not return the
// 'invalid protocol' status code. Note that this segment
// does not support packet error checking or the 'process call'
// protocol.
//
/*If(LNotEqual(Arg0, 0x02)) // Write Quick
{
If(LNotEqual(Arg0, 0x04)) // Send Byte
{
If(LNotEqual(Arg0, 0x06)) // Write Byte
{
If(LNotEqual(Arg0, 0x08)) // Write Word
{
If(LNotEqual(Arg0, 0x0A)) // Write Block
{
Store(0x19, Index(Local0, 0))
Return(Local0)
}
}
}
}
}*/
if(Protocol != 0x02 && Protocol != 0x04 && Protocol != 0x06 && Protocol != 0x08
&& Protocol != 0x0A )
return 0x19;
//
// Acquire the SMBus mutex to ensure transactional synchronization.
//
// If(LEqual(Acquire(SBX0, 0xFFFF), 0))
{
//
// Make sure the SMBus is ready for this transaction. If not,
// return a 'bus busy' error code. Note that 'we' should be
// the only consumer...
//
/* If(LNotEqual(PRTC, 0))
{
Store(0x1A, Local0)
}*/
status = ReadByteFromEC(SMBusBaseOffsetInERAM + EC_SMPR, &buffer) ;
if(status != TRUE) return 0x07;
if( buffer != 0 )
{
// Store(0x1A, Index(Local0, 0)) // ERROR: Bus is busy.
return 0x1A;
}
//Else
else
{
//
// Initiate the transaction by writing the slave address,
// command, and protocol registers. Note that the command
// code and data length are always written, even if the
// protocol (e.g. 'write quick') doesn't require it (it
// will be ignored).
//
//Store(ShiftLeft(Arg1, 1), ADDR)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMAD, SlaveAddress<<1);
//Store(Arg2, CMD)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMCM, Command);
//Store(Arg3, BCNT)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_BCNT, WriteLen);
/*If(LEqual(Arg0, 0x06)) // Write Byte
{
Store(Arg4, DAT0)
}*/
if( Protocol == 0x06 )
{
status = WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMD0, *WriteData) ;
if(status != TRUE) return 0x07;
}
/*If(LEqual(Arg0, 0x08)) // Write Word
{
And(Arg4, 0x00FF, DAT0)
ShiftRight(Arg4, 8, DAT1)
}*/
if( Protocol == 0x08 )
{
status = WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMD0, *WriteData) ;
if(status != TRUE) return 0x07;
status = WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMD0+1, *(WriteData+1)) ;
if(status != TRUE) return 0x07;
}
/*If(LEqual(Arg0, 0x0A)) // Write Block
{
Store(Arg4, DATA)
}*/
if( Protocol == 0x0A )
{
for (i=0; i< WriteLen; i++ )
{
status = WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMD0 +i, *(WriteData+i)) ;
if(status != TRUE) return 0x07;
}
}
//Store(Arg0, PRTC)
WriteByteToEC(SMBusBaseOffsetInERAM + EC_SMPR, Protocol);
//
// Wait for completion.
//
//Store(SWTC(1000), Local0)
if( ECSMBusWaitComplete(SMBusBaseOffsetInERAM,1000) !=0) return 0x07;
}
// Release(SBX0)
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -