1 /*
2  * Copyright 2021-2024 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef QSPI_IP_CONTROLLER_H
8 #define QSPI_IP_CONTROLLER_H
9 
10 /**
11 *   @file Qspi_Ip_Controller.h
12 *
13 *   @addtogroup IPV_QSPI
14 *   @{
15 */
16 
17 
18 #ifdef __cplusplus
19 extern "C"{
20 #endif
21 
22 #include "Qspi_Ip_Types.h"
23 #include "Qspi_Ip_Cfg.h"
24 #include "Qspi_Ip_Common.h"
25 
26 /*==================================================================================================
27 *                              SOURCE FILE VERSION INFORMATION
28 ==================================================================================================*/
29 #define QSPI_IP_CONTROLLER_VENDOR_ID_H                       43
30 #define QSPI_IP_CONTROLLER_AR_RELEASE_MAJOR_VERSION_H        4
31 #define QSPI_IP_CONTROLLER_AR_RELEASE_MINOR_VERSION_H        7
32 #define QSPI_IP_CONTROLLER_AR_RELEASE_REVISION_VERSION_H     0
33 #define QSPI_IP_CONTROLLER_SW_MAJOR_VERSION_H                2
34 #define QSPI_IP_CONTROLLER_SW_MINOR_VERSION_H                0
35 #define QSPI_IP_CONTROLLER_SW_PATCH_VERSION_H                0
36 /*==================================================================================================
37 *                                     FILE VERSION CHECKS
38 ==================================================================================================*/
39 /* Check if current file and Qspi_Ip_Types.h header file are of the same vendor */
40 #if (QSPI_IP_CONTROLLER_VENDOR_ID_H != QSPI_IP_TYPES_VENDOR_ID_CFG)
41     #error "Qspi_Ip_Controller.h and Qspi_Ip_Types.h have different vendor ids"
42 #endif
43 /* Check if current file and Qspi_Ip_Types.h header file are of the same Autosar version */
44 #if ((QSPI_IP_CONTROLLER_AR_RELEASE_MAJOR_VERSION_H    != QSPI_IP_TYPES_AR_RELEASE_MAJOR_VERSION_CFG) || \
45      (QSPI_IP_CONTROLLER_AR_RELEASE_MINOR_VERSION_H    != QSPI_IP_TYPES_AR_RELEASE_MINOR_VERSION_CFG) || \
46      (QSPI_IP_CONTROLLER_AR_RELEASE_REVISION_VERSION_H != QSPI_IP_TYPES_AR_RELEASE_REVISION_VERSION_CFG) \
47     )
48     #error "AutoSar Version Numbers of Qspi_Ip_Controller.h and Qspi_Ip_Types.h are different"
49 #endif
50 /* Check if current file and Qspi_Ip_Types.h header file are of the same Software version */
51 #if ((QSPI_IP_CONTROLLER_SW_MAJOR_VERSION_H != QSPI_IP_TYPES_SW_MAJOR_VERSION_CFG) || \
52      (QSPI_IP_CONTROLLER_SW_MINOR_VERSION_H != QSPI_IP_TYPES_SW_MINOR_VERSION_CFG) || \
53      (QSPI_IP_CONTROLLER_SW_PATCH_VERSION_H != QSPI_IP_TYPES_SW_PATCH_VERSION_CFG) \
54     )
55     #error "Software Version Numbers of Qspi_Ip_Controller.h and Qspi_Ip_Types.h are different"
56 #endif
57 
58 /* Check if current file and Qspi_Ip_Cfg.h header file are of the same vendor */
59 #if (QSPI_IP_CONTROLLER_VENDOR_ID_H != QSPI_IP_VENDOR_ID_CFG)
60     #error "Qspi_Ip_Controller.h and Qspi_Ip_Cfg.h have different vendor ids"
61 #endif
62 /* Check if current file and Qspi_Ip_Cfg.h header file are of the same Autosar version */
63 #if ((QSPI_IP_CONTROLLER_AR_RELEASE_MAJOR_VERSION_H    != QSPI_IP_AR_RELEASE_MAJOR_VERSION_CFG) || \
64      (QSPI_IP_CONTROLLER_AR_RELEASE_MINOR_VERSION_H    != QSPI_IP_AR_RELEASE_MINOR_VERSION_CFG) || \
65      (QSPI_IP_CONTROLLER_AR_RELEASE_REVISION_VERSION_H != QSPI_IP_AR_RELEASE_REVISION_VERSION_CFG) \
66     )
67     #error "AutoSar Version Numbers of Qspi_Ip_Controller.h and Qspi_Ip_Cfg.h are different"
68 #endif
69 /* Check if current file and Qspi_Ip_Cfg.h header file are of the same Software version */
70 #if ((QSPI_IP_CONTROLLER_SW_MAJOR_VERSION_H != QSPI_IP_SW_MAJOR_VERSION_CFG) || \
71      (QSPI_IP_CONTROLLER_SW_MINOR_VERSION_H != QSPI_IP_SW_MINOR_VERSION_CFG) || \
72      (QSPI_IP_CONTROLLER_SW_PATCH_VERSION_H != QSPI_IP_SW_PATCH_VERSION_CFG) \
73     )
74     #error "Software Version Numbers of Qspi_Ip_Controller.h and Qspi_Ip_Cfg.h are different"
75 #endif
76 
77 /* Check if current file and Qspi_Ip_Common.h header file are of the same vendor */
78 #if (QSPI_IP_CONTROLLER_VENDOR_ID_H != QSPI_IP_COMMON_VENDOR_ID_H)
79     #error "Qspi_Ip_Controller.h and Qspi_Ip_Common.h have different vendor ids"
80 #endif
81 /* Check if current file and Qspi_Ip_Common.h header file are of the same Autosar version */
82 #if ((QSPI_IP_CONTROLLER_AR_RELEASE_MAJOR_VERSION_H    != QSPI_IP_COMMON_AR_RELEASE_MAJOR_VERSION_H) || \
83      (QSPI_IP_CONTROLLER_AR_RELEASE_MINOR_VERSION_H    != QSPI_IP_COMMON_AR_RELEASE_MINOR_VERSION_H) || \
84      (QSPI_IP_CONTROLLER_AR_RELEASE_REVISION_VERSION_H != QSPI_IP_COMMON_AR_RELEASE_REVISION_VERSION_H) \
85     )
86     #error "AutoSar Version Numbers of Qspi_Ip_Controller.h and Qspi_Ip_Common.h are different"
87 #endif
88 /* Check if current file and Qspi_Ip_Common.h header file are of the same Software version */
89 #if ((QSPI_IP_CONTROLLER_SW_MAJOR_VERSION_H != QSPI_IP_COMMON_SW_MAJOR_VERSION_H) || \
90      (QSPI_IP_CONTROLLER_SW_MINOR_VERSION_H != QSPI_IP_COMMON_SW_MINOR_VERSION_H) || \
91      (QSPI_IP_CONTROLLER_SW_PATCH_VERSION_H != QSPI_IP_COMMON_SW_PATCH_VERSION_H) \
92     )
93     #error "Software Version Numbers of Qspi_Ip_Controller.h and Qspi_Ip_Common.h are different"
94 #endif
95 
96 #if (QSPI_IP_MEM_INSTANCE_COUNT > 0)
97 
98 /*******************************************************************************
99  * Macros
100  ******************************************************************************/
101 #if (QSPI_IP_ENABLE_USER_MODE_SUPPORT == STD_ON)
102      #define Qspi_Ip_WriteLuts(Instance, StartLutRegister, Data, Size) \
103              OsIf_Trusted_Call4params(Qspi_Ip_WriteLuts_Privileged, Instance, StartLutRegister, Data, Size)
104 
105      #define Qspi_Ip_SetAhbSeqId(instance, seqID) \
106              OsIf_Trusted_Call2params(Qspi_Ip_SetAhbSeqId_Privileged, instance, seqID)
107 
108 #else
109      #define Qspi_Ip_WriteLuts(Instance, StartLutRegister, Data, Size) \
110              Qspi_Ip_WriteLuts_Privileged(Instance, StartLutRegister, Data, Size)
111 
112      #define Qspi_Ip_SetAhbSeqId(instance, seqID) \
113              Qspi_Ip_SetAhbSeqId_Privileged(instance, seqID)
114 
115 #endif
116 
117 /*******************************************************************************
118  * Enumerations.
119  ******************************************************************************/
120 
121 /*******************************************************************************
122 * Definitions
123 ******************************************************************************/
124 
125 #define MEM_43_EXFLS_START_SEC_CONST_UNSPECIFIED
126 #include "Mem_43_EXFLS_MemMap.h"
127 
128 extern QuadSPI_Type * const Qspi_Ip_BaseAddress[];
129 
130 #define MEM_43_EXFLS_STOP_SEC_CONST_UNSPECIFIED
131 #include "Mem_43_EXFLS_MemMap.h"
132 
133 
134 #define MEM_43_EXFLS_START_SEC_VAR_CLEARED_8
135 #include "Mem_43_EXFLS_MemMap.h"
136 
137 /* The padding bytes information to handle unaligned read/write operation for QuadSPI instances */
138 extern uint8 Qspi_Ip_MemoryPadding[QuadSPI_INSTANCE_COUNT];
139 
140 #define MEM_43_EXFLS_STOP_SEC_VAR_CLEARED_8
141 #include "Mem_43_EXFLS_MemMap.h"
142 
143 
144 /*******************************************************************************
145  * API
146  ******************************************************************************/
147 /*!
148  * @name QuadSPI Driver
149  * @{
150  */
151 
152 
153 #define MEM_43_EXFLS_START_SEC_CODE
154 #include "Mem_43_EXFLS_MemMap.h"
155 
156 
157 
158 /*!
159  * @brief Configures LUT commands
160  *
161  * This function configures a pair of LUT commands in the specified LUT register.
162  * LUT sequences start at index multiple of 4 and can have up to 8 commands
163  *
164  * @param instance     QuadSPI peripheral instance number
165  * @param LutRegister  Index in physical LUT array
166  * @param operation0   First operation
167  * @param operation1   Second operation
168  * Implements      Qspi_Ip_SetLut_Activity
169  */
170 void Qspi_Ip_SetLut(uint32 instance,
171                     uint8 LutRegister,
172                     Qspi_Ip_InstrOpType operation0,
173                     Qspi_Ip_InstrOpType operation1
174                    );
175 
176 /*!
177  * @brief Configures LUT commands
178  *
179  * This function configures pairs of LUT commands from the specified LUT register.
180  *
181  * @param Instance          QuadSPI peripheral instance number
182  * @param StartLutRegister  Start index in physical LUT array
183  * @param Data              Data to be written in LUT register
184  * @param Size              Size of data buffer
185  */
186 void Qspi_Ip_WriteLuts_Privileged(uint32 Instance,
187                                   uint8 StartLutRegister,
188                                   const uint32 *Data,
189                                   uint8 Size
190                                  );
191 
192 /*!
193  * @brief Sets sequence ID for AHB operations
194  *
195  * @param instance     QuadSPI peripheral instance number
196  * @param seqID        Sequence ID in LUT for read operation
197  * Implements   Qspi_Ip_SetAhbSeqId_Activity
198  */
199 void Qspi_Ip_SetAhbSeqId_Privileged(uint32 instance,
200                                     uint8 seqID
201                                    );
202 
203 /*!
204  * @brief Returns the physical base address of a flash device
205  *
206  * This function returns the physical base address of a flash device, depending on the QSPI connection.
207  * The controller must be initialized prior to calling this function.
208  *
209  * @param instance        QuadSPI peripheral instance number
210  * @param connectionType  Connection of the flash device to QSPI
211  */
212 uint32 Qspi_Ip_GetBaseAdress(uint32 instance,
213                              Qspi_Ip_ConnectionType connectionType
214                             );
215 
216 /*!
217  * @brief Launches a simple IP command
218  *
219  * @param instance     QuadSPI peripheral instance number
220  * @param SeqId        Sequence ID where the command is to be found
221  * @param addr         Address of the target serial flash
222  * @return    Error or success status returned by API
223  */
224 Qspi_Ip_StatusType Qspi_Ip_IpCommand(uint32 instance,
225                                      uint8 SeqId,
226                                      uint32 addr
227                                     );
228 
229 
230 /*!
231  * @brief Launches an IP read command
232  *
233  * This function can launch a read command in 3 modes:
234  * - normal read (dataRead != NULL_PTR): Data is read from serial flash and placed in the buffer
235  * - verify (dataRead == NULL_PTR, dataCmp != NULL_PTR): Data is read from serial flash and compared to the reference buffer
236  * - blank check (dataRead == NULL_PTR, dataCmp == NULL_PTR): Data is read from serial flash and compared to 0xFF
237  * Only normal read mode can use DMA.
238  *
239  * @param instance       QuadSPI peripheral instance number
240  * @param SeqId          Sequence ID where the command is to be found
241  * @param addr           Start address for read operation in serial flash
242  * @param dataRead       Buffer where to store read data
243  * @param dataCmp        Buffer to be compared to read data
244  * @param size           Size of data buffer
245  * @return    Error or success status returned by API
246  */
247 Qspi_Ip_StatusType Qspi_Ip_IpRead(uint32 instance,
248                                   uint8 SeqId,
249                                   uint32 addr,
250                                   uint8 * dataRead,
251                                   const uint8 * dataCmp,
252                                   uint32 size
253                                  );
254 
255 
256 /*!
257  * @brief Launches an IP write command
258  *
259  * @param instance       QuadSPI peripheral instance number
260  * @param SeqId          Sequence ID where the command is to be found
261  * @param addr           Start address for write operation in serial flash
262  * @param data           Data to be programmed in flash
263  * @param size           Size of data buffer
264  * @return    Error or success status returned by API
265  */
266 Qspi_Ip_StatusType Qspi_Ip_IpWrite(uint32 instance,
267                                    uint8 SeqId,
268                                    uint32 addr,
269                                    const uint8 * data,
270                                    uint32 size
271                                   );
272 
273 
274 #define MEM_43_EXFLS_STOP_SEC_CODE
275 #include "Mem_43_EXFLS_MemMap.h"
276 
277 #endif /* (QSPI_IP_MEM_INSTANCE_COUNT > 0) */
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 
283 /** @} */
284 
285 #endif /* QSPI_IP_CONTROLLER_H */
286 
287