void m25_write_status(u8 sr) { spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_WRSR); spi_xfer(SPI_BUS_FLASH, sr); spi_slave_deselect(); }
/* Returns the 32-bit value representing temperature data from the module. */ static uint32_t max31855_read(void) { uint32_t raw_reading; spi_slave_select(SPI_SLAVE_MAX31855); raw_reading = spi_read_dword(); spi_slave_deselect(); return raw_reading; }
u8 m25_read_status(void) { u8 sr; spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_RDSR); sr = spi_xfer(SPI_BUS_FLASH, 0x00); spi_slave_deselect(); return sr; }
void m25_bulk_erase(void) { spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_BE); spi_slave_deselect(); while(m25_read_status() & M25_SR_WIP); }
/** Write to one of the MAX2769 registers. * * \param addr MAX2769 register to write to. * \param data Data to write to register (28 bits). */ void max2769_write(u8 addr, u32 data) { u32 write_word = ((data << 4) & 0xFFFFFFF0) | (addr & 0x0F); spi_slave_select(SPI_SLAVE_FRONTEND); spi_xfer(SPI_BUS_FRONTEND, (write_word >> 24) & 0xFF); spi_xfer(SPI_BUS_FRONTEND, (write_word >> 16) & 0xFF); spi_xfer(SPI_BUS_FRONTEND, (write_word >> 8) & 0xFF); spi_xfer(SPI_BUS_FRONTEND, (write_word >> 0) & 0xFF); spi_slave_deselect(); }
u32 m25_read_id(void) { u8 manf_id, mem_type, mem_capacity; spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_RDID); manf_id = (u8)spi_xfer(SPI_BUS_FLASH, 0x00); mem_type = (u8)spi_xfer(SPI_BUS_FLASH, 0x00); mem_capacity = (u8)spi_xfer(SPI_BUS_FLASH, 0x00); spi_slave_deselect(); return mem_capacity | mem_type << 8 | manf_id << 16; }
void m25_sector_erase(u32 addr) { spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_SE); spi_xfer(SPI_BUS_FLASH, (addr >> 16) & 0xFF); spi_xfer(SPI_BUS_FLASH, (addr >> 8) & 0xFF); spi_xfer(SPI_BUS_FLASH, addr & 0xFF); spi_slave_deselect(); while(m25_read_status() & M25_SR_WIP); }
void m25_page_program(u32 addr, u8 len, u8 buff[]) { u32 i; spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_PP); spi_xfer(SPI_BUS_FLASH, (addr >> 16) & 0xFF); spi_xfer(SPI_BUS_FLASH, (addr >> 8) & 0xFF); spi_xfer(SPI_BUS_FLASH, addr & 0xFF); for(i = 0; i < len; i++) spi_xfer(SPI_BUS_FLASH, buff[i]); spi_slave_deselect(); while(m25_read_status() & M25_SR_WIP); }
void m25_read(u32 addr, u32 len, u8 *buff) { spi_slave_select(SPI_SLAVE_FLASH); // spi_xfer(SPI_BUS_FLASH, M25_FAST_READ); spi_xfer(SPI_BUS_FLASH, M25_READ); spi_xfer(SPI_BUS_FLASH, (addr >> 16) & 0xFF); spi_xfer(SPI_BUS_FLASH, (addr >> 8) & 0xFF); spi_xfer(SPI_BUS_FLASH, addr & 0xFF); // spi_xfer(SPI_BUS_FLASH, 0x00); // Dummy byte for(u32 i=0; i < len; i++) buff[i] = spi_xfer(SPI_BUS_FLASH, 0x00); spi_slave_deselect(); }
void m25_write_disable(void) { spi_slave_select(SPI_SLAVE_FLASH); spi_xfer(SPI_BUS_FLASH, M25_WRDI); spi_slave_deselect(); }