forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash_hal_mock.cpp
More file actions
36 lines (31 loc) · 969 Bytes
/
Copy pathflash_hal_mock.cpp
File metadata and controls
36 lines (31 loc) · 969 Bytes
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
/* Emulate the flash read/write HAL */
#include <stdint.h>
#include <string.h>
extern "C"
{
uint32_t s_phys_addr = 0;
uint32_t s_phys_size = 0;
uint32_t s_phys_page = 0;
uint32_t s_phys_block = 0;
uint8_t* s_phys_data = nullptr;
}
int32_t flash_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) {
memcpy(dst, s_phys_data + addr, size);
return 0;
}
int32_t flash_hal_write(uint32_t addr, uint32_t size, const uint8_t *src) {
memcpy(s_phys_data + addr, src, size);
return 0;
}
int32_t flash_hal_erase(uint32_t addr, uint32_t size) {
if ((size & (FLASH_SECTOR_SIZE - 1)) != 0 ||
(addr & (FLASH_SECTOR_SIZE - 1)) != 0) {
abort();
}
const uint32_t sector = addr / FLASH_SECTOR_SIZE;
const uint32_t sectorCount = size / FLASH_SECTOR_SIZE;
for (uint32_t i = 0; i < sectorCount; ++i) {
memset(s_phys_data + (sector + i) * FLASH_SECTOR_SIZE, 0xff, FLASH_SECTOR_SIZE);
}
return 0;
}