PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
qprc.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 /******************************************************************************/
52 /******************************************************************************/
53 /* Include files */
54 /******************************************************************************/
55 #include "qprc.h"
56 
57 #if (defined(PDL_PERIPHERAL_QPRC_ACTIVE))
58 
64 
65 /******************************************************************************/
66 /* Local pre-processor symbols/macros ('#define') */
67 /******************************************************************************/
68 #define QPRC_INSTANCE_COUNT (uint32_t)(sizeof(m_astcQprcInstanceDataLut) / sizeof(m_astcQprcInstanceDataLut[0]))
69 
70 /******************************************************************************/
71 /* Global variable definitions (declared in header file with 'extern') */
72 /******************************************************************************/
73 
74 /******************************************************************************/
75 /* Local type definitions ('typedef') */
76 /******************************************************************************/
77 
78 /******************************************************************************/
79 /* Local function prototypes ('static') */
80 /******************************************************************************/
81 static en_result_t QprcIsValidQprcnPtr(volatile stc_qprcn_t *pstcQprc);
82 static volatile stc_qprc_nfn_t* QprcGetNoisFilterPtr( volatile stc_qprcn_t *pstcQprc );
83 #if (PDL_INTERRUPT_ENABLE_QPRC0 == PDL_ON) || \
84  (PDL_INTERRUPT_ENABLE_QPRC1 == PDL_ON) || \
85  (PDL_INTERRUPT_ENABLE_QPRC2 == PDL_ON) || \
86  (PDL_INTERRUPT_ENABLE_QPRC3 == PDL_ON)
87 static stc_qprc_intern_data_t *QprcGetInternDataPtr( volatile stc_qprcn_t *pstcQprc );
88 #endif
89 /******************************************************************************/
90 /* Local variable definitions ('static') */
91 /******************************************************************************/
92 
93 /******************************************************************************/
94 /* Function implementation - global ('extern') and local ('static') */
95 /******************************************************************************/
98 {
99 #if (PDL_PERIPHERAL_ENABLE_QPRC0 == PDL_ON)
100  {
101  &QPRC0, // pstcInstance QPRC
102  &QPRCNF0, // pstcInstanceNf QPRC-NF
103  NULL // stcInternData (not initialized yet)
104  },
105 #endif
106 #if (PDL_PERIPHERAL_ENABLE_QPRC1 == PDL_ON)
107  {
108  &QPRC1, // pstcInstance QPRC
109  &QPRCNF1, // pstcInstanceNf QPRC-NF
110  NULL // stcInternData (not initialized yet)
111  },
112 #endif
113 #if (PDL_PERIPHERAL_ENABLE_QPRC2 == PDL_ON)
114  {
115  &QPRC2, // pstcInstance QPRC
116  &QPRCNF2, // pstcInstanceNf QPRC-NF
117  NULL // stcInternData (not initialized yet)
118  },
119 #endif
120 #if (PDL_PERIPHERAL_ENABLE_QPRC3 == PDL_ON)
121  {
122  &QPRC3, // pstcInstance QPRC
123  &QPRCNF3, // pstcInstanceNf QPRC-NF
124  NULL // stcInternData (not initialized yet)
125  },
126 #endif
127 
128 };
129 
140 static en_result_t QprcIsValidQprcnPtr(volatile stc_qprcn_t *pstcQprc)
141 {
142  uint32_t u32Instance;
143 
144  if (NULL == pstcQprc)
145  {
146  return ErrorInvalidParameter;
147  }
148 
149  for (u32Instance = 0; u32Instance < QPRC_INSTANCE_COUNT; u32Instance++)
150  {
151  if (pstcQprc == m_astcQprcInstanceDataLut[u32Instance].pstcInstance)
152  {
153  return Ok;
154  }
155  }
156 
157  return ErrorInvalidParameter;
158 }
159 
170 volatile stc_qprc_nfn_t *QprcGetNoisFilterPtr( volatile stc_qprcn_t *pstcQprc )
171 {
172  uint32_t u32Instance;
173 
174  for (u32Instance = 0; u32Instance < QPRC_INSTANCE_COUNT; u32Instance++)
175  {
176  if (pstcQprc == m_astcQprcInstanceDataLut[u32Instance].pstcInstance)
177  {
178  return m_astcQprcInstanceDataLut[u32Instance].pstcInstanceNf;
179  }
180  }
181 
182  return (stc_qprc_nfn_t *)NULL;
183 }
184 
185 
186 #if (PDL_INTERRUPT_ENABLE_QPRC0 == PDL_ON) || \
187  (PDL_INTERRUPT_ENABLE_QPRC1 == PDL_ON) || \
188  (PDL_INTERRUPT_ENABLE_QPRC2 == PDL_ON) || \
189  (PDL_INTERRUPT_ENABLE_QPRC3 == PDL_ON)
190 
202 {
203  uint32_t u32Instance;
204 
205  for (u32Instance = 0; u32Instance < QPRC_INSTANCE_COUNT; u32Instance++)
206  {
207  if (pstcQprc == m_astcQprcInstanceDataLut[u32Instance].pstcInstance)
208  {
209  return &m_astcQprcInstanceDataLut[u32Instance].stcInternData;
210  }
211  }
212 
213  return NULL;
214 }
215 
223 static void Qprc_InitNvic(volatile stc_qprcn_t* pstcQprc)
224 {
225  if (pstcQprc == (stc_qprcn_t*)(&QPRC0))
226  {
227  NVIC_ClearPendingIRQ(QPRC0_IRQn);
228  NVIC_EnableIRQ(QPRC0_IRQn);
229  NVIC_SetPriority(QPRC0_IRQn, PDL_IRQ_LEVEL_QPRC0);
230  }
231  else if (pstcQprc == (stc_qprcn_t*)(&QPRC1))
232  {
233  NVIC_ClearPendingIRQ(QPRC1_IRQn);
234  NVIC_EnableIRQ(QPRC1_IRQn);
235  NVIC_SetPriority(QPRC1_IRQn, PDL_IRQ_LEVEL_QPRC1);
236  }
237  else if (pstcQprc == (stc_qprcn_t*)(&QPRC2))
238  {
239  NVIC_ClearPendingIRQ(QPRC2_IRQn);
240  NVIC_EnableIRQ(QPRC2_IRQn);
241  NVIC_SetPriority(QPRC2_IRQn, PDL_IRQ_LEVEL_QPRC2);
242  }
243 }
244 
252 static void Qprc_DeInitNvic(volatile stc_qprcn_t* pstcQprc)
253 {
254  if (pstcQprc == (stc_qprcn_t*)(&QPRC0))
255  {
256  NVIC_ClearPendingIRQ(QPRC0_IRQn);
257  NVIC_DisableIRQ(QPRC0_IRQn);
258  NVIC_SetPriority(QPRC0_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
259  }
260  else if (pstcQprc == (stc_qprcn_t*)(&QPRC1))
261  {
262  NVIC_ClearPendingIRQ(QPRC1_IRQn);
263  NVIC_DisableIRQ(QPRC1_IRQn);
264  NVIC_SetPriority(QPRC1_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
265  }
266  else if (pstcQprc == (stc_qprcn_t*)(&QPRC2))
267  {
268  NVIC_ClearPendingIRQ(QPRC2_IRQn);
269  NVIC_DisableIRQ(QPRC2_IRQn);
270  NVIC_SetPriority(QPRC2_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
271  }
272 }
273 
282 void Qprc_IrqHandler ( volatile stc_qprcn_t *pstcQprc,
283  stc_qprc_intern_data_t *pstcQprcInternData )
284 {
285  if ((NULL == pstcQprc) ||
286  (NULL == pstcQprcInternData))
287  {
288  return;
289  }
290 
291  if (PdlSet == pstcQprc->QICRL_f.QPCMF) // QPCCR match ?
292  {
293  pstcQprc->QICRL_f.QPCMF = PdlClr; // Clear interrupt
294  if (NULL != pstcQprcInternData->pfnPcMatchCallback)
295  {
296  pstcQprcInternData->pfnPcMatchCallback();
297  }
298  }
299 
300  if (PdlSet == pstcQprc->QICRL_f.QPRCMF) // QPRCR match ?
301  {
302  pstcQprc->QICRL_f.QPRCMF = PdlClr; // Clear interrupt
303  if (NULL != pstcQprcInternData->pfnPcRcMatchCallback)
304  {
305  pstcQprcInternData->pfnPcRcMatchCallback();
306  }
307  }
308 
309  if (PdlSet == pstcQprc->QICRL_f.OFDF) //Overflow Interrupe ?
310  {
311  pstcQprc->QICRL_f.OFDF = PdlClr; // Clear interrupt
312  if (NULL != pstcQprcInternData->pfnPcUfOfZeroCallback)
313  {
314  pstcQprcInternData->pfnPcUfOfZeroCallback(QPRC_PC_OVERFLOW_INT);
315  }
316  }
317 
318  if (PdlSet == pstcQprc->QICRL_f.UFDF) //Underflow Interrupe ?
319  {
320  pstcQprc->QICRL_f.UFDF = PdlClr; // Clear interrupt
321  if (NULL != pstcQprcInternData->pfnPcUfOfZeroCallback)
322  {
323  pstcQprcInternData->pfnPcUfOfZeroCallback(QPRC_PC_UNDERFLOW_INT);
324  }
325  }
326 
327  if (PdlSet == pstcQprc->QICRL_f.ZIIF) //Zero Interrupe ?
328  {
329  pstcQprc->QICRL_f.ZIIF = PdlClr; // Clear interrupt
330  if (NULL != pstcQprcInternData->pfnPcUfOfZeroCallback)
331  {
332  pstcQprcInternData->pfnPcUfOfZeroCallback(QPRC_PC_ZERO_INDEX_INT);
333  }
334  }
335 
336  if (PdlSet == pstcQprc->QICRH_f.CDCF) //PC invert match ?
337  {
338  pstcQprc->QICRH_f.CDCF = PdlClr; // Clear interrupt
339  if (NULL != pstcQprcInternData->pfnPcCountInvertCallback)
340  {
341  pstcQprcInternData->pfnPcCountInvertCallback();
342  }
343  }
344 
345  if (PdlSet == pstcQprc->QECR_f.ORNGF) //RC outrange ?
346  {
347  pstcQprc->QECR_f.ORNGF = PdlClr; // Clear interrupt
348  if (NULL != pstcQprcInternData->pfnRcOutrangeCallback)
349  {
350  pstcQprcInternData->pfnRcOutrangeCallback();
351  }
352  }
353 
354  if (PdlSet == pstcQprc->QICRH_f.QPCNRCMF) //PcMatch and RcMatch ?
355  {
356  pstcQprc->QICRH_f.QPCNRCMF = PdlClr; // Clear interrupt
357  if (NULL != pstcQprcInternData->pfnPcMatchRcMatchCallback)
358  {
359  pstcQprcInternData->pfnPcMatchRcMatchCallback();
360  }
361  }
362 
363  return;
364 }
365 
366 #endif
367 
383 en_result_t Qprc_Init( volatile stc_qprcn_t* pstcQprc,
384  stc_qprc_config_t* pstcConfig )
385 {
386  volatile stc_qprc_nfn_t *pstcQprcInternNfn;
387 
388  if ( (Ok != QprcIsValidQprcnPtr(pstcQprc)) ||
389  (NULL == pstcConfig)
390  )
391  {
392  return ErrorInvalidParameter;
393  }
394 
395  if (((pstcConfig->bSwapAinBin != TRUE) && (pstcConfig->bSwapAinBin != FALSE))||
396  (pstcConfig->enComapreMode > QprcComapreWithRevolution) ||
397  (pstcConfig->enZinEdge > QprcZinHighLevel) ||
398  (pstcConfig->enBinEdge > QprcBinBothEdges) ||
399  (pstcConfig->enAinEdge > QprcAinBothEdges) ||
400  (pstcConfig->enPcResetMask > QprcResetMask8Times) ||
401  (pstcConfig->stcAinFilter.enWidth > QprcFilterWidth256Pclk) ||
402  (pstcConfig->stcBinFilter.enWidth > QprcFilterWidth256Pclk) ||
403  (pstcConfig->stcCinFilter.enWidth > QprcFilterWidth256Pclk) ||
404  ((pstcConfig->stcAinFilter.bInputMask != TRUE) && (pstcConfig->stcAinFilter.bInputMask != FALSE))||
405  ((pstcConfig->stcBinFilter.bInputMask != TRUE) && (pstcConfig->stcBinFilter.bInputMask != FALSE))||
406  ((pstcConfig->stcCinFilter.bInputMask != TRUE) && (pstcConfig->stcCinFilter.bInputMask != FALSE))||
407  ((pstcConfig->stcAinFilter.bInputInvert != TRUE) && (pstcConfig->stcAinFilter.bInputInvert != FALSE))||
408  ((pstcConfig->stcBinFilter.bInputInvert != TRUE) && (pstcConfig->stcBinFilter.bInputInvert != FALSE))||
409  ((pstcConfig->stcCinFilter.bInputInvert != TRUE) && (pstcConfig->stcCinFilter.bInputInvert != FALSE)))
410 
411  {
412  return ErrorInvalidParameter;
413  }
414 
415  pstcQprc->QCRL_f.SWAP = (TRUE == pstcConfig->bSwapAinBin) ? 1 : 0 ;
416  pstcQprc->QCRL_f.RSEL = pstcConfig->enComapreMode;
417 
418  switch (pstcConfig->enZinEdge)
419  {
420  case QprcZinDisable: // Disables edge and level detection
421  {
422  pstcQprc->QCRH_f.CGE0 = 0;
423  pstcQprc->QCRH_f.CGE1 = 0;
424  }
425  break;
426 
427  case QprcZinFallingEdge: // ZIN active at falling edge
428  {
429  pstcQprc->QCRL_f.CGSC = 0;
430  pstcQprc->QCRH_f.CGE0 = 1;
431  pstcQprc->QCRH_f.CGE1 = 0;
432  }
433  break;
434 
435  case QprcZinRisingEdge: // ZIN active at rising edge
436  {
437  pstcQprc->QCRL_f.CGSC = 0;
438  pstcQprc->QCRH_f.CGE0 = 0;
439  pstcQprc->QCRH_f.CGE1 = 1;
440  }
441  break;
442 
443  case QprcZinBothEdges: // ZIN active at falling or rising edge
444  {
445  pstcQprc->QCRL_f.CGSC = 0;
446  pstcQprc->QCRH_f.CGE0 = 1;
447  pstcQprc->QCRH_f.CGE1 = 1;
448  }
449  break;
450 
451  case QprcZinLowLevel: // ZIN active at low level detected
452  {
453  pstcQprc->QCRL_f.CGSC = 1;
454  pstcQprc->QCRH_f.CGE0 = 1;
455  pstcQprc->QCRH_f.CGE1 = 0;
456  }
457  break;
458 
459  case QprcZinHighLevel: // ZIN active at high level detected
460  {
461  pstcQprc->QCRL_f.CGSC = 1;
462  pstcQprc->QCRH_f.CGE0 = 0;
463  pstcQprc->QCRH_f.CGE1 = 1;
464  }
465  break;
466 
467  default:
468  break;
469  }
470 
471  switch (pstcConfig->enBinEdge)
472  {
473  case QprcBinDisable: // Disables edge detection
474  {
475  pstcQprc->QCRH_f.BES0 = 0;
476  pstcQprc->QCRH_f.BES1 = 0;
477  }
478  break;
479 
480  case QprcBinFallingEdge: // BIN active at falling edge
481  {
482  pstcQprc->QCRH_f.BES0 = 1;
483  pstcQprc->QCRH_f.BES1 = 0;
484  }
485  break;
486 
487  case QprcBinRisingEdge: // BIN active at rising edge
488  {
489  pstcQprc->QCRH_f.BES0 = 0;
490  pstcQprc->QCRH_f.BES1 = 1;
491  }
492  break;
493 
494  case QprcBinBothEdges: // BIN active at falling or rising edge
495  {
496  pstcQprc->QCRH_f.BES0 = 1;
497  pstcQprc->QCRH_f.BES1 = 1;
498  }
499  break;
500 
501  default:
502  break;
503  }
504 
505  switch (pstcConfig->enAinEdge)
506  {
507  case QprcBinDisable: // Disables edge detection
508  {
509  pstcQprc->QCRH_f.AES0 = 0;
510  pstcQprc->QCRH_f.AES1 = 0;
511  }
512  break;
513 
514  case QprcBinFallingEdge: // BIN active at falling edge
515  {
516  pstcQprc->QCRH_f.AES0 = 1;
517  pstcQprc->QCRH_f.AES1 = 0;
518  }
519  break;
520 
521  case QprcBinRisingEdge: // BIN active at rising edge
522  {
523  pstcQprc->QCRH_f.AES0 = 0;
524  pstcQprc->QCRH_f.AES1 = 1;
525  }
526  break;
527 
528  case QprcBinBothEdges: // BIN active at falling or rising edge
529  {
530  pstcQprc->QCRH_f.AES0 = 1;
531  pstcQprc->QCRH_f.AES1 = 1;
532  }
533  break;
534 
535  default:
536  break;
537  }
538 
539  switch (pstcConfig->enPcResetMask)
540  {
541  case QprcResetMaskDisable: // No reset mask
542  {
543  pstcQprc->QCRH_f.PCRM0 = 0;
544  pstcQprc->QCRH_f.PCRM1 = 0;
545  }
546  break;
547 
548  case QprcResetMask2Times:
549  {
550  pstcQprc->QCRH_f.PCRM0 = 1;
551  pstcQprc->QCRH_f.PCRM1 = 0;
552  }
553  break;
554 
555  case QprcResetMask4Times:
556  {
557  pstcQprc->QCRH_f.PCRM0 = 0;
558  pstcQprc->QCRH_f.PCRM1 = 1;
559  }
560  break;
561 
562  case QprcResetMask8Times:
563  {
564  pstcQprc->QCRH_f.PCRM0 = 1;
565  pstcQprc->QCRH_f.PCRM1 = 1;
566  }
567  break;
568 
569  default:
570  break;
571  }
572 
573  pstcQprc->QECR_f.ORNGMD = (TRUE == pstcConfig->b8KValue) ? 1 : 0 ; // TRUE: Outrange mode from 0 to 0x7FFF, FALSE: Outrange mode from 0 to 0xFFFF:
574 
575  /* Set QPRC Noise Filter */
576  pstcQprcInternNfn = QprcGetNoisFilterPtr(pstcQprc);
577 
578  pstcQprcInternNfn->NFCTLA_f.AINMD = (TRUE == pstcConfig->stcAinFilter.bInputMask) ? 1 : 0 ;
579  pstcQprcInternNfn->NFCTLA_f.AINLV = (TRUE == pstcConfig->stcAinFilter.bInputInvert) ? 1 : 0 ;
580  pstcQprcInternNfn->NFCTLA_f.AINNWS = pstcConfig->stcAinFilter.enWidth;
581 
582  pstcQprcInternNfn->NFCTLB_f.BINMD = (TRUE == pstcConfig->stcBinFilter.bInputMask) ? 1 : 0 ;
583  pstcQprcInternNfn->NFCTLB_f.BINLV = (TRUE == pstcConfig->stcBinFilter.bInputInvert) ? 1 : 0 ;
584  pstcQprcInternNfn->NFCTLB_f.BINNWS = pstcConfig->stcBinFilter.enWidth;
585 
586  pstcQprcInternNfn->NFRCTLZ_f.ZINMD = (TRUE == pstcConfig->stcCinFilter.bInputMask) ? 1 : 0 ;
587  pstcQprcInternNfn->NFRCTLZ_f.ZINLV = (TRUE == pstcConfig->stcCinFilter.bInputInvert) ? 1 : 0 ;
588  pstcQprcInternNfn->NFRCTLZ_f.ZINNWS = pstcConfig->stcCinFilter.enWidth;
589 
590  return Ok;
591 }
592 
603 {
604  // Check for NULL pointer
605  if (NULL == pstcQprc)
606  {
607  return ErrorInvalidParameter ;
608  }
609 
610  pstcQprc->QCRL_f.PSTP = 0;
611  return Ok;
612 }
613 
624 {
625  // Check for NULL pointer
626  if (NULL == pstcQprc)
627  {
628  return ErrorInvalidParameter ;
629  }
630 
631  pstcQprc->QCRL_f.PSTP = 1;
632  return Ok;
633 }
634 
647  uint16_t u16PcValue )
648 {
649  if (NULL == pstcQprc)
650  {
651  return ErrorInvalidParameter;
652  }
653 
654  pstcQprc->QPCR = u16PcValue;
655  return Ok;
656 }
657 
666 uint16_t Qprc_GetPcCount ( volatile stc_qprcn_t *pstcQprc )
667 {
668  if (NULL == pstcQprc)
669  {
670  return ErrorInvalidParameter;
671  }
672 
673  return (uint16_t)pstcQprc->QPCR;
674 }
675 
688  uint16_t u16RcValue )
689 {
690  if (NULL == pstcQprc)
691  {
692  return ErrorInvalidParameter;
693  }
694 
695  pstcQprc->QRCR = u16RcValue;
696  return Ok;
697 }
698 
699 
708 uint16_t Qprc_GetRcCount ( volatile stc_qprcn_t *pstcQprc )
709 {
710  if (NULL == pstcQprc)
711  {
712  return ErrorInvalidParameter;
713  }
714 
715  return (uint16_t)pstcQprc->QPCR;
716 }
717 
730  uint16_t u16PcMaxValue )
731 {
732  if (NULL == pstcQprc)
733  {
734  return ErrorInvalidParameter;
735  }
736 
737  pstcQprc->QMPR = u16PcMaxValue;
738  return Ok;
739 }
740 
749 uint16_t Qprc_GetPcMaxValue(volatile stc_qprcn_t *pstcQprc)
750 {
751  if (NULL == pstcQprc)
752  {
753  return ErrorInvalidParameter;
754  }
755 
756  return (uint16_t)pstcQprc->QMPR;
757 }
758 
772  uint16_t u16PcValue )
773 {
774  if (NULL == pstcQprc)
775  {
776  return ErrorInvalidParameter;
777  }
778 
779  pstcQprc->QPCCR = u16PcValue;
780 
781  return Ok;
782 }
783 
793 uint16_t Qprc_GetPcCompareValue( volatile stc_qprcn_t *pstcQprc)
794 {
795  if (NULL == pstcQprc)
796  {
797  return ErrorInvalidParameter;
798  }
799 
800  return (uint16_t)pstcQprc->QPCCR;
801 }
802 
803 
816  uint16_t u16PcRcValue )
817 {
818  if (NULL == pstcQprc)
819  {
820  return ErrorInvalidParameter;
821  }
822 
823  pstcQprc->QPRCR = u16PcRcValue;
824 
825  return Ok;
826 }
827 
836 uint16_t Qprc_GetPcRcCompareValue(volatile stc_qprcn_t *pstcQprc)
837 {
838  if (NULL == pstcQprc)
839  {
840  return ErrorInvalidParameter;
841  }
842 
843  return (uint16_t)pstcQprc->QPRCR;
844 }
845 
860  en_qprc_pcmode_t enMode )
861 {
862  if ((NULL == pstcQprc) ||
863  (enMode > QprcPcMode3))
864  {
865  return ErrorInvalidParameter;
866  }
867 
868  switch(enMode)
869  {
870  case QprcPcMode0: //Disable position counter
871  {
872  pstcQprc->QCRL_f.PCM0 = 0;
873  pstcQprc->QCRL_f.PCM1 = 0;
874  }
875  break;
876 
877  case QprcPcMode1: //Increments with AIN active edge and decrements with BIN active edge
878  {
879  pstcQprc->QCRL_f.PCM0 = 1;
880  pstcQprc->QCRL_f.PCM1 = 0;
881  }
882  break;
883 
884  case QprcPcMode2: //Phase difference count mode: Counts up if AIN is leading BIN, down if BIN leading.
885  {
886  pstcQprc->QCRL_f.PCM0 = 0;
887  pstcQprc->QCRL_f.PCM1 = 1;
888  }
889  break;
890 
891  case QprcPcMode3: // Directional count mode: Counts up/down with BIN active edge and AIN level
892  {
893  pstcQprc->QCRL_f.PCM0 = 1;
894  pstcQprc->QCRL_f.PCM1 = 1;
895  }
896  break;
897 
898  default:
899  return ErrorInvalidParameter;
900  }
901 
902  return Ok;
903 }
904 
918  en_qprc_rcmode_t enMode )
919 {
920  if ((NULL == pstcQprc) ||
921  (enMode > QprcRcMode3))
922  {
923  return ErrorInvalidParameter;
924  }
925 
926  switch(enMode)
927  {
928  case QprcRcMode0:
929  {
930  pstcQprc->QCRL_f.RCM0 = 0;
931  pstcQprc->QCRL_f.RCM1 = 0;
932  }
933  break;
934 
935  case QprcRcMode1: //Up/down count of RC with ZIN active edge
936  {
937  pstcQprc->QCRL_f.RCM0 = 1;
938  pstcQprc->QCRL_f.RCM1 = 0;
939  }
940  break;
941 
942  case QprcRcMode2: //Up/down count of RC on over or underflow in position count match
943  {
944  pstcQprc->QCRL_f.RCM0 = 0;
945  pstcQprc->QCRL_f.RCM1 = 1;
946  }
947  break;
948 
949  case QprcRcMode3: //Up/down count of RC on over or underflow in position count match and ZIN active edge
950  {
951  pstcQprc->QCRL_f.RCM0 = 1;
952  pstcQprc->QCRL_f.RCM1 = 1;
953  }
954  break;
955 
956  default:
957  return ErrorInvalidParameter;
958  }
959 
960  return Ok;
961 }
962 
963 #if (PDL_INTERRUPT_ENABLE_QPRC0 == PDL_ON) || \
964  (PDL_INTERRUPT_ENABLE_QPRC1 == PDL_ON) || \
965  (PDL_INTERRUPT_ENABLE_QPRC2 == PDL_ON) || \
966  (PDL_INTERRUPT_ENABLE_QPRC3 == PDL_ON)
967 
979 en_result_t Qprc_EnableInt( volatile stc_qprcn_t* pstcQprc, stc_qprc_int_sel_t* pstcIntSel,
980  stc_qprc_int_cb_t* pstcIntCallback )
981 {
982  stc_qprc_intern_data_t *pstcQprcInternData = NULL;
983  if ((NULL == pstcQprc) ||
984  (pstcIntSel->bQprcPcCountInvertInt > 1) ||
985  (pstcIntSel->bQprcPcMatchInt > 1) ||
986  (pstcIntSel->bQprcPcMatchRcMatchInt > 1) ||
987  (pstcIntSel->bQprcPcOfUfZeroInt > 1) ||
988  (pstcIntSel->bQprcPcRcMatchInt > 1) ||
989  (pstcIntSel->bQprcRcOutrangeInt > 1) ||
990  (NULL == pstcIntCallback) )
991  {
992  return ErrorInvalidParameter;
993  }
994 
995  pstcQprcInternData = QprcGetInternDataPtr(pstcQprc);
996 
997  if (NULL == pstcQprcInternData)
998  {
999  return ErrorInvalidParameter;
1000  }
1001  if (TRUE == pstcIntSel->bQprcPcMatchInt)
1002  {
1003  pstcQprcInternData->pfnPcMatchCallback = pstcIntCallback->pfnPcMatchIntCallback;
1004  pstcQprc->QICRL_f.QPCMIE = 1;
1005  }
1006  if (TRUE == pstcIntSel->bQprcPcRcMatchInt)
1007  {
1008  pstcQprcInternData->pfnPcRcMatchCallback = pstcIntCallback->pfnPcRcMatchIntCallback;
1009  pstcQprc->QICRL_f.QPRCMIE = 1;
1010  }
1011  if (TRUE == pstcIntSel->bQprcPcMatchRcMatchInt)
1012  {
1013  pstcQprcInternData->pfnPcMatchRcMatchCallback = pstcIntCallback->pfnPcMatchRcMatchIntCallback;
1014  pstcQprc->QICRH_f.QPCNRCMIE = 1;
1015  }
1016  if (TRUE == pstcIntSel->bQprcPcOfUfZeroInt)
1017  {
1018  pstcQprcInternData->pfnPcUfOfZeroCallback = pstcIntCallback->pfnPcOfUfZeroIntCallback;
1019  pstcQprc->QICRL_f.OUZIE = 1;
1020  }
1021  if (TRUE == pstcIntSel->bQprcPcCountInvertInt)
1022  {
1023  pstcQprcInternData->pfnPcCountInvertCallback = pstcIntCallback->pfnPcCountInvertIntCallback;
1024  pstcQprc->QICRH_f.CDCIE = 1;
1025  }
1026  if (TRUE == pstcIntSel->bQprcRcOutrangeInt)
1027  {
1028  pstcQprcInternData->pfnRcOutrangeCallback = pstcIntCallback->pfnRcOutrangeIntCallback;
1029  pstcQprc->QECR_f.ORNGIE = 1;
1030  }
1031 
1032  Qprc_InitNvic(pstcQprc);
1033 
1034  return Ok;
1035 }
1036 
1048 en_result_t Qprc_DisableInt( volatile stc_qprcn_t* pstcQprc, stc_qprc_int_sel_t* pstcIntSel )
1049 {
1050  stc_qprc_intern_data_t *pstcQprcInternData = NULL;
1051  if((NULL == pstcQprc) ||
1052  (pstcIntSel->bQprcPcCountInvertInt > 1) ||
1053  (pstcIntSel->bQprcPcMatchInt > 1) ||
1054  (pstcIntSel->bQprcPcMatchRcMatchInt > 1) ||
1055  (pstcIntSel->bQprcPcOfUfZeroInt > 1) ||
1056  (pstcIntSel->bQprcPcRcMatchInt > 1) ||
1057  (pstcIntSel->bQprcRcOutrangeInt > 1))
1058  {
1059  return ErrorInvalidParameter;
1060  }
1061 
1062  pstcQprcInternData = QprcGetInternDataPtr(pstcQprc);
1063 
1064  if (NULL == pstcQprcInternData)
1065  {
1066  return ErrorInvalidParameter;
1067  }
1068  if (TRUE == pstcIntSel->bQprcPcMatchInt)
1069  {
1070  pstcQprcInternData->pfnPcMatchCallback = NULL;
1071  pstcQprc->QICRL_f.QPCMIE = 0;
1072  }
1073  if (TRUE == pstcIntSel->bQprcPcRcMatchInt)
1074  {
1075  pstcQprcInternData->pfnPcRcMatchCallback = NULL;
1076  pstcQprc->QICRL_f.QPRCMIE = 0;
1077  }
1078  if (TRUE == pstcIntSel->bQprcPcMatchRcMatchInt)
1079  {
1080  pstcQprcInternData->pfnPcMatchRcMatchCallback = NULL;
1081  pstcQprc->QICRH_f.QPCNRCMIE = 0;
1082  }
1083  if (TRUE == pstcIntSel->bQprcPcOfUfZeroInt)
1084  {
1085  pstcQprcInternData->pfnPcUfOfZeroCallback = NULL;
1086  pstcQprc->QICRL_f.OUZIE = 0;
1087  }
1088  if (TRUE == pstcIntSel->bQprcPcCountInvertInt)
1089  {
1090  pstcQprcInternData->pfnPcCountInvertCallback = NULL;
1091  pstcQprc->QICRH_f.CDCIE = 0;
1092  }
1093  if (TRUE == pstcIntSel->bQprcRcOutrangeInt)
1094  {
1095  pstcQprcInternData->pfnRcOutrangeCallback = NULL;
1096  pstcQprc->QECR_f.ORNGIE = 0;
1097  }
1098 
1099  if((0 == pstcQprc->QICRL_f.QPCMIE) &&
1100  (0 == pstcQprc->QICRL_f.QPRCMIE) &&
1101  (0 == pstcQprc->QICRH_f.QPCNRCMIE) &&
1102  (0 == pstcQprc->QICRL_f.OUZIE) &&
1103  (0 == pstcQprc->QICRH_f.CDCIE) &&
1104  (0 == pstcQprc->QECR_f.ORNGIE) )
1105  {
1106  Qprc_DeInitNvic(pstcQprc);
1107  }
1108 
1109  return Ok;
1110 }
1111 
1112 #endif
1113 
1125  en_qprc_int_t enIntType)
1126 {
1127  en_int_flag_t enIntFlag = PdlClr;
1128 
1129  if ((NULL == pstcQprc) ||
1130  (enIntType > QprcRcOutrangeInt))
1131  {
1132  return PdlClr;
1133  }
1134 
1135  switch(enIntType)
1136  {
1137  case QprcPcOfUfZeroInt:
1138  {
1139  if((PdlSet == pstcQprc->QICRL_f.ZIIF) ||
1140  (PdlSet == pstcQprc->QICRL_f.OFDF) ||
1141  (PdlSet == pstcQprc->QICRL_f.UFDF))
1142  {
1143  enIntFlag = PdlSet;
1144  }
1145  }
1146  break;
1147 
1148  case QprcPcMatchInt:
1149  {
1150  enIntFlag = (1 == pstcQprc->QICRL_f.QPCMF) ? PdlSet : PdlClr ;
1151  }
1152  break;
1153 
1154  case QprcPcRcMatchInt:
1155  {
1156  enIntFlag = (1 == pstcQprc->QICRL_f.QPRCMF) ? PdlSet : PdlClr ;
1157  }
1158  break;
1159 
1160  case QprcPcMatchRcMatchInt:
1161  {
1162  enIntFlag = (1 == pstcQprc->QICRH_f.QPCNRCMF) ? PdlSet : PdlClr ;
1163  }
1164  break;
1165 
1166  case QprcPcCountInvertInt:
1167  {
1168  enIntFlag = (1 == pstcQprc->QICRH_f.CDCF) ? PdlSet : PdlClr ;
1169  }
1170  break;
1171 
1172  case QprcRcOutrangeInt:
1173  {
1174  enIntFlag = (1 == pstcQprc->QECR_f.ORNGF) ? PdlSet : PdlClr ;
1175  }
1176  break;
1177 
1178  default:
1179  break;
1180  }
1181 
1182  return enIntFlag;
1183 }
1184 
1185 
1199  en_qprc_int_t enIntType)
1200 {
1201  if ((NULL == pstcQprc) ||
1202  (enIntType > QprcRcOutrangeInt))
1203  {
1204  return ErrorInvalidParameter;
1205  }
1206 
1207  switch(enIntType)
1208  {
1209  case QprcPcOfUfZeroInt:
1210  {
1211  pstcQprc->QICRL_f.ZIIF = PdlClr;
1212  pstcQprc->QICRL_f.OFDF = PdlClr;
1213  pstcQprc->QICRL_f.UFDF = PdlClr;
1214  }
1215  break;
1216 
1217  case QprcPcMatchInt:
1218  {
1219  pstcQprc->QICRL_f.QPCMF = PdlClr;
1220  }
1221  break;
1222 
1223  case QprcPcRcMatchInt:
1224  {
1225  pstcQprc->QICRL_f.QPRCMF = PdlClr;
1226  }
1227  break;
1228 
1229  case QprcPcMatchRcMatchInt:
1230  {
1231  pstcQprc->QICRH_f.QPCNRCMF = PdlClr;
1232  }
1233  break;
1234 
1235  case QprcPcCountInvertInt:
1236  {
1237  pstcQprc->QICRH_f.CDCF = PdlClr;
1238  }
1239  break;
1240 
1241  case QprcRcOutrangeInt:
1242  {
1243  pstcQprc->QECR_f.ORNGF = PdlClr;
1244  }
1245  break;
1246 
1247  default:
1248  break;
1249  }
1250 
1251  return Ok;
1252 
1253 }
1254 
1265 {
1266  en_stat_flag_t enStatFlag = PdlClr;
1267 
1268  if (NULL == pstcQprc)
1269  {
1270  return PdlClr;
1271  }
1272 
1273  enStatFlag = (1 == pstcQprc->QICRH_f.DIROU) ? PdlSet : PdlClr ;
1274  return enStatFlag;
1275 }
1276 
1287 {
1288  en_stat_flag_t enStatFlag = PdlClr;
1289 
1290  if (NULL == pstcQprc)
1291  {
1292  return PdlClr;
1293  }
1294 
1295  enStatFlag = (1 == pstcQprc->QICRH_f.DIRPC) ? PdlSet : PdlClr ;
1296 
1297  return enStatFlag;
1298 }
1299 
1300 
1301 
1303 
1304 
1305 #endif // #if (defined(PDL_PERIPHERAL_QPRC_ACTIVE))
1306 
1307 /******************************************************************************/
1308 /* EOF (not truncated) */
1309 /******************************************************************************/