| PDL for FM0+ Version1.0 Peripheral Driverl Library for FM0+

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

C:/pdl_v10/library/driver/wc/wc.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 /******************************************************************************/
    00052 /******************************************************************************/
    00053 /* Include files                                                              */
    00054 /******************************************************************************/
    00055 #include "wc.h"
    00056
    00057 #if (defined(PDL_PERIPHERAL_WC_ACTIVE))
    00058
    00059 /******************************************************************************/
    00060 /* Local pre-processor symbols/macros ('#define')                             */
    00061 /******************************************************************************/
    00062
    00063 /******************************************************************************/
    00064 /* Global variable definitions (declared in header file with 'extern')        */
    00065 /******************************************************************************/
    00066 #if (PDL_INTERRUPT_ENABLE_WC == PDL_ON)
    00067 static func_ptr_t  pWcfnIntCallback = NULL;
    00068 #endif
    00069
    00070 #if (PDL_INTERRUPT_ENABLE_WC == PDL_ON)
    00071 /******************************************************************************/
    00072 /* Local Functions                                                            */
    00073 /******************************************************************************/
    00078 static void Wc_InitNvic(void)
    00079 {
    00080     NVIC_ClearPendingIRQ(OSC_PLL_WC_RTC_IRQn);
    00081     NVIC_EnableIRQ(OSC_PLL_WC_RTC_IRQn);
    00082     NVIC_SetPriority(OSC_PLL_WC_RTC_IRQn, PDL_IRQ_LEVEL_CLK_WC_RTC);
    00083 }
    00084
    00089 static void Wc_DeInitNvic(void)
    00090 {
    00091     NVIC_ClearPendingIRQ(OSC_PLL_WC_RTC_IRQn);
    00092     NVIC_DisableIRQ(OSC_PLL_WC_RTC_IRQn);
    00093     NVIC_SetPriority(OSC_PLL_WC_RTC_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
    00094 }
    00099 void Wc_IrqHandler(void)
    00100 {
    00101     if (PdlSet == Wc_GetIntFlag())
    00102     {
    00103         Wc_ClearIntFlag();
    00104         if (pWcfnIntCallback != NULL)
    00105         {
    00106             pWcfnIntCallback();
    00107         }
    00108     }
    00109 }
    00110 #endif
    00111
    00126 en_result_t Wc_Pres_SelClk(stc_wc_pres_clk_t* pstcWcPresClk)
    00127 {
    00128     switch (pstcWcPresClk->enInputClk)
    00129     {
    00130         case WcPresInClkSubOsc:
    00131         case WcPresInClkMainOsc:
    00132         case WcPresInClkHighCr:
    00133         case WcPresInClkLowCr:
    00134             FM0P_WC->CLK_SEL_f.SEL_IN = pstcWcPresClk->enInputClk;
    00135             break;
    00136         default:
    00137             return ErrorInvalidParameter;
    00138     }
    00139
    00140     switch(pstcWcPresClk->enOutputClk)
    00141     {
    00142         case WcPresOutClkArray0:
    00143         case WcPresOutClkArray1:
    00144         case WcPresOutClkArray2:
    00145         case WcPresOutClkArray3:
    00146         case WcPresOutClkArray4:
    00147         case WcPresOutClkArray5:
    00148         case WcPresOutClkArray6:
    00149             FM0P_WC->CLK_SEL_f.SEL_OUT = pstcWcPresClk->enOutputClk;
    00150             break;
    00151         default:
    00152             return ErrorInvalidParameter;
    00153     }
    00154
    00155     return Ok;
    00156 }
    00157
    00167 en_result_t Wc_Pres_EnableDiv()
    00168 {
    00169     FM0P_WC->CLK_EN_f.CLK_EN = 1;
    00170     return Ok;
    00171 }
    00172
    00182 en_result_t Wc_Pres_DisableDiv()
    00183 {
    00184     FM0P_WC->CLK_EN_f.CLK_EN = 0;
    00185     return Ok;
    00186 }
    00187
    00198 en_stat_flag_t Wc_GetDivStat()
    00199 {
    00200     return ((en_stat_flag_t)(FM0P_WC->CLK_EN_f.CLK_EN_R));
    00201 }
    00202
    00216 en_result_t Wc_Init(stc_wc_config_t* pstcWcConfig)
    00217 {
    00218     // Check for NULL pointers
    00219     if (NULL == pstcWcConfig)
    00220     {
    00221         return ErrorInvalidParameter;
    00222     }
    00223
    00224     switch (pstcWcConfig->enCntClk)
    00225     {
    00226         case WcCntClkWcck0:
    00227         case WcCntClkWcck1:
    00228         case WcCntClkWcck2:
    00229         case WcCntClkWcck3:
    00230             FM0P_WC->WCCR_f.CS = pstcWcConfig->enCntClk;
    00231             break;
    00232         default:
    00233            return ErrorInvalidParameter;
    00234     }
    00235
    00236     FM0P_WC->WCRL = pstcWcConfig->u8ReloadValue;
    00237
    00238     return Ok;
    00239 }
    00240
    00241
    00251 en_result_t Wc_EnableCount(void)
    00252 {
    00253     FM0P_WC->WCCR_f.WCEN = 1;
    00254     return Ok;
    00255 }
    00256
    00266 en_result_t Wc_DisableCount(void)
    00267 {
    00268     FM0P_WC->WCCR_f.WCEN = 0;
    00269     return Ok;
    00270 }
    00271
    00272 #if (PDL_INTERRUPT_ENABLE_WC == PDL_ON)
    00273
    00286 en_result_t Wc_EnableInt(func_ptr_t  pfnIntCallback)
    00287 {
    00288     // check for non-null pointers
    00289     if (NULL == pfnIntCallback)
    00290     {
    00291         return ErrorInvalidParameter;
    00292     }
    00293     FM0P_WC->WCCR_f.WCIE = 1;
    00294     pWcfnIntCallback = pfnIntCallback;
    00295     Wc_InitNvic();
    00296     return Ok;
    00297 }
    00298
    00308 en_result_t Wc_DisableInt(void)
    00309 {
    00310     FM0P_WC->WCCR_f.WCIE = 0;
    00311     pWcfnIntCallback = NULL;
    00312
    00313     /* When RTC interrupt is enabled, don't disable IRQ */
    00314     if((FM0P_RTC->WTCR1 & 0xFF000000u) != 0)
    00315     {
    00316         return Ok;
    00317     }
    00318
    00319     Wc_DeInitNvic();
    00320     return Ok;
    00321 }
    00322 #endif
    00323
    00332 en_result_t Wc_WriteReloadVal(uint8_t u8Val)
    00333 {
    00334     FM0P_WC->WCRL = u8Val;
    00335     return Ok;
    00336 }
    00337
    00347 uint8_t Wc_ReadCurCnt()
    00348 {
    00349     return (FM0P_WC->WCRD);
    00350 }
    00351
    00361 en_result_t Wc_ClearIntFlag()
    00362 {
    00363     FM0P_WC->WCCR_f.WCIF = 0;
    00364     return Ok;
    00365 }
    00366
    00377 en_int_flag_t Wc_GetIntFlag()
    00378 {
    00379     return ((en_int_flag_t)(FM0P_WC->WCCR_f.WCIF));
    00380 }
    00381
    00392 en_stat_flag_t Wc_GetOperationFlag()
    00393 {
    00394     return ((en_stat_flag_t)(FM0P_WC->WCCR_f.WCOP));
    00395 }
    00396
    00397
    00398 #endif // #if (defined(PDL_PERIPHERAL_WC_ACTIVE))
    00399
    00400 /******************************************************************************/
    00401 /* EOF (not truncated)                                                        */
    00402 /******************************************************************************/
    00403