flash_api.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef __FLASH_API_H__
  2. #define __FLASH_API_H__
  3. #include "ets_sys.h"
  4. #include "user_config.h"
  5. #include "cpu_esp8266.h"
  6. #define FLASH_SIZE_2MBIT (2 * 1024 * 1024)
  7. #define FLASH_SIZE_4MBIT (4 * 1024 * 1024)
  8. #define FLASH_SIZE_8MBIT (8 * 1024 * 1024)
  9. #define FLASH_SIZE_16MBIT (16 * 1024 * 1024)
  10. #define FLASH_SIZE_32MBIT (32 * 1024 * 1024)
  11. #define FLASH_SIZE_64MBIT (64 * 1024 * 1024)
  12. #define FLASH_SIZE_128MBIT (128 * 1024 * 1024)
  13. #define FLASH_SIZE_256KBYTE (FLASH_SIZE_2MBIT / 8)
  14. #define FLASH_SIZE_512KBYTE (FLASH_SIZE_4MBIT / 8)
  15. #define FLASH_SIZE_1MBYTE (FLASH_SIZE_8MBIT / 8)
  16. #define FLASH_SIZE_2MBYTE (FLASH_SIZE_16MBIT / 8)
  17. #define FLASH_SIZE_4MBYTE (FLASH_SIZE_32MBIT / 8)
  18. #define FLASH_SIZE_8MBYTE (FLASH_SIZE_64MBIT / 8)
  19. #define FLASH_SIZE_16MBYTE (FLASH_SIZE_128MBIT/ 8)
  20. /******************************************************************************
  21. * ROM Function definition
  22. * Note: It is unsafe to use ROM function, but it may efficient.
  23. * SPIEraseSector
  24. * SpiFlashOpResult SPIEraseSector(uint16 sec);
  25. * The 1st parameter is flash sector number.
  26. * Note: Must disable cache read before using it.
  27. * SPIRead
  28. * SpiFlashOpResult SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
  29. * The 1st parameter is source addresses.
  30. * The 2nd parameter is destination addresses.
  31. * The 3rd parameter is size.
  32. * Note: Must disable cache read before using it.
  33. * SPIWrite
  34. * SpiFlashOpResult SPIWrite(uint32_t des_addr, uint32_t *src_addr, uint32_t size);
  35. * The 1st parameter is destination addresses.
  36. * The 2nd parameter is source addresses.
  37. * The 3rd parameter is size.
  38. * Note: Must disable cache read before using it.
  39. *******************************************************************************/
  40. typedef struct
  41. {
  42. uint8_t header_magic;
  43. uint8_t segment_count;
  44. enum
  45. {
  46. MODE_QIO = 0,
  47. MODE_QOUT = 1,
  48. MODE_DIO = 2,
  49. MODE_DOUT = 15,
  50. } mode : 8;
  51. enum
  52. {
  53. SPEED_40MHZ = 0,
  54. SPEED_26MHZ = 1,
  55. SPEED_20MHZ = 2,
  56. SPEED_80MHZ = 15,
  57. } speed : 4;
  58. enum
  59. {
  60. SIZE_4MBIT = 0,
  61. SIZE_2MBIT = 1,
  62. SIZE_8MBIT = 2,
  63. SIZE_16MBIT = 3,
  64. SIZE_32MBIT = 4,
  65. SIZE_16MBIT_8M_8M = 5,
  66. SIZE_32MBIT_8M_8M = 6,
  67. SIZE_32MBIT_16M_16M = 7,
  68. SIZE_64MBIT = 8,
  69. SIZE_128MBIT = 9,
  70. } size : 4;
  71. uint32_t entry_point;
  72. uint32_t memory_offset;
  73. uint32_t segment_size;
  74. } ICACHE_STORE_TYPEDEF_ATTR SPIFlashInfo;
  75. SPIFlashInfo flash_rom_getinfo(void);
  76. uint8_t flash_rom_get_size_type(void);
  77. uint32_t flash_rom_get_size_byte(void);
  78. uint32_t flash_detect_size_byte(void);
  79. bool flash_rom_set_size_type(uint8_t);
  80. bool flash_rom_set_size_byte(uint32_t);
  81. uint16_t flash_rom_get_sec_num(void);
  82. uint8_t flash_rom_get_mode(void);
  83. uint32_t flash_rom_get_speed(void);
  84. uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index);
  85. uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index);
  86. // uint8_t flash_rom_get_checksum(void);
  87. // uint8_t flash_rom_calc_checksum(void);
  88. #endif // __FLASH_API_H__