Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <irq.h>
- #include <uart.h>
- #include <time.h>
- #include <generated/csr.h>
- #include <console.h>
- #include "ahwflags.h"
- #include "eeprom.h"
- unsigned char eeprom_spi_xfer(unsigned char length, unsigned int mosi)
- {
- eeprom_mosi_write(mosi);
- eeprom_length_write(length);
- eeprom_ctrl_write(CTRL_START);
- while(!(eeprom_status_read() & STATUS_DONE));
- return eeprom_miso_read();
- }
- void eeprom_write_enable(void)
- {
- eeprom_spi_xfer(8, WREN<<16);
- }
- void eeprom_write_disable(void)
- {
- eeprom_spi_xfer(8, WRDI<<16);
- }
- unsigned char eeprom_read_status(void)
- {
- return eeprom_spi_xfer(16, RDSR<<16) & 0xff;
- }
- void eeprom_write_status(unsigned char data)
- {
- eeprom_spi_xfer(16, (WRSR<<16) | (data << 8));
- }
- void eeprom_write(unsigned char adr, unsigned char data)
- {
- eeprom_spi_xfer(24, (WRITE<<16) | (adr << 8) | data);
- }
- unsigned char eeprom_read(unsigned char adr)
- {
- return eeprom_spi_xfer(24, (READ<<16) | (adr << 8)) & 0xff;
- }
Advertisement
Add Comment
Please, Sign In to add comment