2014-12-30 19:47:44 +01:00
|
|
|
#ifndef __FLASH_API_H__
|
|
|
|
#define __FLASH_API_H__
|
|
|
|
#include "ets_sys.h"
|
2015-01-01 15:22:05 +01:00
|
|
|
#include "user_config.h"
|
2015-01-05 03:09:51 +01:00
|
|
|
#include "cpu_esp8266.h"
|
2015-02-14 19:13:58 +01:00
|
|
|
|
2015-03-15 17:48:28 +01:00
|
|
|
#define FLASH_SIZE_2MBIT (2 * 1024 * 1024)
|
|
|
|
#define FLASH_SIZE_4MBIT (4 * 1024 * 1024)
|
|
|
|
#define FLASH_SIZE_8MBIT (8 * 1024 * 1024)
|
|
|
|
#define FLASH_SIZE_16MBIT (16 * 1024 * 1024)
|
|
|
|
#define FLASH_SIZE_32MBIT (32 * 1024 * 1024)
|
|
|
|
#define FLASH_SIZE_64MBIT (64 * 1024 * 1024)
|
|
|
|
#define FLASH_SIZE_128MBIT (128 * 1024 * 1024)
|
|
|
|
|
|
|
|
#define FLASH_SIZE_256KBYTE (FLASH_SIZE_2MBIT / 8)
|
|
|
|
#define FLASH_SIZE_512KBYTE (FLASH_SIZE_4MBIT / 8)
|
2015-03-15 22:40:43 +01:00
|
|
|
#define FLASH_SIZE_1MBYTE (FLASH_SIZE_8MBIT / 8)
|
2015-03-15 17:48:28 +01:00
|
|
|
#define FLASH_SIZE_2MBYTE (FLASH_SIZE_16MBIT / 8)
|
|
|
|
#define FLASH_SIZE_4MBYTE (FLASH_SIZE_32MBIT / 8)
|
2015-03-15 22:40:43 +01:00
|
|
|
#define FLASH_SIZE_8MBYTE (FLASH_SIZE_64MBIT / 8)
|
2015-03-15 17:48:28 +01:00
|
|
|
#define FLASH_SIZE_16MBYTE (FLASH_SIZE_128MBIT/ 8)
|
|
|
|
|
|
|
|
#define FLASH_SAFEMODE_ENTER() \
|
|
|
|
do { \
|
|
|
|
extern SpiFlashChip * flashchip; \
|
2015-03-15 17:51:47 +01:00
|
|
|
flashchip->chip_size = FLASH_SIZE_16MBYTE
|
2015-03-15 17:48:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define FLASH_SAFEMODE_LEAVE() \
|
2015-03-15 17:51:47 +01:00
|
|
|
flashchip->chip_size = flash_rom_get_size_byte(); \
|
2015-03-15 17:48:28 +01:00
|
|
|
} while(0)
|
2015-01-02 10:56:34 +01:00
|
|
|
|
2015-01-06 12:32:17 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* ROM Function definition
|
|
|
|
* Note: It is unsafe to use ROM function, but it may efficient.
|
|
|
|
* SPIEraseSector
|
2015-03-15 17:48:28 +01:00
|
|
|
* SpiFlashOpResult SPIEraseSector(uint16 sec);
|
2015-01-06 12:32:17 +01:00
|
|
|
* The 1st parameter is flash sector number.
|
2015-03-15 17:48:28 +01:00
|
|
|
* Note: Must disable cache read before using it.
|
2015-01-06 12:32:17 +01:00
|
|
|
|
2015-03-15 17:48:28 +01:00
|
|
|
* SPIRead
|
|
|
|
* SpiFlashOpResult SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
|
2015-01-06 12:32:17 +01:00
|
|
|
* The 1st parameter is source addresses.
|
|
|
|
* The 2nd parameter is destination addresses.
|
|
|
|
* The 3rd parameter is size.
|
2015-03-15 17:48:28 +01:00
|
|
|
* Note: Must disable cache read before using it.
|
2015-01-06 12:32:17 +01:00
|
|
|
|
2015-03-15 17:48:28 +01:00
|
|
|
* SPIWrite
|
|
|
|
* SpiFlashOpResult SPIWrite(uint32_t des_addr, uint32_t *src_addr, uint32_t size);
|
2015-01-06 12:32:17 +01:00
|
|
|
* The 1st parameter is destination addresses.
|
|
|
|
* The 2nd parameter is source addresses.
|
|
|
|
* The 3rd parameter is size.
|
2015-03-15 17:48:28 +01:00
|
|
|
* Note: Must disable cache read before using it.
|
2015-01-06 12:32:17 +01:00
|
|
|
*******************************************************************************/
|
|
|
|
|
2015-01-01 15:22:05 +01:00
|
|
|
typedef struct
|
2014-12-30 19:47:44 +01:00
|
|
|
{
|
2015-03-15 22:40:43 +01:00
|
|
|
uint8_t header_magic;
|
|
|
|
uint8_t segment_count;
|
2014-12-30 19:47:44 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
MODE_QIO = 0,
|
|
|
|
MODE_QOUT = 1,
|
|
|
|
MODE_DIO = 2,
|
|
|
|
MODE_DOUT = 15,
|
|
|
|
} mode : 8;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SPEED_40MHZ = 0,
|
|
|
|
SPEED_26MHZ = 1,
|
|
|
|
SPEED_20MHZ = 2,
|
|
|
|
SPEED_80MHZ = 15,
|
|
|
|
} speed : 4;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIZE_4MBIT = 0,
|
|
|
|
SIZE_2MBIT = 1,
|
|
|
|
SIZE_8MBIT = 2,
|
|
|
|
SIZE_16MBIT = 3,
|
|
|
|
SIZE_32MBIT = 4,
|
2015-12-30 02:46:43 +01:00
|
|
|
SIZE_16MBIT_8M_8M = 5,
|
|
|
|
SIZE_32MBIT_8M_8M = 6,
|
2014-12-30 19:47:44 +01:00
|
|
|
} size : 4;
|
2015-03-15 22:40:43 +01:00
|
|
|
uint32_t entry_point;
|
|
|
|
uint32_t memory_offset;
|
2015-12-30 02:46:43 +01:00
|
|
|
uint32_t segment_size;
|
2015-01-05 03:09:51 +01:00
|
|
|
} ICACHE_STORE_TYPEDEF_ATTR SPIFlashInfo;
|
2014-12-30 19:47:44 +01:00
|
|
|
|
2015-03-15 17:48:28 +01:00
|
|
|
uint32_t flash_detect_size_byte(void);
|
|
|
|
uint32_t flash_safe_get_size_byte(void);
|
|
|
|
uint16_t flash_safe_get_sec_num(void);
|
|
|
|
SpiFlashOpResult flash_safe_read(uint32 src_addr, uint32 *des_addr, uint32 size);
|
|
|
|
SpiFlashOpResult flash_safe_write(uint32 des_addr, uint32 *src_addr, uint32 size);
|
|
|
|
SpiFlashOpResult flash_safe_erase_sector(uint16 sec);
|
|
|
|
SPIFlashInfo flash_rom_getinfo(void);
|
|
|
|
uint8_t flash_rom_get_size_type(void);
|
|
|
|
uint32_t flash_rom_get_size_byte(void);
|
|
|
|
bool flash_rom_set_size_type(uint8_t);
|
|
|
|
bool flash_rom_set_size_byte(uint32_t);
|
|
|
|
uint16_t flash_rom_get_sec_num(void);
|
|
|
|
uint8_t flash_rom_get_mode(void);
|
|
|
|
uint32_t flash_rom_get_speed(void);
|
2015-01-05 14:56:55 +01:00
|
|
|
bool flash_init_data_written(void);
|
2014-12-31 01:08:31 +01:00
|
|
|
bool flash_init_data_default(void);
|
|
|
|
bool flash_init_data_blank(void);
|
|
|
|
bool flash_self_destruct(void);
|
2015-01-06 18:15:38 +01:00
|
|
|
uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index);
|
2015-05-05 17:59:30 +02:00
|
|
|
uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index);
|
2015-03-15 22:40:43 +01:00
|
|
|
// uint8_t flash_rom_get_checksum(void);
|
|
|
|
// uint8_t flash_rom_calc_checksum(void);
|
2014-12-31 01:08:31 +01:00
|
|
|
|
2014-12-30 19:47:44 +01:00
|
|
|
#endif // __FLASH_API_H__
|