int readbytes()

in shakti/bsp/drivers/i2c/i2c_driver.c [263:302]


int readbytes(i2c_struct * instance, char *buf, int count, int last)
{
	int i, status;
	int wfp;

	/* increment number of bytes to read by one -- read dummy byte */
	for (i = 0; i <= count; i++) {
		wfp = wait_till_txrx_operation_Completes(instance, &status);
		if (wfp) {
			instance->control = I2C_STOP;
			return -1;
		}

		if ((status & I2C_LRB) && (i != count)) {
			instance->control = I2C_STOP;
			printf("\tNo ack\n");
			return -1;
		}

		if (i)
		{
			buf[i - 1] = instance->data;
			printf("\n Read Value: %x", buf[i - 1]);
		}
		else
			instance->data = !instance->data; /* dummy read */

		if (i == count - 1) {
			instance->control = I2C_ESO;
		} else if (i == count) {
			if (last)
				instance->control = I2C_STOP;
			else
				instance->control = I2C_REPSTART_ENI;
		}

	}

	return i-1; //excluding the dummy read
}