lfs_rambd.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Block device emulated in RAM
  3. *
  4. * Copyright (c) 2022, The littlefs authors.
  5. * Copyright (c) 2017, Arm Limited. All rights reserved.
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef LFS_RAMBD_H
  9. #define LFS_RAMBD_H
  10. #include "lfs.h"
  11. #include "lfs_util.h"
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. // Block device specific tracing
  17. #ifdef LFS_RAMBD_YES_TRACE
  18. #define LFS_RAMBD_TRACE(...) LFS_TRACE(__VA_ARGS__)
  19. #else
  20. #define LFS_RAMBD_TRACE(...)
  21. #endif
  22. // rambd config (optional)
  23. struct lfs_rambd_config {
  24. // 8-bit erase value to simulate erasing with. -1 indicates no erase
  25. // occurs, which is still a valid block device
  26. int32_t erase_value;
  27. // Optional statically allocated buffer for the block device.
  28. void *buffer;
  29. };
  30. // rambd state
  31. typedef struct lfs_rambd {
  32. uint8_t *buffer;
  33. const struct lfs_rambd_config *cfg;
  34. } lfs_rambd_t;
  35. // Create a RAM block device using the geometry in lfs_config
  36. int lfs_rambd_create(const struct lfs_config *cfg);
  37. int lfs_rambd_createcfg(const struct lfs_config *cfg,
  38. const struct lfs_rambd_config *bdcfg);
  39. // Clean up memory associated with block device
  40. int lfs_rambd_destroy(const struct lfs_config *cfg);
  41. // Read a block
  42. int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block,
  43. lfs_off_t off, void *buffer, lfs_size_t size);
  44. // Program a block
  45. //
  46. // The block must have previously been erased.
  47. int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block,
  48. lfs_off_t off, const void *buffer, lfs_size_t size);
  49. // Erase a block
  50. //
  51. // A block must be erased before being programmed. The
  52. // state of an erased block is undefined.
  53. int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block);
  54. // Sync the block device
  55. int lfs_rambd_sync(const struct lfs_config *cfg);
  56. #ifdef __cplusplus
  57. } /* extern "C" */
  58. #endif
  59. #endif