Eep_IPW.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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 Eep_IPW.c
  26. *
  27. * @addtogroup EEP_IPW
  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 "Eep.h"
  41. #include "Eep_IPW.h"
  42. #include "Det.h"
  43. /*==================================================================================================
  44. * SOURCE FILE VERSION INFORMATION
  45. ==================================================================================================*/
  46. #define EEP_IPW_VENDOR_ID_C 43
  47. #define EEP_IPW_AR_RELEASE_MAJOR_VERSION_C 4
  48. #define EEP_IPW_AR_RELEASE_MINOR_VERSION_C 4
  49. #define EEP_IPW_AR_RELEASE_REVISION_VERSION_C 0
  50. #define EEP_IPW_SW_MAJOR_VERSION_C 1
  51. #define EEP_IPW_SW_MINOR_VERSION_C 0
  52. #define EEP_IPW_SW_PATCH_VERSION_C 0
  53. /*==================================================================================================
  54. * FILE VERSION CHECKS
  55. ==================================================================================================*/
  56. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  57. /* Version checks for OsIf.h */
  58. #if ((EEP_IPW_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
  59. (EEP_IPW_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION) \
  60. )
  61. #error "AutoSar Version Numbers of Eep_IPW.c and OsIf.h are different"
  62. #endif
  63. #endif
  64. /* Version checks for Eep.h */
  65. #if (EEP_IPW_VENDOR_ID_C != EEP_VENDOR_ID)
  66. #error "Eep_IPW.c and Eep.h have different vendor ids"
  67. #endif
  68. #if ((EEP_IPW_AR_RELEASE_MAJOR_VERSION_C != EEP_AR_RELEASE_MAJOR_VERSION) || \
  69. (EEP_IPW_AR_RELEASE_MINOR_VERSION_C != EEP_AR_RELEASE_MINOR_VERSION) || \
  70. (EEP_IPW_AR_RELEASE_REVISION_VERSION_C != EEP_AR_RELEASE_REVISION_VERSION) \
  71. )
  72. #error "AutoSar Version Numbers of Eep_IPW.c and Eep.h are different"
  73. #endif
  74. #if ((EEP_IPW_SW_MAJOR_VERSION_C != EEP_SW_MAJOR_VERSION) || \
  75. (EEP_IPW_SW_MINOR_VERSION_C != EEP_SW_MINOR_VERSION) || \
  76. (EEP_IPW_SW_PATCH_VERSION_C != EEP_SW_PATCH_VERSION) \
  77. )
  78. #error "Software Version Numbers of Eep_IPW.c and Eep.h are different"
  79. #endif
  80. /* Version checks for Eep_IPW.h */
  81. #if (EEP_IPW_VENDOR_ID_C != EEP_IPW_VENDOR_ID_H)
  82. #error "Eep_IPW.c and Eep_IPW.h have different vendor ids"
  83. #endif
  84. #if ((EEP_IPW_AR_RELEASE_MAJOR_VERSION_C != EEP_IPW_AR_RELEASE_MAJOR_VERSION_H) || \
  85. (EEP_IPW_AR_RELEASE_MINOR_VERSION_C != EEP_IPW_AR_RELEASE_MINOR_VERSION_H) || \
  86. (EEP_IPW_AR_RELEASE_REVISION_VERSION_C != EEP_IPW_AR_RELEASE_REVISION_VERSION_H) \
  87. )
  88. #error "AutoSar Version Numbers of Eep_IPW.c and Eep_IPW.h are different"
  89. #endif
  90. #if ((EEP_IPW_SW_MAJOR_VERSION_C != EEP_IPW_SW_MAJOR_VERSION_H) || \
  91. (EEP_IPW_SW_MINOR_VERSION_C != EEP_IPW_SW_MINOR_VERSION_H) || \
  92. (EEP_IPW_SW_PATCH_VERSION_C != EEP_IPW_SW_PATCH_VERSION_H) \
  93. )
  94. #error "Software Version Numbers of Eep_IPW.c and Eep_IPW.h are different"
  95. #endif
  96. /* Version checks for Det.h */
  97. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  98. #if ((EEP_IPW_AR_RELEASE_MAJOR_VERSION_C != DET_AR_RELEASE_MAJOR_VERSION) || \
  99. (EEP_IPW_AR_RELEASE_MINOR_VERSION_C != DET_AR_RELEASE_MINOR_VERSION) \
  100. )
  101. #error "AutoSar Version Numbers of Eep_IPW.c and Det.h are different"
  102. #endif
  103. #endif
  104. /*==================================================================================================
  105. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  106. ==================================================================================================*/
  107. #if ((EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_ON) || \
  108. (EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_ON))
  109. typedef struct
  110. {
  111. Eep_AddressType DestAddress;
  112. uint8 const * SrcAddress;
  113. Eep_LengthType Length;
  114. boolean InProgress;
  115. } Eep_Ipw_xAsyncJobType;
  116. #endif
  117. /*==================================================================================================
  118. * LOCAL MACROS
  119. ==================================================================================================*/
  120. /*==================================================================================================
  121. * GLOBAL CONSTANTS
  122. ==================================================================================================*/
  123. /*==================================================================================================
  124. * GLOBAL VARIABLES
  125. ==================================================================================================*/
  126. /*==================================================================================================
  127. * LOCAL CONSTANTS
  128. ==================================================================================================*/
  129. /*==================================================================================================
  130. * LOCAL VARIABLES
  131. ==================================================================================================*/
  132. #define EEP_START_SEC_VAR_CLEARED_UNSPECIFIED
  133. #include "Eep_MemMap.h"
  134. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  135. static Eep_ConfigType const * Eep_Ipw_pxEepConfig;
  136. #endif
  137. #if ((EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_ON) || \
  138. (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_ON))
  139. static Eep_Ipw_xAsyncJobType Eep_Ipw_xAsyncJob;
  140. #endif
  141. #define EEP_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  142. #include "Eep_MemMap.h"
  143. /*==================================================================================================
  144. * LOCAL FUNCTION PROTOTYPES
  145. ==================================================================================================*/
  146. #define EEP_START_SEC_CODE
  147. #include "Eep_MemMap.h"
  148. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  149. static void Eep_Ipw_ReportBrownOut (
  150. void
  151. );
  152. #endif
  153. static void Eep_Ipw_ReportFailure (Ftfc_Eep_Ip_StatusType FtfcStatus);
  154. static Ftfc_Eep_Ip_PageSizeType Eep_Ipw_AlignedPageSize (Ftfc_Eep_Ip_AddressType FlexramAddress,
  155. Ftfc_Eep_Ip_AddressType RamAddress,
  156. Ftfc_Eep_Ip_LengthType Length
  157. );
  158. /*==================================================================================================
  159. * GLOBAL FUNCTIONS
  160. ==================================================================================================*/
  161. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  162. * @brief Initialize the FTFC IP
  163. * @details FTFC is the only EEPROM available on this platform.
  164. *
  165. * @return FTFC initialization status
  166. * @retval EEP_E_OK on success
  167. * @retval EEP_E_FAILED on failure
  168. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  169. Eep_ReturnType Eep_Ipw_Init (Eep_ConfigType const * pxEepConfig)
  170. {
  171. Eep_ReturnType RetVal = EEP_E_OK;
  172. Ftfc_Eep_Ip_StatusType FtfcStatus = FTFC_EEP_IP_STATUS_OK;
  173. /* reinitialize the global variables */
  174. #if ((EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_ON) || \
  175. (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_ON))
  176. Eep_Ipw_xAsyncJob.DestAddress = 0U;
  177. Eep_Ipw_xAsyncJob.SrcAddress = NULL_PTR;
  178. Eep_Ipw_xAsyncJob.Length = 0U;
  179. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  180. #endif
  181. /* Call Ip init function */
  182. FtfcStatus = Ftfc_Eep_Ip_Init(pxEepConfig->pxFtfcEepIpConfig);
  183. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  184. Eep_Ipw_pxEepConfig = pxEepConfig;
  185. Eep_Ipw_ReportBrownOut();
  186. #endif
  187. /* Check the status after finishing */
  188. if (FTFC_EEP_IP_STATUS_OK != FtfcStatus)
  189. {
  190. Eep_Ipw_ReportFailure(FtfcStatus);
  191. RetVal = EEP_E_FAILED;
  192. }
  193. return RetVal;
  194. }
  195. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  196. * @brief Check parameters for the Read job.
  197. *
  198. * @param[in] SrcAddress
  199. * @param[in] pu8DestAddress
  200. * @param[in] Length
  201. *
  202. * @return Ok / not ok to proceed with the read operation.
  203. * @retval E_OK
  204. * @retval E_NOT_OK
  205. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  206. Std_ReturnType Eep_Ipw_CheckReadParams (Eep_AddressType SrcAddress,
  207. uint8 const * pu8DestAddress,
  208. Eep_LengthType Length
  209. )
  210. {
  211. Std_ReturnType RetVal = E_NOT_OK;
  212. /* Check the validity of Source Address */
  213. if (SrcAddress >= FTFC_EEP_IP_EEP_SIZE)
  214. {
  215. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  216. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_READ_ID, EEP_E_PARAM_ADDRESS);
  217. #endif
  218. }
  219. /* Check the validity of Length */
  220. else if ((0U == Length) || ((SrcAddress + Length) > FTFC_EEP_IP_EEP_SIZE))
  221. {
  222. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  223. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_READ_ID, EEP_E_PARAM_LENGTH);
  224. #endif
  225. }
  226. /* Check the validity of destination address */
  227. else if (NULL_PTR == pu8DestAddress)
  228. {
  229. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  230. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_READ_ID, EEP_E_PARAM_DATA);
  231. #endif
  232. }
  233. else
  234. {
  235. RetVal = E_OK;
  236. }
  237. return RetVal;
  238. }
  239. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  240. * @brief Synchronous read.
  241. *
  242. * @param[out] pu8DestAddress
  243. *
  244. * @return Synchronous read op status.
  245. * @retval EEP_E_OK
  246. * @retval EEP_E_FAILED
  247. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  248. Eep_ReturnType Eep_Ipw_Read (Eep_AddressType SrcAddress,
  249. uint8 * pu8DestAddress,
  250. Eep_LengthType Length
  251. )
  252. {
  253. Eep_ReturnType RetVal = EEP_E_FAILED;
  254. Ftfc_Eep_Ip_StatusType FtfcStatus = FTFC_EEP_IP_STATUS_OK;
  255. /* Call Ip read function */
  256. FtfcStatus = Ftfc_Eep_Ip_Read(SrcAddress, pu8DestAddress, Length);
  257. /* Check status of read operation */
  258. if (FTFC_EEP_IP_STATUS_OK == FtfcStatus)
  259. {
  260. RetVal = EEP_E_OK;
  261. }
  262. return RetVal;
  263. }
  264. #if (EEP_COMPARE_API == STD_ON)
  265. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  266. * @brief Check the params given for a Compare job.
  267. *
  268. * @param[in] SrcAddress
  269. * @param[in] pu8DestAddress
  270. * @param[in] Length
  271. *
  272. * @return Ok / not ok to proceed to the compare operation with the given params.
  273. * @retval E_OK
  274. * @retval E_NOT_OK
  275. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  276. Std_ReturnType Eep_Ipw_CheckCompareParams (Eep_AddressType SrcAddress,
  277. uint8 const * pu8DestAddress,
  278. Eep_LengthType Length
  279. )
  280. {
  281. Std_ReturnType retVal = E_NOT_OK;
  282. /* Check the validity of source address */
  283. if (SrcAddress >= FTFC_EEP_IP_EEP_SIZE)
  284. {
  285. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  286. (void) Det_ReportError ((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_COMPARE_ID, EEP_E_PARAM_ADDRESS);
  287. #endif
  288. }
  289. /* Check the validity of length */
  290. else if ((0U == Length) || ((SrcAddress + Length) > FTFC_EEP_IP_EEP_SIZE))
  291. {
  292. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  293. (void) Det_ReportError ((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_COMPARE_ID, EEP_E_PARAM_LENGTH);
  294. #endif
  295. }
  296. /* Check the validity of destination address */
  297. else if (NULL_PTR == pu8DestAddress)
  298. {
  299. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  300. (void) Det_ReportError ((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_COMPARE_ID, EEP_E_PARAM_DATA);
  301. #endif
  302. }
  303. else
  304. {
  305. retVal = E_OK;
  306. }
  307. return retVal;
  308. }
  309. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  310. * @brief Compare an EEPROM area with a given buffer.
  311. *
  312. * @param[in] SrcAddress
  313. * @param[in] pu8DestAddress
  314. * @param[in] Length
  315. *
  316. * @return the comparison result:
  317. * @retval EEP_E_OK memory contents match
  318. * @retval EEP_E_BLOCK_INCONSISTENT memory contents do not match
  319. * @retval EEP_E_FAILED compare operation failed
  320. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  321. Eep_ReturnType Eep_Ipw_CompareSync (Eep_AddressType SrcAddress,
  322. uint8 const * pu8DestAddress,
  323. Eep_LengthType Length
  324. )
  325. {
  326. Eep_ReturnType RetVal = EEP_E_OK;
  327. Ftfc_Eep_Ip_StatusType FtfcStatus = FTFC_EEP_IP_STATUS_OK;
  328. /* Call Ip compare function */
  329. FtfcStatus = Ftfc_Eep_Ip_Compare(SrcAddress, pu8DestAddress, Length);
  330. /* Check the status after compare operation */
  331. switch (FtfcStatus)
  332. {
  333. case FTFC_EEP_IP_STATUS_OK:
  334. RetVal = EEP_E_OK;
  335. break;
  336. case FTFC_EEP_IP_STATUS_BLOCK_INCONSISTENT:
  337. RetVal = EEP_E_BLOCK_INCONSISTENT;
  338. break;
  339. default:
  340. RetVal = EEP_E_FAILED;
  341. break;
  342. }
  343. return RetVal;
  344. }
  345. #endif /* EEP_COMPARE_API */
  346. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  347. * @brief Check if the parameters are ok and the HLD can start the erase job.
  348. *
  349. * @param[in] Address
  350. * @param[in] Length
  351. *
  352. * @return Ok / Not ok to start the erase job.
  353. * @retval E_OK
  354. * @retval E_NOT_OK
  355. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  356. Std_ReturnType Eep_Ipw_CheckEraseParams (Eep_AddressType Address,
  357. Eep_LengthType Length
  358. )
  359. {
  360. Std_ReturnType retVal = E_NOT_OK;
  361. /* Check the address */
  362. if (Address >= FTFC_EEP_IP_EEP_SIZE)
  363. {
  364. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  365. (void)Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_ERASE_ID, EEP_E_PARAM_ADDRESS);
  366. #endif
  367. }
  368. /* Check the length */
  369. else if ((0U == Length) || ((Address + Length) > FTFC_EEP_IP_EEP_SIZE))
  370. {
  371. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  372. (void)Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_ERASE_ID, EEP_E_PARAM_LENGTH);
  373. #endif
  374. }
  375. else
  376. {
  377. retVal = E_OK;
  378. }
  379. return retVal;
  380. }
  381. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  382. * @brief Erase starting from @p Address up to Length bytes.
  383. *
  384. * @param[in] address
  385. * @param[in] length
  386. *
  387. * @return Erase status
  388. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  389. Eep_ReturnType Eep_Ipw_Erase (Eep_AddressType Address,
  390. Eep_LengthType Length
  391. )
  392. {
  393. Eep_AddressType EraseAdd = Address;
  394. Eep_LengthType LengthRemaining = Length;
  395. Eep_ReturnType RetVal = EEP_E_FAILED;
  396. Ftfc_Eep_Ip_StatusType FtfcStatus = FTFC_EEP_IP_STATUS_OK;
  397. #if (EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_ON)
  398. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  399. if (FALSE == Eep_Ipw_xAsyncJob.InProgress)
  400. {
  401. Eep_Ipw_xAsyncJob.DestAddress = EraseAdd;
  402. Eep_Ipw_xAsyncJob.SrcAddress = NULL_PTR;
  403. Eep_Ipw_xAsyncJob.Length = LengthRemaining;
  404. PageSize = Eep_Ipw_AlignedPageSize(Eep_Ipw_xAsyncJob.DestAddress, 0U, Eep_Ipw_xAsyncJob.Length);
  405. FtfcStatus = Ftfc_Eep_Ip_Erase(Eep_Ipw_xAsyncJob.DestAddress, PageSize, TRUE);
  406. if (FTFC_EEP_IP_STATUS_PENDING == FtfcStatus)
  407. {
  408. Eep_Ipw_xAsyncJob.DestAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  409. Eep_Ipw_xAsyncJob.Length -= (Ftfc_Eep_Ip_LengthType)PageSize;
  410. Eep_Ipw_xAsyncJob.InProgress = TRUE;
  411. RetVal = EEP_E_PENDING;
  412. }
  413. }
  414. else
  415. {
  416. FtfcStatus = Ftfc_Eep_Ip_GetJobResult();
  417. switch (FtfcStatus)
  418. {
  419. case FTFC_EEP_IP_STATUS_PENDING:
  420. RetVal = EEP_E_PENDING;
  421. break;
  422. case FTFC_EEP_IP_STATUS_OK:
  423. if (Eep_Ipw_xAsyncJob.Length > 0U)
  424. {
  425. PageSize = Eep_Ipw_AlignedPageSize(Eep_Ipw_xAsyncJob.DestAddress, 0U, Eep_Ipw_xAsyncJob.Length);
  426. FtfcStatus = Ftfc_Eep_Ip_Erase(Eep_Ipw_xAsyncJob.DestAddress, PageSize, TRUE);
  427. if (FTFC_EEP_IP_STATUS_PENDING == FtfcStatus)
  428. {
  429. Eep_Ipw_xAsyncJob.DestAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  430. Eep_Ipw_xAsyncJob.Length -= (Ftfc_Eep_Ip_LengthType)PageSize;
  431. RetVal = EEP_E_PENDING;
  432. }
  433. else
  434. {
  435. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  436. }
  437. }
  438. else
  439. {
  440. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  441. RetVal = EEP_E_OK;
  442. }
  443. break;
  444. default:
  445. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  446. break;
  447. }
  448. }
  449. #else /* EEP_ASYNC_ERASE_OPERATIONS_ENABLED */
  450. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  451. while ((LengthRemaining > 0U) && (FTFC_EEP_IP_STATUS_OK == FtfcStatus))
  452. {
  453. PageSize = Eep_Ipw_AlignedPageSize(EraseAdd, 0U, LengthRemaining);
  454. FtfcStatus = Ftfc_Eep_Ip_Erase(EraseAdd, PageSize, FALSE);
  455. LengthRemaining -= (Eep_LengthType)PageSize;
  456. EraseAdd += (Eep_AddressType)PageSize;
  457. }
  458. if (FTFC_EEP_IP_STATUS_OK == FtfcStatus)
  459. {
  460. RetVal = EEP_E_OK;
  461. }
  462. #endif /* EEP_ASYNC_ERASE_OPERATIONS_ENABLED */
  463. /* Repor the status after finishing */
  464. Eep_Ipw_ReportFailure(FtfcStatus);
  465. return RetVal;
  466. }
  467. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  468. * @brief Check the parameters given for a Write job.
  469. *
  470. * @param[in] DestAddress
  471. * @param[in] pu8SrcAddress
  472. * @param[in] Length
  473. *
  474. * @return Ok / not ok to start the write job with those parameters.
  475. * @retval E_OK
  476. * @retval E_NOT_OK
  477. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  478. Std_ReturnType Eep_Ipw_CheckWriteParams (Eep_AddressType DestAddress,
  479. uint8 const * pu8SrcAddress,
  480. Eep_LengthType Length
  481. )
  482. {
  483. Std_ReturnType retVal = E_NOT_OK;
  484. /* Check the validity of destination address */
  485. if (DestAddress >= FTFC_EEP_IP_EEP_SIZE)
  486. {
  487. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  488. (void) Det_ReportError ((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_WRITE_ID, EEP_E_PARAM_ADDRESS);
  489. #endif
  490. }
  491. /* Check the validity of length */
  492. else if ((0U == Length) || ((DestAddress + Length) > FTFC_EEP_IP_EEP_SIZE))
  493. {
  494. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  495. (void) Det_ReportError ((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_WRITE_ID, EEP_E_PARAM_LENGTH);
  496. #endif
  497. }
  498. /* Check the validity of source address */
  499. else if (NULL_PTR == pu8SrcAddress)
  500. {
  501. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  502. (void) Det_ReportError ((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_WRITE_ID, EEP_E_PARAM_DATA);
  503. #endif
  504. }
  505. else
  506. {
  507. retVal = E_OK;
  508. }
  509. return retVal;
  510. }
  511. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  512. * @brief Write operation.
  513. *
  514. * @param[in] DestAddress
  515. * @param[in] pu8SrcAddress
  516. * @param[in] Length
  517. *
  518. * @return The write call may end in one of the following states:
  519. * @retval EEP_E_OK job jas finished successfully
  520. * @retval EEP_E_PENDING async: the job is in progress
  521. * @retval EEP_E_FAILED an error has occurred
  522. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  523. Eep_ReturnType Eep_Ipw_Write (Eep_AddressType DestAddress,
  524. uint8 const * pu8SrcAddress,
  525. Eep_LengthType Length
  526. )
  527. {
  528. Eep_ReturnType RetVal = EEP_E_FAILED;
  529. Ftfc_Eep_Ip_StatusType FtfcStatus = FTFC_EEP_IP_STATUS_OK;
  530. Eep_AddressType DestAdd = DestAddress;
  531. uint8 const * pu8SrcAdd = pu8SrcAddress;
  532. Eep_LengthType LengthRemaining = Length;
  533. #if (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_ON)
  534. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  535. if (FALSE == Eep_Ipw_xAsyncJob.InProgress)
  536. {
  537. Eep_Ipw_xAsyncJob.DestAddress = DestAdd;
  538. Eep_Ipw_xAsyncJob.SrcAddress = pu8SrcAdd;
  539. Eep_Ipw_xAsyncJob.Length = LengthRemaining;
  540. PageSize = Eep_Ipw_AlignedPageSize(Eep_Ipw_xAsyncJob.DestAddress, (Eep_AddressType)Eep_Ipw_xAsyncJob.SrcAddress, Eep_Ipw_xAsyncJob.Length);
  541. FtfcStatus = Ftfc_Eep_Ip_Write(Eep_Ipw_xAsyncJob.DestAddress, Eep_Ipw_xAsyncJob.SrcAddress, PageSize, TRUE);
  542. if (FTFC_EEP_IP_STATUS_PENDING == FtfcStatus)
  543. {
  544. Eep_Ipw_xAsyncJob.DestAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  545. Eep_Ipw_xAsyncJob.SrcAddress = (uint8 const *)((Eep_AddressType)Eep_Ipw_xAsyncJob.SrcAddress + (uint8)PageSize);
  546. Eep_Ipw_xAsyncJob.Length -= (Ftfc_Eep_Ip_LengthType)PageSize;
  547. Eep_Ipw_xAsyncJob.InProgress = TRUE;
  548. RetVal = EEP_E_PENDING;
  549. }
  550. }
  551. else
  552. {
  553. FtfcStatus = Ftfc_Eep_Ip_GetJobResult();
  554. switch (FtfcStatus)
  555. {
  556. case FTFC_EEP_IP_STATUS_PENDING:
  557. RetVal = EEP_E_PENDING;
  558. break;
  559. case FTFC_EEP_IP_STATUS_OK:
  560. if (Eep_Ipw_xAsyncJob.Length > 0U)
  561. {
  562. PageSize = Eep_Ipw_AlignedPageSize(Eep_Ipw_xAsyncJob.DestAddress, (Eep_AddressType)Eep_Ipw_xAsyncJob.SrcAddress, Eep_Ipw_xAsyncJob.Length);
  563. FtfcStatus = Ftfc_Eep_Ip_Write(Eep_Ipw_xAsyncJob.DestAddress, Eep_Ipw_xAsyncJob.SrcAddress, PageSize, TRUE);
  564. if (FTFC_EEP_IP_STATUS_PENDING == FtfcStatus)
  565. {
  566. Eep_Ipw_xAsyncJob.DestAddress += (Ftfc_Eep_Ip_AddressType)PageSize;
  567. Eep_Ipw_xAsyncJob.SrcAddress = (uint8 const *)((Eep_AddressType)Eep_Ipw_xAsyncJob.SrcAddress + (uint8)PageSize);
  568. Eep_Ipw_xAsyncJob.Length -= (Ftfc_Eep_Ip_LengthType)PageSize;
  569. RetVal = EEP_E_PENDING;
  570. }
  571. else
  572. {
  573. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  574. }
  575. }
  576. else
  577. {
  578. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  579. RetVal = EEP_E_OK;
  580. }
  581. break;
  582. default:
  583. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  584. break;
  585. }
  586. }
  587. #else /* EEP_ASYNC_WRITE_OPERATIONS_ENABLED */
  588. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  589. while ((LengthRemaining > 0U) && (FTFC_EEP_IP_STATUS_OK == FtfcStatus))
  590. {
  591. PageSize = Eep_Ipw_AlignedPageSize(DestAdd, (Eep_AddressType)pu8SrcAdd, LengthRemaining);
  592. FtfcStatus = Ftfc_Eep_Ip_Write(DestAdd, pu8SrcAdd, PageSize, FALSE);
  593. LengthRemaining -= (Eep_LengthType)PageSize;
  594. DestAdd += (Eep_AddressType)PageSize;
  595. pu8SrcAdd = (uint8*)((Eep_AddressType)pu8SrcAdd + (Eep_AddressType)PageSize);
  596. }
  597. if (FTFC_EEP_IP_STATUS_OK == FtfcStatus)
  598. {
  599. RetVal = EEP_E_OK;
  600. }
  601. #endif /* EEP_ASYNC_WRITE_OPERATIONS_ENABLED */
  602. /* Report the status of write operation */
  603. Eep_Ipw_ReportFailure(FtfcStatus);
  604. return RetVal;
  605. }
  606. #if (EEP_QUICK_WRITES_API == STD_ON)
  607. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  608. * @brief Check the parameters given for a QuickWrite job.
  609. *
  610. * @param[in] DestAddress
  611. * @param[in] pu8SrcAddress
  612. * @param[in] Length
  613. * @param[in] QuickWritesLength
  614. *
  615. * @return Ok / not ok to start the quick write job with those parameters.
  616. * @retval E_OK
  617. * @retval E_NOT_OK
  618. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  619. Std_ReturnType Eep_Ipw_CheckQuickWriteParams (Eep_AddressType DestAddress,
  620. uint8 const * pu8SrcAddress,
  621. Eep_LengthType Length,
  622. Eep_LengthType QuickWritesLength
  623. )
  624. {
  625. Std_ReturnType retVal = E_NOT_OK;
  626. /* Check the validity of destination address */
  627. if ((DestAddress >= FTFC_EEP_IP_EEP_SIZE) ||
  628. ((DestAddress % 4U) != 0U) ||
  629. ((((uint32)pu8SrcAddress) % 4U) != 0U))
  630. {
  631. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  632. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_QUICK_WRITE_ID, EEP_E_PARAM_ADDRESS);
  633. #endif
  634. }
  635. /* Check the validity of length */
  636. else if ((0U == Length) || ((DestAddress + Length) > FTFC_EEP_IP_EEP_SIZE) ||
  637. (QuickWritesLength < 16U) || (QuickWritesLength > 512U) ||
  638. ((QuickWritesLength % 4U) != 0U) || ((Length % QuickWritesLength) != 0U))
  639. {
  640. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  641. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_QUICK_WRITE_ID, EEP_E_PARAM_LENGTH);
  642. #endif
  643. }
  644. /* Check the validity of source add */
  645. else if (NULL_PTR == pu8SrcAddress)
  646. {
  647. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  648. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_QUICK_WRITE_ID, EEP_E_PARAM_DATA);
  649. #endif
  650. }
  651. else
  652. {
  653. retVal = E_OK;
  654. }
  655. return retVal;
  656. }
  657. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  658. * @brief Quick Write operation.
  659. *
  660. * @param[in] DestAddress
  661. * @param[in] pu8SrcAddress
  662. * @param[in] Length
  663. *
  664. * @return The quick write call may end in one of the following states:
  665. * @retval EEP_E_OK
  666. * @retval EEP_E_FAILED
  667. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  668. Eep_ReturnType Eep_Ipw_QuickWrite (Eep_AddressType DestAddress,
  669. uint8 const * pu8SrcAddress,
  670. Eep_LengthType Length
  671. )
  672. {
  673. Eep_ReturnType RetVal = EEP_E_OK;
  674. Ftfc_Eep_Ip_StatusType FtfcStatus = FTFC_EEP_IP_STATUS_OK;
  675. FtfcStatus = Ftfc_Eep_Ip_QuickWrite(DestAddress, pu8SrcAddress, Length);
  676. /* Check status after operation finish */
  677. if (FTFC_EEP_IP_STATUS_OK != FtfcStatus)
  678. {
  679. RetVal = EEP_E_FAILED;
  680. Eep_Ipw_ReportFailure(FtfcStatus);
  681. }
  682. return RetVal;
  683. }
  684. #endif /* EEP_QUICK_WRITES_API */
  685. #if (EEP_CANCEL_API == STD_ON)
  686. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  687. * @brief Cancel the current operation.
  688. *
  689. * @return the status of the IP HW
  690. * @retval EEP_E_OK the FTFC operation finished
  691. * @retval EEP_E_PENDING a timeout has occured while waiting for the HW IP
  692. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  693. Eep_ReturnType Eep_Ipw_Cancel (
  694. void)
  695. {
  696. Eep_ReturnType Status = EEP_E_OK;
  697. uint32 Timeout = OsIf_MicrosToTicks(FTFC_EEP_IP_ABORT_TIMEOUT, FTFC_EEP_IP_TIMEOUT_TYPE);
  698. uint32 CurrentTicks = OsIf_GetCounter(FTFC_EEP_IP_TIMEOUT_TYPE);
  699. uint32 ElapsedTicks = 0U;
  700. /* wait until FlexRam is ready or abort if timeout is reached */
  701. while (FTFC_EEP_IP_STATUS_PENDING == Ftfc_Eep_Ip_GetJobResult())
  702. {
  703. ElapsedTicks += OsIf_GetElapsed(&CurrentTicks, FTFC_EEP_IP_TIMEOUT_TYPE);
  704. if (ElapsedTicks >= Timeout)
  705. {
  706. Status = EEP_E_PENDING;
  707. break;
  708. }
  709. }
  710. #if ((EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_ON) || \
  711. (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_ON))
  712. Eep_Ipw_xAsyncJob.InProgress = FALSE;
  713. #endif
  714. return Status;
  715. }
  716. #endif /* EEP_CANCEL_API */
  717. /*==================================================================================================
  718. * LOCAL FUNCTIONS
  719. ==================================================================================================*/
  720. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  721. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  722. * @brief Reports the brownout code to DEM.
  723. * @details The brownout code is read at init.
  724. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  725. static void Eep_Ipw_ReportBrownOut (void)
  726. {
  727. switch (Ftfc_Eep_Ip_GetBrownOutCode())
  728. {
  729. case FTFC_EEP_IP_BO_DURING_MAINTENANCE:
  730. if (TRUE == Eep_Ipw_pxEepConfig->Eep_E_BOMaintenanceCfg.state)
  731. {
  732. (void) Dem_SetEventStatus((Dem_EventIdType)Eep_Ipw_pxEepConfig->Eep_E_BOMaintenanceCfg.id, DEM_EVENT_STATUS_FAILED);
  733. }
  734. break;
  735. case FTFC_EEP_IP_BO_DURING_QUICK_WRITES:
  736. if (TRUE == Eep_Ipw_pxEepConfig->Eep_E_BOQuickWritesCfg.state)
  737. {
  738. (void) Dem_SetEventStatus((Dem_EventIdType)Eep_Ipw_pxEepConfig->Eep_E_BOQuickWritesCfg.id, DEM_EVENT_STATUS_FAILED);
  739. }
  740. break;
  741. case FTFC_EEP_IP_BO_DURING_NORMAL_WRITES:
  742. if (TRUE == Eep_Ipw_pxEepConfig->Eep_E_BONormalWritesCfg.state)
  743. {
  744. (void) Dem_SetEventStatus((Dem_EventIdType)Eep_Ipw_pxEepConfig->Eep_E_BONormalWritesCfg.id, DEM_EVENT_STATUS_FAILED);
  745. }
  746. break;
  747. case FTFC_EEP_IP_NO_BO_DETECTED:
  748. /* Nothing to report */
  749. break;
  750. default:
  751. /* corrupted value */
  752. break;
  753. }
  754. }
  755. #endif /* (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF) */
  756. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  757. * @brief Report failures coming from IPL to DET / DEM.
  758. *
  759. * @param[in] FtfcStatus
  760. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  761. static void Eep_Ipw_ReportFailure (Ftfc_Eep_Ip_StatusType FtfcStatus)
  762. {
  763. switch (FtfcStatus)
  764. {
  765. case FTFC_EEP_IP_STATUS_TIMEOUT:
  766. (void) Det_ReportRuntimeError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_WRITE_ID, EEP_E_TIMEOUT);
  767. break;
  768. #if (FTFC_EEP_IP_HIGH_TEMP_CHIP == STD_ON)
  769. case FTFC_EEP_IP_STATUS_FAILED_MGSTAT:
  770. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  771. if (TRUE == Eep_Ipw_pxEepConfig->Eep_E_MGSTAT_BlockCfg.state)
  772. {
  773. (void) Dem_SetEventStatus((Dem_EventIdType)Eep_Ipw_pxEepConfig->Eep_E_MGSTAT_BlockCfg.id, DEM_EVENT_STATUS_FAILED);
  774. }
  775. #endif
  776. break;
  777. #endif
  778. default:
  779. /* nothing to report */
  780. break;
  781. }
  782. }
  783. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  784. * @brief Compute the page size, considering the addresses alignment and the remaining bytes.
  785. *
  786. * @param[in] FlexramAddress the FlexRAM address
  787. * @param[in] RamAddress the RAM address
  788. * @param[in] Length how many bytes are left to process
  789. *
  790. * @return the page size
  791. * @retval FTFC_EEP_IP_PAGE_BYTE for unaligned operations
  792. * @retval FTFC_EEP_IP_PAGE_WORD 16-bit aligned operations
  793. * @retval FTFC_EEP_IP_PAGE_LONGWORD 32-bit aligned operations
  794. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  795. static Ftfc_Eep_Ip_PageSizeType Eep_Ipw_AlignedPageSize (Ftfc_Eep_Ip_AddressType FlexramAddress,
  796. Ftfc_Eep_Ip_AddressType RamAddress,
  797. Ftfc_Eep_Ip_LengthType Length
  798. )
  799. {
  800. Ftfc_Eep_Ip_PageSizeType PageSize = FTFC_EEP_IP_PAGE_BYTE;
  801. #if (FTFC_EEP_IP_ALIGNED_RAM_ACCESS == STD_OFF)
  802. (void) RamAddress; /* avoid compiler warning */
  803. #endif
  804. if ((0U == (FlexramAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD))
  805. #if (FTFC_EEP_IP_ALIGNED_RAM_ACCESS == STD_ON)
  806. && (0U == (RamAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_LONGWORD))
  807. #endif
  808. )
  809. {
  810. if (Length >= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_LONGWORD)
  811. {
  812. /* 4 bytes aligned and length >= 4 bytes: 4 bytes operation */
  813. PageSize = FTFC_EEP_IP_PAGE_LONGWORD;
  814. }
  815. else if (Length >= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_WORD)
  816. {
  817. /* 4 bytes aligned and 4bytes > length >= 2 bytes : 2 bytes operation */
  818. PageSize = FTFC_EEP_IP_PAGE_WORD;
  819. }
  820. else
  821. {
  822. /* 4 bytes aligned and length < 2 bytes : 1 byte operation */
  823. PageSize = FTFC_EEP_IP_PAGE_BYTE;
  824. }
  825. }
  826. else if ((0U == (FlexramAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_WORD))
  827. #if (FTFC_EEP_IP_ALIGNED_RAM_ACCESS == STD_ON)
  828. && (0U == (RamAddress % (Ftfc_Eep_Ip_AddressType)FTFC_EEP_IP_PAGE_WORD))
  829. #endif
  830. )
  831. {
  832. if (Length >= (Ftfc_Eep_Ip_LengthType)FTFC_EEP_IP_PAGE_WORD)
  833. {
  834. /* 2 bytes aligned and length >= 2 bytes : 2 bytes operation */
  835. PageSize = FTFC_EEP_IP_PAGE_WORD;
  836. }
  837. else
  838. {
  839. /* 2 bytes aligned and length < 2 bytes : 1 byte operation */
  840. PageSize = FTFC_EEP_IP_PAGE_BYTE;
  841. }
  842. }
  843. else
  844. {
  845. /* unaligned operation */
  846. PageSize = FTFC_EEP_IP_PAGE_BYTE;
  847. }
  848. return PageSize;
  849. }
  850. #define EEP_STOP_SEC_CODE
  851. #include "Eep_MemMap.h"
  852. #ifdef __cplusplus
  853. }
  854. #endif
  855. /** @}*/