/* Copy data from NVRAM to system memory. 
This is a special form of the READ command used by some Ramtron/Cypress 4Kbit FRAM devices which puts the 9th address bit inside the command byte to be able to use one byte for addressing instead of two. */
static int nvram_spi_read_9bit_addr(nvram_t *dev, uint8_t *dst, uint32_t src, size_t len)
/* Copy data from NVRAM to system memory. 
This is a special form of the READ command used by some Ramtron/Cypress 4Kbit FRAM devices which puts the 9th address bit inside the command byte to be able to use one byte for addressing instead of two. */
static int nvram_spi_read_9bit_addr(nvram_t *dev, uint8_t *dst, uint32_t src, size_t len)
{
    nvram_spi_params_t *spi_dev = (nvram_spi_params_t *) dev->extra;
    int status;
    uint8_t cmd;
    uint8_t addr;
    cmd = NVRAM_SPI_CMD_READ;
    if (src > 0xff) {
        cmd |= 0x08;
    }
    addr = (src & 0xff);
    spi_acquire(spi_dev->spi);
    gpio_clear(spi_dev->cs);
    status = spi_transfer_reg(spi_dev->spi, (char)cmd, addr, NULL);
    if (status < 0)
    {
        return status;
    }
    status = spi_transfer_bytes(spi_dev->spi, NULL, (char *)dst, len);
    if (status < 0)
    {
        return status;
    }
    gpio_set(spi_dev->cs);
    spi_release(spi_dev->spi);
    return status;
}