Guest User

Untitled

a guest
Oct 14th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <irq.h>
  6. #include <uart.h>
  7. #include <time.h>
  8. #include <generated/csr.h>
  9. #include <console.h>
  10.  
  11. #include "ahwflags.h"
  12. #include "eeprom.h"
  13.  
  14. unsigned char eeprom_spi_xfer(unsigned char length, unsigned int mosi)
  15. {
  16.     eeprom_mosi_write(mosi);
  17.     eeprom_length_write(length);
  18.     eeprom_ctrl_write(CTRL_START);
  19.     while(!(eeprom_status_read() & STATUS_DONE));
  20.     return eeprom_miso_read();
  21. }
  22.  
  23. void eeprom_write_enable(void)
  24. {
  25.     eeprom_spi_xfer(8, WREN<<16);
  26. }
  27.  
  28. void eeprom_write_disable(void)
  29. {
  30.     eeprom_spi_xfer(8, WRDI<<16);
  31. }
  32.  
  33. unsigned char eeprom_read_status(void)
  34. {
  35.     return eeprom_spi_xfer(16, RDSR<<16) & 0xff;
  36. }
  37.  
  38. void eeprom_write_status(unsigned char data)
  39. {
  40.     eeprom_spi_xfer(16, (WRSR<<16) | (data << 8));
  41. }
  42.  
  43.  
  44. void eeprom_write(unsigned char adr, unsigned char data)
  45. {
  46.     eeprom_spi_xfer(24, (WRITE<<16) | (adr << 8) | data);
  47. }
  48.  
  49. unsigned char eeprom_read(unsigned char adr)
  50. {
  51.     return eeprom_spi_xfer(24, (READ<<16) | (adr << 8)) & 0xff;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment