Lpit_Icu_Ip_Irq.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : Ftm Lpit Lptmr Port_Ci LpCmp
  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 File with source code used to implement ICU driver interrupts on LPIT module.
  26. * @details This file contains the source code for all interrupt functions which are using
  27. * LPIT module.
  28. * @addtogroup lpit_icu_ip LPIT IPL
  29. * @{
  30. */
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  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 "Lpit_Icu_Ip.h"
  42. #include "Lpit_Icu_Ip_Irq.h"
  43. #if(LPIT_ICU_IP_DEV_ERROR_DETECT == STD_ON)
  44. #include "Devassert.h"
  45. #endif
  46. #include "Mcal.h"
  47. /*==================================================================================================
  48. * SOURCE FILE VERSION INFORMATION
  49. ==================================================================================================*/
  50. #define LPIT_ICU_IP_IRQ_VENDOR_ID_C 43
  51. #define LPIT_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C 4
  52. #define LPIT_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C 4
  53. #define LPIT_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C 0
  54. #define LPIT_ICU_IP_IRQ_SW_MAJOR_VERSION_C 1
  55. #define LPIT_ICU_IP_IRQ_SW_MINOR_VERSION_C 0
  56. #define LPIT_ICU_IP_IRQ_SW_PATCH_VERSION_C 0
  57. /*==================================================================================================
  58. * FILE VERSION CHECKS
  59. ==================================================================================================*/
  60. /* Check if source file and Lpit_Icu_Ip.h header file are of the same vendor */
  61. #if (LPIT_ICU_IP_IRQ_VENDOR_ID_C != LPIT_ICU_IP_VENDOR_ID)
  62. #error "Lpit_Icu_Ip_Irq.c and Lpit_Icu_Ip.h have different vendor IDs"
  63. #endif
  64. /* Check if source file and Lpit_Icu_Ip.h header file are of the same AutoSar version */
  65. #if ((LPIT_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != LPIT_ICU_IP_AR_RELEASE_MAJOR_VERSION) || \
  66. (LPIT_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != LPIT_ICU_IP_AR_RELEASE_MINOR_VERSION) || \
  67. (LPIT_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C != LPIT_ICU_IP_AR_RELEASE_REVISION_VERSION))
  68. #error "AutoSar Version Numbers of Lpit_Icu_Ip_Irq.c and Lpit_Icu_Ip.h are different"
  69. #endif
  70. /* Check if source file and Lpit_Icu_Ip.h header file are of the same Software version */
  71. #if ((LPIT_ICU_IP_IRQ_SW_MAJOR_VERSION_C != LPIT_ICU_IP_SW_MAJOR_VERSION) || \
  72. (LPIT_ICU_IP_IRQ_SW_MINOR_VERSION_C != LPIT_ICU_IP_SW_MINOR_VERSION) || \
  73. (LPIT_ICU_IP_IRQ_SW_PATCH_VERSION_C != LPIT_ICU_IP_SW_PATCH_VERSION))
  74. #error "Software Version Numbers of Lpit_Icu_Ip_Irq.c and Lpit_Icu_Ip.h are different"
  75. #endif
  76. /* Check if source file and Lpit_Icu_Ip_Irq.h header file are of the same vendor */
  77. #if (LPIT_ICU_IP_IRQ_VENDOR_ID_C != LPIT_ICU_IP_IRQ_VENDOR_ID)
  78. #error "Lpit_Icu_Ip_Irq.c and Lpit_Icu_Ip_Irq.h have different vendor IDs"
  79. #endif
  80. /* Check if source file and Lpit_Icu_Ip_Irq.h header file are of the same AutoSar version */
  81. #if ((LPIT_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != LPIT_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION) || \
  82. (LPIT_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != LPIT_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION) || \
  83. (LPIT_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C != LPIT_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION))
  84. #error "AutoSar Version Numbers of Lpit_Icu_Ip_Irq.c and Lpit_Icu_Ip_Irq.h are different"
  85. #endif
  86. /* Check if source file and Lpit_Icu_Ip_Irq.h header file are of the same Software version */
  87. #if ((LPIT_ICU_IP_IRQ_SW_MAJOR_VERSION_C != LPIT_ICU_IP_IRQ_SW_MAJOR_VERSION) || \
  88. (LPIT_ICU_IP_IRQ_SW_MINOR_VERSION_C != LPIT_ICU_IP_IRQ_SW_MINOR_VERSION) || \
  89. (LPIT_ICU_IP_IRQ_SW_PATCH_VERSION_C != LPIT_ICU_IP_IRQ_SW_PATCH_VERSION))
  90. #error "Software Version Numbers of Lpit_Icu_Ip_Irq.c and Lpit_Icu_Ip_Irq.h are different"
  91. #endif
  92. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  93. #if(LPIT_ICU_IP_DEV_ERROR_DETECT == STD_ON)
  94. /* Check if source file and Devassert.h file are of the same Autosar version */
  95. #if ((LPIT_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  96. (LPIT_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION))
  97. #error "AutoSar Version Numbers of Lpit_Icu_Ip.h and Devassert.h are different"
  98. #endif
  99. #endif
  100. #endif
  101. /*==================================================================================================
  102. * LOCAL FUNCTION PROTOTYPES
  103. ==================================================================================================*/
  104. #define ICU_START_SEC_CODE
  105. #include "Icu_MemMap.h"
  106. #if ((defined LPIT_ICU_0_CH_0_ISR_USED) || (defined LPIT_ICU_0_CH_1_ISR_USED) || (defined LPIT_ICU_0_CH_2_ISR_USED) || (defined LPIT_ICU_0_CH_3_ISR_USED) || (defined LPIT_ICU_0_ISR_USED))
  107. #if (STD_ON == LPIT_ICU_TIMESTAMP_API)
  108. /**
  109. * @brief
  110. *
  111. * @param channel
  112. * @param instance
  113. * @internal
  114. */
  115. static void Lpit_Icu_Ip_TimestampHandler(uint8 instance, uint8 channel);
  116. #endif /* STD_ON == LPIT_ICU_TIMESTAMP_API */
  117. /**
  118. * @brief LPIT IP function that handles the interrupt of a LPIT channel for ICU driver.
  119. * @details This function:
  120. * - Reads the status register
  121. * - Clears the pending interrupt
  122. * - Processes interrupt for corresponding LPIT channel
  123. *
  124. * @param[in] instance LPIT hardware module
  125. * @param[in] channel LPIT hardware channel
  126. */
  127. static inline void Lpit_Icu_Ip_IrqHandler(uint8 instance, uint8 channel);
  128. #if (STD_ON == LPIT_ICU_EDGE_DETECT_API)
  129. /**
  130. * @brief
  131. *
  132. * @param instance
  133. * @param hwChannel
  134. */
  135. static inline void Lpit_Icu_Ip_ReportEvents(uint8 instance, uint8 hwChannel);
  136. #endif /* STD_ON == LPIT_ICU_EDGE_DETECT_API */
  137. #endif /* ISRs USED defines */
  138. /*==================================================================================================
  139. * LOCAL FUNCTIONS
  140. ==================================================================================================*/
  141. #if ((defined LPIT_ICU_0_CH_0_ISR_USED) || (defined LPIT_ICU_0_CH_1_ISR_USED) || (defined LPIT_ICU_0_CH_2_ISR_USED) || (defined LPIT_ICU_0_CH_3_ISR_USED) || (defined LPIT_ICU_0_ISR_USED))
  142. #if (STD_ON == LPIT_ICU_TIMESTAMP_API)
  143. static void Lpit_Icu_Ip_TimestampHandler(uint8 instance,
  144. uint8 channel)
  145. {
  146. uint16 chBufferSize;
  147. uint16 chBufferNotify;
  148. chBufferSize = timestampState[instance][channel].bufferSize;
  149. chBufferNotify = timestampState[instance][channel].notifyInterval;
  150. timestampState[instance][channel].bufferPtr[timestampState[instance][channel].bufferIndex] = (uint16)lpitBase[instance]->TMR[channel].CVAL;
  151. timestampState[instance][channel].bufferIndex++;
  152. if (timestampState[instance][channel].bufferIndex >= chBufferSize)
  153. {
  154. /* If circular buffer, loop; if linear buffer, terminate. */
  155. if (LPIT_ICU_IP_CIRCULAR_BUFFER == timestampState[instance][channel].timestampBuffer)
  156. {
  157. timestampState[instance][channel].bufferIndex = 0U;
  158. }
  159. else
  160. {
  161. /* Linear buffer is full, stop the channel */
  162. Lpit_Icu_Ip_DisableDetectionMode(instance, channel);
  163. if (NULL_PTR != channelsState[instance][channel].logicChStateCallback)
  164. {
  165. channelsState[instance][channel].logicChStateCallback(channelsState[instance][channel].callbackParams, (1U << 3), FALSE);
  166. }
  167. }
  168. }
  169. if (0U != chBufferNotify)
  170. {
  171. timestampState[instance][channel].notifyCount++;
  172. if (timestampState[instance][channel].notifyCount >= chBufferNotify)
  173. {
  174. timestampState[instance][channel].notifyCount = 0U;
  175. /* Call User Notification Function */
  176. if ( (NULL_PTR != channelsState[instance][channel].lpitChannelNotify) && \
  177. ((boolean)TRUE == channelsState[instance][channel].notificationEnable))
  178. {
  179. channelsState[instance][channel].lpitChannelNotify();
  180. }
  181. }
  182. }
  183. }
  184. #endif /* STD_ON == LPIT_ICU_TIMESTAMP_API */
  185. static inline void Lpit_Icu_Ip_IrqHandler(uint8 instance, uint8 channel)
  186. {
  187. #if (STD_ON == LPIT_ICU_IP_DEV_ERROR_DETECT)
  188. DevAssert(instance < LPIT_INSTANCE_COUNT);
  189. DevAssert(channel < LPIT_TMR_COUNT);
  190. #endif
  191. boolean channelStatusFlags = FALSE;
  192. Lpit_Icu_Ip_MeasurementMode measMode = channelsState[instance][channel].measurementMode;
  193. /* Interrupt status: enable/disable. */
  194. channelStatusFlags = ((((lpitBase[instance]->MIER & ((uint32)(LPIT_MIER_TIE_START_MASK << (uint32)channel))) != 0U) &&
  195. ((lpitBase[instance]->MSR & ((uint32)(LPIT_MSR_TIF_START_MASK << (uint32)channel))) != 0U)) ?
  196. TRUE : FALSE);
  197. /* Clear pending interrupt serviced. */
  198. lpitBase[instance]->MSR |= (uint32)(LPIT_MSR_TIF_START_MASK << (uint32)channel);
  199. if (LPIT_ICU_MODE_NO_MEASUREMENT != measMode)
  200. {
  201. if (TRUE == channelStatusFlags)
  202. {
  203. switch (measMode)
  204. {
  205. #if (STD_ON == LPIT_ICU_TIMESTAMP_API)
  206. case LPIT_ICU_MODE_TIMESTAMP:
  207. {
  208. /* Copy the Counter value in the Timestamp Buffer*/
  209. /* TODO: lpit has a counter on 32bits but we are treating in the ICU driver values on 16 bits only. */
  210. /* Make the call to handler function. */
  211. Lpit_Icu_Ip_TimestampHandler(instance, channel);
  212. break;
  213. }
  214. #endif /* STD_ON == LPIT_ICU_TIMESTAMP_API */
  215. #if (STD_ON == LPIT_ICU_EDGE_DETECT_API)
  216. case LPIT_ICU_MODE_SIGNAL_EDGE_DETECT:
  217. {
  218. /* Call ReportEvents. */
  219. Lpit_Icu_Ip_ReportEvents(instance, channel);
  220. }
  221. break;
  222. #endif
  223. default:
  224. {
  225. /* Do nothing. */
  226. break;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. #if (STD_ON == LPIT_ICU_EDGE_DETECT_API)
  233. static inline void Lpit_Icu_Ip_ReportEvents(uint8 instance, uint8 hwChannel)
  234. {
  235. /* Calling HLD Report Events for the logical channel */
  236. if(channelsState[instance][hwChannel].callback != NULL_PTR)
  237. {
  238. channelsState[instance][hwChannel].callback(channelsState[instance][hwChannel].callbackParams, FALSE);
  239. }
  240. else
  241. {
  242. /* Calling Notification for the IPL channel */
  243. if ( (NULL_PTR != channelsState[instance][hwChannel].lpitChannelNotify) && \
  244. ((boolean)TRUE == channelsState[instance][hwChannel].notificationEnable))
  245. {
  246. channelsState[instance][hwChannel].lpitChannelNotify();
  247. }
  248. }
  249. }
  250. #endif /* STD_ON == LPIT_ICU_EDGE_DETECT_AP */
  251. #endif /* ISRs USED defines */
  252. /*==================================================================================================
  253. * GLOBAL FUNCTIONS
  254. ==================================================================================================*/
  255. #if (defined LPIT_ICU_0_CH_0_ISR_USED)
  256. /**
  257. * @brief LPIT IP function that handles the interrupt of a LPIT 0 channel 0 for ICU driver.
  258. */
  259. ISR(LPIT_0_CH_0_ISR)
  260. {
  261. uint8 u8LPitchannel = 0U;
  262. uint8 u8ModuleIdx = 0U;
  263. uint32 u32IsrStatus = lpitBase[u8ModuleIdx]->MSR;
  264. if ((uint8)((uint8)u32IsrStatus & (uint8)(1U << u8LPitchannel)) == (uint8)(1U << u8LPitchannel))
  265. {
  266. Lpit_Icu_Ip_IrqHandler(u8ModuleIdx, u8LPitchannel);
  267. }
  268. EXIT_INTERRUPT();
  269. }
  270. #endif
  271. #if (defined LPIT_ICU_0_CH_1_ISR_USED)
  272. /**
  273. * @brief LPIT IP function that handles the interrupt of a LPIT 0 channel 1 for ICU driver.
  274. */
  275. ISR(LPIT_0_CH_1_ISR)
  276. {
  277. uint8 u8LPitchannel = 1U;
  278. uint8 u8ModuleIdx = 0U;
  279. uint32 u32IsrStatus = lpitBase[u8ModuleIdx]->MSR;
  280. if ((uint8)((uint8)u32IsrStatus & (uint8)(1U << u8LPitchannel)) == (uint8)(1U << u8LPitchannel))
  281. {
  282. Lpit_Icu_Ip_IrqHandler(u8ModuleIdx, u8LPitchannel);
  283. }
  284. EXIT_INTERRUPT();
  285. }
  286. #endif
  287. #if (defined LPIT_ICU_0_CH_2_ISR_USED)
  288. /**
  289. * @brief LPIT IP function that handles the interrupt of a LPIT 0 channel 2 for ICU driver.
  290. */
  291. ISR(LPIT_0_CH_2_ISR)
  292. {
  293. uint8 u8LPitchannel = 2U;
  294. uint8 u8ModuleIdx = 0U;
  295. uint32 u32IsrStatus = lpitBase[u8ModuleIdx]->MSR;
  296. if ((uint8)((uint8)u32IsrStatus & (uint8)(1U << u8LPitchannel)) == (uint8)(1U << u8LPitchannel))
  297. {
  298. Lpit_Icu_Ip_IrqHandler(u8ModuleIdx, u8LPitchannel);
  299. }
  300. EXIT_INTERRUPT();
  301. }
  302. #endif
  303. #if (defined LPIT_ICU_0_CH_3_ISR_USED)
  304. /**
  305. * @brief LPIT IP function that handles the interrupt of a LPIT 0 channel 3 for ICU driver.
  306. */
  307. ISR(LPIT_0_CH_3_ISR)
  308. {
  309. uint8 u8LPitchannel = 3U;
  310. uint8 u8ModuleIdx = 0U;
  311. uint32 u32IsrStatus = lpitBase[u8ModuleIdx]->MSR;
  312. if ((uint8)((uint8)u32IsrStatus & (uint8)(1U << u8LPitchannel)) == (uint8)(1U << u8LPitchannel))
  313. {
  314. Lpit_Icu_Ip_IrqHandler(u8ModuleIdx, u8LPitchannel);
  315. }
  316. EXIT_INTERRUPT();
  317. }
  318. #endif
  319. #if (defined LPIT_ICU_0_ISR_USED)
  320. /**
  321. * @brief LPIT IP function that handles the interrupt of a LPIT 0.
  322. */
  323. ISR(LPIT_0_ISR)
  324. {
  325. uint8 u8LPitchannel = 0U;
  326. uint8 u8ModuleIdx = 0U;
  327. uint32 u32IsrStatus = lpitBase[u8ModuleIdx]->MSR;
  328. for (u8LPitchannel = 0U; u8LPitchannel < LPIT_TMR_COUNT; u8LPitchannel++)
  329. {
  330. if ((uint8)((uint8)u32IsrStatus & (uint8)(1U << u8LPitchannel)) == (uint8)(1U << u8LPitchannel))
  331. {
  332. Lpit_Icu_Ip_IrqHandler(u8ModuleIdx, u8LPitchannel);
  333. }
  334. }
  335. EXIT_INTERRUPT();
  336. }
  337. #endif
  338. #define ICU_STOP_SEC_CODE
  339. #include "Icu_MemMap.h"
  340. #ifdef __cplusplus
  341. }
  342. #endif
  343. /** @} */