PDL for FM0+  Version1.0
Peripheral Driverl Library for FM0+
C:/pdl_v10/library/driver/mft/mft_ocu.c
Go to the documentation of this file.
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 /******************************************************************************/
00054 /******************************************************************************/
00055 /* Include files                                                              */
00056 /******************************************************************************/
00057 #include "mft_ocu.h"
00058 
00059 #if (defined(PDL_PERIPHERAL_MFT_OCU_ACTIVE))
00060 
00066 
00067 /******************************************************************************/
00068 /* Local pre-processor symbols/macros ('#define')                             */
00069 /******************************************************************************/
00070 /******************************************************************************/
00071 /* Global variable definitions (declared in header file with 'extern')        */
00072 /******************************************************************************/
00074 stc_mft_ocu_instance_data_t m_astcMftOcuInstanceDataLut[OCU_INSTANCE_COUNT] =
00075 {
00076 #if (PDL_PERIPHERAL_ENABLE_MFT0_OCU == PDL_ON)
00077     {
00078         &MFT0_OCU,  // pstcInstance
00079         {NULL, NULL, NULL, NULL, NULL, NULL}    // stcInternData (not initialized yet)
00080     },
00081 #endif
00082 #if (PDL_PERIPHERAL_ENABLE_MFT1_OCU == PDL_ON)
00083     {
00084         &MFT1_OCU,  // pstcInstance
00085         {NULL, NULL, NULL, NULL, NULL, NULL}    // stcInternData (not initialized yet)
00086     },
00087 #endif
00088 #if (PDL_PERIPHERAL_ENABLE_MFT2_OCU == PDL_ON)
00089     {
00090         &MFT2_OCU,  // pstcInstance
00091         {NULL, NULL, NULL, NULL, NULL, NULL}    // stcInternData (not initialized yet)
00092     },
00093 #endif 
00094 };
00095 
00096 /******************************************************************************/
00097 /* Local type definitions ('typedef')                                         */
00098 /******************************************************************************/
00099 
00100 /******************************************************************************/
00101 /* Local function prototypes ('static')                                       */
00102 /******************************************************************************/
00103 
00104 /******************************************************************************/
00105 /* Local variable definitions ('static')                                      */
00106 /******************************************************************************/
00107 
00108 /******************************************************************************/
00109 /* Function implementation - global ('extern') and local ('static')           */
00110 /******************************************************************************/
00121 static stc_mft_ocu_intern_data_t* MftGetInternDataPtr(volatile stc_mftn_ocu_t* pstcOcu)
00122 {
00123     uint32_t u32Instance;
00124 
00125     for (u32Instance = 0; u32Instance < OCU_INSTANCE_COUNT; u32Instance++)
00126     {
00127         if (pstcOcu == m_astcMftOcuInstanceDataLut[u32Instance].pstcInstance)
00128         {
00129             return &m_astcMftOcuInstanceDataLut[u32Instance].stcInternData;
00130         }
00131     }
00132 
00133     return NULL;
00134 }
00135 
00136 #if (PDL_INTERRUPT_ENABLE_MFT0_OCU == PDL_ON) || \
00137     (PDL_INTERRUPT_ENABLE_MFT1_OCU == PDL_ON) || \
00138     (PDL_INTERRUPT_ENABLE_MFT2_OCU == PDL_ON)  
00139 
00147 void Mft_Ocu_IrqHandler( volatile stc_mftn_ocu_t* pstcOcu,
00148                          stc_mft_ocu_intern_data_t* pstcMftOcuInternData)
00149 {
00150     func_ptr_t funCallBack;
00151     uint32_t* ptemp;
00152     uint8_t Ch;
00153 
00154     //lookup the handler
00155     for(Ch=0;Ch<MFT_OCU_MAXCH;Ch++)
00156     {
00157         if(PdlSet == Mft_Ocu_GetIntFlag(pstcOcu,Ch))
00158         {
00159             //clear the interrupt flag
00160             Mft_Ocu_ClrIntFlag(pstcOcu,Ch);
00161 
00162             //pointer callback function address
00163             ptemp = (uint32_t*)&(pstcMftOcuInternData->pfnOcu0Callback);
00164             funCallBack = (func_ptr_t)(*(ptemp + Ch));
00165             
00166             if(funCallBack != NULL)
00167             {
00168                funCallBack();
00169             }
00170         }
00171     }    
00172 }
00173 
00184 static void Mft_Ocu_InitIrq( volatile stc_mftn_ocu_t* pstcOcu )
00185 {
00186     if ((pstcOcu == (volatile stc_mftn_ocu_t*)(&MFT0_OCU)) ||
00187         (pstcOcu == (volatile stc_mftn_ocu_t*)(&MFT1_OCU)) ||
00188         (pstcOcu == (volatile stc_mftn_ocu_t*)(&MFT2_OCU)))  
00189     {
00190         NVIC_ClearPendingIRQ(OUTCOMP_IRQn);
00191         NVIC_EnableIRQ(OUTCOMP_IRQn);
00192         NVIC_SetPriority(OUTCOMP_IRQn, PDL_IRQ_LEVEL_MFT_OCU);
00193     }
00194 
00195     return ;
00196 }
00197 
00207 static void Mft_Ocu_DeInitIrq( volatile stc_mftn_ocu_t* pstcOcu )
00208 {
00209     if ((pstcOcu == (volatile stc_mftn_ocu_t*)(&MFT0_OCU)) ||
00210         (pstcOcu == (volatile stc_mftn_ocu_t*)(&MFT1_OCU)) ||
00211         (pstcOcu == (volatile stc_mftn_ocu_t*)(&MFT2_OCU)))
00212     {
00213         if(pstcOcu->OCSA10_f.IOE0 == 1)
00214         {
00215             return;
00216         }
00217         if(pstcOcu->OCSA10_f.IOE1 == 1)
00218         {
00219             return;
00220         }
00221         if(pstcOcu->OCSA32_f.IOE0 == 1)
00222         {
00223             return;
00224         }
00225         if(pstcOcu->OCSA32_f.IOE1 == 1)
00226         {
00227             return;
00228         }
00229         if(pstcOcu->OCSA54_f.IOE0 == 1)
00230         {
00231             return;
00232         }
00233         if(pstcOcu->OCSA54_f.IOE1 == 1)
00234         {
00235             return;
00236         }
00237         
00238         NVIC_ClearPendingIRQ(OUTCOMP_IRQn);
00239         NVIC_DisableIRQ(OUTCOMP_IRQn);
00240         NVIC_SetPriority(OUTCOMP_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
00241     }
00242   
00243     return;
00244 }
00245 
00246 #endif
00247 
00248 /******************************************************************************/
00249 /* Local Functions                                                            */
00250 /******************************************************************************/
00251 
00270 en_result_t Mft_Ocu_Init( volatile stc_mftn_ocu_t* pstcOcu, 
00271                           uint8_t u8Ch, stc_mft_ocu_config_t*  pstcOcuConfig)
00272 {
00273     stc_mft_ocu_intern_data_t* pstcOcuInternData;
00274     volatile uint8_t* pu8OCFS;
00275     volatile stc_mft_ocu_ocsb10_field_t* pstcOCSB;
00276     volatile uint8_t* p8OCSC;
00277     volatile uint8_t* pu8OCSD;
00278 
00279     // Check for NULL pointer and configuration parameter
00280     if ( (pstcOcu == NULL) || 
00281          (u8Ch >= MFT_OCU_MAXCH) ||
00282          (pstcOcuConfig->enFrtConnect > OcuFrtToExt) ||
00283          (pstcOcuConfig->bFm4 > 1) ||
00284          (pstcOcuConfig->bCmod > 1) || 
00285          (pstcOcuConfig->enOccpBufMode > OccpBufTrsfByFrtZeroPeak ) || 
00286          (pstcOcuConfig->enOcseBufMode > OcseBufTrsfByFrtZeroPeak ) )
00287     {
00288         return ErrorInvalidParameter ;
00289     }
00290     // Get pointer to internal data structure ...
00291     pstcOcuInternData = MftGetInternDataPtr( pstcOcu ) ;
00292     // ... and check for NULL
00293     if ( pstcOcuInternData != NULL )
00294     {
00295         pstcOcuInternData->pfnOcu0Callback = NULL;
00296         pstcOcuInternData->pfnOcu1Callback = NULL;
00297         pstcOcuInternData->pfnOcu2Callback = NULL;
00298         pstcOcuInternData->pfnOcu3Callback = NULL;
00299         pstcOcuInternData->pfnOcu4Callback = NULL;
00300         pstcOcuInternData->pfnOcu5Callback = NULL;
00301     }
00302 
00303     //Get pointer of current channel OCU register address
00304     pu8OCFS = (volatile uint8_t*)((volatile uint8_t*)pstcOcu + 0x68UL + u8Ch/2);
00305     pstcOCSB = (volatile stc_mft_ocu_ocsb10_field_t*)((volatile uint8_t*)pstcOcu + 0x19UL + (u8Ch/2)*4);
00306     p8OCSC = (volatile uint8_t*)((volatile uint8_t*)pstcOcu + 0x25UL);
00307     pu8OCSD = (volatile uint8_t*)((volatile uint8_t*)pstcOcu + 0x1AUL + (u8Ch/2)*4);
00308 
00309     //set OCSB register, config ocu's operation
00310     pstcOCSB->CMOD = pstcOcuConfig->bCmod;
00311     pstcOCSB->FM4 = pstcOcuConfig->bFm4;
00312 
00313     //set OCSC register, when enable FM3 compatible mode
00314     *p8OCSC = pstcOcuConfig->u8Mod;
00315 
00316     //set OCSD register and RT output level state
00317     if(0 == (u8Ch % 2)) //channel 0, 2, 4
00318     {
00319         *pu8OCSD &= 0x33u; 
00320         *pu8OCSD |= (uint8_t)pstcOcuConfig->enOccpBufMode;
00321         *pu8OCSD |= (uint8_t)((uint8_t)pstcOcuConfig->enOcseBufMode << 4);
00322         *pu8OCFS |= (uint8_t)pstcOcuConfig->enFrtConnect;
00323         pstcOCSB->OTD0 = pstcOcuConfig->enStatePin;
00324     }
00325     else//channel 1, 3, 5
00326     {
00327         *pu8OCSD &= 0xCCu; 
00328         *pu8OCSD |= (uint8_t)((uint8_t)pstcOcuConfig->enOccpBufMode << 2);
00329         *pu8OCSD |= (uint8_t)((uint8_t)pstcOcuConfig->enOcseBufMode << 6);
00330         *pu8OCFS |= (uint8_t)((uint8_t)pstcOcuConfig->enFrtConnect << 4);
00331         pstcOCSB->OTD1 = pstcOcuConfig->enStatePin;
00332     }
00333 
00334     return Ok;
00335 }
00336 
00354 en_result_t Mft_Ocu_SetEvenChCompareMode(volatile stc_mftn_ocu_t* pstcOcu,
00355                                          uint8_t EvenCh,
00356                                          stc_even_compare_config_t* pstcConfig)
00357 {
00358     volatile uint16_t* p16OCSE0;
00359 
00360     // Check for NULL pointer
00361     if ( (pstcOcu == NULL)
00362          || (EvenCh%2 != 0) 
00363          || (pstcConfig == NULL) 
00364          || (pstcConfig->enFrtZeroEvenMatchEvenChRtStatus > RtOutputReverse)  
00365          || (pstcConfig->enFrtZeroEvenNotMatchEvenChRtStatus > RtOutputReverse)  
00366          || (pstcConfig->enFrtUpCntEvenMatchEvenChRtStatus > RtOutputReverse) 
00367          || (pstcConfig->enFrtPeakEvenMatchEvenChRtStatus > RtOutputReverse) 
00368          || (pstcConfig->enFrtPeakEvenNotMatchEvenChStatus > RtOutputReverse)  
00369          || (pstcConfig->enFrtDownCntEvenMatchEvenChRtStatus > RtOutputReverse)  
00370          || (pstcConfig->enIopFlagWhenFrtZeroEvenMatch > IopFlagSet)  
00371          || (pstcConfig->enIopFlagWhenFrtUpCntEvenMatch > IopFlagSet) 
00372          || (pstcConfig->enIopFlagWhenFrtPeakEvenMatch > IopFlagSet)  
00373          || (pstcConfig->enIopFlagWhenFrtDownCntEvenMatch > IopFlagSet)  )
00374     {
00375         return ErrorInvalidParameter ;
00376     }
00377     
00378     p16OCSE0 = (volatile uint16_t*)((volatile uint8_t*)pstcOcu + 0x28UL + EvenCh*4);
00379     *p16OCSE0 = 0;
00380     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enFrtZeroEvenMatchEvenChRtStatus    << 10u);
00381     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enFrtZeroEvenNotMatchEvenChRtStatus << 14u); 
00382     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enFrtUpCntEvenMatchEvenChRtStatus   << 8u);
00383     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enFrtPeakEvenMatchEvenChRtStatus    << 6u);                   
00384     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enFrtPeakEvenNotMatchEvenChStatus   << 12u);
00385     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enFrtDownCntEvenMatchEvenChRtStatus << 4u);
00386     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enIopFlagWhenFrtZeroEvenMatch       << 3u);
00387     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enIopFlagWhenFrtUpCntEvenMatch      << 2u);
00388     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enIopFlagWhenFrtPeakEvenMatch       << 1u);
00389     *p16OCSE0 |= (uint16_t)((uint16_t)pstcConfig->enIopFlagWhenFrtDownCntEvenMatch    << 0u);
00390     return Ok;
00391 }
00392 
00410 en_result_t Mft_Ocu_SetOddChCompareMode (volatile stc_mftn_ocu_t*pstcOcu,
00411                                          uint8_t OddCh,
00412                                          stc_odd_compare_config_t* pstcConfig)
00413 {
00414     volatile uint32_t* pu32OCSE1;
00415     
00416     // Check for NULL pointer
00417     if ( (pstcOcu == NULL)
00418          || (OddCh%2 == 0) 
00419          || (pstcConfig->enFrtZeroOddMatchEvenMatchOddChRtStatus > RtOutputReverse)     
00420          || (pstcConfig->enFrtZeroOddMatchEvenNotMatchOddChRtStatus > RtOutputReverse)     
00421          || (pstcConfig->enFrtZeroOddNotMatchEvenMatchOddChRtStatus > RtOutputReverse)     
00422          || (pstcConfig->enFrtZeroOddNotMatchEvenNotMatchOddChRtStatus > RtOutputReverse)       
00423          || (pstcConfig->enFrtUpCntOddMatchEvenMatchOddChRtStatus  > RtOutputReverse)    
00424          || (pstcConfig->enFrtUpCntOddMatchEvenNotMatchOddChRtStatus > RtOutputReverse)      
00425          || (pstcConfig->enFrtUpCntOddNotMatchEvenMatchOddChRtStatus > RtOutputReverse)       
00426          || (pstcConfig->enFrtPeakOddMatchEvenMatchOddChRtStatus     > RtOutputReverse)     
00427          || (pstcConfig->enFrtPeakOddMatchEvenNotMatchOddChRtStatus  > RtOutputReverse)      
00428          || (pstcConfig->enFrtPeakOddNotMatchEvenMatchOddChRtStatus  > RtOutputReverse)     
00429          || (pstcConfig->enFrtPeakOddNotMatchEvenNotMatchOddChRtStatus > RtOutputReverse)      
00430          || (pstcConfig->enFrtDownOddMatchEvenMatchOddChRtStatus       > RtOutputReverse)     
00431          || (pstcConfig->enFrtDownOddMatchEvenNotMatchOddChRtStatus    > RtOutputReverse)     
00432          || (pstcConfig->enFrtDownOddNotMatchEvenMatchOddChRtStatus    > RtOutputReverse)      
00433          || (pstcConfig->enIopFlagWhenFrtZeroOddMatch    > IopFlagSet)      
00434          || (pstcConfig->enIopFlagWhenFrtUpCntOddMatch   > IopFlagSet)      
00435          || (pstcConfig->enIopFlagWhenFrtPeakOddMatch    > IopFlagSet)     
00436          || (pstcConfig->enIopFlagWhenFrtDownCntOddMatch > IopFlagSet) )
00437     {
00438         return ErrorInvalidParameter ;
00439     }
00440     
00441     pu32OCSE1 = (volatile uint32_t*)((volatile uint8_t*)pstcOcu + 0x28UL + OddCh*4);
00442     *pu32OCSE1 = 0;
00443     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtZeroOddMatchEvenMatchOddChRtStatus        << 26);
00444     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtZeroOddMatchEvenNotMatchOddChRtStatus     << 10);
00445     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtZeroOddNotMatchEvenMatchOddChRtStatus     << 30);
00446     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtZeroOddNotMatchEvenNotMatchOddChRtStatus  << 14);
00447     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtUpCntOddMatchEvenMatchOddChRtStatus       << 24);
00448     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtUpCntOddMatchEvenNotMatchOddChRtStatus    << 8);
00449     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtUpCntOddNotMatchEvenMatchOddChRtStatus    << 18);
00450     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtPeakOddMatchEvenMatchOddChRtStatus        << 22);
00451     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtPeakOddMatchEvenNotMatchOddChRtStatus     << 6) ;
00452     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtPeakOddNotMatchEvenMatchOddChRtStatus     << 28);
00453     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtPeakOddNotMatchEvenNotMatchOddChRtStatus  << 12);
00454     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtDownOddMatchEvenMatchOddChRtStatus        << 20);
00455     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtDownOddMatchEvenNotMatchOddChRtStatus     << 4);
00456     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enFrtDownOddNotMatchEvenMatchOddChRtStatus     << 16); 
00457     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enIopFlagWhenFrtZeroOddMatch                   << 3);
00458     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enIopFlagWhenFrtUpCntOddMatch                  << 2);
00459     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enIopFlagWhenFrtPeakOddMatch                   << 1);
00460     *pu32OCSE1 |= (uint32_t)((uint32_t)pstcConfig->enIopFlagWhenFrtDownCntOddMatch                << 0);
00461     
00462     return Ok;
00463 }
00464 
00481 en_result_t Mft_Ocu_EnableOperation(volatile stc_mftn_ocu_t* pstcOcu, uint8_t u8Ch)
00482 {
00483     volatile stc_mft_ocu_ocsa10_field_t* pstcOCSA;
00484 
00485     // Check for NULL pointer
00486     if ( (pstcOcu == NULL)
00487          || (u8Ch >= MFT_OCU_MAXCH))
00488     {
00489         return ErrorInvalidParameter ;
00490     }
00491 
00492     //Get pointer of current channel OCU register address
00493     pstcOCSA = (volatile stc_mft_ocu_ocsa10_field_t*)((volatile uint8_t*)pstcOcu + 0x18UL + (u8Ch/2)*4);
00494 
00495     //set register
00496     if(0 == (u8Ch%2)) //channel 0,2,4
00497     {
00498         pstcOCSA->CST0 = 1;
00499     }
00500     else //channel 1,3,5
00501     {
00502         pstcOCSA->CST1 = 1;
00503     }
00504 
00505     return Ok;
00506 }
00507 
00524 en_result_t Mft_Ocu_DisableOperation(volatile stc_mftn_ocu_t* pstcOcu, uint8_t u8Ch)
00525 {
00526     volatile stc_mft_ocu_ocsa10_field_t* pstcOCSA;
00527 
00528     // Check for NULL pointer
00529     if ( (pstcOcu == NULL)
00530          || (u8Ch >= MFT_OCU_MAXCH))
00531     {
00532         return ErrorInvalidParameter ;
00533     }
00534 
00535     //Get pointer of current channel OCU register address
00536     pstcOCSA = (volatile stc_mft_ocu_ocsa10_field_t*)((volatile uint8_t*)pstcOcu + 0x18UL + (u8Ch/2)*4);
00537 
00538     //set register
00539     if(0 == (u8Ch%2)) //channel 0,2,4
00540     {
00541         pstcOCSA->CST0 = 0;
00542     }
00543     else //channel 1,3,5
00544     {
00545         pstcOCSA->CST1 = 0;
00546     }
00547 
00548     return Ok;
00549 }
00550 
00551 #if (PDL_INTERRUPT_ENABLE_MFT0_OCU == PDL_ON) || \
00552     (PDL_INTERRUPT_ENABLE_MFT1_OCU == PDL_ON) || \
00553     (PDL_INTERRUPT_ENABLE_MFT2_OCU == PDL_ON)
00554 
00571 en_result_t Mft_Ocu_EnableInt(volatile stc_mftn_ocu_t* pstcOcu,
00572                               uint8_t u8Ch, func_ptr_t  pfnCallback)
00573 {
00574     stc_mft_ocu_intern_data_t* pstcOcuInternData;
00575     volatile stc_mft_ocu_ocsa10_field_t* pstcOCSA;
00576     func_ptr_t* fnCallback;
00577     // Check for NULL pointer
00578     if ( (pstcOcu == NULL)
00579          || (u8Ch >= MFT_OCU_MAXCH))
00580     {
00581         return ErrorInvalidParameter ;
00582     }
00583 
00584     // Get pointer to internal data structure ...
00585     pstcOcuInternData = MftGetInternDataPtr( pstcOcu ) ;
00586 
00587     //Get pointer of current channel OCU register address
00588     pstcOCSA = (volatile stc_mft_ocu_ocsa10_field_t*)((volatile uint8_t*)pstcOcu + 0x18UL + (u8Ch/2)*4);
00589 
00590     //set register
00591     if(0 == (u8Ch%2)) //channel 0,2,4
00592     {
00593         pstcOCSA->IOE0 = 1;
00594     }
00595     else //channel 1,3,5
00596     {
00597         pstcOCSA->IOE1 = 1;
00598     }
00599 
00600     //set callback function
00601     fnCallback = (func_ptr_t*)((uint8_t*)&(pstcOcuInternData->pfnOcu0Callback) 
00602                                + (sizeof(func_ptr_t) * u8Ch));
00603     *fnCallback = pfnCallback;
00604       
00605     Mft_Ocu_InitIrq(pstcOcu);
00606 
00607     return Ok;
00608 }
00609 
00626 en_result_t Mft_Ocu_DisableInt(volatile stc_mftn_ocu_t* pstcOcu,uint8_t u8Ch)
00627 {
00628     stc_mft_ocu_intern_data_t* pstcOcuInternData;
00629     volatile stc_mft_ocu_ocsa10_field_t* pstcOCSA;
00630 
00631     // Check for NULL pointer
00632     if ( (pstcOcu == NULL)
00633          || (u8Ch >= MFT_OCU_MAXCH))
00634     {
00635         return ErrorInvalidParameter ;
00636     }
00637 
00638     // Get pointer to internal data structure ...
00639     pstcOcuInternData = MftGetInternDataPtr( pstcOcu ) ;
00640 
00641     //Get pointer of current channel OCU register address
00642     pstcOCSA = (volatile stc_mft_ocu_ocsa10_field_t*)((volatile uint8_t*)pstcOcu + 0x18UL + (u8Ch/2)*4);
00643     pstcOcuInternData = pstcOcuInternData + (sizeof(pstcOcuInternData)) * u8Ch;
00644 
00645     //set register
00646     if(0 == (u8Ch%2)) //channel 0,2,4
00647     {
00648         pstcOCSA->IOE0 = 0;
00649     }
00650     else //channel 1,3,5
00651     {
00652         pstcOCSA->IOE1 = 0;
00653     }
00654 
00655     //set callback function
00656     pstcOcuInternData = NULL;
00657     
00658     Mft_Ocu_DeInitIrq(pstcOcu);
00659     
00660     return Ok;
00661 }
00662 
00663 #endif
00664 
00678 en_int_flag_t Mft_Ocu_GetIntFlag(volatile stc_mftn_ocu_t* pstcOcu, uint8_t u8Ch)
00679 {
00680     volatile stc_mft_ocu_ocsa10_field_t* pstcOCSA;
00681     en_int_flag_t retval = PdlClr;
00682 
00683     //Get pointer of current channel OCU register address
00684     pstcOCSA = (volatile stc_mft_ocu_ocsa10_field_t*)((volatile uint8_t*)pstcOcu + 0x18UL + (u8Ch/2)*4);
00685 
00686     //set return value
00687     if(0 == (u8Ch%2)) //channel 0,2,4
00688     {   
00689         (pstcOCSA->IOP0 == 1) ? (retval = PdlSet) : (retval = PdlClr);
00690     }
00691     else //channel 1,3,5
00692     {
00693         (pstcOCSA->IOP1 == 1) ? (retval = PdlSet) : (retval = PdlClr);
00694     }
00695 
00696     return retval;
00697 }
00698 
00715 en_result_t Mft_Ocu_ClrIntFlag(volatile stc_mftn_ocu_t* pstcOcu, uint8_t u8Ch)
00716 {
00717     volatile stc_mft_ocu_ocsa10_field_t* pstcOCSA;
00718 
00719     // Check for NULL pointer
00720     if ( (pstcOcu == NULL)
00721          || (u8Ch >= MFT_OCU_MAXCH))
00722     {
00723         return ErrorInvalidParameter ;
00724     }
00725 
00726     //Get pointer of current channel OCU register address
00727     pstcOCSA = (volatile stc_mft_ocu_ocsa10_field_t*)((volatile uint8_t*)pstcOcu + 0x18UL + (u8Ch/2)*4);
00728 
00729     //clear register
00730     if(0 == (u8Ch%2)) //channel 0,2,4
00731     {
00732         pstcOCSA->IOP0 = 0;
00733     }
00734     else //channel 1,3,5
00735     {
00736         pstcOCSA->IOP1 = 0;
00737     }
00738 
00739     return Ok;
00740 }
00741 
00755 en_ocu_rt_out_state_t Mft_Ocu_GetRtPinLevel(volatile stc_mftn_ocu_t* pstcOcu, 
00756                                             uint8_t u8Ch)
00757 {
00758     volatile stc_mft_ocu_ocsb10_field_t* pstcOCSB;
00759     en_ocu_rt_out_state_t enLevel = RtLowLevel;
00760     
00761     // Get the OCSB address
00762     pstcOCSB = (volatile stc_mft_ocu_ocsb10_field_t*)((volatile uint8_t*)pstcOcu + 0x19UL + (u8Ch/2)*4);
00763     if((u8Ch%2) == 0)
00764     {
00765         (pstcOCSB->OTD0 == 1) ? (enLevel = RtHighLevel) : (enLevel = RtLowLevel);
00766     }
00767     else
00768     {
00769         (pstcOCSB->OTD1 == 1) ? (enLevel = RtHighLevel) : (enLevel = RtLowLevel);
00770     }
00771     
00772     return enLevel;
00773 }
00774 
00793 en_result_t Mft_Ocu_WriteOccp(volatile stc_mftn_ocu_t* pstcOcu,
00794                               uint8_t u8Ch, uint16_t u16Occp)
00795 {
00796     volatile uint16_t* p16OCCP;
00797 
00798     // Check for NULL pointer
00799     if ( (pstcOcu == NULL)
00800          || (u8Ch >= MFT_OCU_MAXCH))
00801     {
00802         return ErrorInvalidParameter ;
00803     }
00804     //Get pointer of current channel OCU register address
00805     p16OCCP = (volatile uint16_t*)((volatile uint8_t*)pstcOcu + 0x02 + u8Ch*4);
00806 
00807     //set register
00808     *p16OCCP = u16Occp;
00809 
00810     return Ok;
00811 }
00812 
00825 uint16_t Mft_Ocu_ReadOccp(volatile stc_mftn_ocu_t* pstcOcu, uint8_t u8Ch)
00826 {
00827     volatile uint16_t* p16OCCP;
00828 
00829     // Check for NULL pointer
00830     if ( (pstcOcu == NULL)
00831          || (u8Ch >= MFT_OCU_MAXCH))
00832     {
00833         return 0 ;
00834     }
00835     //Get pointer of current channel OCU register address
00836     p16OCCP = (volatile uint16_t*)((volatile uint8_t*)pstcOcu + 0x02 + u8Ch*4);
00837 
00838     return (uint16_t)((*p16OCCP) & 0xFFFFu);
00839 }
00840 
00842 
00843 #endif // #if (defined(PDL_PERIPHERAL_$$X_ACTIVE))
00844 
00845 /******************************************************************************/
00846 /* EOF (not truncated)                                                        */
00847 /******************************************************************************/