1 /*
2  * Copyright 2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 #ifndef FSL_EEPROM_EMULATION_H_
8 #define FSL_EEPROM_EMULATION_H_
9 
10 #include "fsl_common.h"
11 
12 /*!
13  * @addtogroup eeprom_emulation
14  * @{
15  */
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 
21 /*! @name Driver version */
22 /*! @{ */
23 /*! @brief EEPROM Emulation driver version. */
24 #define EE_EEPROM_EMULATION_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
25 /*! @} */
26 
27 typedef struct _eeprom_emulation_data_record_t
28 {
29     uint32_t dataAddr; /* The address of data source */
30     uint16_t dataID;   /* The unique data ID */
31 } eeprom_emulation_data_record_t;
32 
33 /* Monitoring states */
34 typedef enum
35 {
36     IDLE = 0x00u,
37     BUSY = 0x01u,
38     DONE = 0x02u,
39     FAIL = 0x03u
40 } eeprom_emulation_state_type_t;
41 
42 /*! @brief Eeprom emulation driver state information.
43  *
44  * An instance of this structure is allocated by the user of the eeprom emulation driver and
45  * passed into each of the driver APIs.
46  */
47 typedef struct _eeprom_emulation_config
48 {
49     uint32_t ftfxProgramSize;  /* check align of program function */
50     uint32_t ftfxRD1SECSize;   /* check align of verify section on PFlash function */
51     uint32_t ftfxPGMCheckSize; /* check align of program check function */
52 
53     uint32_t flashStartAddress; /* base address of flash module in byte address space */
54     uint32_t flashSectorSize;   /* flash sector size */
55     uint8_t flashReadMargin;    /* Flash margin read settings */
56 
57     uint32_t eeStartAddress;  /* Start address of Eeprom emulation in byte */
58     uint32_t eeSectorSize;    /* Sector size of Eeprom emulation in bytes. It can be one or multiply consecutive flash
59                                  sectors */
60     uint32_t eeDataValueSize; /* The length of raw data for each record in byte */
61     uint32_t eeActualReadySectors; /* Number of alternative sectors needed for Round Robin scheme. This number must be
62                                       minimum equal to 2 */
63     uint32_t eeMinActualReadySectors; /* The minimum number alternative of sectors that should be allotted for emulation
64                                          Eeprom */
65     uint32_t eeExtraActiveSectors;    /* Number of extra active sectors needed for emulation */
66     uint32_t eeExtraReadySectors;     /* Number of extra ready sectors needed for emulation */
67     uint32_t eeRetryMax;              /* Number of retry if failed to program sector indicator or erase sector */
68     uint32_t eeSectorActIndOffset;    /*active indicator*/
69     uint32_t eeMemorySize;            /* The total raw data user wants to emulate in byte */
70     uint32_t eccSize;                 /*ECC size*/
71 
72 } eeprom_emulation_config_t;
73 
74 /*! @brief Eeprom emulation handle, users should not touch the content of the handle.*/
75 typedef struct _eeprom_emulation_handle
76 {
77     uint32_t ftfxProgramSize;    /* Program size */
78     uint32_t ftfxProgramCommand; /* Program command*/
79     uint32_t ftfxRD1SECSize;     /* Check align of verify section on PFlash function */
80     uint32_t ftfxBitNumber;      /* Number of bit to make programable size */
81     uint32_t ftfxPGMCheckSize;   /* Check align of program check function */
82 
83     uint32_t flashStartAddress; /* Base address of flash module in byte address space */
84     uint32_t flashSectorSize;   /* Flash sector size */
85     uint8_t flashReadMargin;    /* Flash margin read settings */
86 
87     uint32_t eeStartAddress;  /* Start address of Eeprom emulation in byte */
88     uint32_t eeEndAddress;    /* End address of Flash from EEPROM emulation. */
89     uint32_t eeSectorSize;    /* Sector size of Eeprom emulation in bytes, one or multiply consecutive flash sectors */
90     uint32_t eeDataValueSize; /* The length of raw data for each record in byte */
91     uint32_t eeActualReadySectors; /* Number of alternative sectors needed for Round Robin scheme. This number must be
92                                       minimum equal to 2 */
93     uint32_t eeMinActualReadySectors; /* The minimum number alternative of sectors that should be allotted for emulation
94                                          Eeprom */
95     uint32_t eeExtraActiveSectors;    /* Number of extra active sectors needed for emulation */
96     uint32_t eeExtraReadySectors;     /* Number of extra ready sectors needed for emulation */
97     uint32_t eeReadySectors;          /* Number of ready sectors needed for emulation */
98     uint32_t eeRetryMax;              /* Number of retry if failed to program sector indicator or erase sector */
99     uint32_t eeSectorHeaderSize;      /* Header size */
100     uint32_t eeSectorActIndOffset;    /* Active indicator offset */
101     uint32_t eeSectorDeadIndOffset;   /* Dead indicator offset */
102     uint32_t eeSectorEraseCycleOffset; /* Erase cycle offset */
103     uint32_t eeGapSize;                /* The gap between status and ID field */
104     uint32_t eeRecordIDOffset;         /* Record ID offset */
105     uint32_t eeRecordStatusOffset;     /* Record statue offset */
106     uint32_t eeSectorRecordLength;     /* One record length for emulated eeprom */
107     uint16_t eeMaxRecordNumber;        /* Number of Data Records is calculated if we know the total Data Size. */
108     uint32_t eeMemorySize;             /* The total raw data user wants to emulate in byte */
109     uint32_t eeSectorWaste;            /* Number of bytes in a sector that are not used for emulation */
110     uint32_t eeSectorCapacity;         /* Number of records that can be stored in a sector */
111     uint32_t eeActiveSectorRequired;   /* Number of sectors required to store the specified EEPROM size */
112     uint32_t eeActiveSectors;          /* Total number of ACTIVE sectors alloted */
113     uint32_t eeAllotedSectors; /* Total number of sectors alloted will also include some 'alternative sectors' */
114 
115     uint32_t complementSize; /* Determine the complement size to avoid losing data in case having ECC according to
116                                 different ECC size */
117 
118 } eeprom_emulation_handle_t;
119 
120 /* Callback function prototype */
121 typedef void (*PEE_FUNCPOINTER)(void);
122 
123 /******************************************************************************/
124 /*     MACRO for four functionalitys based on eeprom emulation                */
125 /******************************************************************************/
126 /* Flag to indicate the running mode is Async'ed or Sync'ed */
127 #define EE_USE_ASYNCHRONOUS_MODEL false
128 /* Macro to enable or disable Cache Table */
129 #define EE_CACHETABLE_ENABLE false
130 /* Macro to indicate Callback is enabled or not */
131 #define EE_CALLBACK_ENABLE false
132 
133 /******************************************************************************/
134 /*                               Return codes                                 */
135 /******************************************************************************/
136 #define EE_OK          0x00000000u
137 #define EE_ERR_IDRANGE 0x00000100u
138 #define EE_ERR_SECURE  0x00001000u
139 #define EE_MAKEDEAD_OK 0x00010000u
140 #define EE_NOT_OK      0x10000000u
141 #define EE_ERR_UPDATE  0x20000000u
142 
143 /******************************************************************************/
144 /*             Macros related to sector header and record header              */
145 /******************************************************************************/
146 /* size of each field in record header*/
147 #define EE_RECORD_ID_SIZE     0x02u
148 #define EE_RECORD_STATUS_SIZE 0x02u
149 
150 /* offset byte for ID field */
151 #define ID_LOWBYTE_OFFSET  EE_RECORD_ID_SIZE
152 #define ID_HIGHBYTE_OFFSET 0x01u
153 
154 /******************************************************************************/
155 /*             Macros related to value used to program to sector header to
156                 make different sector status*/
157 /******************************************************************************/
158 #define EE_DATA_STATUS_ACTIVE  0xFACFFACFu
159 #define EE_DATA_STATUS_ALIVE   0xFFFF5555u
160 #define EE_DATA_STATUS_DEAD    0x55555555u
161 #define EE_DATA_STATUS_BLANK   0xFFFFFFFFu
162 #define EE_RECORD_STATUS_VALID 0x5555u
163 
164 /****************************************************************************
165              Macros to identify sector status and record status
166 *****************************************************************************/
167 /* Macro to denote the Sector Status */
168 #define EE_SECTOR_BLANK       0x00u
169 #define EE_SECTOR_ALTERNATIVE 0x01u
170 #define EE_SECTOR_ACTIVE      0x02u
171 #define EE_SECTOR_ALIVE       0x03u
172 #define EE_SECTOR_READY       0x04u
173 #define EE_SECTOR_DEAD        0x05u
174 #define EE_SECTOR_INVALID     0x06u
175 
176 /****************************************************************************
177              Macros to identify the status of initialize progress
178 *****************************************************************************/
179 /* Macro to denote the Sector Status */
180 #define EE_FIRST_TIME_NOT_DONE 0x00u
181 #define EE_READY_TO_WORK       0x01u
182 #define EE_SWAPPING            0x02u
183 #define EE_SWAPPING_DONE       0x03u
184 
185 /******************************************************************************/
186 /*                  Macros of devide/multiple fomular                         */
187 /******************************************************************************/
188 /* macro to get the remainder GET_MOD = divisor % dividend*/
189 #define GET_MOD(divisor, dividend) ((divisor) % (dividend))
190 /* macro to get the interger GET_INT = divisor / dividend*/
191 #define GET_INT(divisor, dividend) ((divisor) / (dividend))
192 
193 /****************************************************************************
194              Macros definition uses for synchronous and cache
195 *****************************************************************************/
196 /* Macro to determine the number of IDs to be stored in Cache table */
197 #if (EE_CACHETABLE_ENABLE == true)
198 #define EE_CACHETABLE_MAX_ENTRY 0x4 /* Number of Cache Table entries */
199 #define EE_CACHETABLE_START_ADDRESS \
200     0x2000FF00 /* start address of the cache table in RAM. Must be consistent with linker file */
201 #define EE_CACHETABLE_ITEM_SIZE         0x04u
202 #define EE_CACHETABLE_ITEM_ADDR(dataID) (EE_CACHETABLE_START_ADDRESS + ((dataID - 0x01u) << 0x02u))
203 #endif
204 
205 /******************************************************************************/
206 /*              Macros to determine the total number of sectors               */
207 /*                        alloted for EEPROM Emulation                        */
208 /******************************************************************************/
209 #define EE_MAX_ERASING_CYCLE_VALUE 0xFFFFFFFEu
210 
211 #define MIN2(a, b)      (((a) < (b)) ? (a) : (b))
212 #define MIN3(a, b, c)   ((c) < (MIN2((a), (b))) ? (c) : (MIN2((a), (b))))
213 #define NOT_EQUAL(a, b) (((a) != (b)) ? 0x01u : 0x00u)
214 
215 /******************************************************************************/
216 /*               Read/Write/Set/Clear Operation Macros                        */
217 /******************************************************************************/
218 #define REG_BIT_SET(address, mask)   (*(volatile uint8_t *)(address) |= (mask))
219 #define REG_BIT_CLEAR(address, mask) (*(volatile uint8_t *)(address) &= ~(mask))
220 #define REG_BIT_TEST(address, mask)  (*(volatile uint8_t *)(address) & (mask))
221 #define REG_WRITE(address, value)    (*(volatile uint8_t *)(address) = (value))
222 #define REG_READ(address)            ((uint8_t)(*(volatile uint8_t *)(address)))
223 #define REG_WRITE16(address, value)  (*(volatile uint16_t *)(address) = (value))
224 #define REG_READ16(address)          ((uint16_t)(*(volatile uint16_t *)(address)))
225 
226 #define WRITE8(address, value)  (*(volatile uint8_t *)(address) = (value))
227 #define READ8(address)          ((uint8_t)(*(volatile uint8_t *)(address)))
228 #define WRITE16(address, value) (*(volatile uint16_t *)(address) = (value))
229 #define READ16(address)         ((uint16_t)(*(volatile uint16_t *)(address)))
230 #define WRITE32(address, value) (*(volatile uint32_t *)(address) = (value))
231 #define READ32(address)         ((uint32_t)(*(volatile uint32_t *)(address)))
232 
233 /****************************************************************************
234              Macros definition uses for RAM_TARGET
235 *****************************************************************************/
236 
237 #if EE_CALLBACK_ENABLE
238 /* Counter if is reached, callback will be called */
239 #define EE_CALLBACK_COUNTER 0x4
240 /* A function pointer to the CallBack function */
241 extern PEE_FUNCPOINTER g_EECallBack;
242 /* length of this array depends on total size of the functions need to be copied to RAM*/
243 #define CALLBACK_SIZE 0x30
244 /* Null Callback function defination */
245 #define NULL_EE_CALLBACK ((PEE_FUNCPOINTER)0xFFFFFFFFu)
246 #endif
247 
248 /* Protopyte of interrupt service routin */
249 #define INTERRUPT
250 
251 /* FTFx Flash Module Memory Offset Map */
252 #define FTFx_FSTAT  (FTFE_BASE + 0x00000000u)
253 #define FTFx_FCNFG  (FTFE_BASE + 0x00000001u)
254 #define FTFx_FSEC   (FTFE_BASE + 0x00000002u)
255 #define FTFx_FCCOB0 (FTFE_BASE + 0x00000007u)
256 #define FTFx_FCCOB1 (FTFE_BASE + 0x00000006u)
257 #define FTFx_FCCOB2 (FTFE_BASE + 0x00000005u)
258 #define FTFx_FCCOB3 (FTFE_BASE + 0x00000004u)
259 #define FTFx_FCCOB4 (FTFE_BASE + 0x0000000Bu)
260 #define FTFx_FCCOB5 (FTFE_BASE + 0x0000000Au)
261 #define FTFx_FCCOB6 (FTFE_BASE + 0x00000009u)
262 #define FTFx_FCCOB7 (FTFE_BASE + 0x00000008u)
263 #define FTFx_FCCOB8 (FTFE_BASE + 0x0000000Fu)
264 #define FTFx_FCCOB9 (FTFE_BASE + 0x0000000Eu)
265 #define FTFx_FCCOBA (FTFE_BASE + 0x0000000Du)
266 #define FTFx_FCCOBB (FTFE_BASE + 0x0000000Cu)
267 #define GETINDEX(i) ((((i) / 0x04u) << 0x03u) + 0x03u - (i)) /* (i/4)*8 + 3 - i */
268 
269 /* bit mask for FSTAT register */
270 #define FTFx_FSTAT_CCIF      0x80u
271 #define FTFx_FSTAT_CLEAR_ERR 0x70u /* (FTFx_FSTAT_RDCOLERR | FTFx_FSTAT_ACCERR | FTFx_FSTAT_FPVIOL) */
272 #define FTFx_FSTAT_CHECK_ERR 0x31u /* (FTFx_FSTAT_MGSTAT0 | FTFx_FSTAT_ACCERR | FTFx_FSTAT_FPVIOL) */
273                                    /* bit mask for FCNFG register */
274 #define FTFx_FCNFG_CCIE 0x80u
275 #define FTFx_FSEC_SEC   0x03u
276 
277 /* Programmable size Macro definition for FTFx */
278 #define FTFx_WORD_SIZE     0x02u
279 #define FTFx_LONGWORD_SIZE 0x04u
280 #define FTFx_PHRASE_SIZE   0x08u
281 #define FTFx_DPHRASE_SIZE  0x10u
282 
283 /* Flash hardware algorithm operation commands */
284 #define FTFx_VERIFY_SECTION   0x01u
285 #define FTFx_PROGRAM_CHECK    0x02u
286 #define FTFx_PROGRAM_LONGWORD 0x06u
287 #define FTFx_PROGRAM_PHRASE   0x07u
288 #define FTFx_ERASE_SECTOR     0x09u
289 
290 /*
291 ** define flash command codes for K4W1
292 */
293 
294 #define RD1ALL  0x00 /*Read 1s All (Verify that all flash and IFR space is erased)*/
295 #define RD1BLK  0x01 /*Read 1s Block (Verify that a flash block is erased)*/
296 #define RD1SCR  0x02 /*Read 1s Sector(Verify that a flash sector is erased)*/
297 #define RD1PG   0x03 /*Read 1s Page (Verify that a flash page is erased)*/
298 #define RD1PHR  0x04 /*Read 1s Phrase (Verify that a flash phrase is erased)*/
299 #define RDMISR  0x05 /*Read into MISR (Generate MISR signature for range of flash pages)*/
300 #define RD1ISCR 0x12 /*Read 1s IFR Sector (Verify that an IFR sector is erased)*/
301 #define RD1IPG  0x13 /*Read 1s IFR Page (Verify that an IFR page is erased)*/
302 #define RD1IPHR 0x14 /*Read 1s IFR Phrase (Verify that an IFR phrase is erased)*/
303 #define RDIMISR 0x15 /*Read IFR into MISR (Generate MISR signature for range of IFR pages)*/
304 #define PGMPG   0x23 /*Program Page (Program data to a flash or IFR page)*/
305 #define PGMPHR  0x24 /*Program Phrase (Program data to a flash or IFR phrase)*/
306 #define ERSALL  0x40 /*Erase All (Erase all flash and IFR space)*/
307 #define ERSSCR  0x42 /*Erase Sector (Erase a flash sector)*/
308 
309 #define FMU_CHECK_CCIF (FMU0->FSTAT & FMU_FSTAT_CCIF_MASK)
310 #define FMU_CHECK_PEWEN \
311     (FMU0->FSTAT & FMU_FSTAT_PEWEN_MASK) /* MH - this define was mistakenly referencing the CCIF instead of PEWEN */
312 #define FMU_CHECK_PERDY  (FMU0->FSTAT & FMU_FSTAT_PERDY_MASK)
313 #define FMU_CHECK_FAIL   (FMU0->FSTAT & FMU_FSTAT_FAIL_MASK)
314 #define FMU_CHECK_SECURE (FMU0->FSTAT & FMU_FSTAT_CMDPRT_MASK)
315 #define FMU_CHECK_ERR    (FMU0->FSTAT & (FMU_FSTAT_ACCERR_MASK | FMU_FSTAT_FAIL_MASK | FMU_FSTAT_PVIOL_MASK))
316 
317 #ifndef FLASH_PAGE_SIZE
318 #define FLASH_PAGE_SIZE 128
319 #endif
320 #ifndef FLASH_PHRASE_SIZE
321 #define FLASH_PHRASE_SIZE 16
322 #endif
323 
324 #if defined(FMU0)
325 #define FLASH                   FMU0
326 #define FLASH_FSTAT_FAIL_MASK   FMU_FSTAT_FAIL_MASK
327 #define FLASH_FSTAT_CMDABT_MASK FMU_FSTAT_CMDABT_MASK
328 #define FLASH_FSTAT_PVIOL_MASK  FMU_FSTAT_PVIOL_MASK
329 #define FLASH_FSTAT_ACCERR_MASK FMU_FSTAT_ACCERR_MASK
330 #define FLASH_FSTAT_CWSABT_MASK FMU_FSTAT_CWSABT_MASK
331 #define FLASH_FSTAT_CCIF_MASK   FMU_FSTAT_CCIF_MASK
332 #define FLASH_FSTAT_CMDPRT_MASK FMU_FSTAT_CMDPRT_MASK
333 #define FLASH_FSTAT_CMDP_MASK   FMU_FSTAT_CMDP_MASK
334 #define FLASH_FSTAT_CMDDID_MASK FMU_FSTAT_CMDDID_MASK
335 #define FLASH_FSTAT_DFDIF_MASK  FMU_FSTAT_DFDIF_MASK
336 #define FLASH_FSTAT_PEWEN_MASK  FMU_FSTAT_PEWEN_MASK
337 #define FLASH_FSTAT_PERDY_MASK  FMU_FSTAT_PERDY_MASK
338 #elif defined(MSF1)
339 #define FLASH                   MSF1
340 #define FLASH_FSTAT_FAIL_MASK   MSF1_FSTAT_FAIL_MASK
341 #define FLASH_FSTAT_CMDABT_MASK MSF1_FSTAT_CMDABT_MASK
342 #define FLASH_FSTAT_PVIOL_MASK  MSF1_FSTAT_PVIOL_MASK
343 #define FLASH_FSTAT_ACCERR_MASK MSF1_FSTAT_ACCERR_MASK
344 #define FLASH_FSTAT_CWSABT_MASK MSF1_FSTAT_CWSABT_MASK
345 #define FLASH_FSTAT_CCIF_MASK   MSF1_FSTAT_CCIF_MASK
346 #define FLASH_FSTAT_CMDPRT_MASK MSF1_FSTAT_CMDPRT_MASK
347 #define FLASH_FSTAT_CMDP_MASK   MSF1_FSTAT_CMDP_MASK
348 #define FLASH_FSTAT_CMDDID_MASK MSF1_FSTAT_CMDDID_MASK
349 #define FLASH_FSTAT_DFDIF_MASK  MSF1_FSTAT_DFDIF_MASK
350 #define FLASH_FSTAT_PEWEN_MASK  MSF1_FSTAT_PEWEN_MASK
351 #define FLASH_FSTAT_PERDY_MASK  MSF1_FSTAT_PERDY_MASK
352 #endif
353 
354 #if defined(SMSCM)
355 #define SMSCM_CACHE_CLEAR_MASK         SMSCM_OCMDR0_OCMCF2_MASK
356 #define SMSCM_CACHE_CLEAR(x)           SMSCM_OCMDR0_OCMCF2(x)
357 #define SMSCM_SPECULATION_DISABLE_MASK SMSCM_OCMDR0_OCMCF1_MASK
358 #endif
359 
360 /* Default buffer size of the remaining data */
361 #ifndef EE_DATA_VALUE_REMAINING_PART
362 #define EE_DATA_VALUE_REMAINING_PART 16
363 #endif
364 
365 /*******************************************************************************
366  * API
367  ******************************************************************************/
368 
369 #if defined(__cplusplus)
370 extern "C" {
371 #endif /* _cplusplus */
372 
373 /*!
374  * @name Initialization and deinitialization
375  * @{
376  */
377 
378 /* High level functions */
379 void EE_GetDefaultConfig(eeprom_emulation_config_t *config);
380 void EE_SetEepromEmulationInfo(eeprom_emulation_handle_t *handle, eeprom_emulation_config_t *config);
381 // void EE_DisableCache(FMC_Type *base);
382 // void EE_RestoreCache(FMC_Type *base);
383 uint32_t EE_Init(eeprom_emulation_handle_t *handle);
384 uint32_t EE_WriteData(eeprom_emulation_handle_t *handle, uint16_t dataID, uint32_t source);
385 uint32_t EE_ReadData(eeprom_emulation_handle_t *handle, uint16_t dataID, uint32_t *recordAddr);
386 uint32_t EE_ReportStatus(eeprom_emulation_handle_t *handle);
387 uint32_t EE_Deinit(eeprom_emulation_handle_t *handle);
388 
389 #if (EE_USE_ASYNCHRONOUS_MODEL == true)
390 uint32_t EE_Main(eeprom_emulation_handle_t *handle);
391 #endif
392 
393 /* Middle level functions */
394 uint32_t EE_NextSector(eeprom_emulation_handle_t *handle, uint32_t addr);
395 uint32_t EE_PrevSector(eeprom_emulation_handle_t *handle, uint32_t addr);
396 uint32_t EE_VerifyRecordStatus(eeprom_emulation_handle_t *handle, uint32_t dest, uint32_t expData);
397 uint32_t EE_VerifySectorHeader(eeprom_emulation_handle_t *handle, uint32_t dest, uint32_t expData);
398 uint32_t EE_MultiProgram(eeprom_emulation_handle_t *handle, uint32_t dest, uint32_t size, uint8_t *pData);
399 uint32_t EE_CopyRecord(eeprom_emulation_handle_t *handle,
400                        eeprom_emulation_data_record_t dataRecord,
401                        uint8_t remainData[]);
402 uint32_t EE_SwapSector(eeprom_emulation_handle_t *handle);
403 uint32_t EE_SearchInSector(eeprom_emulation_handle_t *handle, uint16_t expID, uint32_t sectorAddress);
404 uint32_t EE_SearchBlankSpace(eeprom_emulation_handle_t *handle, uint32_t sectorAddress);
405 uint32_t EE_SearchInAllActives(eeprom_emulation_handle_t *handle, uint16_t dataID);
406 uint32_t EE_SearchLoop(eeprom_emulation_handle_t *handle, uint16_t dataID);
407 uint32_t EE_BlankCheck(eeprom_emulation_handle_t *handle, uint32_t address, uint32_t size);
408 uint8_t EE_GetSectorStatus(eeprom_emulation_handle_t *handle, uint32_t sectorAddress);
409 uint32_t EE_FindActSector(eeprom_emulation_handle_t *handle, uint32_t sectorAddress, bool closestFlag, bool nextFlag);
410 uint8_t EE_GetSectorNumber(eeprom_emulation_handle_t *handle, uint8_t expStatus);
411 uint32_t EE_ValidateDeadIndicator(eeprom_emulation_handle_t *handle, uint32_t sectorAddress);
412 uint32_t EE_ValidateEraseCycle(eeprom_emulation_handle_t *handle, uint32_t sectorAddress, uint8_t *pData);
413 uint32_t EE_ValidateActIndicator(eeprom_emulation_handle_t *handle, uint32_t sectorAddress);
414 uint32_t EE_ReEraseEeprom(eeprom_emulation_handle_t *handle, uint32_t sectorAddress);
415 uint32_t EE_CheckAvailabilityStatus(eeprom_emulation_handle_t *handle);
416 
417 #if (EE_CACHETABLE_ENABLE)
418 void EE_UpdateCacheTable(eeprom_emulation_handle_t *handle);
419 uint32_t EE_SearchInCache(uint16_t dataID);
420 #endif
421 
422 #if (EE_USE_ASYNCHRONOUS_MODEL)
423 void INTERRUPT EE_ISRHandler(void);
424 #endif
425 
426 /* Low level functions */
427 AT_QUICKACCESS_SECTION_CODE(uint32_t EE_FlashEraseAll(eeprom_emulation_handle_t *handle));
428 
429 uint32_t EE_FlashCheckErrorCode(void);
430 AT_QUICKACCESS_SECTION_CODE(uint32_t EE_SyncFlashErase(eeprom_emulation_handle_t *handle, uint32_t destination));
431 #if (EE_USE_ASYNCHRONOUS_MODEL)
432 void EE_AsyncFlashErase(eeprom_emulation_handle_t *handle, uint32_t destination);
433 #endif
434 
435 AT_QUICKACCESS_SECTION_CODE(uint32_t EE_FlashEraseVerifySection(
436     eeprom_emulation_handle_t *handle, uint32_t destination, uint16_t Number, uint8_t marginLevel));
437 AT_QUICKACCESS_SECTION_CODE(uint32_t EE_SingleProgram(eeprom_emulation_handle_t *handle,
438                                                       uint32_t destination,
439                                                       uint8_t *pData));
440 uint32_t EE_SingleProgramCheck(eeprom_emulation_handle_t *handle,
441                                uint32_t destination,
442                                uint8_t *pExpectedData,
443                                uint8_t marginLevel);
444 void FLASH_CACHE_Disable(void);
445 
446 /*! @} */
447 
448 #if defined(__cplusplus)
449 }
450 #endif
451 
452 /*! @}*/
453 #endif /*FSL_EEPROM_EMULATION_H_*/
454