Qspi_Ip_HwAccess.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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 QUADSPI_HW_ACCESS_H
  25. #define QUADSPI_HW_ACCESS_H
  26. /**
  27. * @file Qspi_Ip_HwAccess.h
  28. *
  29. * @addtogroup IPV_QSPI QSPI IPV Driver
  30. * @{
  31. */
  32. /* implements Qspi_Ip_HwAccess.h_Artifact */
  33. #ifdef __cplusplus
  34. extern "C"{
  35. #endif
  36. #include "Qspi_Ip.h"
  37. #include "Qspi_Ip_Common.h"
  38. /*==================================================================================================
  39. * SOURCE FILE VERSION INFORMATION
  40. ==================================================================================================*/
  41. #define QSPI_IP_HW_ACCESS_VENDOR_ID_H 43
  42. #define QSPI_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION_H 4
  43. #define QSPI_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION_H 4
  44. #define QSPI_IP_HW_ACCESS_AR_RELEASE_REVISION_VERSION_H 0
  45. #define QSPI_IP_HW_ACCESS_SW_MAJOR_VERSION_H 1
  46. #define QSPI_IP_HW_ACCESS_SW_MINOR_VERSION_H 0
  47. #define QSPI_IP_HW_ACCESS_SW_PATCH_VERSION_H 0
  48. /*==================================================================================================
  49. * FILE VERSION CHECKS
  50. ==================================================================================================*/
  51. /* Check if current file and Qspi_Ip header file are of the same vendor */
  52. #if (QSPI_IP_HW_ACCESS_VENDOR_ID_H != QSPI_IP_VENDOR_ID_H)
  53. #error "Qspi_Ip_HwAccess.h and Qspi_Ip.h have different vendor ids"
  54. #endif
  55. /* Check if current file and Qspi_Ip header file are of the same Autosar version */
  56. #if ((QSPI_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION_H != QSPI_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  57. (QSPI_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION_H != QSPI_IP_AR_RELEASE_MINOR_VERSION_H) || \
  58. (QSPI_IP_HW_ACCESS_AR_RELEASE_REVISION_VERSION_H != QSPI_IP_AR_RELEASE_REVISION_VERSION_H) \
  59. )
  60. #error "AutoSar Version Numbers of Qspi_Ip_HwAccess.h and Qspi_Ip.h are different"
  61. #endif
  62. /* Check if current file and Qspi_Ip header file are of the same Software version */
  63. #if ((QSPI_IP_HW_ACCESS_SW_MAJOR_VERSION_H != QSPI_IP_SW_MAJOR_VERSION_H) || \
  64. (QSPI_IP_HW_ACCESS_SW_MINOR_VERSION_H != QSPI_IP_SW_MINOR_VERSION_H) || \
  65. (QSPI_IP_HW_ACCESS_SW_PATCH_VERSION_H != QSPI_IP_SW_PATCH_VERSION_H) \
  66. )
  67. #error "Software Version Numbers of Qspi_Ip_HwAccess.h and Qspi_Ip.h are different"
  68. #endif
  69. /* Check if current file and Qspi_Ip_Common header file are of the same vendor */
  70. #if (QSPI_IP_HW_ACCESS_VENDOR_ID_H != QSPI_IP_COMMON_VENDOR_ID_H)
  71. #error "Qspi_Ip_HwAccess.h and Qspi_Ip_Common.h have different vendor ids"
  72. #endif
  73. /* Check if current file and Qspi_Ip_Common header file are of the same Autosar version */
  74. #if ((QSPI_IP_HW_ACCESS_AR_RELEASE_MAJOR_VERSION_H != QSPI_IP_COMMON_AR_RELEASE_MAJOR_VERSION_H) || \
  75. (QSPI_IP_HW_ACCESS_AR_RELEASE_MINOR_VERSION_H != QSPI_IP_COMMON_AR_RELEASE_MINOR_VERSION_H) || \
  76. (QSPI_IP_HW_ACCESS_AR_RELEASE_REVISION_VERSION_H != QSPI_IP_COMMON_AR_RELEASE_REVISION_VERSION_H) \
  77. )
  78. #error "AutoSar Version Numbers of Qspi_Ip_HwAccess.h and Qspi_Ip_Common.h are different"
  79. #endif
  80. /* Check if current file and Qspi_Ip_Common header file are of the same Software version */
  81. #if ((QSPI_IP_HW_ACCESS_SW_MAJOR_VERSION_H != QSPI_IP_COMMON_SW_MAJOR_VERSION_H) || \
  82. (QSPI_IP_HW_ACCESS_SW_MINOR_VERSION_H != QSPI_IP_COMMON_SW_MINOR_VERSION_H) || \
  83. (QSPI_IP_HW_ACCESS_SW_PATCH_VERSION_H != QSPI_IP_COMMON_SW_PATCH_VERSION_H) \
  84. )
  85. #error "Software Version Numbers of Qspi_Ip_HwAccess.h and Qspi_Ip_Common.h are different"
  86. #endif
  87. #if (QSPI_IP_MEM_INSTANCE_COUNT > 0)
  88. /*******************************************************************************
  89. * Definitions
  90. ******************************************************************************/
  91. #define QSPI_IP_RX_READOUT_IP 1U /* RX Buffer content is read using the AHB Bus registers QSPI_ARDBn */
  92. /*******************************************************************************
  93. * API
  94. ******************************************************************************/
  95. /*
  96. * Set all hardware registers to their reset value
  97. */
  98. static inline void Qspi_Ip_ResetAllRegisters(QuadSPI_Type *baseAddr)
  99. {
  100. uint8 cnt;
  101. /* reset MCR register */
  102. baseAddr->MCR = (uint32)0x000F400CUL;
  103. /* reset IPCR register */
  104. baseAddr->IPCR = (uint32)0x00000000UL;
  105. /* reset FLSHCR register */
  106. baseAddr->FLSHCR = (uint32)0x00000303UL;
  107. /* reset BUF0CR register */
  108. baseAddr->BUF0CR = (uint32)0x00000003UL;
  109. /* reset BUF1CR register */
  110. baseAddr->BUF1CR = (uint32)0x00000002UL;
  111. /* reset BUF2CR register */
  112. baseAddr->BUF2CR = (uint32)0x00000001UL;
  113. /* reset BUF3CR register */
  114. baseAddr->BUF3CR = (uint32)0x80000000UL;
  115. /* reset BFGENCR register */
  116. baseAddr->BFGENCR = (uint32)0x00000000UL;
  117. /* reset SOCCR register */
  118. baseAddr->SOCCR = (uint32)0x00000000UL;
  119. /* reset BUF0IND register */
  120. baseAddr->BUF0IND = (uint32)0x00000000UL;
  121. /* reset BUF1IND register */
  122. baseAddr->BUF1IND = (uint32)0x00000000UL;
  123. /* reset BUF2IND register */
  124. baseAddr->BUF2IND = (uint32)0x00000000UL;
  125. /* reset SFAR register */
  126. baseAddr->SFAR = (uint32)0x00000000UL;
  127. /* reset SFACR register */
  128. baseAddr->SFACR = (uint32)0x00000000UL;
  129. /* reset SMPR register */
  130. baseAddr->SMPR = (uint32)0x00000000UL;
  131. /* reset RBCT register */
  132. baseAddr->RBCT = (uint32)0x00000000UL;
  133. /* reset TBDR register */
  134. baseAddr->TBDR = (uint32)0x00000000UL;
  135. /* reset TBCT register */
  136. baseAddr->TBCT = (uint32)0x00000000UL;
  137. /* reset FR register - Write 1 to clear */
  138. baseAddr->FR = (uint32)0x0C83F0C1UL;
  139. /* reset RSER register */
  140. baseAddr->RSER = (uint32)0x00000000UL;
  141. /* reset SPTRCLR register */
  142. baseAddr->SPTRCLR = (uint32)0x00000000UL;
  143. /* reset SFA1AD register */
  144. baseAddr->SFA1AD = (uint32)0x6C000000UL;
  145. /* reset SFA2AD register */
  146. baseAddr->SFA2AD = (uint32)0x6C000000UL;
  147. /* reset SFB1AD register */
  148. baseAddr->SFB1AD = (uint32)0x70000000UL;
  149. /* reset SFB2AD register */
  150. baseAddr->SFB2AD = (uint32)0x70000000UL;
  151. /* reset LUTKEY register */
  152. baseAddr->LUTKEY = (uint32)0x5AF05AF0UL;
  153. /* reset LCKCR register */
  154. baseAddr->LCKCR = (uint32)0x00000002UL;
  155. /* reset LUT0 register */
  156. baseAddr->LUT[0] = (uint32)0x08180403UL;
  157. /* reset LUT1 register */
  158. baseAddr->LUT[1] = (uint32)0x24001C08UL;
  159. for (cnt = 2U; cnt < QuadSPI_LUT_COUNT; cnt++)
  160. {
  161. baseAddr->LUT[cnt] = (uint32)0x00000000UL;
  162. }
  163. }
  164. /*
  165. * Triggers an IP transaction
  166. */
  167. static inline void Qspi_Ip_IpTrigger(QuadSPI_Type *baseAddr,
  168. uint8 seqID,
  169. uint16 dataSize
  170. )
  171. {
  172. baseAddr->IPCR = QuadSPI_IPCR_SEQID(seqID)
  173. | QuadSPI_IPCR_IDATSZ(dataSize);
  174. }
  175. /*
  176. * Clear Rx buffer
  177. */
  178. static inline void Qspi_Ip_ClearRxBuf(QuadSPI_Type *baseAddr)
  179. {
  180. baseAddr->MCR |= QuadSPI_MCR_CLR_RXF_MASK;
  181. }
  182. /*
  183. * Clear Tx buffer
  184. */
  185. static inline void Qspi_Ip_ClearTxBuf(QuadSPI_Type *baseAddr)
  186. {
  187. baseAddr->MCR |= QuadSPI_MCR_CLR_TXF_MASK;
  188. }
  189. /*
  190. * Checks the Tx buffer clear flag
  191. * Returns TRUE if the Tx buffer content is invalidated.
  192. */
  193. static inline boolean Qspi_Ip_GetClrTxStatus(const QuadSPI_Type *baseAddr)
  194. {
  195. uint32 regValue = (uint32)baseAddr->MCR;
  196. regValue = (regValue & QuadSPI_MCR_CLR_TXF_MASK) >> QuadSPI_MCR_CLR_TXF_SHIFT;
  197. return (0U == regValue)? TRUE : FALSE;
  198. }
  199. #ifdef QuadSPI_SPTRCLR_ABRT_CLR_MASK
  200. /*
  201. * Clear AHB buffer
  202. */
  203. static inline void Qspi_Ip_ClearAhbBuf(QuadSPI_Type *baseAddr)
  204. {
  205. baseAddr->SPTRCLR |= QuadSPI_SPTRCLR_ABRT_CLR_MASK;
  206. }
  207. /*
  208. * Checks the Ahb buffer clear flag
  209. * Returns TRUE if the Ahb buffer content is invalidated.
  210. */
  211. static inline boolean Qspi_Ip_GetClrAhbStatus(const QuadSPI_Type *baseAddr)
  212. {
  213. uint32 regValue = (uint32)baseAddr->SPTRCLR;
  214. regValue = (regValue & QuadSPI_SPTRCLR_ABRT_CLR_MASK) >> QuadSPI_SPTRCLR_ABRT_CLR_SHIFT;
  215. return (0U == regValue)? TRUE : FALSE;
  216. }
  217. #endif
  218. /*
  219. * Enable QuadSPI device
  220. */
  221. static inline void Qspi_Ip_Enable(QuadSPI_Type *baseAddr)
  222. {
  223. baseAddr->MCR &= ~QuadSPI_MCR_MDIS_MASK;
  224. }
  225. /*
  226. * Disable QuadSPI device
  227. */
  228. static inline void Qspi_Ip_Disable(QuadSPI_Type *baseAddr)
  229. {
  230. baseAddr->MCR |= QuadSPI_MCR_MDIS_MASK;
  231. }
  232. /*
  233. * Enable DDR mode
  234. */
  235. static inline void QSPI_DDR_Enable(QuadSPI_Type *baseAddr)
  236. {
  237. baseAddr->MCR |= QuadSPI_MCR_DDR_EN_MASK;
  238. }
  239. /*
  240. * Disable DDR mode
  241. */
  242. static inline void QSPI_DDR_Disable(QuadSPI_Type *baseAddr)
  243. {
  244. baseAddr->MCR &= ~QuadSPI_MCR_DDR_EN_MASK;
  245. }
  246. /*
  247. * Enable or disable DQS Latency
  248. */
  249. static inline void QSPI_DQS_LatEnable(QuadSPI_Type *baseAddr, boolean enable)
  250. {
  251. uint32 regValue = (uint32)baseAddr->MCR;
  252. regValue &= (uint32)(~((uint32)QuadSPI_MCR_DQS_LAT_EN_MASK));
  253. regValue |= QuadSPI_MCR_DQS_LAT_EN(enable? 1U : 0U);
  254. baseAddr->MCR = (uint32)regValue;
  255. }
  256. /*
  257. * Enable DQS
  258. */
  259. static inline void QSPI_DQS_Enable(QuadSPI_Type *baseAddr)
  260. {
  261. (void)baseAddr;
  262. #ifdef QuadSPI_MCR_DQS_EN_MASK
  263. baseAddr->MCR |= QuadSPI_MCR_DQS_EN_MASK;
  264. #endif
  265. }
  266. /*
  267. * Disable DQS
  268. */
  269. static inline void QSPI_DQS_Disable(QuadSPI_Type *baseAddr)
  270. {
  271. (void)baseAddr;
  272. #ifdef QuadSPI_MCR_DQS_EN_MASK
  273. baseAddr->MCR &= ~QuadSPI_MCR_DQS_EN_MASK;
  274. #endif
  275. }
  276. /*
  277. * Assert QuadSPI sw reset bits
  278. */
  279. static inline void Qspi_Ip_SwResetOn(QuadSPI_Type *baseAddr)
  280. {
  281. baseAddr->MCR |= QuadSPI_MCR_SWRSTHD_MASK | QuadSPI_MCR_SWRSTSD_MASK;
  282. }
  283. /*
  284. * Deassert QuadSPI sw reset bits
  285. */
  286. static inline void Qspi_Ip_SwResetOff(QuadSPI_Type *baseAddr)
  287. {
  288. baseAddr->MCR &= ~(QuadSPI_MCR_SWRSTHD_MASK | QuadSPI_MCR_SWRSTSD_MASK);
  289. }
  290. /*
  291. * Configure idle values for data lines 2:3
  292. */
  293. static inline void Qspi_Ip_SetIdleLineValues(QuadSPI_Type *baseAddr,
  294. uint8 iofa2IdleValue,
  295. uint8 iofa3IdleValue,
  296. uint8 iofb2IdleValue,
  297. uint8 iofb3IdleValue
  298. )
  299. {
  300. /* get value MCR register */
  301. uint32 regValue = (uint32)baseAddr->MCR;
  302. /* set mask for ISD3FA,ISD2FA,ISD2FB,ISD3FB */
  303. regValue &= (uint32)(~(QuadSPI_MCR_ISD2FA_MASK | QuadSPI_MCR_ISD3FA_MASK | QuadSPI_MCR_ISD2FB_MASK | QuadSPI_MCR_ISD3FB_MASK));
  304. regValue |= (QuadSPI_MCR_ISD2FA(iofa2IdleValue) |
  305. QuadSPI_MCR_ISD3FA(iofa3IdleValue) |
  306. QuadSPI_MCR_ISD2FB(iofb2IdleValue) |
  307. QuadSPI_MCR_ISD3FB(iofb3IdleValue));
  308. /* set again the MCR register */
  309. baseAddr->MCR = (uint32)regValue;
  310. }
  311. /*
  312. * Configure external flash memory map size A
  313. */
  314. static inline void Qspi_Ip_SetMemMapSizeA(uint32 instance, QuadSPI_Type *baseAddr, uint32 sizeA1, uint32 sizeA2)
  315. {
  316. baseAddr->SFA1AD = Qspi_Ip_AhbAddress[instance] + sizeA1;
  317. baseAddr->SFA2AD = Qspi_Ip_AhbAddress[instance] + sizeA1 + sizeA2;
  318. }
  319. /*
  320. * Configure external flash memory map size B
  321. */
  322. static inline void Qspi_Ip_SetMemMapSizeB(QuadSPI_Type *baseAddr, uint32 sizeB1, uint32 sizeB2)
  323. {
  324. /* Get memory address of size A2 */
  325. uint32 regValue = (uint32)baseAddr->SFA2AD;
  326. baseAddr->SFB1AD = regValue + sizeB1;
  327. baseAddr->SFB2AD = regValue + sizeB1 + sizeB2;
  328. }
  329. /*
  330. * Set CS hold time in serial clock cycles
  331. */
  332. static inline void Qspi_Ip_SetCsHoldTime(QuadSPI_Type *baseAddr, uint8 cycles)
  333. {
  334. uint32 regValue = (uint32)baseAddr->FLSHCR;
  335. regValue &= (uint32)(~((uint32)QuadSPI_FLSHCR_TCSH_MASK));
  336. regValue |= QuadSPI_FLSHCR_TCSH(cycles);
  337. baseAddr->FLSHCR = (uint32)regValue;
  338. }
  339. /*
  340. * Set CS setup time
  341. */
  342. static inline void Qspi_Ip_SetCsSetupTime(QuadSPI_Type *baseAddr, uint8 cycles)
  343. {
  344. uint32 regValue = (uint32)baseAddr->FLSHCR;
  345. regValue &= (uint32)(~((uint32)QuadSPI_FLSHCR_TCSS_MASK));
  346. regValue |= QuadSPI_FLSHCR_TCSS(cycles);
  347. baseAddr->FLSHCR = (uint32)regValue;
  348. }
  349. /*
  350. * Set data in hold time
  351. */
  352. static inline void Qspi_Ip_SetDataInHoldTime(QuadSPI_Type *baseAddr, Qspi_Ip_FlashDataAlignType enable)
  353. {
  354. uint32 regValue = (uint32)baseAddr->FLSHCR;
  355. regValue &= (uint32)(~(QuadSPI_FLSHCR_TDH_MASK));
  356. regValue |= QuadSPI_FLSHCR_TDH(enable);
  357. baseAddr->FLSHCR = (uint32)regValue;
  358. }
  359. /*
  360. * Sets AHB buffer 0 configuration
  361. */
  362. static inline void Qspi_Ip_SetAhbBuf0(QuadSPI_Type *baseAddr,
  363. uint16 size,
  364. uint8 master
  365. )
  366. {
  367. baseAddr->BUF0CR = QuadSPI_BUF0CR_ADATSZ((uint32)size >> 3U)
  368. | QuadSPI_BUF0CR_MSTRID(master);
  369. }
  370. /*
  371. * Sets AHB buffer 1 configuration
  372. */
  373. static inline void Qspi_Ip_SetAhbBuf1(QuadSPI_Type *baseAddr,
  374. uint16 size,
  375. uint8 master
  376. )
  377. {
  378. baseAddr->BUF1CR = QuadSPI_BUF1CR_ADATSZ((uint32)size >> 3U)
  379. | QuadSPI_BUF1CR_MSTRID(master);
  380. }
  381. /*
  382. * Sets AHB buffer 2 configuration
  383. */
  384. static inline void Qspi_Ip_SetAhbBuf2(QuadSPI_Type *baseAddr,
  385. uint16 size,
  386. uint8 master
  387. )
  388. {
  389. baseAddr->BUF2CR = QuadSPI_BUF2CR_ADATSZ((uint32)size >> 3U)
  390. | QuadSPI_BUF2CR_MSTRID(master);
  391. }
  392. /*
  393. * Sets AHB buffer 3 configuration
  394. */
  395. static inline void Qspi_Ip_SetAhbBuf3(QuadSPI_Type *baseAddr,
  396. uint16 size,
  397. uint8 master,
  398. boolean allMasters
  399. )
  400. {
  401. baseAddr->BUF3CR = QuadSPI_BUF3CR_ADATSZ((uint32)size >> 3U)
  402. | QuadSPI_BUF3CR_MSTRID(master)
  403. | QuadSPI_BUF3CR_ALLMST(allMasters? 1U : 0U);
  404. }
  405. /*
  406. * Sets AHB buffer 0 index. Parameter represents desired end index of the buffer.
  407. */
  408. static inline void Qspi_Ip_SetAhbBuf0Ind(QuadSPI_Type *baseAddr,
  409. uint32 index
  410. )
  411. {
  412. baseAddr->BUF0IND = index;
  413. }
  414. /*
  415. * Sets AHB buffer 1 index. Parameter represents desired end index of the buffer.
  416. */
  417. static inline void Qspi_Ip_SetAhbBuf1Ind(QuadSPI_Type *baseAddr,
  418. uint32 index
  419. )
  420. {
  421. baseAddr->BUF1IND = index;
  422. }
  423. /*
  424. * Sets AHB buffer 2 index. Parameter represents desired end index of the buffer.
  425. */
  426. static inline void Qspi_Ip_SetAhbBuf2Ind(QuadSPI_Type *baseAddr,
  427. uint32 index
  428. )
  429. {
  430. baseAddr->BUF2IND = index;
  431. }
  432. /*
  433. * Sets address for IP transactions
  434. */
  435. static inline void Qspi_Ip_SetIpAddr(QuadSPI_Type *baseAddr,
  436. uint32 addr
  437. )
  438. {
  439. baseAddr->SFAR = addr;
  440. }
  441. /*
  442. * Sets flash address options
  443. */
  444. static inline void Qspi_Ip_SetAddrOptions(QuadSPI_Type *baseAddr,
  445. uint32 columnAddr,
  446. boolean wordAdressable
  447. )
  448. {
  449. baseAddr->SFACR = QuadSPI_SFACR_CAS(columnAddr)
  450. | QuadSPI_SFACR_WA(wordAdressable? 1U : 0U);
  451. }
  452. /*
  453. * Configures parameters related to sampling Rx data
  454. */
  455. static inline void Qspi_Ip_SetRxCfg(QuadSPI_Type *baseAddr,
  456. Qspi_Ip_SampleDelayType delay,
  457. Qspi_Ip_SamplePhaseType clockPhase
  458. )
  459. {
  460. baseAddr->SMPR = QuadSPI_SMPR_FSPHS(clockPhase)
  461. | QuadSPI_SMPR_FSDLY(delay);
  462. }
  463. /*
  464. * Checks if module is busy with a transaction
  465. */
  466. static inline boolean Qspi_Ip_GetBusyStatus(const QuadSPI_Type *baseAddr)
  467. {
  468. uint32 regValue = (uint32)baseAddr->SR;
  469. regValue = (regValue & QuadSPI_SR_BUSY_MASK) >> QuadSPI_SR_BUSY_SHIFT;
  470. return (regValue != 0U)? TRUE : FALSE;
  471. }
  472. /*
  473. * Returns the current fill level of the Rx buffer
  474. */
  475. static inline uint32 Qspi_Ip_GetRxBufFill(const QuadSPI_Type *baseAddr)
  476. {
  477. uint32 regValue = (uint32)baseAddr->RBSR;
  478. regValue = (regValue & QuadSPI_RBSR_RDBFL_MASK) >> QuadSPI_RBSR_RDBFL_SHIFT;
  479. return regValue;
  480. }
  481. /*
  482. * Checks if enough Rx data is available, according to the watermark setting
  483. */
  484. static inline boolean Qspi_Ip_GetRxDataEvent(const QuadSPI_Type *baseAddr)
  485. {
  486. uint32 regValue = (uint32)baseAddr->SR;
  487. regValue = (regValue & QuadSPI_SR_RXWE_MASK) >> QuadSPI_SR_RXWE_SHIFT;
  488. return (regValue != 0U)? TRUE : FALSE;
  489. }
  490. /*
  491. * Returns Tx buffer fill level expressed in 4-byte entries
  492. */
  493. static inline uint32 Qspi_Ip_GetTxBufFill(const QuadSPI_Type *baseAddr)
  494. {
  495. uint32 regValue = (uint32)baseAddr->TBSR;
  496. regValue = (regValue & QuadSPI_TBSR_TRBFL_MASK) >> QuadSPI_TBSR_TRBFL_SHIFT;
  497. return regValue;
  498. }
  499. /*
  500. * Checks the Tx buffer watermark.
  501. * Returns TRUE if number of buffer entries specified by the watermark is available.
  502. */
  503. static inline boolean Qspi_Ip_GetTxWatermarkAvailable(const QuadSPI_Type *baseAddr)
  504. {
  505. uint32 regValue = (uint32)baseAddr->SR;
  506. regValue = (regValue & QuadSPI_SR_TXWA_MASK) >> QuadSPI_SR_TXWA_SHIFT;
  507. return (regValue != 0U)? TRUE : FALSE;
  508. }
  509. /*
  510. * Writes data in the Tx buffer
  511. */
  512. static inline void Qspi_Ip_WriteTxData(QuadSPI_Type *baseAddr, uint32 data)
  513. {
  514. baseAddr->TBDR = data;
  515. }
  516. /*
  517. * Returns the address of the Tx data register
  518. */
  519. static inline uint32 Qspi_Ip_GetTxDataAddr(const QuadSPI_Type *baseAddr)
  520. {
  521. return (uint32)&(baseAddr->TBDR);
  522. }
  523. /*
  524. * Returns the address of the first Rx data register
  525. */
  526. static inline uint32 Qspi_Ip_GetRxDataAddr(const QuadSPI_Type *baseAddr)
  527. {
  528. return (uint32)&(baseAddr->RBDR[0U]);
  529. }
  530. /*
  531. * Enables Tx DMA request (when Tx buffer has room for more data)
  532. */
  533. static inline void Qspi_Ip_EnableTxDmaReq(QuadSPI_Type *baseAddr)
  534. {
  535. baseAddr->RSER |= QuadSPI_RSER_TBFDE_MASK;
  536. }
  537. /*
  538. * Enables Rx DMA request (when Rx buffer has room for more data)
  539. */
  540. static inline void Qspi_Ip_EnableRxDmaReq(QuadSPI_Type *baseAddr)
  541. {
  542. baseAddr->RSER |= QuadSPI_RSER_RBDDE_MASK;
  543. }
  544. /*
  545. * Disables both Rx and Tx DMA requests
  546. */
  547. static inline void Qspi_Ip_DisableDmaReq(QuadSPI_Type *baseAddr)
  548. {
  549. baseAddr->RSER &= ~(QuadSPI_RSER_TBFDE_MASK | QuadSPI_RSER_RBDDE_MASK);
  550. }
  551. /*
  552. * Perform a POP operation on the Rx buffer, removing Rx_watermark entries
  553. */
  554. static inline void Qspi_Ip_RxPop(QuadSPI_Type *baseAddr)
  555. {
  556. baseAddr->FR = QuadSPI_FR_RBDF_MASK;
  557. }
  558. /*
  559. * Configures the watermark for the Rx buffer, expressed in number of 4-byte entries
  560. */
  561. static inline void Qspi_Ip_SetRxWatermark(QuadSPI_Type *baseAddr,
  562. uint8 watermark
  563. )
  564. {
  565. uint32 regValue = (uint32)baseAddr->RBCT;
  566. regValue &= (uint32)(~((uint32)QuadSPI_RBCT_WMRK_MASK));
  567. regValue |= QuadSPI_RBCT_WMRK((uint32)watermark - 1U);
  568. baseAddr->RBCT = (uint32)regValue;
  569. }
  570. /*
  571. * Configures the rx for the Rx buffer, expressed in number of 4-byte entries
  572. */
  573. static inline void Qspi_Ip_SetRxBufReadout(QuadSPI_Type *baseAddr,
  574. uint8 readout
  575. )
  576. {
  577. uint32 regValue = (uint32)baseAddr->RBCT;
  578. regValue &= (uint32)(~((uint32)QuadSPI_RBCT_RXBRD_MASK));
  579. regValue |= QuadSPI_RBCT_RXBRD(readout);
  580. baseAddr->RBCT = (uint32)regValue;
  581. }
  582. /*
  583. * Configures the watermark for the Tx buffer, expressed in number of 4-byte entries
  584. */
  585. static inline void Qspi_Ip_SetTxWatermark(QuadSPI_Type *baseAddr,
  586. uint8 watermark
  587. )
  588. {
  589. uint32 regValue = (uint32)baseAddr->TBCT;
  590. regValue &= (uint32)(~((uint32)QuadSPI_TBCT_WMRK_MASK));
  591. regValue |= QuadSPI_TBCT_WMRK(watermark);
  592. baseAddr->TBCT = (uint32)regValue;
  593. }
  594. /*
  595. * Enables interrupts specified by the mask parameter
  596. */
  597. static inline void Qspi_Ip_EnableInt(QuadSPI_Type *baseAddr,
  598. uint32 mask
  599. )
  600. {
  601. baseAddr->RSER |= mask;
  602. }
  603. /*
  604. * Disables interrupts specified by the mask parameter
  605. */
  606. static inline void Qspi_Ip_DisableInt(QuadSPI_Type *baseAddr,
  607. uint32 mask
  608. )
  609. {
  610. baseAddr->RSER &= ~mask;
  611. }
  612. /*
  613. * Clears interrupt flags specified by the mask parameter
  614. */
  615. static inline void Qspi_Ip_ClearIntFlag(QuadSPI_Type *baseAddr,
  616. uint32 mask
  617. )
  618. {
  619. baseAddr->FR = mask;
  620. }
  621. #ifdef QuadSPI_MCR_SCLKCFG_MASK
  622. /*
  623. * Configure chip-specific clock options
  624. */
  625. static inline void Qspi_Ip_SetClockOptions(QuadSPI_Type *baseAddr, uint8 option)
  626. {
  627. uint32 regValue = (uint32)baseAddr->MCR;
  628. regValue &= (uint32)(~QuadSPI_MCR_SCLKCFG_MASK);
  629. regValue |= QuadSPI_MCR_SCLKCFG(option);
  630. baseAddr->MCR = (uint32)regValue;
  631. }
  632. #endif
  633. #ifdef QuadSPI_SOCCR_SOCCFG_MASK
  634. /*
  635. * Configure chip-specific options
  636. */
  637. static inline void Qspi_Ip_SetChipOptions(QuadSPI_Type *baseAddr, uint32 option)
  638. {
  639. baseAddr->SOCCR = option;
  640. }
  641. #endif
  642. #endif /* (QSPI_IP_MEM_INSTANCE_COUNT > 0) */
  643. #ifdef __cplusplus
  644. }
  645. #endif
  646. /** @} */
  647. #endif /* QUADSPI_HW_ACCESS_H */