sfud.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * This file is part of the Serial Flash Universal Driver Library.
  3. *
  4. * Copyright (c) 2016, 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. /**
  70. * read flash data
  71. *
  72. * @param flash flash device
  73. * @param addr start address
  74. * @param size read size
  75. * @param data read data pointer
  76. *
  77. * @return result
  78. */
  79. sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data);
  80. /**
  81. * erase flash data
  82. *
  83. * @note It will erase align by erase granularity.
  84. *
  85. * @param flash flash device
  86. * @param addr start address
  87. * @param size erase size
  88. *
  89. * @return result
  90. */
  91. sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size);
  92. /**
  93. * write flash data (no erase operate)
  94. *
  95. * @param flash flash device
  96. * @param addr start address
  97. * @param data write data
  98. * @param size write size
  99. *
  100. * @return result
  101. */
  102. sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  103. /**
  104. * erase and write flash data
  105. *
  106. * @param flash flash device
  107. * @param addr start address
  108. * @param size write size
  109. * @param data write data
  110. *
  111. * @return result
  112. */
  113. sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  114. /**
  115. * erase all flash data
  116. *
  117. * @param flash flash device
  118. *
  119. * @return result
  120. */
  121. sfud_err sfud_chip_erase(const sfud_flash *flash);
  122. /**
  123. * read flash register status
  124. *
  125. * @param flash flash device
  126. * @param status register status
  127. *
  128. * @return result
  129. */
  130. sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status);
  131. /**
  132. * write status register
  133. *
  134. * @param flash flash device
  135. * @param is_volatile true: volatile mode, false: non-volatile mode
  136. * @param status register status
  137. *
  138. * @return result
  139. */
  140. sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* _SFUD_H_ */