/* Read data from Serial Flash device. 
This function reads data from the Serial Flash device, into a buffer. */
enum status_code mx25v_read_buffer(uint32_t address, void *data, uint32_t length)
/* Read data from Serial Flash device. 
This function reads data from the Serial Flash device, into a buffer. */
enum status_code mx25v_read_buffer(uint32_t address, void *data, uint32_t length)
{
	enum status_code status;
	uint8_t tx_buf[4] = {
		MX25V_CMD_READ,
		(uint8_t)(address >> 16),
		(uint8_t)(address >> 8),
		(uint8_t)(address)
	};
	Assert(data);
	if ((address + length) > MX25V_FLASH_SIZE) {
		return STATUS_ERR_INVALID_ARG;
	}
	_mx25v_chip_select();
	status = spi_write_buffer_wait(&_mx25v_spi, tx_buf, 4);
	if (status != STATUS_OK) {
		return STATUS_ERR_IO;
	}
	status = spi_read_buffer_wait(&_mx25v_spi, data, length, 0);
	if (status != STATUS_OK) {
		return STATUS_ERR_IO;
	}
	_mx25v_chip_deselect();
	return STATUS_OK;
}