Ftfc_Eep_Ip.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : IPV_FTFC
  5. * Dependencies :
  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. /**
  25. * @file Ftfc_Eep_Ip.c
  26. *
  27. * @addtogroup FTFC_EEP_IP
  28. * @{
  29. */
  30. #ifdef __cplusplus
  31. extern "C"{
  32. #endif
  33. /*==================================================================================================
  34. * INCLUDE FILES
  35. * 1) system and project includes
  36. * 2) needed interfaces from external units
  37. * 3) internal and external interfaces from this unit
  38. ==================================================================================================*/
  39. #include "OsIf.h"
  40. #include "Mcal.h"
  41. #include "SchM_Eep.h"
  42. #include "Ftfc_Eep_Ip.h"
  43. #if (FTFC_EEP_IP_DEV_ERROR_DETECT == STD_ON)
  44. #include "Devassert.h"
  45. #endif
  46. /*==================================================================================================
  47. * SOURCE FILE VERSION INFORMATION
  48. ==================================================================================================*/
  49. #define FTFC_EEP_IP_VENDOR_ID_C 43
  50. #define FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_C 4
  51. #define FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_C 4
  52. #define FTFC_EEP_IP_AR_RELEASE_REVISION_VERSION_C 0
  53. #define FTFC_EEP_IP_SW_MAJOR_VERSION_C 1
  54. #define FTFC_EEP_IP_SW_MINOR_VERSION_C 0
  55. #define FTFC_EEP_IP_SW_PATCH_VERSION_C 0
  56. /*==================================================================================================
  57. * FILE VERSION CHECKS
  58. ==================================================================================================*/
  59. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  60. /* Version checks for OsIf.h */
  61. #if ((FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  62. (FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION) \
  63. )
  64. #error "Ftfc_Eep_Ip.c and OsIf.h are for different AUTOSAR versions!"
  65. #endif
  66. #endif
  67. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  68. /* Version checks for Mcal.h */
  69. #if ((FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_C != MCAL_AR_RELEASE_MAJOR_VERSION) || \
  70. (FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_C != MCAL_AR_RELEASE_MINOR_VERSION) \
  71. )
  72. #error "Ftfc_Eep_Ip.c and Mcal.h are for different AUTOSAR versions!"
  73. #endif
  74. #endif
  75. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  76. /* Version checks for SchM_Eep.h */
  77. #if ((FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_C != SCHM_EEP_AR_RELEASE_MAJOR_VERSION) || \
  78. (FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_C != SCHM_EEP_AR_RELEASE_MINOR_VERSION) \
  79. )
  80. #error "Ftfc_Eep_Ip.c and SchM_Eep.h are for different AUTOSAR versions!"
  81. #endif
  82. #endif
  83. /* Version checks for Ftfc_Eep_Ip.h */
  84. #if (FTFC_EEP_IP_VENDOR_ID_C != FTFC_EEP_IP_VENDOR_ID_H)
  85. #error "Ftfc_Eep_Ip.c and Ftfc_Eep_Ip.h have different vendor IDs!"
  86. #endif
  87. #if ((FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_C != FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  88. (FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_C != FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_H) || \
  89. (FTFC_EEP_IP_AR_RELEASE_REVISION_VERSION_C != FTFC_EEP_IP_AR_RELEASE_REVISION_VERSION_H) \
  90. )
  91. #error "Ftfc_Eep_Ip.c and Ftfc_Eep_Ip.h are for different AUTOSAR versions!"
  92. #endif
  93. #if ((FTFC_EEP_IP_SW_MAJOR_VERSION_C != FTFC_EEP_IP_SW_MAJOR_VERSION_H) || \
  94. (FTFC_EEP_IP_SW_MINOR_VERSION_C != FTFC_EEP_IP_SW_MINOR_VERSION_H) || \
  95. (FTFC_EEP_IP_SW_PATCH_VERSION_C != FTFC_EEP_IP_SW_PATCH_VERSION_H) \
  96. )
  97. #error "Ftfc_Eep_Ip.c and Ftfc_Eep_Ip.h have different SW versions!"
  98. #endif
  99. #if (FTFC_EEP_IP_DEV_ERROR_DETECT == STD_ON)
  100. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  101. /* Version checks for Devassert.h */
  102. #if ((FTFC_EEP_IP_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  103. (FTFC_EEP_IP_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION) \
  104. )
  105. #error "Ftfc_Eep_Ip.c and Devassert.h are for different AUTOSAR versions!"
  106. #endif
  107. #endif
  108. #endif /* FTFC_EEP_IP_DEV_ERROR_DETECT == STD_ON */
  109. /*==================================================================================================
  110. * LOCAL MACROS
  111. ==================================================================================================*/
  112. /** Switch FlexRAM function between RAM and emulated EEPROM. */
  113. #define FTFC_EEP_IP_FLASH_CMD_SETRAM_U8 0x81U
  114. /** Minimum number of bytes allowed for a quick write. */
  115. #define FTFC_EEP_IP_QUICK_WRITES_LENGTH_MIN 16U
  116. /** Maximum number of bytes allowed for a quick write. */
  117. #define FTFC_EEP_IP_QUICK_WRITES_LENGTH_MAX 512U
  118. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  119. #define IP_EEPROM IP_FTFM /**< ptr to the IP_FTFM structure */
  120. #define FCNFG_EEERDY_MASK FTFM_FCNFG_EEERDY_MASK /**< set when FlexRAM is ready for emulated EEPROM operations */
  121. #define FSTAT_CCIF_MASK FTFM_FSTAT_CCIF_MASK /**< zero while a FTFC command or an EEPROM operation is in progress */
  122. #define FSTAT_ACCERR_MASK FTFM_FSTAT_ACCERR_MASK /**< flash access error flag */
  123. #define FSTAT_FPVIOL_MASK FTFM_FSTAT_FPVIOL_MASK /**< a write was attempted to a protected area */
  124. #define FSTAT_RDCOLERR_MASK FTFM_FSTAT_RDCOLERR_MASK /**< collision over a FTFC resource that was being manipulated by a command */
  125. #define FSTAT_MGSTAT0_MASK FTFM_FSTAT_MGSTAT0_MASK /**< set if an error is detected during execution of an FTFC command */
  126. #define FSTAT_MGSTAT1_MASK FTFM_FSTAT_MGSTAT1_MASK /**< uncorrectable ECC fault was detected during execution of a flash command */
  127. #define FSTAT_MGSTAT2_MASK FTFM_FSTAT_MGSTAT2_MASK /**< uncorrectable ECC fault was detected during emulated EEPROM initialization */
  128. #define FSTAT_MGSTAT3_MASK FTFM_FSTAT_MGSTAT3_MASK /**< uncorrectable ECC fault was detected during the flash reset sequence *
  129. unless the error occurred while reading the flash configuration field, *
  130. the FlexNVM EEPROM partition field, or CSEc strict boot firmware. */
  131. #else /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  132. #define IP_EEPROM IP_FTFC /**< ptr to the IP_FTFC structure */
  133. #define FCNFG_EEERDY_MASK FTFC_FCNFG_EEERDY_MASK /**< FlexRAM ready for emulated EEPROM operations */
  134. #define FSTAT_CCIF_MASK FTFC_FSTAT_CCIF_MASK /**< if zero, a FTFC command or an EEPROM operation is in progress */
  135. #define FSTAT_ACCERR_MASK FTFC_FSTAT_ACCERR_MASK /**< flash access error flag */
  136. #define FSTAT_FPVIOL_MASK FTFC_FSTAT_FPVIOL_MASK /**< a write was attempted to a protected area */
  137. #define FSTAT_RDCOLERR_MASK FTFC_FSTAT_RDCOLERR_MASK /**< collision over a FTFC resource that was being manipulated by a command */
  138. #define FSTAT_MGSTAT0_MASK FTFC_FSTAT_MGSTAT0_MASK /**< set if an error is detected during execution of an FTFC command */
  139. #endif /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  140. /** Toggle the development errors detection. */
  141. #if (FTFC_EEP_IP_DEV_ERROR_DETECT == STD_ON)
  142. #define FTFC_DEV_ASSERT(X) DevAssert(X)
  143. #else
  144. #define FTFC_DEV_ASSERT(X)
  145. #endif
  146. #define FTFC_EEP_IP_NO_BO_DETECTED_U8 0x00 /**< No EEPROM issues detected */
  147. #define FTFC_EEP_IP_BO_DURING_MAINTENANCE_U8 0x01 /**< Quick write maintenance has to be completed. */
  148. #define FTFC_EEP_IP_BO_DURING_QUICK_WRITES_U8 0x02 /**< Quick writes were discarded due to a reset. */
  149. #define FTFC_EEP_IP_BO_DURING_NORMAL_WRITES_U8 0x04 /**< A normal write was interrupted by reset. */
  150. /*==================================================================================================
  151. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  152. ==================================================================================================*/
  153. /** FCCOB registers and their position in the IP_EEPROM->FCCOB[] array */
  154. enum
  155. {
  156. FTFC_EEP_IP_FCCOB_3, FTFC_EEP_IP_FCCOB_2, FTFC_EEP_IP_FCCOB_1, FTFC_EEP_IP_FCCOB_0,
  157. FTFC_EEP_IP_FCCOB_7, FTFC_EEP_IP_FCCOB_6, FTFC_EEP_IP_FCCOB_5, FTFC_EEP_IP_FCCOB_4,
  158. FTFC_EEP_IP_FCCOB_B, FTFC_EEP_IP_FCCOB_A, FTFC_EEP_IP_FCCOB_9, FTFC_EEP_IP_FCCOB_8
  159. };
  160. /** Input params written in the FCCOB registers for the flash command: Set FlexRAM Function */
  161. enum
  162. {
  163. FTFC_EEP_IP_FCCOB_SETRAM_WRITE_CMD_SETRAM = FTFC_EEP_IP_FCCOB_0, /**< Flash command: SETRAM (0x81) */
  164. FTFC_EEP_IP_FCCOB_SETRAM_WRITE_FR_FCC = FTFC_EEP_IP_FCCOB_1, /**< FlexRAM Function Control Code */
  165. FTFC_EEP_IP_FCCOB_SETRAM_WRITE_QUICKWRITES_LENGTH_MSB = FTFC_EEP_IP_FCCOB_4, /**< Number of FlexRAM bytes allocated for EEPROM quick writes [15:8] */
  166. FTFC_EEP_IP_FCCOB_SETRAM_WRITE_QUICKWRITES_LENGTH_LSB = FTFC_EEP_IP_FCCOB_5 /**< Number of FlexRAM bytes allocated for EEPROM quick writes [7:0] */
  167. };
  168. /** Returned values read from the FCCOB registers for the flash command: Set FlexRAM Function */
  169. enum
  170. {
  171. FTFC_EEP_IP_FCCOB_SETRAM_READ_BROWNOUT_CODE = FTFC_EEP_IP_FCCOB_5, /**< Brown-out (BO) Detection Codes */
  172. FTFC_EEP_IP_FCCOB_SETRAM_READ_QWRITES_MAINTENANCE_MSB = FTFC_EEP_IP_FCCOB_6, /**< Number of EEPROM quick write records requiring maintenance [15:8] */
  173. FTFC_EEP_IP_FCCOB_SETRAM_READ_QWRITES_MAINTENANCE_LSB = FTFC_EEP_IP_FCCOB_7, /**< Number of EEPROM quick write records requiring maintenance [7:0] */
  174. FTFC_EEP_IP_FCCOB_SETRAM_READ_SECTOR_ERASE_COUNT_MSB = FTFC_EEP_IP_FCCOB_8, /**< EEPROM sector erase count [15:8] */
  175. FTFC_EEP_IP_FCCOB_SETRAM_READ_SECTOR_ERASE_COUNT_LSB = FTFC_EEP_IP_FCCOB_9 /**< EEPROM sector erase count [7:0] */
  176. };
  177. /** FLEXRAM Function Control Codes */
  178. typedef enum
  179. {
  180. FLEXRAM_FCC_MODE_EEERAM_NORMAL = 0x00, /**< Make FlexRAM available for emulated EEPROM */
  181. FLEXRAM_FCC_MODE_EEERAM_QWRITES = 0x55, /**< Make FlexRAM available for EEPROM quick writes */
  182. FLEXRAM_FCC_GET_FLEXRAM_STATUS = 0x77, /**< EEPROM quick write status query */
  183. FLEXRAM_FCC_COMPLETE_MAINTENANCE = 0xAA, /**< Complete interrupted EEPROM quick write process */
  184. FLEXRAM_FCC_MODE_RAM = 0xFF /**< Make FlexRAM available as RAM */
  185. } Ftfc_Eep_Ip_FlexramFccType;
  186. /** Data about the last asynchronous job */
  187. typedef struct
  188. {
  189. /** updated at the beginning of a new async job with OsIf_GetCounter() and with each OsIf_GetElapsed() call */
  190. uint32 TicksStarted;
  191. /** here OsIf_GetElapsed() stores the time elapsed since TicksStarted */
  192. uint32 TicksElapsed;
  193. /** the status of the last asynchronous job may be: ok, pending or failed */
  194. Ftfc_Eep_Ip_StatusType Result;
  195. } Ftfc_Eep_Ip_AsyncJobType;
  196. /*==================================================================================================
  197. * GLOBAL CONSTANTS
  198. ==================================================================================================*/
  199. /*==================================================================================================
  200. * GLOBAL VARIABLES
  201. ==================================================================================================*/
  202. /*==================================================================================================
  203. * LOCAL CONSTANTS
  204. ==================================================================================================*/
  205. #define EEP_START_SEC_CONST_32
  206. #include "Eep_MemMap.h"
  207. /** The contents of an erased EEPROM record.
  208. * This variable needs to be aligned on LONGWORD bytes. */
  209. static uint32 const Ftfc_Eep_Ip_u32EraseValue = 0xFFFFFFFFU;
  210. #define EEP_STOP_SEC_CONST_32
  211. #include "Eep_MemMap.h"
  212. /*==================================================================================================
  213. * LOCAL VARIABLES
  214. ==================================================================================================*/
  215. #define EEP_START_SEC_VAR_CLEARED_UNSPECIFIED
  216. #include "Eep_MemMap.h"
  217. static Ftfc_Eep_Ip_ConfigType const * Ftfc_Eep_Ip_pxConfiguration;
  218. static Ftfc_Eep_Ip_BrownOutCodeType Ftfc_Eep_Ip_eBrownOutCode;
  219. static Ftfc_Eep_Ip_AsyncJobType Ftfc_Eep_Ip_xAsyncJob;
  220. #define EEP_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  221. #include "Eep_MemMap.h"
  222. /*==================================================================================================
  223. * LOCAL FUNCTION PROTOTYPES
  224. ==================================================================================================*/
  225. #define EEP_START_SEC_CODE
  226. #include "Eep_MemMap.h"
  227. static Ftfc_Eep_Ip_PageSizeType Ftfc_Eep_Ip_AlignedPageSize (Ftfc_Eep_Ip_AddressType FlexramAddress,
  228. Ftfc_Eep_Ip_AddressType RamAddress,
  229. Ftfc_Eep_Ip_LengthType Length
  230. );
  231. static boolean Ftfc_Eep_Ip_IsFtfcReady (void);
  232. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_CmdSetFlexramFunction (Ftfc_Eep_Ip_FlexramFccType FlexramFuncControlCode,
  233. uint16 QuickWritesLength
  234. );
  235. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_CheckFstatErrors (void);
  236. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_AcEflashCmd (void);
  237. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_AcEflashWrite (Ftfc_Eep_Ip_AddressType DestAddress,
  238. uint8 const * pu8SrcAddress,
  239. Ftfc_Eep_Ip_PageSizeType PageSize,
  240. boolean Async
  241. );
  242. #define EEP_STOP_SEC_CODE
  243. #include "Eep_MemMap.h"
  244. #if (FTFC_EEP_IP_LOAD_AC_INTO_RAM == STD_ON)
  245. #define EEP_START_SEC_RAMCODE
  246. #else
  247. #define EEP_START_SEC_CODE
  248. #endif
  249. #include "Eep_MemMap.h"
  250. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_StartFlashCommand (void);
  251. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_WriteIntoFlexram (Ftfc_Eep_Ip_AddressType DestAddress,
  252. uint8 const * pu8SrcAddress,
  253. Ftfc_Eep_Ip_PageSizeType PageSize,
  254. boolean Async
  255. );
  256. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_WaitCcifTimeout (uint32 TimeoutCounter);
  257. #if (FTFC_EEP_IP_LOAD_AC_INTO_RAM == STD_ON)
  258. #define EEP_STOP_SEC_RAMCODE
  259. #else
  260. #define EEP_STOP_SEC_CODE
  261. #endif
  262. #include "Eep_MemMap.h"
  263. /*==================================================================================================
  264. * GLOBAL FUNCTIONS
  265. ==================================================================================================*/
  266. #define EEP_START_SEC_CODE
  267. #include "Eep_MemMap.h"
  268. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  269. * @brief Initialize the module.
  270. * @details Set FlexRAM to work as EEERAM.
  271. * Query EEPROM quick write status and complete the maintenance, if needed.
  272. *
  273. * Out of reset with the FSTAT[CCIF] bit clear, the partition settings (EEESIZE, DEPART)
  274. * are read from the data flash IFR and the emulated EEPROM file system is initialized
  275. * accordingly. The emulated EEPROM file system locates all valid EEPROM data records
  276. * in EEPROM backup and copies the newest data to FlexRAM.
  277. *
  278. * CCIF is cleared throughout the reset sequence. Completion of the reset sequence is marked by
  279. * setting CCIF which enables flash user commands.
  280. *
  281. * @param[in] pConfig pointer stored in Ftfc_Eep_Ip_pxConfiguration
  282. *
  283. * @return the initialization result
  284. * @retval FTFC_EEP_IP_STATUS_OK initialization successful
  285. * @retval FTFC_EEP_IP_STATUS_TIMEOUT a flash cmd timeout has occurred
  286. * @retval FTFC_EEP_IP_STATUS_FAILED a flash command failed to execute
  287. * @retval FTFC_EEP_IP_STATUS_FAILED_MGSTAT one or more MGSTAT 1/2/3 bits were set
  288. *
  289. * @implements Ftfc_Eep_Ip_Init_Activity
  290. *
  291. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  292. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_Init (Ftfc_Eep_Ip_ConfigType const * pConfig)
  293. {
  294. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  295. uint8 BrownoutCode = 0U;
  296. FTFC_DEV_ASSERT(NULL_PTR != pConfig);
  297. /* Overwrite all global variables */
  298. Ftfc_Eep_Ip_pxConfiguration = pConfig;
  299. Ftfc_Eep_Ip_eBrownOutCode = FTFC_EEP_IP_NO_BO_DETECTED;
  300. Ftfc_Eep_Ip_xAsyncJob.TicksStarted = 0U;
  301. Ftfc_Eep_Ip_xAsyncJob.TicksElapsed = 0U;
  302. Ftfc_Eep_Ip_xAsyncJob.Result = FTFC_EEP_IP_STATUS_OK;
  303. if (0U == (IP_EEPROM->FCNFG & FCNFG_EEERDY_MASK))
  304. {
  305. /* When the memory partitioning is done without the option to load the EEPROM data
  306. * to FLEXRAM at reset, a FLEXRAM_FCC_MODE_EEERAM_NORMAL command is needed (so EEERDy gets set).
  307. * Also, the FLEXRAM_FCC_GET_FLEXRAM_STATUS cmd is not allowed unless the EEERDY bit is set. */
  308. Status = Ftfc_Eep_Ip_CmdSetFlexramFunction(FLEXRAM_FCC_MODE_EEERAM_NORMAL, 0U);
  309. }
  310. if (FTFC_EEP_IP_STATUS_OK == Status)
  311. {
  312. Status = Ftfc_Eep_Ip_CmdSetFlexramFunction(FLEXRAM_FCC_GET_FLEXRAM_STATUS, 0U);
  313. if (FTFC_EEP_IP_STATUS_OK == Status)
  314. {
  315. BrownoutCode = IP_EEPROM->FCCOB[FTFC_EEP_IP_FCCOB_SETRAM_READ_BROWNOUT_CODE];
  316. switch (BrownoutCode)
  317. {
  318. case FTFC_EEP_IP_BO_DURING_MAINTENANCE_U8:
  319. Ftfc_Eep_Ip_eBrownOutCode = FTFC_EEP_IP_BO_DURING_MAINTENANCE;
  320. break;
  321. case FTFC_EEP_IP_BO_DURING_QUICK_WRITES_U8:
  322. Ftfc_Eep_Ip_eBrownOutCode = FTFC_EEP_IP_BO_DURING_QUICK_WRITES;
  323. break;
  324. case FTFC_EEP_IP_BO_DURING_NORMAL_WRITES_U8:
  325. Ftfc_Eep_Ip_eBrownOutCode = FTFC_EEP_IP_BO_DURING_NORMAL_WRITES;
  326. break;
  327. case FTFC_EEP_IP_NO_BO_DETECTED_U8:
  328. Ftfc_Eep_Ip_eBrownOutCode = FTFC_EEP_IP_NO_BO_DETECTED;
  329. break;
  330. default:
  331. Status = FTFC_EEP_IP_STATUS_FAILED;
  332. break;
  333. }
  334. if (FTFC_EEP_IP_NO_BO_DETECTED != Ftfc_Eep_Ip_eBrownOutCode)
  335. {
  336. Status = Ftfc_Eep_Ip_CmdSetFlexramFunction(FLEXRAM_FCC_COMPLETE_MAINTENANCE, 0U);
  337. }
  338. }
  339. }
  340. return Status;
  341. }
  342. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  343. * @brief Read @p Length bytes from EEPROM @p SrcAddress to @p pu8DestAddress.
  344. *
  345. * @param[in] SrcAddress EEPROM address to read from
  346. * @param[out] pu8DestAddress buffer to store the read data
  347. * @param[in] Length how many bytes to read
  348. *
  349. * @return the read operation status
  350. * @retval FTFC_EEP_IP_STATUS_OK the requested bytes were copied into the destination buffer
  351. * @retval FTFC_EEP_IP_STATUS_FAILED FTFC not ready
  352. * @retval FTFC_EEP_IP_STATUS_FAILED a read was attempted on an invalid page size
  353. *
  354. * @implements Ftfc_Eep_Ip_Read_Activity
  355. *
  356. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  357. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_Read (Ftfc_Eep_Ip_AddressType SrcAddress,
  358. uint8 * pu8DestAddress,
  359. Ftfc_Eep_Ip_LengthType Length
  360. )
  361. {
  362. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  363. Ftfc_Eep_Ip_AddressType FlexramAddress = FTFC_EEP_IP_FLEXRAM_ADDRESS + SrcAddress;
  364. Ftfc_Eep_Ip_AddressType DestinationAddress = (Ftfc_Eep_Ip_AddressType)pu8DestAddress;
  365. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  366. Ftfc_Eep_Ip_LengthType LengthRemaining = Length;
  367. FTFC_DEV_ASSERT(pu8DestAddress != NULL_PTR);
  368. FTFC_DEV_ASSERT(SrcAddress < FTFC_EEP_IP_EEP_SIZE);
  369. FTFC_DEV_ASSERT((SrcAddress + LengthRemaining) <= FTFC_EEP_IP_EEP_SIZE);
  370. FTFC_DEV_ASSERT(LengthRemaining > 0U);
  371. MCAL_FAULT_INJECTION_POINT(EEP_FIP_01_EEP_AFTER_READ_SYNC);
  372. if (Ftfc_Eep_Ip_IsFtfcReady())
  373. {
  374. while ((LengthRemaining > 0U) && (FTFC_EEP_IP_STATUS_OK == Status))
  375. {
  376. PageSize = Ftfc_Eep_Ip_AlignedPageSize(FlexramAddress, DestinationAddress, LengthRemaining);
  377. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  378. switch (PageSize)
  379. {
  380. case FTFC_EEP_IP_PAGE_LONGWORD:
  381. *((uint32 *)DestinationAddress) = *((uint32 *)FlexramAddress);
  382. break;
  383. case FTFC_EEP_IP_PAGE_WORD:
  384. {
  385. uint32 Offset = FlexramAddress % FTFC_EEP_IP_PAGE_LONGWORD;
  386. uint32 PageContents = *(uint32 *)(FlexramAddress - Offset);
  387. *((uint16 *)DestinationAddress) = (uint16)(PageContents >> (Offset * 8U));
  388. }
  389. break;
  390. case FTFC_EEP_IP_PAGE_BYTE:
  391. {
  392. uint32 Offset = FlexramAddress % FTFC_EEP_IP_PAGE_LONGWORD;
  393. uint32 PageContents = *(uint32 *)(FlexramAddress - Offset);
  394. *((uint8 *)DestinationAddress) = (uint8)(PageContents >> (Offset * 8U));
  395. }
  396. break;
  397. default:
  398. Status = FTFC_EEP_IP_STATUS_FAILED;
  399. break;
  400. }
  401. #else /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  402. switch (PageSize)
  403. {
  404. case FTFC_EEP_IP_PAGE_LONGWORD:
  405. *((uint32 *)DestinationAddress) = *((uint32 *)FlexramAddress);
  406. break;
  407. case FTFC_EEP_IP_PAGE_WORD:
  408. *((uint16 *)DestinationAddress) = *((uint16 *)FlexramAddress);
  409. break;
  410. case FTFC_EEP_IP_PAGE_BYTE:
  411. *((uint8 *)DestinationAddress) = *((uint8 *)FlexramAddress);
  412. break;
  413. default:
  414. Status = FTFC_EEP_IP_STATUS_FAILED;
  415. break;
  416. }
  417. #endif /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  418. FlexramAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  419. DestinationAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  420. LengthRemaining -= (Ftfc_Eep_Ip_LengthType)PageSize;
  421. }
  422. }
  423. else
  424. {
  425. Status = FTFC_EEP_IP_STATUS_FAILED;
  426. }
  427. return Status;
  428. }
  429. #if (FTFC_EEP_IP_COMPARE_API == STD_ON)
  430. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  431. * @brief Compare the first @p Length bytes of @p pu8DestAddress to the contents found at @p SrcAddress.
  432. *
  433. * @param[in] pu8DestAddress pointer to the data buffer
  434. * @param[in] SrcAddress where the contents in EEPROM are stored
  435. * @param[in] Length how many bytes to compare
  436. *
  437. * @return the comparison result
  438. * @retval FTFC_EEP_IP_STATUS_OK the contents match
  439. * @retval FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT the contents do not match
  440. * @retval FTFC_EEP_IP_STATUS_FAILED FTFC not ready
  441. * @retval FTFC_EEP_IP_STATUS_FAILED a read was attempted on an invalid page size
  442. *
  443. * @implements Ftfc_Eep_Ip_Compare_Activity
  444. *
  445. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  446. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_Compare (Ftfc_Eep_Ip_AddressType SrcAddress,
  447. uint8 const * pu8DestAddress,
  448. Ftfc_Eep_Ip_LengthType Length
  449. )
  450. {
  451. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  452. Ftfc_Eep_Ip_AddressType FlexramAddress = FTFC_EEP_IP_FLEXRAM_ADDRESS + SrcAddress;
  453. Ftfc_Eep_Ip_AddressType RamAddress = (Ftfc_Eep_Ip_AddressType)pu8DestAddress;
  454. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  455. Ftfc_Eep_Ip_LengthType LengthRemaining = Length;
  456. FTFC_DEV_ASSERT(pu8DestAddress != NULL_PTR);
  457. FTFC_DEV_ASSERT(SrcAddress < FTFC_EEP_IP_EEP_SIZE);
  458. FTFC_DEV_ASSERT((SrcAddress + LengthRemaining) <= FTFC_EEP_IP_EEP_SIZE);
  459. FTFC_DEV_ASSERT(LengthRemaining > 0U);
  460. MCAL_FAULT_INJECTION_POINT(EEP_FIP_02_EEP_AFTER_COMPARE_SYNC);
  461. if (Ftfc_Eep_Ip_IsFtfcReady())
  462. {
  463. while ((LengthRemaining > 0U) && (FTFC_EEP_IP_STATUS_OK == Status))
  464. {
  465. PageSize = Ftfc_Eep_Ip_AlignedPageSize(FlexramAddress, RamAddress, LengthRemaining);
  466. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  467. switch (PageSize)
  468. {
  469. case FTFC_EEP_IP_PAGE_LONGWORD:
  470. if (*((uint32 *)RamAddress) != *((uint32 *)FlexramAddress))
  471. {
  472. Status = FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT;
  473. }
  474. break;
  475. case FTFC_EEP_IP_PAGE_WORD:
  476. {
  477. uint32 Offset = FlexramAddress % FTFC_EEP_IP_PAGE_LONGWORD;
  478. uint32 PageContents = *(uint32 *)(FlexramAddress - Offset);
  479. if (*((uint16 *)RamAddress) != (uint16)(PageContents >> (Offset * 8U)))
  480. {
  481. Status = FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT;
  482. }
  483. }
  484. break;
  485. case FTFC_EEP_IP_PAGE_BYTE:
  486. {
  487. uint32 Offset = FlexramAddress % FTFC_EEP_IP_PAGE_LONGWORD;
  488. uint32 PageContents = *(uint32 *)(FlexramAddress - Offset);
  489. if (*((uint8 *)RamAddress) != (uint8)(PageContents >> (Offset * 8U)))
  490. {
  491. Status = FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT;
  492. }
  493. }
  494. break;
  495. default:
  496. Status = FTFC_EEP_IP_STATUS_FAILED;
  497. break;
  498. }
  499. #else /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  500. switch (PageSize)
  501. {
  502. case FTFC_EEP_IP_PAGE_LONGWORD:
  503. if (*((uint32 *)RamAddress) != *((uint32 *)FlexramAddress))
  504. {
  505. Status = FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT;
  506. }
  507. break;
  508. case FTFC_EEP_IP_PAGE_WORD:
  509. if (*((uint16 *)RamAddress) != *((uint16 *)FlexramAddress))
  510. {
  511. Status = FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT;
  512. }
  513. break;
  514. case FTFC_EEP_IP_PAGE_BYTE:
  515. if (*((uint8 *)RamAddress) != *((uint8 *)FlexramAddress))
  516. {
  517. Status = FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT;
  518. }
  519. break;
  520. default:
  521. Status = FTFC_EEP_IP_STATUS_FAILED;
  522. break;
  523. }
  524. #endif /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  525. FlexramAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  526. RamAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  527. LengthRemaining -= (Ftfc_Eep_Ip_LengthType)PageSize;
  528. }
  529. }
  530. else
  531. {
  532. Status = FTFC_EEP_IP_STATUS_FAILED;
  533. }
  534. return Status;
  535. }
  536. #endif /* FTFC_EEP_IP_COMPARE_API */
  537. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  538. * @brief Write @p PageSize bytes from @p pu8SrcAddress buffer to EEPROM at @p offset DestAddress.
  539. *
  540. * @param[out] DestAddress EEPROM offset
  541. * @param[in] pu8SrcAddress buffer containing the data to be written
  542. * @param[in] PageSize must be a valid PageSize: 1, 2 or 4 bytes for FTFC and only 4 bytes for FTFM
  543. * @param[in] Async choose between a synchronous and an asynchronous job
  544. *
  545. * @return the write operation result
  546. * @retval FTFC_EEP_IP_STATUS_FAILED FTFC not ready
  547. * @retval FTFC_EEP_IP_STATUS_FAILED an invalid page alignment was given
  548. * @retval FTFC_EEP_IP_STATUS_FAILED sync: some of the FSTAT error bits were set
  549. * @retval FTFC_EEP_IP_STATUS_TIMEOUT sync: timeout occurred while waiting for CCIF
  550. * @retval FTFC_EEP_IP_STATUS_OK sync: page successfully written to EFLASH
  551. * @retval FTFC_EEP_IP_STATUS_PENDING async: the page was written to FlexRAM, but the status of
  552. * the EFLASH record shall be interrogated with GetJobResult
  553. *
  554. * @implements Ftfc_Eep_Ip_Write_Activity
  555. *
  556. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  557. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_Write (Ftfc_Eep_Ip_AddressType DestAddress,
  558. uint8 const * pu8SrcAddress,
  559. Ftfc_Eep_Ip_PageSizeType PageSize,
  560. boolean Async
  561. )
  562. {
  563. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_FAILED;
  564. Ftfc_Eep_Ip_AddressType DestAddr = DestAddress;
  565. FTFC_DEV_ASSERT(pu8SrcAddress != NULL_PTR);
  566. FTFC_DEV_ASSERT(DestAddr < FTFC_EEP_IP_EEP_SIZE);
  567. FTFC_DEV_ASSERT((DestAddr + (Ftfc_Eep_Ip_AddressType)PageSize) <= FTFC_EEP_IP_EEP_SIZE);
  568. FTFC_DEV_ASSERT(PageSize == Ftfc_Eep_Ip_AlignedPageSize(DestAddr, \
  569. (Ftfc_Eep_Ip_AddressType)pu8SrcAddress, \
  570. (Ftfc_Eep_Ip_LengthType)PageSize));
  571. /* Convert the EEPROM location to a FlexRAM address */
  572. DestAddr += FTFC_EEP_IP_FLEXRAM_ADDRESS;
  573. if (Ftfc_Eep_Ip_IsFtfcReady())
  574. {
  575. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  576. if ((FTFC_EEP_IP_PAGE_BYTE == PageSize) ||
  577. (FTFC_EEP_IP_PAGE_WORD == PageSize))
  578. {
  579. uint8 Offset = DestAddr % FTFC_EEP_IP_PAGE_LONGWORD;
  580. uint32 * PageAddress = (uint32 *)(DestAddr - Offset);
  581. uint32 PageContents = *PageAddress;
  582. uint8 Position = 0U;
  583. uint8 SrcByte = 0U;
  584. uint32 Mask = 0U;
  585. if (FTFC_EEP_IP_PAGE_LONGWORD - Offset >= PageSize)
  586. {
  587. for (Position = Offset; Position - Offset < PageSize; ++Position)
  588. {
  589. Mask = 0xFFU << (8U * Position); /* construct the mask */
  590. PageContents &= ~Mask; /* clear the targeted byte */
  591. SrcByte = *(pu8SrcAddress + Position - Offset); /* extract the new byte */
  592. PageContents |= SrcByte << (Position * 8U); /* set the desired bits */
  593. }
  594. Status = Ftfc_Eep_Ip_AcEflashWrite((Ftfc_Eep_Ip_AddressType)PageAddress, (uint8 *)&PageContents, PageSize, Async);
  595. }
  596. else
  597. {
  598. /* the request crosses the 4-byte aligned page boundary */
  599. Status = FTFC_EEP_IP_STATUS_FAILED;
  600. }
  601. }
  602. else
  603. #endif /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  604. {
  605. Status = Ftfc_Eep_Ip_AcEflashWrite(DestAddr, pu8SrcAddress, PageSize, Async);
  606. }
  607. if ((FTFC_EEP_IP_STATUS_PENDING == Status) && (TRUE == Async))
  608. {
  609. /* In async mode the user can skip the waiting part, but he must make sure that
  610. * the DFLASH partition is not accessed (for r/w) until the CCIF flag is set. */
  611. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_10();
  612. Ftfc_Eep_Ip_xAsyncJob.Result = FTFC_EEP_IP_STATUS_PENDING;
  613. Ftfc_Eep_Ip_xAsyncJob.TicksStarted = OsIf_GetCounter(FTFC_EEP_IP_TIMEOUT_TYPE);
  614. Ftfc_Eep_Ip_xAsyncJob.TicksElapsed = 0U;
  615. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_10();
  616. }
  617. }
  618. return Status;
  619. }
  620. #if (FTFC_EEP_IP_QUICK_WRITES_API == STD_ON)
  621. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  622. * @brief QuickWrite API
  623. * @details
  624. *
  625. * For configurations with interleaved flash blocks for EEPROM backup, quick writes
  626. * should be restricted to either within the first half of EEERAM or within the second half
  627. * of EEERAM. Otherwise, FSTAT[ACCERR] will be returned.
  628. *
  629. * Once a quick write is started, user must finish the entire quick write activity prior to
  630. * starting another FTFC or CSE command.
  631. *
  632. * @param[out] DestAddress EEPROM offset needs to be 4-bytes aligned
  633. * @param[in] pu8SrcAddress
  634. * @param[in] Length
  635. *
  636. * @return quick write status
  637. * @retval FTFC_EEP_IP_STATUS_FAILED FTFC not ready
  638. * @retval FTFC_EEP_IP_STATUS_OK everything ok
  639. * @retval FTFC_EEP_IP_STATUS_FAILED invalid page size/alignment
  640. * @retval FTFC_EEP_IP_STATUS_FAILED some of the FSTAT error bits were set
  641. * @retval FTFC_EEP_IP_STATUS_FAILED_MGSTAT one or more MGSTAT 1/2/3 bits were set
  642. * @retval FTFC_EEP_IP_STATUS_TIMEOUT timeout occurred while waiting for CCIF
  643. *
  644. * @implements Ftfc_Eep_Ip_QuickWrite_Activity
  645. *
  646. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  647. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_QuickWrite (Ftfc_Eep_Ip_AddressType DestAddress,
  648. uint8 const * pu8SrcAddress,
  649. Ftfc_Eep_Ip_LengthType Length
  650. )
  651. {
  652. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_FAILED;
  653. Ftfc_Eep_Ip_AddressType SrcAddress = (Ftfc_Eep_Ip_AddressType)pu8SrcAddress;
  654. Ftfc_Eep_Ip_AddressType DestAddr = DestAddress;
  655. Ftfc_Eep_Ip_LengthType LengthRemaining = Length;
  656. /* Quick write mode only accepts 4-byte aligned writes */
  657. FTFC_DEV_ASSERT((DestAddr % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD) == 0U);
  658. FTFC_DEV_ASSERT((SrcAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD) == 0U);
  659. /* FSTAT[ACCERR] is Set if FlexRAM Function Control Code is set to make FlexRAM available for
  660. * EEPROM quick writes but the number of bytes allocated for quick write is less than 16,
  661. * more than 512, or not divisible by 4 (only 32-bit quick writes are allowed) */
  662. FTFC_DEV_ASSERT(LengthRemaining >= FTFC_EEP_IP_QUICK_WRITES_LENGTH_MIN);
  663. FTFC_DEV_ASSERT(LengthRemaining <= FTFC_EEP_IP_QUICK_WRITES_LENGTH_MAX);
  664. FTFC_DEV_ASSERT((LengthRemaining % (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_LONGWORD) == 0U);
  665. Status = Ftfc_Eep_Ip_CmdSetFlexramFunction(FLEXRAM_FCC_MODE_EEERAM_QWRITES, (uint16)LengthRemaining);
  666. if (FTFC_EEP_IP_STATUS_OK == Status)
  667. {
  668. while ((LengthRemaining > 0U) && (FTFC_EEP_IP_STATUS_OK == Status))
  669. {
  670. Status = Ftfc_Eep_Ip_Write(DestAddr, (uint8 *)SrcAddress, FTFC_EEP_IP_PAGE_LONGWORD, FALSE);
  671. LengthRemaining -= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_LONGWORD;
  672. DestAddr += (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD;
  673. SrcAddress += (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD;
  674. }
  675. if (FTFC_EEP_IP_STATUS_OK == Status)
  676. {
  677. Status = Ftfc_Eep_Ip_CmdSetFlexramFunction(FLEXRAM_FCC_MODE_EEERAM_NORMAL, 0U);
  678. }
  679. else
  680. {
  681. (void) Ftfc_Eep_Ip_CmdSetFlexramFunction(FLEXRAM_FCC_MODE_EEERAM_NORMAL, 0U);
  682. }
  683. }
  684. return Status;
  685. }
  686. #endif /* FTFC_EEP_IP_QUICK_WRITES_API */
  687. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  688. * @brief Erase API
  689. * @details Invokes a write with ERASED_CELL_VALUE.
  690. *
  691. * @return the erase operation result
  692. * @retval FTFC_EEP_IP_STATUS_FAILED FTFC not ready
  693. * @retval FTFC_EEP_IP_STATUS_FAILED an invalid page size/alignment was given
  694. * @retval FTFC_EEP_IP_STATUS_FAILED sync: some of the FSTAT error bits were set
  695. * @retval FTFC_EEP_IP_STATUS_TIMEOUT sync: timeout occurred while waiting for CCIF
  696. * @retval FTFC_EEP_IP_STATUS_OK sync: page successfully written to EFLASH
  697. * @retval FTFC_EEP_IP_STATUS_PENDING async: the page was written to FlexRAM, but the status of
  698. * the EFLASH record shall be interrogated with GetJobResult
  699. *
  700. * @implements Ftfc_Eep_Ip_Erase_Activity
  701. *
  702. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  703. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_Erase (Ftfc_Eep_Ip_AddressType Address,
  704. Ftfc_Eep_Ip_PageSizeType PageSize,
  705. boolean Async
  706. )
  707. {
  708. return Ftfc_Eep_Ip_Write(Address, (uint8 const *) &Ftfc_Eep_Ip_u32EraseValue, PageSize, Async);
  709. }
  710. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  711. * @brief Interrogate the result of the last async job, considering the timeout and FSTAT errors.
  712. *
  713. * @return the result of the last async job
  714. * @retval FTFC_EEP_IP_STATUS_OK the job finished successfully
  715. * @retval FTFC_EEP_IP_STATUS_FAILED FSTAT error bits were set
  716. * @retval FTFC_EEP_IP_STATUS_PENDING the job is still waiting for CCIF
  717. * @retval FTFC_EEP_IP_STATUS_TIMEOUT a timeout has occurred while waiting for CCIF
  718. *
  719. * @implements Ftfc_Eep_Ip_GetJobResult_Activity
  720. *
  721. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  722. Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_GetJobResult (void)
  723. {
  724. uint32 Timeout = 0U;
  725. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_11();
  726. if (FTFC_EEP_IP_STATUS_PENDING == Ftfc_Eep_Ip_xAsyncJob.Result)
  727. {
  728. if (Ftfc_Eep_Ip_IsFtfcReady())
  729. {
  730. Ftfc_Eep_Ip_xAsyncJob.Result = Ftfc_Eep_Ip_CheckFstatErrors();
  731. Ftfc_Eep_Ip_xAsyncJob.TicksElapsed = 0U;
  732. }
  733. else
  734. {
  735. Timeout = OsIf_MicrosToTicks(FTFC_EEP_IP_ASYNC_WRITE_TIMEOUT, FTFC_EEP_IP_TIMEOUT_TYPE);
  736. Ftfc_Eep_Ip_xAsyncJob.TicksElapsed += OsIf_GetElapsed(&Ftfc_Eep_Ip_xAsyncJob.TicksStarted, FTFC_EEP_IP_TIMEOUT_TYPE);
  737. if (Ftfc_Eep_Ip_xAsyncJob.TicksElapsed >= Timeout)
  738. {
  739. Ftfc_Eep_Ip_xAsyncJob.Result = FTFC_EEP_IP_STATUS_TIMEOUT;
  740. Ftfc_Eep_Ip_xAsyncJob.TicksElapsed = 0U;
  741. }
  742. }
  743. }
  744. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_11();
  745. return Ftfc_Eep_Ip_xAsyncJob.Result;
  746. }
  747. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  748. * @brief Getter for Ftfc_Eep_Ip_eBrownOutCode.
  749. *
  750. * @return the brownout code read after reset
  751. * @retval 0x04 normal write was interrupted
  752. * @retval 0x02 quick write was interrupted before writing all bytes to flash
  753. * @retval 0x01 quick write was interrupted before maintenance completed
  754. *
  755. * @implements Ftfc_Eep_Ip_GetBrownOutCode_Activity
  756. *
  757. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  758. Ftfc_Eep_Ip_BrownOutCodeType Ftfc_Eep_Ip_GetBrownOutCode (void)
  759. {
  760. return Ftfc_Eep_Ip_eBrownOutCode;
  761. }
  762. #define EEP_STOP_SEC_CODE
  763. #include "Eep_MemMap.h"
  764. /*==================================================================================================
  765. * LOCAL FUNCTIONS
  766. ==================================================================================================*/
  767. #define EEP_START_SEC_CODE
  768. #include "Eep_MemMap.h"
  769. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  770. * @brief Compute the page size, considering the addresses alignment and the remaining bytes.
  771. *
  772. * @param[in] FlexramAddress the FlexRAM address
  773. * @param[in] RamAddress the RAM address
  774. * @param[in] Length how many bytes are left to process
  775. *
  776. * @return the page size that FlexRAM will accept given the address/buffer alignments
  777. * @retval FTFC_EEP_IP_PAGE_BYTE for unaligned operations
  778. * @retval FTFC_EEP_IP_PAGE_WORD 16-bit aligned operations
  779. * @retval FTFC_EEP_IP_PAGE_LONGWORD 32-bit aligned operations
  780. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  781. static Ftfc_Eep_Ip_PageSizeType Ftfc_Eep_Ip_AlignedPageSize (Ftfc_Eep_Ip_AddressType FlexramAddress,
  782. Ftfc_Eep_Ip_AddressType RamAddress,
  783. Ftfc_Eep_Ip_LengthType Length
  784. )
  785. {
  786. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  787. #if (FTFC_EEP_IP_ALIGNED_RAM_ACCESS == STD_OFF)
  788. (void) RamAddress; /* avoid compiler warning */
  789. #endif
  790. if ((0U == (FlexramAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD))
  791. #if (FTFC_EEP_IP_ALIGNED_RAM_ACCESS == STD_ON)
  792. && (0U == (RamAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD))
  793. #endif
  794. )
  795. {
  796. if (Length >= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_LONGWORD)
  797. {
  798. /* 4 bytes aligned and length >= 4 bytes: 4 bytes operation */
  799. PageSize = FTFC_EEP_IP_PAGE_LONGWORD;
  800. }
  801. else if (Length >= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_WORD)
  802. {
  803. /* 4 bytes aligned and 4bytes > length >= 2 bytes : 2 bytes operation */
  804. PageSize = FTFC_EEP_IP_PAGE_WORD;
  805. }
  806. else
  807. {
  808. /* 4 bytes aligned and length < 2 bytes : 1 byte operation */
  809. PageSize = FTFC_EEP_IP_PAGE_BYTE;
  810. }
  811. }
  812. else if ((0U == (FlexramAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_WORD))
  813. #if (FTFC_EEP_IP_ALIGNED_RAM_ACCESS == STD_ON)
  814. && (0U == (RamAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_WORD))
  815. #endif
  816. )
  817. {
  818. if (Length >= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_WORD)
  819. {
  820. /* 2 bytes aligned and length >= 2 bytes : 2 bytes operation */
  821. PageSize = FTFC_EEP_IP_PAGE_WORD;
  822. }
  823. else
  824. {
  825. /* 2 bytes aligned and length < 2 bytes : 1 byte operation */
  826. PageSize = FTFC_EEP_IP_PAGE_BYTE;
  827. }
  828. }
  829. else
  830. {
  831. /* unaligned operation */
  832. PageSize = FTFC_EEP_IP_PAGE_BYTE;
  833. }
  834. return PageSize;
  835. }
  836. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  837. * @brief Interrogate the FTFC status.
  838. *
  839. * @details If CCIF is zero, the previous command execution is still active, a new command write
  840. * sequence cannot be started, and all writes to the FCCOB registers are ignored.
  841. *
  842. * @details The CCIF and EEERDY flag will remain negated until all EEPROM maintenance activities
  843. * have been completed.
  844. *
  845. * @return FTFC status
  846. * @retval TRUE FTFC ready
  847. * @retval FALSE FTFC not ready
  848. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  849. static boolean Ftfc_Eep_Ip_IsFtfcReady (void)
  850. {
  851. boolean Status = FALSE;
  852. if (0U != (IP_EEPROM->FCNFG & FCNFG_EEERDY_MASK))
  853. {
  854. if (0U != (IP_EEPROM->FSTAT & FSTAT_CCIF_MASK))
  855. {
  856. Status = TRUE;
  857. }
  858. }
  859. return Status;
  860. }
  861. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  862. * @brief Construct the SETRAM flash command (Set FlexRAM Function)
  863. *
  864. * @details First, set up all required FCCOB fields and then initiate the command's execution
  865. * by writing a 1 to the FSTAT[CCIF] bit.
  866. *
  867. * @param[in] FlexramFuncControlCode the control code for the SETRAM command
  868. * @param[in] QuickWritesLength only used for FLEXRAM_FCC_MODE_EEERAM_QWRITES
  869. *
  870. * @return flash command execution status
  871. * @retval FTFC_EEP_IP_STATUS_OK the command has completed successfully
  872. * @retval FTFC_EEP_IP_STATUS_TIMEOUT a timeout has occurred
  873. * @retval FTFC_EEP_IP_STATUS_FAILED the flash command execution failed
  874. * @retval FTFC_EEP_IP_STATUS_FAILED_MGSTAT one or more MGSTAT 1/2/3 bits were set (FTFM only)
  875. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  876. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_CmdSetFlexramFunction (Ftfc_Eep_Ip_FlexramFccType FlexramFuncControlCode,
  877. uint16 QuickWritesLength
  878. )
  879. {
  880. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_FAILED;
  881. /* If CCIF is zero: *
  882. * - the previous command execution is still active *
  883. * - a new command write sequence cannot be started *
  884. * - all writes to the FCCOB registers are ignored. */
  885. if (0U != (IP_EEPROM->FSTAT & FSTAT_CCIF_MASK))
  886. {
  887. /* The individual registers that make up the FCCOB data set can be written in any order. */
  888. IP_EEPROM->FCCOB[FTFC_EEP_IP_FCCOB_SETRAM_WRITE_CMD_SETRAM] = (uint8)FTFC_EEP_IP_FLASH_CMD_SETRAM_U8;
  889. IP_EEPROM->FCCOB[FTFC_EEP_IP_FCCOB_SETRAM_WRITE_FR_FCC] = (uint8)FlexramFuncControlCode;
  890. if (FLEXRAM_FCC_MODE_EEERAM_QWRITES == FlexramFuncControlCode)
  891. {
  892. IP_EEPROM->FCCOB[FTFC_EEP_IP_FCCOB_SETRAM_WRITE_QUICKWRITES_LENGTH_MSB] = (uint8)(QuickWritesLength >> 8U);
  893. IP_EEPROM->FCCOB[FTFC_EEP_IP_FCCOB_SETRAM_WRITE_QUICKWRITES_LENGTH_LSB] = (uint8) QuickWritesLength;
  894. }
  895. /* This clears the CCIF bit, which locks all FCCOB parameter fields and
  896. * they cannot be changed by the user until the command completes (CCIF returns to 1). */
  897. Status = Ftfc_Eep_Ip_AcEflashCmd();
  898. }
  899. return Status;
  900. }
  901. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  902. * @brief Check the FSTAT error flags.
  903. *
  904. * @details If the parameter check fails, the FSTAT[ACCERR] (access error) flag is set.
  905. * If the protection check fails, the FSTAT[FPVIOL] (protection error) flag is set.
  906. * Run-time errors are reported in the FSTAT[MGSTAT0] bit.
  907. *
  908. * @return the kind of error detected:
  909. * @retval FTFC_EEP_IP_STATUS_OK no error flags were set
  910. * @retval FTFC_EEP_IP_STATUS_FAILED FSTAT error bits were set
  911. * @retval FTFC_EEP_IP_STATUS_FAILED_MGSTAT MGSTAT1/2/3 bits were set (FTFM only)
  912. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  913. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_CheckFstatErrors (void)
  914. {
  915. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  916. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  917. uint8 ErrorFlagsHT = FSTAT_MGSTAT1_MASK | FSTAT_MGSTAT2_MASK | FSTAT_MGSTAT3_MASK;
  918. #endif
  919. uint8 ErrorFlags = FSTAT_MGSTAT0_MASK | FSTAT_FPVIOL_MASK | FSTAT_ACCERR_MASK | FSTAT_RDCOLERR_MASK;
  920. uint8 FlashStatus = IP_EEPROM->FSTAT;
  921. if (0U != (FlashStatus & ErrorFlags))
  922. {
  923. Status = FTFC_EEP_IP_STATUS_FAILED;
  924. }
  925. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  926. if (0U != (FlashStatus & ErrorFlagsHT))
  927. {
  928. Status = FTFC_EEP_IP_STATUS_FAILED_MGSTAT;
  929. }
  930. #endif
  931. return Status;
  932. }
  933. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  934. * @brief Implements the steps needed to be followed when accessing the EFLASH.
  935. *
  936. * @details Clear the FSTAT errors, call the notification functions, run the AC and check for errors.
  937. *
  938. * Do not attempt to read a flash block while the FTFC is running a command (CCIF = 0)
  939. * on that same block.
  940. *
  941. * @return the EFLASH operation result
  942. * @retval FTFC_EEP_IP_STATUS_OK cmd executed successfully
  943. * @retval FTFC_EEP_IP_STATUS_TIMEOUT timeout occurred while waiting for CCIF to be set
  944. * @retval FTFC_EEP_IP_STATUS_FAILED some of the FSTAT error bits were set
  945. * @retval FTFC_EEP_IP_STATUS_FAILED_MGSTAT one or more MGSTAT 1/2/3 bits were set (FTFM only)
  946. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  947. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_AcEflashCmd (void)
  948. {
  949. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  950. /* When set, the Access Error (ACCERR) and Flash Protection Violation (FPVIOL) bits in this
  951. * register prevent the launch of any more commands until the flag is cleared. */
  952. IP_EEPROM->FSTAT = (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK); /* W1C */
  953. if (Ftfc_Eep_Ip_pxConfiguration->startEepromAccessNotifPtr != NULL_PTR)
  954. {
  955. Ftfc_Eep_Ip_pxConfiguration->startEepromAccessNotifPtr();
  956. }
  957. Status = Ftfc_Eep_Ip_StartFlashCommand();
  958. if (Ftfc_Eep_Ip_pxConfiguration->finishedEepromAccessNotifPtr != NULL_PTR)
  959. {
  960. Ftfc_Eep_Ip_pxConfiguration->finishedEepromAccessNotifPtr();
  961. }
  962. if (FTFC_EEP_IP_STATUS_OK == Status)
  963. {
  964. Status = Ftfc_Eep_Ip_CheckFstatErrors();
  965. }
  966. return Status;
  967. }
  968. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  969. * @brief Implements the steps needed to be followed when accessing the EFLASH.
  970. *
  971. * @details Clear the FSTAT errors, call the notification functions, run the AC and check for errors.
  972. *
  973. * @param[in] DestAddress
  974. * @param[in] pu8SrcAddress
  975. * @param[in] PageSize
  976. * @param[in] Async
  977. *
  978. * @return the write operation result
  979. * @retval FTFC_EEP_IP_STATUS_OK sync: page successfully written to EFLASH
  980. * @retval FTFC_EEP_IP_STATUS_FAILED sync: some of the FSTAT error bits were set
  981. * @retval FTFC_EEP_IP_STATUS_FAILED_MGSTAT sync: one or more MGSTAT 1/2/3 bits were set
  982. * @retval FTFC_EEP_IP_STATUS_TIMEOUT sync: timeout occurred while waiting for CCIF
  983. * @retval FTFC_EEP_IP_STATUS_PENDING async: the page was written to FlexRAM, but the status of
  984. * the EFLASH record shall be interrogated with GetJobResult
  985. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  986. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_AcEflashWrite (Ftfc_Eep_Ip_AddressType DestAddress,
  987. uint8 const * pu8SrcAddress,
  988. Ftfc_Eep_Ip_PageSizeType PageSize,
  989. boolean Async
  990. )
  991. {
  992. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  993. /* When set, the Access Error (ACCERR) and Flash Protection Violation (FPVIOL) bits in this
  994. * register prevent writes to the FlexRAM (when EEERDY is set) until the flag is cleared */
  995. IP_EEPROM->FSTAT = (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK); /* W1C */
  996. if (Ftfc_Eep_Ip_pxConfiguration->startEepromAccessNotifPtr != NULL_PTR)
  997. {
  998. Ftfc_Eep_Ip_pxConfiguration->startEepromAccessNotifPtr();
  999. }
  1000. /* When configured for emulated EEPROM use, writes to an unprotected location in FlexRAM invoke
  1001. * the emulated EEPROM file system to program a new EEPROM data record in the emulated EEPROM
  1002. * backup memory in a round-robin fashion. This is why we can't write into FlexRAM
  1003. * while fetching code from the DFLASH partition. */
  1004. Status = Ftfc_Eep_Ip_WriteIntoFlexram(DestAddress, pu8SrcAddress, PageSize, Async);
  1005. if (Ftfc_Eep_Ip_pxConfiguration->finishedEepromAccessNotifPtr != NULL_PTR)
  1006. {
  1007. Ftfc_Eep_Ip_pxConfiguration->finishedEepromAccessNotifPtr();
  1008. }
  1009. if ((FTFC_EEP_IP_STATUS_OK == Status) && (FALSE == Async))
  1010. {
  1011. /* the FSTAT register is ready to be interrogated only after
  1012. * the FlexRAM write has successfully completed */
  1013. Status = Ftfc_Eep_Ip_CheckFstatErrors();
  1014. }
  1015. return Status;
  1016. }
  1017. #define EEP_STOP_SEC_CODE
  1018. #include "Eep_MemMap.h"
  1019. #if (FTFC_EEP_IP_LOAD_AC_INTO_RAM == STD_ON)
  1020. #define EEP_START_SEC_RAMCODE
  1021. #else
  1022. #define EEP_START_SEC_CODE
  1023. #endif
  1024. #include "Eep_MemMap.h"
  1025. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1026. * @brief Start the previously constructed Flash Command and wait for it to complete.
  1027. *
  1028. * @details This function must not run from the DFLASH partition shared with EFLASH.
  1029. *
  1030. * Before launching a command, the ACCERR and FPVIOL bits in the FSTAT register must be zero and
  1031. * the CCIF flag must read 1 to verify that any previous command has completed. If CCIF is zero,
  1032. * the previous command execution is still active, a new command write sequence cannot be started,
  1033. * and all writes to the FCCOB registers are ignored.
  1034. *
  1035. * Once all relevant command parameters have been loaded, the user launches the command
  1036. * by clearing the FSTAT[CCIF] bit by writing a '1' to it.
  1037. *
  1038. * Do not attempt to read a flash block while the FTFC is running a command (CCIF = 0)
  1039. * on that same block.
  1040. * @return the cmd execution result
  1041. * @retval FTFC_EEP_IP_STATUS_OK successful cmd execution
  1042. * @retval FTFC_EEP_IP_STATUS_TIMEOUT a timeout has occurred while waiting for the CCIF flag
  1043. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1044. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_StartFlashCommand (void)
  1045. {
  1046. /* W1C the CCIF bit to start the command */
  1047. IP_EEPROM->FSTAT = FSTAT_CCIF_MASK;
  1048. /* The CCIF flag remains zero until the FTFC command completes */
  1049. return Ftfc_Eep_Ip_WaitCcifTimeout(FTFC_EEP_IP_ABORT_TIMEOUT);
  1050. }
  1051. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1052. * @brief Write a page into FlexRAM.
  1053. * @details This function must not run from the DFLASH partition shared with EFLASH.
  1054. *
  1055. * @param[in] DestAddress
  1056. * @param[in] pu8SrcAddress
  1057. * @param[in] PageSize
  1058. * @param[in] Async
  1059. *
  1060. * @return the result of the write request
  1061. * @retval FTFC_EEP_IP_STATUS_PENDING async: GetJobResult shall be used to check the FSTAT errors
  1062. * @retval FTFC_EEP_IP_STATUS_OK sync: the write has succeeded
  1063. * @retval FTFC_EEP_IP_STATUS_TIMEOUT sync: a timeout has occured while waiting for the CCIF flag
  1064. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1065. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_WriteIntoFlexram (Ftfc_Eep_Ip_AddressType DestAddress,
  1066. uint8 const * pu8SrcAddress,
  1067. Ftfc_Eep_Ip_PageSizeType PageSize,
  1068. boolean Async
  1069. )
  1070. {
  1071. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_PENDING;
  1072. Ftfc_Eep_Ip_AddressType SrcAdd = (Ftfc_Eep_Ip_AddressType)pu8SrcAddress;
  1073. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  1074. *(uint32 *)DestAddress = *(uint32 const *)SrcAdd;
  1075. (void) PageSize; /* Page size is always LONGWORD for FTFM */
  1076. #else /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  1077. switch (PageSize)
  1078. {
  1079. case FTFC_EEP_IP_PAGE_BYTE:
  1080. *(uint8 *)DestAddress = *(uint8 const *)SrcAdd;
  1081. break;
  1082. case FTFC_EEP_IP_PAGE_WORD:
  1083. *(uint16 *)DestAddress = *(uint16 const *)SrcAdd;
  1084. break;
  1085. case FTFC_EEP_IP_PAGE_LONGWORD:
  1086. *(uint32 *)DestAddress = *(uint32 const *)SrcAdd;
  1087. break;
  1088. default:
  1089. /* page size checked in the upper call stack */
  1090. break;
  1091. }
  1092. #endif /* FTFC_EEP_IP_HIGH_TEMP_CHIP */
  1093. MCAL_FAULT_INJECTION_POINT(EEP_FIP_FTFx_CHECK_BO);
  1094. /* When a write occurs the FlexRAM is not accessible until the CCIF bit is set. */
  1095. if (FALSE == Async)
  1096. {
  1097. Status = Ftfc_Eep_Ip_WaitCcifTimeout(FTFC_EEP_IP_SYNC_WRITE_TIMEOUT);
  1098. }
  1099. return Status;
  1100. }
  1101. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1102. * @brief Wait for the CCIF flag to be set or exit with a given timeout.
  1103. *
  1104. * @details This function must not run from the DFLASH partition shared with EFLASH.
  1105. *
  1106. * @param[in] TimeoutCounter given as a dummy counter that is decremented in a while loop
  1107. *
  1108. * @return the status of the flash operation
  1109. * @retval FTFC_EEP_IP_STATUS_OK the flash cmd/write has completed
  1110. * @retval FTFC_EEP_IP_STATUS_TIMEOUT a timeout has occurred
  1111. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1112. static Ftfc_Eep_Ip_StatusType Ftfc_Eep_Ip_WaitCcifTimeout (uint32 TimeoutCounter)
  1113. {
  1114. Ftfc_Eep_Ip_StatusType Status = FTFC_EEP_IP_STATUS_OK;
  1115. uint32 counter = TimeoutCounter;
  1116. while (0U == (IP_EEPROM->FSTAT & FSTAT_CCIF_MASK))
  1117. {
  1118. --counter;
  1119. if (0U == counter)
  1120. {
  1121. Status = FTFC_EEP_IP_STATUS_TIMEOUT;
  1122. break;
  1123. }
  1124. /* feed the watchdog */
  1125. if (NULL_PTR != Ftfc_Eep_Ip_pxConfiguration->acCallBackPtr)
  1126. {
  1127. Ftfc_Eep_Ip_pxConfiguration->acCallBackPtr();
  1128. }
  1129. }
  1130. return Status;
  1131. }
  1132. #if (FTFC_EEP_IP_LOAD_AC_INTO_RAM == STD_ON)
  1133. #define EEP_STOP_SEC_RAMCODE
  1134. #else
  1135. #define EEP_STOP_SEC_CODE
  1136. #endif
  1137. #include "Eep_MemMap.h"
  1138. #ifdef __cplusplus
  1139. }
  1140. #endif
  1141. /** @} */