Eep.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015
  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
  26. *
  27. * @addtogroup EEP_DRIVER Eeprom Driver
  28. * @{
  29. */
  30. /* implements Eep.c_Artifact */
  31. #ifdef __cplusplus
  32. extern "C"{
  33. #endif
  34. /* Compiler warning eep_c_REF_CW_01: explicit cast discards volatile qualifier.
  35. The cast is explicit, intended and the casted value is treated properly.
  36. Sizes of the pointers and integral types for all the supported platforms/compilers are well known
  37. and the volatile keyword is not needed when using the pointer value as a eeprom address counter,
  38. as the pointer value is not updated in the DSI interrupt context or by other hardware means.
  39. */
  40. /*==================================================================================================
  41. * INCLUDE FILES
  42. * 1) system and project includes
  43. * 2) needed interfaces from external units
  44. * 3) internal and external interfaces from this unit
  45. ==================================================================================================*/
  46. #include "Eep.h"
  47. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  48. #include "Dem.h"
  49. #endif
  50. #include "Det.h"
  51. #include "Eep_IPW.h"
  52. #if (EEP_MCORE_ENABLED == STD_ON)
  53. #include "CDD_Rm.h"
  54. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  55. /*==================================================================================================
  56. * SOURCE FILE VERSION INFORMATION
  57. ==================================================================================================*/
  58. #define EEP_VENDOR_ID_C 43
  59. #define EEP_AR_RELEASE_MAJOR_VERSION_C 4
  60. #define EEP_AR_RELEASE_MINOR_VERSION_C 4
  61. #define EEP_AR_RELEASE_REVISION_VERSION_C 0
  62. #define EEP_SW_MAJOR_VERSION_C 1
  63. #define EEP_SW_MINOR_VERSION_C 0
  64. #define EEP_SW_PATCH_VERSION_C 0
  65. /*==================================================================================================
  66. * FILE VERSION CHECKS
  67. ==================================================================================================*/
  68. /* Check if current file and Eep header file are of the same vendor */
  69. #if (EEP_VENDOR_ID_C != EEP_VENDOR_ID)
  70. #error "Eep.c and Eep.h have different vendor ids"
  71. #endif
  72. /* Check if current file and Eep header file are of the same Autosar version */
  73. #if ((EEP_AR_RELEASE_MAJOR_VERSION_C != EEP_AR_RELEASE_MAJOR_VERSION) || \
  74. (EEP_AR_RELEASE_MINOR_VERSION_C != EEP_AR_RELEASE_MINOR_VERSION) || \
  75. (EEP_AR_RELEASE_REVISION_VERSION_C != EEP_AR_RELEASE_REVISION_VERSION) \
  76. )
  77. #error "AutoSar Version Numbers of Eep.c and Eep.h are different"
  78. #endif
  79. /* Check if current file and Eep header file are of the same Software version */
  80. #if ((EEP_SW_MAJOR_VERSION_C != EEP_SW_MAJOR_VERSION) || \
  81. (EEP_SW_MINOR_VERSION_C != EEP_SW_MINOR_VERSION) || \
  82. (EEP_SW_PATCH_VERSION_C != EEP_SW_PATCH_VERSION) \
  83. )
  84. #error "Software Version Numbers of Eep.c and Eep.h are different"
  85. #endif
  86. /* Check if current file and Eep_IPW header file are of the same vendor */
  87. #if (EEP_VENDOR_ID_C != EEP_IPW_VENDOR_ID_H)
  88. #error "Eep.c and Eep_IPW.h have different vendor ids"
  89. #endif
  90. /* Check if current file and Eep_IPW header file are of the same Autosar version */
  91. #if ((EEP_AR_RELEASE_MAJOR_VERSION_C != EEP_IPW_AR_RELEASE_MAJOR_VERSION_H) || \
  92. (EEP_AR_RELEASE_MINOR_VERSION_C != EEP_IPW_AR_RELEASE_MINOR_VERSION_H) || \
  93. (EEP_AR_RELEASE_REVISION_VERSION_C != EEP_IPW_AR_RELEASE_REVISION_VERSION_H) \
  94. )
  95. #error "AutoSar Version Numbers of Eep.c and Eep_IPW.h are different"
  96. #endif
  97. /* Check if current file and Eep_IPW header file are of the same Software version */
  98. #if ((EEP_SW_MAJOR_VERSION_C != EEP_IPW_SW_MAJOR_VERSION_H) || \
  99. (EEP_SW_MINOR_VERSION_C != EEP_IPW_SW_MINOR_VERSION_H) || \
  100. (EEP_SW_PATCH_VERSION_C != EEP_IPW_SW_PATCH_VERSION_H) \
  101. )
  102. #error "Software Version Numbers of Eep.c and Eep_IPW.h are different"
  103. #endif
  104. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  105. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  106. /* Check if current file and Dem header file are of the same Autosar version */
  107. #if ((EEP_AR_RELEASE_MAJOR_VERSION_C != DEM_AR_RELEASE_MAJOR_VERSION) || \
  108. (EEP_AR_RELEASE_MINOR_VERSION_C != DEM_AR_RELEASE_MINOR_VERSION) \
  109. )
  110. #error "AutoSar Version Numbers of Eep.c and Dem.h are different"
  111. #endif
  112. #endif
  113. #endif
  114. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  115. /* Check if current file and Det header file are of the same Autosar version */
  116. #if ((EEP_AR_RELEASE_MAJOR_VERSION_C != DET_AR_RELEASE_MAJOR_VERSION) || \
  117. (EEP_AR_RELEASE_MINOR_VERSION_C != DET_AR_RELEASE_MINOR_VERSION) \
  118. )
  119. #error "AutoSar Version Numbers of Eep.c and Det.h are different"
  120. #endif
  121. #endif
  122. #if (EEP_MCORE_ENABLED == STD_ON)
  123. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  124. /* Check if current file and CDD_Rm header file are of the same Autosar version */
  125. #if ((EEP_AR_RELEASE_MAJOR_VERSION_C != RM_AR_RELEASE_MAJOR_VERSION) || \
  126. (EEP_AR_RELEASE_MINOR_VERSION_C != RM_AR_RELEASE_MINOR_VERSION) \
  127. )
  128. #error "AutoSar Version Numbers of Eep.c and CDD_Rm.h are different"
  129. #endif
  130. #endif
  131. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  132. /*==================================================================================================
  133. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  134. ==================================================================================================*/
  135. /*==================================================================================================
  136. LOCAL MACROS
  137. ==================================================================================================*/
  138. /*==================================================================================================
  139. LOCAL CONSTANTS
  140. ==================================================================================================*/
  141. /*==================================================================================================
  142. LOCAL VARIABLES
  143. ==================================================================================================*/
  144. #define EEP_START_SEC_VAR_CLEARED_UNSPECIFIED
  145. #include "Eep_MemMap.h"
  146. /**
  147. * @brief Maximum number of bytes to read or compare in one cycle of Eep_MainFunction
  148. */
  149. static Eep_LengthType Eep_u32MaxRead;
  150. /**
  151. * @brief Maximum number of bytes to write in one cycle of Eep_MainFunction
  152. */
  153. static Eep_LengthType Eep_u32MaxWrite;
  154. /**
  155. * @brief Logical address of data block currently processed by Eep_MainFunction
  156. */
  157. static Eep_AddressType Eep_u32EepromAddrIt;
  158. /**
  159. * @brief Remainin length to be transfered until the end of the job
  160. */
  161. static Eep_LengthType Eep_u32RemainingLength;
  162. /**
  163. * @brief Result of last eeprom module job
  164. *
  165. */
  166. static MemIf_JobResultType Eep_eJobResult;
  167. /**
  168. * @brief Type of currently executed job (erase, write, read, or compare)
  169. */
  170. static Eep_JobType Eep_eJob;
  171. /**
  172. * @brief Pointer to current eeprom module configuration set
  173. */
  174. static const Eep_ConfigType * Eep_pConfigPtr;
  175. /**
  176. * @brief Pointer to current eeprom module configuration set
  177. */
  178. #if (EEP_MCORE_ENABLED == STD_ON)
  179. Eep_MCoreHwJobStatusType Eep_MCoreHwJobStatus;
  180. #endif
  181. #define EEP_STOP_SEC_VAR_CLEARED_UNSPECIFIED
  182. #include "Eep_MemMap.h"
  183. #define EEP_START_SEC_VAR_CLEARED_8
  184. #include "Eep_MemMap.h"
  185. /**
  186. * @brief Pointer to current position in source data buffer
  187. * @details Used by both write and compare jobs
  188. */
  189. static const uint8 * Eep_pu8JobSrcAddrPtr;
  190. /**
  191. * @brief Pointer to current position in target data buffer
  192. * @details Used only by read job
  193. */
  194. static uint8 * Eep_pu8JobDataDestPtr;
  195. #define EEP_STOP_SEC_VAR_CLEARED_8
  196. #include "Eep_MemMap.h"
  197. #define EEP_START_SEC_VAR_CLEARED_16
  198. #include "Eep_MemMap.h"
  199. /* If FTFC IP is present on the platform */
  200. #if (EEP_QUICK_WRITES_API == STD_ON)
  201. /**
  202. * @brief Requested urgency length to set up number of bytes used for quick writes
  203. * @details Used only by the Eep_QuickWrite, Eep_MainFunction
  204. */
  205. static uint16 Eep_u16QuickWritesLength;
  206. #endif /* EEP_QUICK_WRITES_API */
  207. #define EEP_STOP_SEC_VAR_CLEARED_16
  208. #include "Eep_MemMap.h"
  209. #define EEP_START_SEC_VAR_CLEARED_32
  210. #include "Eep_MemMap.h"
  211. /**
  212. * @brief Pointer to current eeprom module configuration set
  213. *
  214. */
  215. static uint32 Eep_u32AccCRCremainder;
  216. #if (EEP_MCORE_ENABLED == STD_ON)
  217. static uint32 Eep_u32DoMainID;
  218. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  219. #define EEP_STOP_SEC_VAR_CLEARED_32
  220. #include "Eep_MemMap.h"
  221. /*==================================================================================================
  222. GLOBAL CONSTANTS
  223. ==================================================================================================*/
  224. /*==================================================================================================
  225. * GLOBAL VARIABLES
  226. ==================================================================================================*/
  227. /*==================================================================================================
  228. LOCAL FUNCTION PROTOTYPES
  229. ==================================================================================================*/
  230. #define EEP_START_SEC_CODE
  231. #include "Eep_MemMap.h"
  232. static void Eep_InitAllVarriable (void);
  233. static void Eep_AccumulateCRC (uint32 u32InputData);
  234. static void Eep_ResetCRC (void);
  235. static uint32 Eep_FinalizeCRC (void);
  236. static void Eep_UpdateCRCreminder (Eep_CrcDataSizeType eDataSize);
  237. static Eep_CrcType Eep_CalcCfgCRC (void);
  238. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  239. static void Eep_ReportDemErrors(void);
  240. static void Eep_ReportDemPasses(void);
  241. #endif
  242. static MemIf_JobResultType Eep_ProcessWriteJob (void);
  243. #if (EEP_QUICK_WRITES_API == STD_ON)
  244. static MemIf_JobResultType Eep_ProcessQuickWriteJob (void);
  245. #endif
  246. static MemIf_JobResultType Eep_ProcessReadJob (void);
  247. #if (EEP_COMPARE_API == STD_ON)
  248. static MemIf_JobResultType Eep_ProcessCompareJob (void);
  249. #endif
  250. static MemIf_JobResultType Eep_ProcessRequestedJobs (Eep_JobType eJob);
  251. static void Eep_CallNotification (MemIf_JobResultType eJobResult);
  252. static void Eep_EndJobs (void);
  253. #if (EEP_MCORE_ENABLED == STD_ON)
  254. static Eep_MCoreReqReturnType Eep_ReqMCore (void);
  255. static Std_ReturnType Eep_MCoreInitSema4sLock (void);
  256. static Std_ReturnType Eep_MCoreJobSema4Release (void);
  257. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  258. #define EEP_STOP_SEC_CODE
  259. #include "Eep_MemMap.h"
  260. /*==================================================================================================
  261. LOCAL FUNCTIONS
  262. ==================================================================================================*/
  263. #define EEP_START_SEC_CODE
  264. #include "Eep_MemMap.h"
  265. /**
  266. * @brief Eep_InitAllVarriable
  267. * @details Initialize global variables to their default values
  268. *
  269. * @param[in] void
  270. *
  271. * @return void
  272. * @pre N/A
  273. */
  274. static void Eep_InitAllVarriable (void)
  275. {
  276. /* Initialize all global variable */
  277. Eep_u32MaxRead = 0UL;
  278. Eep_u32MaxWrite = 0UL;
  279. Eep_u32EepromAddrIt = 0UL;
  280. Eep_u32RemainingLength = 0UL;
  281. Eep_eJobResult = MEMIF_JOB_OK;
  282. Eep_eJob = EEP_JOB_ERASE;
  283. Eep_pConfigPtr = NULL_PTR;
  284. Eep_pu8JobSrcAddrPtr = NULL_PTR;
  285. Eep_pu8JobDataDestPtr = NULL_PTR;
  286. /* If FTFC IP is present on the platform */
  287. #if (EEP_QUICK_WRITES_API == STD_ON)
  288. Eep_u16QuickWritesLength = 0U;
  289. #endif /* EEP_QUICK_WRITES_API */
  290. /* Initialize CRC remainder */
  291. Eep_u32AccCRCremainder = 0U;
  292. #if (EEP_MCORE_ENABLED == STD_ON)
  293. Eep_u32DoMainID = 0;
  294. Eep_MCoreHwJobStatus = EEP_MCORE_HW_JOB_IDLE;
  295. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  296. }
  297. /**
  298. * @brief Function to handle cumulative CRC calculation over input data.
  299. *
  300. * @details Handles cumulative CRC calculation over input 32-bit data, .
  301. *
  302. * @param[in] inputData ... data to be CRC-ed
  303. *
  304. * @return void
  305. * @retval None.
  306. *
  307. * @pre Eep_ResetCRC() was executed before the first call of
  308. * Eep_AccumulateCRC().
  309. *
  310. *
  311. */
  312. static void Eep_AccumulateCRC (uint32 u32InputData)
  313. {
  314. if (0xFFFFU < u32InputData)
  315. {
  316. /* preparation for accumulation of higher 16 bits of the u32InputData */
  317. Eep_u32AccCRCremainder = (Eep_u32AccCRCremainder << 16U) | (u32InputData >> 16U);
  318. /* make 16-bit accumulated result (in lower 16-bits of Eep_u32AccCRCremainder) */
  319. Eep_UpdateCRCreminder(EEP_CRC_16_BITS);
  320. }
  321. if (0xFFU < u32InputData)
  322. {
  323. /* preparation for accumulation of lower 16 bits of the u32InputData */
  324. Eep_u32AccCRCremainder = (Eep_u32AccCRCremainder << 16U) | (u32InputData & 0x0000FFFFU);
  325. /* make 16-bit accumulated result (in lower 16-bits of Eep_u32AccCRCremainder) */
  326. Eep_UpdateCRCreminder(EEP_CRC_16_BITS);
  327. }
  328. else
  329. {
  330. /* optimization: only 8 LSB bits are processed */
  331. /* preparation for accumulation of lower 8 bits of the u32InputData */
  332. Eep_u32AccCRCremainder = (Eep_u32AccCRCremainder << 8U) | u32InputData;
  333. /* make 16-bit accumulated result (in lower 16-bits of Eep_u32AccCRCremainder) */
  334. Eep_UpdateCRCreminder(EEP_CRC_8_BITS);
  335. }
  336. return;
  337. }
  338. /**
  339. * @brief Function to reset CRC calculation.
  340. *
  341. * @details Resets accumulated Eep_u32AccCRCremainder.
  342. *
  343. * @param[in] void
  344. *
  345. * @return void
  346. * @retval None.
  347. *
  348. * @pre None.
  349. *
  350. *
  351. */
  352. static void Eep_ResetCRC (void)
  353. {
  354. Eep_u32AccCRCremainder = 0U;
  355. }
  356. /**
  357. * @brief Function to finalize CRC calculation.
  358. *
  359. * @details Finalizes accumulated CRC computation and resturns the final
  360. * CRC checksum.
  361. *
  362. * @param[in] void
  363. *
  364. * @return uint32
  365. * @retval The final CRC checksum in the lower 16 bits.
  366. *
  367. * @pre Eep_AccumulateCRC() was executed at least once before
  368. * calling Eep_FinalizeCRC().
  369. *
  370. */
  371. static uint32 Eep_FinalizeCRC (void)
  372. {
  373. /* add the final 0x0000 to the remainder */
  374. Eep_u32AccCRCremainder = (Eep_u32AccCRCremainder << 16U);
  375. /* make the final 16-bit CRC */
  376. Eep_UpdateCRCreminder(EEP_CRC_16_BITS);
  377. return Eep_u32AccCRCremainder;
  378. }
  379. /**
  380. * @brief Function to perfom CRC calculation over input 32-bit data.
  381. *
  382. * @details Process 32-bit data to 16-bit reminder.
  383. *
  384. * @param[in] accDataPtr ... ptr to data to be processed
  385. *
  386. * @return void
  387. * @retval None.
  388. *
  389. * @pre Can be called only from Eep_AccumulateCRC().
  390. *
  391. */
  392. static void Eep_UpdateCRCreminder (Eep_CrcDataSizeType eDataSize)
  393. {
  394. uint32 u32CrcPolynomSft;
  395. uint32 u32LeadingOne;
  396. uint32 u32AccDataLoc;
  397. uint32 u32LeadingOneInitial;
  398. switch (eDataSize)
  399. {
  400. case EEP_CRC_8_BITS:
  401. u32CrcPolynomSft = 0x11021U << 7U; /* shifted CRC-16-CCITT (x.25 protocol)*/
  402. u32LeadingOneInitial = 0x10000U << 7U;
  403. break;
  404. case EEP_CRC_16_BITS:
  405. default:
  406. u32CrcPolynomSft = 0x11021U << 15U; /* shifted CRC-16-CCITT (x.25 protocol)*/
  407. u32LeadingOneInitial = 0x10000U << 15U;
  408. break;
  409. }
  410. /* copy static variable to auto (computation over static may be slow) */
  411. u32AccDataLoc = Eep_u32AccCRCremainder;
  412. /* CRC computation */
  413. for (u32LeadingOne = u32LeadingOneInitial; u32LeadingOne >= 0x00010000U; u32LeadingOne >>= 1U)
  414. {
  415. if ((u32AccDataLoc & u32LeadingOne) != 0U)
  416. {
  417. u32AccDataLoc ^= u32CrcPolynomSft;
  418. }
  419. u32CrcPolynomSft >>= 1U;
  420. }
  421. /* copy back to static variable */
  422. Eep_u32AccCRCremainder = u32AccDataLoc;
  423. return;
  424. }
  425. /**
  426. * @brief Calculates CRC over Eep configuration.
  427. *
  428. * @details Calculates CRC over selected items of Eep configuration set
  429. * pointed to by ConfigPtr.
  430. *
  431. * @param[in] ConfigPtr Pointer to eeprom driver configuration set.
  432. *
  433. * @return uint32
  434. * @retval 0 .. 0xFFFF (16-bit CRC using CRC-16-CCITT polynomial)
  435. *
  436. * @pre Eep_pConfigPtr must not be properly initialized.
  437. *
  438. */
  439. static Eep_CrcType Eep_CalcCfgCRC (void)
  440. {
  441. /* Reset the accumulated CRC value */
  442. Eep_ResetCRC();
  443. /* Accumulate the rest of the params (common for all sectors within a config set) */
  444. /* CRC - Accumulate eDefaultMode */
  445. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->eDefaultMode);
  446. /* CRC - Accumulate u32MaxReadFastMode */
  447. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->u32MaxReadFastMode);
  448. /* CRC - Accumulate u32MaxReadNormalMode */
  449. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->u32MaxReadNormalMode);
  450. /* CRC - Accumulate u32MaxWriteFastMode */
  451. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->u32MaxWriteFastMode);
  452. /* CRC - Accumulate u32MaxWriteNormalMode */
  453. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->u32MaxWriteNormalMode);
  454. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  455. /* CRC - Accumulate EEP_E_COMPARE_FAILED */
  456. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_CompareFailedCfg.state);
  457. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_CompareFailedCfg.id);
  458. /* CRC - Accumulate EEP_E_ERASE_FAILED */
  459. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_EraseFailedCfg.state);
  460. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_EraseFailedCfg.id);
  461. /* CRC - Accumulate EEP_E_READ_FAILED */
  462. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_ReadFailedCfg.state);
  463. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_ReadFailedCfg.id);
  464. /* CRC - Accumulate EEP_E_WRITE_FAILED */
  465. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_WriteFailedCfg.state);
  466. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_WriteFailedCfg.id);
  467. /* CRC - Accumulate EEP_E_BO_MAINTENANCE */
  468. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_BOMaintenanceCfg.state);
  469. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_BOMaintenanceCfg.id);
  470. /* CRC - Accumulate EEP_E_BO_QUICK_WRITES */
  471. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_BOQuickWritesCfg.state);
  472. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_BOQuickWritesCfg.id);
  473. /* CRC - Accumulate EEP_E_BO_NORMAL_WRITES */
  474. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_BONormalWritesCfg.state);
  475. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_BONormalWritesCfg.id);
  476. #if (EEP_HIGH_TEMP_CHIP == STD_ON)
  477. /* CRC - Accumulate EEP_E_MGSTAT_BLOCK */
  478. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_MGSTAT_BlockCfg.state);
  479. Eep_AccumulateCRC((uint32)Eep_pConfigPtr->Eep_E_MGSTAT_BlockCfg.id);
  480. #endif
  481. #endif
  482. return ((Eep_CrcType)Eep_FinalizeCRC());
  483. }
  484. /**
  485. * @brief Function to call notifications
  486. *
  487. * @details The Eep module shall call the callback function defined in the configuration parameter
  488. * - EepJobEndNotification when a job has been completed with a positive result: Read or Write or Erase or
  489. * Compare finished & data blocks are equal.
  490. * - EepJobErrorNotification when a job has been canceled or aborted with negative result:read or write or earse or
  491. * Compare aborted or data blocks are not equal
  492. *
  493. * @param[in] eJobResult ... data
  494. *
  495. * @return void
  496. * @retval None.
  497. *
  498. */
  499. static void Eep_CallNotification (MemIf_JobResultType eJobResult)
  500. {
  501. if (MEMIF_JOB_OK == eJobResult)
  502. {
  503. if (NULL_PTR != Eep_pConfigPtr->jobEndNotificationPtr)
  504. {
  505. /* Call EepJobEndNotification function if configured */
  506. Eep_pConfigPtr->jobEndNotificationPtr();
  507. }
  508. else
  509. {
  510. /* Callback notification configured as null pointer */
  511. }
  512. }
  513. else if ((MEMIF_JOB_FAILED == eJobResult) || (MEMIF_BLOCK_INCONSISTENT == eJobResult) ||
  514. (MEMIF_JOB_CANCELED == eJobResult) || (MEMIF_JOB_PENDING == eJobResult))
  515. {
  516. if (NULL_PTR != Eep_pConfigPtr->jobErrorNotificationPtr)
  517. {
  518. /* Call EepJobErrorNotification function if configured */
  519. Eep_pConfigPtr->jobErrorNotificationPtr();
  520. }
  521. else
  522. {
  523. /* Callback notification configured as null pointer */
  524. }
  525. }
  526. else
  527. {
  528. ;/* Not done yet. There is more data to transfer in following Eep_MainFunction call .*/
  529. }
  530. }
  531. #if (EEP_COMPARE_API == STD_ON)
  532. /**
  533. * @brief Pocess the compare job
  534. *
  535. * @details Compares data from Eep_pu8JobSrcAddrPtr to data from Eep_u32EepromAddrIt
  536. * of lenth equal to Eep_u32MaxRead or Eep_u32RemainingLength.
  537. *
  538. * @param[in]
  539. *
  540. * @pre The module must be initialized
  541. *
  542. *
  543. *
  544. */
  545. static MemIf_JobResultType Eep_ProcessCompareJob (void)
  546. {
  547. MemIf_JobResultType eRetVal = MEMIF_JOB_PENDING;
  548. Eep_ReturnType eTransferRetVal = EEP_E_OK;
  549. uint32 u32TempSource = 0UL;
  550. Eep_LengthType u32TransfLength = 0UL;
  551. /* the function will compare Eep_u32MaxRead or the remaining length */
  552. /* compute length of transfer */
  553. if (Eep_u32RemainingLength > Eep_u32MaxRead)
  554. {
  555. /* Eep_u32MaxWrite must be transferred */
  556. u32TransfLength = Eep_u32MaxRead;
  557. }
  558. else
  559. {
  560. /* Eep_u32RemainingLength must be transferred */
  561. u32TransfLength = Eep_u32RemainingLength;
  562. }
  563. /* if there is something to transfer */
  564. if (u32TransfLength > 0UL)
  565. {
  566. eTransferRetVal = Eep_Ipw_CompareSync(Eep_u32EepromAddrIt, Eep_pu8JobSrcAddrPtr, u32TransfLength);
  567. }
  568. /* update variables to be used for the next iteration */
  569. u32TempSource = (uint32)Eep_pu8JobSrcAddrPtr;
  570. u32TempSource = u32TempSource + u32TransfLength;
  571. Eep_pu8JobSrcAddrPtr = (uint8 *)u32TempSource;
  572. Eep_u32EepromAddrIt = Eep_u32EepromAddrIt + u32TransfLength;
  573. Eep_u32RemainingLength = Eep_u32RemainingLength - u32TransfLength;
  574. /* check status */
  575. if (EEP_E_FAILED == eTransferRetVal)
  576. {
  577. /* job has failed */
  578. eRetVal = MEMIF_JOB_FAILED;
  579. }
  580. if (EEP_E_BLOCK_INCONSISTENT == eTransferRetVal)
  581. {
  582. /* comparison failed */
  583. eRetVal = MEMIF_BLOCK_INCONSISTENT;
  584. }
  585. else if ((0UL == Eep_u32RemainingLength) && (EEP_E_OK == eTransferRetVal))
  586. {
  587. /* the job is finished successfully */
  588. eRetVal = MEMIF_JOB_OK;
  589. }
  590. else
  591. {
  592. /* do nothing */
  593. }
  594. return eRetVal;
  595. }
  596. #endif
  597. /**
  598. * @brief Pocess a read job
  599. *
  600. * @details Reads data from Eep_u32EepromAddrIt to Eep_pu8JobDataDestPtr
  601. * of lenth equal to Eep_u32MaxRead or Eep_u32RemainingLength.
  602. *
  603. * @param[in]
  604. *
  605. * @pre The module must be initialized
  606. *
  607. *
  608. *
  609. */
  610. static MemIf_JobResultType Eep_ProcessReadJob (void)
  611. {
  612. MemIf_JobResultType eRetVal = MEMIF_JOB_PENDING;
  613. Eep_ReturnType eTransferRetVal = EEP_E_OK;
  614. uint32 u32TempSource = 0UL;
  615. Eep_LengthType u32TransfLength = 0UL;
  616. /* transfer information to low level driver */
  617. /* the function will read Eep_u32MaxRead or the remaining length */
  618. /* compute length of transfer */
  619. if (Eep_u32RemainingLength > Eep_u32MaxRead)
  620. {
  621. /* Eep_u32MaxWrite must be transferred */
  622. u32TransfLength = Eep_u32MaxRead;
  623. }
  624. else
  625. {
  626. /* Eep_u32RemainingLength must be transferred */
  627. u32TransfLength = Eep_u32RemainingLength;
  628. }
  629. /* if there is something to transfer */
  630. if (u32TransfLength > 0UL)
  631. {
  632. eTransferRetVal = Eep_Ipw_Read(Eep_u32EepromAddrIt, Eep_pu8JobDataDestPtr, u32TransfLength);
  633. }
  634. /* update variables to be used for the next iteration */
  635. u32TempSource = (uint32)Eep_pu8JobDataDestPtr;
  636. u32TempSource = u32TempSource + u32TransfLength;
  637. Eep_pu8JobDataDestPtr = (uint8 *)u32TempSource;
  638. Eep_u32EepromAddrIt = Eep_u32EepromAddrIt + u32TransfLength;
  639. Eep_u32RemainingLength = Eep_u32RemainingLength - u32TransfLength;
  640. /* check status */
  641. if (EEP_E_FAILED == eTransferRetVal)
  642. {
  643. /* job has failed */
  644. eRetVal = MEMIF_JOB_FAILED;
  645. }
  646. else if ((0UL == Eep_u32RemainingLength) && (EEP_E_OK == eTransferRetVal))
  647. {
  648. /* the job is finished */
  649. eRetVal = MEMIF_JOB_OK;
  650. }
  651. else
  652. {
  653. /* do nothing */
  654. }
  655. return eRetVal;
  656. }
  657. /**
  658. * @brief Pocess a write job
  659. *
  660. * @details Performs the write operation for a main function call.
  661. * Calls low level drivers for async or snc behavior.
  662. *
  663. * @param[in]
  664. *
  665. * @pre The module must be initialized
  666. *
  667. *
  668. *
  669. */
  670. static MemIf_JobResultType Eep_ProcessWriteJob (void)
  671. {
  672. MemIf_JobResultType eRetVal = MEMIF_JOB_PENDING;
  673. Eep_ReturnType eTransferRetVal = EEP_E_OK;
  674. #if (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_OFF)
  675. uint32 u32TempSource = 0UL;
  676. Eep_LengthType u32TransfLength = 0UL;
  677. /* transfer information to low level driver */
  678. /* the function will write Eep_u32MaxWrite or the remaining length */
  679. /* compute length of transfer */
  680. if (Eep_u32RemainingLength > Eep_u32MaxWrite)
  681. {
  682. /* Eep_u32MaxWrite must be transferred */
  683. u32TransfLength = Eep_u32MaxWrite;
  684. }
  685. else
  686. {
  687. /* Eep_u32RemainingLength must be transferred */
  688. u32TransfLength = Eep_u32RemainingLength;
  689. }
  690. /* if there is something to transfer */
  691. if (u32TransfLength > 0UL)
  692. {
  693. eTransferRetVal = Eep_Ipw_Write(Eep_u32EepromAddrIt, Eep_pu8JobSrcAddrPtr, u32TransfLength);
  694. }
  695. /* update variables to be used for the next iteration */
  696. u32TempSource = (uint32)Eep_pu8JobSrcAddrPtr;
  697. u32TempSource = u32TempSource + u32TransfLength;
  698. Eep_pu8JobSrcAddrPtr = (uint8 *)u32TempSource;
  699. Eep_u32EepromAddrIt = Eep_u32EepromAddrIt + u32TransfLength;
  700. Eep_u32RemainingLength = Eep_u32RemainingLength - u32TransfLength;
  701. #else
  702. /* in asynchronous mode in one main function call EEP
  703. * will trigger a hardware write operation for a 1,2, or 4 bytes page and return,
  704. * it will not wait for operation to finish */
  705. eTransferRetVal = Eep_Ipw_Write(Eep_u32EepromAddrIt, Eep_pu8JobSrcAddrPtr, Eep_u32RemainingLength);
  706. /* Clear unused variable */
  707. (void)Eep_u32MaxWrite;
  708. #endif /*#if (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_OFF) */
  709. if (EEP_E_FAILED == eTransferRetVal)
  710. {
  711. /* job has failed */
  712. eRetVal = MEMIF_JOB_FAILED;
  713. }
  714. #if (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_OFF)
  715. else if ((0UL == Eep_u32RemainingLength) && (EEP_E_OK == eTransferRetVal))
  716. #else
  717. else if (EEP_E_OK == eTransferRetVal)
  718. #endif /*#if (EEP_ASYNC_WRITE_OPERATIONS_ENABLED == STD_OFF) */
  719. {
  720. /* the job is finished */
  721. eRetVal = MEMIF_JOB_OK;
  722. /* job is done */
  723. Eep_u32RemainingLength = 0UL;
  724. }
  725. else
  726. {
  727. /* do nothing */
  728. }
  729. return eRetVal;
  730. }
  731. /* If FTFC IP is present on the platform */
  732. #if (EEP_QUICK_WRITES_API == STD_ON)
  733. /**
  734. * @brief Pocess a quick write job
  735. *
  736. * @details Performs the quick write operation for a main function call.
  737. * Calls low level drivers for async or snc behavior.
  738. *
  739. * @pre The module must be initialized
  740. */
  741. static MemIf_JobResultType Eep_ProcessQuickWriteJob (void)
  742. {
  743. MemIf_JobResultType eRetVal = MEMIF_JOB_FAILED;
  744. Eep_ReturnType eTransferRetVal = EEP_E_OK;
  745. uint16 Length = Eep_u16QuickWritesLength;
  746. /* if there is something to transfer */
  747. if (Eep_u32RemainingLength > 0UL)
  748. {
  749. eTransferRetVal = Eep_Ipw_QuickWrite(Eep_u32EepromAddrIt, Eep_pu8JobSrcAddrPtr, Length);
  750. Eep_pu8JobSrcAddrPtr = (uint8*)((uint32)Eep_pu8JobSrcAddrPtr + Length);
  751. Eep_u32EepromAddrIt += Length;
  752. Eep_u32RemainingLength -= Length;
  753. }
  754. if (EEP_E_OK == eTransferRetVal)
  755. {
  756. if (0UL == Eep_u32RemainingLength)
  757. {
  758. eRetVal = MEMIF_JOB_OK;
  759. }
  760. else
  761. {
  762. eRetVal = MEMIF_JOB_PENDING;
  763. }
  764. }
  765. return eRetVal;
  766. }
  767. #endif /* EEP_QUICK_WRITES_API */
  768. /**
  769. * @brief Pocess a erase job
  770. *
  771. * @details Performs the erase operation for a main function call.
  772. * Calls low level drivers for async or snc behavior.
  773. *
  774. * @param[in]
  775. *
  776. * @pre The module must be initialized
  777. */
  778. static MemIf_JobResultType Eep_ProcessEraseJob (void)
  779. {
  780. MemIf_JobResultType eRetVal = MEMIF_JOB_PENDING;
  781. Eep_ReturnType eTransferRetVal = EEP_E_OK;
  782. #if (EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_OFF)
  783. Eep_LengthType u32TransfLength = 0UL;
  784. /* transfer information to low level driver */
  785. /* the function will write Eep_u32MaxWrite or the remaining length */
  786. /* compute length of transfer */
  787. if (Eep_u32RemainingLength > Eep_u32MaxWrite)
  788. {
  789. /* Eep_u32MaxWrite must be transferred */
  790. u32TransfLength = Eep_u32MaxWrite;
  791. }
  792. else
  793. {
  794. /* Eep_u32RemainingLength must be transferred */
  795. u32TransfLength = Eep_u32RemainingLength;
  796. }
  797. /* if there is something to transfer */
  798. if (u32TransfLength > 0UL)
  799. {
  800. eTransferRetVal = Eep_Ipw_Erase(Eep_u32EepromAddrIt, u32TransfLength);
  801. }
  802. /* update variables to be used for the next iteration */
  803. Eep_u32EepromAddrIt = Eep_u32EepromAddrIt + u32TransfLength;
  804. Eep_u32RemainingLength = Eep_u32RemainingLength - u32TransfLength;
  805. #else
  806. eTransferRetVal = Eep_Ipw_Erase(Eep_u32EepromAddrIt, Eep_u32RemainingLength);
  807. /* Clear unused variable */
  808. (void)Eep_u32MaxWrite;
  809. #endif /*#if (EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_OFF) */
  810. if (EEP_E_FAILED == eTransferRetVal)
  811. {
  812. /* job has failed */
  813. eRetVal = MEMIF_JOB_FAILED;
  814. }
  815. #if (EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_OFF)
  816. else if ((0UL == Eep_u32RemainingLength) && (EEP_E_OK == eTransferRetVal))
  817. #else
  818. else if (EEP_E_OK == eTransferRetVal)
  819. #endif /*#if (EEP_ASYNC_ERASE_OPERATIONS_ENABLED == STD_OFF) */
  820. {
  821. /* the job is finished */
  822. eRetVal = MEMIF_JOB_OK;
  823. /* job is done */
  824. Eep_u32RemainingLength = 0UL;
  825. }
  826. else
  827. {
  828. /* do nothing */
  829. }
  830. return eRetVal;
  831. }
  832. /*==================================================================================================
  833. GLOBAL FUNCTIONS
  834. ==================================================================================================*/
  835. /**
  836. * @brief The function initializes Eep module.
  837. * @details The function sets the internal module variables according to given
  838. * configuration set.
  839. *
  840. * @param[in] pConfigPtr Pointer to eeprom driver configuration set.
  841. *
  842. * @api
  843. *
  844. * @pre @p pConfigPtr must not be @p NULL_PTR and the module status must not
  845. * be @p MEMIF_BUSY.
  846. *
  847. * @implements Eep_Init_Activity
  848. *
  849. */
  850. void Eep_Init (const Eep_ConfigType * pConfigPtr)
  851. {
  852. Eep_ReturnType eRetVal = EEP_E_OK;
  853. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  854. /* check DET error codes */
  855. #if defined(EEP_PRECOMPILE_SUPPORT)
  856. if (NULL_PTR != pConfigPtr)
  857. #else
  858. if (NULL_PTR == pConfigPtr)
  859. #endif
  860. {
  861. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_INIT_ID, EEP_E_INIT_FAILED);
  862. }
  863. else if (MEMIF_JOB_PENDING == Eep_eJobResult)
  864. {
  865. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_INIT_ID, EEP_E_BUSY);
  866. }
  867. else
  868. {
  869. #endif /* EEP_DEV_ERROR_DETECT */
  870. Eep_InitAllVarriable();
  871. /* set the configuration pointer according to the config variant */
  872. #if defined(EEP_PRECOMPILE_SUPPORT)
  873. Eep_pConfigPtr = &Eep_PBCfgVariantPredefined;
  874. #if (EEP_DEV_ERROR_DETECT == STD_OFF)
  875. (void)pConfigPtr;
  876. #endif
  877. #else
  878. Eep_pConfigPtr = pConfigPtr;
  879. #endif
  880. /* check configuration CRC */
  881. if (Eep_pConfigPtr->u16ConfigCrc != Eep_CalcCfgCRC())
  882. {
  883. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  884. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_INIT_ID, EEP_E_INIT_FAILED);
  885. Eep_pConfigPtr = NULL_PTR;
  886. #endif
  887. Eep_eJobResult = MEMIF_JOB_FAILED;
  888. }
  889. else
  890. {
  891. /* Set the max number of bytes to read/write
  892. during Eep_MainFunction call */
  893. if (MEMIF_MODE_SLOW == Eep_pConfigPtr->eDefaultMode)
  894. {
  895. Eep_u32MaxRead = Eep_pConfigPtr->u32MaxReadNormalMode;
  896. Eep_u32MaxWrite = Eep_pConfigPtr->u32MaxWriteNormalMode;
  897. }
  898. else
  899. {
  900. Eep_u32MaxRead = Eep_pConfigPtr->u32MaxReadFastMode;
  901. Eep_u32MaxWrite = Eep_pConfigPtr->u32MaxWriteFastMode;
  902. }
  903. #if (EEP_MCORE_ENABLED == STD_ON)
  904. /* Get domain ID from Xrdc which configured by users */
  905. Eep_u32DoMainID = (uint32)Rm_XrdcGetDomainID();
  906. /* Lock gate */
  907. if (E_OK == Eep_MCoreInitSema4sLock())
  908. {
  909. /* Initialize eeprom hardware */
  910. eRetVal = Eep_Ipw_Init(Eep_pConfigPtr);
  911. }
  912. else
  913. {
  914. /* Lock is not successful */
  915. eRetVal = EEP_E_FAILED;
  916. (void) Det_ReportRuntimeError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_INIT_ID, EEP_E_TIMEOUT);
  917. }
  918. /* Release the taken SEMA4s. */
  919. if (E_OK != Eep_MCoreJobSema4Release())
  920. {
  921. /* Unlock is not successful */
  922. eRetVal = EEP_E_FAILED;
  923. }
  924. #else
  925. eRetVal = Eep_Ipw_Init(Eep_pConfigPtr);
  926. #endif /* EEP_MCORE_ENABLED */
  927. if (EEP_E_FAILED == eRetVal)
  928. {
  929. Eep_eJobResult = MEMIF_JOB_FAILED;
  930. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  931. Eep_pConfigPtr = NULL_PTR;
  932. #endif
  933. }
  934. else
  935. {
  936. Eep_eJobResult = MEMIF_JOB_OK;
  937. }
  938. }
  939. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  940. }
  941. #endif
  942. }
  943. /**
  944. * @brief Erase memory by writing erase value.
  945. * @details Starts an erase job asynchronously. The actual job is performed
  946. * by the Eep_MainFunction.
  947. *
  948. * @param[in] TargetAddress Target address in eeprom memory.
  949. * @param[in] Length Number of bytes to erase by writing the erased value.
  950. *
  951. * @return Std_ReturnType
  952. * @retval E_OK Erase command has been accepted.
  953. * @retval E_NOT_OK Erase command has not been accepted.
  954. *
  955. * @api
  956. *
  957. * @pre The module has to be initialized and not busy.
  958. * @post
  959. *
  960. * @implements Eep_Erase_Activity
  961. *
  962. */
  963. Std_ReturnType Eep_Erase (Eep_AddressType u32TargetAddress,
  964. Eep_LengthType u32Length
  965. )
  966. {
  967. Std_ReturnType u8RetVal = E_NOT_OK;
  968. /* Check driver was initialized */
  969. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  970. if (NULL_PTR == Eep_pConfigPtr)
  971. {
  972. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_ERASE_ID, EEP_E_UNINIT);
  973. }
  974. else
  975. {
  976. #endif
  977. if ((Std_ReturnType)E_OK == Eep_Ipw_CheckEraseParams(u32TargetAddress, u32Length))
  978. {
  979. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_01();
  980. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  981. {
  982. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  983. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_ERASE_ID, EEP_E_BUSY);
  984. #endif
  985. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_01();
  986. }
  987. else
  988. {
  989. /* Configure the erase job */
  990. Eep_u32EepromAddrIt = u32TargetAddress;
  991. Eep_u32RemainingLength = u32Length;
  992. Eep_eJob = EEP_JOB_ERASE;
  993. Eep_eJobResult = MEMIF_JOB_PENDING;
  994. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_01();
  995. u8RetVal = E_OK;
  996. }
  997. }
  998. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  999. }
  1000. #endif
  1001. return u8RetVal;
  1002. }
  1003. /**
  1004. * @brief Write one or more complete eeprom pages to the eeprom device.
  1005. * @details Starts a write job asynchronously. The actual job is performed by
  1006. * Eep_MainFunction.
  1007. *
  1008. * @param[in] TargetAddress Target address in eeprom memory.
  1009. * @param[in] SourceAddressPtr Pointer to source data buffer.
  1010. * @param[in] Length Number of bytes to write.
  1011. *
  1012. * @return Std_ReturnType
  1013. * @retval E_OK Write command has been accepted.
  1014. * @retval E_NOT_OK Write command has not been accepted.
  1015. *
  1016. * @api
  1017. *
  1018. * @pre The module has to be initialized and not busy.
  1019. *
  1020. * @implements Eep_Write_Activity
  1021. *
  1022. */
  1023. Std_ReturnType Eep_Write (Eep_AddressType u32TargetAddress,
  1024. const uint8 * pSourceAddressPtr,
  1025. Eep_LengthType u32Length
  1026. )
  1027. {
  1028. Std_ReturnType u8RetVal = E_NOT_OK;
  1029. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1030. if (NULL_PTR == Eep_pConfigPtr)
  1031. {
  1032. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_WRITE_ID, EEP_E_UNINIT);
  1033. }
  1034. else
  1035. {
  1036. #endif
  1037. if ((Std_ReturnType)E_OK == Eep_Ipw_CheckWriteParams(u32TargetAddress, pSourceAddressPtr, u32Length))
  1038. {
  1039. /* enter EA to protect global variables */
  1040. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_02();
  1041. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1042. {
  1043. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1044. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_WRITE_ID, EEP_E_BUSY);
  1045. #endif
  1046. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_02();
  1047. }
  1048. else
  1049. {
  1050. /* Configure the write job */
  1051. /* uint32 destination address which will be incremented during job processing */
  1052. Eep_u32EepromAddrIt = u32TargetAddress;
  1053. /* uint8 source pointer which will be incremented during job processing */
  1054. Eep_pu8JobSrcAddrPtr = pSourceAddressPtr;
  1055. /* remaining length to be transfered */
  1056. Eep_u32RemainingLength = u32Length;
  1057. Eep_eJob = EEP_JOB_WRITE;
  1058. Eep_eJobResult = MEMIF_JOB_PENDING;
  1059. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_02();
  1060. u8RetVal = E_OK;
  1061. }
  1062. }
  1063. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1064. }
  1065. #endif
  1066. return u8RetVal;
  1067. }
  1068. /* If FTFC IP is present on the platform */
  1069. #if (EEP_QUICK_WRITES_API == STD_ON)
  1070. /**
  1071. * @brief Write one or more complete eeprom pages to the eeprom device in quick write mode.
  1072. * @details Starts a write job asynchronously. The actual job is performed by
  1073. * Eep_MainFunction.
  1074. *
  1075. * @param[in] TargetAddress Target address in eeprom memory.
  1076. * @param[in] SourceAddressPtr Pointer to source data buffer.
  1077. * @param[in] Length Number of bytes to write.
  1078. * @param[in] u16QuickWritesLength Number of bytes to allocated for quick write
  1079. *
  1080. * @return Std_ReturnType
  1081. * @retval E_OK Write command has been accepted.
  1082. * @retval E_NOT_OK Write command has not been accepted.
  1083. *
  1084. * @api
  1085. *
  1086. * @pre The module has to be initialized and not busy.
  1087. * @implements Eep_QuickWrite_Activity
  1088. */
  1089. Std_ReturnType Eep_QuickWrite (Eep_AddressType u32TargetAddress,
  1090. uint8 const * pSourceAddressPtr,
  1091. Eep_LengthType u32Length,
  1092. uint16 u16QuickWritesLength
  1093. )
  1094. {
  1095. Std_ReturnType retVal = E_NOT_OK;
  1096. Eep_ReturnType EepIpwReturn = EEP_E_OK;
  1097. uint8 const * pSourceAdd = pSourceAddressPtr;
  1098. Eep_LengthType u32LengthRemaining = u32Length;
  1099. Eep_AddressType u32DestAdd = u32TargetAddress;
  1100. /* in the quick writes mode only 4 bytes alligned writes are allowed */
  1101. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1102. if (NULL_PTR == Eep_pConfigPtr)
  1103. {
  1104. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_QUICK_WRITE_ID, EEP_E_UNINIT);
  1105. }
  1106. else
  1107. {
  1108. #endif
  1109. if ((Std_ReturnType)E_OK == Eep_Ipw_CheckQuickWriteParams(u32DestAdd, pSourceAdd, u32LengthRemaining, u16QuickWritesLength))
  1110. {
  1111. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_05();
  1112. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1113. {
  1114. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_05();
  1115. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1116. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_QUICK_WRITE_ID, EEP_E_BUSY);
  1117. #endif
  1118. }
  1119. else
  1120. {
  1121. EepIpwReturn = Eep_Ipw_QuickWrite(u32DestAdd, pSourceAdd, u16QuickWritesLength);
  1122. pSourceAdd = (uint8*)((uint32)pSourceAdd + u16QuickWritesLength);
  1123. u32DestAdd += u16QuickWritesLength;
  1124. u32LengthRemaining -= u16QuickWritesLength;
  1125. if (u32LengthRemaining == 0U)
  1126. {
  1127. if (EEP_E_OK == EepIpwReturn)
  1128. {
  1129. Eep_eJobResult = MEMIF_JOB_OK;
  1130. retVal = E_OK;
  1131. }
  1132. else
  1133. {
  1134. Eep_eJobResult = MEMIF_JOB_FAILED;
  1135. }
  1136. }
  1137. else
  1138. {
  1139. if (EEP_E_OK == EepIpwReturn)
  1140. {
  1141. /* uint8 source pointer which will be incremented during job processing */
  1142. Eep_pu8JobSrcAddrPtr = pSourceAdd;
  1143. /* uint32 destination address which will be incremented during job processing */
  1144. Eep_u32EepromAddrIt = u32DestAdd;
  1145. Eep_u32RemainingLength = u32LengthRemaining;
  1146. Eep_u16QuickWritesLength = u16QuickWritesLength;
  1147. Eep_eJob = EEP_JOB_QUICK_WRITE;
  1148. Eep_eJobResult = MEMIF_JOB_PENDING;
  1149. retVal = E_OK;
  1150. }
  1151. else
  1152. {
  1153. Eep_eJobResult = MEMIF_JOB_FAILED;
  1154. }
  1155. }
  1156. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_05();
  1157. }
  1158. }
  1159. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1160. }
  1161. #endif
  1162. return retVal;
  1163. }
  1164. #endif /* EEP_QUICK_WRITES_API */
  1165. #if (EEP_CANCEL_API == STD_ON)
  1166. /**
  1167. * @brief Cancel an ongoing eeprom read, write, erase or compare job.
  1168. * @details Abort a running job synchronously so that directly after returning
  1169. * from this function a new job can be started.
  1170. *
  1171. * @api
  1172. *
  1173. * @pre The module must be initialized.
  1174. * @post @p Eep_Cancel changes module status and @p Eep_eJobResult
  1175. * internal variable.
  1176. *
  1177. * @implements Eep_Cancel_Activity
  1178. */
  1179. void Eep_Cancel (void)
  1180. {
  1181. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1182. if (NULL_PTR == Eep_pConfigPtr)
  1183. {
  1184. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_CANCEL_ID, EEP_E_UNINIT);
  1185. }
  1186. else
  1187. {
  1188. #endif
  1189. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_06();
  1190. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1191. {
  1192. #if (EEP_MCORE_ENABLED == STD_ON)
  1193. /* Lock gate */
  1194. if (EEP_MCORE_HW_JOB_STARTED == Eep_MCoreHwJobStatus)
  1195. {
  1196. #endif /* #if (EEP_MCORE_ENABLED == STD_ON)*/
  1197. /* If underlying hardware job was successfully canceled */
  1198. if (EEP_E_OK == Eep_Ipw_Cancel())
  1199. {
  1200. /* Update global job result status */
  1201. Eep_eJobResult = MEMIF_JOB_CANCELED;
  1202. }
  1203. #if (EEP_MCORE_ENABLED == STD_ON)
  1204. }
  1205. else
  1206. {
  1207. /* Job is not started on hardware */
  1208. Eep_eJobResult = MEMIF_JOB_CANCELED;
  1209. }
  1210. if ((Std_ReturnType)E_OK != (Std_ReturnType)(Eep_MCoreJobSema4Release()))
  1211. {
  1212. /* Unlock is not successful */
  1213. Eep_eJobResult = MEMIF_JOB_FAILED;
  1214. }
  1215. Eep_MCoreHwJobStatus = EEP_MCORE_HW_JOB_IDLE;
  1216. #endif /* #if (EEP_MCORE_ENABLED == STD_ON)*/
  1217. /* Call the error notification function if configured */
  1218. Eep_CallNotification(Eep_eJobResult);
  1219. }
  1220. else
  1221. {
  1222. /* Leave the job result unchanged */
  1223. }
  1224. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_06();
  1225. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1226. }
  1227. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1228. }
  1229. #endif /* EEP_CANCEL_API == STD_ON */
  1230. #if (EEP_GET_STATUS_API == STD_ON)
  1231. /**
  1232. * @brief Returns the EEP module status.
  1233. * @details Returns the EEP module status synchronously.
  1234. *
  1235. * @return MemIf_StatusType
  1236. * @retval MEMIF_UNINIT Module has not been initialized (yet).
  1237. * @retval MEMIF_IDLE Module is currently idle.
  1238. * @retval MEMIF_BUSY Module is currently busy.
  1239. *
  1240. * @api
  1241. *
  1242. * @implements Eep_GetStatus_Activity
  1243. */
  1244. MemIf_StatusType Eep_GetStatus (void)
  1245. {
  1246. MemIf_StatusType eRetVal = MEMIF_IDLE;
  1247. /* Check the driver was initialized */
  1248. if (NULL_PTR == Eep_pConfigPtr)
  1249. {
  1250. eRetVal = MEMIF_UNINIT;
  1251. }
  1252. /* There is a pending job */
  1253. else if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1254. {
  1255. eRetVal = MEMIF_BUSY;
  1256. }
  1257. else
  1258. {
  1259. eRetVal = MEMIF_IDLE;
  1260. }
  1261. return eRetVal;
  1262. }
  1263. #endif /* EEP_GET_STATUS_API == STD_ON */
  1264. #if (EEP_GET_JOB_RESULT_API == STD_ON)
  1265. /**
  1266. * @brief Returns the result of the last job.
  1267. * @details Returns synchronously the result of the last job.
  1268. *
  1269. * @return MemIf_JobResultType
  1270. * @retval MEMIF_JOB_OK Successfully completed job.
  1271. * @retval MEMIF_JOB_FAILED Not successfully completed job.
  1272. * @retval MEMIF_JOB_PENDING Still pending job (not yet completed).
  1273. * @retval MEMIF_JOB_CANCELED Job has been canceled.
  1274. * @retval MEMIF_BLOCK_INCONSISTENT Inconsistent block requested, it may
  1275. * contains corrupted data.
  1276. * @retval MEMIF_BLOCK_INVALID Invalid block requested.
  1277. *
  1278. * @api
  1279. *
  1280. * @implements Eep_GetJobResult_Activity
  1281. */
  1282. MemIf_JobResultType Eep_GetJobResult (void)
  1283. {
  1284. MemIf_JobResultType eRetVal = MEMIF_JOB_OK;
  1285. /* Check the driver was initialized */
  1286. if (NULL_PTR == Eep_pConfigPtr)
  1287. {
  1288. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1289. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_GETJOBRESULT_ID, EEP_E_UNINIT);
  1290. #endif
  1291. eRetVal = (MemIf_JobResultType)MEMIF_JOB_FAILED;
  1292. }
  1293. else
  1294. {
  1295. /* Get the job result */
  1296. eRetVal = Eep_eJobResult;
  1297. }
  1298. return eRetVal;
  1299. }
  1300. #endif
  1301. /**
  1302. * @brief Reads from eeprom memory.
  1303. * @details Starts a read job asynchronously. The actual job is performed by
  1304. * @p Eep_MainFunction.
  1305. *
  1306. * @param[in] SourceAddress Source address in eeprom memory.
  1307. * @param[in] Length Number of bytes to read.
  1308. * @param[out] TargetAddressPtr Pointer to target data buffer.
  1309. *
  1310. * @return MemIf_JobResultType
  1311. * @retval MEMIF_JOB_OK Successfully completed job.
  1312. * @retval MEMIF_JOB_FAILED Not successfully completed job.
  1313. * @retval MEMIF_JOB_PENDING Still pending job (not yet completed).
  1314. * @retval MEMIF_JOB_CANCELED Job has been canceled.
  1315. * @retval MEMIF_BLOCK_INCONSISTENT Inconsistent block requested, it may
  1316. * contains corrupted data.
  1317. * @retval MEMIF_BLOCK_INVALID Invalid block requested.
  1318. *
  1319. * @api
  1320. *
  1321. * @pre The module has to be initialized and not busy.
  1322. * @post
  1323. *
  1324. * @implements Eep_Read_Activity
  1325. *
  1326. */
  1327. Std_ReturnType Eep_Read (Eep_AddressType u32SourceAddress,
  1328. uint8 * pTargetAddressPtr,
  1329. Eep_LengthType u32Length
  1330. )
  1331. {
  1332. Std_ReturnType u8RetVal = (Std_ReturnType)E_OK;
  1333. /* Check driver was initialized */
  1334. if (NULL_PTR == Eep_pConfigPtr)
  1335. {
  1336. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1337. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_READ_ID, EEP_E_UNINIT);
  1338. #endif
  1339. u8RetVal = (Std_ReturnType)E_NOT_OK;
  1340. }
  1341. else if ((Std_ReturnType)E_NOT_OK == Eep_Ipw_CheckReadParams(u32SourceAddress, pTargetAddressPtr, u32Length))
  1342. {
  1343. u8RetVal = E_NOT_OK;
  1344. }
  1345. else
  1346. {
  1347. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_03();
  1348. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1349. {
  1350. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1351. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_READ_ID, EEP_E_BUSY);
  1352. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1353. u8RetVal = (Std_ReturnType)E_NOT_OK;
  1354. }
  1355. else
  1356. {
  1357. /* Configure the read job */
  1358. Eep_u32EepromAddrIt = u32SourceAddress;
  1359. Eep_pu8JobDataDestPtr = pTargetAddressPtr;
  1360. Eep_u32RemainingLength = u32Length;
  1361. Eep_eJob = EEP_JOB_READ;
  1362. /* Execute the read job */
  1363. Eep_eJobResult = MEMIF_JOB_PENDING;
  1364. }
  1365. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_03();
  1366. }
  1367. return u8RetVal;
  1368. }
  1369. #if (EEP_COMPARE_API == STD_ON)
  1370. /**
  1371. * @brief Compares a eeprom memory area with an application data buffer.
  1372. * @details Starts a compare job asynchronously. The actual job is performed by
  1373. * Eep_MainFunction.
  1374. *
  1375. * @param[in] SourceAddress Source address in eeprom memory.
  1376. * @param[in] TargetAddressPtr Pointer to source data buffer.
  1377. * @param[in] Length Number of bytes to compare.
  1378. *
  1379. * @return Std_ReturnType
  1380. * @retval E_OK Compare command has been accepted.
  1381. * @retval E_NOT_OK Compare command has not been accepted.
  1382. *
  1383. * @api
  1384. *
  1385. * @pre The module has to be initialized and not busy.
  1386. *
  1387. * @implements Eep_Compare_Activity
  1388. */
  1389. Std_ReturnType Eep_Compare (Eep_AddressType u32SourceAddress,
  1390. const uint8 * pTargetAddressPtr,
  1391. Eep_LengthType u32Length
  1392. )
  1393. {
  1394. Std_ReturnType u8RetVal = (Std_ReturnType)E_OK;
  1395. /* Check driver was initialized */
  1396. if (NULL_PTR == Eep_pConfigPtr)
  1397. {
  1398. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1399. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_COMPARE_ID, EEP_E_UNINIT);
  1400. #endif
  1401. u8RetVal = (Std_ReturnType)E_NOT_OK;
  1402. }
  1403. else if ((Std_ReturnType)E_NOT_OK == Eep_Ipw_CheckCompareParams(u32SourceAddress, pTargetAddressPtr, u32Length))
  1404. {
  1405. u8RetVal = E_NOT_OK;
  1406. }
  1407. else
  1408. {
  1409. SchM_Enter_Eep_EEP_EXCLUSIVE_AREA_04();
  1410. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1411. {
  1412. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1413. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_COMPARE_ID, EEP_E_BUSY);
  1414. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1415. u8RetVal = (Std_ReturnType)E_NOT_OK;
  1416. }
  1417. else
  1418. {
  1419. /* Set job for compare operation */
  1420. Eep_u32EepromAddrIt = u32SourceAddress;
  1421. Eep_pu8JobSrcAddrPtr = pTargetAddressPtr;
  1422. Eep_u32RemainingLength = u32Length;
  1423. Eep_eJob = EEP_JOB_COMPARE;
  1424. Eep_eJobResult = MEMIF_JOB_PENDING;
  1425. }
  1426. SchM_Exit_Eep_EEP_EXCLUSIVE_AREA_04();
  1427. }
  1428. return u8RetVal;
  1429. }
  1430. #endif /* EEP_COMPARE_API == STD_ON */
  1431. #if (EEP_SET_MODE_API == STD_ON)
  1432. /**
  1433. * @brief Sets the EEP module's operation mode to the given Mode.
  1434. * @details Every given mode determinates maximum bytes for read-write
  1435. * operations. Every mode has a set of pre-configured values.
  1436. *
  1437. * @param[in] Mode MEMIF_MODE_FAST or MEMIF_MODE_SLOW.
  1438. *
  1439. * @api
  1440. *
  1441. * @pre The module has to be initialized and not busy.
  1442. * @post @p Eep_SetMode changes internal variables @p Eep_u32MaxRead and
  1443. * @p Eep_u32MaxWrite.
  1444. *
  1445. * @implements Eep_SetMode_Activity
  1446. */
  1447. void Eep_SetMode (MemIf_ModeType eMode)
  1448. {
  1449. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1450. if (NULL_PTR == Eep_pConfigPtr)
  1451. {
  1452. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_SETMODE_ID, EEP_E_UNINIT);
  1453. }
  1454. else if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1455. {
  1456. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_SETMODE_ID, EEP_E_BUSY);
  1457. }
  1458. else
  1459. {
  1460. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1461. /* Set the max number of bytes to read/write
  1462. during Eep_MainFunction call */
  1463. switch (eMode)
  1464. {
  1465. case MEMIF_MODE_FAST:
  1466. Eep_u32MaxRead = Eep_pConfigPtr->u32MaxReadFastMode;
  1467. Eep_u32MaxWrite = Eep_pConfigPtr->u32MaxWriteFastMode;
  1468. break;
  1469. case MEMIF_MODE_SLOW:
  1470. Eep_u32MaxRead = Eep_pConfigPtr->u32MaxReadNormalMode;
  1471. Eep_u32MaxWrite = Eep_pConfigPtr->u32MaxWriteNormalMode;
  1472. break;
  1473. default:
  1474. /* Do nothing - should not happen in Fully Trusted Environment;
  1475. 'default' clause added to fulfill MISRA Rule 15.3 */
  1476. break;
  1477. }
  1478. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1479. }
  1480. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1481. }
  1482. #endif /* EEP_SET_MODE_API == STD_ON */
  1483. #if (EEP_VERSION_INFO_API == STD_ON)
  1484. /**
  1485. * @brief Returns version information about EEP module.
  1486. * @details Version information includes:
  1487. * - Module Id
  1488. * - Vendor Id
  1489. * - Vendor specific version numbers (BSW00407).
  1490. *
  1491. * @param[in,out] pVersionInfoPtr Pointer to where to store the version information of this module.
  1492. *
  1493. * @api
  1494. *
  1495. * @implements Eep_GetVersionInfo_Activity
  1496. *
  1497. */
  1498. void Eep_GetVersionInfo (Std_VersionInfoType * pVersionInfoPtr)
  1499. {
  1500. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1501. if (NULL_PTR == pVersionInfoPtr)
  1502. {
  1503. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_GETVERSIONINFO_ID, EEP_E_PARAM_POINTER);
  1504. }
  1505. else
  1506. {
  1507. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1508. pVersionInfoPtr->moduleID = (uint16)EEP_MODULE_ID;
  1509. pVersionInfoPtr->vendorID = (uint16)EEP_VENDOR_ID;
  1510. pVersionInfoPtr->sw_major_version = (uint8)EEP_SW_MAJOR_VERSION;
  1511. pVersionInfoPtr->sw_minor_version = (uint8)EEP_SW_MINOR_VERSION;
  1512. pVersionInfoPtr->sw_patch_version = (uint8)EEP_SW_PATCH_VERSION;
  1513. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1514. }
  1515. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1516. }
  1517. #endif
  1518. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  1519. /**
  1520. * @brief Reports DEM errors
  1521. * @details Reports production errors.
  1522. *
  1523. * @param[in,out] -
  1524. *
  1525. * @api
  1526. *
  1527. */
  1528. static void Eep_ReportDemErrors (void)
  1529. {
  1530. switch (Eep_eJob)
  1531. {
  1532. case EEP_JOB_ERASE:
  1533. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_EraseFailedCfg.state)
  1534. {
  1535. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_EraseFailedCfg.id, DEM_EVENT_STATUS_FAILED);
  1536. }
  1537. break;
  1538. case EEP_JOB_WRITE:
  1539. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_WriteFailedCfg.state)
  1540. {
  1541. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_WriteFailedCfg.id, DEM_EVENT_STATUS_FAILED);
  1542. }
  1543. break;
  1544. case EEP_JOB_READ:
  1545. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_ReadFailedCfg.state)
  1546. {
  1547. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_ReadFailedCfg.id, DEM_EVENT_STATUS_FAILED);
  1548. }
  1549. break;
  1550. #if (EEP_COMPARE_API == STD_ON)
  1551. case EEP_JOB_COMPARE:
  1552. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_CompareFailedCfg.state)
  1553. {
  1554. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_CompareFailedCfg.id, DEM_EVENT_STATUS_FAILED);
  1555. }
  1556. break;
  1557. #endif
  1558. #if (EEP_QUICK_WRITES_API == STD_ON)
  1559. case EEP_JOB_QUICK_WRITE:
  1560. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_BOQuickWritesCfg.state)
  1561. {
  1562. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_BOQuickWritesCfg.id, DEM_EVENT_STATUS_FAILED);
  1563. }
  1564. break;
  1565. #endif
  1566. default:
  1567. /* Do nothing - should not happen in Fully Trusted Environment;
  1568. 'default' clause added to fulfill MISRA Rule 15.3 */
  1569. break;
  1570. }
  1571. }
  1572. /**
  1573. * @brief Reports DEM passes
  1574. * @details Reports production passes.
  1575. *
  1576. * @param[in,out] -
  1577. *
  1578. * @api
  1579. *
  1580. */
  1581. static void Eep_ReportDemPasses (void)
  1582. {
  1583. switch (Eep_eJob)
  1584. {
  1585. case EEP_JOB_ERASE:
  1586. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_EraseFailedCfg.state)
  1587. {
  1588. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_EraseFailedCfg.id, DEM_EVENT_STATUS_PASSED);
  1589. }
  1590. break;
  1591. case EEP_JOB_WRITE:
  1592. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_WriteFailedCfg.state)
  1593. {
  1594. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_WriteFailedCfg.id, DEM_EVENT_STATUS_PASSED);
  1595. }
  1596. break;
  1597. case EEP_JOB_READ:
  1598. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_ReadFailedCfg.state)
  1599. {
  1600. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_ReadFailedCfg.id, DEM_EVENT_STATUS_PASSED);
  1601. }
  1602. break;
  1603. #if (EEP_COMPARE_API == STD_ON)
  1604. case EEP_JOB_COMPARE:
  1605. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_CompareFailedCfg.state)
  1606. {
  1607. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_CompareFailedCfg.id, DEM_EVENT_STATUS_PASSED);
  1608. }
  1609. break;
  1610. #endif
  1611. #if (EEP_QUICK_WRITES_API == STD_ON)
  1612. case EEP_JOB_QUICK_WRITE:
  1613. if ((uint32)STD_ON == Eep_pConfigPtr->Eep_E_BOQuickWritesCfg.state)
  1614. {
  1615. (void)Dem_SetEventStatus((Dem_EventIdType)Eep_pConfigPtr->Eep_E_BOQuickWritesCfg.id, DEM_EVENT_STATUS_PASSED);
  1616. }
  1617. break;
  1618. #endif
  1619. default:
  1620. /* Do nothing - should not happen in Fully Trusted Environment;
  1621. default clause added to fulfill MISRA Rule 15.3 */
  1622. break;
  1623. }
  1624. }
  1625. #endif
  1626. /**
  1627. * @brief Performs actual eeprom read, write, erase and compare jobs.
  1628. * @pre The module has to be initialized.
  1629. * @param[in] eJob Currently executed job (erase, write, read, or compare)
  1630. *
  1631. * @return MemIf_JobResultType
  1632. * @retval MEMIF_JOB_OK Successfully completed job.
  1633. * @retval MEMIF_JOB_FAILED Not successfully completed job.
  1634. * @retval MEMIF_JOB_PENDING Still pending job (not yet completed).
  1635. * @retval MEMIF_JOB_CANCELED Job has been canceled.
  1636. * @retval MEMIF_BLOCK_INCONSISTENT Inconsistent block requested, it may
  1637. * contains corrupted data.
  1638. * @retval MEMIF_BLOCK_INVALID Invalid block requested.
  1639. */
  1640. static MemIf_JobResultType Eep_ProcessRequestedJobs (Eep_JobType eJob)
  1641. {
  1642. MemIf_JobResultType eRetVal = MEMIF_JOB_FAILED;
  1643. switch (eJob)
  1644. {
  1645. case EEP_JOB_ERASE:
  1646. /* Process erase job */
  1647. eRetVal = Eep_ProcessEraseJob();
  1648. break;
  1649. case EEP_JOB_WRITE:
  1650. /* Process write job */
  1651. eRetVal = Eep_ProcessWriteJob();
  1652. break;
  1653. case EEP_JOB_READ:
  1654. /* Process read job */
  1655. eRetVal = Eep_ProcessReadJob();
  1656. break;
  1657. #if (EEP_COMPARE_API == STD_ON)
  1658. case EEP_JOB_COMPARE:
  1659. /* Process compare job */
  1660. eRetVal = Eep_ProcessCompareJob();
  1661. break;
  1662. #endif
  1663. #if (EEP_QUICK_WRITES_API == STD_ON)
  1664. case EEP_JOB_QUICK_WRITE:
  1665. eRetVal = Eep_ProcessQuickWriteJob();
  1666. break;
  1667. #endif
  1668. default:
  1669. /* Do nothing - should not happen in Fully Trusted Environment;
  1670. 'default' clause added to fulfill MISRA Rule 15.3 */
  1671. break;
  1672. }
  1673. return eRetVal;
  1674. }
  1675. /**
  1676. * @brief Only executed at the end of a new job
  1677. *
  1678. * @param[in] None
  1679. *
  1680. * @pre The module has to be initialized.
  1681. *
  1682. */
  1683. static void Eep_EndJobs (void)
  1684. {
  1685. #if (EEP_DISABLE_DEM_REPORT_ERROR_STATUS == STD_OFF)
  1686. /* if job failed report errors */
  1687. if (MEMIF_JOB_FAILED == Eep_eJobResult)
  1688. {
  1689. Eep_ReportDemErrors();
  1690. }
  1691. else if (MEMIF_JOB_OK == Eep_eJobResult)
  1692. {
  1693. Eep_ReportDemPasses();
  1694. }
  1695. else
  1696. {
  1697. /* Not report any dems */
  1698. }
  1699. #endif
  1700. /* call notifications when job was finished */
  1701. if ((MEMIF_JOB_FAILED == Eep_eJobResult) || (MEMIF_BLOCK_INCONSISTENT == Eep_eJobResult) || (MEMIF_JOB_OK == Eep_eJobResult))
  1702. {
  1703. Eep_CallNotification(Eep_eJobResult);
  1704. }
  1705. }
  1706. /**
  1707. * @brief Performs actual eeprom read, write, erase and compare jobs.
  1708. * @details Bytes number processed per cycle depends by job type (erase, write, read, compare)
  1709. * current EEP module's operating mode (normal, fast)
  1710. * and write, erase Mode of Execution (sync, async).
  1711. *
  1712. * @api
  1713. *
  1714. * @pre The module has to be initialized.
  1715. *
  1716. *
  1717. * @note This function have to be called ciclically by the Basic Software Module;
  1718. * it will do nothing if there aren't pending job.
  1719. * @implements Eep_MainFunction_Activity
  1720. */
  1721. void Eep_MainFunction (void)
  1722. {
  1723. #if (STD_ON == EEP_MCORE_ENABLED)
  1724. static uint32 u32TimeoutTicks = 0U;
  1725. static uint32 u32CurrentTicks = 0U;
  1726. static uint32 u32ElapsedTicks = 0U;
  1727. Eep_MCoreReqReturnType eMcoreStatus;
  1728. #endif
  1729. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1730. if (NULL_PTR == Eep_pConfigPtr)
  1731. {
  1732. (void) Det_ReportError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_MAINFUNCTION_ID, EEP_E_UNINIT);
  1733. }
  1734. else
  1735. {
  1736. #endif
  1737. if (MEMIF_JOB_PENDING == Eep_eJobResult)
  1738. {
  1739. #if (STD_ON == EEP_MCORE_ENABLED)
  1740. if (EEP_MCORE_HW_JOB_IDLE == Eep_MCoreHwJobStatus)
  1741. {
  1742. u32TimeoutTicks = OsIf_MicrosToTicks(EEP_MCORE_LOCK_GATES_TIMEOUT,(OsIf_CounterType)USDHC_IP_TIMEOUT_TYPE);
  1743. u32CurrentTicks = OsIf_GetCounter((OsIf_CounterType)USDHC_IP_TIMEOUT_TYPE);
  1744. u32ElapsedTicks = 0U;
  1745. Eep_MCoreHwJobStatus = EEP_MCORE_HW_JOB_MAINF_STARTED;
  1746. }
  1747. eMcoreStatus = Eep_ReqMCore();
  1748. if (EEP_MCORE_PENDING == eMcoreStatus)
  1749. {
  1750. u32ElapsedTicks += OsIf_GetElapsed(&u32CurrentTicks, (OsIf_CounterType)USDHC_IP_TIMEOUT_TYPE);
  1751. if (u32ElapsedTicks >= u32TimeoutTicks)
  1752. {
  1753. Eep_eJobResult = MEMIF_JOB_FAILED;
  1754. (void)Det_ReportRuntimeError((uint16)EEP_MODULE_ID, EEP_INSTANCE_ID, EEP_MAINFUNCTION_ID, EEP_E_TIMEOUT);
  1755. }
  1756. }
  1757. else
  1758. {
  1759. /* Seme4 is granted */
  1760. Eep_MCoreHwJobStatus = EEP_MCORE_HW_JOB_STARTED;
  1761. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  1762. /* Process the requested jobs : write, compare, erase, read */
  1763. Eep_eJobResult = Eep_ProcessRequestedJobs(Eep_eJob);
  1764. #if (EEP_MCORE_ENABLED == STD_ON)
  1765. }
  1766. #endif /*#if (EEP_MCORE_ENABLED == STD_ON)*/
  1767. if (MEMIF_JOB_PENDING != Eep_eJobResult)
  1768. {
  1769. #if (EEP_MCORE_ENABLED == STD_ON)
  1770. Eep_MCoreHwJobStatus = EEP_MCORE_HW_JOB_IDLE;
  1771. /* Release any sema4 used for processing this job in multicore context, if any was used. */
  1772. if ((Std_ReturnType)E_OK != (Std_ReturnType)(Eep_MCoreJobSema4Release()))
  1773. {
  1774. /* Release is not successful */
  1775. Eep_eJobResult = MEMIF_JOB_FAILED;
  1776. }
  1777. #endif /*#if (EEP_MCORE_ENABLED == STD_ON)*/
  1778. /* only executed at the end of a new job */
  1779. Eep_EndJobs();
  1780. }
  1781. }
  1782. else
  1783. {
  1784. /* Nothing to do since no job is pending */
  1785. }
  1786. #if (EEP_DEV_ERROR_DETECT == STD_ON)
  1787. }
  1788. #endif /* EEP_DEV_ERROR_DETECT == STD_ON */
  1789. }
  1790. #if (EEP_MCORE_ENABLED == STD_ON)
  1791. static Eep_MCoreReqReturnType Eep_ReqMCore(void)
  1792. {
  1793. uint32 u32GetGateStatus;
  1794. Eep_MCoreReqReturnType eRetVal = EEP_MCORE_ERROR;
  1795. u32GetGateStatus = Rm_SemaphoreGetStatus(EEP_MCORE_SEMA4_JOB);
  1796. if (Eep_u32DoMainID == u32GetGateStatus)
  1797. {
  1798. eRetVal = EEP_MCORE_GRANTED;
  1799. }
  1800. else if (RM_SEMAPHORE_FREE == u32GetGateStatus)
  1801. {
  1802. if ((Std_ReturnType)E_OK == (Std_ReturnType)(Rm_SemaphoreLockGate(EEP_MCORE_SEMA4_JOB)))
  1803. {
  1804. /* EEP_MCORE_SEMA4_JOB taken. */
  1805. eRetVal = EEP_MCORE_GRANTED;
  1806. }
  1807. else
  1808. {
  1809. /* Due to race condition this core couldn't take the SEMA4. */
  1810. eRetVal = EEP_MCORE_PENDING;
  1811. }
  1812. }
  1813. else
  1814. {
  1815. /* Sema4 is taken by other core */
  1816. eRetVal = EEP_MCORE_PENDING;
  1817. }
  1818. return eRetVal;
  1819. }
  1820. /* Lock Gate */
  1821. static Std_ReturnType Eep_MCoreInitSema4sLock (void)
  1822. {
  1823. Std_ReturnType eRetVal = (Std_ReturnType)E_OK;
  1824. uint32 u32timeoutTicks = OsIf_MicrosToTicks(EEP_MCORE_LOCK_GATES_TIMEOUT, (OsIf_CounterType)USDHC_IP_TIMEOUT_TYPE);
  1825. uint32 u32currentTicks = OsIf_GetCounter((OsIf_CounterType)USDHC_IP_TIMEOUT_TYPE);
  1826. uint32 u32elapsedTicks = 0U;
  1827. while (((Std_ReturnType)E_OK != (Std_ReturnType)Rm_SemaphoreLockGate((uint8)EEP_MCORE_SEMA4_JOB)) && (u32elapsedTicks < u32timeoutTicks))
  1828. {
  1829. u32elapsedTicks += OsIf_GetElapsed(&u32currentTicks, USDHC_IP_TIMEOUT_TYPE);
  1830. }
  1831. if (u32elapsedTicks >= u32timeoutTicks)
  1832. {
  1833. /* Timeout errors */
  1834. eRetVal = E_NOT_OK;
  1835. }
  1836. return eRetVal;
  1837. }
  1838. /* Release Gate */
  1839. static Std_ReturnType Eep_MCoreJobSema4Release (void)
  1840. {
  1841. Std_ReturnType eRetVal = (Std_ReturnType)E_OK;
  1842. if (Eep_u32DoMainID == (uint32)Rm_SemaphoreGetStatus((uint8)EEP_MCORE_SEMA4_JOB))
  1843. {
  1844. if ((Std_ReturnType)E_OK != (Std_ReturnType)(Rm_SemaphoreUnlockGate((uint8)EEP_MCORE_SEMA4_JOB)))
  1845. {
  1846. eRetVal = E_NOT_OK;
  1847. }
  1848. }
  1849. else
  1850. {
  1851. /* Do nothing. */
  1852. }
  1853. return eRetVal;
  1854. }
  1855. #endif /* #if (EEP_MCORE_ENABLED == STD_ON) */
  1856. #define EEP_STOP_SEC_CODE
  1857. #include "Eep_MemMap.h"
  1858. #ifdef __cplusplus
  1859. }
  1860. #endif
  1861. /** @} */