ic_pal.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2018 NXP
3  * All rights reserved.
4  *
5  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
6  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
9  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
11  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
12  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
13  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
14  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
15  * THE POSSIBILITY OF SUCH DAMAGE.
16  */
77 #include "ic_pal.h"
78 #include "interrupt_manager.h"
79 #include "ic_irq.h"
80 
81 /*******************************************************************************
82  * Variables
83  ******************************************************************************/
84 
85 /* Define state structures for IC PAL */
86 static ic_pal_state_t g_icPalStatePtr[NUMBER_OF_IC_PAL_INSTANCES];
87 
88 /* IC state-instance matching */
89 static uint32_t icStateInstanceMapping[NUMBER_OF_IC_PAL_INSTANCES];
90 /* IC available resources array */
91 static bool icStateIsAllocated[NUMBER_OF_IC_PAL_INSTANCES];
92 
93 #if (defined(IC_PAL_OVER_FTM))
94 /* The FTM state structures */
95 static ftm_state_t g_ftmState[NUMBER_OF_IC_PAL_INSTANCES];
96 #endif
97 
98 /*******************************************************************************
99  * Code
100  ******************************************************************************/
101 /*FUNCTION**********************************************************************
102  *
103  * Function Name : icAllocateState
104  * Description : Allocates one of the available state structure.
105  *
106  *END**************************************************************************/
107 static uint8_t icAllocateState(bool * isAllocated,
108  uint32_t * instanceMapping,
109  uint32_t instance)
110 {
111  uint8_t i;
112 
113  /* Allocate one of the IC state structure for this instance */
114  for (i = 0U;i < NUMBER_OF_IC_PAL_INSTANCES;i++)
115  {
116  if (isAllocated[i] == false)
117  {
118  instanceMapping[i] = instance;
119  isAllocated[i] = true;
120  break;
121  }
122  }
123 
124  return i;
125 }
126 
127 /*FUNCTION**********************************************************************
128  *
129  * Function Name : icFreeState
130  * Description : Deallocates one of the available state structure.
131  *
132  *END**************************************************************************/
133 static void icFreeState(bool * isAllocated,
134  const uint32_t * instanceMapping,
135  uint32_t instance)
136 {
137  uint8_t i;
138 
139  /* Allocate one of the IC state structure for this instance */
140  for (i = 0U;i < NUMBER_OF_IC_PAL_INSTANCES;i++)
141  {
142  if (instanceMapping[i] == instance)
143  {
144  isAllocated[i] = false;
145  break;
146  }
147  }
148 }
149 
150 /*FUNCTION**********************************************************************
151  *
152  * Function Name : FindIcState
153  * Description : Search the state structure of the instance for each IP
154  *
155  *END**************************************************************************/
156 static uint8_t FindIcState(uint32_t instance)
157 {
158  uint8_t i;
159 
160  for (i = 0U;i < NUMBER_OF_IC_PAL_INSTANCES;i++)
161  {
162  if (icStateInstanceMapping[i] == instance)
163  {
164  break;
165  }
166  }
167 
168  return i;
169 }
170 
171 #if (defined(IC_PAL_OVER_FTM))
172 /*FUNCTION**********************************************************************
173  *
174  * Function Name : IC_FtmInit
175  * Description : This function initializes IC_PAL over FTM.
176  *
177  *END**************************************************************************/
178 static status_t IC_FtmInit(uint32_t instance,
179  const ic_config_t * configPtr)
180 {
181  ic_pal_state_t * icState;
182  status_t status = STATUS_SUCCESS;
183  uint8_t index = 0U;
184 
185  /* Allocate one of the IC state structure for this instance */
186  index = FindIcState(instance);
187  icState = &g_icPalStatePtr[index];
188 
189  uint8_t channel = 0U;
190  ftm_pwm_sync_t sync;
191  ftm_user_config_t info;
192  ftm_state_t * ftmState = &g_ftmState[index];
193  ftm_input_param_t param;
195 
196  /* Configure the synchronous to default */
197  sync.softwareSync = true;
198  sync.hardwareSync0 = false;
199  sync.hardwareSync1 = false;
200  sync.hardwareSync2 = false;
201  sync.maxLoadingPoint = true;
202  sync.minLoadingPoint = false;
207  sync.autoClearTrigger = false;
208  sync.syncPoint = FTM_UPDATE_NOW;
209 
210  /* Get some information from user configuration */
211  info.syncMethod = sync;
213  info.ftmPrescaler = ((extension_ftm_for_ic_t *)(configPtr->extension))->ftmPrescaler;
214  info.ftmClockSource = ((extension_ftm_for_ic_t *)(configPtr->extension))->ftmClockSource;
215  info.BDMMode = FTM_BDM_MODE_11;
216  info.isTofIsrEnabled = false;
217  info.enableInitializationTrigger = false;
218 
219  /* Initializes the FTM driver */
220  status = FTM_DRV_Init(instance,
221  &info,
222  ftmState);
223  DEV_ASSERT(STATUS_SUCCESS == status);
224 
225  param.nNumChannels = configPtr->nNumChannels;
226  param.nMaxCountValue = MAX_COUNTER_VALUE;
227 
228  /* Configure a list of channels which are used */
229  for (index = 0U; index < configPtr->nNumChannels; index++)
230  {
231  /* Get the hardware channel ID */
232  channelConfig[index].hwChannelId = configPtr->inputChConfig[index].hwChannelId;
233  channel = channelConfig[index].hwChannelId;
234  /* Check the input capture operation mode */
235  if ((configPtr->inputChConfig[index].inputCaptureMode == IC_TIMESTAMP_RISING_EDGE) || \
236  (configPtr->inputChConfig[index].inputCaptureMode == IC_TIMESTAMP_FALLING_EDGE) || \
238  {
239  channelConfig[index].inputMode = FTM_EDGE_DETECT;
240  channelConfig[index].measurementType = FTM_NO_MEASUREMENT;
241  /* Check the type of signal detection */
243  {
244  channelConfig[index].edgeAlignement = FTM_RISING_EDGE;
245  }
246  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_TIMESTAMP_FALLING_EDGE)
247  {
248  channelConfig[index].edgeAlignement = FTM_FALLING_EDGE;
249  }
250  else
251  {
252  channelConfig[index].edgeAlignement = FTM_BOTH_EDGES;
253  }
254  }
255  else
256  {
257  /* Check the channel ID need to even number in the measurement mode */
258  DEV_ASSERT((channel % 2U) == 0U);
259  channelConfig[index].inputMode = FTM_SIGNAL_MEASUREMENT;
260  channelConfig[index].edgeAlignement = FTM_NO_PIN_CONTROL;
261  /* Check the type of measurement */
263  {
265  }
266  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_MEASURE_FALLING_EDGE_PERIOD)
267  {
269  }
270  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_MEASURE_PULSE_HIGH)
271  {
272  channelConfig[index].measurementType = FTM_PERIOD_ON_MEASUREMENT;
273  }
274  else
275  {
276  channelConfig[index].measurementType = FTM_PERIOD_OFF_MEASUREMENT;
277  }
278  }
279 
280  /* Set channels configuration from user */
281  channelConfig[index].filterEn = configPtr->inputChConfig[index].filterEn;
282  channelConfig[index].filterValue = configPtr->inputChConfig[index].filterValue;
283  channelConfig[index].continuousModeEn = ((channel_extension_ftm_for_ic_t *)(configPtr->inputChConfig[index].channelExtension))->continuousModeEn;
284  channelConfig[index].channelsCallbacksParams = configPtr->inputChConfig[index].channelCallbackParams;
285  channelConfig[index].channelsCallbacks = configPtr->inputChConfig[index].channelCallbacks;
286 
287  /* Store some needed information into state structure */
288  icState->channelConfigArray[index] = configPtr->inputChConfig[index].hwChannelId;
289  icState->icChannelType[channel] = configPtr->inputChConfig[index].inputCaptureMode;
290  icState->enableContinuousMode[channel] = channelConfig[index].continuousModeEn;
291  icState->enableNotification[channel] = true;
292  icState->channelCallbackParams[channel] = channelConfig[index].channelsCallbacksParams;
293  icState->channelCallbacks[channel] = channelConfig[index].channelsCallbacks;
294  }
295 
296  param.inputChConfig = channelConfig;
297  /* Configure channels in input capture mode */
298  status = FTM_DRV_InitInputCapture(instance,
299  &param);
300 
301  return status;
302 }
303 #endif
304 
305 #if (defined(IC_PAL_OVER_EMIOS))
306 /*FUNCTION**********************************************************************
307  *
308  * Function Name : IC_EmiosInit
309  * Description : This function initializes IC_PAL over EMIOS.
310  *
311  *END**************************************************************************/
312 static status_t IC_EmiosInit(uint32_t instance,
313  const ic_config_t * configPtr)
314 {
315  ic_pal_state_t * icState;
316  status_t status = STATUS_SUCCESS;
317  uint8_t index = 0U;
318  const IRQn_Type emiosIrq[eMIOS_INSTANCE_COUNT][(eMIOS_UC_COUNT / 2U)] = eMIOS_IRQS;
319 
320  /* Allocate one of the IC state structure for this instance */
321  index = FindIcState(instance);
322  icState = &g_icPalStatePtr[index];
323 
324  emios_common_param_t commonParam;
325  uint8_t channel = 0U;
326  uint8_t optionMode = 0U;
327  emios_bus_select_t timeBase = EMIOS_BUS_SEL_A;
328  emios_mc_mode_param_t mcParam;
329  emios_input_capture_param_t icParam;
330  emios_gpio_mode_param_t gpioParam;
331 
332  /* Get common parameters from user */
333  commonParam.allowDebugMode = false;
334  commonParam.lowPowerMode = false;
335  commonParam.clkDivVal = ((extension_emios_for_ic_t *)(configPtr->extension))->clkDivVal;
336  commonParam.enableGlobalPrescaler = ((extension_emios_for_ic_t *)(configPtr->extension))->enableGlobalPrescaler;
337  commonParam.enableGlobalTimeBase = ((extension_emios_for_ic_t *)(configPtr->extension))->enableGlobalTimeBase;
338 
339  /* Initialize the global for a eMIOS group */
340  EMIOS_DRV_InitGlobal((uint8_t)instance,
341  &commonParam);
342 
343  /* Get the information from user configuration */
344  mcParam.mode = EMIOS_MODE_MCB_UP_COUNTER_INT_CLK;
345  mcParam.period = MAX_COUNTER_VALUE;
346  mcParam.filterInput = EMIOS_INPUT_FILTER_BYPASS;
347  mcParam.filterEn = false;
348  mcParam.triggerMode = EMIOS_TRIGGER_EDGE_ANY;
349 
350  /* Configure a list of channels which are used */
351  for (index = 0U; index < configPtr->nNumChannels; index++)
352  {
353  mcParam.internalPrescaler = (emios_clock_internal_ps_t)((channel_extension_emios_for_ic_t *)(configPtr->inputChConfig[index].channelExtension))->prescaler;
354  mcParam.internalPrescalerEn = true;
355 
356  switch (((channel_extension_emios_for_ic_t *)(configPtr->inputChConfig[index].channelExtension))->timebase)
357  {
358  case IC_BUS_SEL_A:
359  /* Set channel to use as a time base */
360  channel = 23U;
361  timeBase = EMIOS_BUS_SEL_A;
362  break;
363  case IC_BUS_SEL_B:
364  /* Set channel to use as a time base */
365  channel = 0U;
366  timeBase = EMIOS_BUS_SEL_BCDE;
367  break;
368  case IC_BUS_SEL_C:
369  /* Set channel to use as a time base */
370  channel = 8U;
371  timeBase = EMIOS_BUS_SEL_BCDE;
372  break;
373  case IC_BUS_SEL_D:
374  /* Set channel to use as a time base */
375  channel = 16U;
376  timeBase = EMIOS_BUS_SEL_BCDE;
377  break;
378  case IC_BUS_SEL_E:
379  /* Set channel to use as a time base */
380  channel = 24U;
381  timeBase = EMIOS_BUS_SEL_BCDE;
382  break;
383  case IC_BUS_SEL_F:
384  /* Set channel to use as a time base */
385  channel = 22U;
386  timeBase = EMIOS_BUS_SEL_F;
387  break;
388  case IC_BUS_SEL_INTERNAL:
389  /* Set channel to use as a time base */
390  channel = configPtr->inputChConfig[index].hwChannelId;
391  timeBase = EMIOS_BUS_SEL_INTERNAL;
392  break;
393  default:
394  /* Do nothing */
395  break;
396  }
397 
398  /* Initialize the counter mode */
399  status = EMIOS_DRV_MC_InitCounterMode((uint8_t)instance,
400  channel,
401  &mcParam);
402 
403  channel = configPtr->inputChConfig[index].hwChannelId;
404  icParam.mode = EMIOS_MODE_IC;
405  icParam.timebase = timeBase;
406  icParam.filterInput = (emios_input_filter_t)(configPtr->inputChConfig[index].filterValue);
407  icParam.filterEn = configPtr->inputChConfig[index].filterEn;
408 
410  {
411  icParam.inputCaptureMode = EMIOS_CAPTURE_TRIGGER_EDGE_RISING;
412  }
413  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_TIMESTAMP_FALLING_EDGE)
414  {
415  icParam.inputCaptureMode = EMIOS_CAPTURE_TRIGGER_EDGE_FALLING;
416  }
417  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_DISABLE_OPERATION)
418  {
419  /* Set default configure for an input pin */
420  gpioParam.mode = EMIOS_MODE_GPIO_INPUT;
421  gpioParam.filterEn = false;
422  gpioParam.filterInput = EMIOS_INPUT_FILTER_BYPASS;
423  gpioParam.triggerMode = EMIOS_TRIGGER_EDGE_ANY;
424 
425  /* Disable operation on the channel input */
426  EMIOS_DRV_InitGpioMode((uint8_t)instance,
427  channel,
428  &gpioParam);
429  }
430  else
431  {
432  optionMode = (uint8_t)configPtr->inputChConfig[index].inputCaptureMode - 1U;
433  icParam.inputCaptureMode = (emios_input_capture_mode_t)optionMode;
434  }
435 
436  if (configPtr->inputChConfig[index].inputCaptureMode != IC_DISABLE_OPERATION)
437  {
438  /* Initialize the input capture mode for each channel */
439  status = EMIOS_DRV_IC_InitInputCaptureMode((uint8_t)instance,
440  channel,
441  &icParam);
442  }
443 
444  EMIOS_DRV_ChannelEnableInterruptRequest((uint8_t)instance, channel);
445  /* Enable EMIOS interrupt */
446  INT_SYS_EnableIRQ(emiosIrq[instance][(channel>>1U)]);
447 
448  /* Store some needed information into state structure */
449  icState->channelConfigArray[index] = channel;
450  icState->icChannelType[channel] = configPtr->inputChConfig[index].inputCaptureMode;
451  icState->timeBaseSelection[channel] = icParam.timebase;
452  icState->filterEn[channel] = icParam.filterEn;
453  icState->filterInput[channel] = icParam.filterInput;
454  icState->enableNotification[channel] = true;
455  icState->channelCallbackParams[channel] = configPtr->inputChConfig[index].channelCallbackParams;
456  icState->channelCallbacks[channel] = configPtr->inputChConfig[index].channelCallbacks;
457  }
458 
459  /* Enable the global eMIOS to start counter */
460  EMIOS_DRV_EnableGlobalEmios((uint8_t)instance);
461 
462  return status;
463 }
464 #endif
465 
466 #if (defined(IC_PAL_OVER_ETIMER))
467 /*FUNCTION**********************************************************************
468  *
469  * Function Name : IC_EtimerInit
470  * Description : This function initializes the input capture mode over ETIMER.
471  *
472  *END**************************************************************************/
473 static status_t IC_EtimerInit(uint32_t instance,
474  const ic_config_t * configPtr)
475 {
476  status_t status = STATUS_SUCCESS;
477  uint8_t index = 0U;
478  uint8_t i = 0U;
479  uint16_t channel = 0U;
480  uint16_t maskChannel = 0U;
481  etimer_cptmode_t capCtr[ETIMER_NUM_COMPARE_REGISTERS];
482  ic_pal_state_t * icState;
483  static const IRQn_Type etimerIrqId[ETIMER_INSTANCE_COUNT][ETIMER_CH_MAX_IRQS] = ETIMER_IRQS;
484 
485  /* Allocate one of the IC state structure for this instance */
486  index = FindIcState(instance);
487  icState = &g_icPalStatePtr[index];
488 
489  etimer_user_channel_config_t userChannelConfig;
490 
491  /* Initialize the ETIMER module */
492  ETIMER_DRV_Init((uint16_t)instance);
493 
494  userChannelConfig.coreSettings = ETIMER_COUNTER_NORMAL;
495  userChannelConfig.outputPin.enable = false;
496  userChannelConfig.outputPin.polarity = ETIMER_POLARITY_POSITIVE;
497  userChannelConfig.countDirection = ETIMER_COUNT_UP;
498  userChannelConfig.compareOutputControl = ETIMER_OUTMODE_SOFTWARE;
499  userChannelConfig.compareMode = ETIMER_CMPMODE_COMP1_UP_COMP2_UP;
500  userChannelConfig.primaryInput.polarity = ETIMER_POLARITY_POSITIVE;
501  userChannelConfig.secondaryInput.polarity = ETIMER_POLARITY_POSITIVE;
502 
503  for (index = 0U; index < ETIMER_NUM_COMPARE_REGISTERS; index++)
504  {
505  userChannelConfig.compareValues[index] = 0U;
506  userChannelConfig.compareLoading[index] = ETIMER_CLC_NEVER;
507  capCtr[index] = ETIMER_CPTMODE_DISABLED;
508  }
509 
510  /* Configure a list of channels which are used */
511  for (index = 0U; index < configPtr->nNumChannels; index++)
512  {
513  channel = configPtr->inputChConfig[index].hwChannelId;
514  maskChannel |= (uint16_t)(1U << channel);
515 
516  if (((channel_extension_etimer_for_ic_t *)configPtr->inputChConfig[index].channelExtension)->continuousModeEn == true)
517  {
518  userChannelConfig.timerMode = ETIMER_MODE_INPUT_CAPTURE;
519  }
520  else
521  {
522  userChannelConfig.timerMode = ETIMER_MODE_INPUT_CAPTURE_ONESHOT;
523  }
524 
525  if (configPtr->inputChConfig[index].filterEn)
526  {
527  userChannelConfig.inputFilter.samples = (etimer_filt_cnt_t)configPtr->inputChConfig[index].filterValue;
528  userChannelConfig.inputFilter.rate = ((channel_extension_etimer_for_ic_t *)configPtr->inputChConfig[index].channelExtension)->rate;
529  }
530 
531  userChannelConfig.primaryInput.source = (etimer_input_source_t)(((channel_extension_etimer_for_ic_t *)configPtr->inputChConfig[index].channelExtension)->prescaler);;
532  userChannelConfig.secondaryInput.source = (etimer_input_source_t)channel;
533  userChannelConfig.captureWords = 1U;
534  userChannelConfig.interruptEnableMask = ETIMER_CH_IRQ_SOURCE_ICF1IE;
535 
536  /* Check the type of measurement */
538  {
539  capCtr[0] = ETIMER_CPTMODE_RISING;
540  }
541  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_TIMESTAMP_FALLING_EDGE)
542  {
543  capCtr[0] = ETIMER_CPTMODE_FALLING;
544  }
545  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_TIMESTAMP_BOTH_EDGES)
546  {
547  capCtr[0] = ETIMER_CPTMODE_BOTH;
548  }
549  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_MEASURE_RISING_EDGE_PERIOD)
550  {
551  capCtr[0] = ETIMER_CPTMODE_RISING;
552  userChannelConfig.captureWords = 2U;
553  }
554  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_MEASURE_FALLING_EDGE_PERIOD)
555  {
556  capCtr[0] = ETIMER_CPTMODE_FALLING;
557  userChannelConfig.captureWords = 2U;
558  }
559  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_MEASURE_PULSE_HIGH)
560  {
561  capCtr[0] = ETIMER_CPTMODE_RISING;
562  capCtr[1] = ETIMER_CPTMODE_FALLING;
563  userChannelConfig.interruptEnableMask = ETIMER_CH_IRQ_SOURCE_ICF2IE;
564  }
565  else if (configPtr->inputChConfig[index].inputCaptureMode == IC_MEASURE_PULSE_LOW)
566  {
567  capCtr[0] = ETIMER_CPTMODE_FALLING;
568  capCtr[1] = ETIMER_CPTMODE_RISING;
569  userChannelConfig.interruptEnableMask = ETIMER_CH_IRQ_SOURCE_ICF2IE;
570  }
571  else
572  {
573  /* Nothing to do */
574  }
575 
576  for (i = 0U; i < ETIMER_NUM_COMPARE_REGISTERS; i++)
577  {
578  userChannelConfig.captureControl[i] = capCtr[i];
579  }
580 
581  /* Initialize the channel at the input capture mode */
582  ETIMER_DRV_InitChannel((uint16_t)instance, channel, &userChannelConfig);
583  /* Enable the input capture */
584  ETIMER_DRV_StartCapture((uint16_t)instance, channel);
585  /* Enable interrupt on channel */
586  INT_SYS_EnableIRQ(etimerIrqId[instance][channel]);
587 
588  /* Store some needed information into state structure */
589  icState->channelConfigArray[index] = channel;
590  icState->icChannelType[channel] = configPtr->inputChConfig[index].inputCaptureMode;
591  icState->enableNotification[channel] = true;
592  icState->channelCallbackParams[channel] = configPtr->inputChConfig[index].channelCallbackParams;
593  icState->channelCallbacks[channel] = configPtr->inputChConfig[index].channelCallbacks;
594  }
595 
596  /* Start the channel counting */
597  ETIMER_DRV_StartTimerChannels((uint16_t)instance, maskChannel);
598 
599  return status;
600 }
601 
602 /*FUNCTION**********************************************************************
603  *
604  * Function Name : IC_Etimer_SetChannelMode
605  * Description : This function will change the mode operation in the input capture.
606  *
607  *END**************************************************************************/
608 static void IC_Etimer_SetChannelMode(uint32_t instance,
609  uint8_t channel,
610  ic_option_mode_t channelMode)
611 {
612  DEV_ASSERT(instance < ETIMER_INSTANCE_COUNT);
613  DEV_ASSERT(channel < ETIMER_CH_COUNT);
614  /* Table of base addresses for ETIMER instances */
615  static ETIMER_Type * const s_etimerBase[ETIMER_INSTANCE_COUNT] = ETIMER_BASE_PTRS;
616  ETIMER_Type * base;
617  base = s_etimerBase[instance];
618  uint8_t captureWords = 1U;
619  etimer_cptmode_t captureControl[2] = { ETIMER_CPTMODE_DISABLED, ETIMER_CPTMODE_DISABLED };
620  base->CH[channel].INTDMA &= ~(ETIMER_CH_IRQ_FLAGS_ICF1 | ETIMER_CH_IRQ_FLAGS_ICF2);
621 
622  switch (channelMode)
623  {
625  captureControl[0] = ETIMER_CPTMODE_RISING;
626  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF1;
627  break;
629  captureControl[0] = ETIMER_CPTMODE_FALLING;
630  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF1;
631  break;
633  captureControl[0] = ETIMER_CPTMODE_BOTH;
634  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF1;
635  break;
637  captureControl[0] = ETIMER_CPTMODE_RISING;
638  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF1;
639  captureWords = 2U;
640  break;
642  captureControl[0] = ETIMER_CPTMODE_FALLING;
643  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF1;
644  captureWords = 2U;
645  break;
647  captureControl[0] = ETIMER_CPTMODE_RISING;
648  captureControl[1] = ETIMER_CPTMODE_FALLING;
649  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF2;
650  break;
652  captureControl[0] = ETIMER_CPTMODE_FALLING;
653  captureControl[1] = ETIMER_CPTMODE_RISING;
654  base->CH[channel].INTDMA |= ETIMER_CH_IRQ_FLAGS_ICF2;
655  break;
656  default:
657  /* nothing to do */
658  break;
659  }
660 
661  /* Capture counter value using external inputs */
662  base->CH[channel].CCCTRL &= ((~ETIMER_CCCTRL_CFWM_MASK) & (~ETIMER_CCCTRL_CPT1MODE_MASK) & (~ETIMER_CCCTRL_CPT2MODE_MASK));
663  base->CH[channel].CCCTRL |= ETIMER_CCCTRL_CFWM(captureWords) | ETIMER_CCCTRL_CPT1MODE(captureControl[0]) | ETIMER_CCCTRL_CPT2MODE(captureControl[1]);
664 }
665 #endif
666 
667 /*FUNCTION**********************************************************************
668  *
669  * Function Name : IC_Init
670  * Description : This function will initialize the IC PAL instance, including the
671  * other platform specific HW units used together in the input capture mode. This
672  * function configures a group of channels in instance to detect or measure the
673  * input signal.
674  *
675  * Implements : IC_Init_Activity
676  *END**************************************************************************/
677 status_t IC_Init(const ic_instance_t * const instance,
678  const ic_config_t * configPtr)
679 {
680  DEV_ASSERT(configPtr != NULL);
681  DEV_ASSERT(instance != NULL);
682  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
683  ic_pal_state_t * icState;
684  status_t status = STATUS_SUCCESS;
685  uint8_t index = 0U;
686 
687  /* Allocate one of the IC state structure for this instance */
689  icState = &g_icPalStatePtr[index];
690  DEV_ASSERT(icState->nNumChannels == 0x0U);
691 
692  /* Initialize the internal context to default value */
693  icState->nNumChannels = configPtr->nNumChannels;
694  for (index = 0U; index < IC_PAL_NUM_OF_CHANNEL_MAX; index++)
695  {
696  icState->channelConfigArray[index] = 0U;
697  icState->icChannelType[index] = IC_DISABLE_OPERATION;
698  icState->enableNotification[index] = false;
699  icState->channelCallbackParams[index] = NULL;
700  icState->channelCallbacks[index] = NULL;
701  #if (defined(IC_PAL_OVER_FTM))
702  icState->enableContinuousMode[index] = false;
703  #endif
704  #if (defined(IC_PAL_OVER_ETIMER))
705  icState->measurementResults[index] = 0U;
706  #endif
707  }
708 
709 #if (defined(IC_PAL_OVER_FTM))
710  DEV_ASSERT(instance->instType == IC_INST_TYPE_FTM);
711  status = IC_FtmInit(instance->instIdx, configPtr);
712 #endif
713 
714 #if (defined(IC_PAL_OVER_EMIOS))
715  DEV_ASSERT(instance->instType == IC_INST_TYPE_EMIOS);
716  status = IC_EmiosInit(instance->instIdx, configPtr);
717 #endif
718 
719 #if (defined(IC_PAL_OVER_ETIMER))
720  DEV_ASSERT(instance->instType == IC_INST_TYPE_ETIMER);
721  status = IC_EtimerInit(instance->instIdx, configPtr);
722 #endif
723 
724  return status;
725 }
726 
727 /*FUNCTION**********************************************************************
728  *
729  * Function Name : IC_Deinit
730  * Description : This function will disable the input capture mode. The driver
731  * can't be used again until reinitialized. The context structure is no longer
732  * needed by the driver and can be freed after calling this function.
733  *
734  * Implements : IC_Deinit_Activity
735  *END**************************************************************************/
736 status_t IC_Deinit(const ic_instance_t * const instance)
737 {
738  DEV_ASSERT(instance != NULL);
739  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
740  uint8_t index = 0U;
741  ic_pal_state_t * icState;
742 
743  /* Allocate one of the IC state structure for this instance */
744  index = FindIcState(instance->instIdx);
745  icState = &g_icPalStatePtr[index];
746 
747 #if (defined(IC_PAL_OVER_FTM))
748  DEV_ASSERT(instance->instType == IC_INST_TYPE_FTM);
749  /* Disable the input capture over FTM */
750  (void)FTM_DRV_Deinit(instance->instIdx);
751  ftm_state_t * ftmState = &g_ftmState[index];
752 #endif
753 
754 #if (defined(IC_PAL_OVER_EMIOS))
755  DEV_ASSERT(instance->instType == IC_INST_TYPE_EMIOS);
756  uint8_t channel;
757 
758  for (index = 0U; index < icState->nNumChannels; index++)
759  {
760  channel = icState->channelConfigArray[index];
761  /* Disable channels in the input capture over EMIOS */
762  EMIOS_DRV_DeInitChannel((uint8_t)instance->instIdx,
763  channel);
764  }
765 
766  /* Disable the global of EMIOS */
767  EMIOS_DRV_DisableGlobalEmios((uint8_t)instance->instIdx);
768 #endif
769 
770 #if (defined(IC_PAL_OVER_ETIMER))
771  DEV_ASSERT(instance->instType == IC_INST_TYPE_ETIMER);
772  /* Disable the input capture over ETIMER */
773  ETIMER_DRV_Deinit((uint16_t)instance->instIdx);
774 #endif
775 
776  /* De-Initialize the internal context to default value */
777  icState->nNumChannels = 0U;
778  for (index = 0U; index < IC_PAL_NUM_OF_CHANNEL_MAX; index++)
779  {
780  icState->channelConfigArray[index] = 0U;
781  icState->icChannelType[index] = IC_DISABLE_OPERATION;
782  icState->enableNotification[index] = false;
783  #if (defined(IC_PAL_OVER_FTM))
784  icState->enableContinuousMode[index] = false;
785  ftmState->enableNotification[index] = false;
786  #endif
787  #if (defined(IC_PAL_OVER_ETIMER))
788  icState->measurementResults[index] = 0U;
789  #endif
790  }
791 
792  /* De-Allocate the instance which is not used */
794 
795  return STATUS_SUCCESS;
796 }
797 
798 /*FUNCTION**********************************************************************
799  *
800  * Function Name : IC_StartChannel
801  * Description : This function start channel counting.
802  *
803  * Implements : IC_StartChannel_Activity
804  *END**************************************************************************/
805 void IC_StartChannel(const ic_instance_t * const instance,
806  uint8_t channel)
807 {
808  DEV_ASSERT(instance != NULL);
809  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
810  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
811 
812 #if (defined(IC_PAL_OVER_FTM))
813  uint8_t index = 0U;
814  const ic_pal_state_t * icState;
815  status_t status = STATUS_SUCCESS;
816 
817  /* Allocate one of the IC state structure for this instance */
818  index = FindIcState(instance->instIdx);
819  icState = &g_icPalStatePtr[index];
820 
821  /* Re-start the channel mode */
822  status = IC_SetChannelMode(instance,
823  channel,
824  icState->icChannelType[channel]);
825  (void)status;
826 #endif
827 
828 #if (defined(IC_PAL_OVER_EMIOS))
829  /* Enable the channel clock */
830  EMIOS_DRV_ChannelEnableClk((uint8_t)instance->instIdx,
831  channel);
832 #endif
833 
834 #if (defined(IC_PAL_OVER_ETIMER))
835  ETIMER_DRV_StartCapture((uint16_t)instance->instIdx,
836  (uint16_t)channel);
837  ETIMER_DRV_StartTimerChannels((uint16_t)instance->instIdx,
838  (uint16_t)(1U << channel));
839 #endif
840 }
841 
842 /*FUNCTION**********************************************************************
843  *
844  * Function Name : IC_StopChannel
845  * Description : This function will stop channel counting.
846  *
847  * Implements : IC_StopChannel_Activity
848  *END**************************************************************************/
849 void IC_StopChannel(const ic_instance_t * const instance,
850  uint8_t channel)
851 {
852  DEV_ASSERT(instance != NULL);
853  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
854  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
855 
856 #if (defined(IC_PAL_OVER_FTM))
857  /* Disable pin not used for FTM */
858  (void)FTM_DRV_SetOutputlevel(instance->instIdx,
859  channel,
860  0x0U);
861 #endif
862 
863 #if (defined(IC_PAL_OVER_EMIOS))
864  /* Disable individual channel by stopping its respective clock*/
865  EMIOS_DRV_ChannelDisableClk((uint8_t)instance->instIdx,
866  channel);
867 #endif
868 
869 #if (defined(IC_PAL_OVER_ETIMER))
870  ETIMER_DRV_StopCapture((uint16_t)instance->instIdx,
871  (uint16_t)channel);
872  ETIMER_DRV_StopTimerChannels((uint16_t)instance->instIdx,
873  (uint16_t)(1U << channel));
874 #endif
875 }
876 
877 /*FUNCTION**********************************************************************
878  *
879  * Function Name : IC_SetChannelMode
880  * Description : This function is used to change the channel mode at run time or
881  * when stopping channel. The channel mode is selected in the ic_option_mode_t
882  * enumeration type.
883  *
884  * Implements : IC_SetChannelMode_Activity
885  *END**************************************************************************/
886 status_t IC_SetChannelMode(const ic_instance_t * const instance,
887  uint8_t channel,
888  ic_option_mode_t channelMode)
889 {
890  DEV_ASSERT(instance != NULL);
891  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
892  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
893  uint8_t index = 0U;
894  ic_pal_state_t * icState;
895  status_t status = STATUS_SUCCESS;
896 
897  /* Allocate one of the IC state structure for this instance */
898  index = FindIcState(instance->instIdx);
899  icState = &g_icPalStatePtr[index];
900 
901 #if (defined(IC_PAL_OVER_FTM))
902  bool contModeEnable;
903  index = (uint8_t)channelMode;
904  ftm_ic_op_mode_t inputMode = (ftm_ic_op_mode_t)index;
905 
906  if (true == icState->enableContinuousMode[channel])
907  {
908  contModeEnable = true;
909  }
910  else
911  {
912  contModeEnable = false;
913  }
914 
915  /* Set operation mode for channel input */
916  status = FTM_IC_DRV_SetChannelMode(instance->instIdx,
917  channel,
918  inputMode,
919  contModeEnable);
920 #endif
921 
922 #if (defined(IC_PAL_OVER_EMIOS))
923  emios_input_capture_param_t icParam;
924  emios_gpio_mode_param_t gpioParam;
925  uint8_t optionMode = 0U;
926 
927  if (channelMode == IC_DISABLE_OPERATION)
928  {
929  /* Set default configure for an input pin */
930  gpioParam.mode = EMIOS_MODE_GPIO_INPUT;
931  gpioParam.filterEn = false;
932  gpioParam.filterInput = EMIOS_INPUT_FILTER_BYPASS;
933  gpioParam.triggerMode = EMIOS_TRIGGER_EDGE_ANY;
934 
935  /* Disable operation on the channel input */
936  EMIOS_DRV_InitGpioMode((uint8_t)instance->instIdx,
937  channel,
938  &gpioParam);
939  }
940  else
941  {
942  icParam.mode = EMIOS_MODE_IC;
943  icParam.timebase = icState->timeBaseSelection[channel];
944  icParam.filterInput = icState->filterInput[channel];
945  icParam.filterEn = icState->filterEn[channel];
946 
947  if (channelMode == IC_TIMESTAMP_RISING_EDGE)
948  {
949  icParam.inputCaptureMode = EMIOS_CAPTURE_TRIGGER_EDGE_RISING;
950  }
951  else if (channelMode == IC_TIMESTAMP_FALLING_EDGE)
952  {
953  icParam.inputCaptureMode = EMIOS_CAPTURE_TRIGGER_EDGE_FALLING;
954  }
955  else
956  {
957  optionMode = (uint8_t)(channelMode) - 1U;
958  icParam.inputCaptureMode = (emios_input_capture_mode_t)optionMode;
959  }
960 
961  /* Initialize the input capture mode for each channel */
962  status = EMIOS_DRV_IC_InitInputCaptureMode((uint8_t)instance->instIdx,
963  channel,
964  &icParam);
965  }
966 #endif
967 
968 #if (defined(IC_PAL_OVER_ETIMER))
969  IC_Etimer_SetChannelMode(instance->instIdx,
970  channel,
971  channelMode);
972 #endif
973 
974  /* Update the channel mode */
975  icState->icChannelType[channel] = channelMode;
976 
977  return status;
978 }
979 
980 /*FUNCTION**********************************************************************
981  *
982  * Function Name : IC_GetMeasurement
983  * Description : This function will get the value of measured signal in ticks.
984  *
985  * Implements : IC_GetMeasurement_Activity
986  *END**************************************************************************/
987 uint16_t IC_GetMeasurement(const ic_instance_t * const instance,
988  uint8_t channel)
989 {
990  DEV_ASSERT(instance != NULL);
991  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
992  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
993  uint16_t value = 0U;
994 
995 #if (defined(IC_PAL_OVER_FTM))
996  /* Get the measured value over the FTM */
998  channel);
999 #endif
1000 
1001 #if (defined(IC_PAL_OVER_EMIOS))
1002  status_t status = STATUS_SUCCESS;
1003  uint32_t retValue = 0U;
1004 
1005  /* Get the measured value over the EMIOS */
1006  status = EMIOS_DRV_IC_GetLastMeasurement((uint8_t)instance->instIdx,
1007  channel,
1008  &retValue);
1009  DEV_ASSERT(STATUS_SUCCESS == status);
1010  (void) status;
1011  value = (uint16_t)retValue;
1012 #endif
1013 
1014 #if (defined(IC_PAL_OVER_ETIMER))
1015  uint8_t index = 0U;
1016  const ic_pal_state_t * icState;
1017 
1018  /* Allocate one of the IC state structure for this instance */
1019  index = FindIcState(instance->instIdx);
1020  icState = &g_icPalStatePtr[index];
1021 
1022  value = icState->measurementResults[channel];
1023 #endif
1024 
1025  return value;
1026 }
1027 
1028 /*FUNCTION**********************************************************************
1029  *
1030  * Function Name : IC_EnableNotification
1031  * Description : This function enables channel notification.
1032  *
1033  * Implements : IC_EnableNotification_Activity
1034  *END**************************************************************************/
1035 void IC_EnableNotification(const ic_instance_t * const instance,
1036  uint8_t channel)
1037 {
1038  DEV_ASSERT(instance != NULL);
1039  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
1040  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
1041  uint8_t index = 0U;
1042  ic_pal_state_t * icState;
1043 
1044  /* Allocate one of the IC state structure for this instance */
1045  index = FindIcState(instance->instIdx);
1046  icState = &g_icPalStatePtr[index];
1047 
1048  /* Enable notification */
1049  icState->enableNotification[channel] = true;
1050 
1051 #if (defined(IC_PAL_OVER_FTM))
1052  ftm_state_t * ftmState = ftmStatePtr[instance->instIdx];
1053  ftmState->enableNotification[channel] = true;
1054 #endif
1055 }
1056 
1057 /*FUNCTION**********************************************************************
1058  *
1059  * Function Name : IC_DisableNotification
1060  * Description : This function disables channel notification.
1061  *
1062  * Implements : IC_DisableNotification_Activity
1063  *END**************************************************************************/
1064 void IC_DisableNotification(const ic_instance_t * const instance,
1065  uint8_t channel)
1066 {
1067  DEV_ASSERT(instance != NULL);
1068  DEV_ASSERT(instance->instIdx < IC_PAL_INSTANCE_MAX);
1069  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
1070  uint8_t index = 0U;
1071  ic_pal_state_t * icState;
1072 
1073  /* Allocate one of the IC state structure for this instance */
1074  index = FindIcState(instance->instIdx);
1075  icState = &g_icPalStatePtr[index];
1076 
1077  /* Disable notification */
1078  icState->enableNotification[channel] = false;
1079 
1080 #if (defined(IC_PAL_OVER_FTM))
1081  ftm_state_t * ftmState = ftmStatePtr[instance->instIdx];
1082  ftmState->enableNotification[channel] = false;
1083 #endif
1084 }
1085 
1086 /*FUNCTION**********************************************************************
1087  *
1088  * Function Name : IC_IrqHandler
1089  * Description : Interrupt handler for IC PAL over EMIOS.
1090  * This is not a public API as it is called by IRQ whenever an interrupt occurs.
1091  *
1092  *END**************************************************************************/
1093 void IC_IrqHandler(uint32_t instance, uint8_t channel)
1094 {
1095  DEV_ASSERT(instance < IC_PAL_INSTANCE_MAX);
1096  DEV_ASSERT(channel < IC_PAL_NUM_OF_CHANNEL_MAX);
1097  uint8_t index = 0U;
1098 #if (defined (IC_PAL_OVER_ETIMER))
1099  ic_pal_state_t * icState;
1100 #else
1101  const ic_pal_state_t * icState;
1102 #endif
1103 
1104  /* Allocate one of the IC state structure for this instance */
1105  index = FindIcState(instance);
1106  icState = &g_icPalStatePtr[index];
1107 
1108 #if (defined (IC_PAL_OVER_ETIMER))
1109  uint16_t value = 0U;
1110  uint16_t captureRegister = 0U;
1111  uint16_t captureResultBuffer1[2] = {0U, 0U};
1112  uint16_t captureResultBuffer2[2] = {0U, 0U};
1113  uint8_t captureWordsToRead = 1U;
1114  uint16_t returnCode = 0U;
1115 
1116  if ((icState->icChannelType[channel] == IC_MEASURE_RISING_EDGE_PERIOD) || (icState->icChannelType[channel] == IC_MEASURE_FALLING_EDGE_PERIOD))
1117  {
1118  captureWordsToRead = 2U;
1119  }
1120 
1121  returnCode = ETIMER_DRV_GetCaptureValue((uint16_t)instance,
1122  (uint16_t)channel,
1123  captureRegister,
1124  captureResultBuffer1,
1125  captureWordsToRead);
1126 
1127  if (returnCode == 0U)
1128  {
1129  value = 0U;
1130  }
1131  else if (returnCode == 1U)
1132  {
1133  value = captureResultBuffer1[0];
1134  }
1135  else
1136  {
1137  if (captureResultBuffer1[1] > captureResultBuffer1[0])
1138  {
1139  value = captureResultBuffer1[1] - captureResultBuffer1[0];
1140  }
1141  else
1142  {
1143  value = captureResultBuffer1[1] + (ETIMER_CH_MAX_TIMER_COUNT - captureResultBuffer1[0]);
1144  }
1145  }
1146 
1147  if ((icState->icChannelType[channel] == IC_MEASURE_PULSE_HIGH) || (icState->icChannelType[channel] == IC_MEASURE_PULSE_LOW))
1148  {
1149  captureRegister = 1U;
1150  returnCode = ETIMER_DRV_GetCaptureValue((uint16_t)instance,
1151  (uint16_t)channel,
1152  captureRegister,
1153  captureResultBuffer2,
1154  captureWordsToRead);
1155  if (captureResultBuffer2[0] > captureResultBuffer1[0])
1156  {
1157  value = captureResultBuffer2[0] - captureResultBuffer1[0];
1158  }
1159  else
1160  {
1161  value = captureResultBuffer2[0] + (ETIMER_CH_MAX_TIMER_COUNT - captureResultBuffer1[0]);
1162  }
1163  }
1164 
1165  if (icState->icChannelType[channel] == IC_DISABLE_OPERATION)
1166  {
1167  value = 0U;
1168  }
1169 
1170  (void)returnCode;
1171 
1172  /* Get the time stamp of the event */
1173  icState->measurementResults[channel] = value;
1174 #endif
1175 
1176  if ((icState->channelCallbacks[channel] != NULL) && (icState->enableNotification[channel] == true))
1177  {
1178  /* Call to callback function */
1179  (icState->channelCallbacks[channel])(IC_EVENT_MEASUREMENT_COMPLETE, icState->channelCallbackParams[channel]);
1180  }
1181 
1182 #if (defined (IC_PAL_OVER_EMIOS))
1183  /* Clear interrupt flag */
1184  EMIOS_DRV_ClrFlagState(instance, channel);
1185 #endif
1186 
1187 #if (defined (IC_PAL_OVER_ETIMER))
1188  /* Clear interrupt flag */
1189  ETIMER_DRV_ClearInterruptStatus((uint16_t)instance,
1190  (ETIMER_CH_IRQ_FLAGS_ICF1 | ETIMER_CH_IRQ_FLAGS_ICF2),
1191  channel);
1192 #endif
1193 }
1194 
1195 /*******************************************************************************
1196  * EOF
1197  ******************************************************************************/
ftm_reg_update_t initCounterSync
Definition: ftm_common.h:425
uint8_t hwChannelId
Definition: ic_pal.h:136
ftm_pwm_sync_t syncMethod
Definition: ftm_common.h:438
void * extension
Definition: ic_pal.h:154
Structure storing PAL instance information.
FlexTimer state structure of the driver.
Definition: ftm_common.h:391
void IC_IrqHandler(uint32_t instance, uint8_t channel)
Definition: ic_pal.c:1093
ftm_edge_alignment_mode_t edgeAlignement
ftm_state_t * ftmStatePtr[(2u)]
Pointer to runtime state structure.
Definition: ftm_common.c:84
static ic_pal_state_t g_icPalStatePtr[NUMBER_OF_IC_PAL_INSTANCES]
Definition: ic_pal.c:86
ftm_bdm_mode_t BDMMode
Definition: ftm_common.h:444
bool hardwareSync2
Definition: ftm_common.h:416
status_t IC_Init(const ic_instance_t *const instance, const ic_config_t *configPtr)
Initializes the input capture mode.
Definition: ic_pal.c:677
void * channelExtension
Definition: ic_pal.h:140
#define FEATURE_FTM_CHANNEL_COUNT
Configuration structure that the user needs to set.
Definition: ftm_common.h:436
void IC_DisableNotification(const ic_instance_t *const instance, uint8_t channel)
Disable channel notifications.
Definition: ic_pal.c:1064
static uint32_t icStateInstanceMapping[NUMBER_OF_IC_PAL_INSTANCES]
Definition: ic_pal.c:89
FlexTimer driver input capture parameters.
status_t FTM_IC_DRV_SetChannelMode(uint32_t instance, uint8_t channel, ftm_ic_op_mode_t inputMode, bool enableContinuousCapture)
Set mode operation for channel in the input captue mode.
ic_callback_t channelsCallbacks
FlexTimer Registers sync parameters Please don't use software and hardware trigger simultaneously Imp...
Definition: ftm_common.h:408
void IC_EnableNotification(const ic_instance_t *const instance, uint8_t channel)
Enable channel notifications.
Definition: ic_pal.c:1035
status_t FTM_DRV_SetOutputlevel(uint32_t instance, uint8_t channel, uint8_t level)
This function will set the channel edge or level on the selection of the channel mode.
Definition: ftm_common.c:385
bool hardwareSync1
Definition: ftm_common.h:414
ftm_ic_op_mode_t
The measurement type for input capture mode Implements : ftm_ic_op_mode_t_Class.
Definition: ftm_ic_driver.h:82
uint8_t nNumChannels
Definition: ic_pal.h:152
bool enableNotification[(8U)]
Definition: ftm_common.h:400
static void icFreeState(bool *isAllocated, const uint32_t *instanceMapping, uint32_t instance)
Definition: ic_pal.c:133
void IC_StopChannel(const ic_instance_t *const instance, uint8_t channel)
Stop the counter.
Definition: ic_pal.c:849
status_t IC_Deinit(const ic_instance_t *const instance)
De-initialize a input capture instance.
Definition: ic_pal.c:736
#define DEV_ASSERT(x)
Definition: devassert.h:77
Defines the configuration structures are used in the input capture mode.
Definition: ic_pal.h:150
uint16_t filterValue
Definition: ic_pal.h:139
bool hardwareSync0
Definition: ftm_common.h:412
void * channelCallbackParams
Definition: ic_pal.h:141
status_t IC_SetChannelMode(const ic_instance_t *const instance, uint8_t channel, ic_option_mode_t channelMode)
Get the measured value.
Definition: ic_pal.c:886
status_t FTM_DRV_InitInputCapture(uint32_t instance, const ftm_input_param_t *param)
Configures Channel Input Capture for either getting time-stamps on edge detection or on signal measur...
ftm_pwm_sync_mode_t syncPoint
Definition: ftm_common.h:427
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K118.h:188
ic_inst_type_t instType
uint16_t nMaxCountValue
static bool icStateIsAllocated[NUMBER_OF_IC_PAL_INSTANCES]
Definition: ic_pal.c:91
static uint8_t FindIcState(uint32_t instance)
Definition: ic_pal.c:156
static uint8_t icAllocateState(bool *isAllocated, uint32_t *instanceMapping, uint32_t instance)
Definition: ic_pal.c:107
FlexTimer driver Input capture parameters for each channel.
Definition: ftm_ic_driver.h:99
bool maxLoadingPoint
Definition: ftm_common.h:418
ic_callback_t channelCallbacks
Definition: ic_pal.h:142
The internal context structure.
Definition: ic_pal.h:234
uint32_t instIdx
bool enableInitializationTrigger
Definition: ftm_common.h:447
ic_option_mode_t
The measurement type for input capture mode Implements : ic_option_mode_t_Class.
Definition: ic_pal.h:117
const ic_input_ch_param_t * inputChConfig
Definition: ic_pal.h:153
ftm_reg_update_t inverterSync
Definition: ftm_common.h:422
ftm_signal_measurement_mode_t measurementType
ic_option_mode_t inputCaptureMode
Definition: ic_pal.h:137
ftm_config_mode_t ftmMode
Definition: ftm_common.h:440
status_t FTM_DRV_Deinit(uint32_t instance)
Shuts down the FTM driver.
Definition: ftm_common.c:196
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
ftm_input_ch_param_t * inputChConfig
ftm_reg_update_t maskRegSync
Definition: ftm_common.h:424
bool minLoadingPoint
Definition: ftm_common.h:420
ftm_input_op_mode_t inputMode
bool autoClearTrigger
Definition: ftm_common.h:426
status_t FTM_DRV_Init(uint32_t instance, const ftm_user_config_t *info, ftm_state_t *state)
Initializes the FTM driver.
Definition: ftm_common.c:117
void IC_StartChannel(const ic_instance_t *const instance, uint8_t channel)
Start the counter.
Definition: ic_pal.c:805
uint16_t IC_GetMeasurement(const ic_instance_t *const instance, uint8_t channel)
Get the measured value.
Definition: ic_pal.c:987
ftm_clock_source_t ftmClockSource
Definition: ftm_common.h:443
uint16_t FTM_DRV_GetInputCaptureMeasurement(uint32_t instance, uint8_t channel)
This function is used to calculate the measurement and/or time stamps values which are read from the ...
ftm_reg_update_t outRegSync
Definition: ftm_common.h:423
ftm_clock_ps_t ftmPrescaler
Definition: ftm_common.h:441