mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-12-15 14:13:27 +00:00
01ecf332ff
* Initial import of wear-leveling algorithm. * Alignment. * Docs tweaks. * Lock/unlock. * Update quantum/wear_leveling/wear_leveling_internal.h Co-authored-by: Stefan Kerkmann <karlk90@pm.me> * More tests, fix issue with consolidation when unlocked. * More tests. * Review comments. * Add plumbing for FNV1a. * Another test checking that checksum mismatch clears the cache. * Check that the write log still gets played back. Co-authored-by: Stefan Kerkmann <karlk90@pm.me>
55 lines
1.7 KiB
C
55 lines
1.7 KiB
C
// Copyright 2022 Nick Brassel (@tzarc)
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
/**
|
|
* @typedef Status returned from any wear-leveling API.
|
|
*/
|
|
typedef enum wear_leveling_status_t {
|
|
WEAR_LEVELING_FAILED, //< Invocation failed
|
|
WEAR_LEVELING_SUCCESS, //< Invocation succeeded
|
|
WEAR_LEVELING_CONSOLIDATED //< Invocation succeeded, consolidation occurred
|
|
} wear_leveling_status_t;
|
|
|
|
/**
|
|
* Wear-leveling initialization
|
|
*
|
|
* @return Status of the request
|
|
*/
|
|
wear_leveling_status_t wear_leveling_init(void);
|
|
|
|
/**
|
|
* Wear-leveling erasure.
|
|
*
|
|
* Clears the wear-leveling area, with the definition that the "reset state" of all data is zero.
|
|
*
|
|
* @return Status of the request
|
|
*/
|
|
wear_leveling_status_t wear_leveling_erase(void);
|
|
|
|
/**
|
|
* Writes logical data into the backing store.
|
|
*
|
|
* Skips writes if there are no changes to written values. The entire written block is considered when attempting to
|
|
* determine if an overwrite should occur -- if there is any data mismatch the entire block will be written to the log,
|
|
* not just the changed bytes.
|
|
*
|
|
* @param address[in] the logical address to write data
|
|
* @param value[in] pointer to the source buffer
|
|
* @param length[in] length of the data
|
|
* @return Status of the request
|
|
*/
|
|
wear_leveling_status_t wear_leveling_write(uint32_t address, const void* value, size_t length);
|
|
|
|
/**
|
|
* Reads logical data from the cache.
|
|
*
|
|
* @param address[in] the logical address to read data
|
|
* @param value[out] pointer to the destination buffer
|
|
* @param length[in] length of the data
|
|
* @return Status of the request
|
|
*/
|
|
wear_leveling_status_t wear_leveling_read(uint32_t address, void* value, size_t length);
|