timing_pal.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017 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  */
17 
63 #include <stddef.h>
64 #include "timing_pal.h"
65 #include "timing_irq.h"
66 #include "device_registers.h"
67 #include "interrupt_manager.h"
68 #include "clock_manager.h"
69 
70 /*******************************************************************************
71  * Definitions
72  ******************************************************************************/
73 
80 typedef struct
81 {
83  uint32_t period;
84  uint32_t chanStartVal;
85  timer_chan_type_t chanType;
86  timer_callback_t callback;
87  void * callbackParam;
88  bool enableNotification;
91 
92 /*******************************************************************************
93  * Variables
94  ******************************************************************************/
95 #if (defined(TIMING_OVER_LPIT))
96  /* Table to save LPIT channel runtime state */
98  /* The maximum value of compare register */
99  #define LPIT_COMPARE_MAX (LPIT_TMR_TVAL_TMR_VAL_MASK)
100 #endif
101 
102 #if (defined(TIMING_OVER_LPTMR))
103  /* The maximum value of LPTMR channel number */
104  #define LPTMR_TMR_COUNT LPTMR_IRQS_CH_COUNT
105  /* Table to save LPTMR channel runtime state */
106  static timer_chan_state_t s_lptmrState[LPTMR_INSTANCE_COUNT][LPTMR_TMR_COUNT];
107  /* Table to save LPTMR clock source name */
108  static lptmr_clocksource_t s_lptmrClockSource[LPTMR_INSTANCE_COUNT];
109  /* Table to save LPTMR prescaler */
110  static lptmr_prescaler_t s_lptmrPrescaler[LPTMR_INSTANCE_COUNT];
111  /* Table to save LPTMR bypass prescaler enable */
112  static bool s_lptmrBypassPrescaler[LPTMR_INSTANCE_COUNT];
113  /* The maximum value of compare register */
114  #define LPTMR_COMPARE_MAX (LPTMR_CMR_COMPARE_MASK)
115 #endif
116 
117 #if (defined(TIMING_OVER_FTM))
118 
119  FTM_Type * const ftmBase[FTM_INSTANCE_COUNT] = FTM_BASE_PTRS;
120  /* Table to save FTM channel runtime state */
122  /* Table to save FTM channel running status */
123  bool g_ftmChannelRunning[FTM_INSTANCE_COUNT][FTM_CONTROLS_COUNT];
124  /* The maximum value of compare register */
125  #define FTM_COMPARE_MAX (FTM_CNT_COUNT_MASK)
126 #endif
127 
128 #if (defined(TIMING_OVER_PIT))
129  /* Table to save PIT channel runtime state */
130  static timer_chan_state_t s_pitState[PIT_INSTANCE_COUNT][PIT_TIMER_COUNT];
131  /* Table to save PIT clock source name */
132  static clock_names_t s_pitClockName[PIT_INSTANCE_COUNT] = {PITRTI0_CLK};
133  /* The maximum value of compare register */
134  #define PIT_COMPARE_MAX (PIT_LDVAL_TSV_MASK)
135 #endif
136 
137 #if (defined(TIMING_OVER_STM))
138  /* Table to save STM channel runtime state */
139  static timer_chan_state_t s_stmState[STM_INSTANCE_COUNT][STM_CHANNEL_COUNT];
140 #if FEATURE_STM_HAS_CLOCK_SELECTION
141  /* Table to save STM clock source name */
142  static stm_clock_source_t s_stmClockSource[STM_INSTANCE_COUNT];
143 #endif
144  /* Table to save STM prescaler */
145  static uint8_t s_stmPrescaler[STM_INSTANCE_COUNT];
146  /* The maximum value of compare register */
147  #define STM_COMPARE_MAX (STM_CMP_CMP_MASK)
148 #endif
149 
150 /*******************************************************************************
151  * Private Functions
152  ******************************************************************************/
153 
154 #if (defined(TIMING_OVER_LPIT))
155 /*FUNCTION**********************************************************************
156  *
157  * Function Name : TIMING_InitLpit
158  * Description : This function initializes TIMING over LPIT.
159  *END**************************************************************************/
160 static status_t TIMING_InitLpit(uint32_t instance,
161  const timer_config_t * config)
162 {
163  DEV_ASSERT(instance < LPIT_INSTANCE_COUNT);
164 
165  status_t status = STATUS_SUCCESS;
167  lpit_user_config_t lpitConfig;
168  lpit_user_channel_config_t channelConfig;
169  timer_chan_state_t * channelState;
170  uint32_t chanIndex;
171  uint8_t index;
172 
173  /* Set global structure */
174  lpitConfig.enableRunInDebug = true;
175  lpitConfig.enableRunInDoze = true;
176  /* Set channel configuration structure */
177  channelConfig.timerMode = LPIT_PERIODIC_COUNTER;
178  channelConfig.periodUnits = LPIT_PERIOD_UNITS_COUNTS;
179  channelConfig.period = 0U;
181  channelConfig.triggerSelect = 0U;
182  channelConfig.enableReloadOnTrigger = false;
183  channelConfig.enableStopOnInterrupt = false;
184  channelConfig.enableStartOnTrigger = false;
185  channelConfig.chainChannel = false;
186  channelConfig.isInterruptEnabled = true;
187  /* Initialize LPIT instance */
188  LPIT_DRV_Init(instance, &lpitConfig);
189  /* Initialize LPIT channels */
190  for (index = 0U; index < config->numChan; index++)
191  {
192  chanIndex = config->chanConfigArray[index].channel;
193  channelState = &s_lpitState[instance][chanIndex];
194  /* Initialize LPIT channels */
195  status = LPIT_DRV_InitChannel(instance, chanIndex, &channelConfig);
196  if (status != STATUS_SUCCESS)
197  {
198  break;
199  }
200  /* Save runtime state structure of timer channel */
201  channelState->chanType = config->chanConfigArray[index].chanType;
202  channelState->callback = config->chanConfigArray[index].callback;
203  channelState->callbackParam = config->chanConfigArray[index].callbackParam;
204  channelState->enableNotification = false;
205  /* Enable LPIT interrupt */
206  INT_SYS_EnableIRQ(lpitIrq[instance][chanIndex]);
207  }
208 
209  return status;
210 }
211 #endif
212 
213 #if (defined(TIMING_OVER_LPTMR))
214 /*FUNCTION**********************************************************************
215  *
216  * Function Name : TIMING_InitLptmr
217  * Description : This function initializes TIMING over LPTMR.
218  *END**************************************************************************/
219 static status_t TIMING_InitLptmr(uint32_t instance,
220  const timer_config_t * config)
221 {
222  DEV_ASSERT(instance < LPTMR_INSTANCE_COUNT);
223 
224  status_t status = STATUS_SUCCESS;
225  const IRQn_Type lptmrIrq[LPTMR_INSTANCE_COUNT][LPTMR_TMR_COUNT] = {LPTMR_IRQS};
226  lptmr_config_t lptmrConfig;
227  timer_chan_state_t * channelState;
228  uint8_t chanIndex;
229  uint8_t index;
230 
231  /* Set lptmr structure */
232  lptmrConfig.dmaRequest = false;
233  lptmrConfig.interruptEnable = true;
234  lptmrConfig.freeRun = false;
235  lptmrConfig.workMode = LPTMR_WORKMODE_TIMER;
236  lptmrConfig.clockSelect = ((extension_lptmr_for_timer_t*)(config->extension))->clockSelect;
237  lptmrConfig.prescaler = ((extension_lptmr_for_timer_t*)(config->extension))->prescaler;
238  lptmrConfig.bypassPrescaler = ((extension_lptmr_for_timer_t*)(config->extension))->bypassPrescaler;
240  lptmrConfig.pinSelect = LPTMR_PINSELECT_TRGMUX;
242  lptmrConfig.compareValue = 0U;
243  /* Save LPTMR clock source name */
244  s_lptmrClockSource[instance] = ((extension_lptmr_for_timer_t*)(config->extension))->clockSelect;
245  /* Save LPTMR prescaler */
246  s_lptmrPrescaler[instance] = ((extension_lptmr_for_timer_t*)(config->extension))->prescaler;
247  /* Save LPTMR bypass enable */
248  s_lptmrBypassPrescaler[instance] = ((extension_lptmr_for_timer_t*)(config->extension))->bypassPrescaler;
249  /* Initialize LPTMR instance */
250  LPTMR_DRV_Init(instance, &lptmrConfig, false);
251 
252  for (index = 0U; index < config->numChan; index++)
253  {
254  chanIndex = config->chanConfigArray[index].channel;
255  DEV_ASSERT(chanIndex < LPTMR_TMR_COUNT);
256  channelState = &s_lptmrState[instance][chanIndex];
257  /* Save runtime state structure of timer channel */
258  channelState->chanType = config->chanConfigArray[index].chanType;
259  channelState->callback = config->chanConfigArray[index].callback;
260  channelState->callbackParam = config->chanConfigArray[index].callbackParam;
261  channelState->enableNotification = false;
262  /* Enable LPTMR interrupt */
263  INT_SYS_EnableIRQ(lptmrIrq[instance][chanIndex]);
264  }
265 
266  return status;
267 }
268 #endif
269 
270 #if (defined(TIMING_OVER_FTM))
271 /*FUNCTION**********************************************************************
272  *
273  * Function Name : TIMING_InitFtm
274  * Description : This function initializes TIMING over FTM.
275  *END**************************************************************************/
276 static status_t TIMING_InitFtm(uint32_t instance,
277  const timer_config_t * config)
278 {
279  DEV_ASSERT(instance < FTM_INSTANCE_COUNT);
280 
281  status_t status = STATUS_SUCCESS;
283  static ftm_state_t ftmState;
284  ftm_user_config_t ftmConfig;
285  ftm_output_cmp_param_t outputCmpConfig;
287  timer_chan_state_t * channelState;
288  uint8_t chanIndex;
289  uint8_t index;
290 
291  /* Set ftm structure */
292  ftmConfig.syncMethod.softwareSync = true;
293  ftmConfig.syncMethod.hardwareSync0 = false;
294  ftmConfig.syncMethod.hardwareSync1 = false;
295  ftmConfig.syncMethod.hardwareSync2 = false;
296  ftmConfig.syncMethod.maxLoadingPoint = true;
297  ftmConfig.syncMethod.minLoadingPoint = false;
302  ftmConfig.syncMethod.autoClearTrigger = false;
303  ftmConfig.syncMethod.syncPoint = FTM_UPDATE_NOW;
304  ftmConfig.ftmMode = FTM_MODE_OUTPUT_COMPARE;
305  ftmConfig.ftmPrescaler = ((extension_ftm_for_timer_t*)(config->extension))->prescaler;
306  ftmConfig.ftmClockSource = ((extension_ftm_for_timer_t*)(config->extension))->clockSelect;
307  ftmConfig.BDMMode = FTM_BDM_MODE_00;
308  ftmConfig.isTofIsrEnabled = false;
309  ftmConfig.enableInitializationTrigger = false;
310 
311  /* Initialize running status of FTM channels */
312  for (index = 0U; index < FTM_CONTROLS_COUNT; index++)
313  {
314  g_ftmChannelRunning[instance][index] = false;
315  }
316  /* Set output compare configuration structure */
317  for (index = 0U; index < config->numChan; index++)
318  {
319  chnConfigArray[index].hwChannelId = config->chanConfigArray[index].channel;
320  chnConfigArray[index].chMode = FTM_TOGGLE_ON_MATCH;
321  chnConfigArray[index].comparedValue = FTM_COMPARE_MAX;
322  chnConfigArray[index].enableExternalTrigger = false;
323  }
324  outputCmpConfig.nNumOutputChannels = config->numChan;
325  outputCmpConfig.mode = FTM_MODE_OUTPUT_COMPARE;
326  outputCmpConfig.maxCountValue = ((extension_ftm_for_timer_t*)(config->extension))->finalValue;
327  outputCmpConfig.outputChannelConfig = chnConfigArray;
328 
329  /* Initialize FTM instance */
330  status = FTM_DRV_Init(instance, &ftmConfig, &ftmState);
331  status |= FTM_DRV_InitOutputCompare(instance, &outputCmpConfig);
332 
333  if (status == STATUS_SUCCESS)
334  {
335  for (index = 0U; index < config->numChan; index++)
336  {
337  chanIndex = config->chanConfigArray[index].channel;
338  channelState = &s_ftmState[instance][chanIndex];
339  /* Save runtime state structure of timer channel */
340  channelState->chanType = config->chanConfigArray[index].chanType;
341  channelState->callback = config->chanConfigArray[index].callback;
342  channelState->callbackParam = config->chanConfigArray[index].callbackParam;
343  channelState->enableNotification = false;
344  /* Install FTM irq handler */
345  INT_SYS_InstallHandler(ftmIrq[instance][chanIndex],
346  s_timingOverFtmIsr[instance][chanIndex], (isr_t*)0);
347  /* Enable FTM interrupt */
348  INT_SYS_EnableIRQ(ftmIrq[instance][chanIndex]);
349  }
350  }
351  else
352  {
353  status = STATUS_ERROR;
354  }
355 
356  return status;
357 }
358 #endif
359 
360 #if (defined(TIMING_OVER_PIT))
361 /*FUNCTION**********************************************************************
362  *
363  * Function Name : TIMING_InitPit
364  * Description : This function initializes TIMING over PIT.
365  *END**************************************************************************/
366 static status_t TIMING_InitPit(uint32_t instance,
367  const timer_config_t * config)
368 {
369  DEV_ASSERT(instance < PIT_INSTANCE_COUNT);
370 
371  status_t status = STATUS_SUCCESS;
372  const IRQn_Type pitIrq[PIT_INSTANCE_COUNT][PIT_IRQS_CH_COUNT] = PIT_IRQS;
373  pit_config_t pitConfig;
374  pit_channel_config_t channelConfig;
375  timer_chan_state_t * channelState;
376  uint8_t chanIndex;
377  uint8_t index;
378 
379  /* Set global structure */
380 #if FEATURE_PIT_HAS_RTI_CHANNEL
381  pitConfig.enableRTITimer = false;
382 #endif
383  pitConfig.enableStandardTimers = true;
384  pitConfig.stopRunInDebug = true;
385  /* Set channel configuration structure */
386  channelConfig.hwChannel = 0U;
387  channelConfig.periodUnit = PIT_PERIOD_UNITS_COUNTS;
388  channelConfig.period = 0U;
389  channelConfig.enableChain = false;
390  channelConfig.enableInterrupt = true;
391 
392  /* Initialize PIT instance */
393  PIT_DRV_Init(instance, &pitConfig);
394 
395  for (index = 0U; index < config->numChan; index++)
396  {
397  chanIndex = config->chanConfigArray[index].channel;
398  channelState = &s_pitState[instance][chanIndex];
399  /* Initialize PIT channels */
400  channelConfig.hwChannel = chanIndex;
401  status = PIT_DRV_InitChannel(instance, &channelConfig);
402  if (status != STATUS_SUCCESS)
403  {
404  break;
405  }
406  /* Save runtime state structure of timer channel */
407  channelState->chanType = config->chanConfigArray[index].chanType;
408  channelState->callback = config->chanConfigArray[index].callback;
409  channelState->callbackParam = config->chanConfigArray[index].callbackParam;
410  channelState->enableNotification = false;
411  /* Enable PIT interrupt */
412  INT_SYS_EnableIRQ(pitIrq[instance][chanIndex]);
413  }
414 
415  return status;
416 }
417 #endif
418 
419 #if (defined(TIMING_OVER_STM))
420 /*FUNCTION**********************************************************************
421  *
422  * Function Name : TIMING_InitStm
423  * Description : This function initializes TIMING over STM.
424  *END**************************************************************************/
425 static status_t TIMING_InitStm(uint32_t instance,
426  const timer_config_t * config)
427 {
428  DEV_ASSERT(instance < STM_INSTANCE_COUNT);
429 
430  status_t status = STATUS_SUCCESS;
431  const IRQn_Type stmIrq[STM_INSTANCE_COUNT][STM_CHANNEL_COUNT] = STM_IRQS;
432  stm_config_t stmConfig;
433  timer_chan_state_t * channelState;
434  uint8_t chanIndex;
435  uint8_t index;
436 
437  /* Set stm structure */
438 #if FEATURE_STM_HAS_CLOCK_SELECTION
439  stmConfig.clockSource = ((extension_stm_for_timer_t*)(config->extension))->clockSelect;
440  /* Save LPTMR clock source name */
441  s_stmClockSource[instance] = ((extension_stm_for_timer_t*)(config->extension))->clockSelect;
442 #endif
443  stmConfig.clockPrescaler = ((extension_stm_for_timer_t*)(config->extension))->prescaler;
444  stmConfig.stopInDebugMode = true;
445  stmConfig.startValue = 0U;
446  /* Save LPTMR prescaler */
447  s_stmPrescaler[instance] = ((extension_stm_for_timer_t*)(config->extension))->prescaler;
448  /* Initialize STM instance */
449  STM_DRV_Init(instance, &stmConfig);
450 
451  for (index = 0U; index < config->numChan; index++)
452  {
453  chanIndex = config->chanConfigArray[index].channel;
454  channelState = &s_stmState[instance][chanIndex];
455  /* Save runtime state structure of timer channel */
456  channelState->chanType = config->chanConfigArray[index].chanType;
457  channelState->callback = config->chanConfigArray[index].callback;
458  channelState->callbackParam = config->chanConfigArray[index].callbackParam;
459  channelState->enableNotification = false;
460  /* Enable STM interrupt */
461  INT_SYS_EnableIRQ(stmIrq[instance][chanIndex]);
462  }
463 
464  return status;
465 }
466 #endif
467 
468 /*******************************************************************************
469  * FUCNTION FUNCTION
470  ******************************************************************************/
471 
472 /*FUNCTION**********************************************************************
473  *
474  * Function Name : TIMING_Init
475  * Description : Initialize timer instance.
476  * This function initializes clock source, prescaler of the timer instance(except LPIT, PIT), the final
477  * value of counter (only FTM). This function also setups notification type and callback function of timer channel.
478  * The timer instance number and its configuration structure shall be passed as arguments.
479  * Timer channels do not start counting by default after calling this function.
480  * The function TIMING_StartChannel must be called to start the timer channel counting.
481  *
482  * Implements : TIMING_Init_Activity
483  *END**************************************************************************/
484 status_t TIMING_Init(const timing_instance_t * const instance,
485  const timer_config_t * const config)
486 {
487  DEV_ASSERT(instance != NULL);
488  DEV_ASSERT(config != NULL);
489  status_t status = STATUS_ERROR;
490 
491  /* Define TIMING PAL over LPIT */
492 #if (defined (TIMING_OVER_LPIT))
493  if (instance->instType == TIMING_INST_TYPE_LPIT)
494  {
495  /* Initialize TIMING over LPIT */
496  status = TIMING_InitLpit(instance->instIdx, config);
497  }
498  else
499 #endif
500 
501  /* Define TIMING PAL over LPTMR */
502 #if (defined (TIMING_OVER_LPTMR))
503  if (instance->instType == TIMING_INST_TYPE_LPTMR)
504  {
505  DEV_ASSERT(config->extension != NULL);
506 
507  /* Initialize TIMING over LPTMR */
508  status = TIMING_InitLptmr(instance->instIdx, config);
509  }
510  else
511 #endif
512 
513  /* Define TIMING PAL over FTM */
514 #if (defined (TIMING_OVER_FTM))
515  if (instance->instType == TIMING_INST_TYPE_FTM)
516  {
517  DEV_ASSERT(config->extension != NULL);
518 
519  /* Initialize TIMING over FTM */
520  status = TIMING_InitFtm(instance->instIdx, config);
521  }
522  else
523 #endif
524 
525  /* Define TIMING PAL over PIT */
526 #if (defined (TIMING_OVER_PIT))
527  if (instance->instType == TIMING_INST_TYPE_PIT)
528  {
529  /* Initialize TIMING over LPIT */
530  status = TIMING_InitPit(instance->instIdx, config);
531  }
532  else
533 #endif
534 
535  /* Define TIMING PAL over STM */
536 #if (defined (TIMING_OVER_STM))
537  if (instance->instType == TIMING_INST_TYPE_STM)
538  {
539  DEV_ASSERT(config->extension != NULL);
540 
541  /* Initialize TIMING over STM */
542  status = TIMING_InitStm(instance->instIdx, config);
543  }
544  else
545 #endif
546  {
547  DEV_ASSERT(false);
548  }
549 
550  return status;
551 }
552 
553 /*FUNCTION**********************************************************************
554  *
555  * Function Name : TIMING_Deinit
556  * Description : De-initialize timer instance.
557  * This function de-initializes timer instance.
558  * In order to use the timer instance again, TIMING_Init must be called.
559  *
560  * Implements : TIMING_Deinit_Activity
561  *END**************************************************************************/
562 void TIMING_Deinit(const timing_instance_t * const instance)
563 {
564  DEV_ASSERT(instance != NULL);
565 
566  /* Define TIMING PAL over LPIT */
567 #if (defined (TIMING_OVER_LPIT))
568  if (instance->instType == TIMING_INST_TYPE_LPIT)
569  {
570  LPIT_DRV_Deinit(instance->instIdx);
571  }
572  else
573 #endif
574 
575  /* Define TIMING PAL over LPTMR */
576 #if (defined (TIMING_OVER_LPTMR))
577  if (instance->instType == TIMING_INST_TYPE_LPTMR)
578  {
579  LPTMR_DRV_Deinit(instance->instIdx);
580  }
581  else
582 #endif
583 
584  /* Define TIMING PAL over FTM */
585 #if (defined (TIMING_OVER_FTM))
586  if (instance->instType == TIMING_INST_TYPE_FTM)
587  {
588  status_t retVal;
589 
590  retVal = FTM_DRV_Deinit(instance->instIdx);
591  (void)retVal;
592  }
593  else
594 #endif
595 
596  /* Define TIMING PAL over PIT */
597 #if (defined (TIMING_OVER_PIT))
598  if (instance->instType == TIMING_INST_TYPE_PIT)
599  {
600  PIT_DRV_Deinit(instance->instIdx);
601  }
602  else
603 #endif
604 
605  /* Define TIMING PAL over STM */
606 #if (defined (TIMING_OVER_STM))
607  if (instance->instType == TIMING_INST_TYPE_STM)
608  {
609  STM_DRV_Deinit(instance->instIdx);
610  }
611  else
612 #endif
613  {
614  DEV_ASSERT(false);
615  }
616 }
617 
618 /*FUNCTION**********************************************************************
619  *
620  * Function Name : TIMING_StartChannel
621  * Description : Starts the timer channel counting.
622  * This function starts channel counting with a new period in ticks.
623  * Note that:
624  * - If the timer is PIT or LPIT, to abort the current timer channel period and start a timer channel period with a
625  * new value, the timer channel must be stopped and started again.
626  * - If the timer is FTM, this function start channel by enable channel interrupt generation.
627  * - LPTMR and FTM is 16 bit timer, so the input period must be smaller than 65535.
628  * - LPTMR and FTM is 16 bit timer, so the input period must be smaller than 65535.
629  *
630  * Implements : TIMING_StartChannel_Activity
631  *END**************************************************************************/
632 void TIMING_StartChannel(const timing_instance_t * const instance,
633  const uint8_t channel,
634  const uint32_t periodTicks)
635 {
636  DEV_ASSERT(instance != NULL);
637 
638  timer_chan_state_t * channelState;
639 
640  /* Define TIMING PAL over LPIT */
641 #if (defined (TIMING_OVER_LPIT))
642  if (instance->instType == TIMING_INST_TYPE_LPIT)
643  {
644  uint32_t channelMask = 1UL << channel;
645 
646  /* Set the channel compare value */
647  LPIT_DRV_SetTimerPeriodByCount(instance->instIdx, channel, periodTicks);
648  /* Start the channel counting */
649  LPIT_DRV_StartTimerChannels(instance->instIdx, channelMask);
650 
651  channelState = &s_lpitState[instance->instIdx][channel];
652  /* Save the period of channel */
653  channelState->period = periodTicks;
654  /* Enable notification */
655  channelState->enableNotification = true;
656  }
657  else
658 #endif
659 
660  /* Define TIMING PAL over LPTMR */
661 #if (defined (TIMING_OVER_LPTMR))
662  if (instance->instType == TIMING_INST_TYPE_LPTMR)
663  {
664  DEV_ASSERT(periodTicks <= LPTMR_COMPARE_MAX);
665  DEV_ASSERT(channel < LPTMR_TMR_COUNT);
666  uint32_t lptmrInstance = instance->instIdx;
667  status_t retVal;
668 
669  /* Stop the channel counting */
670  LPTMR_DRV_StopCounter(lptmrInstance);
671  /* Set the channel compare value */
672  retVal = LPTMR_DRV_SetCompareValueByCount(lptmrInstance, (uint16_t)periodTicks);
673  (void)retVal;
674  /* Start the channel counting */
675  LPTMR_DRV_StartCounter(lptmrInstance);
676 
677  channelState = &s_lptmrState[lptmrInstance][channel];
678  /* Save the period of channel */
679  channelState->period = periodTicks;
680  /* Enable notification */
681  channelState->enableNotification = true;
682  }
683  else
684 #endif
685 
686  /* Define TIMING PAL over FTM */
687 #if (defined (TIMING_OVER_FTM))
688  if (instance->instType == TIMING_INST_TYPE_FTM)
689  {
690  uint32_t ftmInstance = instance->instIdx;
691  FTM_Type * const base = ftmBase[ftmInstance];
692  uint32_t currentCounter;
693  status_t retVal;
694 
695  DEV_ASSERT(periodTicks <= FTM_DRV_GetMod(base));
696 
697  /* Clear the channel interrupt flag which may be set after executed initialization timing function or a previous channel match event */
698  FTM_DRV_ClearChnEventStatus(base, channel);
699  /* Get current counter*/
700  currentCounter = FTM_DRV_GetCounter(base);
701  /* Update compare value of the channel */
702  retVal = FTM_DRV_UpdateOutputCompareChannel(ftmInstance, channel, (uint16_t)periodTicks, FTM_RELATIVE_VALUE, false);
703  /* Enable the channel by enable interrupt generation */
704  retVal = FTM_DRV_EnableInterrupts(ftmInstance, (1UL << channel));
705  /* Update channel running status */
706  g_ftmChannelRunning[ftmInstance][channel] = true;
707  (void)retVal;
708  /* Save the start value of channel at the moment the start channel function is called */
709  channelState = &s_ftmState[ftmInstance][channel];
710  channelState->chanStartVal = currentCounter;
711  /* Save the period of channel */
712  channelState->period = periodTicks;
713  /* Enable notification */
714  channelState->enableNotification = true;
715  }
716  else
717 #endif
718 
719  /* Define TIMING PAL over PIT */
720 #if (defined (TIMING_OVER_PIT))
721  if (instance->instType == TIMING_INST_TYPE_PIT)
722  {
723  const uint32_t pitInstance = instance->instIdx;
724  /* Set the channel compare value */
725  PIT_DRV_SetTimerPeriodByCount(pitInstance, channel, periodTicks);
726  /* Start the channel counting */
727  PIT_DRV_StartChannel(pitInstance, channel);
728 
729  channelState = &s_pitState[pitInstance][channel];
730  /* Save the period of channel */
731  channelState->period = periodTicks;
732  /* Enable notification */
733  channelState->enableNotification = true;
734  }
735  else
736 #endif
737 
738  /* Define TIMING PAL over STM */
739 #if (defined (TIMING_OVER_STM))
740  if (instance->instType == TIMING_INST_TYPE_STM)
741  {
742  uint32_t stmInstance = instance->instIdx;
743  uint32_t currentCounter;
744  uint32_t compareValue;
745 
746  /* Get current counter value */
747  currentCounter = STM_DRV_GetCounterValue(stmInstance);
748  /* Calculate the channel compare value */
749  if ((STM_COMPARE_MAX - currentCounter) >= periodTicks)
750  {
751  /* The distance from current value to max of compare register is enough */
752  compareValue = currentCounter + periodTicks;
753  }
754  else
755  {
756  /* The distance is not enough, calculates a new value for compare register */
757  compareValue = periodTicks - (STM_COMPARE_MAX - currentCounter);
758  }
759  /* Configure channel compare value */
760  STM_DRV_ConfigChannel(stmInstance, channel, compareValue);
761  /* Start counter */
762  STM_DRV_StartTimer(stmInstance);
763  /* Save the start value of channel at the moment the start channel function is called */
764  channelState = &s_stmState[stmInstance][channel];
765  channelState->chanStartVal = currentCounter;
766  /* Save the period of channel */
767  channelState->period = periodTicks;
768  /* Enable notification */
769  channelState->enableNotification = true;
770  }
771  else
772 #endif
773  {
774  DEV_ASSERT(false);
775  }
776 
777 }
778 
779 /*FUNCTION**********************************************************************
780  *
781  * Function Name : TIMING_StopChannel
782  * Description : Stop the timer channel counting.
783  * This function stop channel counting. Note that if the timer is FTM,
784  * this function stop channel by disable channel interrupt generation.
785  *
786  * Implements : TIMING_StopChannel_Activity
787  *END**************************************************************************/
788 void TIMING_StopChannel(const timing_instance_t * const instance,
789  const uint8_t channel)
790 {
791  DEV_ASSERT(instance != NULL);
792 
793  timer_chan_state_t * channelState;
794 
795  /* Define TIMING PAL over LPIT */
796 #if (defined (TIMING_OVER_LPIT))
797  if (instance->instType == TIMING_INST_TYPE_LPIT)
798  {
799  /* Stop the channel counting */
800  LPIT_DRV_StopTimerChannels(instance->instIdx, (1UL << channel));
801 
802  channelState = &s_lpitState[instance->instIdx][channel];
803  /* Disable notification */
804  channelState->enableNotification = false;
805  }
806  else
807 #endif
808 
809  /* Define TIMING PAL over LPTMR */
810 #if (defined (TIMING_OVER_LPTMR))
811  if (instance->instType == TIMING_INST_TYPE_LPTMR)
812  {
813  (void)channel;
814 
815  /* Stop the channel counting */
816  LPTMR_DRV_StopCounter(instance->instIdx);
817 
818  channelState = &s_lptmrState[instance->instIdx][channel];
819  /* Disable notification */
820  channelState->enableNotification = false;
821  }
822  else
823 #endif
824 
825  /* Define TIMING PAL over FTM */
826 #if (defined (TIMING_OVER_FTM))
827  if (instance->instType == TIMING_INST_TYPE_FTM)
828  {
829  /* Stop the channel by disable interrupt generation */
830  FTM_DRV_DisableInterrupts(instance->instIdx, (1UL << channel));
831  /* Update channel running status */
832  g_ftmChannelRunning[instance->instIdx][channel] = false;
833  channelState = &s_ftmState[instance->instIdx][channel];
834  /* Disable notification */
835  channelState->enableNotification = false;
836  }
837  else
838 #endif
839 
840  /* Define TIMING PAL over PIT */
841 #if (defined (TIMING_OVER_PIT))
842  if (instance->instType == TIMING_INST_TYPE_PIT)
843  {
844  /* Stop the channel counting */
845  PIT_DRV_StopChannel(instance->instIdx, channel);
846 
847  channelState = &s_pitState[instance->instIdx][channel];
848  /* Disable notification */
849  channelState->enableNotification = false;
850  }
851  else
852 #endif
853 
854  /* Define TIMING PAL over STM */
855 #if (defined (TIMING_OVER_STM))
856  if (instance->instType == TIMING_INST_TYPE_STM)
857  {
858  /* Stop the channel counting */
859  STM_DRV_DisableChannel(instance->instIdx, channel);
860 
861  /* Save the start value of channel at the moment the start channel function is called */
862  channelState = &s_stmState[instance->instIdx][channel];
863  /* Enable notification */
864  channelState->enableNotification = false;
865  }
866  else
867 #endif
868  {
869  DEV_ASSERT(false);
870  }
871 
872 }
873 
874 /*FUNCTION**********************************************************************
875  *
876  * Function Name : TIMING_GetElapsed
877  * Description : Get elapsed ticks.
878  * This function gets elapsed time since the last event by ticks. The elapsed time by nanosecond, microsecond or
879  * millisecond is the result of this function multiplies by the result of the TIMING_GetResolution
880  * function.
881  *
882  * Implements : TIMING_GetElapsed_Activity
883  *END**************************************************************************/
884 uint32_t TIMING_GetElapsed(const timing_instance_t * const instance,
885  const uint8_t channel)
886 {
887  DEV_ASSERT(instance != NULL);
888 
889  uint32_t currentCounter = 0U;
890  uint32_t timeElapsed = 0U;
891 
892  /* Define TIMING PAL over LPIT */
893 #if (defined (TIMING_OVER_LPIT))
894  if (instance->instType == TIMING_INST_TYPE_LPIT)
895  {
896  const timer_chan_state_t * lpitChannelState;
897  /* Get current channel counter value */
898  currentCounter = LPIT_DRV_GetCurrentTimerCount(instance->instIdx, channel);
899 
900  lpitChannelState = &s_lpitState[instance->instIdx][channel];
901  /* Calculate timer elapsed */
902  timeElapsed = lpitChannelState->period - currentCounter;
903  }
904  else
905 #endif
906 
907  /* Define TIMING PAL over LPTMR */
908 #if (defined (TIMING_OVER_LPTMR))
909  if (instance->instType == TIMING_INST_TYPE_LPTMR)
910  {
911  (void)channel;
912  (void)currentCounter;
913 
914  /* Time elapsed is current counter value */
915  timeElapsed = LPTMR_DRV_GetCounterValueByCount(instance->instIdx);
916  }
917  else
918 #endif
919 
920  /* Define TIMING PAL over FTM */
921 #if (defined (TIMING_OVER_FTM))
922  if (instance->instType == TIMING_INST_TYPE_FTM)
923  {
924  DEV_ASSERT((instance->instIdx) < FTM_INSTANCE_COUNT);
925 
926  uint32_t ftmInstance = instance->instIdx;
927  const FTM_Type * const base = ftmBase[ftmInstance];
928  uint16_t finalValue;
929  const timer_chan_state_t * ftmChannelState;
930 
931  /* Get current FTM counter value */
932  currentCounter = FTM_DRV_GetCounter(base);
933  /* Get the final value of counter */
934  finalValue = FTM_DRV_GetMod(base);
935  ftmChannelState = &s_ftmState[ftmInstance][channel];
936  /* Calculate time elapsed */
937  if (currentCounter >= ftmChannelState->chanStartVal)
938  {
939  /* In case the counter is smaller than the final value of counter */
940  timeElapsed = currentCounter - ftmChannelState->chanStartVal;
941  }
942  else
943  {
944  /* In case the counter is over the final value of counter */
945  timeElapsed = (finalValue - ftmChannelState->chanStartVal) + currentCounter;
946  }
947  }
948  else
949 #endif
950 
951  /* Define TIMING PAL over PIT */
952 #if (defined (TIMING_OVER_PIT))
953  if (instance->instType == TIMING_INST_TYPE_PIT)
954  {
955  uint32_t pitInstance = instance->instIdx;
956  const timer_chan_state_t * pitChannelState;
957 
958  /* Get current channel counter value */
959  currentCounter = PIT_DRV_GetCurrentTimerCount(pitInstance, channel);
960 
961  pitChannelState = &s_pitState[pitInstance][channel];
962  /* Calculate time elapsed */
963  timeElapsed = pitChannelState->period - currentCounter;
964  }
965  else
966 #endif
967 
968  /* Define TIMING PAL over STM */
969 #if (defined (TIMING_OVER_STM))
970  if (instance->instType == TIMING_INST_TYPE_STM)
971  {
972  uint32_t stmInstance = instance->instIdx;
973  const timer_chan_state_t * stmChannelState;
974 
975  /* Get current counter value */
976  currentCounter = STM_DRV_GetCounterValue(stmInstance);
977  stmChannelState = &s_stmState[stmInstance][channel];
978  /* Calculate time elapsed */
979  if (currentCounter >= (stmChannelState->chanStartVal))
980  {
981  /* In case the counter is smaller than the final value of counter */
982  timeElapsed = currentCounter - stmChannelState->chanStartVal;
983  }
984  else
985  {
986  /* In case the counter is over the final value of counter */
987  timeElapsed = (STM_COMPARE_MAX - stmChannelState->chanStartVal) + currentCounter;
988  }
989  }
990  else
991 #endif
992  {
993  DEV_ASSERT(false);
994  }
995 
996  return timeElapsed;
997 }
998 
999 /*FUNCTION**********************************************************************
1000  *
1001  * Function Name : TIMING_GetRemaining
1002  * Description : Get remaining ticks.
1003  * This function gets remaining time to next event by ticks. The remaining time by nanosecond, microsecond or
1004  * millisecond is the result of this function multiplies by the result of the TIMING_GetResolution
1005  * function.
1006  *
1007  * Implements : TIMING_GetRemaining_Activity
1008  *END**************************************************************************/
1009 uint32_t TIMING_GetRemaining(const timing_instance_t * const instance,
1010  const uint8_t channel)
1011 {
1012  DEV_ASSERT(instance != NULL);
1013 
1014  uint32_t timeElapsed = 0U;
1015  uint32_t timeRemain = 0U;
1016 
1017  /* Define TIMING PAL over LPIT */
1018 #if (defined (TIMING_OVER_LPIT))
1019  if (instance->instType == TIMING_INST_TYPE_LPIT)
1020  {
1021  (void)timeElapsed;
1022  /* Get the remaining time */
1023  timeRemain = LPIT_DRV_GetCurrentTimerCount(instance->instIdx, channel);
1024  }
1025  else
1026 #endif
1027 
1028  /* Define TIMING PAL over LPTMR */
1029 #if (defined (TIMING_OVER_LPTMR))
1030  if (instance->instType == TIMING_INST_TYPE_LPTMR)
1031  {
1032  DEV_ASSERT(channel < LPTMR_TMR_COUNT);
1033  uint32_t lptmrInstance = instance->instIdx;
1034  const timer_chan_state_t * lptmrChannelState;
1035 
1036  /* Time elapsed is current counter value */
1037  timeElapsed = LPTMR_DRV_GetCounterValueByCount(lptmrInstance);
1038 
1039  lptmrChannelState = &s_lptmrState[lptmrInstance][channel];
1040  /* Calculate the remaining time */
1041  timeRemain = lptmrChannelState->period - timeElapsed;
1042  }
1043  else
1044 #endif
1045 
1046  /* Define TIMING PAL over FTM */
1047 #if (defined (TIMING_OVER_FTM))
1048  if (instance->instType == TIMING_INST_TYPE_FTM)
1049  {
1050  DEV_ASSERT((instance->instIdx) < FTM_INSTANCE_COUNT);
1051 
1052  uint32_t ftmInstance = instance->instIdx;
1053  const FTM_Type * const base = ftmBase[ftmInstance];
1054  uint16_t ftmCurrentCounter = 0U;
1055  uint16_t finalValue;
1056  const timer_chan_state_t * ftmChannelState;
1057 
1058  /* Get current FTM counter value */
1059  ftmCurrentCounter = FTM_DRV_GetCounter(base);
1060  /* Get the final value of counter */
1061  finalValue = FTM_DRV_GetMod(base);
1062  ftmChannelState = &s_ftmState[ftmInstance][channel];
1063  /* Calculate time elapsed */
1064  if (ftmCurrentCounter >= ftmChannelState->chanStartVal)
1065  {
1066  /* In case the counter is smaller than the final value of counter */
1067  timeElapsed = ftmCurrentCounter - ftmChannelState->chanStartVal;
1068  }
1069  else
1070  {
1071  /* In case the counter is over the final value of counter */
1072  timeElapsed = (finalValue - ftmChannelState->chanStartVal) + ftmCurrentCounter;
1073  }
1074  /* Get the remaining time */
1075  timeRemain = ftmChannelState->period - timeElapsed;
1076  }
1077  else
1078 #endif
1079 
1080  /* Define TIMING PAL over PIT */
1081 #if (defined (TIMING_OVER_PIT))
1082  if (instance->instType == TIMING_INST_TYPE_PIT)
1083  {
1084  (void)timeElapsed;
1085 
1086  /* Get the remaining time */
1087  timeRemain = PIT_DRV_GetCurrentTimerCount(instance->instIdx, channel);
1088  }
1089  else
1090 #endif
1091 
1092  /* Define TIMING PAL over STM */
1093 #if (defined (TIMING_OVER_STM))
1094  if (instance->instType == TIMING_INST_TYPE_STM)
1095  {
1096  uint32_t stmInstance = instance->instIdx;
1097  const timer_chan_state_t * stmChannelState;
1098 
1099  /* Get current counter value */
1100  uint32_t stmCurrentCounter = STM_DRV_GetCounterValue(stmInstance);
1101  stmChannelState = &s_stmState[stmInstance][channel];
1102  /* Calculate time elapsed */
1103  if ((stmCurrentCounter >= stmChannelState->chanStartVal))
1104  {
1105  /* In case the counter is smaller than the final value of counter */
1106  timeElapsed = stmCurrentCounter - stmChannelState->chanStartVal;
1107  }
1108  else
1109  {
1110  /* In case the counter is over the final value of counter */
1111  timeElapsed = (STM_COMPARE_MAX - stmChannelState->chanStartVal) + stmCurrentCounter;
1112  }
1113  /* Get the remaining time */
1114  timeRemain = stmChannelState->period - timeElapsed;
1115  }
1116  else
1117 #endif
1118  {
1119  DEV_ASSERT(false);
1120  }
1121 
1122  return timeRemain;
1123 }
1124 
1125 /*FUNCTION**********************************************************************
1126  *
1127  * Function Name : TIMING_EnableNotification
1128  * Description : Enable channel notifications.
1129  * This function enables channel notification.
1130  *
1131  * Implements : TIMING_EnableNotification_Activity
1132  *END**************************************************************************/
1133 void TIMING_EnableNotification(const timing_instance_t * const instance,
1134  const uint8_t channel)
1135 {
1136  DEV_ASSERT(instance != NULL);
1137 
1138  timer_chan_state_t * channelState;
1139 
1140  /* Define TIMING PAL over LPIT */
1141 #if (defined (TIMING_OVER_LPIT))
1142  if (instance->instType == TIMING_INST_TYPE_LPIT)
1143  {
1144  DEV_ASSERT((instance->instIdx) < LPIT_INSTANCE_COUNT);
1145 
1146  channelState = &s_lpitState[instance->instIdx][channel];
1147  /* Enable notification */
1148  channelState->enableNotification = true;
1149  }
1150  else
1151 #endif
1152 
1153  /* Define TIMING PAL over LPTMR */
1154 #if (defined (TIMING_OVER_LPTMR))
1155  if (instance->instType == TIMING_INST_TYPE_LPTMR)
1156  {
1157  DEV_ASSERT((instance->instIdx) < LPTMR_INSTANCE_COUNT);
1158  DEV_ASSERT(channel < LPTMR_TMR_COUNT);
1159  uint32_t lptmrInstance = instance->instIdx;
1160 
1161  channelState = &s_lptmrState[lptmrInstance][channel];
1162  /* Enable notification */
1163  channelState->enableNotification = true;
1164 
1165  }
1166  else
1167 #endif
1168 
1169  /* Define TIMING PAL over FTM */
1170 #if (defined (TIMING_OVER_FTM))
1171  if (instance->instType == TIMING_INST_TYPE_FTM)
1172  {
1173  DEV_ASSERT((instance->instIdx) < FTM_INSTANCE_COUNT);
1174  uint32_t ftmInstance = instance->instIdx;
1175 
1176  channelState = &s_ftmState[ftmInstance][channel];
1177  /* Enable notification */
1178  channelState->enableNotification = true;
1179  }
1180  else
1181 #endif
1182 
1183  /* Define TIMING PAL over PIT */
1184 #if (defined (TIMING_OVER_PIT))
1185  if (instance->instType == TIMING_INST_TYPE_PIT)
1186  {
1187  DEV_ASSERT((instance->instIdx) < PIT_INSTANCE_COUNT);
1188  uint32_t pitInstance = instance->instIdx;
1189 
1190  channelState = &s_pitState[pitInstance][channel];
1191  /* Enable notification */
1192  channelState->enableNotification = true;
1193  }
1194  else
1195 #endif
1196 
1197  /* Define TIMING PAL over STM */
1198 #if (defined (TIMING_OVER_STM))
1199  if (instance->instType == TIMING_INST_TYPE_STM)
1200  {
1201  DEV_ASSERT((instance->instIdx) < STM_INSTANCE_COUNT);
1202  uint32_t stmInstance = instance->instIdx;
1203 
1204  channelState = &s_stmState[stmInstance][channel];
1205  /* Enable notification */
1206  channelState->enableNotification = true;
1207  }
1208  else
1209 #endif
1210  {
1211  DEV_ASSERT(false);
1212  }
1213 }
1214 
1215 /*FUNCTION**********************************************************************
1216  *
1217  * Function Name : TIMING_DisableNotification
1218  * Description : Disable channel notifications
1219  * This function disables channel notification.
1220  *
1221  * Implements : TIMING_DisableNotification_Activity
1222  *END**************************************************************************/
1223 void TIMING_DisableNotification(const timing_instance_t * const instance,
1224  const uint8_t channel)
1225 {
1226  DEV_ASSERT(instance != NULL);
1227 
1228  timer_chan_state_t * channelState;
1229 
1230  /* Define TIMING PAL over LPIT */
1231 #if (defined (TIMING_OVER_LPIT))
1232  if (instance->instType == TIMING_INST_TYPE_LPIT)
1233  {
1234  DEV_ASSERT((instance->instIdx) < LPIT_INSTANCE_COUNT);
1235 
1236  channelState = &s_lpitState[instance->instIdx][channel];
1237  /* Enable notification */
1238  channelState->enableNotification = false;
1239  }
1240  else
1241 #endif
1242 
1243  /* Define TIMING PAL over LPTMR */
1244 #if (defined (TIMING_OVER_LPTMR))
1245  if (instance->instType == TIMING_INST_TYPE_LPTMR)
1246  {
1247  DEV_ASSERT((instance->instIdx) < LPTMR_INSTANCE_COUNT);
1248  DEV_ASSERT(channel < LPTMR_TMR_COUNT);
1249 
1250  channelState = &s_lptmrState[instance->instIdx][channel];
1251  /* Enable notification */
1252  channelState->enableNotification = false;
1253 
1254  }
1255  else
1256 #endif
1257 
1258  /* Define TIMING PAL over FTM */
1259 #if (defined (TIMING_OVER_FTM))
1260  if (instance->instType == TIMING_INST_TYPE_FTM)
1261  {
1262  DEV_ASSERT((instance->instIdx) < FTM_INSTANCE_COUNT);
1263 
1264  channelState = &s_ftmState[instance->instIdx][channel];
1265  /* Enable notification */
1266  channelState->enableNotification = false;
1267  }
1268  else
1269 #endif
1270 
1271  /* Define TIMING PAL over PIT */
1272 #if (defined (TIMING_OVER_PIT))
1273  if (instance->instType == TIMING_INST_TYPE_PIT)
1274  {
1275  DEV_ASSERT((instance->instIdx) < PIT_INSTANCE_COUNT);
1276 
1277  channelState = &s_pitState[instance->instIdx][channel];
1278  /* Enable notification */
1279  channelState->enableNotification = false;
1280  }
1281  else
1282 #endif
1283 
1284  /* Define TIMING PAL over STM */
1285 #if (defined (TIMING_OVER_STM))
1286  if (instance->instType == TIMING_INST_TYPE_STM)
1287  {
1288  DEV_ASSERT((instance->instIdx) < STM_INSTANCE_COUNT);
1289 
1290  channelState = &s_stmState[instance->instIdx][channel];
1291  /* Enable notification */
1292  channelState->enableNotification = false;
1293  }
1294  else
1295 #endif
1296  {
1297  DEV_ASSERT(false);
1298  }
1299 }
1300 
1301 /*FUNCTION**********************************************************************
1302  *
1303  * Function Name : TIMING_GetResolution
1304  * Description : Get tick resolution
1305  * This function gets tick resolution in engineering units (nanosecond, microsecond or millisecond).
1306  * The result of this function is used to calculate period, remaining time or elapsed time in engineering units.
1307  *
1308  * Implements : TIMING_GetResolution_Activity
1309  *END**************************************************************************/
1311  const timer_resolution_type_t type,
1312  uint64_t * const resolution)
1313 {
1314  DEV_ASSERT(instance != NULL);
1315  DEV_ASSERT(resolution != NULL);
1316 
1317  status_t status = STATUS_SUCCESS;
1318  static uint32_t clkFrequency = 0U;
1319  uint64_t prescaler = 1U;
1320 
1321  /* Define TIMING PAL over LPIT */
1322 #if (defined (TIMING_OVER_LPIT))
1323  if (instance->instType == TIMING_INST_TYPE_LPIT)
1324  {
1325  static const clock_names_t lpitClockName[LPIT_INSTANCE_COUNT] = {LPIT0_CLK};
1326  status_t clkErr;
1327 
1328  DEV_ASSERT((instance->instIdx) < LPIT_INSTANCE_COUNT);
1329  /* Gets current functional clock frequency of LPIT instance */
1330  clkErr = CLOCK_SYS_GetFreq(lpitClockName[instance->instIdx], &clkFrequency);
1331  /* Checks the functional clock module is available */
1332  (void)clkErr;
1333  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1334  DEV_ASSERT(clkFrequency > 0U);
1335  }
1336  else
1337 #endif
1338 
1339  /* Define TIMING PAL over LPTMR */
1340 #if (defined (TIMING_OVER_LPTMR))
1341  if (instance->instType == TIMING_INST_TYPE_LPTMR)
1342  {
1343  DEV_ASSERT((instance->instIdx) < LPTMR_INSTANCE_COUNT);
1344 
1345  status_t clkErr;
1346  uint32_t lptmrInstance = instance->instIdx;
1347  clock_names_t inputClockName = SIRCDIV2_CLK;
1348 
1349  switch(s_lptmrClockSource[lptmrInstance])
1350  {
1352  inputClockName = SIRCDIV2_CLK;
1353  break;
1355  inputClockName = SIM_LPO_1K_CLK;
1356  break;
1357  case LPTMR_CLOCKSOURCE_RTC:
1358  inputClockName = SIM_RTCCLK_CLK;
1359  break;
1360  case LPTMR_CLOCKSOURCE_PCC:
1361  inputClockName = LPTMR0_CLK;
1362  break;
1363  default:
1364  /* Invalid clock source */
1365  DEV_ASSERT(false);
1366  break;
1367  }
1368  /* Gets current functional clock frequency of LPTMR instance */
1369  clkErr = CLOCK_SYS_GetFreq(inputClockName, &clkFrequency);
1370  /* Checks the functional clock module is available */
1371  (void)clkErr;
1372  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1373  DEV_ASSERT(clkFrequency > 0U);
1374 
1375  if (!s_lptmrBypassPrescaler[lptmrInstance])
1376  {
1377  prescaler = prescaler << ((uint8_t)s_lptmrPrescaler[lptmrInstance] + 1U);
1378  }
1379  }
1380  else
1381 #endif
1382 
1383  /* Define TIMING PAL over FTM */
1384 #if (defined (TIMING_OVER_FTM))
1385  if (instance->instType == TIMING_INST_TYPE_FTM)
1386  {
1387  DEV_ASSERT((instance->instIdx) < FTM_INSTANCE_COUNT);
1388 
1389  uint32_t ftmInstance = instance->instIdx;
1390 
1391  /* Gets current functional clock frequency of FTM instance */
1392  clkFrequency = FTM_DRV_GetFrequency(ftmInstance);
1393  DEV_ASSERT(clkFrequency > 0U);
1394  }
1395  else
1396 #endif
1397 
1398  /* Define TIMING PAL over PIT */
1399 #if (defined (TIMING_OVER_PIT))
1400  if (instance->instType == TIMING_INST_TYPE_PIT)
1401  {
1402  DEV_ASSERT((instance->instIdx) < PIT_INSTANCE_COUNT);
1403 
1404  status_t clkErr;
1405  uint32_t pitInstance = instance->instIdx;
1406  /* Gets current functional clock frequency of PIT instance */
1407  clkErr = CLOCK_SYS_GetFreq(s_pitClockName[pitInstance], &clkFrequency);
1408  /* Checks the functional clock module is available */
1409  (void)clkErr;
1410  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1411  DEV_ASSERT(clkFrequency > 0U);
1412  }
1413  else
1414 #endif
1415 
1416  /* Define TIMING PAL over STM */
1417 #if (defined (TIMING_OVER_STM))
1418  if (instance->instType == TIMING_INST_TYPE_STM)
1419  {
1420  DEV_ASSERT((instance->instIdx) < STM_INSTANCE_COUNT);
1421 
1422  uint32_t stmInstance = instance->instIdx;
1423  status_t clkErr;
1424  clock_names_t inputClockName = CLOCK_NAME_COUNT;
1425 
1426 #if FEATURE_STM_HAS_CLOCK_SELECTION
1427  switch(s_stmClockSource[stmInstance])
1428  {
1429  case STM_CLOCK_SYSTEM:
1430  inputClockName = FS80_CLK;
1431  break;
1432  case STM_CLOCK_FXOSC:
1433  inputClockName = FXOSC_CLK;
1434  break;
1435  default:
1436  /* Invalid clock source */
1437  DEV_ASSERT(false);
1438  break;
1439  }
1440 #else
1441  inputClockName = PBRIDGEx_CLK;
1442 #endif
1443  /* Gets current functional clock frequency of STM instance */
1444  clkErr = CLOCK_SYS_GetFreq(inputClockName, &clkFrequency);
1445  /* Checks the functional clock module is available */
1446  (void)clkErr;
1447  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1448  DEV_ASSERT(clkFrequency > 0U);
1449  prescaler = (uint64_t)s_stmPrescaler[stmInstance] + 1UL;
1450  }
1451  else
1452 #endif
1453  {
1454  DEV_ASSERT(false);
1455  }
1456 
1458  {
1459  /* For better precision, add half of the frequency before the division */
1460  *resolution = ((1000000000U * prescaler) + ((uint64_t)clkFrequency >> 1U)) / clkFrequency;
1461  }
1462  else if (type == TIMER_RESOLUTION_TYPE_MICROSECOND)
1463  {
1464  /* For better precision, add half of the frequency before the division */
1465  *resolution = ((1000000U * prescaler) + ((uint64_t)clkFrequency >> 1U)) / clkFrequency;
1466  }
1467  else
1468  {
1469  /* For better precision, add half of the frequency before the division */
1470  *resolution = ((1000U * prescaler) + ((uint64_t)clkFrequency >> 1U)) / clkFrequency;
1471  }
1472 
1473  if(*resolution == 0U)
1474  {
1475  status = STATUS_ERROR;
1476  }
1477 
1478  return status;
1479 }
1480 
1481 /*FUNCTION**********************************************************************
1482  *
1483  * Function Name : TIMING_GetMaxPeriod
1484  * Description : Get max period in engineering units
1485  * This function get max period in engineering units.
1486  *
1487  * Implements : TIMING_GetMaxPeriod_Activity
1488  *END**************************************************************************/
1490  const timer_resolution_type_t type,
1491  uint64_t * const maxPeriod)
1492 {
1493  DEV_ASSERT(instance != NULL);
1494  DEV_ASSERT(maxPeriod != NULL);
1495 
1496  status_t status = STATUS_SUCCESS;
1497  static uint32_t clkFrequency = 0U;
1498  uint64_t prescaler = 1U;
1499  uint64_t maxCountValue = 0U;
1500 
1501  /* Define TIMING PAL over LPIT */
1502 #if (defined (TIMING_OVER_LPIT))
1503  if (instance->instType == TIMING_INST_TYPE_LPIT)
1504  {
1505  static const clock_names_t lpitClockName[LPIT_INSTANCE_COUNT] = {LPIT0_CLK};
1506  status_t clkErr;
1507 
1508  DEV_ASSERT((instance->instIdx) < LPIT_INSTANCE_COUNT);
1509  /* Set max count value of LPIT */
1510  maxCountValue = (uint64_t)LPIT_COMPARE_MAX + 1UL;
1511  /* Gets current functional clock frequency of LPIT instance */
1512  clkErr = CLOCK_SYS_GetFreq(lpitClockName[instance->instIdx], &clkFrequency);
1513  /* Checks the functional clock module is available */
1514  (void)clkErr;
1515  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1516  DEV_ASSERT(clkFrequency > 0U);
1517  }
1518  else
1519 #endif
1520 
1521  /* Define TIMING PAL over LPTMR */
1522 #if (defined (TIMING_OVER_LPTMR))
1523  if (instance->instType == TIMING_INST_TYPE_LPTMR)
1524  {
1525  DEV_ASSERT((instance->instIdx) < LPTMR_INSTANCE_COUNT);
1526 
1527  status_t clkErr;
1528  uint32_t lptmrInstance = instance->instIdx;
1529  clock_names_t inputClockName = SIRCDIV2_CLK;
1530 
1531  /* Set max count value of LPTMR */
1532  maxCountValue = LPTMR_COMPARE_MAX + 1UL;
1533  /* Select name of clock source*/
1534  switch(s_lptmrClockSource[lptmrInstance])
1535  {
1537  inputClockName = SIRCDIV2_CLK;
1538  break;
1540  inputClockName = SIM_LPO_1K_CLK;
1541  break;
1542  case LPTMR_CLOCKSOURCE_RTC:
1543  inputClockName = SIM_RTCCLK_CLK;
1544  break;
1545  case LPTMR_CLOCKSOURCE_PCC:
1546  inputClockName = LPTMR0_CLK;
1547  break;
1548  default:
1549  /* Invalid clock source */
1550  DEV_ASSERT(false);
1551  break;
1552  }
1553  /* Gets current functional clock frequency of LPTMR instance */
1554  clkErr = CLOCK_SYS_GetFreq(inputClockName, &clkFrequency);
1555  /* Checks the functional clock module is available */
1556  (void)clkErr;
1557  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1558  DEV_ASSERT(clkFrequency > 0U);
1559 
1560  if (!s_lptmrBypassPrescaler[lptmrInstance])
1561  {
1562  prescaler = prescaler << ((uint8_t)s_lptmrPrescaler[lptmrInstance] + 1U);
1563  }
1564  }
1565  else
1566 #endif
1567 
1568  /* Define TIMING PAL over FTM */
1569 #if (defined (TIMING_OVER_FTM))
1570  if (instance->instType == TIMING_INST_TYPE_FTM)
1571  {
1572  uint32_t ftmInstance = instance->instIdx;
1573 
1574  /* Set max count value of FTM */
1575  maxCountValue = FTM_COMPARE_MAX + 1UL;
1576  /* Gets current functional clock frequency of FTM instance */
1577  clkFrequency = FTM_DRV_GetFrequency(ftmInstance);
1578  DEV_ASSERT(clkFrequency > 0U);
1579  status = STATUS_SUCCESS;
1580  }
1581  else
1582 #endif
1583 
1584  /* Define TIMING PAL over PIT */
1585 #if (defined (TIMING_OVER_PIT))
1586  if (instance->instType == TIMING_INST_TYPE_PIT)
1587  {
1588  DEV_ASSERT((instance->instIdx) < PIT_INSTANCE_COUNT);
1589 
1590  status_t clkErr;
1591  uint32_t pitInstance = instance->instIdx;
1592 
1593  /* Set max count value of PIT */
1594  maxCountValue = (uint64_t)PIT_COMPARE_MAX + 1UL;
1595  /* Gets current functional clock frequency of PIT instance */
1596  clkErr = CLOCK_SYS_GetFreq(s_pitClockName[pitInstance], &clkFrequency);
1597  /* Checks the functional clock module is available */
1598  (void)clkErr;
1599  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1600  DEV_ASSERT(clkFrequency > 0U);
1601  }
1602  else
1603 #endif
1604 
1605  /* Define TIMING PAL over STM */
1606 #if (defined (TIMING_OVER_STM))
1607  if (instance->instType == TIMING_INST_TYPE_STM)
1608  {
1609  DEV_ASSERT((instance->instIdx) < STM_INSTANCE_COUNT);
1610 
1611  status_t clkErr;
1612  uint32_t stmInstance = instance->instIdx;
1613  clock_names_t inputClockName = CLOCK_NAME_COUNT;
1614 
1615  /* Set max count value of STM */
1616  maxCountValue = (uint64_t)STM_COMPARE_MAX + 1UL;
1617 
1618 #if FEATURE_STM_HAS_CLOCK_SELECTION
1619  /* Select name of clock source*/
1620  switch(s_stmClockSource[stmInstance])
1621  {
1622  case STM_CLOCK_SYSTEM:
1623  inputClockName = FS80_CLK;
1624  break;
1625  case STM_CLOCK_FXOSC:
1626  inputClockName = FXOSC_CLK;
1627  break;
1628  default:
1629  /* Invalid clock source */
1630  DEV_ASSERT(false);
1631  break;
1632  }
1633 #else
1634  inputClockName = PBRIDGEx_CLK;
1635 #endif
1636  /* Gets current functional clock frequency of STM instance */
1637  clkErr = CLOCK_SYS_GetFreq(inputClockName, &clkFrequency);
1638  /* Checks the functional clock module is available */
1639  (void)clkErr;
1640  DEV_ASSERT(clkErr == STATUS_SUCCESS);
1641  DEV_ASSERT(clkFrequency > 0U);
1642  prescaler = (uint64_t)s_stmPrescaler[stmInstance] + 1UL;
1643  }
1644  else
1645 #endif
1646  {
1647  DEV_ASSERT(false);
1648  }
1649 
1651  {
1652  /* For better precision, add half of the frequency before the division.
1653  To avoid overflow, divided the clock frequency before multiples by the max count value */
1654  *maxPeriod = (((1000000000U * prescaler) + ((uint64_t)clkFrequency >> 1U)) / clkFrequency) * maxCountValue;
1655  }
1656  else if (type == TIMER_RESOLUTION_TYPE_MICROSECOND)
1657  {
1658  /* For better precision, add half of the frequency before the division. */
1659  *maxPeriod = ((1000000U * prescaler * maxCountValue) + ((uint64_t)clkFrequency >> 1U)) / clkFrequency;
1660  }
1661  else
1662  { /* For better precision, add half of the frequency before the division. */
1663  *maxPeriod = ((1000U * prescaler * maxCountValue) + ((uint64_t)clkFrequency >> 1U)) / clkFrequency;
1664  }
1665 
1666  if(*maxPeriod == 0U)
1667  {
1668  status = STATUS_ERROR;
1669  }
1670 
1671  return status;
1672 }
1673 
1674 #if (defined (TIMING_OVER_LPIT))
1675 /*FUNCTION**********************************************************************
1676  *
1677  * Function Name : TIMING_Lpit_IrqHandler
1678  * Description : Interrupt handler for TIMING over LPIT.
1679  * This is not a public API as it is called by IRQ whenever an interrupt
1680  * occurs.
1681  *
1682  *END**************************************************************************/
1683 void TIMING_Lpit_IrqHandler(uint32_t instance, uint8_t channel)
1684 {
1685  const timer_chan_state_t * channelState = &s_lpitState[instance][channel];
1686 
1687  if ((channelState->callback != NULL) && (channelState->enableNotification))
1688  {
1689  /* Call to callback function */
1690  (channelState->callback)(channelState->callbackParam);
1691 
1692  if (channelState->chanType == TIMER_CHAN_TYPE_ONESHOT)
1693  {
1694  uint32_t channelMask = 1UL << channel;
1695  /* Stop the channel counting */
1696  LPIT_DRV_StopTimerChannels(instance, channelMask);
1697  }
1698  }
1699  LPIT_DRV_ClearInterruptFlagTimerChannels(instance, (1UL << channel));
1700 
1701 }
1702 #endif
1703 
1704 /* Define TIMING PAL over LPTMR */
1705 #if (defined (TIMING_OVER_LPTMR))
1706 /*FUNCTION**********************************************************************
1707  *
1708  * Function Name : TIMING_Lptmr_IrqHandler
1709  * Description : Interrupt handler for TIMING over LPTMR.
1710  * This is not a public API as it is called by IRQ whenever an interrupt
1711  * occurs.
1712  *
1713  *END**************************************************************************/
1714 void TIMING_Lptmr_IrqHandler(uint32_t instance, uint8_t channel)
1715 {
1716  const timer_chan_state_t * channelState = &s_lptmrState[instance][channel];
1717 
1718  if ((channelState->callback != NULL) && (channelState->enableNotification))
1719  {
1720  /* Call to callback function */
1721  (channelState->callback)(channelState->callbackParam);
1722 
1723  if (channelState->chanType == TIMER_CHAN_TYPE_ONESHOT)
1724  {
1725  /* Stop the channel counting */
1726  LPTMR_DRV_StopCounter(instance);
1727  }
1728  }
1729  LPTMR_DRV_ClearCompareFlag(instance);
1730 }
1731 #endif
1732 
1733 /* Define TIMING PAL over FTM */
1734 #if (defined (TIMING_OVER_FTM))
1735 /*FUNCTION**********************************************************************
1736  *
1737  * Function Name : TIMING_Ftm_IrqHandler
1738  * Description : Interrupt handler for TIMING over FTM.
1739  * This is not a public API as it is called by IRQ whenever an interrupt
1740  * occurs.
1741  *
1742  *END**************************************************************************/
1743 void TIMING_Ftm_IrqHandler(uint32_t instance, uint8_t channel)
1744 {
1745  FTM_Type * const base = ftmBase[instance];
1746  timer_chan_state_t * channelState = &s_ftmState[instance][channel];
1747 
1748  if ((channelState->callback != NULL) && (channelState->enableNotification))
1749  {
1750  /* Call to callback function */
1751  (channelState->callback)(channelState->callbackParam);
1752  }
1753  /* Check notification type */
1754  if (channelState->chanType == TIMER_CHAN_TYPE_ONESHOT)
1755  {
1756  /* Stop the channel by disable interrupt generation */
1757  FTM_DRV_DisableInterrupts(instance, (1UL << channel));
1758  /* Update channel running status */
1759  g_ftmChannelRunning[instance][channel] = false;
1760  }
1761  else
1762  {
1763  status_t status;
1764  uint32_t currentCmpValue = 0U;
1765  uint32_t currentPeriod = channelState->period;
1766  uint32_t nexCompareValue = 0U;
1767  uint32_t finalValue;
1768 
1769  /* Get the final value of counter */
1770  finalValue = FTM_DRV_GetMod(base);
1771  /* Get current compare value of the channel */
1772  currentCmpValue = FTM_DRV_GetChnCountVal(base, channel);
1773  /* Calculate the next compare value of the channel */
1774  if ((finalValue - currentCmpValue) > currentPeriod)
1775  {
1776  nexCompareValue = currentCmpValue + currentPeriod;
1777  }
1778  else
1779  {
1780  nexCompareValue = currentPeriod - (finalValue - currentCmpValue);
1781  }
1782  /* Update next compare value to the channel */
1783  status = FTM_DRV_UpdateOutputCompareChannel(instance, channel, (uint16_t)nexCompareValue, FTM_ABSOLUTE_VALUE, false);
1784  (void)status;
1785  /* Save the start value of channel at the moment new period is started */
1786  channelState->chanStartVal = currentCmpValue;
1787  }
1788  /* Clear interrupt flag */
1789  FTM_DRV_ClearChnEventStatus(base, channel);
1790 }
1791 #endif
1792 
1793 /* Define TIMING PAL over PIT */
1794 #if (defined (TIMING_OVER_PIT))
1795 /*FUNCTION**********************************************************************
1796  *
1797  * Function Name : TIMING_Pit_IrqHandler
1798  * Description : Interrupt handler for TIMING over PIT.
1799  * This is not a public API as it is called by IRQ whenever an interrupt
1800  * occurs.
1801  *
1802  *END**************************************************************************/
1803 void TIMING_Pit_IrqHandler(uint32_t instance, uint8_t channel)
1804 {
1805  const timer_chan_state_t * channelState = &s_pitState[instance][channel];
1806 
1807  if ((channelState->callback != NULL) && (channelState->enableNotification))
1808  {
1809  /* Call to callback function */
1810  (channelState->callback)(channelState->callbackParam);
1811  /* Check notification type */
1812  if (channelState->chanType == TIMER_CHAN_TYPE_ONESHOT)
1813  {
1814  /* Stop the channel counting */
1815  PIT_DRV_StopChannel(instance, channel);
1816  }
1817  }
1818  PIT_DRV_ClearStatusFlags(instance, channel);
1819 }
1820 #endif
1821 
1822 /* Define TIMING PAL over STM */
1823 #if (defined (TIMING_OVER_STM))
1824 /*FUNCTION**********************************************************************
1825  *
1826  * Function Name : TIMING_Stm_IrqHandler
1827  * Description : Interrupt handler for TIMING over STM.
1828  * This is not a public API as it is called by IRQ whenever an interrupt
1829  * occurs.
1830  *
1831  *END**************************************************************************/
1832 void TIMING_Stm_IrqHandler(uint32_t instance, uint8_t channel)
1833 {
1834  uint32_t currentCounter = 0U;
1835  timer_chan_state_t * channelState = &s_stmState[instance][channel];
1836 
1837  /* Get current counter value */
1838  currentCounter = STM_DRV_GetCounterValue(instance);
1839 
1840  if ((channelState->callback != NULL) && (channelState->enableNotification))
1841  {
1842  /* Call to callback function */
1843  (channelState->callback)(channelState->callbackParam);
1844  /* Save the start value of channel at the moment new period is started */
1845  channelState->chanStartVal = currentCounter;
1846  }
1847  /* Check notification type */
1848  if (channelState->chanType == TIMER_CHAN_TYPE_ONESHOT)
1849  {
1850  /* Stop the channel counting */
1851  STM_DRV_DisableChannel(instance, channel);
1852  }
1853  else
1854  {
1855  /* Update next compare value of the channel*/
1856  STM_DRV_IncrementTicks(instance, channel, channelState->period);
1857  }
1858  STM_DRV_ClearStatusFlags(instance, channel);
1859 }
1860 #endif
1861 /*******************************************************************************
1862  * EOF
1863  ******************************************************************************/
timer_chan_type_t
Type options available for timer channel notification.
Definition: timing_pal.h:56
ftm_reg_update_t initCounterSync
Definition: ftm_common.h:425
ftm_pwm_sync_t syncMethod
Definition: ftm_common.h:438
static uint16_t FTM_DRV_GetChnCountVal(const FTM_Type *ftmBase, uint8_t channel)
Gets the FTM peripheral timer channel counter value.
Definition: ftm_common.h:746
lptmr_workmode_t workMode
Definition: lptmr_driver.h:119
FlexTimer state structure of the driver.
Definition: ftm_common.h:391
void LPTMR_DRV_Init(const uint32_t instance, const lptmr_config_t *const config, const bool startCounter)
Initialize a LPTMR instance with values from an input configuration structure.
#define FTM_CONTROLS_COUNT
Definition: S32K118.h:3822
#define FTM_IRQS
Definition: S32K118.h:3895
timer_callback_t callback
Definition: timing_pal.h:72
FlexTimer driver PWM parameters.
Definition: ftm_oc_driver.h:68
lpit_timer_modes_t timerMode
Definition: lpit_driver.h:126
timer_chan_type_t chanType
Definition: timing_pal.h:71
status_t TIMING_GetMaxPeriod(const timing_instance_t *const instance, const timer_resolution_type_t type, uint64_t *const maxPeriod)
Get max period in engineering units.
Definition: timing_pal.c:1489
ftm_bdm_mode_t BDMMode
Definition: ftm_common.h:444
bool hardwareSync2
Definition: ftm_common.h:416
Configuration structure that the user needs to set.
Definition: ftm_common.h:436
lptmr_pinpolarity_t pinPolarity
Definition: lptmr_driver.h:128
void TIMING_DisableNotification(const timing_instance_t *const instance, const uint8_t channel)
Disable channel notifications.
Definition: timing_pal.c:1223
void LPTMR_DRV_StopCounter(const uint32_t instance)
Disable the LPTMR / Stop the counter.
ftm_config_mode_t mode
Definition: ftm_oc_driver.h:85
void LPIT_DRV_SetTimerPeriodByCount(uint32_t instance, uint32_t channel, uint32_t count)
Sets the timer channel period in count unit.
Definition: lpit_driver.c:504
lptmr_clocksource_t clockSelect
Definition: lptmr_driver.h:121
Defines the configuration structure for LPTMR.
Definition: lptmr_driver.h:113
void LPTMR_DRV_ClearCompareFlag(const uint32_t instance)
Clear the Compare Flag of a LPTMR instance.
ftm_output_cmp_ch_param_t * outputChannelConfig
Definition: ftm_oc_driver.h:87
lptmr_prescaler_t prescaler
Definition: lptmr_driver.h:122
lptmr_clocksource_t
Clock Source selection Implements : lptmr_clocksource_t_Class.
Definition: lptmr_driver.h:90
uint8_t numChan
Definition: timing_pal.h:85
void TIMING_Deinit(const timing_instance_t *const instance)
De-initialize a timer instance.
Definition: timing_pal.c:562
void LPIT_DRV_StopTimerChannels(uint32_t instance, uint32_t mask)
Stops the timer channel counting.
Definition: lpit_driver.c:248
ftm_output_compare_mode_t chMode
Definition: ftm_oc_driver.h:71
timing_inst_type_t instType
lpit_trigger_source_t triggerSource
Definition: lpit_driver.h:129
lptmr_counter_units_t counterUnits
Definition: lptmr_driver.h:125
bool hardwareSync1
Definition: ftm_common.h:414
lptmr_pinselect_t pinSelect
Definition: lptmr_driver.h:127
#define LPTMR_INSTANCE_COUNT
Definition: S32K118.h:6410
Structure storing PAL instance information.
#define LPIT_TMR_COUNT
Definition: S32K118.h:5800
#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
lptmr_prescaler_t
Prescaler Selection Implements : lptmr_prescaler_t_Class.
Definition: lptmr_driver.h:68
uint32_t FTM_DRV_GetFrequency(uint32_t instance)
Retrieves the frequency of the clock source feeding the FTM counter.
Definition: ftm_common.c:733
uint32_t compareValue
Definition: lptmr_driver.h:124
#define LPIT_INSTANCE_COUNT
Definition: S32K118.h:5821
status_t CLOCK_SYS_GetFreq(clock_names_t clockName, uint32_t *frequency)
Gets the clock frequency for a specific clock name.
void TIMING_StartChannel(const timing_instance_t *const instance, const uint8_t channel, const uint32_t periodTicks)
Starts the timer channel counting.
Definition: timing_pal.c:632
void LPIT_DRV_Init(uint32_t instance, const lpit_user_config_t *userConfig)
Initializes the LPIT module.
Definition: lpit_driver.c:90
uint32_t TIMING_GetElapsed(const timing_instance_t *const instance, const uint8_t channel)
Get elapsed ticks.
Definition: timing_pal.c:884
bool hardwareSync0
Definition: ftm_common.h:412
void LPTMR_DRV_Deinit(const uint32_t instance)
De-initialize a LPTMR instance.
Timer configuration structure.
Definition: timing_pal.h:82
lpit_period_units_t periodUnits
Definition: lpit_driver.h:127
status_t LPIT_DRV_InitChannel(uint32_t instance, uint32_t channel, const lpit_user_channel_config_t *userChannelConfig)
Initializes the LPIT channel.
Definition: lpit_driver.c:152
ftm_pwm_sync_mode_t syncPoint
Definition: ftm_common.h:427
void LPIT_DRV_ClearInterruptFlagTimerChannels(uint32_t instance, uint32_t mask)
Clears the interrupt flag of timer channels.
Definition: lpit_driver.c:688
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
LPIT configuration structure.
Definition: lpit_driver.h:111
timer_resolution_type_t
Type options available for tick resolution.
Definition: timing_pal.h:44
uint32_t TIMING_GetRemaining(const timing_instance_t *const instance, const uint8_t channel)
Get remaining ticks.
Definition: timing_pal.c:1009
bool maxLoadingPoint
Definition: ftm_common.h:418
#define FTM_INSTANCE_COUNT
Definition: S32K118.h:3868
uint16_t LPTMR_DRV_GetCounterValueByCount(const uint32_t instance)
Get the current counter value in counter tick units.
bool enableInitializationTrigger
Definition: ftm_common.h:447
void LPTMR_DRV_StartCounter(const uint32_t instance)
Enable the LPTMR / Start the counter.
Structure to configure the channel timer.
Definition: lpit_driver.h:124
ftm_reg_update_t inverterSync
Definition: ftm_common.h:422
void TIMING_EnableNotification(const timing_instance_t *const instance, const uint8_t channel)
Enable channel notifications.
Definition: timing_pal.c:1133
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
const timer_chan_config_t * chanConfigArray
Definition: timing_pal.h:84
ftm_config_mode_t ftmMode
Definition: ftm_common.h:440
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.
Runtime state of the Timer channel.
Definition: timing_pal.c:80
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 uint16_t FTM_DRV_GetMod(const FTM_Type *ftmBase)
Returns the FTM peripheral counter modulo value.
Definition: ftm_common.h:516
bool minLoadingPoint
Definition: ftm_common.h:420
bool autoClearTrigger
Definition: ftm_common.h:426
#define FTM_BASE_PTRS
Definition: S32K118.h:3883
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 LPIT_DRV_Deinit(uint32_t instance)
De-Initializes the LPIT module.
Definition: lpit_driver.c:125
clock_names_t
Clock names.
void * extension
Definition: timing_pal.h:86
void(* isr_t)(void)
Interrupt handler type.
status_t TIMING_GetResolution(const timing_instance_t *const instance, const timer_resolution_type_t type, uint64_t *const resolution)
Get tick resolution.
Definition: timing_pal.c:1310
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.
void(* timer_callback_t)(void *userData)
Definition: callbacks.h:107
void FTM_DRV_DisableInterrupts(uint32_t instance, uint32_t interruptMask)
This function is used to disable some interrupts.
Definition: ftm_common.c:536
void LPIT_DRV_StartTimerChannels(uint32_t instance, uint32_t mask)
Starts the timer channel counting.
Definition: lpit_driver.c:224
status_t TIMING_Init(const timing_instance_t *const instance, const timer_config_t *const config)
Initialize the timer instance and timer channels with value from input configuration structure...
Definition: timing_pal.c:484
ftm_clock_source_t ftmClockSource
Definition: ftm_common.h:443
void TIMING_StopChannel(const timing_instance_t *const instance, const uint8_t channel)
Stop the timer channel counting.
Definition: timing_pal.c:788
status_t LPTMR_DRV_SetCompareValueByCount(const uint32_t instance, const uint16_t compareValueByCount)
Set the compare value in counter tick units, for a LPTMR instance.
ftm_reg_update_t outRegSync
Definition: ftm_common.h:423
static uint16_t FTM_DRV_GetCounter(const FTM_Type *ftmBase)
Returns the FTM peripheral current counter value.
Definition: ftm_common.h:502
ftm_clock_ps_t ftmPrescaler
Definition: ftm_common.h:441
#define LPIT_IRQS
Definition: S32K118.h:5838
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.
#define LPTMR_IRQS
Definition: S32K118.h:6427
uint32_t LPIT_DRV_GetCurrentTimerCount(uint32_t instance, uint32_t channel)
Gets the current timer channel counting value in count.
Definition: lpit_driver.c:592