1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00
esp8266/tests/host/common/flash_hal_mock.cpp
david gauchard f60defc3d3
flash-size agnostic builds (#6690)
* flash: mapping definition by sketch at runtime depending on flash chip size and user configuration
2022-02-10 18:25:18 +01:00

39 lines
993 B
C++

/* Emulate the flash read/write HAL */
#include <stdint.h>
#include <string.h>
#include "flash_hal.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;
}