Qspi_Ip.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : FTFC_FLS_IP IPV_QSPI
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. #ifndef QSPI_IP_H
  25. #define QSPI_IP_H
  26. /**
  27. * @file Qspi_Ip.h
  28. *
  29. * @addtogroup IPV_QSPI QSPI IPV Driver
  30. * @{
  31. */
  32. /* implements Qspi_Ip.h_Artifact */
  33. #ifdef __cplusplus
  34. extern "C"{
  35. #endif
  36. #include "StandardTypes.h"
  37. #include "Qspi_Ip_Types.h"
  38. #include "Qspi_Ip_Features.h"
  39. /*==================================================================================================
  40. * SOURCE FILE VERSION INFORMATION
  41. ==================================================================================================*/
  42. #define QSPI_IP_VENDOR_ID_H 43
  43. #define QSPI_IP_AR_RELEASE_MAJOR_VERSION_H 4
  44. #define QSPI_IP_AR_RELEASE_MINOR_VERSION_H 4
  45. #define QSPI_IP_AR_RELEASE_REVISION_VERSION_H 0
  46. #define QSPI_IP_SW_MAJOR_VERSION_H 1
  47. #define QSPI_IP_SW_MINOR_VERSION_H 0
  48. #define QSPI_IP_SW_PATCH_VERSION_H 0
  49. /*==================================================================================================
  50. * FILE VERSION CHECKS
  51. ==================================================================================================*/
  52. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  53. /* Check if Qspi_Ip header file and StandardTypes.h header file are of the same Autosar version */
  54. #if ((QSPI_IP_AR_RELEASE_MAJOR_VERSION_H != STD_AR_RELEASE_MAJOR_VERSION) || \
  55. (QSPI_IP_AR_RELEASE_MINOR_VERSION_H != STD_AR_RELEASE_MINOR_VERSION) \
  56. )
  57. #error "Autosar Version Numbers of Qspi_Ip.h and StandardTypes.h are different"
  58. #endif
  59. #endif
  60. /* Check if current file and Qspi_Ip_Types header file are of the same vendor */
  61. #if (FLS_QSPI_TYPES_VENDOR_ID != QSPI_IP_VENDOR_ID_H)
  62. #error "Qspi_Ip.h and Qspi_Ip_Types.h have different vendor ids"
  63. #endif
  64. /* Check if current file and Qspi_Ip_Types header file are of the same Autosar version */
  65. #if ((FLS_QSPI_TYPES_AR_RELEASE_MAJOR_VERSION != QSPI_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  66. (FLS_QSPI_TYPES_AR_RELEASE_MINOR_VERSION != QSPI_IP_AR_RELEASE_MINOR_VERSION_H) || \
  67. (FLS_QSPI_TYPES_AR_RELEASE_REVISION_VERSION != QSPI_IP_AR_RELEASE_REVISION_VERSION_H) \
  68. )
  69. #error "AutoSar Version Numbers of Qspi_Ip.h and Qspi_Ip_Types.h are different"
  70. #endif
  71. /* Check if current file and Qspi_Ip_Types header file are of the same Software version */
  72. #if ((FLS_QSPI_TYPES_SW_MAJOR_VERSION != QSPI_IP_SW_MAJOR_VERSION_H) || \
  73. (FLS_QSPI_TYPES_SW_MINOR_VERSION != QSPI_IP_SW_MINOR_VERSION_H) || \
  74. (FLS_QSPI_TYPES_SW_PATCH_VERSION != QSPI_IP_SW_PATCH_VERSION_H) \
  75. )
  76. #error "Software Version Numbers of Qspi_Ip.h and Qspi_Ip_Types.h are different"
  77. #endif
  78. /* Check if current file and Qspi_Ip_Features header file are of the same vendor */
  79. #if (QSPI_IP_FEATURES_VENDOR_ID_CFG != QSPI_IP_VENDOR_ID_H)
  80. #error "Qspi_Ip.h and Qspi_Ip_Features.h have different vendor ids"
  81. #endif
  82. /* Check if current file and Qspi_Ip_Features header file are of the same Autosar version */
  83. #if ((QSPI_IP_FEATURES_AR_RELEASE_MAJOR_VERSION_CFG != QSPI_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  84. (QSPI_IP_FEATURES_AR_RELEASE_MINOR_VERSION_CFG != QSPI_IP_AR_RELEASE_MINOR_VERSION_H) || \
  85. (QSPI_IP_FEATURES_AR_RELEASE_REVISION_VERSION_CFG != QSPI_IP_AR_RELEASE_REVISION_VERSION_H) \
  86. )
  87. #error "AutoSar Version Numbers of Qspi_Ip.h and Qspi_Ip_Features.h are different"
  88. #endif
  89. /* Check if current file and Qspi_Ip_Features header file are of the same Software version */
  90. #if ((QSPI_IP_FEATURES_SW_MAJOR_VERSION_CFG != QSPI_IP_SW_MAJOR_VERSION_H) || \
  91. (QSPI_IP_FEATURES_SW_MINOR_VERSION_CFG != QSPI_IP_SW_MINOR_VERSION_H) || \
  92. (QSPI_IP_FEATURES_SW_PATCH_VERSION_CFG != QSPI_IP_SW_PATCH_VERSION_H) \
  93. )
  94. #error "Software Version Numbers of Qspi_Ip.h and Qspi_Ip_Features.h are different"
  95. #endif
  96. /*******************************************************************************
  97. * Definitions.
  98. ******************************************************************************/
  99. /*! Maximum number of bytes then can be read in one operation */
  100. #define QSPI_IP_MAX_READ_SIZE (FEATURE_QSPI_RX_BUF_SIZE)
  101. /*! Maximum number of bytes then can be written in one operation */
  102. #define QSPI_IP_MAX_WRITE_SIZE (FEATURE_QSPI_TX_BUF_SIZE)
  103. /*******************************************************************************
  104. * API
  105. ******************************************************************************/
  106. #define FLS_START_SEC_CODE
  107. #include "Fls_MemMap.h"
  108. /*!
  109. * @brief Initializes the serial flash memory driver
  110. *
  111. * This function initializes the external flash driver and prepares it for operation.
  112. *
  113. * @param instance External flash instance number
  114. * @param pConfig Pointer to the driver configuration structure.
  115. * @param pConnect Pointer to the flash device connection structure.
  116. * @return Error or success status returned by API
  117. */
  118. Qspi_Ip_StatusType Qspi_Ip_Init(uint32 instance,
  119. const Qspi_Ip_MemoryConfigType * pConfig,
  120. const Qspi_Ip_MemoryConnectionType * pConnect
  121. );
  122. /*!
  123. * @brief De-initializes the serial flash memory driver
  124. *
  125. * This function de-initializes the qspi driver. The driver can't be used
  126. * again until reinitialized. The state structure is no longer needed by the driver and
  127. * may be freed after calling this function.
  128. *
  129. * @param instance External flash instance number
  130. * @return Error or success status returned by API
  131. */
  132. Qspi_Ip_StatusType Qspi_Ip_Deinit(uint32 instance);
  133. /*!
  134. * @brief Erase a sector in the serial flash.
  135. *
  136. * This function performs one erase sector (block) operation on the external flash. The erase size must match one of
  137. * the device's erase types.
  138. *
  139. * @param instance External flash instance number
  140. * @param address Address of sector to be erased
  141. * @param size Size of the sector to be erase. The sector size must match one of the supported erase sizes of the device.
  142. * @return Error or success status returned by API
  143. */
  144. Qspi_Ip_StatusType Qspi_Ip_EraseBlock(uint32 instance,
  145. uint32 address,
  146. uint32 size
  147. );
  148. /*!
  149. * @brief Erase the entire serial flash
  150. *
  151. * @param instance External flash instance number
  152. * @return Error or success status returned by API
  153. */
  154. Qspi_Ip_StatusType Qspi_Ip_EraseChip(uint32 instance);
  155. /*!
  156. * @brief Check the status of the flash device
  157. *
  158. * @param instance External flash instance number
  159. * @return Error or success status returned by API
  160. */
  161. Qspi_Ip_StatusType Qspi_Ip_GetMemoryStatus(uint32 instance);
  162. /*!
  163. * @brief Sets the protection bits to the requested value.
  164. *
  165. * @param instance External flash instance number
  166. * @param value New value for the protection bits
  167. * @return Error or success status returned by API
  168. */
  169. Qspi_Ip_StatusType Qspi_Ip_SetProtection(uint32 instance,
  170. uint8 value
  171. );
  172. /*!
  173. * @brief Returns the current value of the protection bits
  174. *
  175. * @param instance External flash instance number
  176. * @param value Current value of the protection bits
  177. * @return Error or success status returned by API
  178. */
  179. Qspi_Ip_StatusType Qspi_Ip_GetProtection(uint32 instance,
  180. uint8 *value
  181. );
  182. /*!
  183. * @brief Resets the flash device
  184. *
  185. * @param instance External flash instance number
  186. * @return Error or success status returned by API
  187. */
  188. Qspi_Ip_StatusType Qspi_Ip_Reset(uint32 instance);
  189. /*!
  190. * @brief Enters 0-X-X (no command) mode. This mode assumes only reads are performed.
  191. *
  192. * @param instance External flash instance number
  193. * @return Error or success status returned by API
  194. */
  195. Qspi_Ip_StatusType Qspi_Ip_Enter0XX(uint32 instance);
  196. /*!
  197. * @brief Exits 0-X-X (no command) mode. This allows operations other than reads to be performed.
  198. *
  199. * @param instance External flash instance number
  200. * @return Error or success status returned by API
  201. */
  202. Qspi_Ip_StatusType Qspi_Ip_Exit0XX(uint32 instance);
  203. /*!
  204. * @brief Suspends a program operation.
  205. *
  206. * @param instance External flash instance number
  207. * @return Error or success status returned by API
  208. */
  209. Qspi_Ip_StatusType Qspi_Ip_ProgramSuspend(uint32 instance);
  210. /*!
  211. * @brief Resumes a program operation.
  212. *
  213. * @param instance External flash instance number
  214. * @return Error or success status returned by API
  215. */
  216. Qspi_Ip_StatusType Qspi_Ip_ProgramResume(uint32 instance);
  217. /*!
  218. * @brief Suspends an erase operation.
  219. *
  220. * @param instance External flash instance number
  221. * @return Error or success status returned by API
  222. */
  223. Qspi_Ip_StatusType Qspi_Ip_EraseSuspend(uint32 instance);
  224. /*!
  225. * @brief Resumes an erase operation.
  226. *
  227. * @param instance External flash instance number
  228. * @return Error or success status returned by API
  229. */
  230. Qspi_Ip_StatusType Qspi_Ip_EraseResume(uint32 instance);
  231. /*!
  232. * @brief Read data from serial flash
  233. *
  234. * @param instance External flash instance number
  235. * @param address Start address for read operation
  236. * @param data Buffer where to store read data
  237. * @param size Size of data buffer
  238. * @return Error or success status returned by API
  239. */
  240. Qspi_Ip_StatusType Qspi_Ip_Read(uint32 instance,
  241. uint32 address,
  242. uint8 * data,
  243. uint32 size
  244. );
  245. /*!
  246. * @brief Read manufacturer ID/device ID from serial flash
  247. *
  248. * @param instance External flash instance number
  249. * @param data Buffer where to store read data. Buffer size must match ReadId initialization settings.
  250. * @return Error or success status returned by API
  251. */
  252. Qspi_Ip_StatusType Qspi_Ip_ReadId(uint32 instance,
  253. uint8 * data
  254. );
  255. /*!
  256. * @brief Verifies the correctness of the programmed data
  257. *
  258. * @param instance External flash instance number
  259. * @param address Start address of area to be verified
  260. * @param data Data to be verified
  261. * @param size Size of area to be verified
  262. * @return Error or success status returned by API
  263. */
  264. Qspi_Ip_StatusType Qspi_Ip_ProgramVerify(uint32 instance,
  265. uint32 address,
  266. const uint8 * data,
  267. uint32 size
  268. );
  269. /*!
  270. * @brief Checks whether or not an area in the serial flash is erased
  271. *
  272. * @param instance External flash instance number
  273. * @param address Start address of area to be verified
  274. * @param size Size of area to be verified
  275. * @return Error or success status returned by API
  276. */
  277. Qspi_Ip_StatusType Qspi_Ip_EraseVerify(uint32 instance,
  278. uint32 address,
  279. uint32 size
  280. );
  281. /*!
  282. * @brief Writes data in serial flash
  283. *
  284. * @param instance External flash instance number
  285. * @param address Start address of area to be programmed
  286. * @param data Data to be programmed in flash
  287. * @param size Size of data buffer
  288. * @return Error or success status returned by API
  289. */
  290. Qspi_Ip_StatusType Qspi_Ip_Program(uint32 instance,
  291. uint32 address,
  292. const uint8 * data,
  293. uint32 size
  294. );
  295. /*!
  296. * @brief Launches a simple command for the serial flash.
  297. *
  298. * @param instance External flash instance number
  299. * @param lut Index of command in virtual LUT
  300. * @param addr Address used in the command, or base address of the target serial flash
  301. * @return Error or success status returned by API
  302. */
  303. Qspi_Ip_StatusType Qspi_Ip_RunCommand(uint32 instance,
  304. uint16 lut,
  305. uint32 addr
  306. );
  307. /*!
  308. * @brief Launches a read command for the serial flash
  309. *
  310. * This function can launch a read command in 3 modes:
  311. * - normal read (dataRead != NULL_PTR): Data is read from serial flash and placed in the buffer
  312. * - verify (dataRead == NULL_PTR, dataCmp != NULL_PTR): Data is read from serial flash and compared to the reference buffer
  313. * - blank check (dataRead == NULL_PTR, dataCmp == NULL_PTR): Data is read from serial flash and compared to 0xFF
  314. * Only normal read mode can use DMA.
  315. *
  316. * @param instance External flash instance number
  317. * @param lut Index of LUT register
  318. * @param addr Start address for read operation in serial flash
  319. * @param dataRead Buffer where to store read data
  320. * @param dataCmp Buffer to be compared to read data
  321. * @param size Size of data buffer
  322. * @return Error or success status returned by API
  323. */
  324. Qspi_Ip_StatusType Qspi_Ip_RunReadCommand(uint32 instance,
  325. uint16 lut,
  326. uint32 addr,
  327. uint8 * dataRead,
  328. const uint8 * dataCmp,
  329. uint32 size
  330. );
  331. /*!
  332. * @brief Launches a write command for the serial flash
  333. *
  334. * @param instance External flash instance number
  335. * @param lut Index of LUT register
  336. * @param addr Start address for write operation in serial flash
  337. * @param data Data to be programmed in flash
  338. * @param size Size of data buffer
  339. * @return Error or success status returned by API
  340. */
  341. Qspi_Ip_StatusType Qspi_Ip_RunWriteCommand(uint32 instance,
  342. uint16 lut,
  343. uint32 addr,
  344. const uint8 * data,
  345. uint32 size
  346. );
  347. /*!
  348. * @brief Sets up AHB reads to the serial flash
  349. *
  350. * @param instance External flash instance number
  351. * @return Error or success status returned by API
  352. */
  353. Qspi_Ip_StatusType Qspi_Ip_AhbReadEnable(uint32 instance);
  354. /*!
  355. * @brief Check the status of the QSPI controller
  356. *
  357. * @param instance QSPI peripheral instance number
  358. * @return Error or success status returned by API
  359. */
  360. Qspi_Ip_StatusType Qspi_Ip_ControllerGetStatus(uint32 instance);
  361. /*!
  362. * @brief Initializes the qspi driver
  363. *
  364. * This function initializes the qspi driver and prepares it for operation.
  365. *
  366. * @param instance QSPI peripheral instance number
  367. * @param userConfigPtr Pointer to the qspi configuration structure.
  368. * @return Error or success status returned by API
  369. */
  370. Qspi_Ip_StatusType Qspi_Ip_ControllerInit(uint32 instance,
  371. const Qspi_Ip_ControllerConfigType * userConfigPtr
  372. );
  373. /*!
  374. * @brief De-initialize the qspi driver
  375. *
  376. * This function de-initializes the qspi driver. The driver can't be used
  377. * again until reinitialized. The context structure is no longer needed by the driver and
  378. * can be freed after calling this function.
  379. *
  380. * @param instance QSPI peripheral instance number
  381. * @return Error or success status returned by API
  382. */
  383. Qspi_Ip_StatusType Qspi_Ip_ControllerDeinit(uint32 instance);
  384. /*!
  385. * @brief Initializes the serial flash memory configuration from SFDP table
  386. *
  387. * This function uses the information in the SFDP table to auto-fill the memory configuration structure.
  388. *
  389. * @param pConfig Pointer to the driver configuration structure.
  390. * @param pConnect Pointer to the flash device connection structure.
  391. * @return Error or success status returned by API
  392. */
  393. Qspi_Ip_StatusType Qspi_Ip_ReadSfdp(Qspi_Ip_MemoryConfigType * pConfig,
  394. const Qspi_Ip_MemoryConnectionType * pConnect
  395. );
  396. #define FLS_STOP_SEC_CODE
  397. #include "Fls_MemMap.h"
  398. #if defined(__cplusplus)
  399. }
  400. #endif
  401. /** @} */
  402. #endif /* QSPI_IP_H */