Exemple #1
0
RBAPI(bool) i2cslave_Write(int dev, unsigned char val) {
    unsigned long nowtime;

    if (I2C_action[dev] != I2CACT_SLAVEWRITEREQ)
    {
        err_SetMsg(ERROR_I2CWRONGUSAGE, "slave must write data only when being requested");
        return false;
    }
    
    i2cslave_ClearSlaveWREQ(dev);
    i2c_WriteDataREG(dev, val);

    for (nowtime=0; nowtime<100000L; nowtime++) //trick for performance; timer_nowtime() is time-consuming in some OS
        if (i2c_CheckTXDone(dev) == true) goto TX_SUCCESS;

    nowtime = timer_nowtime();
    while ((i2c_CheckTXDone(dev) == false) && ((timer_nowtime() - nowtime) < I2C_TIMEOUT));

    if (i2c_CheckTXDone(dev) == false)
    {
        err_SetMsg(ERROR_I2CFAIL, "the I2C module doesn't respond");
        I2C_action[dev] = I2CACT_IDLE;
        return false;
    }

TX_SUCCESS:
    i2c_ClearTXDone(dev);
    I2C_action[dev] = I2CACT_SLAVE;
    return true;
}
Exemple #2
0
RBAPI(bool) i2cmaster_Write(int dev, unsigned char val) {
    if (I2C_action[dev] != I2CACT_MASTERWRITE)
    {
        err_SetMsg(ERROR_I2CWRONGUSAGE, "must start a correct transaction before writing data");
        return false;
    }

    i2c_WriteDataREG(dev, val);

    if (check_TX_done(dev) == true) return true;

    I2C_action[dev] = I2CACT_IDLE;
    return false;
}
Exemple #3
0
RBAPI(bool) i2cmaster_Write(int dev, unsigned char val) {
    bool result;

    if (I2C_action[dev] != I2CACT_MASTERWRITE)
    {
        err_SetMsg(ERROR_I2CWRONGUSAGE, "must start a correct transaction before writing data");
        return false;
    }

    if (I2C_swMode[dev] != I2CSW_DISABLE)
        result = i2csw_Write(dev, val);
    else
    {
        i2c_WriteDataREG(dev, val);
        result = check_TX_done(dev);
    }

    if (result == false) I2C_action[dev] = I2CACT_IDLE;
    return result;
}