FsBlockDeviceInterface.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Copyright (c) 2011-2022 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. /**
  26. * \file
  27. * \brief FsBlockDeviceInterface include file.
  28. */
  29. #ifndef FsBlockDeviceInterface_h
  30. #define FsBlockDeviceInterface_h
  31. #include <stdint.h>
  32. #include <stddef.h>
  33. /**
  34. * \class FsBlockDeviceInterface
  35. * \brief FsBlockDeviceInterface class.
  36. */
  37. class FsBlockDeviceInterface {
  38. public:
  39. virtual ~FsBlockDeviceInterface() {}
  40. /** end use of device */
  41. virtual void end() {}
  42. /**
  43. * Check for FsBlockDevice busy.
  44. *
  45. * \return true if busy else false.
  46. */
  47. virtual bool isBusy() = 0;
  48. /**
  49. * Read a sector.
  50. *
  51. * \param[in] sector Logical sector to be read.
  52. * \param[out] dst Pointer to the location that will receive the data.
  53. * \return true for success or false for failure.
  54. */
  55. virtual bool readSector(uint32_t sector, uint8_t* dst) = 0;
  56. /**
  57. * Read multiple sectors.
  58. *
  59. * \param[in] sector Logical sector to be read.
  60. * \param[in] ns Number of sectors to be read.
  61. * \param[out] dst Pointer to the location that will receive the data.
  62. * \return true for success or false for failure.
  63. */
  64. virtual bool readSectors(uint32_t sector, uint8_t* dst, size_t ns) = 0;
  65. /** \return device size in sectors. */
  66. virtual uint32_t sectorCount() = 0;
  67. /** End multi-sector transfer and go to idle state.
  68. * \return true for success or false for failure.
  69. */
  70. virtual bool syncDevice() = 0;
  71. /**
  72. * Writes a sector.
  73. *
  74. * \param[in] sector Logical sector to be written.
  75. * \param[in] src Pointer to the location of the data to be written.
  76. * \return true for success or false for failure.
  77. */
  78. virtual bool writeSector(uint32_t sector, const uint8_t* src) = 0;
  79. /**
  80. * Write multiple sectors.
  81. *
  82. * \param[in] sector Logical sector to be written.
  83. * \param[in] ns Number of sectors to be written.
  84. * \param[in] src Pointer to the location of the data to be written.
  85. * \return true for success or false for failure.
  86. */
  87. virtual bool writeSectors(uint32_t sector, const uint8_t* src, size_t ns) = 0;
  88. };
  89. #endif // FsBlockDeviceInterface_h