![]() |
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 "mft_adcmp.h" 00056 00057 #if (defined(PDL_PERIPHERAL_MFT_ADCMP_ACTIVE)) 00058 00063 /******************************************************************************/ 00064 /* Global variable definitions (declared in header file with 'extern') */ 00065 /******************************************************************************/ 00066 00067 /******************************************************************************/ 00068 /* Local type definitions ('typedef') */ 00069 /******************************************************************************/ 00070 00071 /******************************************************************************/ 00072 /* Local function prototypes ('static') */ 00073 /******************************************************************************/ 00074 00075 /******************************************************************************/ 00076 /* Local variable definitions ('static') */ 00077 /******************************************************************************/ 00078 00079 /******************************************************************************/ 00080 /* Function implementation - global ('extern') and local ('static') */ 00081 /******************************************************************************/ 00082 00104 en_result_t Mft_Adcmp_Init(volatile stc_mftn_adcmp_t* pstcMftAdcmp, 00105 uint8_t u8Ch, 00106 stc_mft_adcmp_config_t* pstcConfig) 00107 { 00108 volatile stc_mft_adcmp_acfs10_field_t* pu8ACFS10 ; 00109 volatile stc_mft_adcmp_acfs32_field_t* pu8ACFS32 ; 00110 volatile stc_mft_adcmp_acfs54_field_t* pu8ACFS54 ; 00111 00112 volatile stc_mft_adcmp_acsc0_field_t* pu8ACSCx ; 00113 volatile stc_mft_adcmp_acsd0_field_t* pstcACSDx ; 00114 00115 if ((pstcMftAdcmp == NULL)||(pstcConfig == NULL)||(u8Ch > MFT_ADCMP_CH_MAX)) 00116 { 00117 return ErrorInvalidParameter ; 00118 } 00119 00120 // Get actual address of register list of current channel 00121 pu8ACFS10 = (volatile stc_mft_adcmp_acfs10_field_t*)(&pstcMftAdcmp->ACFS10); 00122 pu8ACFS32 = (volatile stc_mft_adcmp_acfs32_field_t*)(&pstcMftAdcmp->ACFS32); 00123 pu8ACFS54 = (volatile stc_mft_adcmp_acfs54_field_t*)(&pstcMftAdcmp->ACFS54); 00124 00125 pu8ACSCx = (volatile stc_mft_adcmp_acsc0_field_t*)(&pstcMftAdcmp->ACSC0 + 0x4*u8Ch); 00126 pstcACSDx = (volatile stc_mft_adcmp_acsd0_field_t*)(&pstcMftAdcmp->ACSD0 + 0x4*u8Ch); 00127 00128 // Configure parameter 00129 pstcACSDx->DE = 0u; 00130 pstcACSDx->PE = 0u; 00131 pstcACSDx->UE = 0u; 00132 pstcACSDx->ZE = 0u; 00133 00134 pstcMftAdcmp->ACSA &= 0x0000u; 00135 00136 // Select FRT channel : FRTx -> ADCMPx 00137 switch(u8Ch) 00138 { 00139 case 0: 00140 pu8ACFS10->FSA0 = (uint8_t)pstcConfig->enFrt; 00141 break; 00142 case 1: 00143 pu8ACFS10->FSA1 = (uint8_t)pstcConfig->enFrt; 00144 break; 00145 case 2: 00146 pu8ACFS32->FSA0 = (uint8_t)pstcConfig->enFrt; 00147 break; 00148 case 3: 00149 pu8ACFS32->FSA1 = (uint8_t)pstcConfig->enFrt; 00150 break; 00151 case 4: 00152 pu8ACFS54->FSA0 = (uint8_t)pstcConfig->enFrt; 00153 break; 00154 case 5: 00155 pu8ACFS54->FSA1 = (uint8_t)pstcConfig->enFrt; 00156 break; 00157 default: 00158 return ErrorInvalidParameter; 00159 } 00160 00161 // configure buffer function 00162 if(pstcConfig->enBuf > AdcmpBufFrtZeroPeak) 00163 { 00164 return ErrorInvalidParameter; 00165 } 00166 00167 pu8ACSCx->BUFE = (uint8_t)pstcConfig->enBuf; 00168 00169 // configure start trigger output channel number 00170 if(pstcConfig->enTrigSel > AdcmpTrigAdc2Prio) 00171 { 00172 return ErrorInvalidParameter; 00173 } 00174 00175 pu8ACSCx->ADSEL = (uint8_t)pstcConfig->enTrigSel; 00176 00177 // Select ADCMP running mode 00178 if(pstcConfig->enMode > AdcmpOffsetMode) 00179 { 00180 return ErrorInvalidParameter; 00181 } 00182 pstcACSDx->AMOD = (uint8_t)pstcConfig->enMode; 00183 00184 // select OCU OCCP register: OCCP(x) 00185 if(pstcConfig->enOccpSel > AdcmpSelOccp1) 00186 { 00187 return ErrorInvalidParameter; 00188 } 00189 pstcACSDx->OCUS = (uint8_t)pstcConfig->enOccpSel; 00190 00191 return Ok; 00192 } 00213 en_result_t Mft_Adcmp_EnableOperation(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00214 uint8_t u8Ch, 00215 stc_mft_adcmp_func_t* pstcFunc) 00216 { 00217 volatile stc_mft_adcmp_acsd0_field_t* pstcACSDx ; 00218 00219 // Check for NULL pointer and channel parameter 00220 if ((pstcMftAdcmp == NULL)||(pstcFunc == NULL)||(u8Ch > MFT_ADCMP_CH_MAX)) 00221 { 00222 return ErrorInvalidParameter ; 00223 } 00224 // Get actual address of register list of current channel 00225 pstcACSDx = (volatile stc_mft_adcmp_acsd0_field_t*)(&pstcMftAdcmp->ACSD0 + 0x4*u8Ch); 00226 00227 pstcACSDx->PE = pstcFunc->bPeakEn; 00228 pstcACSDx->ZE = pstcFunc->bZeroEn; 00229 pstcACSDx->UE = pstcFunc->bUpEn; 00230 pstcACSDx->DE = pstcFunc->bDownEn; 00231 00232 return Ok; 00233 } 00253 en_result_t Mft_Adcmp_DisableOperation(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00254 uint8_t u8Ch, 00255 stc_mft_adcmp_func_t* pstcFunc) 00256 { 00257 volatile stc_mft_adcmp_acsd0_field_t* pstcACSDx; 00258 00259 // Check for NULL pointer and channel parameter 00260 if ((pstcMftAdcmp == NULL)||(pstcFunc == NULL)||(u8Ch > MFT_ADCMP_CH_MAX)) 00261 { 00262 return ErrorInvalidParameter ; 00263 } 00264 // Get actual address of register list of current channel 00265 pstcACSDx = (volatile stc_mft_adcmp_acsd0_field_t*)(&pstcMftAdcmp->ACSD0 + 0x4*u8Ch); 00266 00267 pstcACSDx->PE = pstcFunc->bPeakEn; 00268 pstcACSDx->ZE = pstcFunc->bZeroEn; 00269 pstcACSDx->UE = pstcFunc->bUpEn; 00270 pstcACSDx->DE = pstcFunc->bDownEn; 00271 00272 return Ok; 00273 } 00293 en_result_t Mft_Adcmp_WriteAcmp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8Ch, 00294 uint16_t u16AdcmpVal) 00295 { 00296 volatile uint16_t* pu16AdcmpAcpmReg; 00297 00298 // Check for NULL pointer and channel parameter 00299 if ((pstcMftAdcmp == NULL)||(u8Ch > MFT_ADCMP_CH_MAX)) 00300 { 00301 return ErrorInvalidParameter ; 00302 } 00303 pu16AdcmpAcpmReg = (volatile uint16_t*)(&pstcMftAdcmp->ACMP0 + 0x4*u8Ch); 00304 *pu16AdcmpAcpmReg = u16AdcmpVal; 00305 00306 return Ok; 00307 } 00324 uint16_t Mft_Adcmp_ReadAcmp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, uint8_t u8Ch) 00325 { 00326 volatile uint16_t* pu16AdcmpAcpmReg ; 00327 uint16_t u16Data; 00328 00329 // Check for NULL pointer and channel parameter 00330 if ((pstcMftAdcmp == NULL)||(u8Ch > MFT_ADCMP_CH_MAX)) 00331 { 00332 return ErrorInvalidParameter ; 00333 } 00334 pu16AdcmpAcpmReg = (volatile uint16_t*)(&pstcMftAdcmp->ACMP0 + 0x4*u8Ch); 00335 u16Data = *pu16AdcmpAcpmReg; 00336 00337 // return data value of ACMP register 00338 return u16Data; 00339 } 00340 00355 en_result_t Mft_Adcmp_Fm3_Init(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00356 uint8_t u8CoupleCh, 00357 stc_mft_adcmp_fm3_config_t *pstcConfig) 00358 { 00359 volatile stc_mft_adcmp_acsa_field_t* pu16ACSA ; 00360 volatile stc_mft_adcmp_acsc0_field_t* pu16ACSC ; 00361 volatile stc_mft_adcmp_acfs10_field_t* pu8ACFS10 ; 00362 volatile stc_mft_adcmp_acfs32_field_t* pu8ACFS32 ; 00363 volatile stc_mft_adcmp_acfs54_field_t* pu8ACFS54 ; 00364 00365 // Get actual address of register list of current channel 00366 pu16ACSA = (volatile stc_mft_adcmp_acsa_field_t*)(&pstcMftAdcmp->ACSA); 00367 pu16ACSC = (volatile stc_mft_adcmp_acsc0_field_t*)(&pstcMftAdcmp->ACSC0 + 0x4*u8CoupleCh); 00368 pu8ACFS10 = (volatile stc_mft_adcmp_acfs10_field_t*)(&pstcMftAdcmp->ACFS10); 00369 pu8ACFS32 = (volatile stc_mft_adcmp_acfs32_field_t*)(&pstcMftAdcmp->ACFS32); 00370 pu8ACFS54 = (volatile stc_mft_adcmp_acfs54_field_t*)(&pstcMftAdcmp->ACFS54); 00371 00372 switch(u8CoupleCh) 00373 { 00374 case MFT_ADCMP_CH10: 00375 pu8ACFS10->FSA0 = (uint8_t)pstcConfig->enFrt; 00376 pu8ACFS10->FSA1 = (uint8_t)pstcConfig->enFrt; 00377 break; 00378 case MFT_ADCMP_CH32: 00379 pu8ACFS32->FSA0 = (uint8_t)pstcConfig->enFrt; 00380 pu8ACFS32->FSA1 = (uint8_t)pstcConfig->enFrt; 00381 break; 00382 case MFT_ADCMP_CH54: 00383 pu8ACFS54->FSA0 = (uint8_t)pstcConfig->enFrt; 00384 pu8ACFS54->FSA1 = (uint8_t)pstcConfig->enFrt; 00385 break; 00386 default: 00387 return ErrorInvalidParameter; 00388 } 00389 00390 // configure buffer transfer type 00391 if(pstcConfig->enBuf > AdcmpBufFrtZeroPeak) 00392 { 00393 return ErrorInvalidParameter; 00394 } 00395 00396 pu16ACSC->BUFE = (uint8_t)pstcConfig->enBuf; 00397 00398 // configure start trigger output channel number 00399 if(pstcConfig->enTrigSel > AdcmpTrigAdc2Prio) 00400 { 00401 return ErrorInvalidParameter; 00402 } 00403 00404 pu16ACSC->ADSEL = (uint8_t)pstcConfig->enTrigSel; 00405 00406 // configure Adcmp Fm3 trig mode 00407 switch(u8CoupleCh) 00408 { 00409 case MFT_ADCMP_CH10: 00410 pu16ACSA->CE10 = 0; 00411 pu16ACSA->SEL10 = (uint8_t)pstcConfig->enMode; 00412 break; 00413 case MFT_ADCMP_CH32: 00414 pu16ACSA->CE32 = 0; 00415 pu16ACSA->SEL32 = (uint8_t)pstcConfig->enMode; 00416 break; 00417 case MFT_ADCMP_CH54: 00418 pu16ACSA->CE54 = 0; 00419 pu16ACSA->SEL54 = (uint8_t)pstcConfig->enMode; 00420 break; 00421 default: 00422 return ErrorInvalidParameter; 00423 } 00424 return Ok; 00425 } 00440 en_result_t 00441 Mft_Adcmp_Fm3_EnableOperation(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00442 uint8_t u8CoupleCh) 00443 { 00444 volatile stc_mft_adcmp_acsa_field_t* pu16ACSA ; 00445 00446 // Check for NULL pointer and channel parameter 00447 if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX)) 00448 { 00449 return ErrorInvalidParameter ; 00450 } 00451 // Get actual address of register list of current channel 00452 pu16ACSA = (volatile stc_mft_adcmp_acsa_field_t*)(&pstcMftAdcmp->ACSA); 00453 switch(u8CoupleCh) 00454 { 00455 case MFT_ADCMP_CH10: 00456 pu16ACSA->CE10 = 1; 00457 break; 00458 case MFT_ADCMP_CH32: 00459 pu16ACSA->CE32 = 1; 00460 break; 00461 case MFT_ADCMP_CH54: 00462 pu16ACSA->CE54 = 1; 00463 break; 00464 default: 00465 return ErrorInvalidParameter; 00466 } 00467 return Ok; 00468 } 00485 en_result_t 00486 Mft_Adcmp_Fm3_DisableOperation(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00487 uint8_t u8CoupleCh) 00488 { 00489 volatile stc_mft_adcmp_acsa_field_t* pu16ACSA; 00490 00491 // Check for NULL pointer and channel parameter 00492 if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX)) 00493 { 00494 return ErrorInvalidParameter ; 00495 } 00496 // Get actual address of register list of current channel 00497 pu16ACSA = (volatile stc_mft_adcmp_acsa_field_t*)(&pstcMftAdcmp->ACSA); 00498 switch(u8CoupleCh) 00499 { 00500 case MFT_ADCMP_CH10: 00501 pu16ACSA->CE10 = 0; 00502 break; 00503 case MFT_ADCMP_CH32: 00504 pu16ACSA->CE32 = 0; 00505 break; 00506 case MFT_ADCMP_CH54: 00507 pu16ACSA->CE54 = 0; 00508 break; 00509 default: 00510 return ErrorInvalidParameter; 00511 } 00512 return Ok; 00513 } 00530 en_result_t Mft_Adcmp_Fm3_WriteAccp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00531 uint8_t u8CoupleCh, uint16_t u16AccpVal) 00532 { 00533 volatile uint16_t* u16AdcmpAcpmReg; 00534 00535 // Check for NULL pointer and channel parameter 00536 if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX)) 00537 { 00538 return ErrorInvalidParameter ; 00539 } 00540 u16AdcmpAcpmReg = (volatile uint16_t*)(&pstcMftAdcmp->ACMP0 + 0x4*u8CoupleCh); 00541 *u16AdcmpAcpmReg = u16AccpVal; 00542 00543 return Ok; 00544 } 00558 uint16_t Mft_Adcmp_Fm3_ReadAccp(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00559 uint8_t u8CoupleCh) 00560 { 00561 volatile uint16_t* pu16AdcmpAcpmReg; 00562 uint16_t u16Data; 00563 00564 // Check for NULL pointer and channel parameter 00565 if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX)) 00566 { 00567 return ErrorInvalidParameter ; 00568 } 00569 pu16AdcmpAcpmReg = (volatile uint16_t*)(&pstcMftAdcmp->ACMP0 + 0x4*u8CoupleCh); 00570 u16Data = *pu16AdcmpAcpmReg; 00571 // return data value of ACMP register 00572 return u16Data; 00573 } 00591 en_result_t Mft_Adcmp_Fm3_WriteAccpdn(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00592 uint8_t u8CoupleCh, 00593 uint16_t u16AccpdnVal) 00594 { 00595 volatile uint16_t* pu16AdcmpAcpmReg; 00596 00597 // Check for NULL pointer and channel parameter 00598 if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX)) 00599 { 00600 return ErrorInvalidParameter ; 00601 } 00602 pu16AdcmpAcpmReg = (volatile uint16_t*)(&pstcMftAdcmp->ACMP1 + 0x4*u8CoupleCh); 00603 *pu16AdcmpAcpmReg = u16AccpdnVal; 00604 00605 return Ok; 00606 } 00620 uint16_t Mft_Adcmp_Fm3_ReadAccpdn(volatile stc_mftn_adcmp_t *pstcMftAdcmp, 00621 uint8_t u8CoupleCh) 00622 { 00623 volatile uint16_t* pu16AdcmpAcpmReg; 00624 uint16_t u16Data; 00625 00626 // Check for NULL pointer and channel parameter 00627 if ((pstcMftAdcmp == NULL)||(u8CoupleCh > MFT_ADCMP_CPCH_MAX)) 00628 { 00629 return ErrorInvalidParameter ; 00630 } 00631 pu16AdcmpAcpmReg = ((volatile uint16_t*)&pstcMftAdcmp->ACMP1 + 0x4*u8CoupleCh); 00632 u16Data = *pu16AdcmpAcpmReg; 00633 00634 // return data value of ACMP register 00635 return u16Data; 00636 } 00637 00638 #endif 00639 00640