sfud.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * get flash device by its index which in the flash information table
  43. *
  44. * @param index the index which in the flash information table @see flash_table
  45. *
  46. * @return flash device
  47. */
  48. sfud_flash *sfud_get_device(size_t index);
  49. /**
  50. * get flash device total number on flash device information table @see flash_table
  51. *
  52. * @return flash device total number
  53. */
  54. size_t sfud_get_device_num(void);
  55. /**
  56. * get flash device information table @see flash_table
  57. *
  58. * @return flash device table pointer
  59. */
  60. const sfud_flash *sfud_get_device_table(void);
  61. /**
  62. * read flash data
  63. *
  64. * @param flash flash device
  65. * @param addr start address
  66. * @param size read size
  67. * @param data read data pointer
  68. *
  69. * @return result
  70. */
  71. sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data);
  72. /**
  73. * erase flash data
  74. *
  75. * @note It will erase align by erase granularity.
  76. *
  77. * @param flash flash device
  78. * @param addr start address
  79. * @param size erase size
  80. *
  81. * @return result
  82. */
  83. sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size);
  84. /**
  85. * write flash data (no erase operate)
  86. *
  87. * @param flash flash device
  88. * @param addr start address
  89. * @param data write data
  90. * @param size write size
  91. *
  92. * @return result
  93. */
  94. sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  95. /**
  96. * erase and write flash data
  97. *
  98. * @param flash flash device
  99. * @param addr start address
  100. * @param size write size
  101. * @param data write data
  102. *
  103. * @return result
  104. */
  105. sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  106. /**
  107. * erase all flash data
  108. *
  109. * @param flash flash device
  110. *
  111. * @return result
  112. */
  113. sfud_err sfud_chip_erase(const sfud_flash *flash);
  114. /**
  115. * read flash register status
  116. *
  117. * @param flash flash device
  118. * @param status register status
  119. *
  120. * @return result
  121. */
  122. sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status);
  123. /**
  124. * write status register
  125. *
  126. * @param flash flash device
  127. * @param is_volatile true: volatile mode, false: non-volatile mode
  128. * @param status register status
  129. *
  130. * @return result
  131. */
  132. sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status);
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif /* _SFUD_H_ */