S32 SDK
flash_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 -2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
38 #ifndef FLASH_DRIVER_H
39 #define FLASH_DRIVER_H
40 
41 #include <stdbool.h>
42 #include <stddef.h>
43 #include "status.h"
44 #include "device_registers.h"
45 
53 /*******************************************************************************
54  * FTFx - Register instance definitions
55  *******************************************************************************/
56 /*******************************************************************************
57  * FTFE
58  *******************************************************************************/
59 #ifdef FTFE
60 #define FTFx_BASE FTFE_BASE
61 #define FTFx_FSTAT FTFE->FSTAT
62 #define FTFx_FCNFG FTFE->FCNFG
63 #define FTFx_FSEC FTFE->FSEC
64 #define FTFx_FOPT FTFE->FOPT
65 #define FTFx_FCCOB3 FTFE->FCCOB[0]
66 #define FTFx_FCCOB2 FTFE->FCCOB[1]
67 #define FTFx_FCCOB1 FTFE->FCCOB[2]
68 #define FTFx_FCCOB0 FTFE->FCCOB[3]
69 #define FTFx_FCCOB7 FTFE->FCCOB[4]
70 #define FTFx_FCCOB6 FTFE->FCCOB[5]
71 #define FTFx_FCCOB5 FTFE->FCCOB[6]
72 #define FTFx_FCCOB4 FTFE->FCCOB[7]
73 #define FTFx_FCCOBB FTFE->FCCOB[8]
74 #define FTFx_FCCOBA FTFE->FCCOB[9]
75 #define FTFx_FCCOB9 FTFE->FCCOB[10]
76 #define FTFx_FCCOB8 FTFE->FCCOB[11]
77 #define FTFx_FPROT3 FTFE->FPROT[0]
78 #define FTFx_FPROT2 FTFE->FPROT[1]
79 #define FTFx_FPROT1 FTFE->FPROT[2]
80 #define FTFx_FPROT0 FTFE->FPROT[3]
81 #define FTFx_FEPROT FTFE->FEPROT
82 #define FTFx_FDPROT FTFE->FDPROT
83 #ifdef FTFE_FERSTAT
84 #define FTFx_FERSTAT FTFE_FERSTAT
85 #endif
86 #ifdef FTFE_FERCNFG
87 #define FTFx_FERCNFG FTFE_FERCNFG
88 #endif
89 /* FSTAT Bit Fields */
90 #define FTFx_FSTAT_MGSTAT0_MASK FTFE_FSTAT_MGSTAT0_MASK
91 #define FTFx_FSTAT_MGSTAT0_SHIFT FTFE_FSTAT_MGSTAT0_SHIFT
92 #define FTFx_FSTAT_MGSTAT0_WIDTH FTFE_FSTAT_MGSTAT0_WIDTH
93 #define FTFx_FSTAT_MGSTAT0(x) FTFE_FSTAT_MGSTAT0(x)
94 #define FTFx_FSTAT_FPVIOL_MASK FTFE_FSTAT_FPVIOL_MASK
95 #define FTFx_FSTAT_FPVIOL_SHIFT FTFE_FSTAT_FPVIOL_SHIFT
96 #define FTFx_FSTAT_FPVIOL_WIDTH FTFE_FSTAT_FPVIOL_WIDTH
97 #define FTFx_FSTAT_FPVIOL(x) FTFE_FSTAT_FPVIOL(x)
98 #define FTFx_FSTAT_ACCERR_MASK FTFE_FSTAT_ACCERR_MASK
99 #define FTFx_FSTAT_ACCERR_SHIFT FTFE_FSTAT_ACCERR_SHIFT
100 #define FTFx_FSTAT_ACCERR_WIDTH FTFE_FSTAT_ACCERR_WIDTH
101 #define FTFx_FSTAT_ACCERR(x) FTFE_FSTAT_ACCERR(x)
102 #define FTFx_FSTAT_RDCOLERR_MASK FTFE_FSTAT_RDCOLERR_MASK
103 #define FTFx_FSTAT_RDCOLERR_SHIFT FTFE_FSTAT_RDCOLERR_SHIFT
104 #define FTFx_FSTAT_RDCOLERR_WIDTH FTFE_FSTAT_RDCOLERR_WIDTH
105 #define FTFx_FSTAT_RDCOLERR(x) FTFE_FSTAT_RDCOLERR(x)
106 #define FTFx_FSTAT_CCIF_MASK FTFE_FSTAT_CCIF_MASK
107 #define FTFx_FSTAT_CCIF_SHIFT FTFE_FSTAT_CCIF_SHIFT
108 #define FTFx_FSTAT_CCIF_WIDTH FTFE_FSTAT_CCIF_WIDTH
109 #define FTFx_FSTAT_CCIF(x) FTFE_FSTAT_CCIF(x)
110 /* FCNFG Bit Fields */
111 #define FTFx_FCNFG_EEERDY_MASK FTFE_FCNFG_EEERDY_MASK
112 #define FTFx_FCNFG_EEERDY_SHIFT FTFE_FCNFG_EEERDY_SHIFT
113 #define FTFx_FCNFG_EEERDY_WIDTH FTFE_FCNFG_EEERDY_WIDTH
114 #define FTFx_FCNFG_EEERDY(x) FTFE_FCNFG_EEERDY(x)
115 #define FTFx_FCNFG_RAMRDY_MASK FTFE_FCNFG_RAMRDY_MASK
116 #define FTFx_FCNFG_RAMRDY_SHIFT FTFE_FCNFG_RAMRDY_SHIFT
117 #define FTFx_FCNFG_RAMRDY_WIDTH FTFE_FCNFG_RAMRDY_WIDTH
118 #define FTFx_FCNFG_RAMRDY(x) FTFE_FCNFG_RAMRDY(x)
119 #define FTFx_FCNFG_PFLSH_MASK FTFE_FCNFG_PFLSH_MASK
120 #define FTFx_FCNFG_PFLSH_SHIFT FTFE_FCNFG_PFLSH_SHIFT
121 #define FTFx_FCNFG_PFLSH_WIDTH FTFE_FCNFG_PFLSH_WIDTH
122 #define FTFx_FCNFG_PFLSH(x) FTFE_FCNFG_PFLSH(x)
123 #define FTFx_FCNFG_ERSSUSP_MASK FTFE_FCNFG_ERSSUSP_MASK
124 #define FTFx_FCNFG_ERSSUSP_SHIFT FTFE_FCNFG_ERSSUSP_SHIFT
125 #define FTFx_FCNFG_ERSSUSP_WIDTH FTFE_FCNFG_ERSSUSP_WIDTH
126 #define FTFx_FCNFG_ERSSUSP(x) FTFE_FCNFG_ERSSUSP(x)
127 #define FTFx_FCNFG_ERSAREQ_MASK FTFE_FCNFG_ERSAREQ_MASK
128 #define FTFx_FCNFG_ERSAREQ_SHIFT FTFE_FCNFG_ERSAREQ_SHIFT
129 #define FTFx_FCNFG_ERSAREQ_WIDTH FTFE_FCNFG_ERSAREQ_WIDTH
130 #define FTFx_FCNFG_ERSAREQ(x) FTFE_FCNFG_ERSAREQ(x)
131 #define FTFx_FCNFG_RDCOLLIE_MASK FTFE_FCNFG_RDCOLLIE_MASK
132 #define FTFx_FCNFG_RDCOLLIE_SHIFT FTFE_FCNFG_RDCOLLIE_SHIFT
133 #define FTFx_FCNFG_RDCOLLIE_WIDTH FTFE_FCNFG_RDCOLLIE_WIDTH
134 #define FTFx_FCNFG_RDCOLLIE(x) FTFE_FCNFG_RDCOLLIE(x)
135 #define FTFx_FCNFG_CCIE_MASK FTFE_FCNFG_CCIE_MASK
136 #define FTFx_FCNFG_CCIE_SHIFT FTFE_FCNFG_CCIE_SHIFT
137 #define FTFx_FCNFG_CCIE_WIDTH FTFE_FCNFG_CCIE_WIDTH
138 #define FTFx_FCNFG_CCIE(x) FTFE_FCNFG_CCIE(x)
139 /* FSEC Bit Fields */
140 #define FTFx_FSEC_SEC_MASK FTFE_FSEC_SEC_MASK
141 #define FTFx_FSEC_SEC_SHIFT FTFE_FSEC_SEC_SHIFT
142 #define FTFx_FSEC_SEC_WIDTH FTFE_FSEC_SEC_WIDTH
143 #define FTFx_FSEC_SEC(x) FTFE_FSEC_SEC(x)
144 #define FTFx_FSEC_FSLACC_MASK FTFE_FSEC_FSLACC_MASK
145 #define FTFx_FSEC_FSLACC_SHIFT FTFE_FSEC_FSLACC_SHIFT
146 #define FTFx_FSEC_FSLACC_WIDTH FTFE_FSEC_FSLACC_WIDTH
147 #define FTFx_FSEC_FSLACC(x) FTFE_FSEC_FSLACC(x)
148 #define FTFx_FSEC_MEEN_MASK FTFE_FSEC_MEEN_MASK
149 #define FTFx_FSEC_MEEN_SHIFT FTFE_FSEC_MEEN_SHIFT
150 #define FTFx_FSEC_MEEN_WIDTH FTFE_FSEC_MEEN_WIDTH
151 #define FTFx_FSEC_MEEN(x) FTFE_FSEC_MEEN(x)
152 #define FTFx_FSEC_KEYEN_MASK FTFE_FSEC_KEYEN_MASK
153 #define FTFx_FSEC_KEYEN_SHIFT FTFE_FSEC_KEYEN_SHIFT
154 #define FTFx_FSEC_KEYEN_WIDTH FTFE_FSEC_KEYEN_WIDTH
155 #define FTFx_FSEC_KEYEN(x) FTFE_FSEC_KEYEN(x)
156 /* FOPT Bit Fields */
157 #define FTFx_FOPT_OPT_MASK FTFE_FOPT_OPT_MASK
158 #define FTFx_FOPT_OPT_SHIFT FTFE_FOPT_OPT_SHIFT
159 #define FTFx_FOPT_OPT_WIDTH FTFE_FOPT_OPT_WIDTH
160 #define FTFx_FOPT_OPT(x) FTFE_FOPT_OPT(x)
161 /* FCCOB Bit Fields */
162 #define FTFx_FCCOB_CCOBn_MASK FTFE_FCCOB_CCOBn_MASK
163 #define FTFx_FCCOB_CCOBn_SHIFT FTFE_FCCOB_CCOBn_SHIFT
164 #define FTFx_FCCOB_CCOBn_WIDTH FTFE_FCCOB_CCOBn_WIDTH
165 #define FTFx_FCCOB_CCOBn(x) FTFE_FCCOB_CCOBn(x)
166 /* FPROT Bit Fields */
167 #define FTFx_FPROT_PROT_MASK FTFE_FPROT_PROT_MASK
168 #define FTFx_FPROT_PROT_SHIFT FTFE_FPROT_PROT_SHIFT
169 #define FTFx_FPROT_PROT_WIDTH FTFE_FPROT_PROT_WIDTH
170 #define FTFx_FPROT_PROT(x) FTFE_FPROT_PROT(x)
171 /* FEPROT Bit Fields */
172 #define FTFx_FEPROT_EPROT_MASK FTFE_FEPROT_EPROT_MASK
173 #define FTFx_FEPROT_EPROT_SHIFT FTFE_FEPROT_EPROT_SHIFT
174 #define FTFx_FEPROT_EPROT_WIDTH FTFE_FEPROT_EPROT_WIDTH
175 #define FTFx_FEPROT_EPROT(x) FTFE_FEPROT_EPROT(x)
176 /* FDPROT Bit Fields */
177 #define FTFx_FDPROT_DPROT_MASK FTFE_FDPROT_DPROT_MASK
178 #define FTFx_FDPROT_DPROT_SHIFT FTFE_FDPROT_DPROT_SHIFT
179 #define FTFx_FDPROT_DPROT_WIDTH FTFE_FDPROT_DPROT_WIDTH
180 #define FTFx_FDPROT_DPROT(x) FTFE_FDPROT_DPROT(x)
181 /* FERSTAT Bit Fields */
182 #ifdef FTFx_FERSTAT
183 #define FTFx_FERSTAT_DFDIF_MASK FTFE_FERSTAT_DFDIF_MASK
184 #define FTFx_FERSTAT_DFDIF_SHIFT FTFE_FERSTAT_DFDIF_SHIFT
185 #define FTFxFERSTAT_DFDIF_WIDTH FTFE_FERSTAT_DFDIF_WIDTH
186 #define FTFx_FERSTAT_DFDIF(x) FTFE_FERSTAT_DFDIF(x)
187 #endif
188 /* FERCNFG Bit Fields */
189 #ifdef FTFx_FERCNFG
190 #define FTFx_FERCNFG_DFDIE_MASK FTFE_FERCNFG_DFDIE_MASK
191 #define FTFx_FERCNFG_DFDIE_SHIFT FTFE_FERCNFG_DFDIE_SHIFT
192 #define FTFx_FERCNFG_DFDIE_WIDTH FTFE_FERCNFG_DFDIE_WIDTH
193 #define FTFx_FERCNFG_DFDIE(x) FTFE_FERCNFG_DFDIE(x)
194 #define FTFx_FERCNFG_FDFD_MASK FTFE_FERCNFG_FDFD_MASK
195 #define FTFx_FERCNFG_FDFD_SHIFT FTFE_FERCNFG_FDFD_SHIFT
196 #define FTFx_FERCNFG_FDFD_WIDTH FTFE_FERCNFG_FDFD_WIDTH
197 #define FTFx_FERCNFG_FDFD(x) FTFE_FERCNFG_FDFD(x)
198 #endif
199 /*******************************************************************************
200  * FTFC
201  *******************************************************************************/
202 #elif defined(FTFC)
203 #define FTFx_BASE FTFC_BASE
204 #define FTFx_FSTAT FTFC->FSTAT
205 #define FTFx_FCNFG FTFC->FCNFG
206 #define FTFx_FSEC FTFC->FSEC
207 #define FTFx_FOPT FTFC->FOPT
208 #define FTFx_FCCOB3 FTFC->FCCOB[0]
209 #define FTFx_FCCOB2 FTFC->FCCOB[1]
210 #define FTFx_FCCOB1 FTFC->FCCOB[2]
211 #define FTFx_FCCOB0 FTFC->FCCOB[3]
212 #define FTFx_FCCOB7 FTFC->FCCOB[4]
213 #define FTFx_FCCOB6 FTFC->FCCOB[5]
214 #define FTFx_FCCOB5 FTFC->FCCOB[6]
215 #define FTFx_FCCOB4 FTFC->FCCOB[7]
216 #define FTFx_FCCOBB FTFC->FCCOB[8]
217 #define FTFx_FCCOBA FTFC->FCCOB[9]
218 #define FTFx_FCCOB9 FTFC->FCCOB[10]
219 #define FTFx_FCCOB8 FTFC->FCCOB[11]
220 #define FTFx_FPROT3 FTFC->FPROT[0]
221 #define FTFx_FPROT2 FTFC->FPROT[1]
222 #define FTFx_FPROT1 FTFC->FPROT[2]
223 #define FTFx_FPROT0 FTFC->FPROT[3]
224 #define FTFx_FEPROT FTFC->FEPROT
225 #define FTFx_FDPROT FTFC->FDPROT
226 #define FTFx_FCSESTAT FTFC->FCSESTAT
227 #ifdef FTFC_FERSTAT
228 #define FTFx_FERSTAT FTFC_FERSTAT
229 #endif
230 #ifdef FTFC_FERCNFG
231 #define FTFx_FERCNFG FTFC_FERCNFG
232 #endif
233 /* FSTAT Bit Fields */
234 #define FTFx_FSTAT_MGSTAT0_MASK FTFC_FSTAT_MGSTAT0_MASK
235 #define FTFx_FSTAT_MGSTAT0_SHIFT FTFC_FSTAT_MGSTAT0_SHIFT
236 #define FTFx_FSTAT_MGSTAT0_WIDTH FTFC_FSTAT_MGSTAT0_WIDTH
237 #define FTFx_FSTAT_MGSTAT0(x) FTFC_FSTAT_MGSTAT0(x)
238 #define FTFx_FSTAT_FPVIOL_MASK FTFC_FSTAT_FPVIOL_MASK
239 #define FTFx_FSTAT_FPVIOL_SHIFT FTFC_FSTAT_FPVIOL_SHIFT
240 #define FTFx_FSTAT_FPVIOL_WIDTH FTFC_FSTAT_FPVIOL_WIDTH
241 #define FTFx_FSTAT_FPVIOL(x) FTFC_FSTAT_FPVIOL(x)
242 #define FTFx_FSTAT_ACCERR_MASK FTFC_FSTAT_ACCERR_MASK
243 #define FTFx_FSTAT_ACCERR_SHIFT FTFC_FSTAT_ACCERR_SHIFT
244 #define FTFx_FSTAT_ACCERR_WIDTH FTFC_FSTAT_ACCERR_WIDTH
245 #define FTFx_FSTAT_ACCERR(x) FTFC_FSTAT_ACCERR(x)
246 #define FTFx_FSTAT_RDCOLERR_MASK FTFC_FSTAT_RDCOLERR_MASK
247 #define FTFx_FSTAT_RDCOLERR_SHIFT FTFC_FSTAT_RDCOLERR_SHIFT
248 #define FTFx_FSTAT_RDCOLERR_WIDTH FTFC_FSTAT_RDCOLERR_WIDTH
249 #define FTFx_FSTAT_RDCOLERR(x) FTFC_FSTAT_RDCOLERR(x)
250 #define FTFx_FSTAT_CCIF_MASK FTFC_FSTAT_CCIF_MASK
251 #define FTFx_FSTAT_CCIF_SHIFT FTFC_FSTAT_CCIF_SHIFT
252 #define FTFx_FSTAT_CCIF_WIDTH FTFC_FSTAT_CCIF_WIDTH
253 #define FTFx_FSTAT_CCIF(x) FTFC_FSTAT_CCIF(x)
254 /* FCNFG Bit Fields */
255 #define FTFx_FCNFG_EEERDY_MASK FTFC_FCNFG_EEERDY_MASK
256 #define FTFx_FCNFG_EEERDY_SHIFT FTFC_FCNFG_EEERDY_SHIFT
257 #define FTFx_FCNFG_EEERDY_WIDTH FTFC_FCNFG_EEERDY_WIDTH
258 #define FTFx_FCNFG_EEERDY(x) FTFC_FCNFG_EEERDY(x)
259 #define FTFx_FCNFG_RAMRDY_MASK FTFC_FCNFG_RAMRDY_MASK
260 #define FTFx_FCNFG_RAMRDY_SHIFT FTFC_FCNFG_RAMRDY_SHIFT
261 #define FTFx_FCNFG_RAMRDY_WIDTH FTFC_FCNFG_RAMRDY_WIDTH
262 #define FTFx_FCNFG_RAMRDY(x) FTFC_FCNFG_RAMRDY(x)
263 #define FTFx_FCNFG_ERSSUSP_MASK FTFC_FCNFG_ERSSUSP_MASK
264 #define FTFx_FCNFG_ERSSUSP_SHIFT FTFC_FCNFG_ERSSUSP_SHIFT
265 #define FTFx_FCNFG_ERSSUSP_WIDTH FTFC_FCNFG_ERSSUSP_WIDTH
266 #define FTFx_FCNFG_ERSSUSP(x) FTFC_FCNFG_ERSSUSP(x)
267 #define FTFx_FCNFG_ERSAREQ_MASK FTFC_FCNFG_ERSAREQ_MASK
268 #define FTFx_FCNFG_ERSAREQ_SHIFT FTFC_FCNFG_ERSAREQ_SHIFT
269 #define FTFx_FCNFG_ERSAREQ_WIDTH FTFC_FCNFG_ERSAREQ_WIDTH
270 #define FTFx_FCNFG_ERSAREQ(x) FTFC_FCNFG_ERSAREQ(x)
271 #define FTFx_FCNFG_RDCOLLIE_MASK FTFC_FCNFG_RDCOLLIE_MASK
272 #define FTFx_FCNFG_RDCOLLIE_SHIFT FTFC_FCNFG_RDCOLLIE_SHIFT
273 #define FTFx_FCNFG_RDCOLLIE_WIDTH FTFC_FCNFG_RDCOLLIE_WIDTH
274 #define FTFx_FCNFG_RDCOLLIE(x) FTFC_FCNFG_RDCOLLIE(x)
275 #define FTFx_FCNFG_CCIE_MASK FTFC_FCNFG_CCIE_MASK
276 #define FTFx_FCNFG_CCIE_SHIFT FTFC_FCNFG_CCIE_SHIFT
277 #define FTFx_FCNFG_CCIE_WIDTH FTFC_FCNFG_CCIE_WIDTH
278 #define FTFx_FCNFG_CCIE(x) FTFC_FCNFG_CCIE(x)
279 /* FSEC Bit Fields */
280 #define FTFx_FSEC_SEC_MASK FTFC_FSEC_SEC_MASK
281 #define FTFx_FSEC_SEC_SHIFT FTFC_FSEC_SEC_SHIFT
282 #define FTFx_FSEC_SEC_WIDTH FTFC_FSEC_SEC_WIDTH
283 #define FTFx_FSEC_SEC(x) FTFC_FSEC_SEC(x)
284 #define FTFx_FSEC_FSLACC_MASK FTFC_FSEC_FSLACC_MASK
285 #define FTFx_FSEC_FSLACC_SHIFT FTFC_FSEC_FSLACC_SHIFT
286 #define FTFx_FSEC_FSLACC_WIDTH FTFC_FSEC_FSLACC_WIDTH
287 #define FTFx_FSEC_FSLACC(x) FTFC_FSEC_FSLACC(x)
288 #define FTFx_FSEC_MEEN_MASK FTFC_FSEC_MEEN_MASK
289 #define FTFx_FSEC_MEEN_SHIFT FTFC_FSEC_MEEN_SHIFT
290 #define FTFx_FSEC_MEEN_WIDTH FTFC_FSEC_MEEN_WIDTH
291 #define FTFx_FSEC_MEEN(x) FTFC_FSEC_MEEN(x)
292 #define FTFx_FSEC_KEYEN_MASK FTFC_FSEC_KEYEN_MASK
293 #define FTFx_FSEC_KEYEN_SHIFT FTFC_FSEC_KEYEN_SHIFT
294 #define FTFx_FSEC_KEYEN_WIDTH FTFC_FSEC_KEYEN_WIDTH
295 #define FTFx_FSEC_KEYEN(x) FTFC_FSEC_KEYEN(x)
296 /* FOPT Bit Fields */
297 #define FTFx_FOPT_OPT_MASK FTFC_FOPT_OPT_MASK
298 #define FTFx_FOPT_OPT_SHIFT FTFC_FOPT_OPT_SHIFT
299 #define FTFx_FOPT_OPT_WIDTH FTFC_FOPT_OPT_WIDTH
300 #define FTFx_FOPT_OPT(x) FTFC_FOPT_OPT(x)
301 /* FCCOB Bit Fields */
302 #define FTFx_FCCOB_CCOBn_MASK FTFC_FCCOB_CCOBn_MASK
303 #define FTFx_FCCOB_CCOBn_SHIFT FTFC_FCCOB_CCOBn_SHIFT
304 #define FTFx_FCCOB_CCOBn_WIDTH FTFC_FCCOB_CCOBn_WIDTH
305 #define FTFx_FCCOB_CCOBn(x) FTFC_FCCOB_CCOBn(x)
306 /* FPROT Bit Fields */
307 #define FTFx_FPROT_PROT_MASK FTFC_FPROT_PROT_MASK
308 #define FTFx_FPROT_PROT_SHIFT FTFC_FPROT_PROT_SHIFT
309 #define FTFx_FPROT_PROT_WIDTH FTFC_FPROT_PROT_WIDTH
310 #define FTFx_FPROT_PROT(x) FTFC_FPROT_PROT(x)
311 /* FEPROT Bit Fields */
312 #define FTFx_FEPROT_EPROT_MASK FTFC_FEPROT_EPROT_MASK
313 #define FTFx_FEPROT_EPROT_SHIFT FTFC_FEPROT_EPROT_SHIFT
314 #define FTFx_FEPROT_EPROT_WIDTH FTFC_FEPROT_EPROT_WIDTH
315 #define FTFx_FEPROT_EPROT(x) FTFC_FEPROT_EPROT(x)
316 /* FDPROT Bit Fields */
317 #define FTFx_FDPROT_DPROT_MASK FTFC_FDPROT_DPROT_MASK
318 #define FTFx_FDPROT_DPROT_SHIFT FTFC_FDPROT_DPROT_SHIFT
319 #define FTFx_FDPROT_DPROT_WIDTH FTFC_FDPROT_DPROT_WIDTH
320 #define FTFx_FDPROT_DPROT(x) FTFC_FDPROT_DPROT(x)
321 /* FCSESTAT Bit Fields */
322 #define FTFX_FCSESTAT_IDB_MASK FTFC_FCSESTAT_IDB_MASK
323 #define FTFX_FCSESTAT_IDB_SHIFT FTFC_FCSESTAT_IDB_SHIFT
324 #define FTFX_FCSESTAT_IDB_WIDTH FTFC_FCSESTAT_IDB_WIDTH
325 #define FTFX_FCSESTAT_IDB(x) FTFC_FCSESTAT_IDB(x)
326 #define FTFX_FCSESTAT_EDB_MASK FTFC_FCSESTAT_EDB_MASK
327 #define FTFX_FCSESTAT_EDB_SHIFT FTFC_FCSESTAT_EDB_SHIFT
328 #define FTFX_FCSESTAT_EDB_WIDTH FTFC_FCSESTAT_EDB_WIDTH
329 #define FTFX_FCSESTAT_EDB(x) FTFC_FCSESTAT_EDB(x)
330 #define FTFX_FCSESTAT_RIN_MASK FTFC_FCSESTAT_RIN_MASK
331 #define FTFX_FCSESTAT_RIN_SHIFT FTFC_FCSESTAT_RIN_SHIFT
332 #define FTFX_FCSESTAT_RIN_WIDTH FTFC_FCSESTAT_RIN_WIDTH
333 #define FTFX_FCSESTAT_RIN(x) FTFC_FCSESTAT_RIN(x)
334 #define FTFX_FCSESTAT_BOK_MASK FTFC_FCSESTAT_BOK_MASK
335 #define FTFX_FCSESTAT_BOK_SHIFT FTFC_FCSESTAT_BOK_SHIFT
336 #define FTFX_FCSESTAT_BOK_WIDTH FTFC_FCSESTAT_BOK_WIDTH
337 #define FTFX_FCSESTAT_BOK(x) FTFC_FCSESTAT_BOK(x)
338 #define FTFX_FCSESTAT_BFN_MASK FTFC_FCSESTAT_BFN_MASK
339 #define FTFX_FCSESTAT_BFN_SHIFT FTFC_FCSESTAT_BFN_SHIFT
340 #define FTFX_FCSESTAT_BFN_WIDTH FTFC_FCSESTAT_BFN_WIDTH
341 #define FTFX_FCSESTAT_BFN(x) FTFC_FCSESTAT_BFN(x)
342 #define FTFX_FCSESTAT_BIN_MASK FTFC_FCSESTAT_BIN_MASK
343 #define FTFX_FCSESTAT_BIN_SHIFT FTFC_FCSESTAT_BIN_SHIFT
344 #define FTFX_FCSESTAT_BIN_WIDTH FTFC_FCSESTAT_BIN_WIDTH
345 #define FTFX_FCSESTAT_BIN(x) FTFC_FCSESTAT_BIN(x)
346 #define FTFX_FCSESTAT_SB_MASK FTFC_FCSESTAT_SB_MASK
347 #define FTFX_FCSESTAT_SB_SHIFT FTFC_FCSESTAT_SB_SHIFT
348 #define FTFX_FCSESTAT_SB_WIDTH FTFC_FCSESTAT_SB_WIDTH
349 #define FTFX_FCSESTAT_SB(x) FTFC_FCSESTAT_SB(x)
350 #define FTFX_FCSESTAT_BSY_MASK FTFC_FCSESTAT_BSY_MASK
351 #define FTFX_FCSESTAT_BSY_SHIFT FTFC_FCSESTAT_BSY_SHIFT
352 #define FTFX_FCSESTAT_BSY_WIDTH FTFC_FCSESTAT_BSY_WIDTH
353 #define FTFX_FCSESTAT_BSY(x) FTFC_FCSESTAT_BSY(x)
354 /* FERSTAT Bit Fields */
355 #ifdef FTFx_FERSTAT
356 #define FTFx_FERSTAT_DFDIF_MASK FTFC_FERSTAT_DFDIF_MASK
357 #define FTFx_FERSTAT_DFDIF_SHIFT FTFC_FERSTAT_DFDIF_SHIFT
358 #define FTFxFERSTAT_DFDIF_WIDTH FTFC_FERSTAT_DFDIF_WIDTH
359 #define FTFx_FERSTAT_DFDIF(x) FTFC_FERSTAT_DFDIF(x)
360 #endif
361 /* FERCNFG Bit Fields */
362 #ifdef FTFx_FERCNFG
363 #define FTFx_FERCNFG_DFDIE_MASK FTFC_FERCNFG_DFDIE_MASK
364 #define FTFx_FERCNFG_DFDIE_SHIFT FTFC_FERCNFG_DFDIE_SHIFT
365 #define FTFx_FERCNFG_DFDIE_WIDTH FTFC_FERCNFG_DFDIE_WIDTH
366 #define FTFx_FERCNFG_DFDIE(x) FTFC_FERCNFG_DFDIE(x)
367 #define FTFx_FERCNFG_FDFD_MASK FTFC_FERCNFG_FDFD_MASK
368 #define FTFx_FERCNFG_FDFD_SHIFT FTFC_FERCNFG_FDFD_SHIFT
369 #define FTFx_FERCNFG_FDFD_WIDTH FTFC_FERCNFG_FDFD_WIDTH
370 #define FTFx_FERCNFG_FDFD(x) FTFC_FERCNFG_FDFD(x)
371 #endif
372 
373 #else /* ifndef FTFE */
374 #endif /* ifdef FTFE */
375 
376 
377 #define CLEAR_FTFx_FSTAT_ERROR_BITS FTFx_FSTAT = (uint8_t)(FTFx_FSTAT_FPVIOL_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_RDCOLERR_MASK)
378 
379 /* Word size 2 bytes */
380 #define FTFx_WORD_SIZE 0x0002U
381 /* Long word size 4 bytes */
382 #define FTFx_LONGWORD_SIZE 0x0004U
383 /* Phrase size 8 bytes */
384 #define FTFx_PHRASE_SIZE 0x0008U
385 /* Double-phrase size 16 bytes */
386 #define FTFx_DPHRASE_SIZE 0x0010U
387 
388 /* FCCOB offset address to store resource code */
389 #if (FEATURE_FLS_PF_BLOCK_WRITE_UNIT_SIZE == FTFx_PHRASE_SIZE)
390 #define FTFx_RSRC_CODE_REG FTFx_FCCOB4
391 #else
392 #define FTFx_RSRC_CODE_REG FTFx_FCCOB8
393 #endif
394 
395 /*******************************************************************************
396 * Flash hardware algorithm operation commands
397 *******************************************************************************/
398 #define FTFx_VERIFY_BLOCK 0x00U
399 #define FTFx_VERIFY_SECTION 0x01U
400 #define FTFx_PROGRAM_CHECK 0x02U
401 #define FTFx_READ_RESOURCE 0x03U
402 #define FTFx_PROGRAM_LONGWORD 0x06U
403 #define FTFx_PROGRAM_PHRASE 0x07U
404 #define FTFx_ERASE_BLOCK 0x08U
405 #define FTFx_ERASE_SECTOR 0x09U
406 #define FTFx_PROGRAM_SECTION 0x0BU
407 #define FTFx_VERIFY_ALL_BLOCK 0x40U
408 #define FTFx_READ_ONCE 0x41U
409 #define FTFx_PROGRAM_ONCE 0x43U
410 #define FTFx_ERASE_ALL_BLOCK 0x44U
411 #define FTFx_SECURITY_BY_PASS 0x45U
412 #define FTFx_PFLASH_SWAP 0x46U
413 #define FTFx_ERASE_ALL_BLOCK_UNSECURE 0x49U
414 #define FTFx_PROGRAM_PARTITION 0x80U
415 #define FTFx_SET_EERAM 0x81U
416 
417 
423 #define FTFx_SWAP_SET_INDICATOR_ADDR 0x01U
424 
425 #define FTFx_SWAP_SET_IN_PREPARE 0x02U
426 
427 #define FTFx_SWAP_SET_IN_COMPLETE 0x04U
428 
429 #define FTFx_SWAP_REPORT_STATUS 0x08U
430 
437 #define FTFx_SWAP_UNINIT 0x00U
438 
439 #define FTFx_SWAP_READY 0x01U
440 
441 #define FTFx_SWAP_UPDATE 0x02U
442 
443 #define FTFx_SWAP_UPDATE_ERASED 0x03U
444 
445 #define FTFx_SWAP_COMPLETE 0x04U
446 
449 #define RESUME_WAIT_CNT 0x20U
450 
451 #define SUSPEND_WAIT_CNT 0x40U
452 
453 #if (FEATURE_FLS_IS_FTFE == 1U)
454 #define DFLASH_IFR_READRESOURCE_ADDRESS 0x8003F8U
455 #else /* FEATURE_FLASH_IS_FTFL == 1 or FEATURE_FLASH_IS_FTFA == 1 */
456 #define DFLASH_IFR_READRESOURCE_ADDRESS 0x8000FCU
457 #endif
458 
459 #define GET_BIT_0_7(value) ((uint8_t)(((uint32_t)(value)) & 0xFFU))
460 #define GET_BIT_8_15(value) ((uint8_t)((((uint32_t)(value)) >> 8) & 0xFFU))
461 #define GET_BIT_16_23(value) ((uint8_t)((((uint32_t)(value)) >> 16) & 0xFFU))
462 #define GET_BIT_24_31(value) ((uint8_t)(((uint32_t)(value)) >> 24))
463 
464 /* Flash security status */
465 #define FLASH_SECURITY_STATE_KEYEN 0x80U
466 #define FLASH_SECURITY_STATE_UNSECURED 0x02U
467 
468 /* CSEc user key size */
469 #define CSE_KEY_SIZE_CODE_MAX 0x03U
470 
481 typedef enum
482 {
483  EEE_ENABLE = 0x00U,
484  EEE_QUICK_WRITE = 0x55U,
487  EEE_DISABLE = 0xFFU,
489 
495 #define FLASH_NOT_SECURE 0x01U
496 
497 #define FLASH_SECURE_BACKDOOR_ENABLED 0x02U
498 
499 #define FLASH_SECURE_BACKDOOR_DISABLED 0x04U
500 
502 /*******************************************************************************
503 * CallBack function period
504 *******************************************************************************/
505 #ifndef FLASH_CALLBACK_CS
506 
512 #define FLASH_CALLBACK_CS 0x0AU
513 #endif
514 
515 /*******************************************************************************
516 * Null Callback function definition
517 *******************************************************************************/
523 #define NULL_CALLBACK ((flash_callback_t)0xFFFFFFFFU)
524 
525 #if FEATURE_FLS_HAS_PF_BLOCK_SWAP
526 
527 #define NULL_SWAP_CALLBACK ((flash_swap_callback_t)0xFFFFFFFFU)
528 #endif
529 
531 /*******************************************************************************
532 * Callback function prototype
533 *******************************************************************************/
540 typedef void (* flash_callback_t)(void);
541 #if FEATURE_FLS_HAS_PF_BLOCK_SWAP
542 
543 typedef bool (* flash_swap_callback_t)(uint8_t function);
544 #endif
545 
546 /*******************************************************************************
547 * Flash SSD Configuration Structure
548 *******************************************************************************/
554 typedef struct
555 {
556  uint32_t PFlashBase;
557  uint32_t PFlashSize;
558  uint32_t DFlashBase;
560  uint32_t EERAMBase;
565 
578 typedef struct
579 {
580  uint32_t PFlashBase;
581  uint32_t PFlashSize;
582  uint32_t DFlashBase;
584  uint32_t DFlashSize;
587  uint32_t EERAMBase;
589  uint32_t EEESize;
594 
600 typedef struct
601 {
602  uint8_t brownOutCode;
604  uint16_t sectorEraseCount;
606 
607 /*******************************************************************************
608 * Function Prototypes for Flash SSD
609 *******************************************************************************/
615 #if defined(__cplusplus)
616 extern "C" {
617 #endif
618 
619 
631 status_t FLASH_DRV_Init(const flash_user_config_t * const pUserConf,
632  flash_ssd_config_t * const pSSDConfig);
633 
651 void FLASH_DRV_GetPFlashProtection(uint32_t * protectStatus);
652 
674 status_t FLASH_DRV_SetPFlashProtection(uint32_t protectStatus);
675 
689 void FLASH_DRV_GetSecurityState(uint8_t * securityState);
690 
706  const uint8_t * keyBuffer);
707 
722 
741  uint8_t marginLevel);
742 
761  uint32_t dest,
762  uint32_t size);
763 
784  uint32_t dest,
785  uint16_t number,
786  uint8_t marginLevel);
787 
795 void FLASH_DRV_EraseSuspend(void);
796 
804 void FLASH_DRV_EraseResume(void);
805 
822  uint8_t recordIndex,
823  uint8_t * pDataArray);
824 
843  uint8_t recordIndex,
844  const uint8_t * pDataArray);
845 
846 #if FEATURE_FLS_HAS_READ_RESOURCE_CMD
847 
864 status_t FLASH_DRV_ReadResource(const flash_ssd_config_t * pSSDConfig,
865  uint32_t dest,
866  uint8_t * pDataArray,
867  uint8_t resourceSelectCode);
868 #endif
869 
890  uint32_t dest,
891  uint32_t size,
892  const uint8_t * pData);
893 
916  uint32_t dest,
917  uint32_t size,
918  const uint8_t * pExpectedData,
919  uint32_t * pFailAddr,
920  uint8_t marginLevel);
921 
943  uint32_t dest,
944  uint32_t size,
945  uint32_t * pSum);
946 
947 #if FEATURE_FLS_HAS_PROGRAM_SECTION_CMD
948 
972 status_t FLASH_DRV_ProgramSection(const flash_ssd_config_t * pSSDConfig,
973  uint32_t dest,
974  uint16_t number);
975 #endif
976 
977 #if FEATURE_FLS_HAS_ERASE_BLOCK_CMD
978 
992 status_t FLASH_DRV_EraseBlock(const flash_ssd_config_t * pSSDConfig,
993  uint32_t dest);
994 #endif
995 
996 #if FEATURE_FLS_HAS_READ_1S_BLOCK_CMD
997 
1016 status_t FLASH_DRV_VerifyBlock(const flash_ssd_config_t * pSSDConfig,
1017  uint32_t dest,
1018  uint8_t marginLevel);
1019 #endif
1020 
1021 #if FEATURE_FLS_HAS_FLEX_NVM
1022 
1044 status_t FLASH_DRV_GetEERAMProtection(uint8_t * protectStatus);
1045 
1070 status_t FLASH_DRV_SetEERAMProtection(uint8_t protectStatus);
1071 
1100 status_t FLASH_DRV_SetFlexRamFunction(const flash_ssd_config_t * pSSDConfig,
1101  flash_flexRam_function_control_code_t flexRamFuncCode,
1102  uint16_t byteOfQuickWrite,
1103  flash_eeprom_status_t * const pEEPROMStatus);
1104 
1130 status_t FLASH_DRV_EEEWrite(const flash_ssd_config_t * pSSDConfig,
1131  uint32_t dest,
1132  uint32_t size,
1133  const uint8_t * pData);
1134 
1168 status_t FLASH_DRV_DEFlashPartition(const flash_ssd_config_t * pSSDConfig,
1169  uint8_t uEEEDataSizeCode,
1170  uint8_t uDEPartitionCode,
1171  uint8_t uCSEcKeySize,
1172  bool uSFE,
1173  bool flexRamEnableLoadEEEData);
1174 
1195 status_t FLASH_DRV_GetDFlashProtection(const flash_ssd_config_t * pSSDConfig,
1196  uint8_t * protectStatus);
1197 
1219 status_t FLASH_DRV_SetDFlashProtection(const flash_ssd_config_t * pSSDConfig,
1220  uint8_t protectStatus);
1221 #endif /* End of FEATURE_FLS_HAS_FLEX_NVM */
1222 
1223 #if FEATURE_FLS_HAS_PF_BLOCK_SWAP
1224 
1283 status_t FLASH_DRV_PFlashSwap(const flash_ssd_config_t * pSSDConfig,
1284  uint32_t addr,
1285  flash_swap_callback_t pSwapCallback);
1286 
1316 status_t FLASH_DRV_PFlashSwapCtl(const flash_ssd_config_t * pSSDConfig,
1317  uint32_t addr,
1318  uint8_t swapcmd,
1319  uint8_t * pCurrentSwapMode,
1320  uint8_t * pCurrentSwapBlockStatus,
1321  uint8_t * pNextSwapBlockStatus);
1322 
1323 #endif /* End of FEATURE_FLS_HAS_PF_BLOCK_SWAP */
1324 
1325 #if FEATURE_FLS_HAS_ERASE_ALL_BLOCKS_UNSECURE_CMD
1326 
1338 status_t FLASH_DRV_EraseAllBlockUnsecure(const flash_ssd_config_t * pSSDConfig);
1339 
1340 #endif
1341 
1342 #if defined(__cplusplus)
1343 }
1344 #endif
1345  /* End of Flash driver APIs*/ /* End of addtogroup flash_driver */
1348 
1349 #endif /* FLASH_DRIVER_H */
status_t FLASH_DRV_VerifyAllBlock(const flash_ssd_config_t *pSSDConfig, uint8_t marginLevel)
Flash verify all blocks.
void FLASH_DRV_EraseResume(void)
Flash erase resume.
flash_callback_t CallBack
Definition: flash_driver.h:562
void FLASH_DRV_EraseSuspend(void)
Flash erase suspend.
status_t FLASH_DRV_EraseSector(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size)
Flash erase sector.
status_t FLASH_DRV_Init(const flash_user_config_t *const pUserConf, flash_ssd_config_t *const pSSDConfig)
Initializes Flash.
void(* flash_callback_t)(void)
Call back function pointer data type.
Definition: flash_driver.h:540
status_t FLASH_DRV_Program(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, const uint8_t *pData)
Flash program.
flash_flexRam_function_control_code_t
FlexRAM Function control Code.
Definition: flash_driver.h:481
void FLASH_DRV_GetPFlashProtection(uint32_t *protectStatus)
P-Flash get protection.
status_t FLASH_DRV_ProgramCheck(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, const uint8_t *pExpectedData, uint32_t *pFailAddr, uint8_t marginLevel)
Flash program check.
status_t FLASH_DRV_CheckSum(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint32_t size, uint32_t *pSum)
Calculates check sum.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
EEPROM status structure.
Definition: flash_driver.h:600
uint16_t numOfRecordReqMaintain
Definition: flash_driver.h:603
status_t FLASH_DRV_SetPFlashProtection(uint32_t protectStatus)
P-Flash set protection.
status_t FLASH_DRV_VerifySection(const flash_ssd_config_t *pSSDConfig, uint32_t dest, uint16_t number, uint8_t marginLevel)
Flash verify section.
status_t FLASH_DRV_ReadOnce(const flash_ssd_config_t *pSSDConfig, uint8_t recordIndex, uint8_t *pDataArray)
Flash read once.
Flash SSD Configuration Structure.
Definition: flash_driver.h:578
status_t FLASH_DRV_EraseAllBlock(const flash_ssd_config_t *pSSDConfig)
Flash erase all blocks.
Flash User Configuration Structure.
Definition: flash_driver.h:554
status_t FLASH_DRV_SecurityBypass(const flash_ssd_config_t *pSSDConfig, const uint8_t *keyBuffer)
Flash security bypass.
status_t FLASH_DRV_ProgramOnce(const flash_ssd_config_t *pSSDConfig, uint8_t recordIndex, const uint8_t *pDataArray)
Flash program once.
void FLASH_DRV_GetSecurityState(uint8_t *securityState)
Flash get security state.