msg_t Mtd25::spi_write(const uint8_t *txdata, size_t len, uint8_t *writebuf, size_t preamble_len) { memcpy(&writebuf[preamble_len], txdata, len); if (MSG_OK != spi_write_enable()) return MSG_RESET; #if SPI_USE_MUTUAL_EXCLUSION spiAcquireBus(this->spip); #endif spiSelect(spip); spiSend(spip, preamble_len + len, writebuf); spiUnselect(spip); #if SPI_USE_MUTUAL_EXCLUSION spiReleaseBus(this->spip); #endif return wait_op_complete(cfg.programtime); }
/* Page size is usually 256 bytes */ static int it8716f_spi_page_program(struct flashchip *flash, uint8_t *buf, int start) { int i; int result; chipaddr bios = flash->virtual_memory; result = spi_write_enable(); if (result) return result; /* FIXME: The command below seems to be redundant or wrong. */ OUTB(0x06, it8716f_flashport + 1); OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport); for (i = 0; i < flash->page_size; i++) { chip_writeb(buf[i], bios + start + i); } OUTB(0, it8716f_flashport); /* Wait until the Write-In-Progress bit is cleared. * This usually takes 1-10 ms, so wait in 1 ms steps. */ while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) programmer_delay(1000); return 0; }