sfud.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * This file is part of the Serial Flash Universal Driver Library.
  3. *
  4. * Copyright (c) 2016-2018, Armink, <armink.ztl@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * 'Software'), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Function: It is an head file for this library. You can see all of the functions which can be called by user.
  26. * Created on: 2016-04-23
  27. */
  28. #ifndef _SFUD_H_
  29. #define _SFUD_H_
  30. #include "sfud_def.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* ../src/sfup.c */
  35. /**
  36. * SFUD library initialize.
  37. *
  38. * @return result
  39. */
  40. sfud_err sfud_init(void);
  41. /**
  42. * SFUD initialize by flash device
  43. *
  44. * @param flash flash device
  45. *
  46. * @return result
  47. */
  48. sfud_err sfud_device_init(sfud_flash *flash);
  49. /**
  50. * get flash device by its index which in the flash information table
  51. *
  52. * @param index the index which in the flash information table @see flash_table
  53. *
  54. * @return flash device
  55. */
  56. sfud_flash *sfud_get_device(size_t index);
  57. /**
  58. * get flash device total number on flash device information table @see flash_table
  59. *
  60. * @return flash device total number
  61. */
  62. size_t sfud_get_device_num(void);
  63. /**
  64. * get flash device information table @see flash_table
  65. *
  66. * @return flash device table pointer
  67. */
  68. const sfud_flash *sfud_get_device_table(void);
  69. #ifdef SFUD_USING_QSPI
  70. /**
  71. * Enbale the fast read mode in QSPI flash mode. Default read mode is normal SPI mode.
  72. *
  73. * it will find the appropriate fast-read instruction to replace the read instruction(0x03)
  74. * fast-read instruction @see SFUD_FLASH_EXT_INFO_TABLE
  75. *
  76. * @note When Flash is in QSPI mode, the method must be called after sfud_device_init().
  77. *
  78. * @param flash flash device
  79. * @param data_line_width the data lines max width which QSPI bus supported, such as 1, 2, 4
  80. *
  81. * @return result
  82. */
  83. sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width);
  84. #endif /* SFUD_USING_QSPI */
  85. /**
  86. * read flash data
  87. *
  88. * @param flash flash device
  89. * @param addr start address
  90. * @param size read size
  91. * @param data read data pointer
  92. *
  93. * @return result
  94. */
  95. sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data);
  96. /**
  97. * erase flash data
  98. *
  99. * @note It will erase align by erase granularity.
  100. *
  101. * @param flash flash device
  102. * @param addr start address
  103. * @param size erase size
  104. *
  105. * @return result
  106. */
  107. sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size);
  108. /**
  109. * write flash data (no erase operate)
  110. *
  111. * @param flash flash device
  112. * @param addr start address
  113. * @param data write data
  114. * @param size write size
  115. *
  116. * @return result
  117. */
  118. sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  119. /**
  120. * erase and write flash data
  121. *
  122. * @param flash flash device
  123. * @param addr start address
  124. * @param size write size
  125. * @param data write data
  126. *
  127. * @return result
  128. */
  129. sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  130. /**
  131. * erase all flash data
  132. *
  133. * @param flash flash device
  134. *
  135. * @return result
  136. */
  137. sfud_err sfud_chip_erase(const sfud_flash *flash);
  138. /**
  139. * read flash register status
  140. *
  141. * @param flash flash device
  142. * @param status register status
  143. *
  144. * @return result
  145. */
  146. sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status);
  147. /**
  148. * write status register
  149. *
  150. * @param flash flash device
  151. * @param is_volatile true: volatile mode, false: non-volatile mode
  152. * @param status register status
  153. *
  154. * @return result
  155. */
  156. sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status);
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160. #endif /* _SFUD_H_ */