Gpt_Ipw.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : Ftm_Srtc_Lptmr_LPit
  5. * Dependencies : none
  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 Gpt_Ipw.c
  26. *
  27. * @internal
  28. * @addtogroup gpt gpt_ipw
  29. *
  30. * @{
  31. */
  32. #ifdef __cplusplus
  33. extern "C"{
  34. #endif
  35. /*==================================================================================================
  36. * INCLUDE FILES
  37. * 1) system and project includes
  38. * 2) needed interfaces from external units
  39. * 3) internal and external interfaces from this unit
  40. ==================================================================================================*/
  41. #include "Gpt_Ipw.h"
  42. #include "StandardTypes.h"
  43. #include "Mcal.h"
  44. /*==================================================================================================
  45. * SOURCE FILE VERSION INFORMATION
  46. ==================================================================================================*/
  47. #define GPT_IPW_VENDOR_ID_C 43
  48. #define GPT_IPW_AR_RELEASE_MAJOR_VERSION_C 4
  49. #define GPT_IPW_AR_RELEASE_MINOR_VERSION_C 4
  50. #define GPT_IPW_AR_RELEASE_REVISION_VERSION_C 0
  51. #define GPT_IPW_SW_MAJOR_VERSION_C 1
  52. #define GPT_IPW_SW_MINOR_VERSION_C 0
  53. #define GPT_IPW_SW_PATCH_VERSION_C 0
  54. /*==================================================================================================
  55. * FILE VERSION CHECKS
  56. ==================================================================================================*/
  57. #if ( GPT_IPW_VENDOR_ID_C != GPT_IPW_VENDOR_ID)
  58. #error "Gpt_Ipw.c and Gpt_Ipw.h have different vendor ids"
  59. #endif
  60. /* Check if the header files are of the same Autosar version */
  61. #if ((GPT_IPW_AR_RELEASE_MAJOR_VERSION_C != GPT_IPW_AR_RELEASE_MAJOR_VERSION) || \
  62. (GPT_IPW_AR_RELEASE_MINOR_VERSION_C != GPT_IPW_AR_RELEASE_MINOR_VERSION) || \
  63. (GPT_IPW_AR_RELEASE_REVISION_VERSION_C != GPT_IPW_AR_RELEASE_REVISION_VERSION) \
  64. )
  65. #error "AutoSar Version Numbers of Gpt_Ipw.c and Gpt_Ipw.h are different"
  66. #endif
  67. /* Check if the header files are of the same Software version */
  68. #if ((GPT_IPW_SW_MAJOR_VERSION_C != GPT_IPW_SW_MAJOR_VERSION) || \
  69. (GPT_IPW_SW_MINOR_VERSION_C != GPT_IPW_SW_MINOR_VERSION) || \
  70. (GPT_IPW_SW_PATCH_VERSION_C != GPT_IPW_SW_PATCH_VERSION) \
  71. )
  72. #error "Software Version Numbers of Gpt_Ipw.c and Gpt_Ipw.h are different"
  73. #endif
  74. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  75. #if ((GPT_IPW_AR_RELEASE_MAJOR_VERSION_C != STD_AR_RELEASE_MAJOR_VERSION) || \
  76. (GPT_IPW_AR_RELEASE_MINOR_VERSION_C != STD_AR_RELEASE_MINOR_VERSION))
  77. #error "AutoSar Version Numbers of Gpt_Ipw.c and Std_Types.h are different"
  78. #endif
  79. #if ((GPT_IPW_AR_RELEASE_MAJOR_VERSION_C != MCAL_AR_RELEASE_MAJOR_VERSION) || \
  80. (GPT_IPW_AR_RELEASE_MINOR_VERSION_C != MCAL_AR_RELEASE_MINOR_VERSION))
  81. #error "AutoSar Version Numbers of Mcal.h and Gpt_Ipw.c are different"
  82. #endif
  83. #endif
  84. /*==================================================================================================
  85. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  86. ==================================================================================================*/
  87. /*==================================================================================================
  88. * LOCAL MACROS
  89. ==================================================================================================*/
  90. #if (FTM_GPT_IP_USED == STD_ON)
  91. #define FTM_CNT_MAX_VALUE_U32 ((uint32)0xFFFFuL)
  92. #define FTM_OVERFLOW_PAD_U32 ((uint32)1U)
  93. #endif
  94. /*==================================================================================================
  95. * LOCAL CONSTANTS
  96. ==================================================================================================*/
  97. /*==================================================================================================
  98. * LOCAL VARIABLES
  99. ==================================================================================================*/
  100. /*==================================================================================================
  101. * GLOBAL CONSTANTS
  102. ==================================================================================================*/
  103. /*==================================================================================================
  104. * GLOBAL VARIABLES
  105. ==================================================================================================*/
  106. /*==================================================================================================
  107. * LOCAL FUNCTION PROTOTYPES
  108. ==================================================================================================*/
  109. #if (FTM_GPT_IP_USED == STD_ON)
  110. static inline Gpt_ValueType Gpt_Ipw_FtmGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig, Gpt_HwChannelInfoType * pReturnHwChannelInfo);
  111. #endif
  112. #if (SRTC_IP_USED == STD_ON)
  113. static inline Gpt_ValueType Gpt_Ipw_SrtcGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig, Gpt_HwChannelInfoType * pReturnHwChannelInfo);
  114. #endif
  115. #if (LPTMR_GPT_IP_USED == STD_ON)
  116. static inline Gpt_ValueType Gpt_Ipw_LptmrGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig, Gpt_HwChannelInfoType * pReturnHwChannelInfo);
  117. #endif
  118. #if (LPIT_GPT_IP_USED == STD_ON)
  119. static inline Gpt_ValueType Gpt_Ipw_LpitGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig, Gpt_HwChannelInfoType * pReturnHwChannelInfo);
  120. #endif
  121. /*==================================================================================================
  122. * LOCAL FUNCTIONS
  123. ==================================================================================================*/
  124. #define GPT_START_SEC_CODE
  125. #include "Gpt_MemMap.h"
  126. #if (FTM_GPT_IP_USED == STD_ON)
  127. static inline Gpt_ValueType Gpt_Ipw_FtmGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig,
  128. Gpt_HwChannelInfoType * pReturnHwChannelInfo)
  129. {
  130. uint32 returnValue = 0U;
  131. uint32 tempValue = 0U;
  132. uint32 compareValue = 0U;
  133. uint32 counterValue = 0U;
  134. pReturnHwChannelInfo->uTargetTime = Ftm_Gpt_Ip_u32TargetValue[pHwChannelConfig->instance][pHwChannelConfig->channel];
  135. /* Read compare and counter registers */
  136. counterValue = Ftm_Gpt_Ip_GetCounter(pHwChannelConfig->instance);
  137. compareValue = Ftm_Gpt_Ip_GetCompareValue(pHwChannelConfig->instance, pHwChannelConfig->channel);
  138. /* Calculate the elapsed time */
  139. if (counterValue > compareValue)
  140. {
  141. /* Counter value passed the set-up Target value - might have roll-over */
  142. if(((FTM_CNT_MAX_VALUE_U32 - counterValue) + compareValue) <= pReturnHwChannelInfo->uTargetTime)
  143. {
  144. /* New compare value was read by register read - isr served in time - we have roll-over */
  145. returnValue = (pReturnHwChannelInfo->uTargetTime - \
  146. ((FTM_CNT_MAX_VALUE_U32 - counterValue) + compareValue)) + \
  147. FTM_OVERFLOW_PAD_U32;
  148. }
  149. else
  150. {
  151. /* There is an delay in serving ISR or updating u32CompareValue - report last timer time */
  152. returnValue = pReturnHwChannelInfo->uTargetTime;
  153. }
  154. }
  155. else
  156. {
  157. /* Timer in between ISRs period */
  158. returnValue = pReturnHwChannelInfo->uTargetTime - (compareValue - counterValue);
  159. }
  160. tempValue = Ftm_Gpt_Ip_GetInterruptFlag(pHwChannelConfig->instance, pHwChannelConfig->channel);
  161. /*Check interrupt status flag*/
  162. if (0U != tempValue)
  163. {
  164. /* Channel counter was roll-over */
  165. pReturnHwChannelInfo->bChannelRollover = TRUE;
  166. }
  167. else
  168. {
  169. /* Channel counter was not rollover */
  170. pReturnHwChannelInfo->bChannelRollover = FALSE;
  171. }
  172. return((Gpt_ValueType)returnValue);
  173. }
  174. #endif
  175. #if (SRTC_IP_USED == STD_ON)
  176. static inline Gpt_ValueType Gpt_Ipw_SrtcGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig,
  177. Gpt_HwChannelInfoType * pReturnHwChannelInfo)
  178. {
  179. uint32 returnValue = 0U;
  180. uint32 tempValue = 0U;
  181. uint32 compareValue = 0U;
  182. uint32 counterValue = 0U;
  183. pReturnHwChannelInfo->uTargetTime = Srtc_Ip_u32TargetValue;
  184. /* Read Time Seconds Register and Time Alarm Register. Time Alarm was minus one at initial */
  185. counterValue = Srtc_Ip_GetTimeSecondsRegister(pHwChannelConfig->instance);
  186. compareValue = Srtc_Ip_GetTimeAlarmRegister(pHwChannelConfig->instance) + 1U;
  187. /* Calculate the elapsed time */
  188. if (counterValue > compareValue)
  189. {
  190. tempValue = (MAX_32BIT - counterValue) + compareValue + 1U;
  191. }
  192. else
  193. {
  194. tempValue = compareValue - counterValue;
  195. }
  196. if (tempValue > Srtc_Ip_u32TargetValue)
  197. {
  198. returnValue = Srtc_Ip_u32TargetValue;
  199. }
  200. else
  201. {
  202. returnValue = Srtc_Ip_u32TargetValue - tempValue;
  203. }
  204. tempValue = Srtc_Ip_GetStatusFlags(pHwChannelConfig->instance, SRTC_IP_ALARM_INTERRUPT);
  205. /*Check interrupt status flag*/
  206. if (0U != tempValue)
  207. {
  208. /* Channel counter was roll-over */
  209. pReturnHwChannelInfo->bChannelRollover = TRUE;
  210. }
  211. else
  212. {
  213. /* Channel counter was not rollover */
  214. pReturnHwChannelInfo->bChannelRollover = FALSE;
  215. }
  216. return((Gpt_ValueType)returnValue);
  217. }
  218. #endif
  219. #if (LPTMR_GPT_IP_USED == STD_ON)
  220. static inline Gpt_ValueType Gpt_Ipw_LptmrGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig,
  221. Gpt_HwChannelInfoType * pReturnHwChannelInfo)
  222. {
  223. uint32 returnValue = 0U;
  224. /* Read the LPTMR channel load register */
  225. pReturnHwChannelInfo->uTargetTime = Lptmr_Gpt_Ip_GetCompareValue(pHwChannelConfig->instance);
  226. /* The Counter Register returns the current value of the LPTMR at the time this register was last written. */
  227. Lptmr_Gpt_Ip_WriteCounterValue(pHwChannelConfig->instance, 0U);
  228. /* Read the LPTMR counter register*/
  229. returnValue = Lptmr_Gpt_Ip_GetCntValue(pHwChannelConfig->instance);
  230. /*Check interrupt status flag*/
  231. if (TRUE == Lptmr_Gpt_Ip_GetCmpFlagState(pHwChannelConfig->instance))
  232. {
  233. /* Channel counter was roll-over */
  234. pReturnHwChannelInfo->bChannelRollover = TRUE;
  235. }
  236. else
  237. {
  238. /* Channel counter was not roll-over */
  239. pReturnHwChannelInfo->bChannelRollover = FALSE;
  240. }
  241. return((Gpt_ValueType)returnValue);
  242. }
  243. #endif
  244. #if (LPIT_GPT_IP_USED == STD_ON)
  245. static inline Gpt_ValueType Gpt_Ipw_LpitGetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig,
  246. Gpt_HwChannelInfoType * pReturnHwChannelInfo)
  247. {
  248. uint32 returnValue = 0U;
  249. uint32 tempValue = 0U;
  250. pReturnHwChannelInfo->uTargetTime = Lpit_Gpt_Ip_GetTimerValue(pHwChannelConfig->instance,pHwChannelConfig->channel);
  251. returnValue = (uint32)(pReturnHwChannelInfo->uTargetTime) - Lpit_Gpt_Ip_GetCurrentTimervalue(pHwChannelConfig->instance, pHwChannelConfig->channel);
  252. /*Check interrupt status flag*/
  253. tempValue = (uint32)(Lpit_Gpt_Ip_GetInterruptFlagTimerChannels(pHwChannelConfig->instance,(1U << (pHwChannelConfig->channel))) >> pHwChannelConfig->channel);
  254. if (0U != tempValue)
  255. {
  256. /* Channel counter was roll-over */
  257. pReturnHwChannelInfo->bChannelRollover = TRUE;
  258. }
  259. else
  260. {
  261. /* Channel counter was not roll-over */
  262. pReturnHwChannelInfo->bChannelRollover = FALSE;
  263. }
  264. return((Gpt_ValueType)returnValue);
  265. }
  266. #endif
  267. /*==================================================================================================
  268. * GLOBAL FUNCTIONS
  269. ==================================================================================================*/
  270. /*================================================================================================*/
  271. /**
  272. * @brief Gpt driver Autosar independent and IP dependent initialization function.
  273. * @details This Gpt_Ipw_InitInstances is called once for each channel in the used configuration.
  274. * It determines the type of the HW channel and calls the
  275. * appropriate IP function in order to initializes the hardware timer.
  276. * @param[in] configPtr Pointer to the channel configuration structure dependent by platform
  277. *
  278. * @return void
  279. * @pre The driver needs to be initialized.
  280. */
  281. void Gpt_Ipw_InitInstances(const Gpt_ConfigType * configPtr)
  282. {
  283. uint8 index = 0U;
  284. for(index = 0; index < configPtr->instanceCount; index++)
  285. {
  286. switch((*(configPtr->Gpt_Ipw_HwInstanceConfig))[index].instanceType)
  287. {
  288. #if (FTM_GPT_IP_USED == STD_ON)
  289. case(GPT_FTM_MODULE):
  290. {
  291. Ftm_Gpt_Ip_Init((*(configPtr->Gpt_Ipw_HwInstanceConfig))[index].instance,
  292. (*(configPtr->Gpt_Ipw_HwInstanceConfig))[index].Gpt_Ipw_InstanceConfig.Ftm_Gpt_Ip_InstanceConfig);
  293. }
  294. break;
  295. #endif
  296. #if (SRTC_IP_USED == STD_ON)
  297. case(GPT_SRTC_MODULE):
  298. {
  299. /*Srtc is empty because it shall not be executed for InitInstances */
  300. }
  301. break;
  302. #endif
  303. #if (LPTMR_GPT_IP_USED == STD_ON)
  304. case(GPT_LPTMR_MODULE):
  305. {
  306. /*LPtimer is empty because it shall not be executed for InitInstances */
  307. }
  308. break;
  309. #endif
  310. #if (LPIT_GPT_IP_USED == STD_ON)
  311. case(GPT_LPIT_MODULE):
  312. {
  313. Lpit_Gpt_Ip_Init((*(configPtr->Gpt_Ipw_HwInstanceConfig))[index].instance,
  314. (*(configPtr->Gpt_Ipw_HwInstanceConfig))[index].Gpt_Ipw_InstanceConfig.Lpit_Gpt_Ip_InstanceConfig);
  315. }
  316. break;
  317. #endif
  318. default:
  319. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  320. break;
  321. }
  322. }
  323. return;
  324. }
  325. /**
  326. * @brief Gpt driver Autosar independent and IP dependent initialization function.
  327. * @details This function Gpt_Ipw_Init is called once for each channel in the used configuration.
  328. * It determines the type of the HW channel and calls the
  329. * appropriate IP function in order to initializes the hardware timer.
  330. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  331. * @return void
  332. * @pre The driver needs to be initialized.
  333. */
  334. void Gpt_Ipw_Init(const Gpt_Ipw_HwChannelConfigType *pHwChannelConfig)
  335. {
  336. switch(pHwChannelConfig->instanceType)
  337. {
  338. #if (FTM_GPT_IP_USED == STD_ON)
  339. case(GPT_FTM_MODULE):
  340. {
  341. Ftm_Gpt_Ip_InitChannel(pHwChannelConfig->instance,
  342. pHwChannelConfig->Gpt_Ipw_ChannelConfig.Ftm_Gpt_Ip_ChannelConfig);
  343. }
  344. break;
  345. #endif
  346. #if (SRTC_IP_USED == STD_ON)
  347. case(GPT_SRTC_MODULE):
  348. {
  349. Srtc_Ip_Init(pHwChannelConfig->instance,
  350. pHwChannelConfig->Gpt_Ipw_ChannelConfig.Srtc_Ip_ChannelConfig);
  351. }
  352. break;
  353. #endif
  354. #if (LPTMR_GPT_IP_USED == STD_ON)
  355. case(GPT_LPTMR_MODULE):
  356. {
  357. Lptmr_Gpt_Ip_Init(pHwChannelConfig->instance,
  358. pHwChannelConfig->Gpt_Ipw_ChannelConfig.Lptmr_Gpt_Ip_ChannelConfig);
  359. }
  360. break;
  361. #endif
  362. #if (LPIT_GPT_IP_USED == STD_ON)
  363. case(GPT_LPIT_MODULE):
  364. {
  365. Lpit_Gpt_Ip_InitChannel(pHwChannelConfig->instance,
  366. pHwChannelConfig->Gpt_Ipw_ChannelConfig.Lpit_Gpt_Ip_ChannelConfig);
  367. }
  368. break;
  369. #endif
  370. default:
  371. /* This switch branch is empty because it shall not be executed for normal behaviour */
  372. break;
  373. }
  374. return;
  375. }
  376. /*================================================================================================*/
  377. /**
  378. * @brief Gpt driver Autosar independent and platform dependent function for starting the timer channel.
  379. * @details It checks the type of the HW module and calls the appropriate
  380. * IP function for starting the timer channel.
  381. *
  382. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  383. * @param[in] uValue Timeout period (in ticks) after which a notification shall occur (if enabled).
  384. * @return void
  385. * @pre The driver needs to be initialized.Call Gpt_StartTimer before.
  386. */
  387. Std_ReturnType Gpt_Ipw_StartTimer(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig, Gpt_ValueType uValue)
  388. {
  389. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  390. switch(pHwChannelConfig->instanceType)
  391. {
  392. #if (FTM_GPT_IP_USED == STD_ON)
  393. case(GPT_FTM_MODULE):
  394. {
  395. Ftm_Gpt_Ip_StartCounting(pHwChannelConfig->instance,
  396. pHwChannelConfig->channel,
  397. (uint16)uValue);
  398. returnValue = (Std_ReturnType)E_OK;
  399. }
  400. break;
  401. #endif
  402. #if (SRTC_IP_USED == STD_ON)
  403. case(GPT_SRTC_MODULE):
  404. {
  405. Srtc_Ip_StartTimer(pHwChannelConfig->instance,
  406. uValue);
  407. returnValue = (Std_ReturnType)E_OK;
  408. }
  409. break;
  410. #endif
  411. #if (LPTMR_GPT_IP_USED == STD_ON)
  412. case(GPT_LPTMR_MODULE):
  413. {
  414. Lptmr_Gpt_Ip_StartTimer(pHwChannelConfig->instance,
  415. (uint16)uValue);
  416. returnValue = (Std_ReturnType)E_OK;
  417. }
  418. break;
  419. #endif
  420. #if (LPIT_GPT_IP_USED == STD_ON)
  421. case(GPT_LPIT_MODULE):
  422. {
  423. Lpit_Gpt_Ip_StartTimer(pHwChannelConfig->instance,
  424. pHwChannelConfig->channel,
  425. uValue);
  426. returnValue = (Std_ReturnType)E_OK;
  427. }
  428. break;
  429. #endif
  430. default:
  431. /*This switch branch is empty because it shall not be executed for normal behaviour */
  432. break;
  433. }
  434. return returnValue;
  435. }
  436. /*================================================================================================*/
  437. /**
  438. * @brief Gpt driver Autosar independent and IP dependent function for fetching the elapsed timer value.
  439. * @details It determines the type of the HW channel and calls the
  440. * appropriate IP function for reading the elapsed timer value from the HW.
  441. *
  442. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  443. * @param[in] uTargetTime Target time value
  444. * @param[out] pbReturnChannelOverflow Rollover status flag value of the hardware timer channel
  445. * @return returnValue The elapsed time
  446. * @pre The driver needs to be initialized.Call GetTimeElapsed before.
  447. *
  448. */
  449. Gpt_ValueType Gpt_Ipw_GetTimeElapsed(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig,
  450. Gpt_HwChannelInfoType * pReturnHwChannelInfo)
  451. {
  452. uint32 returnValue = 0U;
  453. switch(pHwChannelConfig->instanceType)
  454. {
  455. #if (FTM_GPT_IP_USED == STD_ON)
  456. case(GPT_FTM_MODULE):
  457. {
  458. returnValue = Gpt_Ipw_FtmGetTimeElapsed(pHwChannelConfig, pReturnHwChannelInfo);
  459. }
  460. break;
  461. #endif
  462. #if (SRTC_IP_USED == STD_ON)
  463. case(GPT_SRTC_MODULE):
  464. {
  465. returnValue = Gpt_Ipw_SrtcGetTimeElapsed(pHwChannelConfig, pReturnHwChannelInfo);
  466. }
  467. break;
  468. #endif
  469. #if (LPTMR_GPT_IP_USED == STD_ON)
  470. case(GPT_LPTMR_MODULE):
  471. {
  472. returnValue = Gpt_Ipw_LptmrGetTimeElapsed(pHwChannelConfig, pReturnHwChannelInfo);
  473. }
  474. break;
  475. #endif
  476. #if (LPIT_GPT_IP_USED == STD_ON)
  477. case(GPT_LPIT_MODULE):
  478. {
  479. returnValue = Gpt_Ipw_LpitGetTimeElapsed(pHwChannelConfig, pReturnHwChannelInfo);
  480. }
  481. break;
  482. #endif
  483. default:
  484. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  485. break;
  486. }
  487. return((Gpt_ValueType)returnValue);
  488. }
  489. /*================================================================================================*/
  490. /**
  491. * @brief Gpt driver Autosar independent and platform dependent function for stopping the timer channel.
  492. * @details It checks the type of the HW module and calls the appropriate
  493. * IP function for stopping the timer channel.
  494. *
  495. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  496. * @return void
  497. * @pre The driver needs to be initialized.Call StopTimer before.
  498. */
  499. void Gpt_Ipw_StopTimer(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig)
  500. {
  501. switch(pHwChannelConfig->instanceType)
  502. {
  503. #if (FTM_GPT_IP_USED == STD_ON)
  504. case(GPT_FTM_MODULE):
  505. {
  506. Ftm_Gpt_Ip_DisableChannelInterrupt(pHwChannelConfig->instance,
  507. pHwChannelConfig->channel);
  508. }
  509. break;
  510. #endif
  511. #if (SRTC_IP_USED == STD_ON)
  512. case(GPT_SRTC_MODULE):
  513. {
  514. /* Stop counter */
  515. (void)Srtc_Ip_StopCounter(pHwChannelConfig->instance);
  516. }
  517. break;
  518. #endif
  519. #if (LPTMR_GPT_IP_USED == STD_ON)
  520. case(GPT_LPTMR_MODULE):
  521. {
  522. Lptmr_Gpt_Ip_StopTimer(pHwChannelConfig->instance);
  523. }
  524. break;
  525. #endif
  526. #if (LPIT_GPT_IP_USED == STD_ON)
  527. case(GPT_LPIT_MODULE):
  528. {
  529. Lpit_Gpt_Ip_StopTimer(pHwChannelConfig->instance,
  530. pHwChannelConfig->channel);
  531. }
  532. break;
  533. #endif
  534. default:
  535. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  536. break;
  537. }
  538. return;
  539. }
  540. /*================================================================================================*/
  541. /**
  542. * @brief Gpt driver Autosar independent and platform dependent function for enabling hardware timer interrupts.
  543. * @details It checks the type of the HW module and calls the appropriate
  544. * IP function for enabling hardware timer interrupts.
  545. *
  546. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  547. * @return void
  548. * @pre The driver needs to be initialized.
  549. */
  550. void Gpt_Ipw_EnableInterrupt(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig)
  551. {
  552. switch(pHwChannelConfig->instanceType)
  553. {
  554. #if (FTM_GPT_IP_USED == STD_ON)
  555. case(GPT_FTM_MODULE):
  556. {
  557. /* For a FTM enabled channel the interrupts are always activated */
  558. }
  559. break;
  560. #endif
  561. #if (SRTC_IP_USED == STD_ON)
  562. case(GPT_SRTC_MODULE):
  563. {
  564. Srtc_Ip_EnableInterrupt(pHwChannelConfig->instance, SRTC_IP_ALARM_INTERRUPT);
  565. }
  566. break;
  567. #endif
  568. #if (LPTMR_GPT_IP_USED == STD_ON)
  569. case(GPT_LPTMR_MODULE):
  570. {
  571. Lptmr_Gpt_Ip_EnableInterrupt(pHwChannelConfig->instance);
  572. }
  573. break;
  574. #endif
  575. #if (LPIT_GPT_IP_USED == STD_ON)
  576. case(GPT_LPIT_MODULE):
  577. {
  578. Lpit_Gpt_Ip_EnableChInterrupt(pHwChannelConfig->instance, pHwChannelConfig->channel);
  579. }
  580. break;
  581. #endif
  582. default:
  583. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  584. break;
  585. }
  586. return;
  587. }
  588. /*================================================================================================*/
  589. #if (GPT_DEINIT_API == STD_ON)
  590. /**
  591. * @brief Gpt driver Autosar independent and IP dependent de-initialization function.
  592. * @details This function is called for each channel from the current configuration.
  593. * It determines the type of the HW channel and calls the
  594. * appropriate IP function in order to de-initializes the hardware timer.
  595. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  596. * @return void
  597. * @pre The driver needs to be initialized. On/Off by the configuration parameter: GPT_DEINIT_API
  598. */
  599. void Gpt_Ipw_DeInit(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig)
  600. {
  601. switch(pHwChannelConfig->instanceType)
  602. {
  603. #if (FTM_GPT_IP_USED == STD_ON)
  604. case(GPT_FTM_MODULE):
  605. {
  606. Ftm_Gpt_Ip_Deinit(pHwChannelConfig->instance);
  607. }
  608. break;
  609. #endif
  610. #if (SRTC_IP_USED == STD_ON)
  611. case(GPT_SRTC_MODULE):
  612. {
  613. Srtc_Ip_DeInit(pHwChannelConfig->instance);
  614. }
  615. break;
  616. #endif
  617. #if (LPTMR_GPT_IP_USED == STD_ON)
  618. case(GPT_LPTMR_MODULE):
  619. {
  620. Lptmr_Gpt_Ip_DeInit(pHwChannelConfig->instance);
  621. }
  622. break;
  623. #endif
  624. #if (LPIT_GPT_IP_USED == STD_ON)
  625. case(GPT_LPIT_MODULE):
  626. {
  627. Lpit_Gpt_Ip_Deinit(pHwChannelConfig->instance);
  628. }
  629. break;
  630. #endif
  631. default:
  632. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  633. break;
  634. }
  635. return;
  636. }
  637. #endif
  638. /*================================================================================================*/
  639. #if ((GPT_ENABLE_DISABLE_NOTIFICATION_API == STD_ON) || (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON))
  640. /**
  641. * @brief Gpt driver Autosar independent and platform dependent function for disabling hardware timer interrupts.
  642. * @details It checks the type of the HW module and calls the appropriate
  643. * IP function for disabling hardware timer interrupts.
  644. *
  645. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  646. * @return void
  647. * @pre The driver needs to be initialized.On/Off by the configuration parameter: GPT_ENABLE_DISABLE_NOTIFICATION_API
  648. */
  649. void Gpt_Ipw_DisableInterrupt(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig)
  650. {
  651. switch(pHwChannelConfig->instanceType)
  652. {
  653. #if (FTM_GPT_IP_USED == STD_ON)
  654. case(GPT_FTM_MODULE):
  655. {
  656. /* For a FTM enabled channel the interrupts are always activated */
  657. }
  658. break;
  659. #endif
  660. #if (SRTC_IP_USED == STD_ON)
  661. case(GPT_SRTC_MODULE):
  662. {
  663. Srtc_Ip_DisableInterrupt(pHwChannelConfig->instance, SRTC_IP_ALARM_INTERRUPT);
  664. }
  665. break;
  666. #endif
  667. #if (LPTMR_GPT_IP_USED == STD_ON)
  668. case(GPT_LPTMR_MODULE):
  669. {
  670. Lptmr_Gpt_Ip_DisableInterrupt(pHwChannelConfig->instance);
  671. }
  672. break;
  673. #endif
  674. #if (LPIT_GPT_IP_USED == STD_ON)
  675. case(GPT_LPIT_MODULE):
  676. {
  677. Lpit_Gpt_Ip_DisableChInterrupt(pHwChannelConfig->instance, pHwChannelConfig->channel);
  678. }
  679. break;
  680. #endif
  681. default:
  682. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  683. break;
  684. }
  685. return;
  686. }
  687. #endif
  688. /*================================================================================================*/
  689. #if (GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON)
  690. /**
  691. * @brief Gpt driver Autosar independent and IP dependent function to change compare register value.
  692. * @details This function:
  693. * - Write next timeout to local variable
  694. *
  695. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent
  696. * by platform
  697. * @param[in] value New Timeout period (in ticks) after which a notification
  698. * shall occur (if enabled).
  699. * @return void
  700. * @pre The driver needs to be initialized.On/Off by the configuration parameter: GPT_CHANGE_NEXT_TIMEOUT_VALUE
  701. *
  702. */
  703. Std_ReturnType Gpt_Ipw_ChangeNextTimeoutValue(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig,
  704. Gpt_ValueType value)
  705. {
  706. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  707. switch(pHwChannelConfig->instanceType)
  708. {
  709. #if (FTM_GPT_IP_USED == STD_ON)
  710. case (GPT_FTM_MODULE):
  711. {
  712. Ftm_Gpt_Ip_ChangeNextTimeoutValue( pHwChannelConfig->instance,
  713. pHwChannelConfig->channel, (uint16)value);
  714. returnValue =(Std_ReturnType)E_OK;
  715. }
  716. break;
  717. #endif
  718. default:
  719. /*This switch branch is empty because it shall not be executed for normal behaviour */
  720. break;
  721. }
  722. return returnValue;
  723. }
  724. #endif /* GPT_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON */
  725. /*================================================================================================*/
  726. /**
  727. * @brief Gpt driver Autosar independent and IP dependent function to change eMios compare register value.
  728. * @details Calls the eMios function to change the eMios compare register value at the next match.
  729. *
  730. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  731. * @param[in] clkMode Clock mode for configuration channel
  732. *
  733. * @return void
  734. * @pre The driver needs to be initialized.On/Off by the configuration parameter: GPT_SET_CLOCK_MODE
  735. */
  736. #if (GPT_SET_CLOCK_MODE == STD_ON)
  737. void Gpt_Ipw_SetClockModeInStance(const Gpt_Ipw_HwInstanceConfigType * pHwInstanceConfig,
  738. Gpt_ClockModeType clkMode)
  739. {
  740. switch(pHwInstanceConfig->instanceType)
  741. {
  742. #if (FTM_GPT_IP_USED == STD_ON)
  743. case (GPT_FTM_MODULE):
  744. {
  745. if(GPT_CLOCKMODE_NORMAL == clkMode)
  746. {
  747. Ftm_Gpt_Ip_SetClockMode(pHwInstanceConfig->instance, FTM_GPT_IP_CLOCKMODE_NORMAL);
  748. }
  749. else
  750. {
  751. Ftm_Gpt_Ip_SetClockMode(pHwInstanceConfig->instance, FTM_GPT_IP_CLOCKMODE_ALTERNATE);
  752. }
  753. }
  754. break;
  755. #endif
  756. #if (LPTMR_GPT_IP_USED == STD_ON)
  757. case (GPT_LPTMR_MODULE):
  758. {
  759. if(GPT_CLOCKMODE_NORMAL == clkMode)
  760. {
  761. Lptmr_Gpt_Ip_SetClockMode(pHwInstanceConfig->instance, LPTMR_GPT_IP_CLOCKMODE_NORMAL);
  762. }
  763. else
  764. {
  765. Lptmr_Gpt_Ip_SetClockMode(pHwInstanceConfig->instance, LPTMR_GPT_IP_CLOCKMODE_ALTERNATE);
  766. }
  767. }
  768. break;
  769. #endif
  770. default:
  771. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  772. break;
  773. }
  774. }
  775. #endif /* GPT_SET_CLOCK_MODE == STD_ON */
  776. /*================================================================================================*/
  777. #if(GPT_CHAIN_MODE == STD_ON)
  778. /**
  779. * @brief The function Gpt_Ipw_EnableChainMode.
  780. * @details This function:
  781. * - Chain the timer.
  782. *
  783. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  784. * @return returnValue
  785. * @pre The driver needs to be initialized. CHAIN_MODE == STD_ON
  786. */
  787. Std_ReturnType Gpt_Ipw_EnableChainMode(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig)
  788. {
  789. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  790. switch(pHwChannelConfig->instanceType)
  791. {
  792. #if (LPIT_GPT_IP_USED == STD_ON)
  793. case (GPT_LPIT_MODULE):
  794. {
  795. returnValue = (Std_ReturnType)Lpit_Gpt_Ip_ChainMode(pHwChannelConfig->instance, pHwChannelConfig->channel, TRUE);
  796. }
  797. break;
  798. #endif
  799. default:
  800. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  801. break;
  802. }
  803. return returnValue;
  804. }
  805. #endif /*(GPT_CHAIN_MODE == STD_ON)*/
  806. /*================================================================================================*/
  807. #if(GPT_CHAIN_MODE == STD_ON)
  808. /**
  809. * @brief The function Gpt_Ipw_DisableChainMode.
  810. * @details This function:
  811. * - Chain the timer.
  812. *
  813. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  814. * @return returnValue
  815. * @pre The driver needs to be initialized. CHAIN_MODE == STD_ON
  816. */
  817. Std_ReturnType Gpt_Ipw_DisableChainMode(const Gpt_Ipw_HwChannelConfigType * pHwChannelConfig)
  818. {
  819. Std_ReturnType returnValue = (Std_ReturnType)E_NOT_OK;
  820. switch(pHwChannelConfig->instanceType)
  821. {
  822. #if (LPIT_GPT_IP_USED == STD_ON)
  823. case (GPT_LPIT_MODULE):
  824. {
  825. returnValue = (Std_ReturnType)Lpit_Gpt_Ip_ChainMode(pHwChannelConfig->instance, pHwChannelConfig->channel, FALSE);
  826. }
  827. break;
  828. #endif
  829. default:
  830. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  831. break;
  832. }
  833. return returnValue;
  834. }
  835. #endif /*(GPT_CHAIN_MODE == STD_ON)*/
  836. /*================================================================================================*/
  837. #if(GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON)
  838. /**
  839. * @brief Gpt driver Autosar start predeftimer hw.
  840. * @details This function to start channel, which using predeftimer feature in the used configuration.
  841. * It determines the type of the HW channel and calls the
  842. * appropriate IP function in order to initializes the hardware timer.
  843. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  844. * @return void
  845. * @pre The driver needs to be initialized. On/Off GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON
  846. */
  847. void Gpt_Ipw_StartPredefTimer
  848. (
  849. const Gpt_ConfigType * configPtr
  850. )
  851. {
  852. Gpt_ChannelType channel;
  853. const Gpt_HwPredefChannelConfigType * pHwChannelConfig;
  854. for(channel = 0U; channel < GPT_HW_PREDEFTIMER_NUM; channel++)
  855. {
  856. pHwChannelConfig = (configPtr->Gpt_pChannelPredefConfigType)[channel];
  857. if(NULL_PTR != pHwChannelConfig)
  858. {
  859. switch(pHwChannelConfig->instanceType)
  860. {
  861. #if (FTM_GPT_IP_USED == STD_ON)
  862. case GPT_FTM_MODULE:
  863. {
  864. Ftm_Gpt_Ip_StartPredefTimer(pHwChannelConfig->instance, \
  865. pHwChannelConfig->channel, \
  866. pHwChannelConfig->Gpt_uPrescaler, \
  867. pHwChannelConfig->Gpt_uClockSource, \
  868. pHwChannelConfig->Gpt_bFreezeEnable);
  869. }
  870. break;
  871. #endif
  872. default:
  873. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  874. break;
  875. }
  876. }
  877. }
  878. return;
  879. }
  880. /**
  881. * @brief Gpt driver Autosar get value of predeftimer hw.
  882. * @details This function to start channel, which using predeftimer feature in the used configuration.
  883. * It determines the type of the HW channel and calls the
  884. * appropriate IP function in order to initializes the hardware timer.
  885. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  886. * @param[in] TimeValuePtr The pointer using for save current value of hardware channel
  887. * @param[in] PredefTimer Gpt_PredefTimerType
  888. * @return void
  889. * @pre The driver needs to be initialized. On/Off GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON
  890. */
  891. void Gpt_Ipw_GetPredefTimerValue
  892. (
  893. const Gpt_HwPredefChannelConfigType * pHwChannelConfig,
  894. Gpt_PredefTimerType PredefTimer,
  895. uint32 * TimeValuePtr
  896. )
  897. {
  898. uint32 u32ReturnValue = 0U;
  899. switch(pHwChannelConfig->instanceType)
  900. {
  901. #if (FTM_GPT_IP_USED == STD_ON)
  902. case GPT_FTM_MODULE:
  903. {
  904. u32ReturnValue = Ftm_Gpt_Ip_GetCounter(pHwChannelConfig->instance);
  905. }
  906. break;
  907. #endif
  908. default:
  909. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  910. break;
  911. }
  912. if(0U != u32ReturnValue)
  913. {
  914. switch(PredefTimer)
  915. {
  916. case GPT_PREDEF_TIMER_1US_16BIT:
  917. *TimeValuePtr = (0x0000FFFFU & u32ReturnValue);
  918. break;
  919. case GPT_PREDEF_TIMER_1US_24BIT:
  920. *TimeValuePtr = (0x00FFFFFFU & u32ReturnValue);
  921. break;
  922. case GPT_PREDEF_TIMER_1US_32BIT:
  923. *TimeValuePtr = u32ReturnValue;
  924. break;
  925. case GPT_PREDEF_TIMER_100US_32BIT:
  926. *TimeValuePtr = u32ReturnValue;
  927. break;
  928. default:
  929. /* 32bit timer */
  930. break;
  931. }
  932. }
  933. return;
  934. }
  935. /**
  936. * @brief Gpt driver Autosar stop predeftimer hw.
  937. * @details This function to start channel, which using predeftimer feature in the used configuration.
  938. * It determines the type of the HW channel and calls the
  939. * appropriate IP function in order to initializes the hardware timer.
  940. * @param[in] pHwChannelConfig Pointer to the channel configuration structure dependent by platform
  941. * @return void
  942. * @pre The driver needs to be initialized. GPT_PREDEFTIMER_FUNCTIONALITY_API == STD_ON
  943. */
  944. void Gpt_Ipw_StopPredefTimer
  945. (
  946. const Gpt_ConfigType * configPtr
  947. )
  948. {
  949. Gpt_ChannelType channel;
  950. const Gpt_HwPredefChannelConfigType * pHwChannelConfig;
  951. for(channel = 0U; channel < GPT_HW_PREDEFTIMER_NUM; channel++)
  952. {
  953. pHwChannelConfig = (configPtr->Gpt_pChannelPredefConfigType)[channel];
  954. if(NULL_PTR != pHwChannelConfig)
  955. {
  956. switch(pHwChannelConfig->instanceType)
  957. {
  958. #if (FTM_GPT_IP_USED == STD_ON)
  959. case GPT_FTM_MODULE:
  960. {
  961. Ftm_Gpt_Ip_StopPredefTimer(pHwChannelConfig->instance, \
  962. pHwChannelConfig->channel);
  963. }
  964. break;
  965. #endif
  966. default:
  967. /*This switch branch is empty because it shall not be executed for normal behaviour*/
  968. break;
  969. }
  970. }
  971. }
  972. return;
  973. }
  974. #endif
  975. #define GPT_STOP_SEC_CODE
  976. #include "Gpt_MemMap.h"
  977. #ifdef __cplusplus
  978. }
  979. /** @} */
  980. #endif/*GPT_IPW_C*/