serialflash.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _DEV_SERIALFLASH_H_
  2. #define _DEV_SERIALFLASH_H_
  3. /*
  4. * Copyright (C) 2010 by egnite GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. */
  36. #include <dev/spibus.h>
  37. /*!
  38. * \addtogroup xgSerialflash
  39. */
  40. /*@{*/
  41. /*! \brief Max. number of pages. */
  42. #ifndef SERIALFLASH_MAX_UNITS
  43. #if defined(__AVR__)
  44. #define SERIALFLASH_MAX_UNITS 65535
  45. #else
  46. #define SERIALFLASH_MAX_UNITS 65536
  47. #endif
  48. #endif
  49. #if SERIALFLASH_MAX_UNITS <= 65535
  50. typedef uint16_t sf_unit_t;
  51. typedef uint_fast16_t sf_unit_fast_t;
  52. #else
  53. typedef uint32_t sf_unit_t;
  54. typedef uint_fast32_t sf_unit_fast_t;
  55. #endif
  56. /*!
  57. * \brief Serial flash support information structure type.
  58. */
  59. typedef struct _NUTSERIALFLASH NUTSERIALFLASH;
  60. /*!
  61. * \brief Serial flash support information structure.
  62. */
  63. struct _NUTSERIALFLASH {
  64. /*! \brief Pointer to the SPI node structure. */
  65. NUTSPINODE *sf_node;
  66. /*! \brief Pointer to a local information structure. */
  67. void *sf_info;
  68. /*! \brief Size of the erase/write unit. */
  69. size_t sf_unit_size;
  70. /*! \brief Total number of units available, including reserved ones. */
  71. sf_unit_t sf_units;
  72. /*! \brief Configurable number of reserved units at the bottom. */
  73. sf_unit_t sf_rsvbot;
  74. /*! \brief Configurable number of reserved units at the top. */
  75. sf_unit_t sf_rsvtop;
  76. /*! \brief Flash device initialization. */
  77. int (*sf_init) (NUTSERIALFLASH *);
  78. /*! \brief Release the flash device. */
  79. void (*sf_exit) (NUTSERIALFLASH *);
  80. /*! \brief Check a number of units. */
  81. int (*sf_check) (NUTSERIALFLASH *, sf_unit_t, int);
  82. /*! \brief Read bytes from a unit. */
  83. int (*sf_read) (NUTSERIALFLASH *, sf_unit_t, int, void *, int);
  84. /*! \brief Compare bytes of a unit. */
  85. int (*sf_compare) (NUTSERIALFLASH *, sf_unit_t, int, const void *, int);
  86. /*! \brief Find first used byte. */
  87. int (*sf_used) (NUTSERIALFLASH *, sf_unit_t, int);
  88. /*! \brief Write bytes from a unit. */
  89. int (*sf_write) (NUTSERIALFLASH *, sf_unit_t, int, const void *, int);
  90. /*! \brief Copy a unit. */
  91. int (*sf_copy) (NUTSERIALFLASH *, sf_unit_t, sf_unit_t);
  92. /*! \brief Commit changes. */
  93. int (*sf_commit) (NUTSERIALFLASH *, sf_unit_t);
  94. /*! \brief Erase a number of units. */
  95. int (*sf_erase) (NUTSERIALFLASH *, sf_unit_t, int);
  96. };
  97. /*@}*/
  98. #endif