spi_flash: change pointer type to void*

pull/65/head
Ivan Grokhotkov 2016-10-27 00:46:33 +08:00
rodzic e03b45eb0a
commit 9f0f05d520
6 zmienionych plików z 25 dodań i 25 usunięć

Wyświetl plik

@ -37,7 +37,7 @@ esp_err_t Page::load(uint32_t sectorNumber)
mErasedEntryCount = 0; mErasedEntryCount = 0;
Header header; Header header;
auto rc = spi_flash_read(mBaseAddress, reinterpret_cast<uint8_t*>(&header), sizeof(header)); auto rc = spi_flash_read(mBaseAddress, &header, sizeof(header));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -48,7 +48,7 @@ esp_err_t Page::load(uint32_t sectorNumber)
// reading the whole page takes ~40 times less than erasing it // reading the whole page takes ~40 times less than erasing it
uint32_t line[8]; uint32_t line[8];
for (uint32_t i = 0; i < SPI_FLASH_SEC_SIZE; i += sizeof(line)) { for (uint32_t i = 0; i < SPI_FLASH_SEC_SIZE; i += sizeof(line)) {
rc = spi_flash_read(mBaseAddress + i, reinterpret_cast<uint8_t*>(line), sizeof(line)); rc = spi_flash_read(mBaseAddress + i, line, sizeof(line));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -86,7 +86,7 @@ esp_err_t Page::load(uint32_t sectorNumber)
esp_err_t Page::writeEntry(const Item& item) esp_err_t Page::writeEntry(const Item& item)
{ {
auto rc = spi_flash_write(getEntryAddress(mNextFreeEntry), reinterpret_cast<const uint8_t*>(&item), sizeof(item)); auto rc = spi_flash_write(getEntryAddress(mNextFreeEntry), &item, sizeof(item));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -396,7 +396,7 @@ esp_err_t Page::mLoadEntryTable()
if (mState == PageState::ACTIVE || if (mState == PageState::ACTIVE ||
mState == PageState::FULL || mState == PageState::FULL ||
mState == PageState::FREEING) { mState == PageState::FREEING) {
auto rc = spi_flash_read(mBaseAddress + ENTRY_TABLE_OFFSET, reinterpret_cast<uint8_t*>(mEntryTable.data()), auto rc = spi_flash_read(mBaseAddress + ENTRY_TABLE_OFFSET, mEntryTable.data(),
mEntryTable.byteSize()); mEntryTable.byteSize());
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
@ -435,7 +435,7 @@ esp_err_t Page::mLoadEntryTable()
while (mNextFreeEntry < ENTRY_COUNT) { while (mNextFreeEntry < ENTRY_COUNT) {
uint32_t entryAddress = getEntryAddress(mNextFreeEntry); uint32_t entryAddress = getEntryAddress(mNextFreeEntry);
uint32_t header; uint32_t header;
auto rc = spi_flash_read(entryAddress, reinterpret_cast<uint8_t*>(&header), sizeof(header)); auto rc = spi_flash_read(entryAddress, &header, sizeof(header));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -559,7 +559,7 @@ esp_err_t Page::initialize()
header.mSeqNumber = mSeqNumber; header.mSeqNumber = mSeqNumber;
header.mCrc32 = header.calculateCrc32(); header.mCrc32 = header.calculateCrc32();
auto rc = spi_flash_write(mBaseAddress, reinterpret_cast<const uint8_t*>(&header), sizeof(header)); auto rc = spi_flash_write(mBaseAddress, &header, sizeof(header));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -578,7 +578,7 @@ esp_err_t Page::alterEntryState(size_t index, EntryState state)
size_t wordToWrite = mEntryTable.getWordIndex(index); size_t wordToWrite = mEntryTable.getWordIndex(index);
uint32_t word = mEntryTable.data()[wordToWrite]; uint32_t word = mEntryTable.data()[wordToWrite];
auto rc = spi_flash_write(mBaseAddress + ENTRY_TABLE_OFFSET + static_cast<uint32_t>(wordToWrite) * 4, auto rc = spi_flash_write(mBaseAddress + ENTRY_TABLE_OFFSET + static_cast<uint32_t>(wordToWrite) * 4,
reinterpret_cast<uint8_t*>(&word), sizeof(word)); &word, sizeof(word));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -602,7 +602,7 @@ esp_err_t Page::alterEntryRangeState(size_t begin, size_t end, EntryState state)
if (nextWordIndex != wordIndex) { if (nextWordIndex != wordIndex) {
uint32_t word = mEntryTable.data()[wordIndex]; uint32_t word = mEntryTable.data()[wordIndex];
auto rc = spi_flash_write(mBaseAddress + ENTRY_TABLE_OFFSET + static_cast<uint32_t>(wordIndex) * 4, auto rc = spi_flash_write(mBaseAddress + ENTRY_TABLE_OFFSET + static_cast<uint32_t>(wordIndex) * 4,
reinterpret_cast<const uint8_t*>(&word), 4); &word, 4);
if (rc != ESP_OK) { if (rc != ESP_OK) {
return rc; return rc;
} }
@ -615,7 +615,7 @@ esp_err_t Page::alterEntryRangeState(size_t begin, size_t end, EntryState state)
esp_err_t Page::alterPageState(PageState state) esp_err_t Page::alterPageState(PageState state)
{ {
uint32_t state_val = static_cast<uint32_t>(state); uint32_t state_val = static_cast<uint32_t>(state);
auto rc = spi_flash_write(mBaseAddress, reinterpret_cast<const uint8_t*>(&state_val), sizeof(state)); auto rc = spi_flash_write(mBaseAddress, &state_val, sizeof(state));
if (rc != ESP_OK) { if (rc != ESP_OK) {
mState = PageState::INVALID; mState = PageState::INVALID;
return rc; return rc;
@ -626,7 +626,7 @@ esp_err_t Page::alterPageState(PageState state)
esp_err_t Page::readEntry(size_t index, Item& dst) const esp_err_t Page::readEntry(size_t index, Item& dst) const
{ {
auto rc = spi_flash_read(getEntryAddress(index), reinterpret_cast<uint8_t*>(&dst), sizeof(dst)); auto rc = spi_flash_read(getEntryAddress(index), &dst, sizeof(dst));
if (rc != ESP_OK) { if (rc != ESP_OK) {
return rc; return rc;
} }

Wyświetl plik

@ -35,7 +35,7 @@ esp_err_t spi_flash_erase_sector(size_t sec)
return ESP_OK; return ESP_OK;
} }
esp_err_t spi_flash_write(size_t des_addr, const uint8_t *src_addr, size_t size) esp_err_t spi_flash_write(size_t des_addr, const void *src_addr, size_t size)
{ {
if (!s_emulator) { if (!s_emulator) {
return ESP_ERR_FLASH_OP_TIMEOUT; return ESP_ERR_FLASH_OP_TIMEOUT;
@ -48,7 +48,7 @@ esp_err_t spi_flash_write(size_t des_addr, const uint8_t *src_addr, size_t size)
return ESP_OK; return ESP_OK;
} }
esp_err_t spi_flash_read(size_t src_addr, uint8_t *des_addr, size_t size) esp_err_t spi_flash_read(size_t src_addr, void *des_addr, size_t size)
{ {
if (!s_emulator) { if (!s_emulator) {
return ESP_ERR_FLASH_OP_TIMEOUT; return ESP_ERR_FLASH_OP_TIMEOUT;

Wyświetl plik

@ -42,9 +42,9 @@ TEST_CASE("invalid writes are checked", "[spi_flash_emu]")
SpiFlashEmulator emu(1); SpiFlashEmulator emu(1);
uint32_t val = 0; uint32_t val = 0;
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(&val), 4) == ESP_OK); CHECK(spi_flash_write(0, &val, 4) == ESP_OK);
val = 1; val = 1;
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(&val), 4) == ESP_ERR_FLASH_OP_FAIL); CHECK(spi_flash_write(0, &val, 4) == ESP_ERR_FLASH_OP_FAIL);
} }
@ -53,11 +53,11 @@ TEST_CASE("out of bounds writes fail", "[spi_flash_emu]")
SpiFlashEmulator emu(4); SpiFlashEmulator emu(4);
uint32_t vals[8]; uint32_t vals[8];
std::fill_n(vals, 8, 0); std::fill_n(vals, 8, 0);
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(vals), sizeof(vals)) == ESP_OK); CHECK(spi_flash_write(0, vals, sizeof(vals)) == ESP_OK);
CHECK(spi_flash_write(4*4096 - sizeof(vals), reinterpret_cast<const uint8_t*>(vals), sizeof(vals)) == ESP_OK); CHECK(spi_flash_write(4*4096 - sizeof(vals), vals, sizeof(vals)) == ESP_OK);
CHECK(spi_flash_write(4*4096 - sizeof(vals) + 4, reinterpret_cast<const uint8_t*>(vals), sizeof(vals)) == ESP_ERR_FLASH_OP_FAIL); CHECK(spi_flash_write(4*4096 - sizeof(vals) + 4, vals, sizeof(vals)) == ESP_ERR_FLASH_OP_FAIL);
} }
@ -65,9 +65,9 @@ TEST_CASE("after erase the sector is set to 0xff", "[spi_flash_emu]")
{ {
SpiFlashEmulator emu(4); SpiFlashEmulator emu(4);
uint32_t val1 = 0xab00cd12; uint32_t val1 = 0xab00cd12;
CHECK(spi_flash_write(0, reinterpret_cast<const uint8_t*>(&val1), sizeof(val1)) == ESP_OK); CHECK(spi_flash_write(0, &val1, sizeof(val1)) == ESP_OK);
uint32_t val2 = 0x5678efab; uint32_t val2 = 0x5678efab;
CHECK(spi_flash_write(4096 - 4, reinterpret_cast<const uint8_t*>(&val2), sizeof(val2)) == ESP_OK); CHECK(spi_flash_write(4096 - 4, &val2, sizeof(val2)) == ESP_OK);
CHECK(emu.words()[0] == val1); CHECK(emu.words()[0] == val1);
CHECK(range_empty_n(emu.words() + 1, 4096 / 4 - 2)); CHECK(range_empty_n(emu.words() + 1, 4096 / 4 - 2));

Wyświetl plik

@ -124,7 +124,7 @@ esp_err_t IRAM_ATTR spi_flash_erase_range(uint32_t start_addr, uint32_t size)
return spi_flash_translate_rc(rc); return spi_flash_translate_rc(rc);
} }
esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const uint8_t *src, size_t size) esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const void *src, size_t size)
{ {
// TODO: replace this check with code which deals with unaligned sources // TODO: replace this check with code which deals with unaligned sources
if (((ptrdiff_t) src) % 4 != 0) { if (((ptrdiff_t) src) % 4 != 0) {
@ -157,7 +157,7 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const uint8_t *src, size_t
return spi_flash_translate_rc(rc); return spi_flash_translate_rc(rc);
} }
esp_err_t IRAM_ATTR spi_flash_read(size_t src_addr, uint8_t *dest, size_t size) esp_err_t IRAM_ATTR spi_flash_read(size_t src_addr, void *dest, size_t size)
{ {
// TODO: replace this check with code which deals with unaligned destinations // TODO: replace this check with code which deals with unaligned destinations
if (((ptrdiff_t) dest) % 4 != 0) { if (((ptrdiff_t) dest) % 4 != 0) {

Wyświetl plik

@ -159,7 +159,7 @@ void esp_partition_iterator_release(esp_partition_iterator_t iterator);
* or one of error codes from lower-level flash driver. * or one of error codes from lower-level flash driver.
*/ */
esp_err_t esp_partition_read(const esp_partition_t* partition, esp_err_t esp_partition_read(const esp_partition_t* partition,
size_t src_offset, uint8_t* dst, size_t size); size_t src_offset, void* dst, size_t size);
/** /**
* @brief Write data to the partition * @brief Write data to the partition
@ -185,7 +185,7 @@ esp_err_t esp_partition_read(const esp_partition_t* partition,
* or one of error codes from lower-level flash driver. * or one of error codes from lower-level flash driver.
*/ */
esp_err_t esp_partition_write(const esp_partition_t* partition, esp_err_t esp_partition_write(const esp_partition_t* partition,
size_t dst_offset, const uint8_t* src, size_t size); size_t dst_offset, const void* src, size_t size);
/** /**
* @brief Erase part of the partition * @brief Erase part of the partition

Wyświetl plik

@ -83,7 +83,7 @@ esp_err_t spi_flash_erase_range(size_t start_addr, size_t size);
* *
* @return esp_err_t * @return esp_err_t
*/ */
esp_err_t spi_flash_write(size_t des_addr, const uint8_t *src_addr, size_t size); esp_err_t spi_flash_write(size_t dest, const void *src, size_t size);
/** /**
* @brief Read data from Flash. * @brief Read data from Flash.
@ -97,7 +97,7 @@ esp_err_t spi_flash_write(size_t des_addr, const uint8_t *src_addr, size_t size)
* *
* @return esp_err_t * @return esp_err_t
*/ */
esp_err_t spi_flash_read(size_t src_addr, uint8_t *des_addr, size_t size); esp_err_t spi_flash_read(size_t src, void *dest, size_t size);
/** /**
* @brief Enumeration which specifies memory space requested in an mmap call * @brief Enumeration which specifies memory space requested in an mmap call