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

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

C:/pdl_v10/library/driver/wdg/swwdg.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 "swwdg.h"
    00056
    00057 #if (defined(PDL_PERIPHERAL_WDG_ACTIVE))
    00058
    00064
    00065 #if (PDL_PERIPHERAL_ENABLE_SWWDG == PDL_ON)
    00066 /******************************************************************************/
    00067 /* Local pre-processor symbols/macros ('#define')                             */
    00068 /******************************************************************************/
    00069 /* for WDOGLOAD */
    00070 #define SWWDG_DEFAULT_VAL   (0xFFFFFFFFu)
    00071
    00072 /* for WDOGCONTROL */
    00073 #define SWWDG_CTL_INTEN     (0x01u)
    00074 #define SWWDG_CTL_RESEN     (0x02u)
    00075 #define SWWDG_CTL_TWD100    (0x00u)
    00076 #define SWWDG_CTL_TWD75     (0x04u)
    00077 #define SWWDG_CTL_TWD50     (0x08u)
    00078 #define SWWDG_CTL_TWD25     (0x0Cu)
    00079 #define SWWDG_CTL_SPM       (0x10u)
    00080
    00081 /* for WDOGSPMC */
    00082 #define SWWDG_SPMC_TGR      (0x01u)
    00083
    00084 /******************************************************************************/
    00085 /* Global variable definitions (declared in header file with 'extern')        */
    00086 /******************************************************************************/
    00087 static func_ptr_t pfnSwwdgCallback;
    00088
    00089 /******************************************************************************/
    00090 /* Local type definitions ('typedef')                                         */
    00091 /******************************************************************************/
    00092
    00093 /******************************************************************************/
    00094 /* Local function prototypes ('static')                                       */
    00095 /******************************************************************************/
    00096
    00097 /******************************************************************************/
    00098 /* Local variable definitions ('static')                                      */
    00099 /******************************************************************************/
    00100
    00101 /******************************************************************************/
    00102 /* Function implementation - global ('extern') and local ('static')           */
    00103 /******************************************************************************/
    00104
    00109 void SwwdgIrqHandler(void)
    00110 {
    00111     /* Check software interrupt status */
    00112     if (TRUE == FM0P_SWWDT->WDOGRIS_f.RIS)
    00113     {
    00114         if (NULL != pfnSwwdgCallback)
    00115         {
    00116             pfnSwwdgCallback();
    00117         }
    00118     }
    00119 } /* SwwdgIrqHandler */
    00120
    00134 en_result_t Swwdg_Init(stc_swwdg_config_t* pstcConfig)
    00135 {
    00136     en_result_t enResult;
    00137     uint8_t     u8WdogControl = 0;  /* Preset Watchdog Control Register */
    00138     uint8_t     u8WdogSpmc    = 0;  /* Preset Window Watchdog Control Register */
    00139
    00140     enResult = ErrorInvalidParameter;
    00141
    00142     /* Check for NULL Pointer */
    00143     if (NULL != pstcConfig)
    00144     {
    00145         enResult = Ok;
    00146         /* Un Lock */
    00147         FM0P_SWWDT->WDOGLOCK = SWWDG_REG_UNLOCK;
    00148
    00149         /* Window watchdog mode */
    00150         if (TRUE == pstcConfig->bWinWdgEnable)
    00151         {
    00152             /* Set SPM bit */
    00153             u8WdogControl |= SWWDG_CTL_SPM;
    00154             /* Set reset enable when reload without timing window was occured */
    00155             if (TRUE == pstcConfig->bWinWdgResetEnable)
    00156             {
    00157                 u8WdogSpmc = SWWDG_SPMC_TGR;
    00158             }
    00159             /* Set timing window for window watchdog mode */
    00160             switch (pstcConfig->u8TimingWindow)
    00161             {
    00162                 case en_swwdg_timing_window_100:
    00163                     u8WdogControl |= SWWDG_CTL_TWD100;
    00164                     break;
    00165                 case en_swwdg_timing_window_75:
    00166                     u8WdogControl |= SWWDG_CTL_TWD75;
    00167                     break;
    00168                 case en_swwdg_timing_window_50:
    00169                     u8WdogControl |= SWWDG_CTL_TWD50;
    00170                     break;
    00171                 case en_swwdg_timing_window_25:
    00172                     u8WdogControl |= SWWDG_CTL_TWD25;
    00173                     break;
    00174                 default:
    00175                     enResult = ErrorInvalidParameter;
    00176                     break;
    00177             }
    00178         }
    00179
    00180         if (Ok == enResult)
    00181         {
    00182             /* Set reset enable */
    00183             if (TRUE == pstcConfig->bResetEnable)
    00184             {
    00185                 /* Set RESEN bit */
    00186                 u8WdogControl |= SWWDG_CTL_RESEN;
    00187             }
    00188
    00189             // Set interval
    00190             FM0P_SWWDT->WDOGLOAD = pstcConfig->u32LoadValue;
    00191
    00192             FM0P_SWWDT->WDOGSPMC    = u8WdogSpmc;    /* Setup Window watchdog and */
    00193             FM0P_SWWDT->WDOGCONTROL = u8WdogControl; /* Setup SW-Watchdog */
    00194             FM0P_SWWDT->WDOGLOCK    = 0;             /* Lock it! */
    00195
    00196             /* Initialize callback to NULL */
    00197             pfnSwwdgCallback = NULL;
    00198
    00199             /* Enable NVIC */
    00200             NVIC_ClearPendingIRQ(SWDT_IRQn);
    00201             NVIC_EnableIRQ(SWDT_IRQn);
    00202             NVIC_SetPriority(SWDT_IRQn, PDL_IRQ_LEVEL_SWWDG);
    00203         }
    00204     }
    00205
    00206     return (enResult);
    00207 } /* Swwdg_Init */
    00208
    00214 void Swwdg_DeInit(void)
    00215 {
    00216     /* Disable NVIC */
    00217     NVIC_ClearPendingIRQ(SWDT_IRQn);
    00218     NVIC_DisableIRQ(SWDT_IRQn);
    00219     NVIC_SetPriority(SWDT_IRQn, PDL_DEFAULT_INTERRUPT_LEVEL);
    00220
    00221     FM0P_SWWDT->WDOGLOCK    = SWWDG_REG_UNLOCK;  /* Un Lock */
    00222     FM0P_SWWDT->WDOGCONTROL = 0;                 /* Reset SW-Watchdog */
    00223     FM0P_SWWDT->WDOGSPMC    = 0;                 /* Reset Window watchdog */
    00224     FM0P_SWWDT->WDOGLOAD    = SWWDG_DEFAULT_VAL; /* Set default value to load value */
    00225
    00226     pfnSwwdgCallback       = NULL;              /* Initialize callback to NULL */
    00227 } /* Swwdg_DeInit */
    00228
    00241 en_result_t Swwdg_Start(func_ptr_t pfnSwwdgCb)
    00242 {
    00243     en_result_t enResult;
    00244
    00245     /* If software watchdog is active, error is returned. */
    00246     if (TRUE == FM0P_SWWDT->WDOGCONTROL_f.INTEN)
    00247     {
    00248         enResult = ErrorOperationInProgress;
    00249     }
    00250     else
    00251     {
    00252         /* Set callback pointer to global variable for SW-Wdg-ISR */
    00253         pfnSwwdgCallback = pfnSwwdgCb;
    00254
    00255         FM0P_SWWDT->WDOGLOCK = SWWDG_REG_UNLOCK; /* Un Lock */
    00256         FM0P_SWWDT->WDOGCONTROL_f.INTEN = TRUE;  /* Enable interrupt and count */
    00257         FM0P_SWWDT->WDOGLOCK = 0;                /* Lock */
    00258
    00259         enResult = Ok;
    00260     }
    00261
    00262     return (enResult);
    00263 } /* Swwdg_Start */
    00264
    00270 void Swwdg_Stop(void)
    00271 {
    00272     if (TRUE == FM0P_SWWDT->WDOGCONTROL_f.INTEN)
    00273     {
    00274         FM0P_SWWDT->WDOGLOCK = SWWDG_REG_UNLOCK; /* Un Lock */
    00275         FM0P_SWWDT->WDOGCONTROL_f.INTEN = FALSE; /* Disable interrupt and count */
    00276         FM0P_SWWDT->WDOGLOCK = 0;                /* Lock */
    00277     }
    00278 } /* Swwdg_Stop */
    00279
    00287 void Swwdg_WriteWdgLoad(uint32_t u32LoadValue)
    00288 {
    00289     FM0P_SWWDT->WDOGLOCK = SWWDG_REG_UNLOCK;     /* Un Lock */
    00290     FM0P_SWWDT->WDOGLOAD = u32LoadValue;         /* Write the load value */
    00291     FM0P_SWWDT->WDOGLOCK = 0;                    /* Lock */
    00292 } /* Swwdg_WriteWdgLoad */
    00293
    00301 uint32_t Swwdg_ReadWdgValue(void)
    00302 {
    00303     return (FM0P_SWWDT->WDOGVALUE);
    00304 } /* Swwdg_ReadWdgValue */
    00305
    00314 void Swwdg_Feed(void)
    00315 {
    00316     FM0P_SWWDT->WDOGLOCK   = SWWDG_REG_UNLOCK;   /* Release Lock */
    00317     FM0P_SWWDT->WDOGINTCLR = 1;                  /* Clear possible interrupt and reload value */
    00318     FM0P_SWWDT->WDOGLOCK   = 0;                  /* Lock again it! */
    00319 } /* Swwdg_Feed */
    00320
    00326 void Swwdg_EnableDbgBrkWdgCtl(void)
    00327 {
    00328     stc_crg_dbwdt_ctl_field_t stcDBWDT_CTL;
    00329
    00330     stcDBWDT_CTL         = FM0P_CRG->DBWDT_CTL_f;
    00331     stcDBWDT_CTL.DPSWBE  = TRUE;
    00332     FM0P_CRG->DBWDT_CTL_f = stcDBWDT_CTL;
    00333 } /* Swwdt_EnableDbgBrkWdtCtl */
    00334
    00340 void Swwdg_DisableDbgBrkWdgCtl(void)
    00341 {
    00342     stc_crg_dbwdt_ctl_field_t stcDBWDT_CTL;
    00343
    00344     stcDBWDT_CTL         = FM0P_CRG->DBWDT_CTL_f;
    00345     stcDBWDT_CTL.DPSWBE  = FALSE;
    00346     FM0P_CRG->DBWDT_CTL_f = stcDBWDT_CTL;
    00347 } /* Swwdt_DisableDbgBrkWdtCtl */
    00348
    00349 #endif /* #if (PDL_PERIPHERAL_ENABLE_SWWDG == PDL_ON) */
    00350
    00352
    00353 #endif /* #if (defined(PDL_PERIPHERAL_WDG_ACTIVE)) */
    00354
    00355 /******************************************************************************/
    00356 /* EOF (not truncated)                                                        */
    00357 /******************************************************************************/