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