forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash_hal.h
93 lines (74 loc) · 3.19 KB
/
flash_hal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef flash_hal_h
#define flash_hal_h
/*
flash_hal.h - API for accessing raw flash for filesystems
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
This code was influenced by NodeMCU and Sming libraries, and first version of
Arduino wrapper written by Hristo Gochkov.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef __cplusplus
extern "C" {
#endif
#if FLASH_MAP_SUPPORT
#include <FlashMap.h>
extern uint32_t spi_flash_get_id (void); // <user_interface.h>
extern bool flashinit(void);
extern uint32_t __flashindex;
extern const flash_map_s __flashdesc[];
#define FLASH_MAP_SETUP_CONFIG(conf) FLASH_MAP_SETUP_CONFIG_ATTR(,conf)
#define FLASH_MAP_SETUP_CONFIG_ATTR(attr, conf...) \
const flash_map_s __flashdesc[] PROGMEM = conf; \
bool flashinit (void) attr; \
bool flashinit (void) \
{ \
uint32_t flash_chip_size_kb = 1 << (((spi_flash_get_id() >> 16) & 0xff) - 10); \
for (__flashindex = 0; __flashindex < sizeof(__flashdesc) / sizeof(__flashdesc[0]); __flashindex++) \
if (__flashdesc[__flashindex].flash_size_kb == flash_chip_size_kb) \
return true; \
return false; /* configuration not found */ \
}
#define EEPROM_start (__flashdesc[__flashindex].eeprom_start)
#define FS_start (__flashdesc[__flashindex].fs_start)
#define FS_end (__flashdesc[__flashindex].fs_end)
#define FS_block (__flashdesc[__flashindex].fs_block_size)
#define FS_page (__flashdesc[__flashindex].fs_page_size)
#else // !FLASH_MAP_SUPPORT
extern uint32_t _FS_start;
extern uint32_t _FS_end;
extern uint32_t _FS_page;
extern uint32_t _FS_block;
extern uint32_t _EEPROM_start;
#define EEPROM_start ((uint32_t)&_EEPROM_start)
#define FS_start ((uint32_t)&_FS_start)
#define FS_end ((uint32_t)&_FS_end)
#define FS_page ((uint32_t)&_FS_page)
#define FS_block ((uint32_t)&_FS_block)
#endif // FLASH_MAP_SUPPORT
#define FS_PHYS_ADDR ((uint32_t)FS_start - 0x40200000)
#define FS_PHYS_SIZE ((uint32_t)(FS_end - FS_start))
#define FS_PHYS_PAGE ((uint32_t)FS_page)
#define FS_PHYS_BLOCK ((uint32_t)FS_block)
// Return values of the following functions
#define FLASH_HAL_OK (0)
#define FLASH_HAL_READ_ERROR (-1)
#define FLASH_HAL_WRITE_ERROR (-2)
#define FLASH_HAL_ERASE_ERROR (-3)
extern int32_t flash_hal_write(uint32_t addr, uint32_t size, const uint8_t *src);
extern int32_t flash_hal_erase(uint32_t addr, uint32_t size);
extern int32_t flash_hal_read(uint32_t addr, uint32_t size, uint8_t *dst);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // !defined(flash_hal_h)