block_device.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _BLOCK_DEVICE_H_
  13. #define _BLOCK_DEVICE_H_
  14. #include <stdint.h>
  15. #include <stddef.h>
  16. #include "quec_proj_config.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef struct blockDevice blockDevice_t;
  21. typedef struct
  22. {
  23. unsigned read_block_count;
  24. unsigned write_block_count;
  25. unsigned erase_block_count;
  26. unsigned min_erase_count;
  27. unsigned max_erase_count;
  28. } blockDeviceStat_t;
  29. typedef struct
  30. {
  31. int (*read)(blockDevice_t *dev, uint64_t nr, int count, void *buf);
  32. int (*write)(blockDevice_t *dev, uint64_t nr, int count, const void *data);
  33. int (*erase)(blockDevice_t *dev, uint64_t nr, int count);
  34. void (*stat)(blockDevice_t *dev, blockDeviceStat_t *stat);
  35. void (*destroy)(blockDevice_t *dev);
  36. } blockDeviceOps_t;
  37. struct blockDevice
  38. {
  39. blockDeviceOps_t ops;
  40. size_t block_size;
  41. uint64_t block_count;
  42. #ifdef CONFIG_QUEC_PROJECT_FEATURE
  43. uint8_t block_device_type;
  44. uint8_t part_num;
  45. #endif
  46. void *priv;
  47. uint32_t typeid;
  48. };
  49. int blockDeviceRead(blockDevice_t *dev, uint64_t nr, int count, void *buf);
  50. int blockDeviceWrite(blockDevice_t *dev, uint64_t nr, int count, const void *data);
  51. int blockDeviceErase(blockDevice_t *dev, uint64_t nr, int count);
  52. void blockDeviceStat(blockDevice_t *dev, blockDeviceStat_t *stat);
  53. void blockDeviceDestroy(blockDevice_t *dev);
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif