Ejemplo n.º 1
0
/*
 * Init level 2: Start first sensor read.
 */
static int SkI2cInit2(
SK_AC	*pAC,	/* Adapter Context */
SK_IOC	IoC)	/* I/O Context */
{
	int		ReadComplete;
	SK_SENSOR	*pSen;

	if (pAC->I2c.InitLevel != SK_INIT_IO) {
		/* ReInit not needed in I2C module */
		/* Init0 and Init2 not permitted */
		return(0);
	}

	pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
	ReadComplete = SkI2cReadSensor(pAC, IoC, pSen);

	if (ReadComplete) {
		SK_ERR_LOG(pAC, SK_ERRCL_INIT, SKERR_I2C_E008, SKERR_I2C_E008MSG);
	}

	/* Now we are correctly initialized */
	pAC->I2c.InitLevel = SK_INIT_RUN;

	return(0);
}	/* SkI2cInit2*/
Ejemplo n.º 2
0
/*
 * The only Event to be served is the timeout event
 *
 */
int	SkI2cEvent(
    SK_AC		*pAC,	/* Adapter Context */
    SK_IOC		IoC,	/* I/O Context */
    SK_U32		Event,	/* Module specific Event */
    SK_EVPARA	Para)	/* Event specific Parameter */
{
    int			ReadComplete;
    SK_SENSOR	*pSen;
    SK_U32		Time;
    SK_EVPARA	ParaLocal;
    int			i;

    switch (Event) {
    case SK_I2CEV_IRQ:
    case SK_I2CEV_TIM:
        pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
        ReadComplete = SkI2cReadSensor(pAC, IoC, pSen);

        if (ReadComplete) {
            /* Check sensor against defined thresholds */
            SkI2cCheckSensor (pAC, pSen);

            /* Increment Current and set appropriate Timeout */
            Time = SK_I2C_TIM_SHORT;

            pAC->I2c.CurrSens ++;
            if (pAC->I2c.CurrSens == pAC->I2c.MaxSens) {
                pAC->I2c.CurrSens = 0;
                Time = SK_I2C_TIM_LONG;
            }

            /* Start Timer */
            ParaLocal.Para64 = (SK_U64) 0;
            SkTimerStart(pAC, IoC, &pAC->I2c.SenTimer, Time,
                         SKGE_I2C, SK_I2CEV_TIM, ParaLocal);
        }
        break;
    case SK_I2CEV_CLEAR:
        for (i = 0; i < SK_MAX_SENSORS; i ++) {
            pAC->I2c.SenTable[i].SenErrFlag = SK_SEN_ERR_OK;
            pAC->I2c.SenTable[i].SenErrCts = 0;
            pAC->I2c.SenTable[i].SenWarnCts = 0;
            pAC->I2c.SenTable[i].SenBegErrTS = 0;
            pAC->I2c.SenTable[i].SenBegWarnTS = 0;
            pAC->I2c.SenTable[i].SenLastErrTrapTS = (SK_U64)0;
            pAC->I2c.SenTable[i].SenLastErrLogTS = (SK_U64)0;
            pAC->I2c.SenTable[i].SenLastWarnTrapTS = (SK_U64)0;
            pAC->I2c.SenTable[i].SenLastWarnLogTS = (SK_U64)0;
        }
        break;
    default:
        SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E006, SKERR_I2C_E006MSG);
    }

    return(0);
}	/* SkI2cEvent*/