oc_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  */
84 #include "oc_pal.h"
85 #include "oc_pal_cfg.h"
86 #include "interrupt_manager.h"
87 #include "oc_irq.h"
88 #if (defined(OC_PAL_OVER_ETIMER))
89 /* private ETIMER functions */
90 #include "etimer_hw_access.h"
91 #endif
92 
93 /*******************************************************************************
94  * Definitions
95  ******************************************************************************/
104 typedef struct
105 {
107  uint8_t nNumChannels;
108  uint8_t channelConfigArray[OC_PAL_NUM_OF_CHANNEL_MAX];
109  oc_option_mode_t ocChannelMode[OC_PAL_NUM_OF_CHANNEL_MAX];
110  void * channelCallbackParams[OC_PAL_NUM_OF_CHANNEL_MAX];
111  oc_callback_t channelCallbacks[OC_PAL_NUM_OF_CHANNEL_MAX];
112  bool enableNotification[OC_PAL_NUM_OF_CHANNEL_MAX];
115 
116 /*******************************************************************************
117  * Variables
118  ******************************************************************************/
119 
120 /* Pointer to runtime state structures */
121 static oc_pal_state_t g_ocPalStatePtr[NUMBER_OF_OC_PAL_INSTANCES];
122 
123 /* OC state-instance matching */
124 static uint32_t ocStateInstanceMapping[NUMBER_OF_OC_PAL_INSTANCES];
125 /* OC available resources table */
126 static bool ocStateIsAllocated[NUMBER_OF_OC_PAL_INSTANCES];
127 
128 #if (defined(OC_PAL_OVER_FTM))
129 /* The FTM state structures */
130 static ftm_state_t g_ocFtmState[NUMBER_OF_OC_PAL_INSTANCES];
131 #endif
132 
133 /*******************************************************************************
134  * Code
135  ******************************************************************************/
136 
137 /*FUNCTION**********************************************************************
138  *
139  * Function Name : ocAllocateState
140  * Description : Allocates one of the available state structure.
141  *
142  *END**************************************************************************/
143 static uint8_t ocAllocateState(bool * isAllocated,
144  uint32_t * instanceMapping,
145  uint32_t instance,
146  uint8_t numberOfInstances)
147 {
148  uint8_t i;
149 
150  /* Allocate one of the OC state structure for this instance */
151  for (i = 0;i < numberOfInstances;i++)
152  {
153  if (isAllocated[i] == false)
154  {
155  instanceMapping[i] = instance;
156  isAllocated[i] = true;
157  break;
158  }
159  }
160 
161  return i;
162 }
163 
164 /*FUNCTION**********************************************************************
165  *
166  * Function Name : ocFreeState
167  * Description : Deallocates one of the available state structure.
168  *
169  *END**************************************************************************/
170 static void ocFreeState(bool * isAllocated,
171  uint32_t * instanceMapping,
172  uint32_t instance,
173  uint8_t numberOfInstances)
174 {
175  uint8_t i;
176 
177  /* Allocate one of the OC state structure for this instance */
178  for (i = 0;i < numberOfInstances;i++)
179  {
180  if (instanceMapping[i] == instance)
181  {
182  isAllocated[i] = false;
183  break;
184  }
185  }
186 }
187 
188 /*FUNCTION**********************************************************************
189  *
190  * Function Name : FindOcState
191  * Description : Search the state structure of the instance for each IP
192  *
193  *END**************************************************************************/
194 static uint8_t FindOcState(uint32_t instance)
195 {
196  uint8_t i;
197 
198  for (i = 0U;i < NUMBER_OF_OC_PAL_INSTANCES;i++)
199  {
200  if (ocStateInstanceMapping[i] == instance)
201  {
202  break;
203  }
204  }
205 
206  return i;
207 }
208 
209  #if (defined(OC_PAL_OVER_FTM))
210 /*FUNCTION**********************************************************************
211  *
212  * Function Name : OC_InitFtm
213  * Description : This function initializes output compare over FTM.
214  *END**************************************************************************/
215  static status_t OC_InitFtm(uint32_t instance,
216  const oc_config_t * configPtr)
217 {
218  status_t status = STATUS_SUCCESS;
219  static oc_pal_state_t * ocState;
220  uint8_t indexInstance = 0U;
221  uint8_t index = 0U;
222  uint8_t channel = 0U;
223 
224  /* Allocate one of the OC state structure for this instance */
225  indexInstance = ocAllocateState(ocStateIsAllocated, ocStateInstanceMapping, instance, NUMBER_OF_OC_PAL_INSTANCES);
226  ocState = &g_ocPalStatePtr[indexInstance];
227  DEV_ASSERT(ocState->nNumChannels == 0x0U);
228 
229  /* Initialize the internal context to default value */
230  ocState->nNumChannels = configPtr->nNumChannels;
231  for (index = 0U; index < OC_PAL_NUM_OF_CHANNEL_MAX; index++)
232  {
233  ocState->channelConfigArray[index] = 0U;
234  ocState->ocChannelMode[index] = OC_DISABLE_OUTPUT;
235  ocState->enableNotification[index] = false;
236  ocState->channelCallbackParams[index] = NULL;
237  ocState->channelCallbacks[index] = NULL;
238  }
239 
240  ftm_pwm_sync_t sync;
241  ftm_user_config_t info;
242  ftm_state_t * ftmState = &g_ocFtmState[indexInstance];
246 
247  /* Configure the synchronous to default */
248  sync.softwareSync = true;
249  sync.hardwareSync0 = false;
250  sync.hardwareSync1 = false;
251  sync.hardwareSync2 = false;
252  sync.maxLoadingPoint = true;
253  sync.minLoadingPoint = false;
258  sync.autoClearTrigger = false;
259  sync.syncPoint = FTM_UPDATE_NOW;
260 
261  /* Get some information from user configuration */
262  info.syncMethod = sync;
264  info.ftmPrescaler = ((extension_ftm_for_oc_t *)(configPtr->extension))->ftmPrescaler;
265  info.ftmClockSource = ((extension_ftm_for_oc_t *)(configPtr->extension))->ftmClockSource;
266  info.BDMMode = FTM_BDM_MODE_11;
267  info.isTofIsrEnabled = false;
268  info.enableInitializationTrigger = false;
269 
270  /* Initializes the FTM driver */
271  status = FTM_DRV_Init((uint32_t)instance,
272  &info, ftmState);
273  DEV_ASSERT(STATUS_SUCCESS == status);
274 
275  param.nNumOutputChannels = configPtr->nNumChannels;
277  param.maxCountValue = ((extension_ftm_for_oc_t *)(configPtr->extension))->maxCountValue;
278 
279  /* Configure a list of channels which are used */
280  for (index = 0U; index < configPtr->nNumChannels; index++)
281  {
282  /* Get the hardware channel ID */
283  channelConfig[index].hwChannelId = configPtr->outputChConfig[index].hwChannelId;
284  channel = channelConfig[index].hwChannelId;
285  /* Set channels configuration from user */
286  channelConfig[index].chMode = (ftm_output_compare_mode_t)(configPtr->outputChConfig[index].chMode);
287  channelConfig[index].comparedValue = configPtr->outputChConfig[index].comparedValue;
288  channelConfig[index].enableExternalTrigger = false;
289 
290  /* Store some needed information into state structure */
291  ocState->channelConfigArray[index] = configPtr->outputChConfig[index].hwChannelId;
292  ocState->ocChannelMode[channel] = configPtr->outputChConfig[index].chMode;
293  ocState->enableNotification[channel] = true;
294  ocState->channelCallbackParams[channel] = configPtr->outputChConfig[index].channelCallbackParams;
295  ocState->channelCallbacks[channel] = configPtr->outputChConfig[index].channelCallbacks;
296  }
297 
298  param.outputChannelConfig = channelConfig;
299 
300  /* Configure channels in output compare mode */
301  status = FTM_DRV_InitOutputCompare((uint32_t)instance,
302  &param);
303 
304  if (status == STATUS_SUCCESS)
305  {
306  for (index = 0U; index < configPtr->nNumChannels; index++)
307  {
308  /* Get the hardware channel ID */
309  channel = configPtr->outputChConfig[index].hwChannelId;
310 
311  status = FTM_DRV_EnableInterrupts((uint32_t)instance, (uint32_t)(1U << channel));
312  /* Install FTM irq handler */
313  INT_SYS_InstallHandler(ftmIrq[instance][channel],
314  s_ocOverFtmIsr[instance][channel], (isr_t*)0);
315  /* Enable FTM interrupt */
316  INT_SYS_EnableIRQ(ftmIrq[instance][channel]);
317  }
318  }
319  return status;
320 }
321 #endif
322 
323 #if (defined(OC_PAL_OVER_EMIOS))
324 /*FUNCTION**********************************************************************
325  *
326  * Function Name : OC_InitEMIOS
327  * Description : This function initializes output compare over EMIOS.
328  *END**************************************************************************/
329  static status_t OC_InitEMIOS(uint32_t instance,
330  const oc_config_t * configPtr)
331 {
332  status_t status = STATUS_SUCCESS;
333  static oc_pal_state_t * ocState;
334  uint8_t indexInstance = 0U;
335  uint8_t index = 0U;
336  uint8_t channel = 0U;
337 
338  emios_common_param_t commonParam;
339  emios_mc_mode_param_t mcParam;
340  emios_oc_param_t ocParam;
341  emios_bus_select_t timeBaseSelection = EMIOS_BUS_SEL_BCDE;
342  const IRQn_Type emiosIrq[eMIOS_INSTANCE_COUNT][(eMIOS_UC_COUNT / 2U)] = eMIOS_IRQS;
343 
344  /* Allocate one of the OC state structure for this instance */
345  indexInstance = ocAllocateState(ocStateIsAllocated, ocStateInstanceMapping, instance, NUMBER_OF_OC_PAL_INSTANCES);
346  ocState = &g_ocPalStatePtr[indexInstance];
347  DEV_ASSERT(ocState->nNumChannels == 0x0U);
348 
349  /* Initialize the internal context to default value */
350  ocState->nNumChannels = configPtr->nNumChannels;
351  for (index = 0U; index < OC_PAL_NUM_OF_CHANNEL_MAX; index++)
352  {
353  ocState->channelConfigArray[index] = 0U;
354  ocState->ocChannelMode[index] = OC_DISABLE_OUTPUT;
355  ocState->enableNotification[index] = false;
356  ocState->channelCallbackParams[index] = NULL;
357  ocState->channelCallbacks[index] = NULL;
358  }
359 
360  /* Get common parameters from user */
361  commonParam.allowDebugMode = false;
362  commonParam.lowPowerMode = false;
363  commonParam.clkDivVal = ((extension_emios_for_oc_t *)(configPtr->extension))->clkDivVal;
364  commonParam.enableGlobalPrescaler = ((extension_emios_for_oc_t *)(configPtr->extension))->enableGlobalPrescaler;
365  commonParam.enableGlobalTimeBase = ((extension_emios_for_oc_t *)(configPtr->extension))->enableGlobalTimeBase;
366 
367  /* Initialize the global for a eMIOS group */
368  EMIOS_DRV_InitGlobal((uint8_t)instance,
369  &commonParam);
370 
371  /* Get the information from user configuration */
372  mcParam.mode = EMIOS_MODE_MCB_UP_COUNTER_INT_CLK;
373  mcParam.filterInput = EMIOS_INPUT_FILTER_BYPASS;
374  mcParam.filterEn = false;
375  mcParam.triggerMode = EMIOS_TRIGGER_EDGE_ANY;
376 
377  for (index = 0U; index < configPtr->nNumChannels; index++)
378  {
379  mcParam.period = ((channel_extension_emios_for_oc_t *)(configPtr->outputChConfig[index].channelExtension))->period;
380  mcParam.internalPrescaler = ((channel_extension_emios_for_oc_t *)(configPtr->outputChConfig[index].channelExtension))->prescaler;
381  mcParam.internalPrescalerEn = true;
382 
383  switch (((channel_extension_emios_for_oc_t *)(configPtr->outputChConfig[index].channelExtension))->timebase)
384  {
385  case OC_BUS_SEL_A:
386  /* Set channel to use as a time base */
387  channel = 23U;
388  timeBaseSelection = EMIOS_BUS_SEL_A;
389  break;
390  case OC_BUS_SEL_B:
391  /* Set channel to use as a time base */
392  channel = 0U;
393  timeBaseSelection = EMIOS_BUS_SEL_BCDE;
394  break;
395  case OC_BUS_SEL_C:
396  /* Set channel to use as a time base */
397  channel = 8U;
398  timeBaseSelection = EMIOS_BUS_SEL_BCDE;
399  break;
400  case OC_BUS_SEL_D:
401  /* Set channel to use as a time base */
402  channel = 16U;
403  timeBaseSelection = EMIOS_BUS_SEL_BCDE;
404  break;
405  case OC_BUS_SEL_E:
406  /* Set channel to use as a time base */
407  channel = 24U;
408  timeBaseSelection = EMIOS_BUS_SEL_BCDE;
409  break;
410  case OC_BUS_SEL_F:
411  /* Set channel to use as a time base */
412  channel = 22U;
413  timeBaseSelection = EMIOS_BUS_SEL_F;
414  break;
415  case OC_BUS_SEL_INTERNAL:
416  /* Set channel to use as a time base */
417  channel = configPtr->outputChConfig[index].hwChannelId;
418  timeBaseSelection = EMIOS_BUS_SEL_INTERNAL;
419  break;
420  default:
421  /* Do nothing */
422  break;
423  }
424 
425  /* Initialize the counter mode */
426  status = EMIOS_DRV_MC_InitCounterMode((uint8_t)instance,
427  channel,
428  &mcParam);
429  DEV_ASSERT(STATUS_SUCCESS == status);
430 
431  channel = configPtr->outputChConfig[index].hwChannelId;
432 
433  ocParam.mode = EMIOS_MODE_SAOC;
434  ocParam.timebase = timeBaseSelection;
435  ocParam.matchLeadingEdgeValue = (uint32_t)(configPtr->outputChConfig[index].comparedValue);
436  ocParam.matchTrailingEdgeValue = 0U;
437 
438  /* Check the operation mode of channel output */
439  if (OC_CLEAR_ON_MATCH == configPtr->outputChConfig[index].chMode)
440  {
441  ocParam.outputActiveMode = EMIOS_OUTPUT_ACTIVE_LOW;
442  }
443  else if (OC_SET_ON_MATCH == configPtr->outputChConfig[index].chMode)
444  {
445  ocParam.outputActiveMode = EMIOS_OUTPUT_ACTIVE_HIGH;
446  }
447  else if (OC_TOGGLE_ON_MATCH == configPtr->outputChConfig[index].chMode)
448  {
449  ocParam.outputActiveMode = EMIOS_OUTPUT_ACTIVE_TOGGLE;
450  }
451  else
452  {
453  DEV_ASSERT(false);
454  }
455 
456  /* Initialize the output compare mode for each channel */
457  status = EMIOS_DRV_OC_InitOutputCompareMode((uint8_t)instance,
458  channel,
459  &ocParam);
460 
461  /* Enable EMIOS interrupt */
462  EMIOS_DRV_ChannelEnableInterruptRequest((uint8_t)instance, channel);
463  INT_SYS_EnableIRQ(emiosIrq[instance][(channel>>1U)]);
464 
465  /* Store some needed information into state structure */
466  ocState->channelConfigArray[index] = channel;
467  ocState->ocChannelMode[channel] = configPtr->outputChConfig[index].chMode;
468  ocState->enableNotification[channel] = true;
469  ocState->channelCallbackParams[channel] = configPtr->outputChConfig[index].channelCallbackParams;
470  ocState->channelCallbacks[channel] = configPtr->outputChConfig[index].channelCallbacks;
471  }
472 
473  /* Enable the global eMIOS to start counter */
474  EMIOS_DRV_EnableGlobalEmios((uint8_t)instance);
475 
476  return status;
477 }
478 #endif
479 
480 #if (defined(OC_PAL_OVER_ETIMER))
481 /*FUNCTION**********************************************************************
482  *
483  * Function Name : OC_EtimerInit
484  * Description : This function initializes the output compare mode over ETIMER.
485  *
486  *END**************************************************************************/
487 static status_t OC_EtimerInit(uint32_t etimerInstance,
488  const oc_config_t * configPtr)
489 {
490  status_t status = STATUS_SUCCESS;
491  uint8_t index = 0U;
492  uint16_t channel = 0U;
493  uint16_t maskChannel = 0U;
494  oc_pal_state_t * ocState;
495 
496  /* Allocate one of the OC state structure for this instance */
497  index = ocAllocateState(ocStateIsAllocated, ocStateInstanceMapping, etimerInstance, NUMBER_OF_OC_PAL_INSTANCES);
498  ocState = &g_ocPalStatePtr[index];
499  DEV_ASSERT(ocState->nNumChannels == 0x0U);
500 
501  /* Initialize the internal context to default value */
502  ocState->nNumChannels = configPtr->nNumChannels;
503  for (index = 0U; index < OC_PAL_NUM_OF_CHANNEL_MAX; index++)
504  {
505  ocState->channelConfigArray[index] = 0U;
506  ocState->ocChannelMode[index] = OC_DISABLE_OUTPUT;
507  ocState->enableNotification[index] = false;
508  ocState->channelCallbackParams[index] = NULL;
509  ocState->channelCallbacks[index] = NULL;
510  }
511 
512  /* Initialize the ETIMER module */
513  ETIMER_DRV_Init(etimerInstance);
514 
515  /* default config */
516  etimer_user_channel_config_t userChannelConfig = {
517  .timerMode = ETIMER_MODE_OUTPUT_COMPARE,
518  .coreSettings = ETIMER_COUNTER_NORMAL,
519  .inputFilter =
520  {
521  .samples = ETIMER_FILT_CNT_3,
522  .rate = 100,
523  },
524  .primaryInput =
525  {
526  .source = ETIMER_IN_SRC_CLK_DIV_128,
527  .polarity = ETIMER_POLARITY_POSITIVE,
528  },
529  .secondaryInput =
530  {
531  .source = ETIMER_IN_SRC_CNT0_IN,
532  .polarity = ETIMER_POLARITY_POSITIVE,
533  },
534  .outputPin =
535  {
536  .enable = true,
537  .polarity = ETIMER_POLARITY_POSITIVE,
538  },
539  .countDirection = ETIMER_COUNT_UP,
540  .compareValues =
541  {
542  0U,
543  0U,
544  },
545  .compareLoading =
546  {
547  ETIMER_CLC_FROM_CMPLD1_WHEN_COMP1,
548  ETIMER_CLC_NEVER,
549  },
550  .compareOutputControl = ETIMER_OUTMODE_SOFTWARE,
551  .compareMode = ETIMER_CMPMODE_COMP1_UP_COMP2_DOWN,
552  .captureControl =
553  {
554  ETIMER_CPTMODE_DISABLED,
555  ETIMER_CPTMODE_DISABLED,
556  },
557  .captureWords = 0U,
558  .interruptEnableMask = (ETIMER_CH_IRQ_SOURCE_TCF1IE|0U),
559  };
560 
561  /* Configure a list of channels which are used */
562  for (index = 0U; index < configPtr->nNumChannels; index++)
563  {
564  channel = (uint16_t)(configPtr->outputChConfig[index].hwChannelId);
565  maskChannel |= (uint16_t)(1U << channel);
566 
567  /* setup clocking */
568  userChannelConfig.primaryInput.source = ((channel_extension_etimer_for_oc_t *)configPtr->outputChConfig[index].channelExtension)->primaryInput.source;
569  userChannelConfig.primaryInput.polarity = ((channel_extension_etimer_for_oc_t *)configPtr->outputChConfig[index].channelExtension)->primaryInput.polarity;
570 
571  /* output pin */
572  userChannelConfig.outputPin.polarity = ((channel_extension_etimer_for_oc_t *)configPtr->outputChConfig[index].channelExtension)->outputPin.polarity;
573  userChannelConfig.outputPin.enable = ((channel_extension_etimer_for_oc_t *)configPtr->outputChConfig[index].channelExtension)->outputPin.enable;
574 
575  /* set compare threshold */
576  userChannelConfig.compareValues[0] = configPtr->outputChConfig[index].comparedValue;
577 
578  /* Check the operation mode of channel output */
579  if (OC_CLEAR_ON_MATCH == configPtr->outputChConfig[index].chMode)
580  {
581  userChannelConfig.compareOutputControl = ETIMER_OUTMODE_COMPARE_CLEAR;
582  ETIMER_DRV_ReloadOnCompare(etimerInstance, channel, 0, false);
583  }
584  else if (OC_SET_ON_MATCH == configPtr->outputChConfig[index].chMode)
585  {
586  userChannelConfig.compareOutputControl = ETIMER_OUTMODE_COMPARE_SET;
587  ETIMER_DRV_ReloadOnCompare(etimerInstance, channel, 0, false);
588  }
589  else if (OC_TOGGLE_ON_MATCH == configPtr->outputChConfig[index].chMode)
590  {
591  userChannelConfig.compareOutputControl = ETIMER_OUTMODE_COMPARE_TOGGLE;
592  ETIMER_DRV_ReloadOnCompare(etimerInstance, channel, 0, true);
593  }
594  else
595  {
596  DEV_ASSERT(false);
597  userChannelConfig.compareOutputControl = ETIMER_OUTMODE_SOFTWARE;
598  maskChannel &= ~((uint16_t)(1U << channel));
599  }
600 
601  /* Initialize the channel at the output compare mode */
602  ETIMER_DRV_InitChannel((uint16_t)etimerInstance, channel, &userChannelConfig);
603 
604  if (OC_TOGGLE_ON_MATCH == configPtr->outputChConfig[index].chMode)
605  {
606  ETIMER_DRV_ReloadOnCompare((uint16_t)etimerInstance, channel, 0, true);
607  }
608 
609  /* Enable ETIMER channel interrupt and install an ISR */
610  IRQn_Type etimer_ch_irq_id = ETIMER_DRV_GetInterruptNumber((uint16_t)etimerInstance,(etimer_irq_vector_t)channel);
611  INT_SYS_EnableIRQ(etimer_ch_irq_id);
612 
613  /* Store some needed information into state structure */
614  ocState->channelConfigArray[index] = channel;
615  ocState->ocChannelMode[channel] = configPtr->outputChConfig[index].chMode;
616  ocState->enableNotification[channel] = true;
617  ocState->channelCallbackParams[channel] = configPtr->outputChConfig[index].channelCallbackParams;
618  ocState->channelCallbacks[channel] = configPtr->outputChConfig[index].channelCallbacks;
619  }
620 
621  /* Start the channel counting */
622  ETIMER_DRV_StartTimerChannels((uint16_t)etimerInstance, maskChannel);
623 
624  return status;
625 }
626 
627 /*FUNCTION**********************************************************************
628  *
629  * Function Name : OC_ETIMER_SetOutputMode
630  * Description : This function will configure channel mode of output signal.
631  *
632  *END**************************************************************************/
633 static status_t OC_ETIMER_SetOutputMode(uint32_t instance,
634  uint8_t channel,
635  oc_option_mode_t channelMode)
636 {
637  switch (channelMode)
638  {
639  case OC_TOGGLE_ON_MATCH:
640  ETIMER_DRV_SetOutputFunction(instance, channel, ETIMER_OUTMODE_COMPARE_TOGGLE);
641  ETIMER_DRV_OutputPinEnable(instance, channel);
642  break;
643  case OC_CLEAR_ON_MATCH:
644  ETIMER_DRV_SetOutputFunction(instance, channel, ETIMER_OUTMODE_COMPARE_CLEAR);
645  ETIMER_DRV_OutputPinEnable(instance, channel);
646  break;
647  case OC_SET_ON_MATCH:
648  ETIMER_DRV_SetOutputFunction(instance, channel, ETIMER_OUTMODE_COMPARE_SET);
649  ETIMER_DRV_OutputPinEnable(instance, channel);
650  break;
651  default:
652  /* disable the output pin, go to tri-state mode */
653  ETIMER_DRV_OutputPinDisable(instance, channel);
654  break;
655  }
656 
657  return STATUS_SUCCESS;
658 }
659 
660 /*FUNCTION**********************************************************************
661  *
662  * Function Name : OC_ETIMER_ForceOutput
663  * Description : This function will force the output signal to specified value.
664  *
665  *END**************************************************************************/
666 static status_t OC_ETIMER_ForceOutput(uint32_t instance,
667  uint8_t channel,
668  bool outputValue)
669 {
670 
671  ETIMER_DRV_ForceOutputLogicLevel((uint16_t) instance, (uint16_t) channel,outputValue);
672 
673  return STATUS_SUCCESS;
674 }
675 #endif
676 
677 /*FUNCTION**********************************************************************
678  *
679  * Function Name : OC_Init
680  * Description : This function will initialize the OC PAL instance, including the
681  * other platform specific HW units used together in the output compare mode. This
682  * function configures a group of channels in instance to generate timed pulses with
683  * programmable position, polarity, duration, and frequency. The channel (n) output
684  * can be set, cleared, or toggled.
685  *
686  * Implements : OC_Init_Activity
687  *END**************************************************************************/
688 status_t OC_Init(const oc_instance_t * const instance,
689  const oc_config_t * const configPtr)
690 {
691  DEV_ASSERT(configPtr != NULL);
692  DEV_ASSERT(instance != NULL);
693  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
694  DEV_ASSERT(configPtr->nNumChannels > 0U);
695  status_t status = STATUS_SUCCESS;
696 
697 #if (defined(OC_PAL_OVER_FTM))
698  if(instance->instType == OC_INST_TYPE_FTM)
699  {
700  DEV_ASSERT(configPtr->extension != NULL);
701  /* Initialize output compare over FTM */
702  status = OC_InitFtm(instance->instIdx, configPtr);
703  }
704  else
705 #endif
706 
707 #if (defined(OC_PAL_OVER_EMIOS))
708  if(instance->instType == OC_INST_TYPE_EMIOS)
709  {
710  DEV_ASSERT(configPtr->extension != NULL);
711  /* Initialize output compare over EMIOS */
712  status = OC_InitEMIOS(instance->instIdx, configPtr);
713  }
714  else
715 #endif
716 
717 #if (defined(OC_PAL_OVER_ETIMER))
718  if(instance->instType == OC_INST_TYPE_ETIMER)
719  {
720  /* Initialize output compare over ETIMER */
721  status = OC_EtimerInit(instance->instIdx, configPtr);
722  }
723  else
724 #endif
725 
726  {
727  DEV_ASSERT(false);
728  }
729 
730  return status;
731 }
732 
733 /*FUNCTION**********************************************************************
734  *
735  * Function Name : OC_Deinit
736  * Description : This function will disable the output compare mode. The driver
737  * can't be used again until reinitialized. The context structure is no longer
738  * needed by the driver and can be freed after calling this function.
739  *
740  * Implements : OC_Deinit_Activity
741  *END**************************************************************************/
742 status_t OC_Deinit(const oc_instance_t * const instance)
743 {
744  DEV_ASSERT(instance != NULL);
745  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
746  status_t status = STATUS_ERROR;
747  uint8_t index;
748  oc_pal_state_t * ocState;
749 
750  /* Allocate one of the OC state structure for this instance */
751  index = FindOcState(instance->instIdx);
752  ocState = &g_ocPalStatePtr[index];
753 
754 #if (defined(OC_PAL_OVER_FTM))
755  if(instance-> instType == OC_INST_TYPE_FTM)
756  {
757  /* Disable the output compare over FTM */
758  status = FTM_DRV_Deinit(instance->instIdx);
759  }
760  else
761 #endif
762 
763 #if (defined(OC_PAL_OVER_EMIOS))
764  uint8_t channel;
765  if(instance-> instType == OC_INST_TYPE_EMIOS)
766  {
767  for (index = 0U; index < ocState->nNumChannels; index++)
768  {
769  channel = ocState->channelConfigArray[index];
770  /* Disable channels in the output compare over EMIOS */
771  EMIOS_DRV_DeInitChannel((uint8_t)instance->instIdx, channel);
772  }
773  status = STATUS_SUCCESS;
774  }
775  else
776 #endif
777 
778 #if (defined(OC_PAL_OVER_ETIMER))
779  if(instance->instType == OC_INST_TYPE_ETIMER)
780  {
781  /* Disable the output compare over ETIMER */
782  ETIMER_DRV_Deinit((uint16_t)instance->instIdx);
783  status = STATUS_SUCCESS;
784  }
785  else
786 #endif
787 
788  {
789  DEV_ASSERT(false);
790  }
791 
792  /* De-Initialize the internal context to default value */
793  ocState->nNumChannels = 0U;
794  for (index = 0U; index < OC_PAL_NUM_OF_CHANNEL_MAX; index++)
795  {
796  ocState->channelConfigArray[index] = 0U;
797  ocState->ocChannelMode[index] = OC_DISABLE_OUTPUT;
798  ocState->enableNotification[index] = false;
799  }
800 
801  if (STATUS_SUCCESS == status)
802  {
803  /* De-Allocate the instance which is not used */
804  ocFreeState(ocStateIsAllocated, ocStateInstanceMapping, instance->instIdx, NUMBER_OF_OC_PAL_INSTANCES);
805  }
806 
807  return status;
808 }
809 
810 /*FUNCTION**********************************************************************
811  *
812  * Function Name : OC_StartChannel
813  * Description : This function start channel counting.
814  *
815  * Implements : OC_StartChannel_Activity
816  *END**************************************************************************/
817 void OC_StartChannel(const oc_instance_t * const instance,
818  const uint8_t channel)
819 {
820  status_t status = STATUS_SUCCESS;
821  DEV_ASSERT(instance != NULL);
822  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
823  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
824 
825 #if (defined(OC_PAL_OVER_FTM))
826  uint8_t index;
827  oc_pal_state_t * ocState;
828 
829  /* Allocate one of the OC state structure for this instance */
830  index = FindOcState(instance->instIdx);
831  ocState = &g_ocPalStatePtr[index];
832  oc_option_mode_t channelMode = ocState->ocChannelMode[channel];
833  if(instance->instType == OC_INST_TYPE_FTM)
834  {
835  /* Set the channel output mode */
836  status = FTM_DRV_SetOutputlevel(instance->instIdx, channel,
837  (uint8_t)channelMode);
838  DEV_ASSERT(status == STATUS_SUCCESS);
839  }
840  else
841 #endif
842 
843 #if (defined(OC_PAL_OVER_EMIOS))
844  if(instance->instType == OC_INST_TYPE_EMIOS)
845  {
846  /* Enable the channel clock */
847  EMIOS_DRV_ChannelEnableClk((uint8_t)instance->instIdx, channel);
848  }
849  else
850 #endif
851 
852 #if (defined(OC_PAL_OVER_ETIMER))
853  if(instance->instType == OC_INST_TYPE_ETIMER)
854  {
855  ETIMER_DRV_StartTimerChannels((uint16_t)(instance->instIdx),
856  (uint16_t)(1U << channel));
857  }
858  else
859 #endif
860 
861  {
862  DEV_ASSERT(false);
863  }
864  (void)status;
865 }
866 
867 /*FUNCTION**********************************************************************
868  *
869  * Function Name : OC_StopChannel
870  * Description : This function will stop channel counting.
871  *
872  * Implements : OC_StopChannel_Activity
873  *END**************************************************************************/
874 void OC_StopChannel(const oc_instance_t * const instance,
875  const uint8_t channel)
876 {
877  status_t status = STATUS_SUCCESS;
878  DEV_ASSERT(instance != NULL);
879  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
880  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
881 
882 #if (defined(OC_PAL_OVER_FTM))
883  if(instance->instType == OC_INST_TYPE_FTM)
884  {
885  /* Disable pin not used for FTM */
886  status = FTM_DRV_SetOutputlevel(instance->instIdx, channel, 0x0U);
887  DEV_ASSERT(status == STATUS_SUCCESS);
888  }
889  else
890 #endif
891 
892 #if (defined(OC_PAL_OVER_EMIOS))
893  if(instance->instType == OC_INST_TYPE_EMIOS)
894  {
895  /* Disable individual channel by stopping its respective clock*/
896  EMIOS_DRV_ChannelDisableClk((uint8_t)instance->instIdx, channel);
897  }
898  else
899 #endif
900 
901 #if (defined(OC_PAL_OVER_ETIMER))
902  if(instance->instType == OC_INST_TYPE_ETIMER)
903  {
904  ETIMER_DRV_StopTimerChannels((uint16_t)(instance->instIdx),
905  (uint16_t)(1U << channel));
906  }
907  else
908 #endif
909 
910  {
911  DEV_ASSERT(false);
912  }
913  (void)status;
914 }
915 
916 /*FUNCTION**********************************************************************
917  *
918  * Function Name : OC_SetOutputState
919  * Description : This function is used to forces the output pin to a specified
920  * value. It can be used to control the output pin value when the OC channel
921  * is disabled.
922  *
923  * Implements : OC_SetOutputState_Activity
924  *END**************************************************************************/
925 status_t OC_SetOutputState(const oc_instance_t * const instance,
926  const uint8_t channel, bool outputValue)
927 {
928  DEV_ASSERT(instance != NULL);
929  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
930  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
931  status_t status = STATUS_SUCCESS;
932 
933 #if (defined(OC_PAL_OVER_FTM))
934  if(instance->instType == OC_INST_TYPE_FTM)
935  {
936  uint8_t channelMask = (uint8_t)(1U << channel);
937  /* Enable the software output control */
938  status = FTM_DRV_SetSoftwareOutputChannelControl(instance->instIdx, channelMask, false);
939  /* Set the value of channel output */
940  status = FTM_DRV_SetSoftOutChnValue(instance->instIdx, outputValue ? channelMask : 0x00U, true);
941  }
942  else
943 #endif
944 
945 #if (defined(OC_PAL_OVER_EMIOS))
946  if(instance->instType == OC_INST_TYPE_EMIOS)
947  {
948  /* Set the state on the output signal */
949  EMIOS_DRV_SetOutputLevel((uint8_t)instance->instIdx, channel, false, outputValue);
950  /* Force the channel output which sets by software */
951  EMIOS_DRV_OC_ForceSingleActOutputCmpMatch((uint8_t)instance->instIdx, channel);
952  (void)status;
953  }
954  else
955 #endif
956 
957 #if (defined(OC_PAL_OVER_ETIMER))
958  if(instance->instType == OC_INST_TYPE_ETIMER)
959  {
960  /* Force the channel output which sets by software */
961  status = OC_ETIMER_ForceOutput(instance->instIdx,
962  channel,
963  outputValue);
964  }
965  else
966 #endif
967 
968  {
969  DEV_ASSERT(false);
970  }
971  return status;
972 }
973 
974 /*FUNCTION**********************************************************************
975  *
976  * Function Name : OC_SetOutputAction
977  * Description : This function is used to sets the action executed on a compare
978  * match value to set output pin, clear output pin, toggle output pin.
979  *
980  * Implements : OC_SetOutputAction_Activity
981  *END**************************************************************************/
983  const uint8_t channel,
984  oc_option_mode_t channelMode)
985 {
986  DEV_ASSERT(instance != NULL);
987  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
988  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
989  status_t status = STATUS_SUCCESS;
990  uint8_t index;
991  oc_pal_state_t * ocState;
992 
993  /* Allocate one of the OC state structure for this instance */
994  index = FindOcState(instance->instIdx);
995  ocState = &g_ocPalStatePtr[index];
996 
997 #if (defined(OC_PAL_OVER_FTM))
998  if(instance->instType == OC_INST_TYPE_FTM)
999  {
1000  /* Set the channel output mode */
1001  status = FTM_DRV_SetOutputlevel(instance->instIdx,
1002  channel,
1003  (uint8_t)channelMode);
1004  }
1005  else
1006 #endif
1007 
1008 #if (defined(OC_PAL_OVER_EMIOS))
1009  if(instance->instType == OC_INST_TYPE_EMIOS)
1010  {
1011  /* Set the channel output mode */
1012  EMIOS_DRV_SetOutputLevel((uint8_t)instance->instIdx, channel,
1013  ((((uint8_t)channelMode & 0x02U) == 0U) ? true : false),
1014  ((((uint8_t)channelMode & 0x01U) == 0U) ? false : true));
1015  status = STATUS_SUCCESS;
1016  }
1017  else
1018 #endif
1019 
1020 #if (defined(OC_PAL_OVER_ETIMER))
1021  if(instance->instType == OC_INST_TYPE_ETIMER)
1022  {
1023  status = OC_ETIMER_SetOutputMode(instance->instIdx,
1024  channel,
1025  channelMode);
1026  }
1027  else
1028 #endif
1029 
1030  {
1031  DEV_ASSERT(false);
1032  }
1033  /* Update the channel mode */
1034  ocState->ocChannelMode[channel] = channelMode;
1035 
1036  return status;
1037 }
1038 
1039 /*FUNCTION**********************************************************************
1040  *
1041  * Function Name : OC_SetCompareValue
1042  * Description : This function will update the compare value to change the
1043  * output signal in the output compare mode.
1044  *
1045  * Implements : OC_SetCompareValue_Activity
1046  *END**************************************************************************/
1048  const uint8_t channel,
1049  uint32_t nextCompareMatchValue,
1050  oc_option_update_t typeOfupdate)
1051 {
1052  DEV_ASSERT(instance != NULL);
1053  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
1054  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
1055  status_t status = STATUS_SUCCESS;
1056 
1057 #if (defined(OC_PAL_OVER_FTM))
1058  if(instance->instType == OC_INST_TYPE_FTM)
1059  {
1060  /* Update the output compare value over FTM */
1061  status = FTM_DRV_UpdateOutputCompareChannel(instance->instIdx, channel,
1062  (uint16_t)nextCompareMatchValue,
1063  (ftm_output_compare_update_t)typeOfupdate,
1064  true);
1065  }
1066  else
1067 #endif
1068 
1069 #if (defined(OC_PAL_OVER_EMIOS))
1070  if(instance->instType == OC_INST_TYPE_EMIOS)
1071  {
1072  uint32_t compareValue = 0U;
1073  uint32_t maxCounterValue = 0U;
1074  uint32_t counterValue = EMIOS_DRV_MC_CounterRead((uint8_t)instance->instIdx, channel);
1075 
1076  if (typeOfupdate == OC_RELATIVE_VALUE)
1077  {
1078  maxCounterValue = EMIOS_DRV_MC_GetCounterPeriod((uint8_t)instance->instIdx, channel);
1079  /* Configure channel compare register */
1080  if (nextCompareMatchValue > (maxCounterValue - counterValue))
1081  {
1082  compareValue = (nextCompareMatchValue - (maxCounterValue - counterValue));
1083  }
1084  else
1085  {
1086  compareValue = (counterValue + nextCompareMatchValue);
1087  }
1088  }
1089  else
1090  {
1091  compareValue = nextCompareMatchValue;
1092  }
1093 
1094  /* Update the output compare value over EMIOS */
1095  EMIOS_DRV_OC_SetSingleActOutputCmpMatch((uint8_t)instance->instIdx,
1096  channel, compareValue);
1097  status = STATUS_SUCCESS;
1098  }
1099  else
1100 #endif
1101 
1102 #if (defined(OC_PAL_OVER_ETIMER))
1103  if(instance->instType == OC_INST_TYPE_ETIMER)
1104  {
1105  uint16_t compareValue = 0U;
1106  uint16_t counterValue = ETIMER_DRV_GetTimerTicks((uint16_t)instance->instIdx, (uint16_t)channel);
1107 
1108  if (typeOfupdate == OC_RELATIVE_VALUE)
1109  {
1110  /* Configure channel compare register */
1111  if ((uint16_t)nextCompareMatchValue > (ETIMER_CH_MAX_TIMER_COUNT - counterValue))
1112  {
1113  compareValue = ((uint16_t)nextCompareMatchValue - (ETIMER_CH_MAX_TIMER_COUNT - counterValue));
1114  }
1115  else
1116  {
1117  compareValue = (counterValue + (uint16_t)nextCompareMatchValue);
1118  }
1119  }
1120  else
1121  {
1122  compareValue = (uint16_t)nextCompareMatchValue;
1123  }
1124 
1125  /* Update the output compare value over ETIMER */
1126  ETIMER_DRV_Set_CMPLD1((uint16_t)instance->instIdx,
1127  channel,
1128  compareValue);
1129  }
1130  else
1131 #endif
1132 
1133  {
1134  DEV_ASSERT(false);
1135  }
1136  return status;
1137 }
1138 
1139 /*FUNCTION**********************************************************************
1140  *
1141  * Function Name : OC_EnableNotification
1142  * Description : This function enables channel notification.
1143  *
1144  * Implements : OC_EnableNotification_Activity
1145  *END**************************************************************************/
1146 void OC_EnableNotification(const oc_instance_t * const instance,
1147  const uint8_t channel)
1148 {
1149  DEV_ASSERT(instance != NULL);
1150  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
1151  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
1152  uint8_t index = 0U;
1153  oc_pal_state_t * ocState;
1154 
1155  /* Allocate one of the OC state structure for this instance */
1156  index = FindOcState(instance->instIdx);
1157  ocState = &g_ocPalStatePtr[index];
1158 
1159  /* Enable notification */
1160  ocState->enableNotification[channel] = true;
1161 }
1162 
1163 /*FUNCTION**********************************************************************
1164  *
1165  * Function Name : OC_DisableNotification
1166  * Description : This function disables channel notification.
1167  *
1168  * Implements : OC_DisableNotification_Activity
1169  *END**************************************************************************/
1170 void OC_DisableNotification(const oc_instance_t * const instance,
1171  const uint8_t channel)
1172 {
1173  DEV_ASSERT(instance != NULL);
1174  DEV_ASSERT(instance->instIdx < OC_PAL_INSTANCES_MAX);
1175  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
1176  uint8_t index = 0U;
1177  oc_pal_state_t * ocState;
1178 
1179  /* Allocate one of the OC state structure for this instance */
1180  index = FindOcState(instance->instIdx);
1181  ocState = &g_ocPalStatePtr[index];
1182 
1183  /* Disable notification */
1184  ocState->enableNotification[channel] = false;
1185 }
1186 
1187 /*FUNCTION**********************************************************************
1188  *
1189  * Function Name : OC_IrqHandler
1190  * Description : Interrupt handler for OC PAL.
1191  * This is not a public API as it is called by IRQ whenever an interrupt occurs.
1192  *
1193  *END**************************************************************************/
1194 void OC_IrqHandler(uint32_t instance, uint8_t channel)
1195 {
1196  DEV_ASSERT(instance < OC_PAL_INSTANCES_MAX);
1197  DEV_ASSERT(channel < OC_PAL_NUM_OF_CHANNEL_MAX);
1198  uint8_t index = 0U;
1199  oc_pal_state_t * ocState;
1200 #if (defined (OC_PAL_OVER_FTM))
1201  FTM_Type * const base = g_ftmBase[instance];
1202 #endif
1203 
1204  /* Allocate one of the OC state structure for this instance */
1205  index = FindOcState(instance);
1206  ocState = &g_ocPalStatePtr[index];
1207 
1208  if ((ocState->channelCallbacks[channel] != NULL) && (ocState->enableNotification[channel] == true))
1209  {
1210  /* Call to callback function */
1211  (ocState->channelCallbacks[channel])(OC_EVENT_GENERATION_OUTPUT_COMPLETE, ocState->channelCallbackParams[channel]);
1212  }
1213 
1214 #if (defined (OC_PAL_OVER_FTM))
1215  /* Clear interrupt flag */
1216  FTM_DRV_ClearChnEventStatus(base, channel);
1217 #endif
1218 
1219 #if (defined(OC_PAL_OVER_EMIOS))
1220  /* Clear interrupt flag */
1221  EMIOS_DRV_ClrFlagState(instance, channel);
1222 #endif
1223 
1224 #if (defined(OC_PAL_OVER_ETIMER))
1225  /* Clear interrupt flag */
1226  ETIMER_DRV_ClearInterruptStatus((uint16_t)instance,
1227  (ETIMER_CH_IRQ_FLAGS_TCF | ETIMER_CH_IRQ_FLAGS_TCF1 | ETIMER_CH_IRQ_FLAGS_TCF2),
1228  channel);
1229 #endif
1230 }
1231 
1232 /*******************************************************************************
1233  * EOF
1234  ******************************************************************************/
status_t OC_SetCompareValue(const oc_instance_t *const instance, const uint8_t channel, uint32_t nextCompareMatchValue, oc_option_update_t typeOfupdate)
Update the match value on the channel.
Definition: oc_pal.c:1047
ftm_reg_update_t initCounterSync
Definition: ftm_common.h:425
status_t FTM_DRV_SetSoftwareOutputChannelControl(uint32_t instance, uint8_t channelsMask, bool softwareTrigger)
This function will configure which output channel can be software controlled.
Definition: ftm_common.c:301
ftm_pwm_sync_t syncMethod
Definition: ftm_common.h:438
uint8_t nNumChannels
Definition: oc_pal.h:102
FlexTimer state structure of the driver.
Definition: ftm_common.h:391
#define FTM_CONTROLS_COUNT
Definition: S32K118.h:3822
#define FTM_IRQS
Definition: S32K118.h:3895
FlexTimer driver PWM parameters.
Definition: ftm_oc_driver.h:68
ftm_bdm_mode_t BDMMode
Definition: ftm_common.h:444
bool hardwareSync2
Definition: ftm_common.h:416
#define FEATURE_FTM_CHANNEL_COUNT
uint16_t comparedValue
Definition: oc_pal.h:89
Configuration structure that the user needs to set.
Definition: ftm_common.h:436
uint32_t instIdx
ftm_config_mode_t mode
Definition: ftm_oc_driver.h:85
void OC_IrqHandler(uint32_t instance, uint8_t channel)
Definition: oc_pal.c:1194
ftm_output_cmp_ch_param_t * outputChannelConfig
Definition: ftm_oc_driver.h:87
static oc_pal_state_t g_ocPalStatePtr[NUMBER_OF_OC_PAL_INSTANCES]
Definition: oc_pal.c:121
The internal context structure.
Definition: oc_pal.c:104
oc_callback_t channelCallbacks
Definition: oc_pal.h:92
FlexTimer Registers sync parameters Please don't use software and hardware trigger simultaneously Imp...
Definition: ftm_common.h:408
ftm_output_compare_mode_t chMode
Definition: ftm_oc_driver.h:71
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
ftm_output_compare_mode_t
FlexTimer Mode configuration for output compare mode.
Definition: ftm_oc_driver.h:44
bool hardwareSync1
Definition: ftm_common.h:414
void OC_StartChannel(const oc_instance_t *const instance, const uint8_t channel)
Start the counter.
Definition: oc_pal.c:817
oc_inst_type_t instType
void * channelExtension
Definition: oc_pal.h:90
#define DEV_ASSERT(x)
Definition: devassert.h:77
status_t FTM_DRV_InitOutputCompare(uint32_t instance, const ftm_output_cmp_param_t *param)
Configures the FTM to generate timed pulses(Output compare mode).
Definition: ftm_oc_driver.c:45
const oc_output_ch_param_t * outputChConfig
Definition: oc_pal.h:103
void * channelCallbackParams
Definition: oc_pal.h:91
ftm_output_compare_update_t
FlexTimer input capture type of the next output compare value.
Definition: ftm_oc_driver.h:57
status_t OC_SetOutputState(const oc_instance_t *const instance, const uint8_t channel, bool outputValue)
Control the channel output by software.
Definition: oc_pal.c:925
bool hardwareSync0
Definition: ftm_common.h:412
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
status_t OC_SetOutputAction(const oc_instance_t *const instance, const uint8_t channel, oc_option_mode_t channelMode)
Set the operation mode of channel output.
Definition: oc_pal.c:982
status_t OC_Deinit(const oc_instance_t *const instance)
De-initialize the output compare instance.
Definition: oc_pal.c:742
bool maxLoadingPoint
Definition: ftm_common.h:418
void OC_StopChannel(const oc_instance_t *const instance, const uint8_t channel)
Stop the counter.
Definition: oc_pal.c:874
#define FTM_INSTANCE_COUNT
Definition: S32K118.h:3868
oc_option_mode_t
The type of comparison for output compare mode Implements : oc_option_mode_t_Class.
Definition: oc_pal.h:62
bool enableInitializationTrigger
Definition: ftm_common.h:447
static uint32_t ocStateInstanceMapping[NUMBER_OF_OC_PAL_INSTANCES]
Definition: oc_pal.c:124
ftm_reg_update_t inverterSync
Definition: ftm_common.h:422
void * extension
Definition: oc_pal.h:104
void OC_EnableNotification(const oc_instance_t *const instance, const uint8_t channel)
Enable channel notifications.
Definition: oc_pal.c:1146
uint8_t hwChannelId
Definition: oc_pal.h:87
status_t FTM_DRV_EnableInterrupts(uint32_t instance, uint32_t interruptMask)
This function will enable the generation a list of interrupts. It includes the FTM overflow interrupt...
Definition: ftm_common.c:485
ftm_config_mode_t ftmMode
Definition: ftm_common.h:440
void(* oc_callback_t)(oc_event_t event, void *userData)
Definition: callbacks.h:177
FlexTimer driver PWM parameters.
Definition: ftm_oc_driver.h:82
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_reg_update_t maskRegSync
Definition: ftm_common.h:424
static void FTM_DRV_ClearChnEventStatus(FTM_Type *const ftmBase, uint8_t channel)
Clears the FTM peripheral timer all channel event status.
Definition: ftm_common.h:796
static bool ocStateIsAllocated[NUMBER_OF_OC_PAL_INSTANCES]
Definition: oc_pal.c:126
bool minLoadingPoint
Definition: ftm_common.h:420
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
status_t FTM_DRV_SetSoftOutChnValue(uint32_t instance, uint8_t channelsValues, bool softwareTrigger)
This function will force the output value of a channel to a specific value. Before using this functio...
Definition: ftm_common.c:281
status_t OC_Init(const oc_instance_t *const instance, const oc_config_t *const configPtr)
Initializes the output compare mode.
Definition: oc_pal.c:688
void(* isr_t)(void)
Interrupt handler type.
void OC_DisableNotification(const oc_instance_t *const instance, const uint8_t channel)
Disable channel notifications.
Definition: oc_pal.c:1170
status_t FTM_DRV_UpdateOutputCompareChannel(uint32_t instance, uint8_t channel, uint16_t nextComparematchValue, ftm_output_compare_update_t update, bool softwareTrigger)
Sets the next compare match value based on the current counter value.
static uint8_t FindOcState(uint32_t instance)
Definition: oc_pal.c:194
static uint8_t ocAllocateState(bool *isAllocated, uint32_t *instanceMapping, uint32_t instance, uint8_t numberOfInstances)
Definition: oc_pal.c:143
ftm_clock_source_t ftmClockSource
Definition: ftm_common.h:443
oc_option_update_t
The type of update on the channel match Implements : oc_option_mode_t_Class.
Definition: oc_pal.h:74
ftm_reg_update_t outRegSync
Definition: ftm_common.h:423
Defines the configuration structures are used in the output compare mode.
Definition: oc_pal.h:100
static void ocFreeState(bool *isAllocated, uint32_t *instanceMapping, uint32_t instance, uint8_t numberOfInstances)
Definition: oc_pal.c:170
ftm_clock_ps_t ftmPrescaler
Definition: ftm_common.h:441
oc_option_mode_t chMode
Definition: oc_pal.h:88
FTM_Type *const g_ftmBase[(2u)]
Table of base addresses for FTM instances.
Definition: ftm_common.c:71
void INT_SYS_InstallHandler(IRQn_Type irqNumber, const isr_t newHandler, isr_t *const oldHandler)
Installs an interrupt handler routine for a given IRQ number.
Structure storing PAL instance information.