Example #1
0
 public static byte smbDetect(byte addr)
 {
     Ring0.WriteSmbus(SMB_HSTADD, (addr << 1) | SMB_WRITE);
     Ring0.WriteSmbus(SMB_HSTCNT, 0);
     if (transaction() == true)
     {
         return(addr);
     }
     return(0x00);
 }
Example #2
0
        public static byte smbDetect(byte addr)
        {
            Ring0.WriteSmbus(SMBHSTADD, ((addr & 0x7f) << 1) | SMB_WRITE);
            Ring0.WriteSmbus(SMBAUXCTL, Ring0.ReadSmbus(SMBAUXCTL) & (~SMBAUXCTL_CRC));

            int res = transaction(0x00);

            Ring0.WriteSmbus(SMBAUXCTL, Ring0.ReadSmbus(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B));

            return((res < 0) ? (byte)0x00 : addr);
        }
Example #3
0
        public static ushort getWord(byte addr, byte command)
        {
            Ring0.WriteSmbus(SMB_HSTADD, (addr << 1) | SMB_READ);
            Ring0.WriteSmbus(SMB_HSTCMD, command);

            Ring0.WriteSmbus(SMB_HSTCNT, 0x0C);

            transaction();

            ushort temp = (ushort)(Ring0.ReadSmbus(SMB_HSTDAT0) + (Ring0.ReadSmbus(SMB_HSTDAT1) << 8));

            return(temp);
        }
Example #4
0
        public static ushort getWord(byte addr, byte command)
        {
            Ring0.WriteSmbus(SMBHSTADD, ((addr & 0x7f) << 1) | SMB_READ);
            Ring0.WriteSmbus(SMBHSTCMD, command);

            Ring0.WriteSmbus(SMBAUXCTL, Ring0.ReadSmbus(SMBAUXCTL) & (~SMBAUXCTL_CRC));

            transaction(0x0C);

            Ring0.WriteSmbus(SMBAUXCTL, Ring0.ReadSmbus(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B));

            ushort wordData = (ushort)(Ring0.ReadSmbus(SMBHSTDAT0) + (Ring0.ReadSmbus(SMBHSTDAT1) << 8));

            return(wordData);
        }
Example #5
0
        private static int transaction(byte xact)
        {
            int result = checkPre();

            if (result < 0)
            {
                return(result);
            }

            Ring0.WriteSmbus(SMBHSTCNT, Ring0.ReadSmbus(SMBHSTCNT) & ~SMBHSTCNT_INTREN);
            Ring0.WriteSmbus(SMBHSTCNT, xact | SMBHSTCNT_START);

            int status = waitIntr();

            return(checkPost(status));
        }
Example #6
0
        private static bool transaction()
        {
            byte temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS);

            if (temp != 0x00)
            {
                Ring0.WriteSmbus(SMB_HSTSTS, temp);

                temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS);

                if (temp != 0x00)
                {
                    return(false);
                }
            }

            temp = (byte)Ring0.ReadSmbus(SMB_HSTCNT);
            Ring0.WriteSmbus(SMB_HSTCNT, (byte)(temp | 0x040));

            temp = 0;
            int timeout     = 0;
            int MAX_TIMEOUT = 5000;

            while ((++timeout < MAX_TIMEOUT) && temp <= 1)
            {
                temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS);
            }

            if (timeout == MAX_TIMEOUT || (temp & 0x10) > 0 || (temp & 0x08) > 0 || (temp & 0x04) > 0)
            {
                return(false);
            }

            temp = (byte)Ring0.ReadSmbus(SMB_HSTSTS);
            if (temp != 0x00)
            {
                Ring0.WriteSmbus(SMB_HSTSTS, temp);
            }

            return(true);
        }
Example #7
0
        private static int checkPre()
        {
            ushort status = Ring0.ReadSmbus(SMBHSTSTS);

            if ((status & SMBHSTSTS_HOST_BUSY) > 0)
            {
                return(-1);
            }

            status &= STATUS_FLAGS;
            if (status > 0)
            {
                Ring0.WriteSmbus(SMBHSTSTS, status);
                status = (ushort)(Ring0.ReadSmbus(SMBHSTSTS) & STATUS_FLAGS);
                if (status > 0)
                {
                    return(-1);
                }
            }
            return(0);
        }
Example #8
0
        private static int checkPost(int status)
        {
            int result = 0;

            if (status < 0)
            {
                Ring0.WriteSmbus(SMBHSTCNT, Ring0.ReadSmbus(SMBHSTCNT) | SMBHSTCNT_KILL);
                Thread.Sleep(1);
                Ring0.WriteSmbus(SMBHSTCNT, Ring0.ReadSmbus(SMBHSTCNT) & (~SMBHSTCNT_KILL));

                Ring0.WriteSmbus(SMBHSTSTS, STATUS_FLAGS);
                return(-1);
            }

            if ((status & SMBHSTSTS_FAILED) > 0 || (status & SMBHSTSTS_DEV_ERR) > 0 || (status & SMBHSTSTS_BUS_ERR) > 0)
            {
                result = -1;
            }

            Ring0.WriteSmbus(SMBHSTSTS, status);

            return(result);
        }