![]() |
PDL for FM0+
Version1.0
Peripheral Driverl Library for FM0+
|
00001 /******************************************************************************* 00002 * Copyright (C) 2013 Spansion LLC. All Rights Reserved. 00003 * 00004 * This software is owned and published by: 00005 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion"). 00006 * 00007 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND 00008 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT. 00009 * 00010 * This software contains source code for use with Spansion 00011 * components. This software is licensed by Spansion to be adapted only 00012 * for use in systems utilizing Spansion components. Spansion shall not be 00013 * responsible for misuse or illegal use of this software for devices not 00014 * supported herein. Spansion is providing this software "AS IS" and will 00015 * not be responsible for issues arising from incorrect user implementation 00016 * of the software. 00017 * 00018 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE, 00019 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS), 00020 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING, 00021 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED 00022 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED 00023 * WARRANTY OF NONINFRINGEMENT. 00024 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT, 00025 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT 00026 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, 00027 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR 00028 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT, 00029 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA, 00030 * SAVINGS OR PROFITS, 00031 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00032 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR 00033 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED 00034 * FROM, THE SOFTWARE. 00035 * 00036 * This software may be replicated in part or whole for the licensed use, 00037 * with the restriction that this Disclaimer and Copyright notice must be 00038 * included with each copy of this software, whether used in part or whole, 00039 * at all times. 00040 */ 00041 /******************************************************************************/ 00052 /******************************************************************************/ 00053 /* Include files */ 00054 /******************************************************************************/ 00055 #include "qprc.h" 00056 00057 #if (defined(PDL_PERIPHERAL_QPRC_ACTIVE)) 00058 00063 /******************************************************************************/ 00064 /* Local pre-processor symbols/macros ('#define') */ 00065 /******************************************************************************/ 00066 00067 /******************************************************************************/ 00068 /* Global variable definitions (declared in header file with 'extern') */ 00069 /******************************************************************************/ 00070 00071 /******************************************************************************/ 00072 /* Local type definitions ('typedef') */ 00073 /******************************************************************************/ 00074 00075 /******************************************************************************/ 00076 /* Local function prototypes ('static') */ 00077 /******************************************************************************/ 00078 static en_result_t QprcIsValidQprcnPtr(volatile stc_qprcn_t *pstcQprc); 00079 static volatile stc_qprc_nfn_t* QprcGetNoisFilterPtr( volatile stc_qprcn_t *pstcQprc ); 00080 #if (PDL_INTERRUPT_ENABLE_QPRC0 == PDL_ON) || \ 00081 (PDL_INTERRUPT_ENABLE_QPRC1 == PDL_ON) || \ 00082 (PDL_INTERRUPT_ENABLE_QPRC2 == PDL_ON) 00083 static stc_qprc_intern_data_t *QprcGetInternDataPtr( volatile stc_qprcn_t *pstcQprc ); 00084 #endif 00085 /******************************************************************************/ 00086 /* Local variable definitions ('static') */ 00087 /******************************************************************************/ 00088 00089 /******************************************************************************/ 00090 /* Function implementation - global ('extern') and local ('static') */ 00091 /******************************************************************************/ 00093 stc_qprc_instance_data_t m_astcQprcInstanceDataLut[QPRC_INSTANCE_COUNT] = 00094 { 00095 #if (PDL_PERIPHERAL_ENABLE_QPRC0 == PDL_ON) 00096 { 00097 &QPRC0, // pstcInstance QPRC 00098 &QPRCNF0, // pstcInstanceNf QPRC-NF 00099 {NULL,NULL,NULL,NULL,NULL,NULL} // stcInternData (not initialized yet) 00100 }, 00101 #endif 00102 #if (PDL_PERIPHERAL_ENABLE_QPRC1 == PDL_ON) 00103 { 00104 &QPRC1, // pstcInstance QPRC 00105 &QPRCNF1, // pstcInstanceNf QPRC-NF 00106 {NULL,NULL,NULL,NULL,NULL,NULL} // stcInternData (not initialized yet) 00107 }, 00108 #endif 00109 #if (PDL_PERIPHERAL_ENABLE_QPRC2 == PDL_ON) 00110 { 00111 &QPRC2, // pstcInstance QPRC 00112 &QPRCNF2, // pstcInstanceNf QPRC-NF 00113 {NULL,NULL,NULL,NULL,NULL,NULL} // stcInternData (not initialized yet) 00114 }, 00115 #endif 00116 00117 }; 00118 00129 static en_result_t QprcIsValidQprcnPtr(volatile stc_qprcn_t *pstcQprc) 00130 { 00131 uint32_t u32Instance; 00132 00133 if (NULL == pstcQprc) 00134 { 00135 return ErrorInvalidParameter; 00136 } 00137 00138 for (u32Instance = 0; u32Instance < QPRC_INSTANCE_COUNT; u32Instance++) 00139 { 00140 if (pstcQprc == m_astcQprcInstanceDataLut[u32Instance].pstcInstance) 00141 { 00142 return Ok; 00143 } 00144 } 00145 00146 return ErrorInvalidParameter; 00147 } 00148 00158 static volatile stc_qprc_nfn_t *QprcGetNoisFilterPtr( volatile stc_qprcn_t *pstcQprc ) 00159 { 00160 uint32_t u32Instance; 00161 00162 for (u32Instance = 0; u32Instance < QPRC_INSTANCE_COUNT; u32Instance++) 00163 { 00164 if (pstcQprc == m_astcQprcInstanceDataLut[u32Instance].pstcInstance) 00165 { 00166 return m_astcQprcInstanceDataLut[u32Instance].pstcInstanceNf; 00167 } 00168 } 00169 00170 return (volatile stc_qprc_nfn_t *)NULL; 00171 } 00172 00173 00174 #if (PDL_INTERRUPT_ENABLE_QPRC0 == PDL_ON) || \ 00175 (PDL_INTERRUPT_ENABLE_QPRC1 == PDL_ON) || \ 00176 (PDL_INTERRUPT_ENABLE_QPRC2 == PDL_ON) 00177 00186 static stc_qprc_intern_data_t *QprcGetInternDataPtr( volatile stc_qprcn_t *pstcQprc ) 00187 { 00188 uint32_t u32Instance; 00189 00190 for (u32Instance = 0; u32Instance < QPRC_INSTANCE_COUNT; u32Instance++) 00191 { 00192 if (pstcQprc == m_astcQprcInstanceDataLut[u32Instance].pstcInstance) 00193 { 00194 return &m_astcQprcInstanceDataLut[u32Instance].stcInternData; 00195 } 00196 } 00197 00198 return NULL; 00199 } 00200 00208 static void Qprc_InitNvic(volatile stc_qprcn_t* pstcQprc) 00209 { 00210 if ((pstcQprc == (volatile stc_qprcn_t*)(&QPRC0)) || 00211 (pstcQprc == (volatile stc_qprcn_t*)(&QPRC1)) || 00212 (pstcQprc == (volatile stc_qprcn_t*)(&QPRC2))) 00213 { 00214 NVIC_ClearPendingIRQ(DTIM_QDU_IRQn); 00215 NVIC_EnableIRQ(DTIM_QDU_IRQn); 00216 NVIC_SetPriority(DTIM_QDU_IRQn, PDL_IRQ_LEVEL_DT_QPRC); 00217 } 00218 } 00219 00227 static void Qprc_DeInitNvic(volatile stc_qprcn_t* pstcQprc) 00228 { 00229 FM0P_DTIM_TypeDef* pDtReg = ((FM0P_DTIM_TypeDef *)FM0P_DTIM_BASE); 00230 00231 if ((pstcQprc == (volatile stc_qprcn_t*)(&QPRC0)) || 00232 (pstcQprc == (volatile stc_qprcn_t*)(&QPRC1)) || 00233 (pstcQprc == (volatile stc_qprcn_t*)(&QPRC2))) 00234 { 00235 if((FM0P_QPRC0->QECR & 0x0004u) != 0x0000u) /* ORNGIE = 0? */ 00236 { 00237 return; 00238 } 00239 00240 if((FM0P_QPRC0->QICRL & 0x15u) != 0x00u) /* OUZIE=QPRCMIE=QPCMIE=0? */ 00241 { 00242 return; 00243 } 00244 00245 if((FM0P_QPRC0->QICRH & 0x01u) != 0x00u) /* CDCIE=0? */ 00246 { 00247 return; 00248 } 00249 00250 if((FM0P_QPRC1->QECR & 0x0004u) != 0x0000u) /* ORNGIE = 0? */ 00251 { 00252 return; 00253 } 00254 00255 if((FM0P_QPRC1->QICRL & 0x15u) != 0x00u) /* OUZIE=QPRCMIE=QPCMIE=0? */ 00256 { 00257 return; 00258 } 00259 00260 if((FM0P_QPRC1->QICRH & 0x01u) != 0x00u) /* CDCIE=0? */ 00261 { 00262 return; 00263 } 00264 00265 if((FM0P_QPRC2->QECR & 0x0004u) != 0x0000u) /* ORNGIE = 0? */ 00266 { 00267 return; 00268 } 00269 00270 if((FM0P_QPRC2->QICRL & 0x15u) != 0x00u) /* OUZIE=QPRCMIE=QPCMIE=0? */ 00271 { 00272 return; 00273 } 00274 00275 if((FM0P_QPRC2->QICRH & 0x01u) != 0x00u) /* CDCIE=0? */ 00276 { 00277 return; 00278 } 00279 00280 if((pDtReg->TIMERXCONTROL & 0x00000020u) != 0x00000000u) /* DT Int disable? */ 00281 { 00282 return; 00283 } 00284 00285 if(((pDtReg+1)->TIMERXCONTROL & 0x00000020u) != 0x00000000u) /* DT Int disable? */ 00286 { 00287 return; 00288 } 00289 00290 /* QPRC and DT interrupt are all disabled, disable this IRQ */ 00291 NVIC_ClearPendingIRQ(DTIM_QDU_IRQn); 00292 NVIC_DisableIRQ(DTIM_QDU_IRQn); 00293 NVIC_SetPriority(DTIM_QDU_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL); 00294 00295 } 00296 00297 return; 00298 } 00299 00308 void Qprc_IrqHandler ( volatile stc_qprcn_t *pstcQprc, 00309 stc_qprc_intern_data_t *pstcQprcInternData ) 00310 { 00311 if ((NULL == pstcQprc) || 00312 (NULL == pstcQprcInternData)) 00313 { 00314 return; 00315 } 00316 00317 if (PdlSet == pstcQprc->QICRL_f.QPCMF) // QPCCR match ? 00318 { 00319 pstcQprc->QICRL_f.QPCMF = PdlClr; // Clear interrupt 00320 if (NULL != pstcQprcInternData->pfnPcMatchCallback) 00321 { 00322 pstcQprcInternData->pfnPcMatchCallback(); 00323 } 00324 } 00325 00326 if (PdlSet == pstcQprc->QICRL_f.QPRCMF) // QPRCR match ? 00327 { 00328 pstcQprc->QICRL_f.QPRCMF = PdlClr; // Clear interrupt 00329 if (NULL != pstcQprcInternData->pfnPcRcMatchCallback) 00330 { 00331 pstcQprcInternData->pfnPcRcMatchCallback(); 00332 } 00333 } 00334 00335 if (PdlSet == pstcQprc->QICRL_f.OFDF) //Overflow Interrupe ? 00336 { 00337 pstcQprc->QICRL_f.OFDF = PdlClr; // Clear interrupt 00338 if (NULL != pstcQprcInternData->pfnPcUfOfZeroCallback) 00339 { 00340 pstcQprcInternData->pfnPcUfOfZeroCallback(QPRC_PC_OVERFLOW_INT); 00341 } 00342 } 00343 00344 if (PdlSet == pstcQprc->QICRL_f.UFDF) //Underflow Interrupe ? 00345 { 00346 pstcQprc->QICRL_f.UFDF = PdlClr; // Clear interrupt 00347 if (NULL != pstcQprcInternData->pfnPcUfOfZeroCallback) 00348 { 00349 pstcQprcInternData->pfnPcUfOfZeroCallback(QPRC_PC_UNDERFLOW_INT); 00350 } 00351 } 00352 00353 if (PdlSet == pstcQprc->QICRL_f.ZIIF) //Zero Interrupe ? 00354 { 00355 pstcQprc->QICRL_f.ZIIF = PdlClr; // Clear interrupt 00356 if (NULL != pstcQprcInternData->pfnPcUfOfZeroCallback) 00357 { 00358 pstcQprcInternData->pfnPcUfOfZeroCallback(QPRC_PC_ZERO_INDEX_INT); 00359 } 00360 } 00361 00362 if (PdlSet == pstcQprc->QICRH_f.CDCF) //PC invert match ? 00363 { 00364 pstcQprc->QICRH_f.CDCF = PdlClr; // Clear interrupt 00365 if (NULL != pstcQprcInternData->pfnPcCountInvertCallback) 00366 { 00367 pstcQprcInternData->pfnPcCountInvertCallback(); 00368 } 00369 } 00370 00371 if (PdlSet == pstcQprc->QECR_f.ORNGF) //RC outrange ? 00372 { 00373 pstcQprc->QECR_f.ORNGF = PdlClr; // Clear interrupt 00374 if (NULL != pstcQprcInternData->pfnRcOutrangeCallback) 00375 { 00376 pstcQprcInternData->pfnRcOutrangeCallback(); 00377 } 00378 } 00379 00380 if (PdlSet == pstcQprc->QICRH_f.QPCNRCMF) //PcMatch and RcMatch ? 00381 { 00382 pstcQprc->QICRH_f.QPCNRCMF = PdlClr; // Clear interrupt 00383 if (NULL != pstcQprcInternData->pfnPcMatchRcMatchCallback) 00384 { 00385 pstcQprcInternData->pfnPcMatchRcMatchCallback(); 00386 } 00387 } 00388 00389 return; 00390 } 00391 00392 #endif 00393 00410 en_result_t Qprc_Init( volatile stc_qprcn_t* pstcQprc, 00411 stc_qprc_config_t* pstcConfig ) 00412 { 00413 volatile stc_qprc_nfn_t *pstcQprcInternNfn; 00414 00415 if ( (Ok != QprcIsValidQprcnPtr(pstcQprc)) || 00416 (NULL == pstcConfig) 00417 ) 00418 { 00419 return ErrorInvalidParameter; 00420 } 00421 00422 if (((pstcConfig->bSwapAinBin != TRUE) && (pstcConfig->bSwapAinBin != FALSE))|| 00423 (pstcConfig->enComapreMode > QprcComapreWithRevolution) || 00424 (pstcConfig->enZinEdge > QprcZinHighLevel) || 00425 (pstcConfig->enBinEdge > QprcBinBothEdges) || 00426 (pstcConfig->enAinEdge > QprcAinBothEdges) || 00427 (pstcConfig->enPcResetMask > QprcResetMask8Times) || 00428 (pstcConfig->stcAinFilter.enWidth > QprcFilterWidth256Pclk) || 00429 (pstcConfig->stcBinFilter.enWidth > QprcFilterWidth256Pclk) || 00430 (pstcConfig->stcCinFilter.enWidth > QprcFilterWidth256Pclk) || 00431 ((pstcConfig->stcAinFilter.bInputMask != TRUE) && (pstcConfig->stcAinFilter.bInputMask != FALSE))|| 00432 ((pstcConfig->stcBinFilter.bInputMask != TRUE) && (pstcConfig->stcBinFilter.bInputMask != FALSE))|| 00433 ((pstcConfig->stcCinFilter.bInputMask != TRUE) && (pstcConfig->stcCinFilter.bInputMask != FALSE))|| 00434 ((pstcConfig->stcAinFilter.bInputInvert != TRUE) && (pstcConfig->stcAinFilter.bInputInvert != FALSE))|| 00435 ((pstcConfig->stcBinFilter.bInputInvert != TRUE) && (pstcConfig->stcBinFilter.bInputInvert != FALSE))|| 00436 ((pstcConfig->stcCinFilter.bInputInvert != TRUE) && (pstcConfig->stcCinFilter.bInputInvert != FALSE))) 00437 00438 { 00439 return ErrorInvalidParameter; 00440 } 00441 00442 pstcQprc->QCRL_f.SWAP = (TRUE == pstcConfig->bSwapAinBin) ? 1 : 0 ; 00443 pstcQprc->QCRL_f.RSEL = pstcConfig->enComapreMode; 00444 00445 switch (pstcConfig->enZinEdge) 00446 { 00447 case QprcZinDisable: // Disables edge and level detection 00448 { 00449 pstcQprc->QCRH_f.CGE = 0u; 00450 } 00451 break; 00452 00453 case QprcZinFallingEdge: // ZIN active at falling edge 00454 { 00455 pstcQprc->QCRL_f.CGSC = 0u; 00456 pstcQprc->QCRH_f.CGE = 1u; 00457 } 00458 break; 00459 00460 case QprcZinRisingEdge: // ZIN active at rising edge 00461 { 00462 pstcQprc->QCRL_f.CGSC = 0u; 00463 pstcQprc->QCRH_f.CGE = 2u; 00464 } 00465 break; 00466 00467 case QprcZinBothEdges: // ZIN active at falling or rising edge 00468 { 00469 pstcQprc->QCRL_f.CGSC = 0u; 00470 pstcQprc->QCRH_f.CGE = 3u; 00471 } 00472 break; 00473 00474 case QprcZinLowLevel: // ZIN active at low level detected 00475 { 00476 pstcQprc->QCRL_f.CGSC = 1u; 00477 pstcQprc->QCRH_f.CGE = 1u; 00478 } 00479 break; 00480 00481 case QprcZinHighLevel: // ZIN active at high level detected 00482 { 00483 pstcQprc->QCRL_f.CGSC = 1; 00484 pstcQprc->QCRH_f.CGE = 2u; 00485 } 00486 break; 00487 00488 default: 00489 break; 00490 } 00491 00492 switch (pstcConfig->enBinEdge) 00493 { 00494 case QprcBinDisable: // Disables edge detection 00495 { 00496 pstcQprc->QCRH_f.BES = 0u; 00497 } 00498 break; 00499 00500 case QprcBinFallingEdge: // BIN active at falling edge 00501 { 00502 pstcQprc->QCRH_f.BES = 1u; 00503 } 00504 break; 00505 00506 case QprcBinRisingEdge: // BIN active at rising edge 00507 { 00508 pstcQprc->QCRH_f.BES = 2u; 00509 } 00510 break; 00511 00512 case QprcBinBothEdges: // BIN active at falling or rising edge 00513 { 00514 pstcQprc->QCRH_f.BES = 3u; 00515 } 00516 break; 00517 00518 default: 00519 break; 00520 } 00521 00522 switch (pstcConfig->enAinEdge) 00523 { 00524 case QprcBinDisable: // Disables edge detection 00525 { 00526 pstcQprc->QCRH_f.AES = 0u; 00527 } 00528 break; 00529 00530 case QprcBinFallingEdge: // BIN active at falling edge 00531 { 00532 pstcQprc->QCRH_f.AES = 1u; 00533 } 00534 break; 00535 00536 case QprcBinRisingEdge: // BIN active at rising edge 00537 { 00538 pstcQprc->QCRH_f.AES = 2u; 00539 } 00540 break; 00541 00542 case QprcBinBothEdges: // BIN active at falling or rising edge 00543 { 00544 pstcQprc->QCRH_f.AES = 3u; 00545 } 00546 break; 00547 00548 default: 00549 break; 00550 } 00551 00552 switch (pstcConfig->enPcResetMask) 00553 { 00554 case QprcResetMaskDisable: // No reset mask 00555 { 00556 pstcQprc->QCRH_f.PCRM = 0u; 00557 } 00558 break; 00559 00560 case QprcResetMask2Times: 00561 { 00562 pstcQprc->QCRH_f.PCRM = 1u; 00563 } 00564 break; 00565 00566 case QprcResetMask4Times: 00567 { 00568 pstcQprc->QCRH_f.PCRM = 2u; 00569 } 00570 break; 00571 00572 case QprcResetMask8Times: 00573 { 00574 pstcQprc->QCRH_f.PCRM = 3u; 00575 } 00576 break; 00577 00578 default: 00579 break; 00580 } 00581 00582 pstcQprc->QECR_f.ORNGMD = (TRUE == pstcConfig->b8KValue) ? 1 : 0 ; // TRUE: Outrange mode from 0 to 0x7FFF, FALSE: Outrange mode from 0 to 0xFFFF: 00583 00584 /* Set QPRC Noise Filter */ 00585 pstcQprcInternNfn = QprcGetNoisFilterPtr(pstcQprc); 00586 00587 pstcQprcInternNfn->NFCTLA_f.AINMD = (TRUE == pstcConfig->stcAinFilter.bInputMask) ? 1 : 0 ; 00588 pstcQprcInternNfn->NFCTLA_f.AINLV = (TRUE == pstcConfig->stcAinFilter.bInputInvert) ? 1 : 0 ; 00589 pstcQprcInternNfn->NFCTLA_f.AINNWS = pstcConfig->stcAinFilter.enWidth; 00590 00591 pstcQprcInternNfn->NFCTLB_f.BINMD = (TRUE == pstcConfig->stcBinFilter.bInputMask) ? 1 : 0 ; 00592 pstcQprcInternNfn->NFCTLB_f.BINLV = (TRUE == pstcConfig->stcBinFilter.bInputInvert) ? 1 : 0 ; 00593 pstcQprcInternNfn->NFCTLB_f.BINNWS = pstcConfig->stcBinFilter.enWidth; 00594 00595 pstcQprcInternNfn->NFCTLZ_f.ZINMD = (TRUE == pstcConfig->stcCinFilter.bInputMask) ? 1 : 0 ; 00596 pstcQprcInternNfn->NFCTLZ_f.ZINLV = (TRUE == pstcConfig->stcCinFilter.bInputInvert) ? 1 : 0 ; 00597 pstcQprcInternNfn->NFCTLZ_f.ZINNWS = pstcConfig->stcCinFilter.enWidth; 00598 00599 return Ok; 00600 } 00601 00611 en_result_t Qprc_StopPcCount(volatile stc_qprcn_t *pstcQprc) 00612 { 00613 // Check for NULL pointer 00614 if (NULL == pstcQprc) 00615 { 00616 return ErrorInvalidParameter ; 00617 } 00618 00619 pstcQprc->QCRL_f.PSTP = 1; 00620 return Ok; 00621 } 00622 00632 en_result_t Qprc_RestartPcCount(volatile stc_qprcn_t *pstcQprc) 00633 { 00634 // Check for NULL pointer 00635 if (NULL == pstcQprc) 00636 { 00637 return ErrorInvalidParameter ; 00638 } 00639 00640 pstcQprc->QCRL_f.PSTP = 0; 00641 return Ok; 00642 } 00643 00654 en_result_t Qprc_SetPcCount ( volatile stc_qprcn_t *pstcQprc, 00655 uint16_t u16PcValue ) 00656 { 00657 if (NULL == pstcQprc) 00658 { 00659 return ErrorInvalidParameter; 00660 } 00661 00662 pstcQprc->QPCR = u16PcValue; 00663 return Ok; 00664 } 00665 00676 uint16_t Qprc_GetPcCount ( volatile stc_qprcn_t *pstcQprc ) 00677 { 00678 if (NULL == pstcQprc) 00679 { 00680 return 0xFFFFu; 00681 } 00682 00683 return (uint16_t)pstcQprc->QPCR; 00684 } 00685 00696 en_result_t Qprc_SetRcCount ( volatile stc_qprcn_t *pstcQprc, 00697 uint16_t u16RcValue ) 00698 { 00699 if (NULL == pstcQprc) 00700 { 00701 return ErrorInvalidParameter; 00702 } 00703 00704 pstcQprc->QRCR = u16RcValue; 00705 return Ok; 00706 } 00707 00708 00719 uint16_t Qprc_GetRcCount ( volatile stc_qprcn_t *pstcQprc ) 00720 { 00721 if (NULL == pstcQprc) 00722 { 00723 return 0xFFFFu; 00724 } 00725 00726 return (uint16_t)pstcQprc->QPCR; 00727 } 00728 00739 en_result_t Qprc_SetPcMaxValue( volatile stc_qprcn_t *pstcQprc, 00740 uint16_t u16PcMaxValue ) 00741 { 00742 if (NULL == pstcQprc) 00743 { 00744 return ErrorInvalidParameter; 00745 } 00746 00747 pstcQprc->QMPR = u16PcMaxValue; 00748 return Ok; 00749 } 00750 00761 uint16_t Qprc_GetPcMaxValue(volatile stc_qprcn_t *pstcQprc) 00762 { 00763 if (NULL == pstcQprc) 00764 { 00765 return 0xFFFFu; 00766 } 00767 00768 return (uint16_t)pstcQprc->QMPR; 00769 } 00770 00782 en_result_t Qprc_SetPcCompareValue( volatile stc_qprcn_t *pstcQprc, 00783 uint16_t u16PcValue ) 00784 { 00785 if (NULL == pstcQprc) 00786 { 00787 return ErrorInvalidParameter; 00788 } 00789 00790 pstcQprc->QPCCR = u16PcValue; 00791 00792 return Ok; 00793 } 00794 00804 uint16_t Qprc_GetPcCompareValue( volatile stc_qprcn_t *pstcQprc) 00805 { 00806 if (NULL == pstcQprc) 00807 { 00808 return ErrorInvalidParameter; 00809 } 00810 00811 return (uint16_t)pstcQprc->QPCCR; 00812 } 00813 00814 00829 en_result_t Qprc_SetPcRcCompareValue( volatile stc_qprcn_t *pstcQprc, 00830 uint16_t u16PcRcValue ) 00831 { 00832 if (NULL == pstcQprc) 00833 { 00834 return ErrorInvalidParameter; 00835 } 00836 00837 pstcQprc->QPRCR = u16PcRcValue; 00838 00839 return Ok; 00840 } 00841 00852 uint16_t Qprc_GetPcRcCompareValue(volatile stc_qprcn_t *pstcQprc) 00853 { 00854 if (NULL == pstcQprc) 00855 { 00856 return 0xFFFFu; 00857 } 00858 00859 return (uint16_t)pstcQprc->QPRCR; 00860 } 00861 00876 en_result_t Qprc_ConfigPcMode( volatile stc_qprcn_t *pstcQprc, 00877 en_qprc_pcmode_t enMode ) 00878 { 00879 if ((NULL == pstcQprc) || 00880 (enMode > QprcPcMode3)) 00881 { 00882 return ErrorInvalidParameter; 00883 } 00884 00885 switch(enMode) 00886 { 00887 case QprcPcMode0: //Disable position counter 00888 { 00889 pstcQprc->QCRL_f.PCM = 0u; 00890 } 00891 break; 00892 00893 case QprcPcMode1: //Increments with AIN active edge and decrements with BIN active edge 00894 { 00895 pstcQprc->QCRL_f.PCM = 1u; 00896 } 00897 break; 00898 00899 case QprcPcMode2: //Phase difference count mode: Counts up if AIN is leading BIN, down if BIN leading. 00900 { 00901 pstcQprc->QCRL_f.PCM = 2u; 00902 } 00903 break; 00904 00905 case QprcPcMode3: // Directional count mode: Counts up/down with BIN active edge and AIN level 00906 { 00907 pstcQprc->QCRL_f.PCM = 3u; 00908 } 00909 break; 00910 00911 default: 00912 return ErrorInvalidParameter; 00913 } 00914 00915 return Ok; 00916 } 00917 00931 en_result_t Qprc_ConfigRcMode( volatile stc_qprcn_t *pstcQprc, 00932 en_qprc_rcmode_t enMode ) 00933 { 00934 if ((NULL == pstcQprc) || 00935 (enMode > QprcRcMode3)) 00936 { 00937 return ErrorInvalidParameter; 00938 } 00939 00940 switch(enMode) 00941 { 00942 case QprcRcMode0: 00943 { 00944 pstcQprc->QCRL_f.RCM = 0u; 00945 } 00946 break; 00947 00948 case QprcRcMode1: //Up/down count of RC with ZIN active edge 00949 { 00950 pstcQprc->QCRL_f.RCM = 1u; 00951 } 00952 break; 00953 00954 case QprcRcMode2: //Up/down count of RC on over or underflow in position count match 00955 { 00956 pstcQprc->QCRL_f.RCM = 2u; 00957 } 00958 break; 00959 00960 case QprcRcMode3: //Up/down count of RC on over or underflow in position count match and ZIN active edge 00961 { 00962 pstcQprc->QCRL_f.RCM = 3u; 00963 } 00964 break; 00965 00966 default: 00967 return ErrorInvalidParameter; 00968 } 00969 00970 return Ok; 00971 } 00972 00973 #if (PDL_INTERRUPT_ENABLE_QPRC0 == PDL_ON) || \ 00974 (PDL_INTERRUPT_ENABLE_QPRC1 == PDL_ON) || \ 00975 (PDL_INTERRUPT_ENABLE_QPRC2 == PDL_ON) || \ 00976 (PDL_INTERRUPT_ENABLE_QPRC3 == PDL_ON) 00977 00990 en_result_t Qprc_EnableInt( volatile stc_qprcn_t* pstcQprc, stc_qprc_int_sel_t* pstcIntSel, 00991 stc_qprc_int_cb_t* pstcIntCallback ) 00992 { 00993 stc_qprc_intern_data_t *pstcQprcInternData = NULL; 00994 if ((NULL == pstcQprc) || 00995 (pstcIntSel->bQprcPcCountInvertInt > 1) || 00996 (pstcIntSel->bQprcPcMatchInt > 1) || 00997 (pstcIntSel->bQprcPcMatchRcMatchInt > 1) || 00998 (pstcIntSel->bQprcPcOfUfZeroInt > 1) || 00999 (pstcIntSel->bQprcPcRcMatchInt > 1) || 01000 (pstcIntSel->bQprcRcOutrangeInt > 1) || 01001 (NULL == pstcIntCallback) ) 01002 { 01003 return ErrorInvalidParameter; 01004 } 01005 01006 pstcQprcInternData = QprcGetInternDataPtr(pstcQprc); 01007 01008 if (NULL == pstcQprcInternData) 01009 { 01010 return ErrorInvalidParameter; 01011 } 01012 if (TRUE == pstcIntSel->bQprcPcMatchInt) 01013 { 01014 pstcQprcInternData->pfnPcMatchCallback = pstcIntCallback->pfnPcMatchIntCallback; 01015 pstcQprc->QICRL_f.QPCMIE = 1; 01016 } 01017 if (TRUE == pstcIntSel->bQprcPcRcMatchInt) 01018 { 01019 pstcQprcInternData->pfnPcRcMatchCallback = pstcIntCallback->pfnPcRcMatchIntCallback; 01020 pstcQprc->QICRL_f.QPRCMIE = 1; 01021 } 01022 if (TRUE == pstcIntSel->bQprcPcMatchRcMatchInt) 01023 { 01024 pstcQprcInternData->pfnPcMatchRcMatchCallback = pstcIntCallback->pfnPcMatchRcMatchIntCallback; 01025 pstcQprc->QICRH_f.QPCNRCMIE = 1; 01026 } 01027 if (TRUE == pstcIntSel->bQprcPcOfUfZeroInt) 01028 { 01029 pstcQprcInternData->pfnPcUfOfZeroCallback = pstcIntCallback->pfnPcOfUfZeroIntCallback; 01030 pstcQprc->QICRL_f.OUZIE = 1; 01031 } 01032 if (TRUE == pstcIntSel->bQprcPcCountInvertInt) 01033 { 01034 pstcQprcInternData->pfnPcCountInvertCallback = pstcIntCallback->pfnPcCountInvertIntCallback; 01035 pstcQprc->QICRH_f.CDCIE = 1; 01036 } 01037 if (TRUE == pstcIntSel->bQprcRcOutrangeInt) 01038 { 01039 pstcQprcInternData->pfnRcOutrangeCallback = pstcIntCallback->pfnRcOutrangeIntCallback; 01040 pstcQprc->QECR_f.ORNGIE = 1; 01041 } 01042 01043 Qprc_InitNvic(pstcQprc); 01044 01045 return Ok; 01046 } 01047 01060 en_result_t Qprc_DisableInt( volatile stc_qprcn_t* pstcQprc, stc_qprc_int_sel_t* pstcIntSel ) 01061 { 01062 stc_qprc_intern_data_t *pstcQprcInternData = NULL; 01063 if((NULL == pstcQprc) || 01064 (pstcIntSel->bQprcPcCountInvertInt > 1) || 01065 (pstcIntSel->bQprcPcMatchInt > 1) || 01066 (pstcIntSel->bQprcPcMatchRcMatchInt > 1) || 01067 (pstcIntSel->bQprcPcOfUfZeroInt > 1) || 01068 (pstcIntSel->bQprcPcRcMatchInt > 1) || 01069 (pstcIntSel->bQprcRcOutrangeInt > 1)) 01070 { 01071 return ErrorInvalidParameter; 01072 } 01073 01074 pstcQprcInternData = QprcGetInternDataPtr(pstcQprc); 01075 01076 if (NULL == pstcQprcInternData) 01077 { 01078 return ErrorInvalidParameter; 01079 } 01080 if (TRUE == pstcIntSel->bQprcPcMatchInt) 01081 { 01082 pstcQprcInternData->pfnPcMatchCallback = NULL; 01083 pstcQprc->QICRL_f.QPCMIE = 0; 01084 } 01085 if (TRUE == pstcIntSel->bQprcPcRcMatchInt) 01086 { 01087 pstcQprcInternData->pfnPcRcMatchCallback = NULL; 01088 pstcQprc->QICRL_f.QPRCMIE = 0; 01089 } 01090 if (TRUE == pstcIntSel->bQprcPcMatchRcMatchInt) 01091 { 01092 pstcQprcInternData->pfnPcMatchRcMatchCallback = NULL; 01093 pstcQprc->QICRH_f.QPCNRCMIE = 0; 01094 } 01095 if (TRUE == pstcIntSel->bQprcPcOfUfZeroInt) 01096 { 01097 pstcQprcInternData->pfnPcUfOfZeroCallback = NULL; 01098 pstcQprc->QICRL_f.OUZIE = 0; 01099 } 01100 if (TRUE == pstcIntSel->bQprcPcCountInvertInt) 01101 { 01102 pstcQprcInternData->pfnPcCountInvertCallback = NULL; 01103 pstcQprc->QICRH_f.CDCIE = 0; 01104 } 01105 if (TRUE == pstcIntSel->bQprcRcOutrangeInt) 01106 { 01107 pstcQprcInternData->pfnRcOutrangeCallback = NULL; 01108 pstcQprc->QECR_f.ORNGIE = 0; 01109 } 01110 01111 Qprc_DeInitNvic(pstcQprc); 01112 01113 return Ok; 01114 } 01115 01116 #endif 01117 01128 en_int_flag_t Qprc_GetIntFlag( volatile stc_qprcn_t *pstcQprc, 01129 en_qprc_int_t enIntType) 01130 { 01131 en_int_flag_t enIntFlag = PdlClr; 01132 01133 if ((NULL == pstcQprc) || 01134 (enIntType > QprcRcOutrangeInt)) 01135 { 01136 return PdlClr; 01137 } 01138 01139 switch(enIntType) 01140 { 01141 case QprcPcOfUfZeroInt: 01142 if(PdlSet == pstcQprc->QICRL_f.ZIIF) 01143 { 01144 enIntFlag = PdlSet; 01145 break; 01146 } 01147 01148 if(PdlSet == pstcQprc->QICRL_f.OFDF) 01149 { 01150 enIntFlag = PdlSet; 01151 break; 01152 } 01153 01154 if(PdlSet == pstcQprc->QICRL_f.UFDF) 01155 { 01156 enIntFlag = PdlSet; 01157 break; 01158 } 01159 break; 01160 01161 case QprcPcMatchInt: 01162 enIntFlag = (1 == pstcQprc->QICRL_f.QPCMF) ? PdlSet : PdlClr ; 01163 break; 01164 01165 case QprcPcRcMatchInt: 01166 enIntFlag = (1 == pstcQprc->QICRL_f.QPRCMF) ? PdlSet : PdlClr ; 01167 break; 01168 01169 case QprcPcMatchRcMatchInt: 01170 enIntFlag = (1 == pstcQprc->QICRH_f.QPCNRCMF) ? PdlSet : PdlClr ; 01171 break; 01172 01173 case QprcPcCountInvertInt: 01174 enIntFlag = (1 == pstcQprc->QICRH_f.CDCF) ? PdlSet : PdlClr ; 01175 break; 01176 01177 case QprcRcOutrangeInt: 01178 enIntFlag = (1 == pstcQprc->QECR_f.ORNGF) ? PdlSet : PdlClr ; 01179 break; 01180 01181 default: 01182 break; 01183 } 01184 01185 return enIntFlag; 01186 } 01187 01188 01202 en_result_t Qprc_ClrIntFlag( volatile stc_qprcn_t *pstcQprc, 01203 en_qprc_int_t enIntType) 01204 { 01205 if ((NULL == pstcQprc) || 01206 (enIntType > QprcRcOutrangeInt)) 01207 { 01208 return ErrorInvalidParameter; 01209 } 01210 01211 switch(enIntType) 01212 { 01213 case QprcPcOfUfZeroInt: 01214 { 01215 pstcQprc->QICRL_f.ZIIF = PdlClr; 01216 pstcQprc->QICRL_f.OFDF = PdlClr; 01217 pstcQprc->QICRL_f.UFDF = PdlClr; 01218 } 01219 break; 01220 01221 case QprcPcMatchInt: 01222 { 01223 pstcQprc->QICRL_f.QPCMF = PdlClr; 01224 } 01225 break; 01226 01227 case QprcPcRcMatchInt: 01228 { 01229 pstcQprc->QICRL_f.QPRCMF = PdlClr; 01230 } 01231 break; 01232 01233 case QprcPcMatchRcMatchInt: 01234 { 01235 pstcQprc->QICRH_f.QPCNRCMF = PdlClr; 01236 } 01237 break; 01238 01239 case QprcPcCountInvertInt: 01240 { 01241 pstcQprc->QICRH_f.CDCF = PdlClr; 01242 } 01243 break; 01244 01245 case QprcRcOutrangeInt: 01246 { 01247 pstcQprc->QECR_f.ORNGF = PdlClr; 01248 } 01249 break; 01250 01251 default: 01252 break; 01253 } 01254 01255 return Ok; 01256 01257 } 01258 01268 en_stat_flag_t Qprc_GetPcOfUfDir( volatile stc_qprcn_t *pstcQprc ) 01269 { 01270 en_stat_flag_t enStatFlag = PdlClr; 01271 01272 if (NULL == pstcQprc) 01273 { 01274 return PdlClr; 01275 } 01276 01277 enStatFlag = (1 == pstcQprc->QICRH_f.DIROU) ? PdlSet : PdlClr ; 01278 return enStatFlag; 01279 } 01280 01290 en_stat_flag_t Qprc_GetPcDir( volatile stc_qprcn_t *pstcQprc ) 01291 { 01292 en_stat_flag_t enStatFlag = PdlClr; 01293 01294 if (NULL == pstcQprc) 01295 { 01296 return PdlClr; 01297 } 01298 01299 enStatFlag = (1 == pstcQprc->QICRH_f.DIRPC) ? PdlSet : PdlClr ; 01300 01301 return enStatFlag; 01302 } 01303 01304 01305 01307 01308 01309 #endif // #if (defined(PDL_PERIPHERAL_QPRC_ACTIVE)) 01310 01311 /******************************************************************************/ 01312 /* EOF (not truncated) */ 01313 /******************************************************************************/