wear_leveling.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2022 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <stdint.h>
  5. #include <stdlib.h>
  6. /**
  7. * @typedef Status returned from any wear-leveling API.
  8. */
  9. typedef enum wear_leveling_status_t {
  10. WEAR_LEVELING_FAILED, //< Invocation failed
  11. WEAR_LEVELING_SUCCESS, //< Invocation succeeded
  12. WEAR_LEVELING_CONSOLIDATED //< Invocation succeeded, consolidation occurred
  13. } wear_leveling_status_t;
  14. /**
  15. * Wear-leveling initialization
  16. *
  17. * @return Status of the request
  18. */
  19. wear_leveling_status_t wear_leveling_init(void);
  20. /**
  21. * Wear-leveling erasure.
  22. *
  23. * Clears the wear-leveling area, with the definition that the "reset state" of all data is zero.
  24. *
  25. * @return Status of the request
  26. */
  27. wear_leveling_status_t wear_leveling_erase(void);
  28. /**
  29. * Writes logical data into the backing store.
  30. *
  31. * Skips writes if there are no changes to written values. The entire written block is considered when attempting to
  32. * determine if an overwrite should occur -- if there is any data mismatch the entire block will be written to the log,
  33. * not just the changed bytes.
  34. *
  35. * @param address[in] the logical address to write data
  36. * @param value[in] pointer to the source buffer
  37. * @param length[in] length of the data
  38. * @return Status of the request
  39. */
  40. wear_leveling_status_t wear_leveling_write(uint32_t address, const void* value, size_t length);
  41. /**
  42. * Reads logical data from the cache.
  43. *
  44. * @param address[in] the logical address to read data
  45. * @param value[out] pointer to the destination buffer
  46. * @param length[in] length of the data
  47. * @return Status of the request
  48. */
  49. wear_leveling_status_t wear_leveling_read(uint32_t address, void* value, size_t length);