xflash.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //xflash.h
  2. #ifndef _XFLASH_H
  3. #define _XFLASH_H
  4. #include <inttypes.h>
  5. #include "config.h"
  6. #include "spi.h"
  7. #define XFLASH_STATUS_BUSY 0x01
  8. #define XFLASH_STATUS_WEL 0x02
  9. #define XFLASH_STATUS_BP0 0x04
  10. #define XFLASH_STATUS_BP1 0x08
  11. #define XFLASH_STATUS_TB 0x20
  12. #define XFLASH_STATUS_SRP 0x80
  13. #define XFLASH_SPI_RATE 0 // fosc/4 = 4MHz
  14. #define XFLASH_SPCR SPI_SPCR(XFLASH_SPI_RATE, 1, 1, 1, 0)
  15. #define XFLASH_SPSR SPI_SPSR(XFLASH_SPI_RATE)
  16. #define XFLASH_SPI_ENTER() spi_setup(XFLASH_SPCR, XFLASH_SPSR)
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif //defined(__cplusplus)
  20. extern int8_t xflash_init(void);
  21. extern void xflash_enable_wr(void);
  22. extern void xflash_disable_wr(void);
  23. extern uint8_t xflash_rd_status_reg(void);
  24. #if 0
  25. extern void w25x20cl_wr_status_reg(uint8_t val);
  26. #endif
  27. extern void xflash_rd_data(uint32_t addr, uint8_t* data, uint16_t cnt);
  28. extern void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
  29. extern void xflash_page_program_P(uint32_t addr, uint8_t* data, uint16_t cnt);
  30. extern void xflash_sector_erase(uint32_t addr);
  31. extern void xflash_block32_erase(uint32_t addr);
  32. extern void xflash_block64_erase(uint32_t addr);
  33. extern void xflash_chip_erase(void);
  34. extern void xflash_page_program(uint32_t addr, uint8_t* data, uint16_t cnt);
  35. extern void xflash_rd_uid(uint8_t* uid);
  36. extern void xflash_wait_busy(void);
  37. #if defined(__cplusplus)
  38. }
  39. #endif //defined(__cplusplus)
  40. #endif //_XFLASH_H