sfud.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file sfud.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef _SFUD_H_
  35. #define _SFUD_H_
  36. #include "sfud_def.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /* ../src/sfup.c */
  41. /**
  42. * SFUD library initialize.
  43. *
  44. * @return result
  45. */
  46. sfud_err sfud_init(void);
  47. /**
  48. * SFUD initialize by flash device
  49. *
  50. * @param flash flash device
  51. *
  52. * @return result
  53. */
  54. sfud_err sfud_device_init(sfud_flash *flash);
  55. /**
  56. * get flash device by its index which in the flash information table
  57. *
  58. * @param index the index which in the flash information table @see flash_table
  59. *
  60. * @return flash device
  61. */
  62. sfud_flash *sfud_get_device(size_t index);
  63. /**
  64. * get flash device total number on flash device information table @see flash_table
  65. *
  66. * @return flash device total number
  67. */
  68. size_t sfud_get_device_num(void);
  69. /**
  70. * get flash device information table @see flash_table
  71. *
  72. * @return flash device table pointer
  73. */
  74. const sfud_flash *sfud_get_device_table(void);
  75. #ifdef SFUD_USING_QSPI
  76. /**
  77. * Enbale the fast read mode in QSPI flash mode. Default read mode is normal SPI mode.
  78. *
  79. * it will find the appropriate fast-read instruction to replace the read instruction(0x03)
  80. * fast-read instruction @see SFUD_FLASH_EXT_INFO_TABLE
  81. *
  82. * @note When Flash is in QSPI mode, the method must be called after sfud_device_init().
  83. *
  84. * @param flash flash device
  85. * @param data_line_width the data lines max width which QSPI bus supported, such as 1, 2, 4
  86. *
  87. * @return result
  88. */
  89. sfud_err sfud_qspi_fast_read_enable(sfud_flash *flash, uint8_t data_line_width);
  90. #endif /* SFUD_USING_QSPI */
  91. /**
  92. * read flash data
  93. *
  94. * @param flash flash device
  95. * @param addr start address
  96. * @param size read size
  97. * @param data read data pointer
  98. *
  99. * @return result
  100. */
  101. sfud_err sfud_read(const sfud_flash *flash, uint32_t addr, size_t size, uint8_t *data);
  102. /**
  103. * erase flash data
  104. *
  105. * @note It will erase align by erase granularity.
  106. *
  107. * @param flash flash device
  108. * @param addr start address
  109. * @param size erase size
  110. *
  111. * @return result
  112. */
  113. sfud_err sfud_erase(const sfud_flash *flash, uint32_t addr, size_t size);
  114. /**
  115. * write flash data (no erase operate)
  116. *
  117. * @param flash flash device
  118. * @param addr start address
  119. * @param data write data
  120. * @param size write size
  121. *
  122. * @return result
  123. */
  124. sfud_err sfud_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  125. /**
  126. * erase and write flash data
  127. *
  128. * @param flash flash device
  129. * @param addr start address
  130. * @param size write size
  131. * @param data write data
  132. *
  133. * @return result
  134. */
  135. sfud_err sfud_erase_write(const sfud_flash *flash, uint32_t addr, size_t size, const uint8_t *data);
  136. /**
  137. * erase all flash data
  138. *
  139. * @param flash flash device
  140. *
  141. * @return result
  142. */
  143. sfud_err sfud_chip_erase(const sfud_flash *flash);
  144. /**
  145. * read flash register status
  146. *
  147. * @param flash flash device
  148. * @param status register status
  149. *
  150. * @return result
  151. */
  152. sfud_err sfud_read_status(const sfud_flash *flash, uint8_t *status);
  153. /**
  154. * write status register
  155. *
  156. * @param flash flash device
  157. * @param is_volatile true: volatile mode, false: non-volatile mode
  158. * @param status register status
  159. *
  160. * @return result
  161. */
  162. sfud_err sfud_write_status(const sfud_flash *flash, bool is_volatile, uint8_t status);
  163. #ifdef __cplusplus
  164. }
  165. #endif
  166. #endif /* _SFUD_H_ */