-
-
Notifications
You must be signed in to change notification settings - Fork 40.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022 Nick Brassel (@tzarc) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#include <stdbool.h> | ||
#include <hal.h> | ||
#include "timer.h" | ||
#include "wear_leveling.h" | ||
#include "wear_leveling_internal.h" | ||
|
||
bool backing_store_init(void) { | ||
bs_dprintf("Init\n"); | ||
flash_init(); | ||
return true; | ||
} | ||
|
||
bool backing_store_unlock(void) { | ||
bs_dprintf("Unlock\n"); | ||
// No-op -- handled by the flash driver as it is. | ||
return true; | ||
} | ||
|
||
bool backing_store_erase(void) { | ||
#ifdef WEAR_LEVELING_DEBUG_OUTPUT | ||
uint32_t start = timer_read32(); | ||
#endif | ||
|
||
bool ret = true; | ||
for (int i = 0; i < (WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_COUNT); ++i) { | ||
flash_status_t status = flash_erase_block(((WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_OFFSET) + i) * (EXTERNAL_FLASH_BLOCK_SIZE)); | ||
if (status != FLASH_STATUS_SUCCESS) { | ||
ret = false; | ||
break; | ||
} | ||
} | ||
|
||
bs_dprintf("Backing store erase took %ldms to complete\n", ((long)(timer_read32() - start))); | ||
return ret; | ||
} | ||
|
||
bool backing_store_write(uint32_t address, backing_store_int_t value) { | ||
bs_dprintf("Write "); | ||
uint32_t offset = (WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_OFFSET) * (EXTERNAL_FLASH_BLOCK_SIZE) + address; | ||
wl_dump(offset, &value, sizeof(value)); | ||
value = ~value; | ||
return flash_write_block(offset, &value, sizeof(value)) == FLASH_STATUS_SUCCESS; | ||
} | ||
|
||
bool backing_store_lock(void) { | ||
bs_dprintf("Lock \n"); | ||
// No-op -- handled by the flash driver as it is. | ||
return true; | ||
} | ||
|
||
bool backing_store_read(uint32_t address, backing_store_int_t *value) { | ||
bs_dprintf("Read "); | ||
uint32_t offset = (WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_OFFSET) * (EXTERNAL_FLASH_BLOCK_SIZE) + address; | ||
flash_status_t status = flash_read_block(offset, value, sizeof(backing_store_int_t)); | ||
*value = ~(*value); | ||
wl_dump(offset, value, sizeof(backing_store_int_t)); | ||
return status == FLASH_STATUS_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 Nick Brassel (@tzarc) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#ifndef __ASSEMBLER__ | ||
# include <stdlib.h> | ||
# include <stdint.h> | ||
# include "flash_spi.h" | ||
#endif | ||
|
||
// Use 1 block -- check the config for the SPI flash to determine how big it is | ||
#ifndef WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_COUNT | ||
# define WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_COUNT 1 | ||
#endif // WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_COUNT | ||
|
||
// Start at the first block of the external flash | ||
#ifndef WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_OFFSET | ||
# define WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_OFFSET 0 | ||
#endif // WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_OFFSET | ||
|
||
// 8-byte writes by default | ||
#ifndef BACKING_STORE_WRITE_SIZE | ||
# define BACKING_STORE_WRITE_SIZE 8 | ||
#endif | ||
|
||
// The space allocated by the block | ||
#ifndef WEAR_LEVELING_BACKING_SIZE | ||
# define WEAR_LEVELING_BACKING_SIZE ((EXTERNAL_FLASH_BLOCK_SIZE) * (WEAR_LEVELING_EXTERNAL_FLASH_BLOCK_COUNT)) | ||
#endif // WEAR_LEVELING_BACKING_SIZE | ||
|
||
// Use half of the backing size for logical EEPROM | ||
#ifndef WEAR_LEVELING_LOGICAL_SIZE | ||
# define WEAR_LEVELING_LOGICAL_SIZE ((WEAR_LEVELING_BACKING_SIZE) / 2) | ||
#endif // WEAR_LEVELING_LOGICAL_SIZE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters