1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  *     @file       File with source code used to implement ICU driver functionality on EMIOS module.
9  *     @details    This file contains the source code for all functions which are using EMIOS module.
10  *     @addtogroup emios_icu_ip EMIOS IPL
11  *     @{
12  */
13 
14 #ifdef __cplusplus
15 extern "C"{
16 #endif
17 
18 /*==================================================================================================
19 *                                         INCLUDE FILES
20 * 1) system and project includes
21 * 2) needed interfaces from external units
22 * 3) internal and external interfaces from this unit
23 ==================================================================================================*/
24 #include "Emios_Icu_Ip.h"
25 #include "Emios_Icu_Ip_Irq.h"
26 #include "SchM_Icu.h"
27 
28 #if (STD_ON == EMIOS_ICU_IP_USED)
29     #if (EMIOS_ICU_IP_DEV_ERROR_DETECT == STD_ON)
30         #include "Devassert.h"
31     #endif
32 #endif  /* EMIOS_ICU_IP_USED */
33 
34 /*==================================================================================================
35 *                                        LOCAL MACROS
36 ==================================================================================================*/
37 #define EMIOS_ICU_IP_IRQ_VENDOR_ID_C                       43
38 #define EMIOS_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C        4
39 #define EMIOS_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C        7
40 #define EMIOS_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C     0
41 #define EMIOS_ICU_IP_IRQ_SW_MAJOR_VERSION_C                3
42 #define EMIOS_ICU_IP_IRQ_SW_MINOR_VERSION_C                0
43 #define EMIOS_ICU_IP_IRQ_SW_PATCH_VERSION_C                0
44 
45 /*==================================================================================================
46 *                                      FILE VERSION CHECKS
47 ==================================================================================================*/
48 #if (EMIOS_ICU_IP_IRQ_VENDOR_ID_C != EMIOS_ICU_IP_IRQ_VENDOR_ID)
49     #error "Emios_Icu_Ip_Irq.c and Emios_Icu_Ip_Irq.h have different vendor ids"
50 #endif
51 
52 /* Check if  header file and Emios_Icu_Ip_Irq.h file are of the same Autosar version */
53 #if ((EMIOS_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != EMIOS_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION) || \
54      (EMIOS_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != EMIOS_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION) || \
55      (EMIOS_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C != EMIOS_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION))
56     #error "AutoSar Version Numbers of Emios_Icu_Ip_Irq.c and Emios_Icu_Ip_Irq.h are different"
57 #endif
58 
59 /* Check if header file and Emios_Icu_Ip_Irq.h file are of the same Software version */
60 #if ((EMIOS_ICU_IP_IRQ_SW_MAJOR_VERSION_C != EMIOS_ICU_IP_IRQ_SW_MAJOR_VERSION) || \
61      (EMIOS_ICU_IP_IRQ_SW_MINOR_VERSION_C != EMIOS_ICU_IP_IRQ_SW_MINOR_VERSION) || \
62      (EMIOS_ICU_IP_IRQ_SW_PATCH_VERSION_C != EMIOS_ICU_IP_IRQ_SW_PATCH_VERSION))
63     #error "Software Version Numbers of Emios_Icu_Ip_Irq.c and Emios_Icu_Ip_Irq.h are different"
64 #endif
65 
66 #if (EMIOS_ICU_IP_IRQ_VENDOR_ID_C != EMIOS_ICU_IP_VENDOR_ID)
67     #error "Emios_Icu_Ip_Irq.c and Emios_Icu_Ip.h have different vendor ids"
68 #endif
69 
70 /* Check if  header file and Emios_Icu_Ip.h file are of the same Autosar version */
71 #if ((EMIOS_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != EMIOS_ICU_IP_AR_RELEASE_MAJOR_VERSION) || \
72      (EMIOS_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != EMIOS_ICU_IP_AR_RELEASE_MINOR_VERSION) || \
73      (EMIOS_ICU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C != EMIOS_ICU_IP_AR_RELEASE_REVISION_VERSION))
74     #error "AutoSar Version Numbers of Emios_Icu_Ip_Irq.c and Emios_Icu_Ip.h are different"
75 #endif
76 
77 /* Check if header file and Emios_Icu_Ip.h file are of the same Software version */
78 #if ((EMIOS_ICU_IP_IRQ_SW_MAJOR_VERSION_C != EMIOS_ICU_IP_SW_MAJOR_VERSION) || \
79      (EMIOS_ICU_IP_IRQ_SW_MINOR_VERSION_C != EMIOS_ICU_IP_SW_MINOR_VERSION) || \
80      (EMIOS_ICU_IP_IRQ_SW_PATCH_VERSION_C != EMIOS_ICU_IP_SW_PATCH_VERSION))
81     #error "Software Version Numbers of Emios_Icu_Ip_Irq.c and Emios_Icu_Ip.h are different"
82 #endif
83 
84 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
85     /* Check if this header file and SchM_Icu.h file are of the same Autosar version */
86     #if ((EMIOS_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != SCHM_ICU_AR_RELEASE_MAJOR_VERSION) || \
87         (EMIOS_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != SCHM_ICU_AR_RELEASE_MINOR_VERSION))
88         #error "AutoSar Version Numbers of Emios_Icu_Ip_Irq.c and SchM_Icu.h are different"
89     #endif
90 
91     #if (STD_ON == EMIOS_ICU_IP_USED)
92         #if(EMIOS_ICU_IP_DEV_ERROR_DETECT == STD_ON)
93             /* Check if this header file and Devassert.h file are of the same Autosar version */
94             #if ((EMIOS_ICU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
95                 (EMIOS_ICU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION))
96                 #error "AutoSar Version Numbers of Emios_Icu_Ip_Irq.c and Devassert.h are different"
97             #endif
98         #endif
99     #endif  /* EMIOS_ICU_IP_USED */
100 #endif
101 /*==================================================================================================
102 *                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
103 ==================================================================================================*/
104 
105 /*==================================================================================================
106 *                                       LOCAL CONSTANTS
107 ==================================================================================================*/
108 
109 /*==================================================================================================
110 *                                       LOCAL VARIABLES
111 ==================================================================================================*/
112 
113 /*==================================================================================================
114                                        GLOBAL CONSTANTS
115 ==================================================================================================*/
116 
117 /*==================================================================================================
118 *                                       GLOBAL VARIABLES
119 ==================================================================================================*/
120 #if (STD_ON == EMIOS_ICU_IP_USED)
121 
122 #define ICU_START_SEC_VAR_CLEARED_UNSPECIFIED
123 #include "Icu_MemMap.h"
124 
125 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
126 extern eMios_Icu_Ip_MeasStatusType eMios_Icu_Ip_aeInt_Counter[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
127 extern eMios_Icu_ValueType eMios_Icu_Ip_CapturedActivePulseWidth[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
128 extern eMios_Icu_ValueType eMios_Icu_Ip_TimeStart[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
129 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
130 #if (EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)
131 extern eMios_Icu_ValueType eMios_Icu_Ip_BufferPtr[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
132 #endif /* EMIOS_ICU_IP_TIMESTAMP_API == STD_ON */
133 #define ICU_STOP_SEC_VAR_CLEARED_UNSPECIFIED
134 #include "Icu_MemMap.h"
135 
136 #define ICU_START_SEC_VAR_CLEARED_UNSPECIFIED
137 #include "Icu_MemMap.h"
138 extern eMios_Icu_Ip_ChStateType eMios_Icu_Ip_ChState[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
139 #define ICU_STOP_SEC_VAR_CLEARED_UNSPECIFIED
140 #include "Icu_MemMap.h"
141 
142 #define ICU_START_SEC_VAR_INIT_8
143 #include "Icu_MemMap.h"
144 /* This array stores the positions in the eMios_Icu_Ip_ChState array of the configured eMios channels. */
145 extern uint8 eMios_Icu_Ip_IndexInChState[EMIOS_ICU_IP_INSTANCE_COUNT][EMIOS_ICU_IP_NUM_OF_CHANNELS];
146 #define ICU_STOP_SEC_VAR_INIT_8
147 #include "Icu_MemMap.h"
148 
149 #define ICU_START_SEC_CONST_UNSPECIFIED
150 #include "Icu_MemMap.h"
151 
152 extern eMIOS_Type * const s_emiosBase[];
153 
154 #define ICU_STOP_SEC_CONST_UNSPECIFIED
155 #include "Icu_MemMap.h"
156 
157 #define ICU_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
158 #include "Icu_MemMap.h"
159 
160 #if (STD_ON == EMIOS_ICU_IP_SIGNALMEASUREMENT_USES_DMA_IPL)
161 /** @brief Array for saving value of DMA **/
162 extern uint32 Emios_Icu_Ip_aDmaBuffer[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED][EMIOS_ICU_IP_DMA_MAJORLOOP_COUNT];
163 
164 /** @brief Array for saving the period */
165 extern uint32 Emios_Icu_Ip_aIsSecondInterrupt[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
166 
167 /** @brief Array for saving the period */
168 extern uint32 Emios_Icu_Ip_aFirstEdgeTimeStamp[EMIOS_ICU_IP_NUM_OF_CHANNELS_USED];
169 
170 #endif /* EMIOS_ICU_IP_SIGNALMEASUREMENT_USES_DMA_IPL */
171 
172 #define ICU_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
173 
174 #include "Icu_MemMap.h"
175 /*==================================================================================================
176 *                                   LOCAL FUNCTION PROTOTYPES
177 ==================================================================================================*/
178 #define ICU_START_SEC_CODE
179 #include "Icu_MemMap.h"
180 /**
181  * @brief
182  *
183  * @param instance
184  * @param channel
185  * @param bOverflow
186  */
187 static inline void Emios_Icu_Ip_ReportEvents(uint8 instance, uint8 hwChannel, boolean bOverflow);
188 
189 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON) || (EMIOS_ICU_IP_EDGE_COUNT_API == STD_ON))
190 /**
191  * @brief
192  *
193  * @param instance
194  * @param channel
195  * @param bOverflow
196  */
197 static inline void Emios_Icu_Ip_ReportOverflow(uint8 instance, uint8 hwChannel, boolean bOverflow);
198 #endif
199 
200 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
201 /**
202 * @brief      Emios_Icu_Ip_GetCaptureRegB
203 * @details    This function returns the register B of the given eMIOS Unified Channel
204 * @param[in]  hwChannel  - eMIOS encoded hardware channel
205 * @return     uint32 - Captured value of the register B
206 *
207 * @api
208 */
209 static inline uint32 Emios_Icu_Ip_GetCaptureRegB
210 (
211     const uint8 instance,
212     const uint8 hwChannel
213 );
214 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
215 
216 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
217 /**
218 * @brief      Emios_Icu_Ip_GetCaptureRegA
219 * @details    This function returns the register A of the given eMIOS Unified Channel
220 * @param[in]  hwChannel  - eMIOS encoded hardware channel
221 * @return     uint32 - Captured value of the register A
222 *
223 * @api
224 */
225 static inline uint32 Emios_Icu_Ip_GetCaptureRegA
226 (
227     const uint8 instance,
228     const uint8 hwChannel
229 );
230 #endif /* (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON) */
231 
232 /**
233 * @brief      Emios_Icu_Ip_ClearStatusFlags
234 * @details    Clear the flags set only for selected interrupts that are enabled
235 *
236 * @param[in]      hwChannel    - eMIOS Hardware Channel
237 * @param[in]      u32BitMask   - flags to be cleared
238 *
239 * @return void
240 *
241 **/
242 static inline void Emios_Icu_Ip_ClearStatusFlags
243 (
244     const uint8 instance,
245     const uint8 hwChannel,
246     uint32 u32BitMask
247 );
248 
249 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
250 /**
251 * @brief      Icu driver function that checks the overflow flag
252 * @details    This function returns clock mode of channel
253 *
254 * @param[in]  hwChannel - hardware channel eMIOS
255 *
256 * @return     uint32
257 *
258 * @api
259 */
260 static inline uint32 Emios_Icu_Ip_GetChannelClockMode
261 (
262     const uint8 instance,
263     const uint8 hwChannel
264 );
265 
266 static inline void Emios_Icu_Ip_SignalMeasurementStore(uint8  instance,
267                                                        uint8  hwChannel,
268                                                        eMios_Icu_ValueType activePulseWidth,
269                                                        eMios_Icu_ValueType period,
270                                                        boolean bOverflow);
271 
272 /**
273  @brief      This function is used to read the period values for channels
274  @details    This function returns the Counter Value based on the configuration
275  @param[in]  hwChannel - hardware channel eMIOS
276  @pre        Icu_Init must be called before.
277 */
278 static inline uint32 Emios_Icu_Ip_ReadCounterBus
279 (
280     const uint8 instance,
281     const uint8 hwChannel
282 );
283 
284 static inline void Emios_Icu_Ip_SignalMeasurementWithIPWMMode
285 (
286     const uint8 instance,
287     const uint8 hwChannel,
288     boolean bOverflow
289 );
290 
291 static inline void Emios_Icu_Ip_SignalMeasurementWithIPMMode
292 (
293     const uint8 instance,
294     const uint8 hwChannel,
295     boolean bOverflow
296 );
297 
298 #if (STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE)
299 static inline void Emios_Icu_Ip_SignalMeasurementWithSAICMode
300 (
301     const uint8 instance,
302     const uint8 hwChannel,
303     boolean bOverflow
304 );
305 #endif  /* STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE */
306 
307 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
308 
309 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON))
310 /**
311 * @brief      Icu driver function that handles the masterbus interrupt of eMIOS channel.
312 * @details    This function:
313 *              - Report overflow to notify if necessary
314 *
315 * @param[in]  hwChannel - eMIOS hardware channel
316 *
317 */
318 static inline eMios_Icu_Ip_BusType Emios_Icu_Ip_ValidateChannelUsedMasterbus
319 (
320     const uint8 instance,
321     const uint8 hwChannel
322 );
323 #endif
324 
325 /**
326 * @brief      Emios_Icu_Ip_GetStatusFlags
327 * @details    Returns the flags set only for the enabled interrupts
328 *
329 * @param[in]   hwChannel - eMIOS Hardware Channel
330 *
331 * @return      uint32 - Flags set for enabled interrupts
332 **/
333 static inline uint32 Emios_Icu_Ip_GetStatusFlags
334 (
335     const uint8 instance,
336     const uint8 hwChannel
337 );
338 
339 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON))
340 /**
341 * @brief      Icu driver function that handles the masterbus interrupt of eMIOS channel.
342 * @details    This function:
343 *              - Report overflow to notify if necessary
344 *
345 * @param[in]  hwChannel - eMIOS hardware channel
346 */
347 static inline void Emios_Icu_Ip_ProcessMasterBusInterrupt
348 (
349     const uint8 instance,
350     const uint8 hwChannel
351 );
352 #endif
353 
354 #if (STD_ON == EMIOS_ICU_IP_TIMESTAMP_API )
355 /**
356  * @brief      Icu driver function that handles the timestamp measurement type interrupt.
357  * @details    This service is  called when an  interrupt is recognized  as a Timestamp
358  *             Measurement type.
359  *
360  * @param[in]  hwChannel - The index of ICU channel for current configuration structure
361  * @param[in]  bOverflow        Parameter that indicates the source of report is an overflow
362  * @implements Emios_Icu_Ip_TimestampHandler_Activity
363 */
364 static void Emios_Icu_Ip_TimestampHandler(uint8        instance,
365                                           uint8        hwChannel,
366                                           const eMios_Icu_ValueType *bufferPtr,
367                                           boolean      bOverflow);
368 #endif /* STD_ON == EMIOS_ICU_IP_TIMESTAMP_API */
369 
370 #if (STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE)
371 extern void Emios_Icu_Ip_SetActivation
372 (
373     uint8 instance,
374     uint8 hwChannel,
375     eMios_Icu_Ip_EdgeType edge
376 );
377 #endif  /* STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE */
378 /*==================================================================================================
379 *                                       LOCAL FUNCTIONS
380 ==================================================================================================*/
381 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_GetCaptureRegB(const uint8 instance,const uint8 hwChannel)382 static inline uint32 Emios_Icu_Ip_GetCaptureRegB
383 (
384     const uint8 instance,
385     const uint8 hwChannel
386 )
387 {
388     /*return the value of shadow register*/
389     return s_emiosBase[instance]->CH.UC[hwChannel].B;
390 }
391 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
392 
393 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_GetCaptureRegA(const uint8 instance,const uint8 hwChannel)394 static inline uint32 Emios_Icu_Ip_GetCaptureRegA
395 (
396     const uint8 instance,
397     const uint8 hwChannel
398 )
399 {
400 #if (STD_ON == EMIOS_ICU_IP_DEV_ERROR_DETECT)
401     DevAssert(instance < EMIOS_ICU_IP_INSTANCE_COUNT);
402     DevAssert(hwChannel < EMIOS_ICU_IP_NUM_OF_CHANNELS);
403 #endif
404     /*get the value of A shadow register*/
405     return s_emiosBase[instance]->CH.UC[hwChannel].A;
406 }
407 #endif /* (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON) */
408 
Emios_Icu_Ip_ClearStatusFlags(const uint8 instance,const uint8 hwChannel,uint32 u32BitMask)409 static inline void Emios_Icu_Ip_ClearStatusFlags
410 (
411     const uint8 instance,
412     const uint8 hwChannel,
413     uint32 u32BitMask
414 )
415 {
416     s_emiosBase[instance]->CH.UC[hwChannel].S |= (u32BitMask & (eMIOS_S_OVR_MASK | eMIOS_S_OVFL_MASK | eMIOS_S_FLAG_MASK));
417 }
418 
419 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_GetChannelClockMode(const uint8 instance,const uint8 hwChannel)420 static inline uint32 Emios_Icu_Ip_GetChannelClockMode
421 (
422     const uint8 instance,
423     const uint8 hwChannel
424 )
425 {
426     /*return the value of mode selection*/
427     return (s_emiosBase[instance]->CH.UC[hwChannel].C & eMIOS_C_MODE_MASK);
428 }
429 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
430 
431 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_SignalMeasurementStore(uint8 instance,uint8 hwChannel,eMios_Icu_ValueType activePulseWidth,eMios_Icu_ValueType period,boolean bOverflow)432 static inline void Emios_Icu_Ip_SignalMeasurementStore(uint8  instance,
433                                                        uint8  hwChannel,
434                                                        eMios_Icu_ValueType activePulseWidth,
435                                                        eMios_Icu_ValueType period,
436                                                        boolean bOverflow)
437 {
438     /* Saving measurement data into state variable for later usage */
439     eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aActivePulseWidth = activePulseWidth;
440     eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aPeriod = period;
441 
442 
443     /* Calling HLD logical channel status changer */
444     if(NULL_PTR != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].logicChStateCallback)
445     {
446         eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].logicChStateCallback(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callbackParam, (1U << 1), TRUE);
447     }
448 
449     /* Calling HLD for reporting wakeup and overflow */
450     Emios_Icu_Ip_ReportOverflow(instance, hwChannel, bOverflow);
451 }
452 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
453 
454 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_ReadCounterBus(const uint8 instance,const uint8 hwChannel)455 static inline uint32 Emios_Icu_Ip_ReadCounterBus
456 (
457     const uint8 instance,
458     const uint8 hwChannel
459 )
460 {
461     uint32 u32Period = (uint32)0u;
462     uint32 u32BusChannelClockMode = (uint32)0u;
463 
464     /* Get eMiosBus of hardware channel */
465     eMios_Icu_Ip_BusType u32ChannelEmiosBus = eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].BusSelected;
466 
467     switch (u32ChannelEmiosBus)
468     {
469         case EMIOS_ICU_BUS_INTERNAL_COUNTER:
470         {
471             u32Period = EMIOS_ICU_IP_COUNTER_MASK;
472         }
473         break;
474 
475         case EMIOS_ICU_BUS_DIVERSE:
476         {
477             if (EMIOS_ICU_IP_CHANNEL_7 >= hwChannel)
478             {
479                 u32BusChannelClockMode = Emios_Icu_Ip_GetChannelClockMode(instance, EMIOS_ICU_IP_CHANNEL_0);
480                 /* eMIOS Counter Bus_B Channel (EMIOS_ICU_IP_CHANNEL_0) is in Modulous counter buffer or
481                 Modulous counter mode */
482                 if (EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == u32BusChannelClockMode)
483                 {
484                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegA(instance, EMIOS_ICU_IP_CHANNEL_0);
485                 }
486                 else
487                 {
488                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegB(instance, EMIOS_ICU_IP_CHANNEL_0);
489                 }
490             }
491 
492             /* eMIOS Channel configured is using Counter Bus_C */
493             else if (EMIOS_ICU_IP_CHANNEL_15 >= hwChannel)
494             {
495                 u32BusChannelClockMode = Emios_Icu_Ip_GetChannelClockMode(instance, EMIOS_ICU_IP_CHANNEL_8);
496                 /* eMIOS Counter Bus_C Channel (EMIOS_ICU_IP_CHANNEL_8) is in Modulous counter buffer or
497                  Modulous counter mode */
498                 if (EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == u32BusChannelClockMode)
499                 {
500                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegA(instance, EMIOS_ICU_IP_CHANNEL_8);
501                 }
502                 else
503                 {
504                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegB(instance, EMIOS_ICU_IP_CHANNEL_8);
505                 }
506             }
507 
508             /* eMIOS Channel configured is using Counter Bus_D */
509             else if (EMIOS_ICU_IP_CHANNEL_23 >= hwChannel )
510             {
511                 u32BusChannelClockMode = Emios_Icu_Ip_GetChannelClockMode(instance, EMIOS_ICU_IP_CHANNEL_16);
512                 /* eMIOS Counter Bus_D Channel (EMIOS_ICU_IP_CHANNEL_16) is in Modulous counter buffer or
513                  Modulous counter mode */
514                 if (EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == u32BusChannelClockMode)
515                 {
516                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegA(instance, EMIOS_ICU_IP_CHANNEL_16);
517                 }
518                 else
519                 {
520                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegB(instance, EMIOS_ICU_IP_CHANNEL_16);
521                 }
522             }
523 
524 #if (STD_ON == EMIOS_ICU_IP_CHANNEL_24_USED)
525             /* eMIOS Channel configured is using Counter Bus_E */
526             else if (EMIOS_ICU_IP_CHANNEL_31  >= hwChannel)
527             {
528                 u32BusChannelClockMode = Emios_Icu_Ip_GetChannelClockMode(instance, EMIOS_ICU_IP_CHANNEL_24);
529                 /* eMIOS Counter Bus_E Channel (EMIOS_ICU_IP_CHANNEL_24) is in Modulous counter buffer or
530                  Modulous counter mode */
531                 if (EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == u32BusChannelClockMode)
532                 {
533                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegA(instance, EMIOS_ICU_IP_CHANNEL_24);
534                 }
535                 else
536                 {
537                     u32Period= (uint32)Emios_Icu_Ip_GetCaptureRegB(instance, EMIOS_ICU_IP_CHANNEL_24);
538                 }
539             }
540 #endif
541             else
542             {
543                 /* Do Nothing */
544             }
545         }
546         break;
547 
548         case EMIOS_ICU_BUS_A:
549         {
550             /* Get clock mode */
551             u32BusChannelClockMode = Emios_Icu_Ip_GetChannelClockMode(instance, EMIOS_ICU_IP_CHANNEL_23);
552 
553             if(EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == u32BusChannelClockMode)
554             {
555                 u32Period  = (uint32) Emios_Icu_Ip_GetCaptureRegA(instance, EMIOS_ICU_IP_CHANNEL_23);
556             }
557             else
558             {
559                 u32Period  = (uint32) Emios_Icu_Ip_GetCaptureRegB(instance, EMIOS_ICU_IP_CHANNEL_23);
560             }
561         }
562         break;
563 
564         case EMIOS_ICU_BUS_F:
565         {
566             /* Get clock mode of bus F */
567             u32BusChannelClockMode = Emios_Icu_Ip_GetChannelClockMode(instance, EMIOS_ICU_IP_CHANNEL_22);
568 
569             if(EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == u32BusChannelClockMode)
570             {
571                 u32Period  = (uint32) Emios_Icu_Ip_GetCaptureRegA(instance, EMIOS_ICU_IP_CHANNEL_22);
572             }
573             else
574             {
575                 u32Period  = (uint32) Emios_Icu_Ip_GetCaptureRegB(instance, EMIOS_ICU_IP_CHANNEL_22);
576             }
577         }
578         break;
579 
580         default:
581         {
582             /* Rule 16.1 requires switch well-formed */
583         }
584         break;
585     }
586 
587     /* return u32Period */
588     return (u32Period);
589 }
590 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
591 
592 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_SignalMeasurementWithIPWMMode(const uint8 instance,const uint8 hwChannel,boolean bOverflow)593 static inline void Emios_Icu_Ip_SignalMeasurementWithIPWMMode
594 (
595     const uint8 instance,
596     const uint8 hwChannel,
597     boolean bOverflow
598 )
599 {
600     uint8 u8ChIndex = eMios_Icu_Ip_IndexInChState[instance][hwChannel];
601     eMios_Icu_ValueType activePulseWidth;
602     eMios_Icu_ValueType IcuPeriod;
603     eMios_Icu_ValueType Bus_Period;
604     eMios_Icu_Ip_MeasType nMeasurement_property = eMios_Icu_Ip_ChState[u8ChIndex].measurement;
605 
606     eMios_Icu_ValueType IcuTempA = (eMios_Icu_ValueType)Emios_Icu_Ip_GetCaptureRegA(instance, hwChannel);
607     eMios_Icu_ValueType IcuTempB = (eMios_Icu_ValueType)Emios_Icu_Ip_GetCaptureRegB(instance, hwChannel);
608 
609     if ((EMIOS_ICU_HIGH_TIME == nMeasurement_property) || \
610         (EMIOS_ICU_LOW_TIME == nMeasurement_property))
611     {
612         if (IcuTempA > IcuTempB)
613         {
614             activePulseWidth = (eMios_Icu_ValueType)(IcuTempA - IcuTempB);
615         }
616         else /*Counter overflow Case*/
617         {
618             Bus_Period = (eMios_Icu_ValueType)Emios_Icu_Ip_ReadCounterBus(instance, hwChannel);
619             activePulseWidth = (eMios_Icu_ValueType)(IcuTempA + ((uint32)Bus_Period - IcuTempB) + 1U);
620         }
621 
622         Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, activePulseWidth, 0U, bOverflow);
623     }
624     /* Duty cycle */
625     else
626     {
627         /* Check if a complete signal was acquired */
628         if (EMIOS_ICU_MEASUREMENT_PENDING == eMios_Icu_Ip_aeInt_Counter[u8ChIndex])
629         {
630             /* Mark that the complete signal was acquired */
631             eMios_Icu_Ip_aeInt_Counter[u8ChIndex] = EMIOS_ICU_MEASUREMENT_DUTY;
632             /* Report event and possible overflow to HLD or IPL user overflow notification */
633             Emios_Icu_Ip_ReportOverflow (instance, hwChannel, bOverflow);
634         }
635         else
636         {
637             /* Compute Period of the signal */
638             if (IcuTempB > eMios_Icu_Ip_TimeStart[u8ChIndex])
639             {
640                 IcuPeriod = IcuTempB - eMios_Icu_Ip_TimeStart[u8ChIndex];
641             }
642             else     /*Counter overflow Case */
643             {
644                 Bus_Period = (eMios_Icu_ValueType)Emios_Icu_Ip_ReadCounterBus(instance, hwChannel);
645                 IcuPeriod = (eMios_Icu_ValueType)\
646                 (IcuTempB + ((uint32)Bus_Period - eMios_Icu_Ip_TimeStart[u8ChIndex]) + 1U);
647             }
648             activePulseWidth = eMios_Icu_Ip_CapturedActivePulseWidth[u8ChIndex];
649 
650             if (EMIOS_ICU_DUTY_CYCLE == nMeasurement_property)
651             {
652                 Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, activePulseWidth, IcuPeriod, bOverflow);
653             }
654             else if (EMIOS_ICU_PERIOD_TIME == nMeasurement_property)
655             {
656                 Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, 0U, IcuPeriod, bOverflow);
657             }
658             else
659             {
660                 /* Nothing to do */
661             }
662         }
663     }
664 
665     if (IcuTempA > IcuTempB)
666     {
667         eMios_Icu_Ip_CapturedActivePulseWidth[u8ChIndex] = (eMios_Icu_ValueType)(IcuTempA - IcuTempB);
668     }
669     else /*Counter overflow Case */
670     {
671         Bus_Period = (eMios_Icu_ValueType)Emios_Icu_Ip_ReadCounterBus(instance, hwChannel);
672         eMios_Icu_Ip_CapturedActivePulseWidth[u8ChIndex] = (eMios_Icu_ValueType)(IcuTempA + ((uint32)Bus_Period - IcuTempB) + 1U);
673     }
674     eMios_Icu_Ip_TimeStart[u8ChIndex] = (eMios_Icu_ValueType)IcuTempB;
675 }
676 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
677 
678 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_SignalMeasurementWithIPMMode(const uint8 instance,const uint8 hwChannel,boolean bOverflow)679 static inline void Emios_Icu_Ip_SignalMeasurementWithIPMMode
680 (
681     const uint8 instance,
682     const uint8 hwChannel,
683     boolean bOverflow
684 )
685 {
686     eMios_Icu_ValueType IcuPeriod;
687     eMios_Icu_ValueType Bus_Period;
688     eMios_Icu_ValueType IcuTempA = (eMios_Icu_ValueType)Emios_Icu_Ip_GetCaptureRegA(instance, hwChannel);
689     eMios_Icu_ValueType IcuTempB = (eMios_Icu_ValueType)Emios_Icu_Ip_GetCaptureRegB(instance, hwChannel);
690 
691     if (IcuTempA > IcuTempB)
692     {
693         IcuPeriod = (eMios_Icu_ValueType)(IcuTempA - IcuTempB);
694     }
695     else     /*Counter overflow Case*/
696     {
697         Bus_Period = (eMios_Icu_ValueType)Emios_Icu_Ip_ReadCounterBus(instance, hwChannel);
698         IcuPeriod = (eMios_Icu_ValueType)(IcuTempA + ((uint32)Bus_Period - IcuTempB) + 1U);
699     }
700     Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, 0U, IcuPeriod, bOverflow);
701 }
702 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
703 
704 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
705 #if (STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE)
Emios_Icu_Ip_SignalMeasurementWithSAICMode(const uint8 instance,const uint8 hwChannel,boolean bOverflow)706 static inline void Emios_Icu_Ip_SignalMeasurementWithSAICMode
707 (
708     const uint8 instance,
709     const uint8 hwChannel,
710     boolean bOverflow
711 )
712 {
713     uint8 u8ChIndex = eMios_Icu_Ip_IndexInChState[instance][hwChannel];
714     eMios_Icu_ValueType activePulseWidth;
715     eMios_Icu_ValueType IcuPeriod;
716     eMios_Icu_ValueType Bus_Period;
717     eMios_Icu_Ip_MeasType nMeasurement_property = eMios_Icu_Ip_ChState[u8ChIndex].measurement;
718     eMios_Icu_ValueType IcuTempA = (eMios_Icu_ValueType)Emios_Icu_Ip_GetCaptureRegA(instance, hwChannel);
719     eMios_Icu_ValueType Previous_Value;
720     eMios_Icu_ValueType Pulse_Width;
721 
722     Emios_Icu_Ip_SetActivation (instance, hwChannel, EMIOS_OPPOSITE_EDGES);
723 
724     if (EMIOS_ICU_MEASUREMENT_PENDING == eMios_Icu_Ip_aeInt_Counter[u8ChIndex])
725     {
726         /* store the first value */
727         eMios_Icu_Ip_TimeStart[u8ChIndex] = IcuTempA;
728         eMios_Icu_Ip_aeInt_Counter[u8ChIndex] = EMIOS_ICU_MEASUREMENT_DUTY;
729     }
730     else
731     {
732         Previous_Value = eMios_Icu_Ip_TimeStart[u8ChIndex];
733         /* if first value is greater than the second value */
734         if (IcuTempA < Previous_Value)
735         {
736             Bus_Period = (eMios_Icu_ValueType)Emios_Icu_Ip_ReadCounterBus(instance, hwChannel);
737             Pulse_Width = (Bus_Period - Previous_Value) + IcuTempA + 1U;
738         }
739         else
740         {
741             Pulse_Width = IcuTempA - Previous_Value;
742         }
743 
744         /* HIGH TIME or LOW TIME measurement */
745         if ((EMIOS_ICU_HIGH_TIME == nMeasurement_property) ||   \
746             (EMIOS_ICU_LOW_TIME == nMeasurement_property)
747            )
748         {
749             activePulseWidth = Pulse_Width;
750             /* clear to measure next LOW/HIGH pulse */
751             eMios_Icu_Ip_aeInt_Counter[u8ChIndex] = EMIOS_ICU_MEASUREMENT_PENDING;
752             Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, activePulseWidth, (eMios_Icu_ValueType)0U, bOverflow);
753         }
754         /* Duty Cycle */
755         else
756         {
757             /* DUTYCYCLE or PERIOD measurement */
758             if (EMIOS_ICU_MEASUREMENT_DUTY == eMios_Icu_Ip_aeInt_Counter[u8ChIndex])
759             {
760                 eMios_Icu_Ip_CapturedActivePulseWidth[u8ChIndex] = Pulse_Width;
761                 eMios_Icu_Ip_aeInt_Counter[u8ChIndex] = EMIOS_ICU_MEASUREMENT_PERIOD;
762                 if(eMios_Icu_Ip_ChState[u8ChIndex].callback != NULL_PTR)
763                 {
764                     eMios_Icu_Ip_ChState[u8ChIndex].callback(eMios_Icu_Ip_ChState[u8ChIndex].callbackParam, bOverflow);
765                 }
766             }
767             else
768             {
769                 /* eMios_Icu_Ip_aeInt_Counter is for period */
770                 IcuPeriod = eMios_Icu_Ip_CapturedActivePulseWidth[u8ChIndex] + Pulse_Width;
771                 activePulseWidth = eMios_Icu_Ip_CapturedActivePulseWidth[u8ChIndex];
772 
773                 /* set to Duty to find active pulse width next time */
774                 eMios_Icu_Ip_aeInt_Counter[u8ChIndex] = EMIOS_ICU_MEASUREMENT_DUTY;
775                 if (EMIOS_ICU_DUTY_CYCLE == nMeasurement_property)
776                 {
777                     Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, activePulseWidth, IcuPeriod, bOverflow);
778                 }
779                 else if (EMIOS_ICU_PERIOD_TIME == nMeasurement_property)
780                 {
781                     Emios_Icu_Ip_SignalMeasurementStore(instance, hwChannel, (eMios_Icu_ValueType)0U, IcuPeriod, bOverflow);
782                 }
783                 else
784                 {
785                     /**/
786                 }
787             }
788             /* store for next time */
789             eMios_Icu_Ip_TimeStart[u8ChIndex] = IcuTempA;
790         }
791     }
792 }
793 #endif  /* STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE */
794 #endif /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
795 
796 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON))
Emios_Icu_Ip_ValidateChannelUsedMasterbus(const uint8 instance,const uint8 hwChannel)797 static inline eMios_Icu_Ip_BusType Emios_Icu_Ip_ValidateChannelUsedMasterbus
798 (
799     const uint8 instance,
800     const uint8 hwChannel
801 )
802 {
803     eMios_Icu_Ip_BusType busResult = (eMios_Icu_Ip_BusType)EMIOS_ICU_BUS_INTERNAL_COUNTER;
804 
805     /*change bus if it is not the mode of no measurement*/
806     if (EMIOS_ICU_MODE_NO_MEASUREMENT != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].channelMode)
807     {
808         busResult = (eMios_Icu_Ip_BusType)eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].BusSelected;
809     }
810     return busResult;
811 }
812 #endif
813 
814 #if (STD_ON == EMIOS_ICU_IP_TIMESTAMP_API )
Emios_Icu_Ip_TimestampHandler(uint8 instance,uint8 hwChannel,const eMios_Icu_ValueType * bufferPtr,boolean bOverflow)815 static void Emios_Icu_Ip_TimestampHandler(uint8        instance,
816                                           uint8        hwChannel,
817                                           const eMios_Icu_ValueType *bufferPtr,
818                                           boolean      bOverflow)
819 {
820     Emios_Icu_Ip_ReportOverflow(instance, hwChannel, bOverflow);
821 
822     eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBuffer[eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex] = bufferPtr[0U];
823     eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex++;
824 
825     if (eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex >= eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferSize)
826     {
827         if(EMIOS_ICU_CIRCULAR_BUFFER == eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].timestampBufferType)
828         {
829             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex = 0U;
830         }
831         else
832         {
833             Emios_Icu_Ip_StopTimestamp(instance, hwChannel);
834             if (NULL_PTR != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].logicChStateCallback)
835             {
836                 eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].logicChStateCallback(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callbackParam, (1U << 3), FALSE);
837             }
838 
839         }
840     }
841 
842     if (0U != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify)
843     {
844         eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount++;
845         if (eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount >= eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify)
846         {
847             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount = 0U;
848 
849             /* Call User Notification Function for IPL and HLD */
850             if ((NULL_PTR != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosChannelNotification) && \
851                 ((boolean)TRUE == eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].notificationEnable))
852             {
853                 eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosChannelNotification();
854             }
855         }
856     }
857 }
858 #endif  /* EMIOS_ICU_IP_TIMESTAMP_API */
859 
860 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON))
Emios_Icu_Ip_ProcessMasterBusInterrupt(const uint8 instance,const uint8 hwChannel)861 static inline void Emios_Icu_Ip_ProcessMasterBusInterrupt
862 (
863     const uint8 instance,
864     const uint8 hwChannel
865 )
866 {
867     uint8 nCounter;
868     boolean bOverflowUsingMasterbus = FALSE;
869     eMios_Icu_Ip_ModeType nMeasMode;
870     eMios_Icu_Ip_BusType BusSelected;
871 
872     for(nCounter=0U; nCounter < EMIOS_ICU_IP_NUM_OF_CHANNELS; nCounter++)
873     {
874         if (eMios_Icu_Ip_IndexInChState[instance][nCounter] < EMIOS_ICU_IP_NUM_OF_CHANNELS_USED)
875         {
876             bOverflowUsingMasterbus = FALSE;
877             BusSelected = Emios_Icu_Ip_ValidateChannelUsedMasterbus(instance, nCounter);
878             switch(BusSelected)
879             {
880                 case EMIOS_ICU_BUS_DIVERSE:
881                 {
882                     if
883                     (
884                         ((hwChannel % ((uint8)8U)) == 0U) && \
885                         (nCounter <= (hwChannel + ((uint8)7U))) && (nCounter >= (hwChannel + ((uint8)1U)))
886                     )
887                     {
888                         bOverflowUsingMasterbus = TRUE;
889                     }
890                 }
891                 break;
892                 case EMIOS_ICU_BUS_A:
893                 {
894                     if(EMIOS_ICU_IP_CHANNEL_23 == hwChannel)
895                     {
896                         bOverflowUsingMasterbus = TRUE;
897                     }
898                 }
899                 break;
900                 case EMIOS_ICU_BUS_F:
901                 {
902                     if(EMIOS_ICU_IP_CHANNEL_22 == hwChannel)
903                     {
904                         bOverflowUsingMasterbus = TRUE;
905                     }
906                 }
907                 break;
908                 default:
909                 {
910                     /* Do nothing. */
911                 }
912                 break;
913             }
914             if(TRUE == bOverflowUsingMasterbus)
915             {
916                 nMeasMode = eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][nCounter]].channelMode;
917                 if((EMIOS_ICU_MODE_TIMESTAMP == nMeasMode) || (EMIOS_ICU_MODE_SIGNAL_MEASUREMENT == nMeasMode))
918                 {
919                     Emios_Icu_Ip_ReportOverflow(instance, nCounter, TRUE);
920                 }
921             }
922         }
923     }
924 }
925 #endif
926 
Emios_Icu_Ip_GetStatusFlags(const uint8 instance,const uint8 hwChannel)927 static inline uint32 Emios_Icu_Ip_GetStatusFlags
928 (
929     const uint8 instance,
930     const uint8 hwChannel
931 )
932 {
933     /*return the value of status*/
934     return s_emiosBase[instance]->CH.UC[hwChannel].S ;
935 }
936 
937 
Emios_Icu_Ip_ReportEvents(uint8 instance,uint8 hwChannel,boolean bOverflow)938 static inline void Emios_Icu_Ip_ReportEvents(uint8 instance, uint8 hwChannel, boolean bOverflow)
939 {
940     /* Calling HLD Report Events for the logical channel */
941     if(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callback != NULL_PTR)
942     {
943         eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callback(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callbackParam, bOverflow);
944     }
945     else
946     {
947         /* Calling Notification for the IPL channel */
948         if ((NULL_PTR != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosChannelNotification) && \
949            ((boolean)TRUE == eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].notificationEnable))
950         {
951             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosChannelNotification();
952         }
953 
954         /* Calling User Overflow Notification for the IPL channel */
955         if ( bOverflow && (NULL_PTR != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosOverflowNotification))
956         {
957             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosOverflowNotification();
958         }
959     }
960 }
961 
962 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON) || (EMIOS_ICU_IP_EDGE_COUNT_API == STD_ON))
Emios_Icu_Ip_ReportOverflow(uint8 instance,uint8 hwChannel,boolean bOverflow)963 static inline void Emios_Icu_Ip_ReportOverflow(uint8 instance, uint8 hwChannel, boolean bOverflow)
964 {
965     /* Calling HLD Report wakeup and overflow for the logical channel */
966     if(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callback != NULL_PTR)
967     {
968         eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callback(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].callbackParam, bOverflow);
969     }
970     else
971     {
972         /* Calling User Overflow Notification for the IPL channel */
973         if ((NULL_PTR != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosOverflowNotification) && bOverflow)
974         {
975             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosOverflowNotification();
976         }
977     }
978 }
979 #endif
980 
981 /*==================================================================================================
982 *                                        GLOBAL FUNCTIONS
983 ==================================================================================================*/
984 
985 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
Emios_Icu_Ip_SignalMeasurementHandler(const uint8 instance,const uint8 hwChannel,boolean bOverflow)986 void Emios_Icu_Ip_SignalMeasurementHandler
987 (
988     const uint8 instance,
989     const uint8 hwChannel,
990     boolean bOverflow
991 )
992 {
993     eMios_Icu_Ip_UCModeType eMios_OperationMode;
994 
995 #if (STD_ON == EMIOS_ICU_IP_DEV_ERROR_DETECT)
996     DevAssert(instance < EMIOS_ICU_IP_INSTANCE_COUNT);
997     DevAssert(hwChannel < EMIOS_ICU_IP_NUM_OF_CHANNELS);
998     DevAssert(eMios_Icu_Ip_IndexInChState[instance][hwChannel] < EMIOS_ICU_IP_NUM_OF_CHANNELS_USED);
999 #endif
1000 
1001     eMios_OperationMode = eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].operationMode;
1002     switch(eMios_OperationMode)
1003     {
1004         case EMIOS_ICU_IPWM :
1005         {
1006             Emios_Icu_Ip_SignalMeasurementWithIPWMMode(instance, hwChannel, bOverflow);
1007         }
1008         break;
1009 
1010         case EMIOS_ICU_IPM :
1011         {
1012             Emios_Icu_Ip_SignalMeasurementWithIPMMode(instance, hwChannel, bOverflow);
1013         }
1014         break;
1015 #if (STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE)
1016         case EMIOS_ICU_SAIC :
1017         {
1018             Emios_Icu_Ip_SignalMeasurementWithSAICMode(instance, hwChannel, bOverflow);
1019         }
1020         break;
1021 #endif  /* STD_ON == EMIOS_ICU_IP_SIGNAL_MEASUREMENT_USES_SAIC_MODE */
1022         default:
1023         {
1024                 /* Do nothing. */
1025         }
1026         break;
1027     }
1028 }
1029 #endif  /* EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON */
1030 
1031 /* @implements Emios_Icu_Ip_IrqHandler_Activity */
Emios_Icu_Ip_IrqHandler(uint8 instance,uint8 channel)1032 void Emios_Icu_Ip_IrqHandler(uint8 instance, uint8 channel)
1033 {
1034     eMios_Icu_Ip_ModeType nMeasMode;
1035     uint32      u32RegCSR;
1036 
1037 #if (STD_ON == EMIOS_ICU_IP_DEV_ERROR_DETECT)
1038     DevAssert(instance < EMIOS_ICU_IP_INSTANCE_COUNT);
1039     DevAssert(channel < EMIOS_ICU_IP_NUM_OF_CHANNELS);
1040 #endif
1041 
1042     uint8 u8ChIndex = eMios_Icu_Ip_IndexInChState[instance][channel];
1043 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON))
1044     uint32 u32RegCCR = s_emiosBase[instance]->CH.UC[channel].C;
1045 #endif
1046     boolean     bOverflow    = FALSE;
1047     boolean     bEnableInter = FALSE;
1048     /* Read UC Status Register */
1049     u32RegCSR = Emios_Icu_Ip_GetStatusFlags(instance, channel);
1050 
1051     if (eMIOS_C_FEN_MASK == (s_emiosBase[instance]->CH.UC[channel].C & eMIOS_C_FEN_MASK))
1052     {
1053         /* Note: what if this channel is Counter Bus -> MCL must clear the flags. */
1054         Emios_Icu_Ip_ClearStatusFlags(instance, channel, u32RegCSR);
1055         bEnableInter = TRUE;
1056     }
1057 
1058     /* MCL common ISR checks for spurios interrupts already */
1059     if(u8ChIndex < (uint8)EMIOS_ICU_IP_NUM_OF_CHANNELS_USED)
1060     {
1061         if((EMIOS_ICU_MODE_NO_MEASUREMENT != eMios_Icu_Ip_ChState[u8ChIndex].channelMode) && bEnableInter)
1062         {
1063 #if (EMIOS_ICU_IP_OVERFLOW_NOTIFICATION_API == STD_OFF)
1064             bOverflow = ((eMIOS_S_OVFL_MASK == (u32RegCSR & eMIOS_S_OVFL_MASK)) ? TRUE : FALSE);
1065 #endif
1066             nMeasMode = eMios_Icu_Ip_ChState[u8ChIndex].channelMode;
1067             switch (nMeasMode)
1068             {
1069                 case EMIOS_ICU_MODE_SIGNAL_EDGE_DETECT:
1070                 {
1071                     Emios_Icu_Ip_ReportEvents (instance, channel, bOverflow);
1072                 }
1073                 break;
1074 #if (EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)
1075                 case EMIOS_ICU_MODE_TIMESTAMP:
1076                 {
1077                     if(EMIOS_ICU_MODE_WITHOUT_DMA == eMios_Icu_Ip_ChState[u8ChIndex].dmaMode)
1078                     {
1079                         /* Copy the Counter value in the Timestamp Buffer. */
1080                         eMios_Icu_Ip_BufferPtr[u8ChIndex] = (eMios_Icu_ValueType)s_emiosBase[instance]->CH.UC[channel].A;
1081 
1082                         /* Call timestamp handler. */
1083                         Emios_Icu_Ip_TimestampHandler(instance, channel, &eMios_Icu_Ip_BufferPtr[u8ChIndex], bOverflow);
1084                     }
1085 #if (EMIOS_ICU_IP_TIMESTAMP_USES_DMA == STD_ON)
1086                     else
1087                     {
1088                         /* Note: - look if the existing EMIOSs hardware need this branch. */
1089                         if(eMios_Icu_Ip_ChState[u8ChIndex].callback != NULL_PTR)
1090                         {
1091                             eMios_Icu_Ip_ChState[u8ChIndex].callback(eMios_Icu_Ip_ChState[u8ChIndex].callbackParam, bOverflow);
1092                         }
1093                     }
1094 #endif
1095                 }
1096                 break;
1097 #endif /* EMIOS_ICU_IP_TIMESTAMP_API == STD_ON */
1098 
1099 #if (EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON)
1100                 case EMIOS_ICU_MODE_SIGNAL_MEASUREMENT:
1101                 {
1102                     Emios_Icu_Ip_SignalMeasurementHandler(instance, channel, bOverflow);
1103                 }
1104                 break;
1105 #endif
1106 #if (EMIOS_ICU_IP_EDGE_COUNT_API == STD_ON)
1107                 case EMIOS_ICU_MODE_EDGE_COUNTER:
1108                 {
1109                     /* Calling HLD Report Wakeup and Overflow for the logical channel */
1110                     /* Note: - actual version of emios does not have IRQ for overflow, in some configuration this will not get executed */
1111                     Emios_Icu_Ip_ReportOverflow(instance, channel, TRUE);
1112                 }
1113                 break;
1114 #endif
1115                 default:
1116                 {
1117                     /* Rule 16.1 requires switch well-formed */
1118                 }
1119                 break;
1120             }
1121         }
1122         else
1123         {
1124             /* Nothing to do */
1125         }
1126     }
1127 #if ((EMIOS_ICU_IP_TIMESTAMP_API == STD_ON)||(EMIOS_ICU_IP_SIGNAL_MEASUREMENT_API == STD_ON))
1128     else if ((uint8)EMIOS_ICU_IP_MASTERBUS_CHANNEL_USED == u8ChIndex)
1129     {
1130         if(((0U == (channel & (uint8)EMIOS_ICU_IP_CB_DIVERSE)) || (EMIOS_ICU_IP_CHANNEL_22 == channel) || (EMIOS_ICU_IP_CHANNEL_23 == channel)) \
1131             && (EMIOS_ICU_IP_MCB_INT_CLOCK_U32 == (u32RegCCR & eMIOS_C_MODE_MASK)))
1132         {
1133             Emios_Icu_Ip_ProcessMasterBusInterrupt(instance, channel);
1134         }
1135     }
1136 #endif
1137     else
1138     {
1139         /* Nothing to do */
1140     }
1141 }
1142 
1143 #if (STD_ON == EMIOS_ICU_IP_TIMESTAMP_USES_DMA_IPL)
1144 /*   @implements  Emios_Icu_Ip_TimestampDmaProcessing */
Emios_Icu_Ip_TimestampDmaProcessing(uint8 instance,uint8 hwChannel)1145 void Emios_Icu_Ip_TimestampDmaProcessing(uint8 instance, uint8 hwChannel)
1146 {
1147     uint32 crtIterCount;
1148     uint16 noOfBufferElemToFill = 0U;
1149 
1150     Dma_Ip_LogicChannelTransferListType Dma_IpChUpdateDestAddress[1U];
1151     Dma_Ip_LogicChannelTransferListType Dma_IpChUpdateIterCount[2U];
1152 
1153     Dma_Ip_GetLogicChannelParam(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, DMA_IP_CH_GET_BEGIN_ITER_COUNT, &crtIterCount);
1154 
1155     eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex += (uint16)crtIterCount;
1156     noOfBufferElemToFill = eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferSize - eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex;
1157 
1158     /* Handling notification*/
1159     if (0U != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify)
1160     {
1161         eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount += (uint16)crtIterCount;
1162         if  (eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount == eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify)
1163         {
1164             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount = 0U;
1165             /* Call User Notification Function and/or Wakeup Function */
1166             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMiosChannelNotification();
1167         }
1168     }
1169 
1170     if (0U == noOfBufferElemToFill)
1171     {
1172         if ((uint8) EMIOS_ICU_CIRCULAR_BUFFER ==  eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].timestampBufferType)
1173         {
1174             eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferIndex = 0U;
1175             if ((eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify < eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferSize) &&
1176             (0U != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify))
1177             {
1178                 Dma_IpChUpdateDestAddress[0U].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
1179                 Dma_IpChUpdateDestAddress[0U].Value = (uint32)eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBuffer;
1180                 Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateDestAddress, 1U);
1181             }
1182 
1183             if ((eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferSize > (eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify - eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount)) &&
1184                 (0U != eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify))
1185             {
1186                 Dma_IpChUpdateIterCount[0U].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1187                 Dma_IpChUpdateIterCount[0U].Value = (uint32)eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify - (uint32)eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aNotifyCount;
1188                 Dma_IpChUpdateIterCount[1U].Param = DMA_IP_CH_SET_DESTINATION_SIGNED_LAST_ADDR_ADJ;
1189                 Dma_IpChUpdateIterCount[1U].Value = (uint32)0U;
1190                 Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateIterCount, 2U);
1191             }
1192         }
1193         else /* if linear buffer stop the timestamp*/
1194         {
1195             Emios_Icu_Ip_StopTimestamp(instance, hwChannel);
1196         }
1197     }
1198     else
1199     {
1200         if (crtIterCount < eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify)
1201         {
1202             Dma_IpChUpdateIterCount[0U].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1203             Dma_IpChUpdateIterCount[0U].Value = eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify;
1204             Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateIterCount, 1U);
1205         }
1206         if (noOfBufferElemToFill < eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].eMios_Icu_Ip_aBufferNotify)
1207         {
1208             Dma_IpChUpdateIterCount[0U].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1209             Dma_IpChUpdateIterCount[0U].Value = noOfBufferElemToFill;
1210             Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateIterCount, 1U);
1211         }
1212     }
1213 }
1214 #endif /* (STD_ON == EMIOS_ICU_IP_TIMESTAMP_USES_DMA_IPL) */
1215 
1216 #if (STD_ON == EMIOS_ICU_IP_SIGNALMEASUREMENT_USES_DMA_IPL)
1217 /*   @implements  Emios_Icu_Ip_TimestampDmaProcessing */
Emios_Icu_Ip_SignalMeasurementDmaProcessing(uint8 instance,uint8 hwChannel)1218 void Emios_Icu_Ip_SignalMeasurementDmaProcessing(uint8 instance, uint8 hwChannel)
1219 {
1220     uint8 u8index;
1221     uint32 BufferValue1;
1222     uint32 BufferValue2;
1223     uint32 BufferValue3;
1224     Dma_Ip_LogicChannelTransferListType Dma_IpChUpdateDestAddress[1U];
1225     Dma_Ip_LogicChannelTransferListType Dma_IpChUpdateIterCount[1U];
1226 
1227     uint32 Emios_Icu_Ip_aActivePulseWidth;
1228     uint32 Emios_Icu_Ip_aPeriod;
1229 
1230     Dma_Ip_SetLogicChannelCommand(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, DMA_IP_CH_CLEAR_HARDWARE_REQUEST);
1231 
1232     if ((uint32)1 == Emios_Icu_Ip_aIsSecondInterrupt[eMios_Icu_Ip_IndexInChState[instance][hwChannel]])
1233     {
1234         BufferValue1 = Emios_Icu_Ip_aFirstEdgeTimeStamp[eMios_Icu_Ip_IndexInChState[instance][hwChannel]];
1235         BufferValue2 = Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][0];
1236         BufferValue3 = Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][1];
1237         Dma_IpChUpdateDestAddress[0U].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
1238         Dma_IpChUpdateDestAddress[0U].Value = (uint32)&Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][0];
1239         Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateDestAddress, 1U);
1240         Dma_Ip_SetLogicChannelCommand(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
1241 
1242         /* Store the aPeriod value */
1243 
1244         if(BufferValue2 > BufferValue1)
1245         {
1246             Emios_Icu_Ip_aActivePulseWidth = BufferValue2 - BufferValue1;
1247         }
1248         else
1249         {
1250             Emios_Icu_Ip_aActivePulseWidth = (EMIOS_ICU_IP_COUNTER_MASK - BufferValue1) + BufferValue2;
1251         }
1252 
1253         /* Store the aPeriod value */
1254         if(BufferValue3 > BufferValue1)
1255         {
1256             Emios_Icu_Ip_aPeriod =  BufferValue3 - BufferValue1;
1257         }
1258         else
1259         {
1260             Emios_Icu_Ip_aPeriod = (EMIOS_ICU_IP_COUNTER_MASK- BufferValue1) + BufferValue3;
1261         }
1262         Emios_Icu_Ip_SetPWandPeriod(instance, hwChannel, Emios_Icu_Ip_aActivePulseWidth, Emios_Icu_Ip_aPeriod);
1263 
1264         Emios_Icu_Ip_aFirstEdgeTimeStamp[eMios_Icu_Ip_IndexInChState[instance][hwChannel]] = Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][1];
1265     }
1266     else
1267     {
1268         Emios_Icu_Ip_aIsSecondInterrupt[eMios_Icu_Ip_IndexInChState[instance][hwChannel]] = (uint16)1;
1269         Emios_Icu_Ip_aFirstEdgeTimeStamp[eMios_Icu_Ip_IndexInChState[instance][hwChannel]] = Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][0];
1270         Dma_IpChUpdateDestAddress[0U].Param = DMA_IP_CH_SET_DESTINATION_ADDRESS;
1271         Dma_IpChUpdateDestAddress[0U].Value = (uint32)&Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][0];
1272         Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateDestAddress, 1U);
1273         Dma_IpChUpdateIterCount[0U].Param = DMA_IP_CH_SET_MAJORLOOP_COUNT;
1274         Dma_IpChUpdateIterCount[0U].Value = (uint16)EMIOS_ICU_IP_DMA_MAJORLOOP_COUNT;
1275         Dma_Ip_SetLogicChannelTransferList(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, Dma_IpChUpdateIterCount, 1U);
1276         Dma_Ip_SetLogicChannelCommand(eMios_Icu_Ip_ChState[eMios_Icu_Ip_IndexInChState[instance][hwChannel]].dmaChannel, DMA_IP_CH_SET_HARDWARE_REQUEST);
1277         for(u8index = 0U; u8index < EMIOS_ICU_IP_DMA_MAJORLOOP_COUNT; u8index++)
1278         {
1279             Emios_Icu_Ip_aDmaBuffer[eMios_Icu_Ip_IndexInChState[instance][hwChannel]][u8index] = (uint16)0;
1280         }
1281         Emios_Icu_Ip_SetActivation(instance, hwChannel, EMIOS_ICU_BOTH_EDGES);
1282     }
1283 }
1284 #endif
1285 
1286 #define ICU_STOP_SEC_CODE
1287 #include "Icu_MemMap.h"
1288 
1289 #endif  /* EMIOS_ICU_IP_USED */
1290 
1291 #ifdef __cplusplus
1292 }
1293 #endif
1294 
1295 /** @} */
1296