ESP8266_RTOS_SDK v1.4.0

- Main Page
- Modules
- Data Structures
- Files

- File List

spi_flash.h
1 /*
2 * ESPRSSIF MIT License
3 *
4 * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5 *
6 * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7 * it is free of charge, to any person obtaining a copy of this software and associated
8 * documentation files (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 * to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or
14 * substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #ifndef __SPI_FLASH_H__
26 #define __SPI_FLASH_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
48 typedef enum {
49 SPI_FLASH_RESULT_OK,
50 SPI_FLASH_RESULT_ERR,
51 SPI_FLASH_RESULT_TIMEOUT
52 } SpiFlashOpResult;
53
54 typedef struct{
55 uint32 deviceId;
56 uint32 chip_size; // chip size in byte
57 uint32 block_size;
58 uint32 sector_size;
59 uint32 page_size;
60 uint32 status_mask;
61 } SpiFlashChip;
62
63 #define SPI_FLASH_SEC_SIZE 4096
72 uint32 spi_flash_get_id(void);
73
81 SpiFlashOpResult spi_flash_read_status(uint32 *status);
82
90 SpiFlashOpResult spi_flash_write_status(uint32 status_value);
91
99 SpiFlashOpResult spi_flash_erase_sector(uint16 sec);
100
110 SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size);
111
121 SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size);
122
135 typedef SpiFlashOpResult (* user_spi_flash_read)(
136 SpiFlashChip *spi,
137 uint32 src_addr,
138 uint32 *des_addr,
139 uint32 size);
140
151 void spi_flash_set_read_func(user_spi_flash_read read);
152
161 #ifdef __cplusplus
162 }
163 #endif
164
165 #endif
SpiFlashChip
Definition: spi_flash.h:54
spi_flash_write_status
SpiFlashOpResult spi_flash_write_status(uint32 status_value)
Write state register of SPI Flash.
spi_flash_read
SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size)
Read data from Flash.
SPI_FLASH_RESULT_ERR
Definition: spi_flash.h:50
spi_flash_erase_sector
SpiFlashOpResult spi_flash_erase_sector(uint16 sec)
Erase the Flash sector.
SPI_FLASH_RESULT_TIMEOUT
Definition: spi_flash.h:51
spi_flash_write
SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size)
Write data to Flash.
SpiFlashOpResult
SpiFlashOpResult
Definition: spi_flash.h:48
user_spi_flash_read
SpiFlashOpResult(* user_spi_flash_read)(SpiFlashChip *spi, uint32 src_addr, uint32 *des_addr, uint32 size)
Registered function for spi_flash_set_read_func.
Definition: spi_flash.h:135
spi_flash_read_status
SpiFlashOpResult spi_flash_read_status(uint32 *status)
Read state register of SPI Flash.
SPI_FLASH_RESULT_OK
Definition: spi_flash.h:49
spi_flash_set_read_func
void spi_flash_set_read_func(user_spi_flash_read read)
Register user-define SPI flash read API.