lfs_rambd.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef LFS_RAMBD_TRACE
  18. #ifdef LFS_RAMBD_YES_TRACE
  19. #define LFS_RAMBD_TRACE(...) LFS_TRACE(__VA_ARGS__)
  20. #else
  21. #define LFS_RAMBD_TRACE(...)
  22. #endif
  23. #endif
  24. // rambd config (optional)
  25. struct lfs_rambd_config {
  26. // Optional statically allocated buffer for the block device.
  27. void *buffer;
  28. };
  29. // rambd state
  30. typedef struct lfs_rambd {
  31. uint8_t *buffer;
  32. const struct lfs_rambd_config *cfg;
  33. } lfs_rambd_t;
  34. // Create a RAM block device using the geometry in lfs_config
  35. int lfs_rambd_create(const struct lfs_config *cfg);
  36. int lfs_rambd_createcfg(const struct lfs_config *cfg,
  37. const struct lfs_rambd_config *bdcfg);
  38. // Clean up memory associated with block device
  39. int lfs_rambd_destroy(const struct lfs_config *cfg);
  40. // Read a block
  41. int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block,
  42. lfs_off_t off, void *buffer, lfs_size_t size);
  43. // Program a block
  44. //
  45. // The block must have previously been erased.
  46. int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block,
  47. lfs_off_t off, const void *buffer, lfs_size_t size);
  48. // Erase a block
  49. //
  50. // A block must be erased before being programmed. The
  51. // state of an erased block is undefined.
  52. int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block);
  53. // Sync the block device
  54. int lfs_rambd_sync(const struct lfs_config *cfg);
  55. #ifdef __cplusplus
  56. } /* extern "C" */
  57. #endif
  58. #endif