PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
mft_frt.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
53 /******************************************************************************/
54 /* Include files */
55 /******************************************************************************/
56 #include "mft_frt.h"
57 
58 #if (defined(PDL_PERIPHERAL_MFT_FRT_ACTIVE))
59 
65 
66 /******************************************************************************/
67 /* Local pre-processor symbols/macros ('#define') */
68 /******************************************************************************/
70 #define FRT_INSTANCE_COUNT (uint32_t)(sizeof(m_astcMftFrtInstanceDataLut) \
71  / sizeof(m_astcMftFrtInstanceDataLut[0]))
72 
73 /******************************************************************************/
74 /* Global variable definitions (declared in header file with 'extern') */
75 /******************************************************************************/
78 {
79 #if (PDL_PERIPHERAL_ENABLE_MFT0_FRT == PDL_ON)
80  {
81  &MFT0_FRT, // pstcInstance
82  NULL // stcInternData (not initialized yet)
83  },
84 #endif
85 #if (PDL_PERIPHERAL_ENABLE_MFT1_FRT == PDL_ON)
86  {
87  &MFT1_FRT, // pstcInstance
88  NULL // stcInternData (not initialized yet)
89  },
90 #endif
91 #if (PDL_PERIPHERAL_ENABLE_MFT2_FRT == PDL_ON)
92  {
93  &MFT2_FRT, // pstcInstance
94  NULL // stcInternData (not initialized yet)
95  },
96 #endif
97 };
98 
99 /******************************************************************************/
100 /* Local type definitions ('typedef') */
101 /******************************************************************************/
102 /******************************************************************************/
103 /* Local function prototypes ('static') */
104 /******************************************************************************/
105 /******************************************************************************/
106 /* Local variable definitions ('static') */
107 /******************************************************************************/
108 /******************************************************************************/
109 /* Function implementation - global ('extern') and local ('static') */
110 /******************************************************************************/
122 {
123  uint32_t u32Instance;
124 
125  for (u32Instance = 0; u32Instance < FRT_INSTANCE_COUNT; u32Instance++)
126  {
127  if (pstcFrt == m_astcMftFrtInstanceDataLut[u32Instance].pstcInstance)
128  {
129  return &m_astcMftFrtInstanceDataLut[u32Instance].stcInternData;
130  }
131  }
132 
133  return NULL;
134 }
135 
136 #if (PDL_INTERRUPT_ENABLE_MFT0_FRT == PDL_ON) || \
137  (PDL_INTERRUPT_ENABLE_MFT1_FRT == PDL_ON) || \
138  (PDL_INTERRUPT_ENABLE_MFT2_FRT == PDL_ON)
139 
154 void Mft_Frt_IrqHandler( volatile stc_mftn_frt_t*pstcMft,
155  stc_mft_frt_intern_data_t* pstcMftFrtInternData)
156 {
157 
158  static func_ptr_t funCallBack;
159  static uint32_t* ptemp;
160  uint8_t ch;
161 
162  /* Peak match Interrupt */
163  for(ch=0;ch<3;ch++)
164  {
165  if(PdlSet == Mft_Frt_GetIntFlag(pstcMft,ch,enFrtPeakMatchInt))
166  {
167  /* Clear Interrupt */
169 
170  //get peak match callback address of each channel
171  ptemp = (uint32_t*)&(pstcMftFrtInternData->pfnFrt0PeakCallback);
172  funCallBack = (func_ptr_t)(*(uint32_t*)((uint32_t)ptemp +
173  (sizeof(func_ptr_t) * ch)));
174 
175  if(funCallBack != NULL)
176  {
177  funCallBack();
178  }
179  }
180  }
181 
182  /* Zero match Interrupt */
183  for(ch=0;ch<3;ch++)
184  {
185  if(PdlSet == Mft_Frt_GetIntFlag(pstcMft,ch,enFrtZeroMatchInt))
186  {
187  /* Clear Interrupt */
189 
190  //get Zero match callback address of each channel
191  ptemp = (uint32_t*)&(pstcMftFrtInternData->pfnFrt0ZeroCallback);
192  funCallBack = (func_ptr_t)(*(uint32_t*)((uint32_t)ptemp +
193  (sizeof(func_ptr_t) * ch)));
194 
195 
196  if(funCallBack != NULL)
197  {
198  funCallBack();
199  }
200  }
201  }
202 }
203 
215 static en_result_t Mft_Frt_InitIrq( volatile stc_mftn_frt_t* pstcMft,
216  stc_frt_int_sel_t* pstcIntSel )
217 {
218 #if (PDL_INTERRUPT_ENABLE_MFT0_FRT == PDL_ON)
219  if (pstcMft == (stc_mftn_frt_t*)(&MFT0_FRT))
220  {
221  if(pstcIntSel->bFrtZeroMatchInt == 1)
222  {
223  NVIC_ClearPendingIRQ(FRT0_ZERO_IRQn);
224  NVIC_EnableIRQ(FRT0_ZERO_IRQn);
225  NVIC_SetPriority(FRT0_ZERO_IRQn, PDL_IRQ_LEVEL_MFT0_FRT);
226  }
227  if(pstcIntSel->bFrtPeakMatchInt == 1)
228  {
229  NVIC_ClearPendingIRQ(FRT0_PEAK_IRQn);
230  NVIC_EnableIRQ(FRT0_PEAK_IRQn);
231  NVIC_SetPriority(FRT0_PEAK_IRQn, PDL_IRQ_LEVEL_MFT0_FRT);
232  }
233  }
234 #endif
235 #if (PDL_INTERRUPT_ENABLE_MFT1_FRT == PDL_ON)
236  if (pstcMft == (stc_mftn_frt_t*)(&MFT1_FRT))
237  {
238  if(pstcIntSel->bFrtZeroMatchInt == 1)
239  {
240  NVIC_ClearPendingIRQ(FRT1_ZERO_IRQn);
241  NVIC_EnableIRQ(FRT1_ZERO_IRQn);
242  NVIC_SetPriority(FRT1_ZERO_IRQn, PDL_IRQ_LEVEL_MFT1_FRT);
243  }
244  if(pstcIntSel->bFrtPeakMatchInt == 1)
245  {
246  NVIC_ClearPendingIRQ(FRT1_PEAK_IRQn);
247  NVIC_EnableIRQ(FRT1_PEAK_IRQn);
248  NVIC_SetPriority(FRT1_PEAK_IRQn, PDL_IRQ_LEVEL_MFT1_FRT);
249  }
250  }
251 #endif
252 #if (PDL_INTERRUPT_ENABLE_MFT2_FRT == PDL_ON)
253  if (pstcMft == (stc_mftn_frt_t*)(&MFT2_FRT))
254  {
255  if(pstcIntSel->bFrtZeroMatchInt == 1)
256  {
257  NVIC_ClearPendingIRQ(FRT2_ZERO_IRQn);
258  NVIC_EnableIRQ(FRT2_ZERO_IRQn);
259  NVIC_SetPriority(FRT2_ZERO_IRQn, PDL_IRQ_LEVEL_MFT2_FRT);
260  }
261  if(pstcIntSel->bFrtPeakMatchInt == 1)
262  {
263  NVIC_ClearPendingIRQ(FRT2_PEAK_IRQn);
264  NVIC_EnableIRQ(FRT2_PEAK_IRQn);
265  NVIC_SetPriority(FRT2_PEAK_IRQn, PDL_IRQ_LEVEL_MFT2_FRT);
266  }
267  }
268 #endif
269  return Ok;
270 }
271 
272 
284 static en_result_t Mft_Frt_DeInitIrq( volatile stc_mftn_frt_t* pstcMft,
285  stc_frt_int_sel_t* pstcIntSel )
286 {
287  // Check for NULL pointer
288  if ((pstcMft == NULL))
289  {
290  return ErrorInvalidParameter ;
291  }
292 #if (PDL_INTERRUPT_ENABLE_MFT0_FRT == PDL_ON)
293  if (pstcMft == (stc_mftn_frt_t*)(&MFT0_FRT))
294  {
295  if(pstcIntSel->bFrtZeroMatchInt == 1)
296  {
297  if((pstcMft->TCSA0_f.IRQZE == 0) && (pstcMft->TCSA1_f.IRQZE == 0) && (pstcMft->TCSA2_f.IRQZE == 0))
298  {
299  NVIC_ClearPendingIRQ(FRT0_ZERO_IRQn);
300  NVIC_DisableIRQ(FRT0_ZERO_IRQn);
301  NVIC_SetPriority(FRT0_ZERO_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
302  }
303  }
304  if(pstcIntSel->bFrtPeakMatchInt == 1)
305  {
306  if((pstcMft->TCSA0_f.ICRE == 0) && (pstcMft->TCSA1_f.ICRE == 0) && (pstcMft->TCSA2_f.ICRE == 0))
307  {
308  NVIC_ClearPendingIRQ(FRT0_PEAK_IRQn);
309  NVIC_DisableIRQ(FRT0_PEAK_IRQn);
310  NVIC_SetPriority(FRT0_PEAK_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
311  }
312  }
313  }
314 #endif
315 #if (PDL_INTERRUPT_ENABLE_MFT1_FRT == PDL_ON)
316  if (pstcMft == (stc_mftn_frt_t*)(&MFT1_FRT))
317  {
318  if(pstcIntSel->bFrtZeroMatchInt == 1)
319  {
320  if((pstcMft->TCSA0_f.IRQZE == 0) && (pstcMft->TCSA1_f.IRQZE == 0) && (pstcMft->TCSA2_f.IRQZE == 0))
321  {
322  NVIC_ClearPendingIRQ(FRT1_ZERO_IRQn);
323  NVIC_DisableIRQ(FRT1_ZERO_IRQn);
324  NVIC_SetPriority(FRT1_ZERO_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
325  }
326  }
327  if(pstcIntSel->bFrtPeakMatchInt == 1)
328  {
329  if((pstcMft->TCSA0_f.ICRE == 0) && (pstcMft->TCSA1_f.ICRE == 0) && (pstcMft->TCSA2_f.ICRE == 0))
330  {
331  NVIC_ClearPendingIRQ(FRT1_PEAK_IRQn);
332  NVIC_DisableIRQ(FRT1_PEAK_IRQn);
333  NVIC_SetPriority(FRT1_PEAK_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
334  }
335  }
336  }
337 
338 #endif
339 #if (PDL_INTERRUPT_ENABLE_MFT2_FRT == PDL_ON)
340  if (pstcMft == (stc_mftn_frt_t*)(&MFT2_FRT))
341  {
342  if(pstcIntSel->bFrtZeroMatchInt == 1)
343  {
344  if((pstcMft->TCSA0_f.IRQZE == 0) && (pstcMft->TCSA1_f.IRQZE == 0) && (pstcMft->TCSA2_f.IRQZE == 0))
345  {
346  NVIC_ClearPendingIRQ(FRT2_ZERO_IRQn);
347  NVIC_DisableIRQ(FRT2_ZERO_IRQn);
348  NVIC_SetPriority(FRT2_ZERO_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
349  }
350  }
351  if(pstcIntSel->bFrtPeakMatchInt == 1)
352  {
353  if((pstcMft->TCSA0_f.ICRE == 0) && (pstcMft->TCSA1_f.ICRE == 0) && (pstcMft->TCSA2_f.ICRE == 0))
354  {
355  NVIC_ClearPendingIRQ(FRT2_PEAK_IRQn);
356  NVIC_DisableIRQ(FRT2_PEAK_IRQn);
357  NVIC_SetPriority(FRT2_PEAK_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
358  }
359  }
360  }
361 #endif
362  return Ok;
363 }
364 
365 #endif
366 
367 /******************************************************************************/
368 /* Local Functions */
369 /******************************************************************************/
370 
389 en_result_t Mft_Frt_Init(volatile stc_mftn_frt_t *pstcMft, uint8_t u8Ch,
390  stc_mft_frt_config_t* pstcFrtConfig)
391 {
392  // Pointer to internal data
393  stc_mft_frt_intern_data_t* pstcFrtInternData ;
394  stc_mft_frt_tcsa0_field_t* pstcTCSA;
395 
396  // Check for NULL pointer and configuration parameter
397  if ((pstcMft == NULL) ||
398  (pstcFrtConfig == NULL) ||
399  (pstcFrtConfig->enFrtMode > FrtUpDownCount) ||
400  (pstcFrtConfig->enFrtClockDiv > FrtPclkDiv1024) ||
401  (pstcFrtConfig->bEnBuffer > 1) ||
402  (pstcFrtConfig->bEnExtClock > 1) )
403  {
404  return ErrorInvalidParameter ;
405  }
406 
407  // Get pointer to internal data structure ...
408  pstcFrtInternData = MftGetInternDataPtr( pstcMft ) ;
409  // ... and check for NULL
410  if ( pstcFrtInternData != NULL )
411  {
412  pstcFrtInternData->pfnFrt0PeakCallback = NULL;
413  pstcFrtInternData->pfnFrt0ZeroCallback = NULL;
414  pstcFrtInternData->pfnFrt1PeakCallback = NULL;
415  pstcFrtInternData->pfnFrt1ZeroCallback = NULL;
416  pstcFrtInternData->pfnFrt2PeakCallback = NULL;
417  pstcFrtInternData->pfnFrt2ZeroCallback = NULL;
418  }
419 
420  //Get pointer of current channel frt register address
421  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft + 0x48 + u8Ch*0x0C);
422 
423  //set count clock cycle of FRT counter
424  pstcTCSA->CLK0 = (pstcFrtConfig->enFrtClockDiv >> 0) & 0x01;
425  pstcTCSA->CLK1 = (pstcFrtConfig->enFrtClockDiv >> 1) & 0x01;
426  pstcTCSA->CLK2 = (pstcFrtConfig->enFrtClockDiv >> 2) & 0x01;
427  pstcTCSA->CLK3 = (pstcFrtConfig->enFrtClockDiv >> 3) & 0x01;
428 
429  //set frt mode
430  pstcTCSA->MODE = pstcFrtConfig->enFrtMode;
431 
432  //set buffer enable bit
433  pstcTCSA->BFE = pstcFrtConfig->bEnBuffer;
434 
435  //set external clock enable bit
436  pstcTCSA->ECKE = pstcFrtConfig->bEnExtClock;
437 
438  return Ok;
439 }
440 
460  uint8_t u8Ch, uint8_t u8Times)
461 {
462  stc_mft_frt_tcsc0_field_t* pstcTCSC;
463 
464  // Check for NULL pointer
465  if ( (pstcMft == NULL) ||
466  (u8Ch >= MFT_FRT_MAX_CH) ||
467  (u8Times > 15) )
468  {
469  return ErrorInvalidParameter ;
470  }
471 
472  //Get pointer of current channel frt register address
473  pstcTCSC=(stc_mft_frt_tcsc0_field_t*)((uint8_t*)pstcMft+0x4AUL+u8Ch*0x0C);
474 
475  pstcTCSC->MSZI = u8Times;
476 
477  return Ok;
478 }
479 
496 uint8_t Mft_Frt_GetMaskZeroTimes(volatile stc_mftn_frt_t*pstcMft, uint8_t u8Ch)
497 {
498  stc_mft_frt_tcsc0_field_t* pstcTCSC;
499 
500  // Check for NULL pointer
501  if ( (pstcMft == NULL)
502  || (u8Ch >= MFT_FRT_MAX_CH))
503  {
504  return 0 ;
505  }
506 
507  //Get pointer of current channel frt register address
508  pstcTCSC = (stc_mft_frt_tcsc0_field_t*)((uint8_t*)pstcMft+0x4AUL+u8Ch*0x0C);
509 
510  return (uint8_t)pstcTCSC->MSZC;
511 }
531  uint8_t u8Ch, uint8_t u8Times)
532 {
533  stc_mft_frt_tcsc0_field_t* pstcTCSC;
534 
535  // Check for NULL pointer
536  if ( (pstcMft == NULL) ||
537  (u8Ch >= MFT_FRT_MAX_CH) ||
538  (u8Times > 15) )
539  {
540  return ErrorInvalidParameter ;
541  }
542 
543  //Get pointer of current channel frt register address
544  pstcTCSC = (stc_mft_frt_tcsc0_field_t*)((uint8_t*)pstcMft+0x4AUL+u8Ch*0x0C);
545 
546  pstcTCSC->MSPI = u8Times;
547 
548  return Ok;
549 }
550 
567 uint8_t Mft_Frt_GetMaskPeakTimes(volatile stc_mftn_frt_t*pstcMft, uint8_t u8Ch)
568 {
569  stc_mft_frt_tcsc0_field_t* pstcTCSC;
570 
571  // Check for NULL pointer
572  if ( (pstcMft == NULL)
573  || (u8Ch >= MFT_FRT_MAX_CH))
574  {
575  return 0 ;
576  }
577 
578  //Get pointer of current channel frt register address
579  pstcTCSC = (stc_mft_frt_tcsc0_field_t*)((uint8_t*)pstcMft+0x4AUL+u8Ch*0x0C);
580 
581  return (uint8_t)pstcTCSC->MSPC;
582 }
583 
600 en_result_t Mft_Frt_Start(volatile stc_mftn_frt_t*pstcMft, uint8_t u8Ch)
601 {
602  stc_mft_frt_tcsa0_field_t* pstcTCSA;
603 
604  // Check for NULL pointer
605  if ( (pstcMft == NULL)
606  || (u8Ch >= MFT_FRT_MAX_CH))
607  {
608  return ErrorInvalidParameter ;
609  }
610 
611  //Get pointer of current channel frt register address
612  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft+0x48UL+u8Ch*0x0C);
613  pstcTCSA->STOP = 0;
614  pstcTCSA->SCLR = 0;
615  return Ok;
616 }
617 
634 en_result_t Mft_Frt_Stop(volatile stc_mftn_frt_t*pstcMft, uint8_t u8Ch)
635 {
636  stc_mft_frt_tcsa0_field_t* pstcTCSA;
637 
638  // Check for NULL pointer
639  if ( (pstcMft == NULL)
640  || (u8Ch >= MFT_FRT_MAX_CH))
641  {
642  return ErrorInvalidParameter ;
643  }
644 
645  //Get pointer of current channel frt register address
646  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft+0x48UL+u8Ch*0x0C);
647 
648  pstcTCSA->STOP = 1;
649  pstcTCSA->SCLR = 1;
650  return Ok;
651 }
652 
653 #if (PDL_INTERRUPT_ENABLE_MFT0_FRT == PDL_ON) || \
654  (PDL_INTERRUPT_ENABLE_MFT1_FRT == PDL_ON) || \
655  (PDL_INTERRUPT_ENABLE_MFT2_FRT == PDL_ON)
656 
680  uint8_t u8Ch,
681  stc_frt_int_sel_t* pstcIntSel,
682  stc_frt_int_cb_t* pstcFrtIntCallback)
683 {
684  stc_mft_frt_tcsa0_field_t* pstcTCSA;
685  stc_mft_frt_intern_data_t* pstcFrtInternData ;
686 
687  // Check for NULL pointer
688  if ( (pstcMft == NULL)
689  || (u8Ch >= MFT_FRT_MAX_CH)
690  || (pstcIntSel->bFrtPeakMatchInt > 1)
691  || (pstcIntSel->bFrtZeroMatchInt > 1) )
692  {
693  return ErrorInvalidParameter ;
694  }
695 
696  // Get pointer to internal data structure ...
697  pstcFrtInternData = MftGetInternDataPtr( pstcMft ) ;
698 
699  //Get pointer of current channel frt register address
700  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft+0x48UL+u8Ch*0x0C);
701 
702  if(pstcIntSel->bFrtZeroMatchInt == 1) //zero detect interrupt
703  {
704  pstcTCSA->IRQZE = 1;
705  }
706  if(pstcIntSel->bFrtPeakMatchInt == 1) //peak detect interrupt
707  {
708  pstcTCSA->ICRE = 1;
709  }
710 
711  //set callback function
712  switch(u8Ch)
713  {
714  case MFT_FRT_CH0: //channel 0
715  if(pstcIntSel->bFrtZeroMatchInt == 1) //zero detect interrupt
716  {
717  pstcFrtInternData->pfnFrt0ZeroCallback = pstcFrtIntCallback->pfnFrtZeroCallback;
718  }
719  if(pstcIntSel->bFrtPeakMatchInt == 1) //peak detect interrupt
720  {
721  pstcFrtInternData->pfnFrt0PeakCallback = pstcFrtIntCallback->pfnFrtPeakCallback;
722  }
723  break;
724 
725  case MFT_FRT_CH1: //channel 1
726  if(pstcIntSel->bFrtZeroMatchInt == 1) //zero detect interrupt
727  {
728  pstcFrtInternData->pfnFrt1ZeroCallback = pstcFrtIntCallback->pfnFrtZeroCallback;
729  }
730  if(pstcIntSel->bFrtPeakMatchInt == 1) //peak detect interrupt
731  {
732  pstcFrtInternData->pfnFrt1PeakCallback = pstcFrtIntCallback->pfnFrtPeakCallback;
733  }
734  break;
735  case MFT_FRT_CH2: //channel 2
736  if(pstcIntSel->bFrtZeroMatchInt == 1) //zero detect interrupt
737  {
738  pstcFrtInternData->pfnFrt2ZeroCallback = pstcFrtIntCallback->pfnFrtZeroCallback;
739  }
740  if(pstcIntSel->bFrtPeakMatchInt == 1) //peak detect interrupt
741  {
742  pstcFrtInternData->pfnFrt2PeakCallback = pstcFrtIntCallback->pfnFrtPeakCallback;
743  }
744  break;
745  default :
746  return ErrorInvalidParameter;
747  }
748  Mft_Frt_InitIrq(pstcMft,pstcIntSel);
749 
750  return Ok;
751 }
752 
773 en_result_t Mft_Frt_DisableInt(volatile stc_mftn_frt_t*pstcMft,uint8_t u8Ch,
774  stc_frt_int_sel_t* pstcIntSel)
775 {
776  stc_mft_frt_tcsa0_field_t* pstcTCSA;
777 
778  // Check for NULL pointer
779  if ( (pstcMft == NULL)
780  || (u8Ch >= MFT_FRT_MAX_CH)
781  || (pstcIntSel->bFrtPeakMatchInt > 1)
782  || (pstcIntSel->bFrtZeroMatchInt > 1))
783  {
784  return ErrorInvalidParameter ;
785  }
786 
787  //Get pointer of current channel frt register address
788  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft+0x48UL+u8Ch*0x0C);
789 
790  if(pstcIntSel->bFrtZeroMatchInt == 1) //zero detect interrupt
791  {
792  pstcTCSA->IRQZE = 0;
793  }
794  if(pstcIntSel->bFrtPeakMatchInt == 1) //peak detect interrupt
795  {
796  pstcTCSA->ICRE = 0;
797  }
798  Mft_Frt_DeInitIrq(pstcMft, pstcIntSel);
799  return Ok;
800 }
801 
802 #endif
803 
825  uint8_t u8Ch,
826  en_mft_frt_int_t enIntType)
827 {
828  stc_mft_frt_tcsa0_field_t* pstcTCSA;
829  en_int_flag_t retval;
830 
831  //Get pointer of current channel frt register address
832  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft+0x48UL+u8Ch*0x0C);
833 
834  if(enFrtZeroMatchInt == enIntType) //zero detect interrupt
835  {
836  retval = (en_int_flag_t)pstcTCSA->IRQZF;
837  }
838  else //peak detect interrupt
839  {
840  retval = (en_int_flag_t)pstcTCSA->ICLR;
841  }
842 
843  return retval;
844 }
845 
867  uint8_t u8Ch,
868  en_mft_frt_int_t enIntType)
869 {
870  stc_mft_frt_tcsa0_field_t* pstcTCSA;
871 
872  // Check for NULL pointer
873  if ( (pstcMft == NULL)
874  || (u8Ch >= MFT_FRT_MAX_CH))
875  {
876  return ErrorInvalidParameter ;
877  }
878 
879  //Get pointer of current channel frt register address
880  pstcTCSA = (stc_mft_frt_tcsa0_field_t*)((uint8_t*)pstcMft+0x48UL+u8Ch*0x0C);
881 
882  if(enFrtZeroMatchInt == enIntType) //zero detect interrupt
883  {
884  pstcTCSA->IRQZF = 0;
885  }
886  else //peak detect interrupt
887  {
888  pstcTCSA->ICLR = 0;
889  }
890 
891  return Ok;
892 }
893 
915  uint8_t u8Ch, uint16_t u16Cycle)
916 {
917  uint16_t* pstcTCCP;
918 
919  // Check for NULL pointer
920  if ( (pstcMft == NULL)
921  || (u8Ch >= MFT_FRT_MAX_CH))
922  {
923  return ErrorInvalidParameter ;
924  }
925 
926  //Get pointer of current channel frt register address
927  pstcTCCP = (uint16_t*)( (uint8_t*)pstcMft + 0x42UL + u8Ch*0x0C);
928 
929  *pstcTCCP = u16Cycle;
930 
931  return Ok;
932 }
933 
954  uint8_t u8Ch,uint16_t u16Count)
955 {
956  uint16_t* pstcTCDT;
957 
958  // Check for NULL pointer
959  if ( (pstcMft == NULL)
960  || (u8Ch >= MFT_FRT_MAX_CH))
961  {
962  return ErrorInvalidParameter ;
963  }
964 
965  //Get pointer of current channel frt register address
966  pstcTCDT = (uint16_t*)( (uint8_t*)pstcMft + 0x46UL + u8Ch*0x0C);
967 
968  *pstcTCDT = u16Count;
969 
970  return Ok;
971 }
972 
987 uint16_t Mft_Frt_GetCurCount(volatile stc_mftn_frt_t*pstcMft, uint8_t u8Ch)
988 {
989  uint16_t retTCDT;
990  uint16_t* pstcTCDT;
991 
992  // Check for NULL pointer
993  if ( (pstcMft == NULL)
994  || (u8Ch >= MFT_FRT_MAX_CH))
995  {
996  return ErrorInvalidParameter ;
997  }
998 
999  //Get pointer of current channel frt register address
1000  pstcTCDT = (uint16_t*)( (uint8_t*)pstcMft + 0x46UL + u8Ch*0x0C);
1001 
1002  retTCDT = *pstcTCDT;
1003 
1004  return retTCDT;
1005 }
1006 
1008 
1009 #endif // #if (defined(PDL_PERIPHERAL_$$X_ACTIVE))
1010 
1011 /******************************************************************************/
1012 /* EOF (not truncated) */
1013 /******************************************************************************/