hv_drv_Flash.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * @file hv_drv_Flash.h
  3. * @brief Header file of misc module.
  4. *
  5. * @verbatim
  6. * ==============================================================================
  7. * ##### How to use #####
  8. * ==============================================================================
  9. * (+) Use ()
  10. *
  11. * @endverbatim
  12. * @author HiView SoC Software Team
  13. * @version 1.0.0
  14. * @date 2023-05-11
  15. */
  16. #ifndef _HV_DRV_FLASH_H
  17. #define _HV_DRV_FLASH_H
  18. typedef enum _FlashAddressWidth
  19. {
  20. FLASH_ADDRESS_WIDTH_24 = 24,
  21. FLASH_ADDRESS_WIDTH_32 = 32,
  22. } FlashAddressWidth;
  23. typedef enum FlashRateMode
  24. {
  25. FLASH_STANDARD = 0,
  26. FLASH_DUAL,
  27. FLASH_QUAD,
  28. FLASH_4XIO,
  29. FLASH_QPI,
  30. } FlashRateMode;
  31. typedef enum _FlashMultiIOType
  32. {
  33. /*!< In Dual and quad mode, instruction and address send by one line*/
  34. FLASH_MULTIIO_FAST_TYPE = 0,
  35. /*!< instruction and address send by 4 line */
  36. FLASH_INSTRUCT_ADDR_4LINE,
  37. FLASH_ADDR_4LINE,
  38. } FlashMultiIOType;
  39. typedef enum _FlashWorkModeSel
  40. {
  41. FLASH_USE_POLLING = 0,
  42. FLASH_USE_INT,
  43. FLASH_USE_DMA,
  44. } FlashWorkModeSel;
  45. typedef enum _FlashDataWidth
  46. {
  47. /*! <The DataSize for transmition is 8bits */
  48. FLASH_DATAWIDTH_8 = 8,
  49. /*!< The DataSize for transmition is 16bits */
  50. FLASH_DATAWIDTH_16 = 16,
  51. /*!< The DataSize for transmition is 32bits */
  52. FLASH_DATAWIDTH_32 = 32,
  53. } FlashDataWidth;
  54. typedef enum _FlashEraseType
  55. {
  56. FLASH_ERASE_SECTOR = 0,
  57. FLASH_ERASE_MULTI_SECTOR,
  58. FLASH_ERASE_CHIP
  59. } FlashEraseType;
  60. typedef enum _FlashTransRW
  61. {
  62. FLASH_WRITE = 0,
  63. FLASH_READ,
  64. } FlashTransRW;
  65. typedef enum _FlashCSSel
  66. {
  67. FLASH_CS_HARDWARE_SELF = 0,
  68. FLASH_CS_BY_GPIO,
  69. } FlashCSSel;
  70. typedef struct _FlashTxMem
  71. {
  72. UCHAR8 cmdAddr[20];
  73. UCHAR8 txData[256];
  74. } FlashTxMem;
  75. typedef Status (*Flash_CpltCallback)(FlashTransRW transType, void *arg);
  76. typedef struct _FlashInitParam
  77. {
  78. /*!< Specifies flash adress is 24 or 32 bits */
  79. FlashAddressWidth AddrWidth;
  80. FlashWorkModeSel WorkModeSel;
  81. FlashRateMode RateMode;
  82. /*!< Specifies the SPI data size. */
  83. FlashDataWidth DataSize;
  84. FlashMultiIOType TransType;
  85. Flash_CpltCallback FlashCpltCallback;
  86. FlashModel FlashModel;
  87. FlashCSSel CsSel;
  88. void* FlashCallback;
  89. }FlashInitParam;
  90. typedef struct _FlashSelf FlashSelf;
  91. /** @defgroup flash flash
  92. * flash rd/rw functions
  93. * @{
  94. */
  95. /**
  96. * @brief write pm data to flash.
  97. * @param uiAddress write offset at flash
  98. * @param pucData address write data to
  99. * @param uiDataSize write data size
  100. * @retval Status
  101. */
  102. Status Hv_Drv_Flash_WritePMConfigData(UINT32 uiIndex, UINT32 uiData);
  103. /**
  104. * @brief write data to flash.
  105. * @param uiAddress write offset at flash. only support monitordata partition
  106. * @param pucData address write data to
  107. * @param uiDataSize write data size
  108. * @retval Status
  109. */
  110. Status Hv_Drv_Flash_WriteMonitorData(UINT32 uiAddress, UCHAR8 *pucData, UINT32 uiDataSize);
  111. /**
  112. * @brief read data from flash in xip mode.
  113. * @param uiAddress read offset at flash
  114. * @param pucData address for read data
  115. * @param uiDataSize size to read data
  116. * @retval Status
  117. */
  118. Status Hv_Drv_Flash_ReadXIP(UINT32 uiAddress, UCHAR8 *pucData, UINT32 uiDataSize);
  119. /**
  120. * @brief read data from flash.
  121. * @param uiAddress read offset at flash. only support monitordata partition
  122. * @param pucData address for read data
  123. * @param uiDataSize size to read data
  124. * @retval Status
  125. */
  126. Status Hv_Drv_Flash_ReadMonitorData(UINT32 uiAddress, UCHAR8 *pucData, UINT32 uiDataSize);
  127. /**
  128. * @brief int flash interface.
  129. */
  130. void Hv_Drv_Flash_SetQspiMode(FlashModel FlashModel, FlashRateMode RateMode, FlashWorkModeSel workMode);
  131. /**
  132. * @brief deint flash interface.
  133. */
  134. void Hv_Drv_Flash_SetXipMode(void);
  135. /**
  136. * @brief config logo data and pq etc data partition flag
  137. */
  138. void Hv_Drv_Flash_ConfigPartFlag(void);
  139. /**
  140. * @brief erase flash.
  141. * @param[in] uiWriteAddr Address of flash to do erase.
  142. * @param[in] uiLength Date length to be written.
  143. * @return None
  144. */
  145. void Hv_Drv_Flash_OnlyErase(UINT32 uiReadAddr, UINT32 uiLength);
  146. /**
  147. * @brief Erase flash by a 64K Bytes(Multi Sector) length.
  148. Warning: Always erase 64K bytes, please be sure to keep your data safe.
  149. * @param[in] uiAddr Address of flash to do erase.
  150. * @return None
  151. */
  152. void Hv_Drv_Flash_OnlyEraseMultiSector(UINT32 uiAddr);
  153. /**
  154. * @brief Write flash.
  155. * @param[in] uiWriteAddr Address of flash to do write.
  156. * @param[in] pucWriteBuf Date buffer to be written.
  157. * @param[in] uiLength Date length to be written.
  158. * @return Status
  159. */
  160. Status Hv_Drv_Flash_OnlyWrite(UINT32 uiWriteAddr, UCHAR8 *pucWriteBuf, UINT32 uiLength);
  161. /**
  162. * @brief Write flash.
  163. * @param[in] uiReadAddr Address of flash to do read.
  164. * @param[in] pucReadBuf Buffer for saving read back data.
  165. * @param[in] uiLength Date length to be read.
  166. * @return None
  167. */
  168. void Hv_Drv_Flash_OnlyRead(UINT32 uiReadAddr, UCHAR8* pucReadBuf, UINT32 uiLength);
  169. /**
  170. * @brief whether w/r is ongoing.
  171. * @return w/r state
  172. */
  173. UCHAR8 Hv_Drv_Flash_InWritting(void);
  174. /**
  175. * @brief Flash chip erase.
  176. * @param[in] None.
  177. * @return None
  178. */
  179. void Hv_Drv_Flash_EraseChip(void);
  180. /** @} */
  181. #endif