PDL for FM0+  Version1.0
Peripheral Driverl Library for FM0+
C:/pdl_v10/library/driver/mft/mft_wfg.h
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 /******************************************************************************/
00052 #ifndef __MFT_WFG_H__
00053 #define __MFT_WFG_H__
00054 
00055 #include "mcu.h"
00056 #include "pdl_user.h"
00057 
00058 #if (defined(PDL_PERIPHERAL_MFT_WFG_ACTIVE))
00059 
00060 /* C binding of definitions if building with C++ compiler */
00061 #ifdef __cplusplus
00062 extern "C"
00063 {
00064 #endif
00065   
00281 /******************************************************************************
00282  * Global definitions
00283  ******************************************************************************/
00284 #define stc_mftn_wfg_t FM0P_MFT_WFG_TypeDef
00285 
00286 #define MFT0_WFG       (*((volatile stc_mftn_wfg_t *) FM0P_MFT0_WFG_BASE))
00287 #define MFT1_WFG       (*((volatile stc_mftn_wfg_t *) FM0P_MFT1_WFG_BASE))
00288 #define MFT2_WFG       (*((volatile stc_mftn_wfg_t *) FM0P_MFT2_WFG_BASE))
00289 
00290 #define  MFT_WFG_CH0             0
00291 #define  MFT_WFG_CH1             1
00292 #define  MFT_WFG_CH2             2
00293 #define  MFT_WFG_CH3             3  
00294 #define  MFT_WFG_CH4             4
00295 #define  MFT_WFG_CH5             5
00296 
00297 #define  MFT_WFG_CH10            0
00298 #define  MFT_WFG_CH32            1
00299 #define  MFT_WFG_CH54            2
00300 #define  MFT_WFG_MAXCH           3
00301   
00302 #define WFG_INSTANCE_COUNT       (PDL_PERIPHERAL_ENABLE_MFT0_WFG == PDL_ON ? 1 : 0) + \
00303                                  (PDL_PERIPHERAL_ENABLE_MFT1_WFG == PDL_ON ? 1 : 0) + \
00304                                  (PDL_PERIPHERAL_ENABLE_MFT2_WFG == PDL_ON ? 1 : 0)  
00305 
00310 typedef enum en_wfg_instance_index
00311 {
00312 #if (PDL_PERIPHERAL_ENABLE_MFT0_WFG == PDL_ON)  
00313     WfgInstanceIndexWfg0 = 0,  
00314 #endif
00315 #if (PDL_PERIPHERAL_ENABLE_MFT1_WFG == PDL_ON)
00316     WfgInstanceIndexWfg1,      
00317 #endif 
00318 #if (PDL_PERIPHERAL_ENABLE_MFT2_WFG == PDL_ON)
00319     WfgInstanceIndexWfg2,      
00320 #endif    
00321 
00322 } en_wfg_instance_index_t;  
00323   
00324 /******************************************************************************
00325  * \brief WFG operation mode
00326  ******************************************************************************/
00327 typedef enum en_mft_wfg_mode
00328 {
00329     WfgThroughMode = 0,           
00330     WfgRtPpgMode = 1,             
00331     WfgTimerPpgMode = 2,          
00332     WfgRtDeadTimerMode = 4,       
00333     WfgRtDeadTimerFilterMode = 5, 
00334     WfgPpgDeadTimerFilterMode = 6,
00335     WfgPpgDeadTimerMode = 7,      
00336     
00337 }en_mft_wfg_mode_t;
00338 
00339 /******************************************************************************
00340  * \brief Enumeration of GTEN bits setting
00341  ******************************************************************************/
00342 typedef enum en_gten_bits
00343 {
00344     GtenBits00B = 0,     
00345     GtenBits01B,         
00346     GtenBits10B,         
00347     GtenBits11B,         
00348   
00349 }en_gten_bits_t;
00350 
00351 /******************************************************************************
00352  * \brief Enumeration of PSEL bits setting
00353  ******************************************************************************/
00354 typedef enum en_psel_bits
00355 {
00356     PselBits00B = 0,    
00357     PselBits01B,        
00358     PselBits10B,        
00359     PselBits11B,        
00360   
00361 }en_psel_bits_t;
00362 
00363 /******************************************************************************
00364  * \brief Enumeration of PGEN bits setting
00365  ******************************************************************************/
00366 typedef enum en_pgen_bits
00367 {
00368     PgenBits00B = 0,   
00369     PgenBits01B,       
00370     PgenBits10B,       
00371     PgenBits11B,       
00372     
00373 }en_pgen_bits_t;
00374 
00375 /******************************************************************************
00376  * \brief Enumeration of DMOD bit setting
00377  ******************************************************************************/
00378 typedef enum en_dmod_bit
00379 {
00380     DmodBit0B = 0, 
00381     DmodBit1B,     
00382     
00383 }en_dmod_bit_t;
00384 
00385 /******************************************************************************
00386  * \brief WFG control configure
00387  ******************************************************************************/
00388 typedef struct stc_wfg_ctrl_bits
00389 {
00390     en_gten_bits_t   enGtenBits; 
00391     en_psel_bits_t   enPselBits; 
00392     en_pgen_bits_t   enPgenBits; 
00393     en_dmod_bit_t    enDmodBit;  
00394     
00395 }stc_wfg_ctrl_bits_t;
00396 
00397 /******************************************************************************
00398  * \brief Enumeration to set count clock prescaler
00399  ******************************************************************************/
00400 typedef enum en_wfg_timer_clock
00401 {
00402     WfgPlckDiv1 = 0,  
00403     WfgPlckDiv2,      
00404     WfgPlckDiv4,      
00405     WfgPlckDiv8,      
00406     WfgPlckDiv16,     
00407     WfgPlckDiv32,     
00408     WfgPlckDiv64,     
00409     WfgPlckDiv128,    
00410   
00411 }en_wfg_timer_clock_t;
00412 
00413 /******************************************************************************
00414  * \brief WFG internal data
00415  ******************************************************************************/
00416 typedef struct stc_mft_wfg_intern_data
00417 {
00418     func_ptr_t  pfnWfg10TimerCallback;      
00419     func_ptr_t  pfnWfg32TimerCallback;      
00420     func_ptr_t  pfnWfg54TimerCallback;      
00421     func_ptr_t  pfnWfgAnalogFilterCallback; 
00422     func_ptr_t  pfnWfgDigtalFilterCallback; 
00423 }stc_mft_wfg_intern_data_t;
00424 
00425 /******************************************************************************
00426  * brief noise canceling width for a digital noise-canceler
00427  ******************************************************************************/
00428 typedef enum en_nzcl_filter_width
00429 {
00430     NzlcNoFilter,      
00431     NzlcWidth4Cycle,   
00432     NzlcWidth8Cycle,   
00433     NzlcWidth16Cycle,  
00434     NzlcWidth32Cycle,  
00435     NzlcWidth64Cycle,  
00436     NzlcWidth128Cycle, 
00437     
00438 }en_nzcl_filter_width_t;
00439 
00440 /******************************************************************************
00441  * brief NZCL configure
00442  ******************************************************************************/
00443 typedef struct stc_wfg_nzcl_config
00444 {
00445     boolean_t               bEnDigitalFilter;      
00446     en_nzcl_filter_width_t  enDigitalFilterWidth;  
00447     boolean_t               bEnAnalogFilter;       
00448     boolean_t               bSwitchToGpio;           
00449 }stc_wfg_nzcl_config_t;
00450 
00451 /******************************************************************************
00452  * \brief Structure of DTIF interrupt selection
00453  ******************************************************************************/
00454 typedef struct stc_dtif_int_sel
00455 {
00456     boolean_t  bDtifDigitalFilterInt;  
00457     boolean_t  bDtifAnalogFilterInt;   
00458   
00459 }stc_dtif_int_sel_t;
00460 
00461 /******************************************************************************
00462  * \brief Structure of DTIF callback function array
00463  ******************************************************************************/
00464 typedef struct stc_dtif_int_cb
00465 {
00466     func_ptr_t  pfnWfgAnalogFilterCallback;  
00467     func_ptr_t  pfnWfgDigtalFilterCallback;  
00468   
00469 }stc_dtif_int_cb_t;
00470 
00471 /******************************************************************************
00472  * brief structure of WFG instance data
00473  ******************************************************************************/
00474 typedef struct stc_mft_wfg_instance_data
00475 {
00476   volatile stc_mftn_wfg_t*  pstcInstance;  
00477   stc_mft_wfg_intern_data_t stcInternData; 
00478 } stc_mft_wfg_instance_data_t;
00479 
00480 /******************************************************************************/
00481 /* Global variable declarations ('extern', definition in C source)            */
00482 /******************************************************************************/
00484 extern stc_mft_wfg_instance_data_t m_astcMftWfgInstanceDataLut[WFG_INSTANCE_COUNT];
00485 
00486 /******************************************************************************/
00487 /* Global function prototypes ('extern', definition in C source)              */
00488 /******************************************************************************/
00489 /* 1. WFG function configuration */
00490 en_result_t Mft_Wfg_ConfigMode(volatile stc_mftn_wfg_t* pstcWfg,
00491                                uint8_t u8CoupleCh, 
00492                                en_mft_wfg_mode_t enMode);
00493 en_result_t Mft_Wfg_ConfigCtrlBits(volatile stc_mftn_wfg_t* pstcWfg,
00494                                    uint8_t u8CoupleCh,
00495                                    stc_wfg_ctrl_bits_t* pstcCtrlBits);
00496 
00497 /* 2. WFG timer configuration */
00498 en_result_t Mft_Wfg_InitTimerClock(volatile stc_mftn_wfg_t* pstcWfg,
00499                                    uint8_t u8CoupleCh,
00500                                    en_wfg_timer_clock_t enClk);
00501 #if (PDL_INTERRUPT_ENABLE_MFT0_WFG == PDL_ON) || \
00502     (PDL_INTERRUPT_ENABLE_MFT1_WFG == PDL_ON) || \
00503     (PDL_INTERRUPT_ENABLE_MFT2_WFG == PDL_ON) 
00504 en_result_t Mft_Wfg_EnableTimerInt(volatile stc_mftn_wfg_t* pstcWfg,
00505                                    uint8_t u8CoupleCh, 
00506                                    func_ptr_t pfnCallback);
00507 en_result_t Mft_Wfg_DisableTimerInt(volatile stc_mftn_wfg_t* pstcWfg, 
00508                                     uint8_t u8CoupleCh);
00509 #endif
00510 en_result_t Mft_Wfg_StartTimer(volatile stc_mftn_wfg_t* pstcWfg, uint8_t u8CoupleCh);
00511 en_result_t Mft_Wfg_StopTimer(volatile stc_mftn_wfg_t* pstcWfg, uint8_t u8CoupleCh);
00512 en_int_flag_t Mft_Wfg_GetTimerIntFlag(volatile stc_mftn_wfg_t* pstcWfg, uint8_t u8CoupleCh);
00513 en_result_t Mft_Wfg_ClrTimerIntFlag(volatile stc_mftn_wfg_t* pstcWfg, uint8_t u8CoupleCh);
00514 en_result_t Mft_Wfg_WriteTimerCountCycle(volatile stc_mftn_wfg_t* pstcWfg,
00515                                          uint8_t u8CoupleCh, 
00516                                          uint16_t u16CycleA, 
00517                                          uint16_t u16CycleB);
00518 en_result_t Mft_Wfg_SetTimerCycle( volatile stc_mftn_wfg_t* pstcWfg,
00519                                       uint8_t u8CoupleCh, uint16_t u16Count);
00520 uint16_t Mft_Wfg_GetTimerCurCycle(volatile stc_mftn_wfg_t* pstcWfg, uint8_t u8CoupleCh);
00521 
00522 /* 3. WFG NZCL configuration */
00523 en_result_t Mft_Wfg_ConfigNzcl(volatile stc_mftn_wfg_t* pstcWfg,
00524                                stc_wfg_nzcl_config_t* pstcNzclConfig);
00525 #if (PDL_INTERRUPT_ENABLE_MFT0_WFG == PDL_ON) || \
00526     (PDL_INTERRUPT_ENABLE_MFT1_WFG == PDL_ON) || \
00527     (PDL_INTERRUPT_ENABLE_MFT2_WFG == PDL_ON) 
00528 en_result_t Mft_Wfg_EnableDtifInt(volatile stc_mftn_wfg_t* pstcWfg, 
00529                                   stc_dtif_int_sel_t* pstcIntSel, 
00530                                   stc_dtif_int_cb_t* pstcCallback);
00531 en_result_t Mft_Wfg_DisableDtifInt(volatile stc_mftn_wfg_t* pstcWfg, 
00532                                    stc_dtif_int_sel_t* stcIntSel);
00533 #endif
00534 en_result_t Mft_Wfg_SwTiggerDtif(volatile stc_mftn_wfg_t* pstcWfg);
00535 en_int_flag_t Mft_Wfg_GetDigitalFilterIntFlag(volatile stc_mftn_wfg_t* pstcWfg);
00536 en_result_t Mft_Wfg_ClrDigitalFilterIntFlag(volatile stc_mftn_wfg_t* pstcWfg);
00537 en_int_flag_t Mft_Wfg_GetAnalogFilterIntFlag(volatile stc_mftn_wfg_t* pstcWfg);
00538 en_result_t Mft_Wfg_ClrAnalogFilterIntFlag(volatile stc_mftn_wfg_t* pstcWfg);
00539 
00540 /* 4. IRQ handler */
00541 void Mft_Wfg_IrqHandler(volatile  stc_mftn_wfg_t* pstcWfg,
00542                         stc_mft_wfg_intern_data_t* pstcMftWfgInternData) ;
00543 
00544 #ifdef __cplusplus
00545 }
00546 #endif
00547 
00549 
00550 #endif // #if (defined(PDL_PERIPHERAL_ADC_ACTIVE))
00551 #endif