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