/* * waits for a completion of an I2C transfer * * Returns * Nothing */ void SkI2cWaitIrq( SK_AC *pAC, /* Adapter Context */ SK_IOC IoC) /* I/O Context */ { SK_SENSOR *pSen; SK_U64 StartTime; SK_U32 IrqSrc; pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens]; if (pSen->SenState == SK_SEN_IDLE) { return; } StartTime = SkOsGetTime(pAC); do { if (SkOsGetTime(pAC) - StartTime > SK_TICKS_PER_SEC / 8) { SK_I2C_STOP(IoC); #ifndef SK_DIAG SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E016, SKERR_I2C_E016MSG); #endif /* !SK_DIAG */ return; } SK_IN32(IoC, B0_ISRC, &IrqSrc); } while ((IrqSrc & IS_I2C_READY) == 0); pSen->SenState = SK_SEN_IDLE; return; } /* SkI2cWaitIrq */
int spi_timer(SK_AC *pAC, unsigned int t) { if (t) { pAC->TimeBuf = SkOsGetTime(pAC)+(SK_U64)t*SK_TICKS_PER_SEC; } else { if (pAC->TimeBuf <= SkOsGetTime(pAC)) { return(1); } } return(0); }
/* * waits for a completion of an I2C transfer * * returns 0: success, transfer completes * 1: error, transfer does not complete, I2C transfer * killed, wait loop terminated. */ int SkI2cWait( SK_AC *pAC, /* Adapter Context */ SK_IOC IoC, /* I/O Context */ int Event) /* complete event to wait for (I2C_READ or I2C_WRITE) */ { SK_U64 StartTime; SK_U32 I2cCtrl; StartTime = SkOsGetTime(pAC); do { if (SkOsGetTime(pAC) - StartTime > SK_TICKS_PER_SEC / 8) { SK_I2C_STOP(IoC); #ifndef SK_DIAG SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E002, SKERR_I2C_E002MSG); #endif /* !SK_DIAG */ return(1); } SK_I2C_GET_CTL(IoC, &I2cCtrl); } while ((I2cCtrl & I2C_FLAG) == (SK_U32)Event << 31); return(0); } /* SkI2cWait */
/* * waits for a completion of a TWSI transfer * * returns 0: success, transfer completes * 1: error, transfer does not complete, TWSI transfer * killed, wait loop terminated. */ int SkI2cWait( SK_AC *pAC, /* Adapter Context */ SK_IOC IoC, /* I/O Context */ int Event) /* complete event to wait for (I2C_READ or I2C_WRITE) */ { SK_U64 StartTime; SK_U64 CurrentTime; SK_U32 I2cCtrl; StartTime = SkOsGetTime(pAC); do { CurrentTime = SkOsGetTime(pAC); if (CurrentTime - StartTime > SK_TICKS_PER_SEC / 8) { SK_I2C_STOP(IoC); #ifndef SK_DIAG if (pAC->I2c.InitLevel > SK_INIT_DATA) { SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E002, SKERR_I2C_E002MSG); } #endif /* !SK_DIAG */ return(1); } SK_I2C_GET_CTL(IoC, &I2cCtrl); #ifdef xYUKON_DBG printf("StartTime=%lu, CurrentTime=%lu\n", StartTime, CurrentTime); if (kbhit()) { return(1); } #endif /* YUKON_DBG */ } while ((I2cCtrl & I2C_FLAG) == (SK_U32)Event << 31); return(0); } /* SkI2cWait */
/* * Check this sensors Value against the threshold and send events. */ static void SkI2cCheckSensor( SK_AC *pAC, /* Adapter Context */ SK_SENSOR *pSen) { SK_EVPARA ParaLocal; SK_BOOL TooHigh; /* Is sensor too high? */ SK_BOOL TooLow; /* Is sensor too low? */ SK_U64 CurrTime; /* Current Time */ SK_BOOL DoTrapSend; /* We need to send a trap */ SK_BOOL DoErrLog; /* We need to log the error */ SK_BOOL IsError; /* We need to log the error */ /* Check Dummy Reads first */ if (pAC->I2c.DummyReads > 0) { pAC->I2c.DummyReads--; return; } /* Get the current time */ CurrTime = SkOsGetTime(pAC); /* Set para to the most useful setting: The current sensor. */ ParaLocal.Para64 = (SK_U64)pAC->I2c.CurrSens; /* Check the Value against the thresholds. First: Error Thresholds */ TooHigh = (pSen->SenValue > pSen->SenThreErrHigh); TooLow = (pSen->SenValue < pSen->SenThreErrLow); IsError = SK_FALSE; if (TooHigh || TooLow) { /* Error condition is satisfied */ DoTrapSend = SK_TRUE; DoErrLog = SK_TRUE; /* Now error condition is satisfied */ IsError = SK_TRUE; if (pSen->SenErrFlag == SK_SEN_ERR_ERR) { /* This state is the former one */ /* So check first whether we have to send a trap */ if (pSen->SenLastErrTrapTS + SK_SEN_ERR_TR_HOLD > CurrTime) { /* * Do NOT send the Trap. The hold back time * has to run out first. */ DoTrapSend = SK_FALSE; } /* Check now whether we have to log an Error */ if (pSen->SenLastErrLogTS + SK_SEN_ERR_LOG_HOLD > CurrTime) { /* * Do NOT log the error. The hold back time * has to run out first. */ DoErrLog = SK_FALSE; } } else { /* We came from a different state -> Set Begin Time Stamp */ pSen->SenBegErrTS = CurrTime; pSen->SenErrFlag = SK_SEN_ERR_ERR; } if (DoTrapSend) { /* Set current Time */ pSen->SenLastErrTrapTS = CurrTime; pSen->SenErrCts++; /* Queue PNMI Event */ SkEventQueue(pAC, SKGE_PNMI, (TooHigh ? SK_PNMI_EVT_SEN_ERR_UPP : SK_PNMI_EVT_SEN_ERR_LOW), ParaLocal); } if (DoErrLog) { /* Set current Time */ pSen->SenLastErrLogTS = CurrTime; if (pSen->SenType == SK_SEN_TEMP) { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E011, SKERR_I2C_E011MSG); } else if (pSen->SenType == SK_SEN_VOLT) { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E012, SKERR_I2C_E012MSG); } else { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E015, SKERR_I2C_E015MSG); } } } /* Check the Value against the thresholds */ /* 2nd: Warning thresholds */ TooHigh = (pSen->SenValue > pSen->SenThreWarnHigh); TooLow = (pSen->SenValue < pSen->SenThreWarnLow); if (!IsError && (TooHigh || TooLow)) { /* Error condition is satisfied */ DoTrapSend = SK_TRUE; DoErrLog = SK_TRUE; if (pSen->SenErrFlag == SK_SEN_ERR_WARN) { /* This state is the former one */ /* So check first whether we have to send a trap */ if (pSen->SenLastWarnTrapTS + SK_SEN_WARN_TR_HOLD > CurrTime) { /* * Do NOT send the Trap. The hold back time * has to run out first. */ DoTrapSend = SK_FALSE; } /* Check now whether we have to log an Error */ if (pSen->SenLastWarnLogTS + SK_SEN_WARN_LOG_HOLD > CurrTime) { /* * Do NOT log the error. The hold back time * has to run out first. */ DoErrLog = SK_FALSE; } } else { /* We came from a different state -> Set Begin Time Stamp */ pSen->SenBegWarnTS = CurrTime; pSen->SenErrFlag = SK_SEN_ERR_WARN; } if (DoTrapSend) { /* Set current Time */ pSen->SenLastWarnTrapTS = CurrTime; pSen->SenWarnCts++; /* Queue PNMI Event */ SkEventQueue(pAC, SKGE_PNMI, (TooHigh ? SK_PNMI_EVT_SEN_WAR_UPP : SK_PNMI_EVT_SEN_WAR_LOW), ParaLocal); } if (DoErrLog) { /* Set current Time */ pSen->SenLastWarnLogTS = CurrTime; if (pSen->SenType == SK_SEN_TEMP) { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E009, SKERR_I2C_E009MSG); } else if (pSen->SenType == SK_SEN_VOLT) { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E010, SKERR_I2C_E010MSG); } else { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E014, SKERR_I2C_E014MSG); } } } /* Check for NO error at all */ if (!IsError && !TooHigh && !TooLow) { /* Set o.k. Status if no error and no warning condition */ pSen->SenErrFlag = SK_SEN_ERR_OK; } /* End of check against the thresholds */ /* Bug fix AF: 16.Aug.2001: Correct the init base * of LM80 sensor. */ if (pSen->SenInit == SK_SEN_DYN_INIT_PCI_IO) { pSen->SenInit = SK_SEN_DYN_INIT_NONE; if (pSen->SenValue > SK_SEN_PCI_IO_RANGE_LIMITER) { /* 5V PCI-IO Voltage */ pSen->SenThreWarnLow = SK_SEN_PCI_IO_5V_LOW_WARN; pSen->SenThreErrLow = SK_SEN_PCI_IO_5V_LOW_ERR; } else { /* 3.3V PCI-IO Voltage */ pSen->SenThreWarnHigh = SK_SEN_PCI_IO_3V3_HIGH_WARN; pSen->SenThreErrHigh = SK_SEN_PCI_IO_3V3_HIGH_ERR; } } #ifdef TEST_ONLY /* Dynamic thresholds also for VAUX of LM80 sensor */ if (pSen->SenInit == SK_SEN_DYN_INIT_VAUX) { pSen->SenInit = SK_SEN_DYN_INIT_NONE; /* 3.3V VAUX Voltage */ if (pSen->SenValue > SK_SEN_VAUX_RANGE_LIMITER) { pSen->SenThreWarnLow = SK_SEN_VAUX_3V3_LOW_WARN; pSen->SenThreErrLow = SK_SEN_VAUX_3V3_LOW_ERR; } /* 0V VAUX Voltage */ else { pSen->SenThreWarnHigh = SK_SEN_VAUX_0V_WARN_ERR; pSen->SenThreErrHigh = SK_SEN_VAUX_0V_WARN_ERR; } } /* * Check initialization state: * The VIO Thresholds need adaption */ if (!pSen->SenInit && pSen->SenReg == LM80_VT1_IN && pSen->SenValue > SK_SEN_WARNLOW2C && pSen->SenValue < SK_SEN_WARNHIGH2) { pSen->SenThreErrLow = SK_SEN_ERRLOW2C; pSen->SenThreWarnLow = SK_SEN_WARNLOW2C; pSen->SenInit = SK_TRUE; } if (!pSen->SenInit && pSen->SenReg == LM80_VT1_IN && pSen->SenValue > SK_SEN_WARNLOW2 && pSen->SenValue < SK_SEN_WARNHIGH2C) { pSen->SenThreErrHigh = SK_SEN_ERRHIGH2C; pSen->SenThreWarnHigh = SK_SEN_WARNHIGH2C; pSen->SenInit = SK_TRUE; } #endif if (pSen->SenInit != SK_SEN_DYN_INIT_NONE) { SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E013, SKERR_I2C_E013MSG); } } /* SkI2cCheckSensor */