enum i2c_status {
IDLE = 0, // no I2C command pending
DONE_STOP = 1, // I2C command done and STOP executed
BUSY = 2, // executing I2C command
TO_SCL = 3, // executing I2C command, time out on clock stretching
TO_ARB = 4, // time out on arbitration trial, still trying
DONE_WRITE = 5, // I2C command done and awaiting next write command
DONE_READ = 6, // I2C command done and awaiting next read command
DONE_WRITE_TO = 7, // see 5, and time out on status echo
DONE_READ_TO = 8, // see 6, and time out on status echo
NO_DEVICE = 9, // no acknowledge on device slave address
NO_ACKN = 10, // no acknowledge after data byte transfer
BUS_ERR = 11, // bus error
ARB_LOST = 12, // arbitration lost during transfer
SEQ_ERR = 13, // erroneous programming sequence
ST_ERR = 14, // wrong status echoing
SW_ERR = 15 // software error
};
enum i2c_attr {
NOP = 0, // no operation on I2C bus
STOP = 1, // stop condition, no associated byte transfer CONTINUE = 2, // continue with byte transfer
START = 3 // start condition with byte transfer
};
staticinlineint i2c_is_error(enum i2c_status status)
{ switch (status) { case NO_DEVICE: case NO_ACKN: case BUS_ERR: case ARB_LOST: case SEQ_ERR: case ST_ERR: returntrue; default: returnfalse;
}
}
staticinlineint i2c_is_idle(enum i2c_status status)
{ switch (status) { case IDLE: case DONE_STOP: returntrue; default: returnfalse;
}
}
staticinlineint i2c_is_busy(enum i2c_status status)
{ switch (status) { case BUSY: case TO_SCL: case TO_ARB: returntrue; default: returnfalse;
}
}
staticint i2c_is_busy_wait(struct saa7134_dev *dev)
{ enum i2c_status status; int count;
for (count = 0; count < I2C_WAIT_RETRY; count++) {
status = i2c_get_status(dev); if (!i2c_is_busy(status)) break;
saa_wait(I2C_WAIT_DELAY);
} if (I2C_WAIT_RETRY == count) returnfalse; returntrue;
}
staticint i2c_reset(struct saa7134_dev *dev)
{ enum i2c_status status; int count;
i2c_dbg(2, "i2c reset\n");
status = i2c_get_status(dev); if (!i2c_is_error(status)) returntrue;
i2c_set_status(dev,status);
for (count = 0; count < I2C_WAIT_RETRY; count++) {
status = i2c_get_status(dev); if (!i2c_is_error(status)) break;
udelay(I2C_WAIT_DELAY);
} if (I2C_WAIT_RETRY == count) returnfalse;
i2c_set_attr(dev,CONTINUE); if (!i2c_is_busy_wait(dev)) return -EIO;
status = i2c_get_status(dev); if (i2c_is_error(status)) return -EIO;
data = saa_readb(SAA7134_I2C_DATA);
i2c_dbg(2, "i2c data <= 0x%x\n", data); return data;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.